@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.
Files changed (298) hide show
  1. package/common/lib/theming/index.ts +1 -1
  2. package/common/lib/theming/styled.ts +6 -3
  3. package/common/lib/utils/elements.ts +4 -4
  4. package/common/lib/utils/index.ts +0 -1
  5. package/dist/commonjs/card/lib/Card.d.ts +1 -1
  6. package/dist/commonjs/card/lib/CardBody.d.ts +1 -1
  7. package/dist/commonjs/card/lib/CardBody.d.ts.map +1 -1
  8. package/dist/commonjs/common/lib/theming/index.d.ts +1 -1
  9. package/dist/commonjs/common/lib/theming/index.d.ts.map +1 -1
  10. package/dist/commonjs/common/lib/theming/styled.d.ts +2 -0
  11. package/dist/commonjs/common/lib/theming/styled.d.ts.map +1 -1
  12. package/dist/commonjs/common/lib/theming/styled.js +1 -2
  13. package/dist/commonjs/common/lib/utils/elements.d.ts +1 -1
  14. package/dist/commonjs/common/lib/utils/elements.d.ts.map +1 -1
  15. package/dist/commonjs/common/lib/utils/elements.js +3 -3
  16. package/dist/commonjs/common/lib/utils/index.d.ts +0 -1
  17. package/dist/commonjs/common/lib/utils/index.d.ts.map +1 -1
  18. package/dist/commonjs/common/lib/utils/index.js +0 -1
  19. package/dist/commonjs/dialog/lib/Dialog.d.ts +1 -1
  20. package/dist/commonjs/icon/lib/SystemIcon.d.ts +1 -1
  21. package/dist/commonjs/icon/lib/SystemIcon.d.ts.map +1 -1
  22. package/dist/commonjs/index.d.ts +1 -0
  23. package/dist/commonjs/index.d.ts.map +1 -1
  24. package/dist/commonjs/index.js +1 -0
  25. package/dist/commonjs/layout/index.d.ts +8 -4
  26. package/dist/commonjs/layout/index.d.ts.map +1 -1
  27. package/dist/commonjs/layout/index.js +10 -2
  28. package/dist/commonjs/layout/lib/Box.d.ts +6 -4
  29. package/dist/commonjs/layout/lib/Box.d.ts.map +1 -1
  30. package/dist/commonjs/layout/lib/Box.js +8 -9
  31. package/dist/commonjs/layout/lib/Flex.d.ts +5 -2
  32. package/dist/commonjs/layout/lib/Flex.d.ts.map +1 -1
  33. package/dist/commonjs/layout/lib/Flex.js +5 -1
  34. package/dist/commonjs/layout/lib/Grid.d.ts +5 -6
  35. package/dist/commonjs/layout/lib/Grid.d.ts.map +1 -1
  36. package/dist/commonjs/layout/lib/Grid.js +2 -2
  37. package/dist/commonjs/layout/lib/Stack.d.ts +4 -4
  38. package/dist/commonjs/layout/lib/utils/background.d.ts +44 -0
  39. package/dist/commonjs/layout/lib/utils/background.d.ts.map +1 -0
  40. package/dist/commonjs/layout/lib/utils/background.js +57 -0
  41. package/dist/commonjs/layout/lib/utils/border/color.d.ts +47 -0
  42. package/dist/commonjs/layout/lib/utils/border/color.d.ts.map +1 -0
  43. package/dist/commonjs/layout/lib/utils/border/color.js +42 -0
  44. package/dist/commonjs/layout/lib/utils/border/index.d.ts +26 -0
  45. package/dist/commonjs/layout/lib/utils/border/index.d.ts.map +1 -0
  46. package/dist/commonjs/layout/lib/utils/border/index.js +46 -0
  47. package/dist/commonjs/layout/lib/utils/border/lineStyle.d.ts +38 -0
  48. package/dist/commonjs/layout/lib/utils/border/lineStyle.d.ts.map +1 -0
  49. package/dist/commonjs/layout/lib/utils/border/lineStyle.js +52 -0
  50. package/dist/commonjs/layout/lib/utils/border/radius.d.ts +33 -0
  51. package/dist/commonjs/layout/lib/utils/border/radius.d.ts.map +1 -0
  52. package/dist/commonjs/layout/lib/utils/border/radius.js +32 -0
  53. package/dist/commonjs/layout/lib/utils/border/shorthand.d.ts +34 -0
  54. package/dist/commonjs/layout/lib/utils/border/shorthand.d.ts.map +1 -0
  55. package/dist/commonjs/layout/lib/utils/border/shorthand.js +42 -0
  56. package/dist/commonjs/layout/lib/utils/border/width.d.ts +34 -0
  57. package/dist/commonjs/layout/lib/utils/border/width.d.ts.map +1 -0
  58. package/dist/commonjs/layout/lib/utils/border/width.js +42 -0
  59. package/dist/commonjs/layout/lib/utils/buildStyleFns.d.ts +12 -0
  60. package/dist/commonjs/layout/lib/utils/buildStyleFns.d.ts.map +1 -0
  61. package/dist/commonjs/layout/lib/utils/buildStyleFns.js +90 -0
  62. package/dist/commonjs/layout/lib/utils/color.d.ts +23 -16
  63. package/dist/commonjs/layout/lib/utils/color.d.ts.map +1 -1
  64. package/dist/commonjs/layout/lib/utils/color.js +25 -49
  65. package/dist/commonjs/layout/lib/utils/depth.d.ts +17 -11
  66. package/dist/commonjs/layout/lib/utils/depth.d.ts.map +1 -1
  67. package/dist/commonjs/layout/lib/utils/depth.js +20 -20
  68. package/dist/commonjs/layout/lib/utils/flex.d.ts +31 -12
  69. package/dist/commonjs/layout/lib/utils/flex.d.ts.map +1 -1
  70. package/dist/commonjs/layout/lib/utils/flex.js +58 -25
  71. package/dist/commonjs/layout/lib/utils/flexItem.d.ts +18 -15
  72. package/dist/commonjs/layout/lib/utils/flexItem.d.ts.map +1 -1
  73. package/dist/commonjs/layout/lib/utils/flexItem.js +43 -26
  74. package/dist/commonjs/layout/lib/utils/grid.d.ts +40 -35
  75. package/dist/commonjs/layout/lib/utils/grid.d.ts.map +1 -1
  76. package/dist/commonjs/layout/lib/utils/grid.js +99 -72
  77. package/dist/commonjs/layout/lib/utils/gridItem.d.ts +17 -14
  78. package/dist/commonjs/layout/lib/utils/gridItem.d.ts.map +1 -1
  79. package/dist/commonjs/layout/lib/utils/gridItem.js +58 -30
  80. package/dist/commonjs/layout/lib/utils/layout.d.ts +47 -25
  81. package/dist/commonjs/layout/lib/utils/layout.d.ts.map +1 -1
  82. package/dist/commonjs/layout/lib/utils/layout.js +71 -33
  83. package/dist/commonjs/layout/lib/utils/other.d.ts +44 -2
  84. package/dist/commonjs/layout/lib/utils/other.d.ts.map +1 -1
  85. package/dist/commonjs/layout/lib/utils/other.js +101 -17
  86. package/dist/commonjs/layout/lib/utils/position.d.ts +37 -20
  87. package/dist/commonjs/layout/lib/utils/position.d.ts.map +1 -1
  88. package/dist/commonjs/layout/lib/utils/position.js +49 -66
  89. package/dist/commonjs/layout/lib/utils/space.d.ts +107 -51
  90. package/dist/commonjs/layout/lib/utils/space.d.ts.map +1 -1
  91. package/dist/commonjs/layout/lib/utils/space.js +98 -148
  92. package/dist/commonjs/layout/lib/utils/stack.d.ts +3 -6
  93. package/dist/commonjs/layout/lib/utils/stack.d.ts.map +1 -1
  94. package/dist/commonjs/layout/lib/utils/stack.js +13 -39
  95. package/dist/commonjs/layout/lib/utils/systemProps.d.ts +31 -0
  96. package/dist/commonjs/layout/lib/utils/systemProps.d.ts.map +1 -0
  97. package/dist/commonjs/layout/lib/utils/systemProps.js +2 -0
  98. package/dist/commonjs/layout/lib/utils/text.d.ts +33 -15
  99. package/dist/commonjs/layout/lib/utils/text.d.ts.map +1 -1
  100. package/dist/commonjs/layout/lib/utils/text.js +74 -38
  101. package/dist/commonjs/modal/lib/Modal.d.ts +1 -1
  102. package/dist/commonjs/popup/lib/Popup.d.ts +1 -1
  103. package/dist/commonjs/popup/lib/PopupBody.d.ts +1 -1
  104. package/dist/commonjs/popup/lib/hooks/useReturnFocus.d.ts.map +1 -1
  105. package/dist/commonjs/popup/lib/hooks/useReturnFocus.js +72 -7
  106. package/dist/commonjs/tabs/lib/TabsItem.d.ts +1 -1
  107. package/dist/commonjs/testing/index.d.ts +5 -0
  108. package/dist/commonjs/testing/index.d.ts.map +1 -0
  109. package/dist/commonjs/testing/index.js +16 -0
  110. package/dist/commonjs/testing/lib/ComponentStatesTable.d.ts +26 -0
  111. package/dist/commonjs/testing/lib/ComponentStatesTable.d.ts.map +1 -0
  112. package/dist/commonjs/testing/lib/ComponentStatesTable.js +48 -0
  113. package/dist/commonjs/testing/lib/StaticStates.d.ts +7 -0
  114. package/dist/commonjs/testing/lib/StaticStates.d.ts.map +1 -0
  115. package/dist/commonjs/{common/lib/utils → testing/lib}/StaticStates.js +1 -1
  116. package/dist/commonjs/testing/lib/permutateProps.d.ts +5 -0
  117. package/dist/commonjs/testing/lib/permutateProps.d.ts.map +1 -0
  118. package/dist/commonjs/testing/lib/permutateProps.js +47 -0
  119. package/dist/commonjs/testing/lib/propTypes.d.ts +15 -0
  120. package/dist/commonjs/testing/lib/propTypes.d.ts.map +1 -0
  121. package/dist/commonjs/testing/lib/propTypes.js +2 -0
  122. package/dist/commonjs/tokens/lib/colors.types.d.ts +4 -6
  123. package/dist/commonjs/tokens/lib/colors.types.d.ts.map +1 -1
  124. package/dist/es6/card/lib/Card.d.ts +1 -1
  125. package/dist/es6/card/lib/CardBody.d.ts +1 -1
  126. package/dist/es6/card/lib/CardBody.d.ts.map +1 -1
  127. package/dist/es6/common/lib/theming/index.d.ts +1 -1
  128. package/dist/es6/common/lib/theming/index.d.ts.map +1 -1
  129. package/dist/es6/common/lib/theming/styled.d.ts +2 -0
  130. package/dist/es6/common/lib/theming/styled.d.ts.map +1 -1
  131. package/dist/es6/common/lib/theming/styled.js +1 -2
  132. package/dist/es6/common/lib/utils/elements.d.ts +1 -1
  133. package/dist/es6/common/lib/utils/elements.d.ts.map +1 -1
  134. package/dist/es6/common/lib/utils/elements.js +3 -3
  135. package/dist/es6/common/lib/utils/index.d.ts +0 -1
  136. package/dist/es6/common/lib/utils/index.d.ts.map +1 -1
  137. package/dist/es6/common/lib/utils/index.js +0 -1
  138. package/dist/es6/dialog/lib/Dialog.d.ts +1 -1
  139. package/dist/es6/icon/lib/SystemIcon.d.ts +1 -1
  140. package/dist/es6/icon/lib/SystemIcon.d.ts.map +1 -1
  141. package/dist/es6/index.d.ts +1 -0
  142. package/dist/es6/index.d.ts.map +1 -1
  143. package/dist/es6/index.js +1 -0
  144. package/dist/es6/layout/index.d.ts +8 -4
  145. package/dist/es6/layout/index.d.ts.map +1 -1
  146. package/dist/es6/layout/index.js +7 -1
  147. package/dist/es6/layout/lib/Box.d.ts +6 -4
  148. package/dist/es6/layout/lib/Box.d.ts.map +1 -1
  149. package/dist/es6/layout/lib/Box.js +8 -9
  150. package/dist/es6/layout/lib/Flex.d.ts +5 -2
  151. package/dist/es6/layout/lib/Flex.d.ts.map +1 -1
  152. package/dist/es6/layout/lib/Flex.js +5 -1
  153. package/dist/es6/layout/lib/Grid.d.ts +5 -6
  154. package/dist/es6/layout/lib/Grid.d.ts.map +1 -1
  155. package/dist/es6/layout/lib/Grid.js +2 -2
  156. package/dist/es6/layout/lib/Stack.d.ts +4 -4
  157. package/dist/es6/layout/lib/utils/background.d.ts +44 -0
  158. package/dist/es6/layout/lib/utils/background.d.ts.map +1 -0
  159. package/dist/es6/layout/lib/utils/background.js +54 -0
  160. package/dist/es6/layout/lib/utils/border/color.d.ts +47 -0
  161. package/dist/es6/layout/lib/utils/border/color.d.ts.map +1 -0
  162. package/dist/es6/layout/lib/utils/border/color.js +39 -0
  163. package/dist/es6/layout/lib/utils/border/index.d.ts +26 -0
  164. package/dist/es6/layout/lib/utils/border/index.d.ts.map +1 -0
  165. package/dist/es6/layout/lib/utils/border/index.js +43 -0
  166. package/dist/es6/layout/lib/utils/border/lineStyle.d.ts +38 -0
  167. package/dist/es6/layout/lib/utils/border/lineStyle.d.ts.map +1 -0
  168. package/dist/es6/layout/lib/utils/border/lineStyle.js +49 -0
  169. package/dist/es6/layout/lib/utils/border/radius.d.ts +33 -0
  170. package/dist/es6/layout/lib/utils/border/radius.d.ts.map +1 -0
  171. package/dist/es6/layout/lib/utils/border/radius.js +29 -0
  172. package/dist/es6/layout/lib/utils/border/shorthand.d.ts +34 -0
  173. package/dist/es6/layout/lib/utils/border/shorthand.d.ts.map +1 -0
  174. package/dist/es6/layout/lib/utils/border/shorthand.js +39 -0
  175. package/dist/es6/layout/lib/utils/border/width.d.ts +34 -0
  176. package/dist/es6/layout/lib/utils/border/width.d.ts.map +1 -0
  177. package/dist/es6/layout/lib/utils/border/width.js +39 -0
  178. package/dist/es6/layout/lib/utils/buildStyleFns.d.ts +12 -0
  179. package/dist/es6/layout/lib/utils/buildStyleFns.d.ts.map +1 -0
  180. package/dist/es6/layout/lib/utils/buildStyleFns.js +85 -0
  181. package/dist/es6/layout/lib/utils/color.d.ts +23 -16
  182. package/dist/es6/layout/lib/utils/color.d.ts.map +1 -1
  183. package/dist/es6/layout/lib/utils/color.js +24 -47
  184. package/dist/es6/layout/lib/utils/depth.d.ts +17 -11
  185. package/dist/es6/layout/lib/utils/depth.d.ts.map +1 -1
  186. package/dist/es6/layout/lib/utils/depth.js +19 -18
  187. package/dist/es6/layout/lib/utils/flex.d.ts +31 -12
  188. package/dist/es6/layout/lib/utils/flex.d.ts.map +1 -1
  189. package/dist/es6/layout/lib/utils/flex.js +57 -23
  190. package/dist/es6/layout/lib/utils/flexItem.d.ts +18 -15
  191. package/dist/es6/layout/lib/utils/flexItem.d.ts.map +1 -1
  192. package/dist/es6/layout/lib/utils/flexItem.js +42 -24
  193. package/dist/es6/layout/lib/utils/grid.d.ts +40 -35
  194. package/dist/es6/layout/lib/utils/grid.d.ts.map +1 -1
  195. package/dist/es6/layout/lib/utils/grid.js +98 -70
  196. package/dist/es6/layout/lib/utils/gridItem.d.ts +17 -14
  197. package/dist/es6/layout/lib/utils/gridItem.d.ts.map +1 -1
  198. package/dist/es6/layout/lib/utils/gridItem.js +57 -28
  199. package/dist/es6/layout/lib/utils/layout.d.ts +47 -25
  200. package/dist/es6/layout/lib/utils/layout.d.ts.map +1 -1
  201. package/dist/es6/layout/lib/utils/layout.js +70 -31
  202. package/dist/es6/layout/lib/utils/other.d.ts +44 -2
  203. package/dist/es6/layout/lib/utils/other.d.ts.map +1 -1
  204. package/dist/es6/layout/lib/utils/other.js +100 -15
  205. package/dist/es6/layout/lib/utils/position.d.ts +37 -20
  206. package/dist/es6/layout/lib/utils/position.d.ts.map +1 -1
  207. package/dist/es6/layout/lib/utils/position.js +48 -64
  208. package/dist/es6/layout/lib/utils/space.d.ts +107 -51
  209. package/dist/es6/layout/lib/utils/space.d.ts.map +1 -1
  210. package/dist/es6/layout/lib/utils/space.js +97 -146
  211. package/dist/es6/layout/lib/utils/stack.d.ts +3 -6
  212. package/dist/es6/layout/lib/utils/stack.d.ts.map +1 -1
  213. package/dist/es6/layout/lib/utils/stack.js +13 -39
  214. package/dist/es6/layout/lib/utils/systemProps.d.ts +31 -0
  215. package/dist/es6/layout/lib/utils/systemProps.d.ts.map +1 -0
  216. package/dist/es6/layout/lib/utils/systemProps.js +1 -0
  217. package/dist/es6/layout/lib/utils/text.d.ts +33 -15
  218. package/dist/es6/layout/lib/utils/text.d.ts.map +1 -1
  219. package/dist/es6/layout/lib/utils/text.js +73 -36
  220. package/dist/es6/modal/lib/Modal.d.ts +1 -1
  221. package/dist/es6/popup/lib/Popup.d.ts +1 -1
  222. package/dist/es6/popup/lib/PopupBody.d.ts +1 -1
  223. package/dist/es6/popup/lib/hooks/useReturnFocus.d.ts.map +1 -1
  224. package/dist/es6/popup/lib/hooks/useReturnFocus.js +73 -8
  225. package/dist/es6/tabs/lib/TabsItem.d.ts +1 -1
  226. package/dist/es6/testing/index.d.ts +5 -0
  227. package/dist/es6/testing/index.d.ts.map +1 -0
  228. package/dist/es6/testing/index.js +4 -0
  229. package/dist/es6/testing/lib/ComponentStatesTable.d.ts +26 -0
  230. package/dist/es6/testing/lib/ComponentStatesTable.d.ts.map +1 -0
  231. package/dist/es6/testing/lib/ComponentStatesTable.js +41 -0
  232. package/dist/es6/testing/lib/StaticStates.d.ts +7 -0
  233. package/dist/es6/testing/lib/StaticStates.d.ts.map +1 -0
  234. package/dist/es6/{common/lib/utils → testing/lib}/StaticStates.js +1 -1
  235. package/dist/es6/testing/lib/permutateProps.d.ts +5 -0
  236. package/dist/es6/testing/lib/permutateProps.d.ts.map +1 -0
  237. package/dist/es6/testing/lib/permutateProps.js +43 -0
  238. package/dist/es6/testing/lib/propTypes.d.ts +15 -0
  239. package/dist/es6/testing/lib/propTypes.d.ts.map +1 -0
  240. package/dist/es6/testing/lib/propTypes.js +1 -0
  241. package/dist/es6/tokens/lib/colors.types.d.ts +4 -6
  242. package/dist/es6/tokens/lib/colors.types.d.ts.map +1 -1
  243. package/icon/lib/SystemIcon.tsx +1 -1
  244. package/index.ts +1 -0
  245. package/layout/index.ts +8 -4
  246. package/layout/lib/Box.tsx +10 -36
  247. package/layout/lib/Flex.tsx +5 -1
  248. package/layout/lib/Grid.tsx +3 -4
  249. package/layout/lib/utils/background.ts +83 -0
  250. package/layout/lib/utils/border/color.ts +85 -0
  251. package/layout/lib/utils/border/index.ts +49 -0
  252. package/layout/lib/utils/border/lineStyle.ts +87 -0
  253. package/layout/lib/utils/border/radius.ts +61 -0
  254. package/layout/lib/utils/border/shorthand.ts +73 -0
  255. package/layout/lib/utils/border/width.ts +73 -0
  256. package/layout/lib/utils/buildStyleFns.ts +117 -0
  257. package/layout/lib/utils/color.ts +40 -55
  258. package/layout/lib/utils/depth.ts +28 -24
  259. package/layout/lib/utils/flex.ts +83 -32
  260. package/layout/lib/utils/flexItem.ts +54 -36
  261. package/layout/lib/utils/grid.ts +131 -94
  262. package/layout/lib/utils/gridItem.ts +69 -41
  263. package/layout/lib/utils/layout.ts +109 -50
  264. package/layout/lib/utils/other.ts +142 -15
  265. package/layout/lib/utils/position.ts +79 -73
  266. package/layout/lib/utils/space.ts +202 -196
  267. package/layout/lib/utils/stack.ts +19 -45
  268. package/layout/lib/utils/systemProps.ts +46 -0
  269. package/layout/lib/utils/text.ts +99 -34
  270. package/package.json +3 -3
  271. package/popup/lib/hooks/useReturnFocus.tsx +83 -9
  272. package/testing/LICENSE +52 -0
  273. package/testing/README.md +6 -0
  274. package/testing/index.ts +4 -0
  275. package/testing/lib/ComponentStatesTable.tsx +80 -0
  276. package/{common/lib/utils → testing/lib}/StaticStates.tsx +5 -4
  277. package/testing/lib/permutateProps.ts +47 -0
  278. package/testing/lib/propTypes.ts +15 -0
  279. package/testing/package.json +6 -0
  280. package/tokens/lib/colors.types.ts +4 -7
  281. package/dist/commonjs/common/lib/utils/StaticStates.d.ts +0 -8
  282. package/dist/commonjs/common/lib/utils/StaticStates.d.ts.map +0 -1
  283. package/dist/commonjs/layout/lib/utils/border.d.ts +0 -103
  284. package/dist/commonjs/layout/lib/utils/border.d.ts.map +0 -1
  285. package/dist/commonjs/layout/lib/utils/border.js +0 -153
  286. package/dist/commonjs/layout/lib/utils/font.d.ts +0 -29
  287. package/dist/commonjs/layout/lib/utils/font.d.ts.map +0 -1
  288. package/dist/commonjs/layout/lib/utils/font.js +0 -57
  289. package/dist/es6/common/lib/utils/StaticStates.d.ts +0 -8
  290. package/dist/es6/common/lib/utils/StaticStates.d.ts.map +0 -1
  291. package/dist/es6/layout/lib/utils/border.d.ts +0 -103
  292. package/dist/es6/layout/lib/utils/border.d.ts.map +0 -1
  293. package/dist/es6/layout/lib/utils/border.js +0 -149
  294. package/dist/es6/layout/lib/utils/font.d.ts +0 -29
  295. package/dist/es6/layout/lib/utils/font.d.ts.map +0 -1
  296. package/dist/es6/layout/lib/utils/font.js +0 -53
  297. package/layout/lib/utils/border.ts +0 -263
  298. 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
- // 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);