@blueprintjs/labs 0.16.2 → 6.1.0

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 (148) hide show
  1. package/LICENSE +153 -167
  2. package/README.md +1 -1
  3. package/lib/cjs/common/classes.d.ts +6 -0
  4. package/lib/cjs/common/classes.js +20 -0
  5. package/lib/cjs/common/classes.js.map +1 -0
  6. package/lib/cjs/common/index.d.ts +3 -1
  7. package/lib/cjs/common/index.js +9 -4
  8. package/lib/cjs/common/index.js.map +1 -1
  9. package/lib/cjs/common/props.d.ts +1 -0
  10. package/lib/cjs/common/props.js +10 -0
  11. package/lib/cjs/common/props.js.map +1 -0
  12. package/lib/cjs/components/box/box.d.ts +8 -0
  13. package/lib/cjs/components/box/box.js +25 -0
  14. package/lib/cjs/components/box/box.js.map +1 -0
  15. package/lib/cjs/components/box/box.test.d.ts +1 -0
  16. package/lib/cjs/components/box/box.test.js +80 -0
  17. package/lib/cjs/components/box/box.test.js.map +1 -0
  18. package/lib/cjs/components/box/boxProps.d.ts +246 -0
  19. package/lib/cjs/components/box/boxProps.js +6 -0
  20. package/lib/cjs/components/box/boxProps.js.map +1 -0
  21. package/lib/cjs/components/box/buildStyles.d.ts +23 -0
  22. package/lib/cjs/components/box/buildStyles.js +258 -0
  23. package/lib/cjs/components/box/buildStyles.js.map +1 -0
  24. package/lib/cjs/components/flex/flex.d.ts +7 -0
  25. package/lib/cjs/components/flex/flex.js +18 -0
  26. package/lib/cjs/components/flex/flex.js.map +1 -0
  27. package/lib/cjs/components/flex/flex.test.d.ts +1 -0
  28. package/lib/cjs/components/flex/flex.test.js +59 -0
  29. package/lib/cjs/components/flex/flex.test.js.map +1 -0
  30. package/lib/cjs/components/index.d.ts +3 -1
  31. package/lib/cjs/components/index.js +8 -4
  32. package/lib/cjs/components/index.js.map +1 -1
  33. package/lib/cjs/components/slot/slot.d.ts +7 -0
  34. package/lib/cjs/components/slot/slot.js +31 -0
  35. package/lib/cjs/components/slot/slot.js.map +1 -0
  36. package/lib/cjs/components/slot/slot.test.d.ts +1 -0
  37. package/lib/cjs/components/slot/slot.test.js +47 -0
  38. package/lib/cjs/components/slot/slot.test.js.map +1 -0
  39. package/lib/cjs/index.d.ts +0 -7
  40. package/lib/cjs/index.js +6 -15
  41. package/lib/cjs/index.js.map +1 -1
  42. package/lib/css/blueprint-labs.css +1630 -7
  43. package/lib/css/blueprint-labs.css.map +1 -10
  44. package/lib/esm/common/classes.d.ts +6 -0
  45. package/lib/esm/common/classes.js +16 -0
  46. package/lib/esm/common/classes.js.map +1 -0
  47. package/lib/esm/common/index.d.ts +3 -1
  48. package/lib/esm/common/index.js +6 -4
  49. package/lib/esm/common/index.js.map +1 -1
  50. package/lib/esm/common/props.d.ts +1 -0
  51. package/lib/esm/common/props.js +7 -0
  52. package/lib/esm/common/props.js.map +1 -0
  53. package/lib/esm/components/box/box.d.ts +8 -0
  54. package/lib/esm/components/box/box.js +21 -0
  55. package/lib/esm/components/box/box.js.map +1 -0
  56. package/lib/esm/components/box/box.test.d.ts +1 -0
  57. package/lib/esm/components/box/box.test.js +78 -0
  58. package/lib/esm/components/box/box.test.js.map +1 -0
  59. package/lib/esm/components/box/boxProps.d.ts +246 -0
  60. package/lib/esm/components/box/boxProps.js +5 -0
  61. package/lib/esm/components/box/boxProps.js.map +1 -0
  62. package/lib/esm/components/box/buildStyles.d.ts +23 -0
  63. package/lib/esm/components/box/buildStyles.js +254 -0
  64. package/lib/esm/components/box/buildStyles.js.map +1 -0
  65. package/lib/esm/components/flex/flex.d.ts +7 -0
  66. package/lib/esm/components/flex/flex.js +15 -0
  67. package/lib/esm/components/flex/flex.js.map +1 -0
  68. package/lib/esm/components/flex/flex.test.d.ts +1 -0
  69. package/lib/esm/components/flex/flex.test.js +57 -0
  70. package/lib/esm/components/flex/flex.test.js.map +1 -0
  71. package/lib/esm/components/index.d.ts +3 -1
  72. package/lib/esm/components/index.js +5 -4
  73. package/lib/esm/components/index.js.map +1 -1
  74. package/lib/esm/components/slot/slot.d.ts +7 -0
  75. package/lib/esm/components/slot/slot.js +27 -0
  76. package/lib/esm/components/slot/slot.js.map +1 -0
  77. package/lib/esm/components/slot/slot.test.d.ts +1 -0
  78. package/lib/esm/components/slot/slot.test.js +45 -0
  79. package/lib/esm/components/slot/slot.test.js.map +1 -0
  80. package/lib/esm/index.d.ts +2 -9
  81. package/lib/esm/index.js +5 -12
  82. package/lib/esm/index.js.map +1 -1
  83. package/lib/esnext/common/classes.d.ts +6 -0
  84. package/lib/esnext/common/classes.js +16 -0
  85. package/lib/esnext/common/classes.js.map +1 -0
  86. package/lib/esnext/common/index.d.ts +3 -0
  87. package/lib/esnext/common/index.js +8 -0
  88. package/lib/esnext/common/index.js.map +1 -0
  89. package/lib/esnext/common/props.d.ts +1 -0
  90. package/lib/esnext/common/props.js +7 -0
  91. package/lib/esnext/common/props.js.map +1 -0
  92. package/lib/esnext/components/box/box.d.ts +8 -0
  93. package/lib/esnext/components/box/box.js +21 -0
  94. package/lib/esnext/components/box/box.js.map +1 -0
  95. package/lib/esnext/components/box/box.test.d.ts +1 -0
  96. package/lib/esnext/components/box/box.test.js +78 -0
  97. package/lib/esnext/components/box/box.test.js.map +1 -0
  98. package/lib/esnext/components/box/boxProps.d.ts +246 -0
  99. package/lib/esnext/components/box/boxProps.js +5 -0
  100. package/lib/esnext/components/box/boxProps.js.map +1 -0
  101. package/lib/esnext/components/box/buildStyles.d.ts +23 -0
  102. package/lib/esnext/components/box/buildStyles.js +254 -0
  103. package/lib/esnext/components/box/buildStyles.js.map +1 -0
  104. package/lib/esnext/components/flex/flex.d.ts +7 -0
  105. package/lib/esnext/components/flex/flex.js +15 -0
  106. package/lib/esnext/components/flex/flex.js.map +1 -0
  107. package/lib/esnext/components/flex/flex.test.d.ts +1 -0
  108. package/lib/esnext/components/flex/flex.test.js +57 -0
  109. package/lib/esnext/components/flex/flex.test.js.map +1 -0
  110. package/lib/esnext/components/index.d.ts +3 -0
  111. package/lib/esnext/components/index.js +7 -0
  112. package/lib/esnext/components/index.js.map +1 -0
  113. package/lib/esnext/components/slot/slot.d.ts +7 -0
  114. package/lib/esnext/components/slot/slot.js +27 -0
  115. package/lib/esnext/components/slot/slot.js.map +1 -0
  116. package/lib/esnext/components/slot/slot.test.d.ts +1 -0
  117. package/lib/esnext/components/slot/slot.test.js +45 -0
  118. package/lib/esnext/components/slot/slot.test.js.map +1 -0
  119. package/lib/esnext/index.d.ts +2 -0
  120. package/lib/esnext/index.js +7 -0
  121. package/lib/esnext/index.js.map +1 -0
  122. package/package.json +59 -44
  123. package/src/_common.scss +9 -0
  124. package/src/blueprint-labs.scss +5 -7
  125. package/src/common/classes.ts +20 -0
  126. package/src/common/index.ts +7 -6
  127. package/src/common/props.ts +8 -0
  128. package/src/components/box/_box.scss +543 -0
  129. package/src/components/box/box.md +59 -0
  130. package/src/components/box/box.test.tsx +119 -0
  131. package/src/components/box/box.tsx +32 -0
  132. package/src/components/box/boxProps.ts +334 -0
  133. package/src/components/box/buildStyles.ts +307 -0
  134. package/src/components/flex/flex.md +52 -0
  135. package/src/components/flex/flex.test.tsx +93 -0
  136. package/src/components/flex/flex.tsx +20 -0
  137. package/src/components/index.ts +6 -6
  138. package/src/components/slot/slot.test.tsx +73 -0
  139. package/src/components/slot/slot.tsx +30 -0
  140. package/src/index.md +16 -5
  141. package/src/index.ts +3 -20
  142. package/src/tsconfig.json +5 -3
  143. package/src/vitest-env.d.ts +6 -0
  144. package/vitest.config.mts +17 -0
  145. package/vitest.setup.mts +13 -0
  146. package/dist/labs.bundle.js +0 -1
  147. package/src/components/_index.scss +0 -3
  148. package/src/tsconfig.cjs.json +0 -7
@@ -0,0 +1,32 @@
1
+ /* !
2
+ * (c) Copyright 2025 Palantir Technologies Inc. All rights reserved.
3
+ */
4
+
5
+ import classNames from "classnames";
6
+ import { forwardRef, useMemo } from "react";
7
+
8
+ import { Classes, DISPLAYNAME_PREFIX } from "../../common";
9
+ import { Slot } from "../slot/slot";
10
+
11
+ import type { BoxProps } from "./boxProps";
12
+ import { buildStyles } from "./buildStyles";
13
+
14
+ /**
15
+ * Box component.
16
+ *
17
+ * @see https://blueprintjs.com/docs/#labs/components/box
18
+ */
19
+ export const Box = forwardRef<HTMLDivElement, BoxProps>(function Box({ asChild, className, ...props }, ref) {
20
+ const Component = asChild ? Slot : "div";
21
+ const { generatedClassNames, passThroughProps } = useMemo(() => buildStyles(props), [props]);
22
+
23
+ return (
24
+ <Component
25
+ {...passThroughProps}
26
+ className={classNames(className, Classes.BOX, generatedClassNames)}
27
+ ref={ref}
28
+ />
29
+ );
30
+ });
31
+
32
+ Box.displayName = `${DISPLAYNAME_PREFIX}.Box`;
@@ -0,0 +1,334 @@
1
+ /* !
2
+ * (c) Copyright 2025 Palantir Technologies Inc. All rights reserved.
3
+ */
4
+
5
+ /**
6
+ * Prop-type definitions for the <Box> component.
7
+ *
8
+ * The guiding idea behind <Box> is to provide a small, typed subset of the
9
+ * CSS box-model and flexbox APIs as *props* instead of requiring consumers to
10
+ * write custom styles or class names. We purposefully whitelist only a finite
11
+ * number of safe values (see the union literals below) so that:
12
+ *
13
+ * 1. Design-system-approved spacing / sizing tokens can be enforced at compile
14
+ * time.
15
+ * 2. We can consistently translate prop values into utility class names
16
+ * generated by `buildStyles`.
17
+ * 3. Invalid HTML attributes (e.g. `foo="bar"`) are rejected by TypeScript in
18
+ * user code, while *supported* DOM props such as `id`, `title`, etc. are
19
+ * still allowed through the generic overlay.
20
+ */
21
+
22
+ import type * as React from "react";
23
+
24
+ /**
25
+ * The range of values for spacing tokens.
26
+ */
27
+ type SpacingRange = 0 | 0.5 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
28
+
29
+ /**
30
+ * The range of values for size as a percentage.
31
+ */
32
+ type SizeRange = 25 | 50 | 75 | 100;
33
+
34
+ /**
35
+ * The range of values for `gap`.
36
+ *
37
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/gap
38
+ */
39
+ export type Gap = SpacingRange | `${SpacingRange}`;
40
+
41
+ /**
42
+ * The range of values for `margin`.
43
+ *
44
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/margin
45
+ */
46
+ export type Margin = SpacingRange | `${SpacingRange}` | "auto";
47
+
48
+ /**
49
+ * The range of values for `padding`.
50
+ *
51
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/padding
52
+ */
53
+ export type Padding = SpacingRange | `${SpacingRange}`;
54
+
55
+ /**
56
+ * The range of values for `inset`.
57
+ *
58
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/inset
59
+ */
60
+ export type Inset = SpacingRange | `${SpacingRange}`;
61
+
62
+ /**
63
+ * The range of values for `width`.
64
+ *
65
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/width
66
+ */
67
+ export type Width = SizeRange | `${SizeRange}` | "auto";
68
+
69
+ /**
70
+ * The range of values for `height`.
71
+ *
72
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/height
73
+ */
74
+ export type Height = SizeRange | `${SizeRange}` | "auto";
75
+
76
+ /**
77
+ * The range of values for `align-content`.
78
+ *
79
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/align-content
80
+ */
81
+ export type AlignContent =
82
+ | "start"
83
+ | "center"
84
+ | "end"
85
+ | "space-between"
86
+ | "space-around"
87
+ | "space-evenly"
88
+ | "stretch"
89
+ | "normal"
90
+ | "baseline";
91
+
92
+ /**
93
+ * The range of values for `align-items`.
94
+ *
95
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/align-items
96
+ */
97
+ export type AlignItems = "start" | "end" | "center" | "baseline" | "stretch";
98
+
99
+ /**
100
+ * The range of values for `align-self`.
101
+ *
102
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/align-self
103
+ */
104
+ export type AlignSelf = "auto" | "start" | "end" | "center" | "baseline" | "stretch";
105
+
106
+ /**
107
+ * The range of values for `display`.
108
+ *
109
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/display
110
+ */
111
+ export type Display =
112
+ | "block"
113
+ | "inline-block"
114
+ | "inline"
115
+ | "flex"
116
+ | "inline-flex"
117
+ | "grid"
118
+ | "inline-grid"
119
+ | "table"
120
+ | "inline-table"
121
+ | "table-cell"
122
+ | "table-row"
123
+ | "none";
124
+
125
+ /**
126
+ * The range of values for `flex`.
127
+ *
128
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/flex
129
+ */
130
+ export type Flex = 1 | "1" | "auto" | "initial" | "none";
131
+
132
+ /**
133
+ * The range of values for `flex-direction`.
134
+ *
135
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/flex-direction
136
+ */
137
+ export type FlexDirection = "row" | "row-reverse" | "column" | "column-reverse";
138
+
139
+ /**
140
+ * The range of values for `flex-wrap`.
141
+ *
142
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap
143
+ */
144
+ export type FlexWrap = "nowrap" | "wrap" | "wrap-reverse";
145
+
146
+ /**
147
+ * The range of values for `justify-content`.
148
+ *
149
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content
150
+ */
151
+ export type JustifyContent =
152
+ | "start"
153
+ | "center"
154
+ | "end"
155
+ | "space-between"
156
+ | "space-around"
157
+ | "space-evenly"
158
+ | "stretch"
159
+ | "normal";
160
+
161
+ /**
162
+ * The range of values for `justify-items`.
163
+ *
164
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/justify-items
165
+ */
166
+ export type JustifyItems = "start" | "end" | "center" | "stretch";
167
+
168
+ /**
169
+ * The range of values for `justify-self`.
170
+ *
171
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/justify-self
172
+ */
173
+ export type JustifySelf = "auto" | "start" | "end" | "center" | "stretch";
174
+
175
+ /**
176
+ * The range of values for `overflow`.
177
+ *
178
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/overflow
179
+ */
180
+ export type Overflow = "visible" | "hidden" | "scroll" | "auto";
181
+
182
+ /**
183
+ * The range of values for `position`.
184
+ *
185
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/position
186
+ */
187
+ export type Position = "static" | "absolute" | "relative" | "fixed" | "sticky";
188
+
189
+ /**
190
+ * Props for the `<Box>` component.
191
+ *
192
+ * Extends standard HTML div props with Box-specific layout props.
193
+ */
194
+ export interface BoxProps extends React.ComponentPropsWithoutRef<"div"> {
195
+ /**
196
+ * When true, `<Box>` will **not** render an extra wrapper element. Instead, it will
197
+ * clone & enhance its single child element, merging class names and props.
198
+ */
199
+ asChild?: boolean;
200
+
201
+ /** Shorthand for the CSS `gap` property (applies to flex and grid layouts). */
202
+ gap?: Gap;
203
+
204
+ // ────────────────────────────────────────────────────────────
205
+ // Margin
206
+ // ────────────────────────────────────────────────────────────
207
+
208
+ /** CSS `margin` */
209
+ margin?: Margin;
210
+ /** CSS `margin-inline` */
211
+ marginX?: Margin;
212
+ /** CSS `margin-inline-start` */
213
+ marginXStart?: Margin;
214
+ /** CSS `margin-inline-end` */
215
+ marginXEnd?: Margin;
216
+ /** CSS `margin-block` */
217
+ marginY?: Margin;
218
+ /** CSS `margin-block-start` */
219
+ marginYStart?: Margin;
220
+ /** CSS `margin-block-end` */
221
+ marginYEnd?: Margin;
222
+ /** CSS `margin-top` */
223
+ marginTop?: Margin;
224
+ /** CSS `margin-right` */
225
+ marginRight?: Margin;
226
+ /** CSS `margin-bottom` */
227
+ marginBottom?: Margin;
228
+ /** CSS `margin-left` */
229
+ marginLeft?: Margin;
230
+
231
+ // ────────────────────────────────────────────────────────────
232
+ // Padding
233
+ // ────────────────────────────────────────────────────────────
234
+
235
+ /** CSS `padding` */
236
+ padding?: Padding;
237
+ /** CSS `padding-inline` */
238
+ paddingX?: Padding;
239
+ /** CSS `padding-inline-start` */
240
+ paddingXStart?: Padding;
241
+ /** CSS `padding-inline-end` */
242
+ paddingXEnd?: Padding;
243
+ /** CSS `padding-block` */
244
+ paddingY?: Padding;
245
+ /** CSS `padding-block-start` */
246
+ paddingYStart?: Padding;
247
+ /** CSS `padding-block-end` */
248
+ paddingYEnd?: Padding;
249
+ /** CSS `padding-top` */
250
+ paddingTop?: Padding;
251
+ /** CSS `padding-right` */
252
+ paddingRight?: Padding;
253
+ /** CSS `padding-bottom` */
254
+ paddingBottom?: Padding;
255
+ /** CSS `padding-left` */
256
+ paddingLeft?: Padding;
257
+
258
+ // ────────────────────────────────────────────────────────────
259
+ // Inset
260
+ // ────────────────────────────────────────────────────────────
261
+
262
+ /** CSS `inset` */
263
+ inset?: Inset;
264
+ /** CSS `inset-inline` */
265
+ insetX?: Inset;
266
+ /** CSS `inset-inline-start` */
267
+ insetXStart?: Inset;
268
+ /** CSS `inset-inline-end` */
269
+ insetXEnd?: Inset;
270
+ /** CSS `inset-block` */
271
+ insetY?: Inset;
272
+ /** CSS `inset-block-start` */
273
+ insetYStart?: Inset;
274
+ /** CSS `inset-block-end` */
275
+ insetYEnd?: Inset;
276
+ /** CSS `top` */
277
+ insetTop?: Inset;
278
+ /** CSS `right` */
279
+ insetRight?: Inset;
280
+ /** CSS `bottom` */
281
+ insetBottom?: Inset;
282
+ /** CSS `left` */
283
+ insetLeft?: Inset;
284
+
285
+ // ────────────────────────────────────────────────────────────
286
+ // Size
287
+ // ────────────────────────────────────────────────────────────
288
+
289
+ /** CSS `width` */
290
+ width?: Width;
291
+ /** CSS `height` */
292
+ height?: Height;
293
+
294
+ // ────────────────────────────────────────────────────────────
295
+ // Flexbox & Grid alignment
296
+ // ────────────────────────────────────────────────────────────
297
+
298
+ /** CSS `align-content` */
299
+ alignContent?: AlignContent;
300
+ /** CSS `align-items` */
301
+ alignItems?: AlignItems;
302
+ /** CSS `align-self` */
303
+ alignSelf?: AlignSelf;
304
+
305
+ /** CSS `display` */
306
+ display?: Display;
307
+ /** CSS `flex` (shorthand for `flex-grow`, `flex-shrink`, `flex-basis`) */
308
+ flex?: Flex;
309
+ /** CSS `flex-direction` */
310
+ flexDirection?: FlexDirection;
311
+ /** CSS `flex-wrap` */
312
+ flexWrap?: FlexWrap;
313
+
314
+ /** CSS `justify-content` */
315
+ justifyContent?: JustifyContent;
316
+ /** CSS `justify-items` */
317
+ justifyItems?: JustifyItems;
318
+ /** CSS `justify-self` */
319
+ justifySelf?: JustifySelf;
320
+
321
+ // ────────────────────────────────────────────────────────────
322
+ // Position & Overflow
323
+ // ────────────────────────────────────────────────────────────
324
+
325
+ /** CSS `position` */
326
+ position?: Position;
327
+
328
+ /** CSS `overflow` */
329
+ overflow?: Overflow;
330
+ /** CSS `overflow-x` */
331
+ overflowX?: Overflow;
332
+ /** CSS `overflow-y` */
333
+ overflowY?: Overflow;
334
+ }
@@ -0,0 +1,307 @@
1
+ /* !
2
+ * (c) Copyright 2025 Palantir Technologies Inc. All rights reserved.
3
+ */
4
+
5
+ /* eslint-disable sort-keys */
6
+
7
+ import { Classes } from "../../common";
8
+
9
+ import type {
10
+ AlignContent,
11
+ AlignItems,
12
+ AlignSelf,
13
+ Display,
14
+ Flex,
15
+ FlexDirection,
16
+ FlexWrap,
17
+ Gap,
18
+ Height,
19
+ Inset,
20
+ JustifyContent,
21
+ JustifyItems,
22
+ JustifySelf,
23
+ Margin,
24
+ Overflow,
25
+ Padding,
26
+ Position,
27
+ Width,
28
+ } from "./boxProps";
29
+
30
+ const NS = Classes.getClassNamespace();
31
+
32
+ /**
33
+ * Runtime helper that converts <Box> style-props into utility class names.
34
+ *
35
+ * The implementation is intentionally simple:
36
+ * 1. A prop key that exists in the `styles` map is considered a style prop.
37
+ * Its value is run through a converter (created via `appendValue` or
38
+ * `mapping`) which returns the corresponding class string, e.g.
39
+ * `display="flex"` → `"flex"`.
40
+ * 2. Any prop that is *not* in the map is assumed to be a valid intrinsic
41
+ * DOM attribute (e.g. `id`, `title`) or a component-specific prop and is
42
+ * therefore forwarded untouched.
43
+ *
44
+ * Returns an object with two pieces of information:
45
+ * • `generatedClassNames` – an array of class names to apply to the element.
46
+ * • `passThroughProps` – the remaining props to forward.
47
+ *
48
+ * @param props - The props object to convert.
49
+ * @returns An object with `generatedClassNames` and `passThroughProps`.
50
+ */
51
+ export function buildStyles<T extends Record<string, any>>(props: T) {
52
+ const classNames = new Set<string>();
53
+ const passThroughProps: Record<string, unknown> = {};
54
+
55
+ for (const [key, value] of Object.entries(props)) {
56
+ if (Object.prototype.hasOwnProperty.call(styles, key)) {
57
+ const className = styles[key]?.(value);
58
+ if (className != null) {
59
+ classNames.add(className);
60
+ }
61
+ } else {
62
+ passThroughProps[key] = value;
63
+ }
64
+ }
65
+
66
+ return { generatedClassNames: Array.from(classNames), passThroughProps };
67
+ }
68
+
69
+ function appendValue<T>(prefix: string) {
70
+ return (value: T) => `${NS}-${prefix}-${value}`;
71
+ }
72
+
73
+ function mapping<T extends string | number | symbol>(styleMap: Record<T, string>) {
74
+ return (value: T) => `${NS}-${styleMap[value]}`;
75
+ }
76
+
77
+ const gap = appendValue<Gap>("gap");
78
+
79
+ const margin = appendValue<Margin>("margin");
80
+ const marginX = appendValue<Margin>("margin-inline");
81
+ const marginXStart = appendValue<Margin>("margin-inline-start");
82
+ const marginXEnd = appendValue<Margin>("margin-inline-end");
83
+ const marginY = appendValue<Margin>("margin-block");
84
+ const marginYStart = appendValue<Margin>("margin-block-start");
85
+ const marginYEnd = appendValue<Margin>("margin-block-end");
86
+ const marginTop = appendValue<Margin>("margin-top");
87
+ const marginRight = appendValue<Margin>("margin-right");
88
+ const marginBottom = appendValue<Margin>("margin-bottom");
89
+ const marginLeft = appendValue<Margin>("margin-left");
90
+
91
+ const padding = appendValue<Padding>("padding");
92
+ const paddingX = appendValue<Padding>("padding-inline");
93
+ const paddingXStart = appendValue<Padding>("padding-inline-start");
94
+ const paddingXEnd = appendValue<Padding>("padding-inline-end");
95
+ const paddingY = appendValue<Padding>("padding-block");
96
+ const paddingYStart = appendValue<Padding>("padding-block-start");
97
+ const paddingYEnd = appendValue<Padding>("padding-block-end");
98
+ const paddingTop = appendValue<Padding>("padding-top");
99
+ const paddingRight = appendValue<Padding>("padding-right");
100
+ const paddingBottom = appendValue<Padding>("padding-bottom");
101
+ const paddingLeft = appendValue<Padding>("padding-left");
102
+
103
+ const width = mapping<Width>({
104
+ 25: "width-25",
105
+ 50: "width-50",
106
+ 75: "width-75",
107
+ 100: "width-100",
108
+ auto: "width-auto",
109
+ });
110
+
111
+ const height = mapping<Height>({
112
+ 25: "height-25",
113
+ 50: "height-50",
114
+ 75: "height-75",
115
+ 100: "height-100",
116
+ auto: "height-auto",
117
+ });
118
+
119
+ const inset = appendValue<Inset>("inset");
120
+ const insetX = appendValue<Inset>("inset-inline");
121
+ const insetXStart = appendValue<Inset>("inset-inline-start");
122
+ const insetXEnd = appendValue<Inset>("inset-inline-end");
123
+ const insetY = appendValue<Inset>("inset-block");
124
+ const insetYStart = appendValue<Inset>("inset-block-start");
125
+ const insetYEnd = appendValue<Inset>("inset-block-end");
126
+ const insetTop = appendValue<Inset>("inset-top");
127
+ const insetRight = appendValue<Inset>("inset-right");
128
+ const insetBottom = appendValue<Inset>("inset-bottom");
129
+ const insetLeft = appendValue<Inset>("inset-left");
130
+
131
+ const alignContent = mapping<AlignContent>({
132
+ start: "content-start",
133
+ center: "content-center",
134
+ end: "content-end",
135
+ "space-between": "content-between",
136
+ "space-around": "content-around",
137
+ "space-evenly": "content-evenly",
138
+ stretch: "content-stretch",
139
+ normal: "content-normal",
140
+ baseline: "content-baseline",
141
+ });
142
+
143
+ const alignItems = mapping<AlignItems>({
144
+ start: "items-start",
145
+ end: "items-end",
146
+ center: "items-center",
147
+ baseline: "items-baseline",
148
+ stretch: "items-stretch",
149
+ });
150
+
151
+ const alignSelf = mapping<AlignSelf>({
152
+ auto: "self-auto",
153
+ start: "self-start",
154
+ end: "self-end",
155
+ center: "self-center",
156
+ baseline: "self-baseline",
157
+ stretch: "self-stretch",
158
+ });
159
+
160
+ const display = mapping<Display>({
161
+ block: "block",
162
+ "inline-block": "inline-block",
163
+ inline: "inline",
164
+ flex: "flex",
165
+ "inline-flex": "inline-flex",
166
+ grid: "grid",
167
+ "inline-grid": "inline-grid",
168
+ table: "table",
169
+ "inline-table": "inline-table",
170
+ "table-row": "table-row",
171
+ "table-cell": "table-cell",
172
+ none: "none",
173
+ });
174
+
175
+ const flex = mapping<Flex>({
176
+ "1": "flex-1",
177
+ auto: "flex-auto",
178
+ initial: "flex-initial",
179
+ none: "flex-none",
180
+ });
181
+
182
+ const flexDirection = mapping<FlexDirection>({
183
+ row: "flex-row",
184
+ "row-reverse": "flex-row-reverse",
185
+ column: "flex-column",
186
+ "column-reverse": "flex-column-reverse",
187
+ });
188
+
189
+ const flexWrap = mapping<FlexWrap>({
190
+ nowrap: "flex-nowrap",
191
+ wrap: "flex-wrap",
192
+ "wrap-reverse": "flex-wrap-reverse",
193
+ });
194
+
195
+ const justifyContent = mapping<JustifyContent>({
196
+ start: "justify-start",
197
+ center: "justify-center",
198
+ end: "justify-end",
199
+ "space-between": "justify-between",
200
+ "space-around": "justify-around",
201
+ "space-evenly": "justify-evenly",
202
+ normal: "justify-normal",
203
+ stretch: "justify-stretch",
204
+ });
205
+
206
+ const justifyItems = mapping<JustifyItems>({
207
+ start: "justify-items-start",
208
+ end: "justify-items-end",
209
+ center: "justify-items-center",
210
+ stretch: "justify-items-stretch",
211
+ });
212
+
213
+ const justifySelf = mapping<JustifySelf>({
214
+ auto: "justify-self-auto",
215
+ start: "justify-self-start",
216
+ end: "justify-self-end",
217
+ center: "justify-self-center",
218
+ stretch: "justify-self-stretch",
219
+ });
220
+
221
+ const position = mapping<Position>({
222
+ static: "static",
223
+ relative: "relative",
224
+ absolute: "absolute",
225
+ fixed: "fixed",
226
+ sticky: "sticky",
227
+ });
228
+
229
+ const overflow = mapping<Overflow>({
230
+ visible: "overflow-visible",
231
+ hidden: "overflow-hidden",
232
+ scroll: "overflow-scroll",
233
+ auto: "overflow-auto",
234
+ });
235
+
236
+ const overflowX = mapping<Overflow>({
237
+ visible: "overflow-x-visible",
238
+ hidden: "overflow-x-hidden",
239
+ scroll: "overflow-x-scroll",
240
+ auto: "overflow-x-auto",
241
+ });
242
+
243
+ const overflowY = mapping<Overflow>({
244
+ visible: "overflow-y-visible",
245
+ hidden: "overflow-y-hidden",
246
+ scroll: "overflow-y-scroll",
247
+ auto: "overflow-y-auto",
248
+ });
249
+
250
+ // Look-up table of style-prop name → converter function
251
+ const styles: Record<string, (value: any) => string> = {
252
+ gap,
253
+
254
+ margin,
255
+ marginX,
256
+ marginXStart,
257
+ marginXEnd,
258
+ marginY,
259
+ marginYStart,
260
+ marginYEnd,
261
+ marginTop,
262
+ marginRight,
263
+ marginBottom,
264
+ marginLeft,
265
+
266
+ padding,
267
+ paddingX,
268
+ paddingXStart,
269
+ paddingXEnd,
270
+ paddingY,
271
+ paddingYStart,
272
+ paddingYEnd,
273
+ paddingTop,
274
+ paddingRight,
275
+ paddingBottom,
276
+ paddingLeft,
277
+
278
+ inset,
279
+ insetX,
280
+ insetXStart,
281
+ insetXEnd,
282
+ insetY,
283
+ insetYStart,
284
+ insetYEnd,
285
+ insetTop,
286
+ insetRight,
287
+ insetBottom,
288
+ insetLeft,
289
+
290
+ width,
291
+ height,
292
+
293
+ alignContent,
294
+ alignItems,
295
+ alignSelf,
296
+ display,
297
+ flex,
298
+ flexDirection,
299
+ flexWrap,
300
+ justifyContent,
301
+ justifyItems,
302
+ justifySelf,
303
+ position,
304
+ overflow,
305
+ overflowX,
306
+ overflowY,
307
+ };