Skip to content

Commit fbe7b20

Browse files
authored
feat: add global CSS props for focus offset and color (#6782)
**Related Issue:** #3392 ## Summary Adds the following global CSS props: * `--calcite-ui-focus-color` * `--calcite-ui-focus-offset-invert` – inverts the applied offset when set to `1` or keeps as is when `0`
1 parent 2276b43 commit fbe7b20

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

calcite-preset.ts

+29-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
import flattenColorPalette from "tailwindcss/lib/util/flattenColorPalette";
22
import plugin from "tailwindcss/plugin";
33

4+
/**
5+
* This helper inverts a value based on a boolean CSS prop flag
6+
*
7+
* When the flag is 0, it will not be inverted. When 1, it will invert it (multiplied by -1)
8+
*
9+
* @param {string} value - the CSS value to invert
10+
* @param {string} flagPropName - the boolean CSS prop (value must be 0 or 1)
11+
*/
12+
function invert(value: string, flagPropName: string): string {
13+
return `calc(
14+
${value} *
15+
calc(
16+
1 -
17+
2 * clamp(
18+
0,
19+
var(${flagPropName}),
20+
1
21+
)
22+
)
23+
)`;
24+
}
25+
426
export default {
527
theme: {
628
borderColor: ({ theme }): object => ({
@@ -233,23 +255,23 @@ export default {
233255
"outline-color": "transparent"
234256
},
235257
".focus-normal": {
236-
outline: "2px solid var(--calcite-ui-brand)"
258+
outline: "2px solid var(--calcite-ui-focus-color)"
237259
},
238260
".focus-outset": {
239-
outline: "2px solid var(--calcite-ui-brand)",
240-
"outline-offset": "2px"
261+
outline: "2px solid var(--calcite-ui-focus-color)",
262+
"outline-offset": invert("2px", "--calcite-ui-focus-offset-invert")
241263
},
242264
".focus-inset": {
243-
outline: "2px solid var(--calcite-ui-brand)",
244-
"outline-offset": "-2px"
265+
outline: "2px solid var(--calcite-ui-focus-color)",
266+
"outline-offset": invert("-2px", "--calcite-ui-focus-offset-invert")
245267
},
246268
".focus-outset-danger": {
247269
outline: "2px solid var(--calcite-ui-danger)",
248-
"outline-offset": "2px"
270+
"outline-offset": invert("2px", "--calcite-ui-focus-offset-invert")
249271
},
250272
".focus-inset-danger": {
251273
outline: "2px solid var(--calcite-ui-danger)",
252-
"outline-offset": "-2px"
274+
"outline-offset": invert("-2px", "--calcite-ui-focus-offset-invert")
253275
},
254276
".transition-default": {
255277
transition: "all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s"

src/assets/styles/global.scss

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@
4444

4545
--calcite-border-radius: 4px;
4646
--calcite-border-radius-base: 0;
47-
--calcite-ui-opacity-disabled: 0.5;
4847
--calcite-panel-width-multiplier: 1;
48+
--calcite-ui-focus-color: var(--calcite-ui-brand);
49+
--calcite-ui-focus-offset-invert: 0; // should be 0 or 1
4950
--calcite-ui-icon-color: currentColor;
51+
--calcite-ui-opacity-disabled: 0.5;
5052

5153
@apply font-sans;
5254
}

0 commit comments

Comments
 (0)