@workday/canvas-kit-react 8.0.0-alpha.208-next.1 → 8.0.0-alpha.222-next.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common/lib/theming/index.ts +1 -1
- package/common/lib/theming/styled.ts +6 -3
- package/common/lib/utils/elements.ts +4 -4
- package/common/lib/utils/index.ts +0 -1
- package/dist/commonjs/card/lib/Card.d.ts +1 -1
- package/dist/commonjs/card/lib/CardBody.d.ts +1 -1
- package/dist/commonjs/card/lib/CardBody.d.ts.map +1 -1
- package/dist/commonjs/common/lib/theming/index.d.ts +1 -1
- package/dist/commonjs/common/lib/theming/index.d.ts.map +1 -1
- package/dist/commonjs/common/lib/theming/styled.d.ts +2 -0
- package/dist/commonjs/common/lib/theming/styled.d.ts.map +1 -1
- package/dist/commonjs/common/lib/theming/styled.js +1 -2
- package/dist/commonjs/common/lib/utils/elements.d.ts +1 -1
- package/dist/commonjs/common/lib/utils/elements.d.ts.map +1 -1
- package/dist/commonjs/common/lib/utils/elements.js +3 -3
- package/dist/commonjs/common/lib/utils/index.d.ts +0 -1
- package/dist/commonjs/common/lib/utils/index.d.ts.map +1 -1
- package/dist/commonjs/common/lib/utils/index.js +0 -1
- package/dist/commonjs/dialog/lib/Dialog.d.ts +1 -1
- package/dist/commonjs/icon/lib/SystemIcon.d.ts +1 -1
- package/dist/commonjs/icon/lib/SystemIcon.d.ts.map +1 -1
- package/dist/commonjs/index.d.ts +1 -0
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +1 -0
- package/dist/commonjs/layout/index.d.ts +8 -4
- package/dist/commonjs/layout/index.d.ts.map +1 -1
- package/dist/commonjs/layout/index.js +10 -2
- package/dist/commonjs/layout/lib/Box.d.ts +6 -4
- package/dist/commonjs/layout/lib/Box.d.ts.map +1 -1
- package/dist/commonjs/layout/lib/Box.js +8 -9
- package/dist/commonjs/layout/lib/Flex.d.ts +5 -2
- package/dist/commonjs/layout/lib/Flex.d.ts.map +1 -1
- package/dist/commonjs/layout/lib/Flex.js +5 -1
- package/dist/commonjs/layout/lib/Grid.d.ts +5 -6
- package/dist/commonjs/layout/lib/Grid.d.ts.map +1 -1
- package/dist/commonjs/layout/lib/Grid.js +2 -2
- package/dist/commonjs/layout/lib/Stack.d.ts +4 -4
- package/dist/commonjs/layout/lib/utils/background.d.ts +44 -0
- package/dist/commonjs/layout/lib/utils/background.d.ts.map +1 -0
- package/dist/commonjs/layout/lib/utils/background.js +57 -0
- package/dist/commonjs/layout/lib/utils/border/color.d.ts +47 -0
- package/dist/commonjs/layout/lib/utils/border/color.d.ts.map +1 -0
- package/dist/commonjs/layout/lib/utils/border/color.js +42 -0
- package/dist/commonjs/layout/lib/utils/border/index.d.ts +26 -0
- package/dist/commonjs/layout/lib/utils/border/index.d.ts.map +1 -0
- package/dist/commonjs/layout/lib/utils/border/index.js +46 -0
- package/dist/commonjs/layout/lib/utils/border/lineStyle.d.ts +38 -0
- package/dist/commonjs/layout/lib/utils/border/lineStyle.d.ts.map +1 -0
- package/dist/commonjs/layout/lib/utils/border/lineStyle.js +52 -0
- package/dist/commonjs/layout/lib/utils/border/radius.d.ts +33 -0
- package/dist/commonjs/layout/lib/utils/border/radius.d.ts.map +1 -0
- package/dist/commonjs/layout/lib/utils/border/radius.js +32 -0
- package/dist/commonjs/layout/lib/utils/border/shorthand.d.ts +34 -0
- package/dist/commonjs/layout/lib/utils/border/shorthand.d.ts.map +1 -0
- package/dist/commonjs/layout/lib/utils/border/shorthand.js +42 -0
- package/dist/commonjs/layout/lib/utils/border/width.d.ts +34 -0
- package/dist/commonjs/layout/lib/utils/border/width.d.ts.map +1 -0
- package/dist/commonjs/layout/lib/utils/border/width.js +42 -0
- package/dist/commonjs/layout/lib/utils/buildStyleFns.d.ts +12 -0
- package/dist/commonjs/layout/lib/utils/buildStyleFns.d.ts.map +1 -0
- package/dist/commonjs/layout/lib/utils/buildStyleFns.js +90 -0
- package/dist/commonjs/layout/lib/utils/color.d.ts +23 -16
- package/dist/commonjs/layout/lib/utils/color.d.ts.map +1 -1
- package/dist/commonjs/layout/lib/utils/color.js +25 -49
- package/dist/commonjs/layout/lib/utils/depth.d.ts +17 -11
- package/dist/commonjs/layout/lib/utils/depth.d.ts.map +1 -1
- package/dist/commonjs/layout/lib/utils/depth.js +20 -20
- package/dist/commonjs/layout/lib/utils/flex.d.ts +31 -12
- package/dist/commonjs/layout/lib/utils/flex.d.ts.map +1 -1
- package/dist/commonjs/layout/lib/utils/flex.js +58 -25
- package/dist/commonjs/layout/lib/utils/flexItem.d.ts +18 -15
- package/dist/commonjs/layout/lib/utils/flexItem.d.ts.map +1 -1
- package/dist/commonjs/layout/lib/utils/flexItem.js +43 -26
- package/dist/commonjs/layout/lib/utils/grid.d.ts +40 -35
- package/dist/commonjs/layout/lib/utils/grid.d.ts.map +1 -1
- package/dist/commonjs/layout/lib/utils/grid.js +99 -72
- package/dist/commonjs/layout/lib/utils/gridItem.d.ts +17 -14
- package/dist/commonjs/layout/lib/utils/gridItem.d.ts.map +1 -1
- package/dist/commonjs/layout/lib/utils/gridItem.js +58 -30
- package/dist/commonjs/layout/lib/utils/layout.d.ts +47 -25
- package/dist/commonjs/layout/lib/utils/layout.d.ts.map +1 -1
- package/dist/commonjs/layout/lib/utils/layout.js +71 -33
- package/dist/commonjs/layout/lib/utils/other.d.ts +44 -2
- package/dist/commonjs/layout/lib/utils/other.d.ts.map +1 -1
- package/dist/commonjs/layout/lib/utils/other.js +101 -17
- package/dist/commonjs/layout/lib/utils/position.d.ts +37 -20
- package/dist/commonjs/layout/lib/utils/position.d.ts.map +1 -1
- package/dist/commonjs/layout/lib/utils/position.js +49 -66
- package/dist/commonjs/layout/lib/utils/space.d.ts +107 -51
- package/dist/commonjs/layout/lib/utils/space.d.ts.map +1 -1
- package/dist/commonjs/layout/lib/utils/space.js +98 -148
- package/dist/commonjs/layout/lib/utils/stack.d.ts +3 -6
- package/dist/commonjs/layout/lib/utils/stack.d.ts.map +1 -1
- package/dist/commonjs/layout/lib/utils/stack.js +13 -39
- package/dist/commonjs/layout/lib/utils/systemProps.d.ts +31 -0
- package/dist/commonjs/layout/lib/utils/systemProps.d.ts.map +1 -0
- package/dist/commonjs/layout/lib/utils/systemProps.js +2 -0
- package/dist/commonjs/layout/lib/utils/text.d.ts +33 -15
- package/dist/commonjs/layout/lib/utils/text.d.ts.map +1 -1
- package/dist/commonjs/layout/lib/utils/text.js +74 -38
- package/dist/commonjs/modal/lib/Modal.d.ts +1 -1
- package/dist/commonjs/popup/lib/Popup.d.ts +1 -1
- package/dist/commonjs/popup/lib/PopupBody.d.ts +1 -1
- package/dist/commonjs/popup/lib/hooks/useReturnFocus.d.ts.map +1 -1
- package/dist/commonjs/popup/lib/hooks/useReturnFocus.js +72 -7
- package/dist/commonjs/tabs/lib/TabsItem.d.ts +1 -1
- package/dist/commonjs/testing/index.d.ts +5 -0
- package/dist/commonjs/testing/index.d.ts.map +1 -0
- package/dist/commonjs/testing/index.js +16 -0
- package/dist/commonjs/testing/lib/ComponentStatesTable.d.ts +26 -0
- package/dist/commonjs/testing/lib/ComponentStatesTable.d.ts.map +1 -0
- package/dist/commonjs/testing/lib/ComponentStatesTable.js +48 -0
- package/dist/commonjs/testing/lib/StaticStates.d.ts +7 -0
- package/dist/commonjs/testing/lib/StaticStates.d.ts.map +1 -0
- package/dist/commonjs/{common/lib/utils → testing/lib}/StaticStates.js +1 -1
- package/dist/commonjs/testing/lib/permutateProps.d.ts +5 -0
- package/dist/commonjs/testing/lib/permutateProps.d.ts.map +1 -0
- package/dist/commonjs/testing/lib/permutateProps.js +47 -0
- package/dist/commonjs/testing/lib/propTypes.d.ts +15 -0
- package/dist/commonjs/testing/lib/propTypes.d.ts.map +1 -0
- package/dist/commonjs/testing/lib/propTypes.js +2 -0
- package/dist/commonjs/tokens/lib/colors.types.d.ts +4 -6
- package/dist/commonjs/tokens/lib/colors.types.d.ts.map +1 -1
- package/dist/es6/card/lib/Card.d.ts +1 -1
- package/dist/es6/card/lib/CardBody.d.ts +1 -1
- package/dist/es6/card/lib/CardBody.d.ts.map +1 -1
- package/dist/es6/common/lib/theming/index.d.ts +1 -1
- package/dist/es6/common/lib/theming/index.d.ts.map +1 -1
- package/dist/es6/common/lib/theming/styled.d.ts +2 -0
- package/dist/es6/common/lib/theming/styled.d.ts.map +1 -1
- package/dist/es6/common/lib/theming/styled.js +1 -2
- package/dist/es6/common/lib/utils/elements.d.ts +1 -1
- package/dist/es6/common/lib/utils/elements.d.ts.map +1 -1
- package/dist/es6/common/lib/utils/elements.js +3 -3
- package/dist/es6/common/lib/utils/index.d.ts +0 -1
- package/dist/es6/common/lib/utils/index.d.ts.map +1 -1
- package/dist/es6/common/lib/utils/index.js +0 -1
- package/dist/es6/dialog/lib/Dialog.d.ts +1 -1
- package/dist/es6/icon/lib/SystemIcon.d.ts +1 -1
- package/dist/es6/icon/lib/SystemIcon.d.ts.map +1 -1
- package/dist/es6/index.d.ts +1 -0
- package/dist/es6/index.d.ts.map +1 -1
- package/dist/es6/index.js +1 -0
- package/dist/es6/layout/index.d.ts +8 -4
- package/dist/es6/layout/index.d.ts.map +1 -1
- package/dist/es6/layout/index.js +7 -1
- package/dist/es6/layout/lib/Box.d.ts +6 -4
- package/dist/es6/layout/lib/Box.d.ts.map +1 -1
- package/dist/es6/layout/lib/Box.js +8 -9
- package/dist/es6/layout/lib/Flex.d.ts +5 -2
- package/dist/es6/layout/lib/Flex.d.ts.map +1 -1
- package/dist/es6/layout/lib/Flex.js +5 -1
- package/dist/es6/layout/lib/Grid.d.ts +5 -6
- package/dist/es6/layout/lib/Grid.d.ts.map +1 -1
- package/dist/es6/layout/lib/Grid.js +2 -2
- package/dist/es6/layout/lib/Stack.d.ts +4 -4
- package/dist/es6/layout/lib/utils/background.d.ts +44 -0
- package/dist/es6/layout/lib/utils/background.d.ts.map +1 -0
- package/dist/es6/layout/lib/utils/background.js +54 -0
- package/dist/es6/layout/lib/utils/border/color.d.ts +47 -0
- package/dist/es6/layout/lib/utils/border/color.d.ts.map +1 -0
- package/dist/es6/layout/lib/utils/border/color.js +39 -0
- package/dist/es6/layout/lib/utils/border/index.d.ts +26 -0
- package/dist/es6/layout/lib/utils/border/index.d.ts.map +1 -0
- package/dist/es6/layout/lib/utils/border/index.js +43 -0
- package/dist/es6/layout/lib/utils/border/lineStyle.d.ts +38 -0
- package/dist/es6/layout/lib/utils/border/lineStyle.d.ts.map +1 -0
- package/dist/es6/layout/lib/utils/border/lineStyle.js +49 -0
- package/dist/es6/layout/lib/utils/border/radius.d.ts +33 -0
- package/dist/es6/layout/lib/utils/border/radius.d.ts.map +1 -0
- package/dist/es6/layout/lib/utils/border/radius.js +29 -0
- package/dist/es6/layout/lib/utils/border/shorthand.d.ts +34 -0
- package/dist/es6/layout/lib/utils/border/shorthand.d.ts.map +1 -0
- package/dist/es6/layout/lib/utils/border/shorthand.js +39 -0
- package/dist/es6/layout/lib/utils/border/width.d.ts +34 -0
- package/dist/es6/layout/lib/utils/border/width.d.ts.map +1 -0
- package/dist/es6/layout/lib/utils/border/width.js +39 -0
- package/dist/es6/layout/lib/utils/buildStyleFns.d.ts +12 -0
- package/dist/es6/layout/lib/utils/buildStyleFns.d.ts.map +1 -0
- package/dist/es6/layout/lib/utils/buildStyleFns.js +85 -0
- package/dist/es6/layout/lib/utils/color.d.ts +23 -16
- package/dist/es6/layout/lib/utils/color.d.ts.map +1 -1
- package/dist/es6/layout/lib/utils/color.js +24 -47
- package/dist/es6/layout/lib/utils/depth.d.ts +17 -11
- package/dist/es6/layout/lib/utils/depth.d.ts.map +1 -1
- package/dist/es6/layout/lib/utils/depth.js +19 -18
- package/dist/es6/layout/lib/utils/flex.d.ts +31 -12
- package/dist/es6/layout/lib/utils/flex.d.ts.map +1 -1
- package/dist/es6/layout/lib/utils/flex.js +57 -23
- package/dist/es6/layout/lib/utils/flexItem.d.ts +18 -15
- package/dist/es6/layout/lib/utils/flexItem.d.ts.map +1 -1
- package/dist/es6/layout/lib/utils/flexItem.js +42 -24
- package/dist/es6/layout/lib/utils/grid.d.ts +40 -35
- package/dist/es6/layout/lib/utils/grid.d.ts.map +1 -1
- package/dist/es6/layout/lib/utils/grid.js +98 -70
- package/dist/es6/layout/lib/utils/gridItem.d.ts +17 -14
- package/dist/es6/layout/lib/utils/gridItem.d.ts.map +1 -1
- package/dist/es6/layout/lib/utils/gridItem.js +57 -28
- package/dist/es6/layout/lib/utils/layout.d.ts +47 -25
- package/dist/es6/layout/lib/utils/layout.d.ts.map +1 -1
- package/dist/es6/layout/lib/utils/layout.js +70 -31
- package/dist/es6/layout/lib/utils/other.d.ts +44 -2
- package/dist/es6/layout/lib/utils/other.d.ts.map +1 -1
- package/dist/es6/layout/lib/utils/other.js +100 -15
- package/dist/es6/layout/lib/utils/position.d.ts +37 -20
- package/dist/es6/layout/lib/utils/position.d.ts.map +1 -1
- package/dist/es6/layout/lib/utils/position.js +48 -64
- package/dist/es6/layout/lib/utils/space.d.ts +107 -51
- package/dist/es6/layout/lib/utils/space.d.ts.map +1 -1
- package/dist/es6/layout/lib/utils/space.js +97 -146
- package/dist/es6/layout/lib/utils/stack.d.ts +3 -6
- package/dist/es6/layout/lib/utils/stack.d.ts.map +1 -1
- package/dist/es6/layout/lib/utils/stack.js +13 -39
- package/dist/es6/layout/lib/utils/systemProps.d.ts +31 -0
- package/dist/es6/layout/lib/utils/systemProps.d.ts.map +1 -0
- package/dist/es6/layout/lib/utils/systemProps.js +1 -0
- package/dist/es6/layout/lib/utils/text.d.ts +33 -15
- package/dist/es6/layout/lib/utils/text.d.ts.map +1 -1
- package/dist/es6/layout/lib/utils/text.js +73 -36
- package/dist/es6/modal/lib/Modal.d.ts +1 -1
- package/dist/es6/popup/lib/Popup.d.ts +1 -1
- package/dist/es6/popup/lib/PopupBody.d.ts +1 -1
- package/dist/es6/popup/lib/hooks/useReturnFocus.d.ts.map +1 -1
- package/dist/es6/popup/lib/hooks/useReturnFocus.js +73 -8
- package/dist/es6/tabs/lib/TabsItem.d.ts +1 -1
- package/dist/es6/testing/index.d.ts +5 -0
- package/dist/es6/testing/index.d.ts.map +1 -0
- package/dist/es6/testing/index.js +4 -0
- package/dist/es6/testing/lib/ComponentStatesTable.d.ts +26 -0
- package/dist/es6/testing/lib/ComponentStatesTable.d.ts.map +1 -0
- package/dist/es6/testing/lib/ComponentStatesTable.js +41 -0
- package/dist/es6/testing/lib/StaticStates.d.ts +7 -0
- package/dist/es6/testing/lib/StaticStates.d.ts.map +1 -0
- package/dist/es6/{common/lib/utils → testing/lib}/StaticStates.js +1 -1
- package/dist/es6/testing/lib/permutateProps.d.ts +5 -0
- package/dist/es6/testing/lib/permutateProps.d.ts.map +1 -0
- package/dist/es6/testing/lib/permutateProps.js +43 -0
- package/dist/es6/testing/lib/propTypes.d.ts +15 -0
- package/dist/es6/testing/lib/propTypes.d.ts.map +1 -0
- package/dist/es6/testing/lib/propTypes.js +1 -0
- package/dist/es6/tokens/lib/colors.types.d.ts +4 -6
- package/dist/es6/tokens/lib/colors.types.d.ts.map +1 -1
- package/icon/lib/SystemIcon.tsx +1 -1
- package/index.ts +1 -0
- package/layout/index.ts +8 -4
- package/layout/lib/Box.tsx +10 -36
- package/layout/lib/Flex.tsx +5 -1
- package/layout/lib/Grid.tsx +3 -4
- package/layout/lib/utils/background.ts +83 -0
- package/layout/lib/utils/border/color.ts +85 -0
- package/layout/lib/utils/border/index.ts +49 -0
- package/layout/lib/utils/border/lineStyle.ts +87 -0
- package/layout/lib/utils/border/radius.ts +61 -0
- package/layout/lib/utils/border/shorthand.ts +73 -0
- package/layout/lib/utils/border/width.ts +73 -0
- package/layout/lib/utils/buildStyleFns.ts +117 -0
- package/layout/lib/utils/color.ts +40 -55
- package/layout/lib/utils/depth.ts +28 -24
- package/layout/lib/utils/flex.ts +83 -32
- package/layout/lib/utils/flexItem.ts +54 -36
- package/layout/lib/utils/grid.ts +131 -94
- package/layout/lib/utils/gridItem.ts +69 -41
- package/layout/lib/utils/layout.ts +109 -50
- package/layout/lib/utils/other.ts +142 -15
- package/layout/lib/utils/position.ts +79 -73
- package/layout/lib/utils/space.ts +202 -196
- package/layout/lib/utils/stack.ts +19 -45
- package/layout/lib/utils/systemProps.ts +46 -0
- package/layout/lib/utils/text.ts +99 -34
- package/package.json +3 -3
- package/popup/lib/hooks/useReturnFocus.tsx +83 -9
- package/testing/LICENSE +52 -0
- package/testing/README.md +6 -0
- package/testing/index.ts +4 -0
- package/testing/lib/ComponentStatesTable.tsx +80 -0
- package/{common/lib/utils → testing/lib}/StaticStates.tsx +5 -4
- package/testing/lib/permutateProps.ts +47 -0
- package/testing/lib/propTypes.ts +15 -0
- package/testing/package.json +6 -0
- package/tokens/lib/colors.types.ts +4 -7
- package/dist/commonjs/common/lib/utils/StaticStates.d.ts +0 -8
- package/dist/commonjs/common/lib/utils/StaticStates.d.ts.map +0 -1
- package/dist/commonjs/layout/lib/utils/border.d.ts +0 -103
- package/dist/commonjs/layout/lib/utils/border.d.ts.map +0 -1
- package/dist/commonjs/layout/lib/utils/border.js +0 -153
- package/dist/commonjs/layout/lib/utils/font.d.ts +0 -29
- package/dist/commonjs/layout/lib/utils/font.d.ts.map +0 -1
- package/dist/commonjs/layout/lib/utils/font.js +0 -57
- package/dist/es6/common/lib/utils/StaticStates.d.ts +0 -8
- package/dist/es6/common/lib/utils/StaticStates.d.ts.map +0 -1
- package/dist/es6/layout/lib/utils/border.d.ts +0 -103
- package/dist/es6/layout/lib/utils/border.d.ts.map +0 -1
- package/dist/es6/layout/lib/utils/border.js +0 -149
- package/dist/es6/layout/lib/utils/font.d.ts +0 -29
- package/dist/es6/layout/lib/utils/font.d.ts.map +0 -1
- package/dist/es6/layout/lib/utils/font.js +0 -53
- package/layout/lib/utils/border.ts +0 -263
- package/layout/lib/utils/font.ts +0 -67
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import {
|
|
2
|
+
borderRadius as borderRadiusTokens,
|
|
3
|
+
colors as colorTokens,
|
|
4
|
+
depth as depthTokens,
|
|
5
|
+
space as spaceTokens,
|
|
6
|
+
type as typeTokens,
|
|
7
|
+
} from '@workday/canvas-kit-react/tokens';
|
|
8
|
+
|
|
9
|
+
import {CanvasSystemPropValues, SystemPropNames, SystemPropValues} from './systemProps';
|
|
10
|
+
|
|
11
|
+
export type StyleFnConfig = {
|
|
12
|
+
name: string;
|
|
13
|
+
properties: string[];
|
|
14
|
+
system: SystemPropNames | 'none';
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type StyleFns = {
|
|
18
|
+
[key: string]: (value: unknown) => {};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const getColor = (value: SystemPropValues['color']) => {
|
|
22
|
+
return colorTokens[value] || value;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const getDepth = (value: SystemPropValues['depth']) => {
|
|
26
|
+
return depthTokens[value];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const getShape = (value: SystemPropValues['shape']) => {
|
|
30
|
+
return borderRadiusTokens[value as CanvasSystemPropValues['shape']] || value;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const getSpace = (value: SystemPropValues['space']) => {
|
|
34
|
+
return spaceTokens[value as CanvasSystemPropValues['space']] || value;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const getFont = (value: SystemPropValues['font']) => {
|
|
38
|
+
return typeTokens.properties.fontFamilies[value as CanvasSystemPropValues['font']] || value;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const getFontSize = (value: SystemPropValues['fontSize'] | string) => {
|
|
42
|
+
return typeTokens.properties.fontSizes[value as CanvasSystemPropValues['fontSize']] || value;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const getFontWeight = (value: SystemPropValues['fontWeight'] | string) => {
|
|
46
|
+
return typeTokens.properties.fontWeights[value as CanvasSystemPropValues['fontWeight']] || value;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export function buildStyleFns(styleFnConfigs: StyleFnConfig[]): StyleFns {
|
|
50
|
+
return styleFnConfigs.reduce((styleFns = {}, styleFnConfig) => {
|
|
51
|
+
const styleFn = (value: unknown) => {
|
|
52
|
+
return styleFnConfig.properties.reduce((styles = {}, property: string) => {
|
|
53
|
+
if (styleFnConfig.system === 'color') {
|
|
54
|
+
return {...styles, [property]: getColor(value as SystemPropValues['color'])};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (styleFnConfig.system === 'depth') {
|
|
58
|
+
// Depth tokens return the style property (box-shadow) and the value
|
|
59
|
+
const depthStyle = getDepth(value as SystemPropValues['depth']);
|
|
60
|
+
return {...styles, ...depthStyle};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (styleFnConfig.system === 'font') {
|
|
64
|
+
return {
|
|
65
|
+
...styles,
|
|
66
|
+
[property]: getFont(value as SystemPropValues['font']),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (styleFnConfig.system === 'fontSize') {
|
|
71
|
+
return {
|
|
72
|
+
...styles,
|
|
73
|
+
[property]: getFontSize(value as SystemPropValues['fontSize']),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (styleFnConfig.system === 'fontWeight') {
|
|
78
|
+
return {
|
|
79
|
+
...styles,
|
|
80
|
+
[property]: getFontWeight(value as SystemPropValues['fontWeight']),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (styleFnConfig.system === 'shape') {
|
|
85
|
+
return {
|
|
86
|
+
...styles,
|
|
87
|
+
[property]: getShape(value as SystemPropValues['shape']),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (styleFnConfig.system === 'space') {
|
|
92
|
+
return {...styles, [property]: getSpace(value as SystemPropValues['space'])};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {...styles, [property]: value};
|
|
96
|
+
}, {});
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
return {...styleFns, [styleFnConfig.name]: styleFn};
|
|
100
|
+
}, {});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function buildStylePropFn<P extends {}>(styleFns: StyleFns) {
|
|
104
|
+
return (props: P) => {
|
|
105
|
+
let styles = {};
|
|
106
|
+
for (const key in props) {
|
|
107
|
+
if (key in props && key in styleFns) {
|
|
108
|
+
const styleFn = styleFns[key];
|
|
109
|
+
const value = props[key];
|
|
110
|
+
const style = styleFn(value);
|
|
111
|
+
styles = {...styles, ...style};
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return styles;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -1,67 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
colors as colorTokens,
|
|
4
|
-
CanvasColor,
|
|
5
|
-
CanvasTypeVariants,
|
|
6
|
-
} from '@workday/canvas-kit-react/tokens';
|
|
1
|
+
import {Property} from 'csstype';
|
|
7
2
|
|
|
8
|
-
|
|
3
|
+
import {buildStyleFns, buildStylePropFn, StyleFnConfig} from './buildStyleFns';
|
|
4
|
+
import {SystemPropValues} from './systemProps';
|
|
9
5
|
|
|
10
|
-
/** style props to
|
|
6
|
+
/** style props to set CSS color properties */
|
|
11
7
|
export type ColorStyleProps = {
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const getBackgroundColor = (value: CanvasColor | string) => ({
|
|
27
|
-
backgroundColor: colorTokens[value] || value,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const getBackgroundImage = (value: string) => ({
|
|
31
|
-
backgroundImage: value,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const getColor = (value: CanvasColor | keyof CanvasTypeVariants | string) => ({
|
|
35
|
-
color: colorTokens[value] || value,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const colorProps = {
|
|
39
|
-
background: getBackground,
|
|
40
|
-
backgroundColor: getBackgroundColor,
|
|
41
|
-
backgroundImage: getBackgroundImage,
|
|
42
|
-
color: getColor,
|
|
8
|
+
/**
|
|
9
|
+
* - sets [CSS background-color property](https://developer.mozilla.org/en-US/docs/Web/CSS/background-color)
|
|
10
|
+
* - system tokens: `color`
|
|
11
|
+
* */
|
|
12
|
+
backgroundColor?: SystemPropValues['color'];
|
|
13
|
+
/**
|
|
14
|
+
* - sets [CSS color property](https://developer.mozilla.org/en-US/docs/Web/CSS/color)
|
|
15
|
+
* - system tokens: `color`
|
|
16
|
+
* */
|
|
17
|
+
color?: SystemPropValues['color'];
|
|
18
|
+
/** sets [CSS opacity property](https://developer.mozilla.org/en-US/docs/Web/CSS/opacity) */
|
|
19
|
+
opacity?: Property.Opacity;
|
|
43
20
|
};
|
|
44
21
|
|
|
22
|
+
export const colorStyleFnConfigs: StyleFnConfig[] = [
|
|
23
|
+
{
|
|
24
|
+
name: 'backgroundColor',
|
|
25
|
+
properties: ['backgroundColor'],
|
|
26
|
+
system: 'color',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'color',
|
|
30
|
+
properties: ['color'],
|
|
31
|
+
system: 'color',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'opacity',
|
|
35
|
+
properties: ['opacity'],
|
|
36
|
+
system: 'none',
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
export const colorFns = buildStyleFns(colorStyleFnConfigs);
|
|
45
41
|
/**
|
|
46
|
-
* A style prop function that takes
|
|
42
|
+
* A style prop function that takes component props and returns color styles from Canvas token values.
|
|
47
43
|
* If no `ColorStyleProps` are found, it returns an empty object.
|
|
48
44
|
*
|
|
49
45
|
* @example
|
|
50
|
-
*
|
|
46
|
+
* ```tsx
|
|
51
47
|
* const BoxExample = () => (
|
|
52
|
-
* <Box
|
|
48
|
+
* <Box color="frenchVanilla100" opacity={0.6}>Hello, colors!</Box>
|
|
53
49
|
* );
|
|
54
|
-
*
|
|
50
|
+
* ```
|
|
55
51
|
*/
|
|
56
|
-
export
|
|
57
|
-
let styles = {};
|
|
58
|
-
for (const key in props) {
|
|
59
|
-
if (key in colorProps) {
|
|
60
|
-
const value = props[key as keyof ColorStyleProps] as CanvasColor | string;
|
|
61
|
-
const colorFn = colorProps[key as keyof ColorStyleProps];
|
|
62
|
-
const style = colorFn(value);
|
|
63
|
-
styles = {...styles, ...style};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return styles;
|
|
67
|
-
}
|
|
52
|
+
export const color = buildStylePropFn<ColorStyleProps>(colorFns);
|
|
@@ -1,37 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type DepthTokenKeys = keyof DepthTokens;
|
|
5
|
-
export type DepthTokenValues = DepthTokens[keyof DepthTokens];
|
|
1
|
+
import {Property} from 'csstype';
|
|
2
|
+
import {buildStyleFns, buildStylePropFn, StyleFnConfig} from './buildStyleFns';
|
|
3
|
+
import {SystemPropValues} from './systemProps';
|
|
6
4
|
|
|
7
5
|
/** style props to for depth styles */
|
|
8
6
|
export type DepthStyleProps = {
|
|
9
|
-
/** sets
|
|
10
|
-
|
|
7
|
+
/** sets [CSS box-shadow styles](https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow) */
|
|
8
|
+
boxShadow?: Property.BoxShadow;
|
|
9
|
+
/**
|
|
10
|
+
* - sets [CSS box-shadow styles](https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow)
|
|
11
|
+
* - system tokens: `depth`
|
|
12
|
+
* */
|
|
13
|
+
depth?: SystemPropValues['depth'];
|
|
11
14
|
};
|
|
12
15
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
export const depthStyleFnConfigs: StyleFnConfig[] = [
|
|
17
|
+
{
|
|
18
|
+
name: 'boxShadow',
|
|
19
|
+
properties: ['boxShadow'],
|
|
20
|
+
system: 'none',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'depth',
|
|
24
|
+
properties: ['boxShadow'],
|
|
25
|
+
system: 'depth',
|
|
26
|
+
},
|
|
27
|
+
];
|
|
16
28
|
|
|
29
|
+
export const depthStyleFns = buildStyleFns(depthStyleFnConfigs);
|
|
17
30
|
/**
|
|
18
|
-
* A style prop function that takes
|
|
31
|
+
* A style prop function that takes component props and returns depth styles from Canvas token values.
|
|
19
32
|
* If no `DepthStyleProps` are found, it returns an empty object.
|
|
20
33
|
*
|
|
21
34
|
* @example
|
|
22
|
-
*
|
|
23
|
-
* const
|
|
35
|
+
* ```tsx
|
|
36
|
+
* const DepthExample = () => (
|
|
24
37
|
* <Box depth={3}>Hello, box shadows!</Box>
|
|
25
38
|
* );
|
|
26
|
-
*
|
|
39
|
+
* ```
|
|
27
40
|
*/
|
|
28
|
-
export
|
|
29
|
-
for (const key in props) {
|
|
30
|
-
if (key in depthProps) {
|
|
31
|
-
const token = props[key as keyof DepthStyleProps] as DepthTokenKeys;
|
|
32
|
-
const depthFn = depthProps[key as keyof DepthStyleProps];
|
|
33
|
-
return depthFn(token);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return {} as DepthTokenValues;
|
|
37
|
-
}
|
|
41
|
+
export const depth = buildStylePropFn<DepthStyleProps>(depthStyleFns);
|
package/layout/lib/utils/flex.ts
CHANGED
|
@@ -1,58 +1,109 @@
|
|
|
1
1
|
import {Property} from 'csstype';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import {buildStyleFns, buildStylePropFn, StyleFnConfig} from './buildStyleFns';
|
|
4
|
+
import {SystemPropValues} from './systemProps';
|
|
5
|
+
|
|
6
|
+
/** style props to for CSS flexbox container properties */
|
|
4
7
|
export type FlexStyleProps = {
|
|
5
|
-
/** sets
|
|
8
|
+
/** sets [CSS align-items property](https://developer.mozilla.org/en-US/docs/Web/CSS/align-items) */
|
|
6
9
|
alignItems?: Property.AlignItems;
|
|
7
|
-
/** sets
|
|
10
|
+
/** sets [CSS align-content property](https://developer.mozilla.org/en-US/docs/Web/CSS/align-content) */
|
|
8
11
|
alignContent?: Property.AlignContent;
|
|
9
12
|
/**
|
|
10
|
-
* sets
|
|
11
|
-
* @default 'flex'
|
|
13
|
+
* - sets [CSS display property](https://developer.mozilla.org/en-US/docs/Web/CSS/display)
|
|
14
|
+
* - @default 'flex'
|
|
12
15
|
* */
|
|
13
16
|
display?: 'flex' | 'inline-flex';
|
|
14
|
-
/** sets
|
|
17
|
+
/** sets [CSS justify-items property](https://developer.mozilla.org/en-US/docs/Web/CSS/justify-items) */
|
|
15
18
|
justifyItems?: Property.JustifyItems;
|
|
16
|
-
/** sets
|
|
19
|
+
/** sets [CSS justify-content property](https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content) */
|
|
17
20
|
justifyContent?: Property.JustifyContent;
|
|
18
|
-
/** sets
|
|
21
|
+
/** sets [CSS flex-wrap property](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap) */
|
|
19
22
|
flexWrap?: Property.FlexWrap;
|
|
20
|
-
/** sets
|
|
23
|
+
/** sets [CSS flex-direction property](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-direction) */
|
|
21
24
|
flexDirection?: Property.FlexDirection;
|
|
25
|
+
/**
|
|
26
|
+
* - sets [CSS gap property](https://developer.mozilla.org/en-US/docs/Web/CSS/gap)
|
|
27
|
+
* - system tokens: `space`
|
|
28
|
+
* */
|
|
29
|
+
gap?: SystemPropValues['space'];
|
|
30
|
+
/**
|
|
31
|
+
* - sets [CSS column-gap property](https://developer.mozilla.org/en-US/docs/Web/CSS/column-gap)
|
|
32
|
+
* - system tokens: `space`
|
|
33
|
+
* */
|
|
34
|
+
columnGap?: SystemPropValues['space'];
|
|
35
|
+
/**
|
|
36
|
+
* - sets [CSS row-gap property](https://developer.mozilla.org/en-US/docs/Web/CSS/row-gap)
|
|
37
|
+
* - system tokens: `space`
|
|
38
|
+
* */
|
|
39
|
+
rowGap?: SystemPropValues['space'];
|
|
22
40
|
};
|
|
23
41
|
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
42
|
+
export const flexStyleFnConfigs: StyleFnConfig[] = [
|
|
43
|
+
{
|
|
44
|
+
name: 'alignContent',
|
|
45
|
+
properties: ['alignContent'],
|
|
46
|
+
system: 'none',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'alignItems',
|
|
50
|
+
properties: ['alignItems'],
|
|
51
|
+
system: 'none',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'display',
|
|
55
|
+
properties: ['display'],
|
|
56
|
+
system: 'none',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'flexDirection',
|
|
60
|
+
properties: ['flexDirection'],
|
|
61
|
+
system: 'none',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'flexWrap',
|
|
65
|
+
properties: ['flexWrap'],
|
|
66
|
+
system: 'none',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'justifyContent',
|
|
70
|
+
properties: ['justifyContent'],
|
|
71
|
+
system: 'none',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'justifyItems',
|
|
75
|
+
properties: ['justifyItems'],
|
|
76
|
+
system: 'none',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: 'gap',
|
|
80
|
+
properties: ['gap'],
|
|
81
|
+
system: 'space',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: 'columnGap',
|
|
85
|
+
properties: ['columnGap'],
|
|
86
|
+
system: 'space',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'rowGap',
|
|
90
|
+
properties: ['rowGap'],
|
|
91
|
+
system: 'space',
|
|
92
|
+
},
|
|
93
|
+
];
|
|
33
94
|
|
|
95
|
+
export const flexStyleFns = buildStyleFns(flexStyleFnConfigs);
|
|
34
96
|
/**
|
|
35
97
|
* A style prop function that takes component props and returns flexbox styles.
|
|
36
98
|
* If no `FlexStyleProps` are found, it returns an empty object.
|
|
37
99
|
*
|
|
38
100
|
* @example
|
|
39
|
-
*
|
|
101
|
+
* ```tsx
|
|
40
102
|
* const FlexExample = () => (
|
|
41
103
|
* <Flex justifyContent="center" alignItems="center">
|
|
42
104
|
* Hello, flex!
|
|
43
105
|
* </Flex>
|
|
44
106
|
* );
|
|
45
|
-
*
|
|
107
|
+
* ```
|
|
46
108
|
*/
|
|
47
|
-
export
|
|
48
|
-
const styles = {};
|
|
49
|
-
for (const key in props) {
|
|
50
|
-
if (key in flexProps) {
|
|
51
|
-
const attr = flexProps[key as keyof FlexStyleProps];
|
|
52
|
-
const value = props[key];
|
|
53
|
-
// @ts-ignore TS doesn't like adding a potentially unknown key to an object, but because we own this object, it's fine.
|
|
54
|
-
styles[attr] = value;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return styles;
|
|
58
|
-
}
|
|
109
|
+
export const flex = buildStylePropFn<FlexStyleProps>(flexStyleFns);
|
|
@@ -1,56 +1,74 @@
|
|
|
1
1
|
import {Property} from 'csstype';
|
|
2
|
+
import {buildStyleFns, buildStylePropFn, StyleFnConfig} from './buildStyleFns';
|
|
2
3
|
|
|
3
|
-
/** style props to for
|
|
4
|
+
/** style props to for CSS flex item properties */
|
|
4
5
|
export type FlexItemStyleProps = {
|
|
5
|
-
/** sets
|
|
6
|
-
flex?:
|
|
7
|
-
/** sets
|
|
8
|
-
flexGrow?:
|
|
9
|
-
/** sets
|
|
10
|
-
flexShrink?:
|
|
11
|
-
/** sets
|
|
12
|
-
flexBasis?:
|
|
13
|
-
/** sets
|
|
6
|
+
/** sets [CSS flex property](https://developer.mozilla.org/en-US/docs/Web/CSS/flex) */
|
|
7
|
+
flex?: Property.Flex;
|
|
8
|
+
/** sets [CSS flex-grow property](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-grow) */
|
|
9
|
+
flexGrow?: Property.FlexGrow;
|
|
10
|
+
/** sets [CSS flex-shrink property](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-shrink) */
|
|
11
|
+
flexShrink?: Property.FlexShrink;
|
|
12
|
+
/** sets [CSS flex-basis property](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-basis) */
|
|
13
|
+
flexBasis?: Property.FlexBasis;
|
|
14
|
+
/** sets [CSS justify-self property](https://developer.mozilla.org/en-US/docs/Web/CSS/justify-self) */
|
|
14
15
|
justifySelf?: Property.JustifySelf;
|
|
15
|
-
/** sets
|
|
16
|
+
/** sets [CSS align-self property](https://developer.mozilla.org/en-US/docs/Web/CSS/align-self) */
|
|
16
17
|
alignSelf?: Property.AlignSelf;
|
|
17
|
-
/** sets
|
|
18
|
+
/** sets [CSS order property](https://developer.mozilla.org/en-US/docs/Web/CSS/order) */
|
|
18
19
|
order?: Property.Order;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
export const flexItemStyleFnConfigs: StyleFnConfig[] = [
|
|
23
|
+
{
|
|
24
|
+
name: 'flex',
|
|
25
|
+
properties: ['flex'],
|
|
26
|
+
system: 'none',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'flexGrow',
|
|
30
|
+
properties: ['flexGrow'],
|
|
31
|
+
system: 'none',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'flexShrink',
|
|
35
|
+
properties: ['flexShrink'],
|
|
36
|
+
system: 'none',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'flexBasis',
|
|
40
|
+
properties: ['flexBasis'],
|
|
41
|
+
system: 'none',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'justifySelf',
|
|
45
|
+
properties: ['justifySelf'],
|
|
46
|
+
system: 'none',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'alignSelf',
|
|
50
|
+
properties: ['alignSelf'],
|
|
51
|
+
system: 'none',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'order',
|
|
55
|
+
properties: ['order'],
|
|
56
|
+
system: 'none',
|
|
57
|
+
},
|
|
58
|
+
];
|
|
31
59
|
|
|
60
|
+
export const flexItemStyleFns = buildStyleFns(flexItemStyleFnConfigs);
|
|
32
61
|
/**
|
|
33
62
|
* A style prop function that takes component props and returns flexbox item styles.
|
|
34
63
|
* If no `FlexItemStyleProps` are found, it returns an empty object.
|
|
35
64
|
*
|
|
36
65
|
* @example
|
|
37
|
-
*
|
|
66
|
+
* ```tsx
|
|
38
67
|
* const FlexItemExample = () => (
|
|
39
68
|
* <Box flex={1} flexBasis="auto" alignSelf={center}>
|
|
40
69
|
* Hello, flex item!
|
|
41
70
|
* </Box>
|
|
42
71
|
* );
|
|
43
|
-
*
|
|
72
|
+
* ```
|
|
44
73
|
*/
|
|
45
|
-
export
|
|
46
|
-
const styles = {};
|
|
47
|
-
for (const key in props) {
|
|
48
|
-
if (key in flexItemProps) {
|
|
49
|
-
const attr = flexItemProps[key as keyof FlexItemStyleProps];
|
|
50
|
-
const value = props[key];
|
|
51
|
-
// @ts-ignore TS doesn't like adding a potentially unknown key to an object, but because we own this object, it's fine.
|
|
52
|
-
styles[attr] = value;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return styles;
|
|
56
|
-
}
|
|
74
|
+
export const flexItem = buildStylePropFn<FlexItemStyleProps>(flexItemStyleFns);
|