@workday/canvas-kit-react 8.0.0-alpha.208-next.1 → 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 +72 -1
  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 +73 -2
  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 +82 -3
  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,207 +1,213 @@
1
- import {
2
- ContentDirection,
3
- PartialEmotionCanvasTheme,
4
- useTheme,
5
- } from '@workday/canvas-kit-react/common';
6
- import {space as spaceTokens, CanvasSpace, CanvasSpaceKeys} from '@workday/canvas-kit-react/tokens';
7
-
8
- type SpacePropValues = CanvasSpaceKeys | number | (string & {});
9
-
10
- /** These props automatically adjust for bidirectionality (LTR & RTL) */
11
- export type SpaceLogicalProps = {
12
- /** sets margin-left property (bidirectional support) */
13
- marginInlineStart?: SpacePropValues;
14
- /** sets margin-right property (bidirectional support) */
15
- marginInlineEnd?: SpacePropValues;
16
- /** sets padding-left property (bidirectional support) */
17
- paddingInlineStart?: SpacePropValues;
18
- /** sets padding-right property (bidirectional support) */
19
- paddingInlineEnd?: SpacePropValues;
20
- };
21
-
22
- /** These props do not adjust for bidirectionality (LTR & RTL) */
23
- export type SpaceStandardProps = {
24
- /** sets margin property */
25
- margin?: SpacePropValues;
26
- /** sets margin-left and margin-right properties */
27
- marginX?: SpacePropValues;
28
- /** sets margin-top and margin-bottom properties */
29
- marginY?: SpacePropValues;
30
- /** sets margin-top property */
31
- marginTop?: SpacePropValues;
32
- /** sets margin-right property (no bidirectional support) */
33
- marginRight?: SpacePropValues;
34
- /** sets margin-bottom property */
35
- marginBottom?: SpacePropValues;
36
- /** sets margin-left property (no bidirectional support) */
37
- marginLeft?: SpacePropValues;
38
- /** sets padding property */
39
- padding?: SpacePropValues;
40
- /** sets padding-left and margin-right properties */
41
- paddingX?: SpacePropValues;
42
- /** sets padding-top and padding-bottom properties */
43
- paddingY?: SpacePropValues;
44
- /** sets padding-top property */
45
- paddingTop?: SpacePropValues;
46
- /** sets padding-right property (no bidirectional support) */
47
- paddingRight?: SpacePropValues;
48
- /** sets padding-bottom */
49
- paddingBottom?: SpacePropValues;
50
- /** sets padding-left property (no bidirectional support) */
51
- paddingLeft?: SpacePropValues;
52
- };
53
-
54
- export type SpaceStyleProps = SpaceStandardProps & SpaceLogicalProps;
55
-
56
- const margin = (value: SpacePropValues) => {
57
- return {margin: spaceTokens[value as keyof CanvasSpace] || value};
58
- };
59
-
60
- const marginX = (value: SpacePropValues) => {
61
- return {
62
- marginLeft: spaceTokens[value as CanvasSpaceKeys] || value,
63
- marginRight: spaceTokens[value as CanvasSpaceKeys] || value,
64
- };
65
- };
66
-
67
- const marginY = (value: SpacePropValues) => {
68
- return {
69
- marginTop: spaceTokens[value as CanvasSpaceKeys] || value,
70
- marginBottom: spaceTokens[value as CanvasSpaceKeys] || value,
71
- };
72
- };
73
-
74
- const marginTop = (value: SpacePropValues) => {
75
- return {
76
- marginTop: spaceTokens[value as CanvasSpaceKeys] || value,
77
- };
78
- };
79
-
80
- const marginRight = (value: SpacePropValues, isRTL = false) => {
81
- const attr = isRTL ? 'marginLeft' : 'marginRight';
82
- return {
83
- [attr]: spaceTokens[value as CanvasSpaceKeys] || value,
84
- };
85
- };
86
-
87
- const marginBottom = (value: SpacePropValues) => {
88
- return {
89
- marginBottom: spaceTokens[value as CanvasSpaceKeys] || value,
90
- };
91
- };
92
-
93
- const marginLeft = (value: SpacePropValues, isRTL = false) => {
94
- const attr = isRTL ? 'marginRight' : 'marginLeft';
95
- return {
96
- [attr]: spaceTokens[value as CanvasSpaceKeys] || value,
97
- };
98
- };
99
-
100
- const padding = (value: SpacePropValues) => {
101
- return {
102
- padding: spaceTokens[value as CanvasSpaceKeys] || value,
103
- };
104
- };
105
-
106
- const paddingX = (value: SpacePropValues) => {
107
- return {
108
- paddingLeft: spaceTokens[value as CanvasSpaceKeys] || value,
109
- paddingRight: spaceTokens[value as CanvasSpaceKeys] || value,
110
- };
111
- };
112
-
113
- const paddingY = (value: SpacePropValues) => {
114
- return {
115
- paddingTop: spaceTokens[value as CanvasSpaceKeys] || value,
116
- paddingBottom: spaceTokens[value as CanvasSpaceKeys] || value,
117
- };
118
- };
119
-
120
- const paddingTop = (value: SpacePropValues) => {
121
- return {
122
- paddingTop: spaceTokens[value as CanvasSpaceKeys] || value,
123
- };
124
- };
125
-
126
- const paddingRight = (value: SpacePropValues, isRTL = false) => {
127
- const attr = isRTL ? 'paddingLeft' : 'paddingRight';
128
- return {
129
- [attr]: spaceTokens[value as CanvasSpaceKeys] || value,
130
- };
131
- };
132
-
133
- const paddingBottom = (value: SpacePropValues) => {
134
- return {
135
- paddingBottom: spaceTokens[value as CanvasSpaceKeys] || value,
136
- };
137
- };
138
-
139
- const paddingLeft = (value: SpacePropValues, isRTL = false) => {
140
- const attr = isRTL ? 'paddingRight' : 'paddingLeft';
141
- return {
142
- [attr]: spaceTokens[value as CanvasSpaceKeys] || value,
143
- };
144
- };
145
-
146
- const logicalSpaceStyleProps = {
147
- marginInlineStart: marginLeft,
148
- marginInlineEnd: marginRight,
149
- paddingInlineStart: paddingLeft,
150
- paddingInlineEnd: paddingRight,
151
- };
152
-
153
- const standardSpaceStyleProps = {
154
- margin,
155
- marginX,
156
- marginY,
157
- marginTop,
158
- marginRight,
159
- marginBottom,
160
- marginLeft,
161
- padding,
162
- paddingX,
163
- paddingY,
164
- paddingTop,
165
- paddingRight,
166
- paddingBottom,
167
- paddingLeft,
168
- };
169
-
1
+ import {buildStyleFns, buildStylePropFn, StyleFnConfig} from './buildStyleFns';
2
+ import {SystemPropValues} from './systemProps';
3
+
4
+ /** style props to for CSS space properties */
5
+ export type SpaceStyleProps = {
6
+ /**
7
+ * - sets [CSS margin-inline-start property](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline-start)
8
+ * - bidirectional support
9
+ * - system tokens: `space`
10
+ * */
11
+ marginInlineStart?: SystemPropValues['space'];
12
+ /**
13
+ * - sets [CSS margin-inline-end property](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline-end)
14
+ * - bidirectional support
15
+ * - system tokens: `space`
16
+ * */
17
+ marginInlineEnd?: SystemPropValues['space'];
18
+ /**
19
+ * - sets [CSS padding-inline-start property](https://developer.mozilla.org/en-US/docs/Web/CSS/padding-inline-start)
20
+ * - bidirectional support
21
+ * - system tokens: `space`
22
+ * */
23
+ paddingInlineStart?: SystemPropValues['space'];
24
+ /**
25
+ * - sets [CSS padding-inline-end property](https://developer.mozilla.org/en-US/docs/Web/CSS/padding-inline-end)
26
+ * - bidirectional support
27
+ * - system tokens: `space`
28
+ * */
29
+ paddingInlineEnd?: SystemPropValues['space'];
30
+ /**
31
+ * - sets [CSS margin property](https://developer.mozilla.org/en-US/docs/Web/CSS/margin)
32
+ * - system tokens: `space`
33
+ * */
34
+ margin?: SystemPropValues['space'];
35
+ /**
36
+ * - sets [CSS margin-left](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-left) and [margin-right properties](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-right)
37
+ * - system tokens: `space`
38
+ * */
39
+ marginX?: SystemPropValues['space'];
40
+ /**
41
+ * - sets [CSS margin-top](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-top) and [margin-bottom properties](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-bottom)
42
+ * - system tokens: `space`
43
+ * */
44
+ marginY?: SystemPropValues['space'];
45
+ /**
46
+ * - sets [CSS margin-top property](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-top)
47
+ * - system tokens: `space`
48
+ * */
49
+ marginTop?: SystemPropValues['space'];
50
+ /**
51
+ * - sets [CSS margin-right property](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-right)
52
+ * - no bidirectional support
53
+ * - system tokens: `space`
54
+ * */
55
+ marginRight?: SystemPropValues['space'];
56
+ /**
57
+ * - sets [CSS margin-bottom property](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-bottom)
58
+ * - system tokens: `space`
59
+ * */
60
+ marginBottom?: SystemPropValues['space'];
61
+ /**
62
+ * - sets [CSS margin-left property](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-left)
63
+ * - no bidirectional support
64
+ * - system tokens: `space`
65
+ * */
66
+ marginLeft?: SystemPropValues['space'];
67
+ /**
68
+ * - sets [CSS padding property](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
69
+ * - system tokens: `space`
70
+ * */
71
+ padding?: SystemPropValues['space'];
72
+ /**
73
+ * - sets [CSS padding-left]((https://developer.mozilla.org/en-US/docs/Web/CSS/padding-left) and [padding-right properties](https://developer.mozilla.org/en-US/docs/Web/CSS/padding-right)
74
+ * - system tokens: `space`
75
+ * */
76
+ paddingX?: SystemPropValues['space'];
77
+ /**
78
+ * - sets [CSS padding-top](https://developer.mozilla.org/en-US/docs/Web/CSS/padding-top) and [padding-bottom properties](https://developer.mozilla.org/en-US/docs/Web/CSS/padding-bottom)
79
+ * - system tokens: `space`
80
+ * */
81
+ paddingY?: SystemPropValues['space'];
82
+ /**
83
+ * - sets [CSS padding-top property](https://developer.mozilla.org/en-US/docs/Web/CSS/padding-top)
84
+ * - system tokens: `space`
85
+ * */
86
+ paddingTop?: SystemPropValues['space'];
87
+ /**
88
+ * - sets [CSS padding-right property](https://developer.mozilla.org/en-US/docs/Web/CSS/padding-right)
89
+ * - no bidirectional support
90
+ * - system tokens: `space`
91
+ * */
92
+ paddingRight?: SystemPropValues['space'];
93
+ /**
94
+ * - sets [CSS padding-bottom](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
95
+ * - system tokens: `space`
96
+ * */
97
+ paddingBottom?: SystemPropValues['space'];
98
+ /**
99
+ * - sets [CSS padding-left property](https://developer.mozilla.org/en-US/docs/Web/CSS/padding-left)
100
+ * - no bidirectional support
101
+ * - system tokens: `space`
102
+ * */
103
+ paddingLeft?: SystemPropValues['space'];
104
+ };
105
+
106
+ export const spaceStyleFnConfigs: StyleFnConfig[] = [
107
+ {
108
+ name: 'marginInlineStart',
109
+ properties: ['marginInlineStart'],
110
+ system: 'space',
111
+ },
112
+ {
113
+ name: 'marginInlineEnd',
114
+ properties: ['marginInlineEnd'],
115
+ system: 'space',
116
+ },
117
+ {
118
+ name: 'paddingInlineStart',
119
+ properties: ['paddingInlineStart'],
120
+ system: 'space',
121
+ },
122
+ {
123
+ name: 'paddingInlineEnd',
124
+ properties: ['paddingInlineEnd'],
125
+ system: 'space',
126
+ },
127
+ {
128
+ name: 'margin',
129
+ properties: ['margin'],
130
+ system: 'space',
131
+ },
132
+ {
133
+ name: 'marginX',
134
+ properties: ['marginLeft', 'marginRight'],
135
+ system: 'space',
136
+ },
137
+ {
138
+ name: 'marginY',
139
+ properties: ['marginTop', 'marginBottom'],
140
+ system: 'space',
141
+ },
142
+ {
143
+ name: 'marginTop',
144
+ properties: ['marginTop'],
145
+ system: 'space',
146
+ },
147
+ {
148
+ name: 'marginRight',
149
+ properties: ['marginRight'],
150
+ system: 'space',
151
+ },
152
+ {
153
+ name: 'marginBottom',
154
+ properties: ['marginBottom'],
155
+ system: 'space',
156
+ },
157
+ {
158
+ name: 'marginLeft',
159
+ properties: ['marginLeft'],
160
+ system: 'space',
161
+ },
162
+ {
163
+ name: 'padding',
164
+ properties: ['padding'],
165
+ system: 'space',
166
+ },
167
+ {
168
+ name: 'paddingX',
169
+ properties: ['paddingLeft', 'paddingRight'],
170
+ system: 'space',
171
+ },
172
+ {
173
+ name: 'paddingY',
174
+ properties: ['paddingTop', 'paddingBottom'],
175
+ system: 'space',
176
+ },
177
+ {
178
+ name: 'paddingTop',
179
+ properties: ['paddingTop'],
180
+ system: 'space',
181
+ },
182
+ {
183
+ name: 'paddingRight',
184
+ properties: ['paddingRight'],
185
+ system: 'space',
186
+ },
187
+ {
188
+ name: 'paddingBottom',
189
+ properties: ['paddingBottom'],
190
+ system: 'space',
191
+ },
192
+ {
193
+ name: 'paddingLeft',
194
+ properties: ['paddingLeft'],
195
+ system: 'space',
196
+ },
197
+ ];
198
+
199
+ export const spaceStyleFns = buildStyleFns(spaceStyleFnConfigs);
170
200
  /**
171
201
  * A style prop function that takes component props and returns space styles.
172
202
  * If no `SpaceStyleProps` are found, it returns an empty object.
173
203
  *
174
204
  * @example
175
- * // You'll most likely use `space` with low-level, styled components
205
+ * ```tsx
176
206
  * const BoxExample = () => (
177
207
  * <Box padding="xs" margin="m">
178
208
  * Hello, space!
179
209
  * </Box>
180
210
  * );
181
- *
211
+ * ```
182
212
  */
183
- export function space<P extends SpaceStyleProps & {theme?: PartialEmotionCanvasTheme}>(props: P) {
184
- // space will always be used within the context of a component, but eslint doesn't know that
185
- // eslint-disable-next-line react-hooks/rules-of-hooks
186
- const {canvas} = useTheme(props.theme);
187
- let styles = {};
188
- for (const key in props) {
189
- if (props.hasOwnProperty(key)) {
190
- if (key in standardSpaceStyleProps) {
191
- const value = props[key as keyof SpaceStandardProps] as SpacePropValues;
192
- const spaceFn = standardSpaceStyleProps[key as keyof SpaceStandardProps];
193
- const style = spaceFn(value);
194
- styles = {...styles, ...style};
195
- continue;
196
- }
197
- if (key in logicalSpaceStyleProps) {
198
- const value = props[key as keyof SpaceLogicalProps] as SpacePropValues;
199
- const spaceFn = logicalSpaceStyleProps[key as keyof SpaceLogicalProps];
200
- const isRTL = canvas.direction === ContentDirection.RTL;
201
- const style = spaceFn(value, isRTL);
202
- styles = {...styles, ...style};
203
- }
204
- }
205
- }
206
- return styles;
207
- }
213
+ export const space = buildStylePropFn<SpaceStyleProps>(spaceStyleFns);
@@ -1,15 +1,11 @@
1
- import {
2
- ContentDirection,
3
- PartialEmotionCanvasTheme,
4
- useTheme,
5
- } from '@workday/canvas-kit-react/common';
6
- import {space as spaceTokens, CanvasSpaceKeys} from '@workday/canvas-kit-react/tokens';
1
+ import {space as spaceTokens} from '@workday/canvas-kit-react/tokens';
2
+ import {CanvasSystemPropValues, SystemPropValues} from './systemProps';
7
3
 
8
4
  export type StackDirection = 'row' | 'column' | 'row-reverse' | 'column-reverse';
9
5
 
10
6
  const selector = '& > *:not(style) ~ *:not(style)';
11
7
 
12
- export type StackSpacing = CanvasSpaceKeys | number | (string & {});
8
+ export type StackSpacing = SystemPropValues['space'];
13
9
 
14
10
  export type StackStyleProps = {
15
11
  /** sets space values between child elements (bidirectional support) */
@@ -26,50 +22,28 @@ export type StackStyleProps = {
26
22
  shouldWrapChildren?: boolean;
27
23
  };
28
24
 
29
- const column = (value: StackSpacing) => ({
30
- marginTop: spaceTokens[value as CanvasSpaceKeys] || value,
31
- });
32
-
33
- const columnReverse = (value: StackSpacing) => ({
34
- marginBottom: spaceTokens[value as CanvasSpaceKeys] || value,
35
- });
36
-
37
- const row = (value: StackSpacing, isRTL = false) => {
38
- const attr = isRTL ? 'marginRight' : 'marginLeft';
39
- return {
40
- [attr]: spaceTokens[value as CanvasSpaceKeys] || value,
41
- };
25
+ const getSpace = (value: SystemPropValues['space']) => {
26
+ return spaceTokens[value as CanvasSystemPropValues['space']] || value;
42
27
  };
43
28
 
44
- const rowReverse = (value: StackSpacing, isRTL = false) => {
45
- const attr = isRTL ? 'marginLeft' : 'marginRight';
46
- return {
47
- [attr]: spaceTokens[value as CanvasSpaceKeys] || value,
48
- };
49
- };
29
+ export function stack<P extends StackStyleProps>(props: P) {
30
+ const {flexDirection = 'row', spacing} = props;
31
+ let styles = {};
50
32
 
51
- const stackDirectionProps = {
52
- column,
53
- 'column-reverse': columnReverse,
54
- row,
55
- 'row-reverse': rowReverse,
56
- };
33
+ if (flexDirection === 'column') {
34
+ styles = {marginTop: getSpace(spacing)};
35
+ }
57
36
 
58
- export function stack<P extends StackStyleProps & {theme?: PartialEmotionCanvasTheme}>(props: P) {
59
- let styles = {};
60
- const {flexDirection = 'row', spacing} = props;
61
- if (flexDirection === 'column' || flexDirection === 'column-reverse') {
62
- const stackFn = stackDirectionProps[flexDirection];
63
- styles = stackFn(spacing);
37
+ if (flexDirection === 'column-reverse') {
38
+ styles = {marginBottom: getSpace(spacing)};
39
+ }
40
+
41
+ if (flexDirection === 'row') {
42
+ styles = {marginInlineStart: getSpace(spacing)};
64
43
  }
65
44
 
66
- if (flexDirection === 'row' || flexDirection === 'row-reverse') {
67
- // stack will always be used within the context of a component, but eslint doesn't know that
68
- // eslint-disable-next-line react-hooks/rules-of-hooks
69
- const {canvas} = useTheme(props.theme);
70
- const stackFn = stackDirectionProps[flexDirection];
71
- const isRTL = canvas.direction === ContentDirection.RTL;
72
- styles = stackFn(spacing, isRTL);
45
+ if (flexDirection === 'row-reverse') {
46
+ styles = {marginInlineEnd: getSpace(spacing)};
73
47
  }
74
48
 
75
49
  return {
@@ -0,0 +1,46 @@
1
+ import {
2
+ CanvasBorderRadiusKeys,
3
+ CanvasColor,
4
+ CanvasDepth,
5
+ CanvasSpaceKeys,
6
+ CanvasTypeProperties,
7
+ } from '@workday/canvas-kit-react/tokens';
8
+
9
+ export type SystemPropNames =
10
+ | 'color'
11
+ | 'depth'
12
+ | 'font'
13
+ | 'fontSize'
14
+ | 'fontWeight'
15
+ | 'shape'
16
+ | 'space';
17
+
18
+ /**
19
+ * Canvas System Prop Values
20
+ * ---
21
+ * These system prop values are restricted to Canvas token values.
22
+ */
23
+ export type CanvasSystemPropValues = {
24
+ color: CanvasColor;
25
+ depth: keyof CanvasDepth;
26
+ font: keyof CanvasTypeProperties['fontFamilies'];
27
+ fontSize: keyof CanvasTypeProperties['fontSizes'];
28
+ fontWeight: keyof CanvasTypeProperties['fontWeights'];
29
+ shape: CanvasBorderRadiusKeys;
30
+ space: CanvasSpaceKeys;
31
+ };
32
+
33
+ /**
34
+ * System Prop Values
35
+ * ---
36
+ * These system prop values include Canvas System Prop Values and generic values.
37
+ */
38
+ export type SystemPropValues = {
39
+ color: CanvasSystemPropValues['color'] | (string & {});
40
+ depth: CanvasSystemPropValues['depth'];
41
+ font: CanvasSystemPropValues['font'] | (string & {});
42
+ fontSize: CanvasSystemPropValues['fontSize'] | (string & {});
43
+ fontWeight: CanvasSystemPropValues['fontWeight'] | (string & {});
44
+ shape: CanvasSystemPropValues['shape'] | number | (string & {});
45
+ space: CanvasSystemPropValues['space'] | number | (string & {});
46
+ };