@workday/canvas-kit-react 8.0.0-alpha.204-next.4 → 8.0.0-alpha.216-next.4

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.
Files changed (230) hide show
  1. package/common/lib/utils/elements.ts +4 -4
  2. package/dist/commonjs/card/lib/Card.d.ts +1 -1
  3. package/dist/commonjs/card/lib/CardBody.d.ts +1 -1
  4. package/dist/commonjs/card/lib/CardBody.d.ts.map +1 -1
  5. package/dist/commonjs/common/lib/utils/elements.d.ts +1 -1
  6. package/dist/commonjs/common/lib/utils/elements.d.ts.map +1 -1
  7. package/dist/commonjs/common/lib/utils/elements.js +3 -3
  8. package/dist/commonjs/dialog/lib/Dialog.d.ts +1 -1
  9. package/dist/commonjs/icon/lib/SystemIcon.d.ts +1 -1
  10. package/dist/commonjs/icon/lib/SystemIcon.d.ts.map +1 -1
  11. package/dist/commonjs/layout/index.d.ts +8 -4
  12. package/dist/commonjs/layout/index.d.ts.map +1 -1
  13. package/dist/commonjs/layout/index.js +10 -2
  14. package/dist/commonjs/layout/lib/Box.d.ts +6 -4
  15. package/dist/commonjs/layout/lib/Box.d.ts.map +1 -1
  16. package/dist/commonjs/layout/lib/Box.js +8 -9
  17. package/dist/commonjs/layout/lib/Flex.d.ts +5 -2
  18. package/dist/commonjs/layout/lib/Flex.d.ts.map +1 -1
  19. package/dist/commonjs/layout/lib/Flex.js +5 -1
  20. package/dist/commonjs/layout/lib/Grid.d.ts +5 -6
  21. package/dist/commonjs/layout/lib/Grid.d.ts.map +1 -1
  22. package/dist/commonjs/layout/lib/Grid.js +2 -2
  23. package/dist/commonjs/layout/lib/Stack.d.ts +4 -4
  24. package/dist/commonjs/layout/lib/utils/background.d.ts +44 -0
  25. package/dist/commonjs/layout/lib/utils/background.d.ts.map +1 -0
  26. package/dist/commonjs/layout/lib/utils/background.js +57 -0
  27. package/dist/commonjs/layout/lib/utils/border/color.d.ts +47 -0
  28. package/dist/commonjs/layout/lib/utils/border/color.d.ts.map +1 -0
  29. package/dist/commonjs/layout/lib/utils/border/color.js +42 -0
  30. package/dist/commonjs/layout/lib/utils/border/index.d.ts +26 -0
  31. package/dist/commonjs/layout/lib/utils/border/index.d.ts.map +1 -0
  32. package/dist/commonjs/layout/lib/utils/border/index.js +46 -0
  33. package/dist/commonjs/layout/lib/utils/border/lineStyle.d.ts +38 -0
  34. package/dist/commonjs/layout/lib/utils/border/lineStyle.d.ts.map +1 -0
  35. package/dist/commonjs/layout/lib/utils/border/lineStyle.js +52 -0
  36. package/dist/commonjs/layout/lib/utils/border/radius.d.ts +33 -0
  37. package/dist/commonjs/layout/lib/utils/border/radius.d.ts.map +1 -0
  38. package/dist/commonjs/layout/lib/utils/border/radius.js +32 -0
  39. package/dist/commonjs/layout/lib/utils/border/shorthand.d.ts +34 -0
  40. package/dist/commonjs/layout/lib/utils/border/shorthand.d.ts.map +1 -0
  41. package/dist/commonjs/layout/lib/utils/border/shorthand.js +42 -0
  42. package/dist/commonjs/layout/lib/utils/border/width.d.ts +34 -0
  43. package/dist/commonjs/layout/lib/utils/border/width.d.ts.map +1 -0
  44. package/dist/commonjs/layout/lib/utils/border/width.js +42 -0
  45. package/dist/commonjs/layout/lib/utils/buildStyleFns.d.ts +12 -0
  46. package/dist/commonjs/layout/lib/utils/buildStyleFns.d.ts.map +1 -0
  47. package/dist/commonjs/layout/lib/utils/buildStyleFns.js +90 -0
  48. package/dist/commonjs/layout/lib/utils/color.d.ts +23 -16
  49. package/dist/commonjs/layout/lib/utils/color.d.ts.map +1 -1
  50. package/dist/commonjs/layout/lib/utils/color.js +25 -49
  51. package/dist/commonjs/layout/lib/utils/depth.d.ts +17 -11
  52. package/dist/commonjs/layout/lib/utils/depth.d.ts.map +1 -1
  53. package/dist/commonjs/layout/lib/utils/depth.js +20 -20
  54. package/dist/commonjs/layout/lib/utils/flex.d.ts +31 -12
  55. package/dist/commonjs/layout/lib/utils/flex.d.ts.map +1 -1
  56. package/dist/commonjs/layout/lib/utils/flex.js +58 -25
  57. package/dist/commonjs/layout/lib/utils/flexItem.d.ts +18 -15
  58. package/dist/commonjs/layout/lib/utils/flexItem.d.ts.map +1 -1
  59. package/dist/commonjs/layout/lib/utils/flexItem.js +43 -26
  60. package/dist/commonjs/layout/lib/utils/grid.d.ts +40 -35
  61. package/dist/commonjs/layout/lib/utils/grid.d.ts.map +1 -1
  62. package/dist/commonjs/layout/lib/utils/grid.js +99 -72
  63. package/dist/commonjs/layout/lib/utils/gridItem.d.ts +17 -14
  64. package/dist/commonjs/layout/lib/utils/gridItem.d.ts.map +1 -1
  65. package/dist/commonjs/layout/lib/utils/gridItem.js +58 -30
  66. package/dist/commonjs/layout/lib/utils/layout.d.ts +47 -25
  67. package/dist/commonjs/layout/lib/utils/layout.d.ts.map +1 -1
  68. package/dist/commonjs/layout/lib/utils/layout.js +71 -33
  69. package/dist/commonjs/layout/lib/utils/other.d.ts +44 -2
  70. package/dist/commonjs/layout/lib/utils/other.d.ts.map +1 -1
  71. package/dist/commonjs/layout/lib/utils/other.js +101 -17
  72. package/dist/commonjs/layout/lib/utils/position.d.ts +37 -20
  73. package/dist/commonjs/layout/lib/utils/position.d.ts.map +1 -1
  74. package/dist/commonjs/layout/lib/utils/position.js +49 -66
  75. package/dist/commonjs/layout/lib/utils/space.d.ts +107 -51
  76. package/dist/commonjs/layout/lib/utils/space.d.ts.map +1 -1
  77. package/dist/commonjs/layout/lib/utils/space.js +98 -148
  78. package/dist/commonjs/layout/lib/utils/stack.d.ts +3 -6
  79. package/dist/commonjs/layout/lib/utils/stack.d.ts.map +1 -1
  80. package/dist/commonjs/layout/lib/utils/stack.js +13 -39
  81. package/dist/commonjs/layout/lib/utils/systemProps.d.ts +31 -0
  82. package/dist/commonjs/layout/lib/utils/systemProps.d.ts.map +1 -0
  83. package/dist/commonjs/layout/lib/utils/systemProps.js +2 -0
  84. package/dist/commonjs/layout/lib/utils/text.d.ts +33 -15
  85. package/dist/commonjs/layout/lib/utils/text.d.ts.map +1 -1
  86. package/dist/commonjs/layout/lib/utils/text.js +74 -38
  87. package/dist/commonjs/modal/lib/Modal.d.ts +1 -1
  88. package/dist/commonjs/popup/lib/Popup.d.ts +1 -1
  89. package/dist/commonjs/popup/lib/PopupBody.d.ts +1 -1
  90. package/dist/commonjs/popup/lib/hooks/useReturnFocus.d.ts.map +1 -1
  91. package/dist/commonjs/popup/lib/hooks/useReturnFocus.js +102 -2
  92. package/dist/commonjs/tabs/lib/TabsItem.d.ts +1 -1
  93. package/dist/commonjs/tokens/lib/colors.types.d.ts +4 -6
  94. package/dist/commonjs/tokens/lib/colors.types.d.ts.map +1 -1
  95. package/dist/es6/card/lib/Card.d.ts +1 -1
  96. package/dist/es6/card/lib/CardBody.d.ts +1 -1
  97. package/dist/es6/card/lib/CardBody.d.ts.map +1 -1
  98. package/dist/es6/common/lib/utils/elements.d.ts +1 -1
  99. package/dist/es6/common/lib/utils/elements.d.ts.map +1 -1
  100. package/dist/es6/common/lib/utils/elements.js +3 -3
  101. package/dist/es6/dialog/lib/Dialog.d.ts +1 -1
  102. package/dist/es6/icon/lib/SystemIcon.d.ts +1 -1
  103. package/dist/es6/icon/lib/SystemIcon.d.ts.map +1 -1
  104. package/dist/es6/layout/index.d.ts +8 -4
  105. package/dist/es6/layout/index.d.ts.map +1 -1
  106. package/dist/es6/layout/index.js +7 -1
  107. package/dist/es6/layout/lib/Box.d.ts +6 -4
  108. package/dist/es6/layout/lib/Box.d.ts.map +1 -1
  109. package/dist/es6/layout/lib/Box.js +8 -9
  110. package/dist/es6/layout/lib/Flex.d.ts +5 -2
  111. package/dist/es6/layout/lib/Flex.d.ts.map +1 -1
  112. package/dist/es6/layout/lib/Flex.js +5 -1
  113. package/dist/es6/layout/lib/Grid.d.ts +5 -6
  114. package/dist/es6/layout/lib/Grid.d.ts.map +1 -1
  115. package/dist/es6/layout/lib/Grid.js +2 -2
  116. package/dist/es6/layout/lib/Stack.d.ts +4 -4
  117. package/dist/es6/layout/lib/utils/background.d.ts +44 -0
  118. package/dist/es6/layout/lib/utils/background.d.ts.map +1 -0
  119. package/dist/es6/layout/lib/utils/background.js +54 -0
  120. package/dist/es6/layout/lib/utils/border/color.d.ts +47 -0
  121. package/dist/es6/layout/lib/utils/border/color.d.ts.map +1 -0
  122. package/dist/es6/layout/lib/utils/border/color.js +39 -0
  123. package/dist/es6/layout/lib/utils/border/index.d.ts +26 -0
  124. package/dist/es6/layout/lib/utils/border/index.d.ts.map +1 -0
  125. package/dist/es6/layout/lib/utils/border/index.js +43 -0
  126. package/dist/es6/layout/lib/utils/border/lineStyle.d.ts +38 -0
  127. package/dist/es6/layout/lib/utils/border/lineStyle.d.ts.map +1 -0
  128. package/dist/es6/layout/lib/utils/border/lineStyle.js +49 -0
  129. package/dist/es6/layout/lib/utils/border/radius.d.ts +33 -0
  130. package/dist/es6/layout/lib/utils/border/radius.d.ts.map +1 -0
  131. package/dist/es6/layout/lib/utils/border/radius.js +29 -0
  132. package/dist/es6/layout/lib/utils/border/shorthand.d.ts +34 -0
  133. package/dist/es6/layout/lib/utils/border/shorthand.d.ts.map +1 -0
  134. package/dist/es6/layout/lib/utils/border/shorthand.js +39 -0
  135. package/dist/es6/layout/lib/utils/border/width.d.ts +34 -0
  136. package/dist/es6/layout/lib/utils/border/width.d.ts.map +1 -0
  137. package/dist/es6/layout/lib/utils/border/width.js +39 -0
  138. package/dist/es6/layout/lib/utils/buildStyleFns.d.ts +12 -0
  139. package/dist/es6/layout/lib/utils/buildStyleFns.d.ts.map +1 -0
  140. package/dist/es6/layout/lib/utils/buildStyleFns.js +85 -0
  141. package/dist/es6/layout/lib/utils/color.d.ts +23 -16
  142. package/dist/es6/layout/lib/utils/color.d.ts.map +1 -1
  143. package/dist/es6/layout/lib/utils/color.js +24 -47
  144. package/dist/es6/layout/lib/utils/depth.d.ts +17 -11
  145. package/dist/es6/layout/lib/utils/depth.d.ts.map +1 -1
  146. package/dist/es6/layout/lib/utils/depth.js +19 -18
  147. package/dist/es6/layout/lib/utils/flex.d.ts +31 -12
  148. package/dist/es6/layout/lib/utils/flex.d.ts.map +1 -1
  149. package/dist/es6/layout/lib/utils/flex.js +57 -23
  150. package/dist/es6/layout/lib/utils/flexItem.d.ts +18 -15
  151. package/dist/es6/layout/lib/utils/flexItem.d.ts.map +1 -1
  152. package/dist/es6/layout/lib/utils/flexItem.js +42 -24
  153. package/dist/es6/layout/lib/utils/grid.d.ts +40 -35
  154. package/dist/es6/layout/lib/utils/grid.d.ts.map +1 -1
  155. package/dist/es6/layout/lib/utils/grid.js +98 -70
  156. package/dist/es6/layout/lib/utils/gridItem.d.ts +17 -14
  157. package/dist/es6/layout/lib/utils/gridItem.d.ts.map +1 -1
  158. package/dist/es6/layout/lib/utils/gridItem.js +57 -28
  159. package/dist/es6/layout/lib/utils/layout.d.ts +47 -25
  160. package/dist/es6/layout/lib/utils/layout.d.ts.map +1 -1
  161. package/dist/es6/layout/lib/utils/layout.js +70 -31
  162. package/dist/es6/layout/lib/utils/other.d.ts +44 -2
  163. package/dist/es6/layout/lib/utils/other.d.ts.map +1 -1
  164. package/dist/es6/layout/lib/utils/other.js +100 -15
  165. package/dist/es6/layout/lib/utils/position.d.ts +37 -20
  166. package/dist/es6/layout/lib/utils/position.d.ts.map +1 -1
  167. package/dist/es6/layout/lib/utils/position.js +48 -64
  168. package/dist/es6/layout/lib/utils/space.d.ts +107 -51
  169. package/dist/es6/layout/lib/utils/space.d.ts.map +1 -1
  170. package/dist/es6/layout/lib/utils/space.js +97 -146
  171. package/dist/es6/layout/lib/utils/stack.d.ts +3 -6
  172. package/dist/es6/layout/lib/utils/stack.d.ts.map +1 -1
  173. package/dist/es6/layout/lib/utils/stack.js +13 -39
  174. package/dist/es6/layout/lib/utils/systemProps.d.ts +31 -0
  175. package/dist/es6/layout/lib/utils/systemProps.d.ts.map +1 -0
  176. package/dist/es6/layout/lib/utils/systemProps.js +1 -0
  177. package/dist/es6/layout/lib/utils/text.d.ts +33 -15
  178. package/dist/es6/layout/lib/utils/text.d.ts.map +1 -1
  179. package/dist/es6/layout/lib/utils/text.js +73 -36
  180. package/dist/es6/modal/lib/Modal.d.ts +1 -1
  181. package/dist/es6/popup/lib/Popup.d.ts +1 -1
  182. package/dist/es6/popup/lib/PopupBody.d.ts +1 -1
  183. package/dist/es6/popup/lib/hooks/useReturnFocus.d.ts.map +1 -1
  184. package/dist/es6/popup/lib/hooks/useReturnFocus.js +103 -3
  185. package/dist/es6/tabs/lib/TabsItem.d.ts +1 -1
  186. package/dist/es6/tokens/lib/colors.types.d.ts +4 -6
  187. package/dist/es6/tokens/lib/colors.types.d.ts.map +1 -1
  188. package/icon/lib/SystemIcon.tsx +1 -1
  189. package/layout/index.ts +8 -4
  190. package/layout/lib/Box.tsx +10 -36
  191. package/layout/lib/Flex.tsx +5 -1
  192. package/layout/lib/Grid.tsx +3 -4
  193. package/layout/lib/utils/background.ts +83 -0
  194. package/layout/lib/utils/border/color.ts +85 -0
  195. package/layout/lib/utils/border/index.ts +49 -0
  196. package/layout/lib/utils/border/lineStyle.ts +87 -0
  197. package/layout/lib/utils/border/radius.ts +61 -0
  198. package/layout/lib/utils/border/shorthand.ts +73 -0
  199. package/layout/lib/utils/border/width.ts +73 -0
  200. package/layout/lib/utils/buildStyleFns.ts +117 -0
  201. package/layout/lib/utils/color.ts +40 -55
  202. package/layout/lib/utils/depth.ts +28 -24
  203. package/layout/lib/utils/flex.ts +83 -32
  204. package/layout/lib/utils/flexItem.ts +54 -36
  205. package/layout/lib/utils/grid.ts +131 -94
  206. package/layout/lib/utils/gridItem.ts +69 -41
  207. package/layout/lib/utils/layout.ts +109 -50
  208. package/layout/lib/utils/other.ts +142 -15
  209. package/layout/lib/utils/position.ts +79 -73
  210. package/layout/lib/utils/space.ts +202 -196
  211. package/layout/lib/utils/stack.ts +19 -45
  212. package/layout/lib/utils/systemProps.ts +46 -0
  213. package/layout/lib/utils/text.ts +99 -34
  214. package/package.json +3 -3
  215. package/popup/lib/hooks/useReturnFocus.tsx +117 -4
  216. package/tokens/lib/colors.types.ts +4 -7
  217. package/dist/commonjs/layout/lib/utils/border.d.ts +0 -103
  218. package/dist/commonjs/layout/lib/utils/border.d.ts.map +0 -1
  219. package/dist/commonjs/layout/lib/utils/border.js +0 -153
  220. package/dist/commonjs/layout/lib/utils/font.d.ts +0 -29
  221. package/dist/commonjs/layout/lib/utils/font.d.ts.map +0 -1
  222. package/dist/commonjs/layout/lib/utils/font.js +0 -57
  223. package/dist/es6/layout/lib/utils/border.d.ts +0 -103
  224. package/dist/es6/layout/lib/utils/border.d.ts.map +0 -1
  225. package/dist/es6/layout/lib/utils/border.js +0 -149
  226. package/dist/es6/layout/lib/utils/font.d.ts +0 -29
  227. package/dist/es6/layout/lib/utils/font.d.ts.map +0 -1
  228. package/dist/es6/layout/lib/utils/font.js +0 -53
  229. package/layout/lib/utils/border.ts +0 -263
  230. package/layout/lib/utils/font.ts +0 -67
@@ -1,67 +1,52 @@
1
- // type changes no need
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
- export type ColorTokens = typeof colorTokens;
3
+ import {buildStyleFns, buildStylePropFn, StyleFnConfig} from './buildStyleFns';
4
+ import {SystemPropValues} from './systemProps';
9
5
 
10
- /** style props to for color properties */
6
+ /** style props to set CSS color properties */
11
7
  export type ColorStyleProps = {
12
- /** sets `background` property */
13
- background?: CanvasColor | (string & {});
14
- /** sets `background-color` property */
15
- backgroundColor?: CanvasColor | (string & {});
16
- /** sets `background-image` property */
17
- backgroundImage?: string;
18
- /** sets `color` property */
19
- color?: CanvasColor | (string & {});
20
- };
21
-
22
- const getBackground = (value: CanvasColor | string) => ({
23
- background: colorTokens[value] || value,
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 components props and returns color styles from canvas token values.
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
- * // You'll most likely use `color` with low-level, styled components
46
+ * ```tsx
51
47
  * const BoxExample = () => (
52
- * <Box backgroundColor="blueberry500" color="frenchVanilla100">Hello, colors!</Box>
48
+ * <Box color="frenchVanilla100" opacity={0.6}>Hello, colors!</Box>
53
49
  * );
54
- *
50
+ * ```
55
51
  */
56
- export function color<P extends ColorStyleProps>(props: P) {
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 {depth as depthTokens} from '@workday/canvas-kit-react/tokens';
2
-
3
- export type DepthTokens = typeof depthTokens;
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 depth styles (box-shadow & border) */
10
- depth?: DepthTokenKeys;
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 depthProps = {
14
- depth: (token: DepthTokenKeys) => depthTokens[token],
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 components props and returns depth styles from canvas token values.
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
- * // You'll mostly likely use `depth` with low-level, styled components
23
- * const BoxExample = () => (
35
+ * ```tsx
36
+ * const DepthExample = () => (
24
37
  * <Box depth={3}>Hello, box shadows!</Box>
25
38
  * );
26
- *
39
+ * ```
27
40
  */
28
- export function depth<P extends DepthStyleProps>(props: P): DepthTokenValues {
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);
@@ -1,58 +1,109 @@
1
1
  import {Property} from 'csstype';
2
2
 
3
- /** style props to for flexbox container properties */
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 `align-items` property */
8
+ /** sets [CSS align-items property](https://developer.mozilla.org/en-US/docs/Web/CSS/align-items) */
6
9
  alignItems?: Property.AlignItems;
7
- /** sets `align-content` property */
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 `display` property
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 `justify-items` property */
17
+ /** sets [CSS justify-items property](https://developer.mozilla.org/en-US/docs/Web/CSS/justify-items) */
15
18
  justifyItems?: Property.JustifyItems;
16
- /** sets `justify-content` property */
19
+ /** sets [CSS justify-content property](https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content) */
17
20
  justifyContent?: Property.JustifyContent;
18
- /** sets `flex-wrap` property */
21
+ /** sets [CSS flex-wrap property](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap) */
19
22
  flexWrap?: Property.FlexWrap;
20
- /** sets `flex-direction` property */
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 flexProps = {
25
- alignContent: 'alignContent',
26
- alignItems: 'alignItems',
27
- display: 'display',
28
- flexDirection: 'flexDirection',
29
- flexWrap: 'flexWrap',
30
- justifyContent: 'justifyContent',
31
- justifyItems: 'justifyItems',
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
- * // You'll most likely use `flex` with low-level, styled components
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 function flex<P extends FlexStyleProps>(props: P) {
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 flexbox item properties */
4
+ /** style props to for CSS flex item properties */
4
5
  export type FlexItemStyleProps = {
5
- /** sets `flex` property */
6
- flex?: number | string;
7
- /** sets `flex-grow` property */
8
- flexGrow?: number | string;
9
- /** sets `flex-shrink` property */
10
- flexShrink?: number | string;
11
- /** sets `flex-basis` property */
12
- flexBasis?: number | string;
13
- /** sets `justify-self` property */
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 `align-self` property */
16
+ /** sets [CSS align-self property](https://developer.mozilla.org/en-US/docs/Web/CSS/align-self) */
16
17
  alignSelf?: Property.AlignSelf;
17
- /** sets `order` property */
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
- /** style props to for flexbox item properties */
22
- const flexItemProps = {
23
- flex: 'flex',
24
- flexGrow: 'flexGrow',
25
- flexShrink: 'flexShrink',
26
- flexBasis: 'flexBasis',
27
- justifySelf: 'justifySelf',
28
- alignSelf: 'alignSelf',
29
- order: 'order',
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
- * // You'll most likely use `flexItem` with low-level, styled components
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 function flexItem<P extends FlexItemStyleProps>(props: P) {
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);