@dashforge/tw 0.1.0-beta → 0.2.1-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/A11Y.md +130 -0
- package/CHANGELOG.md +231 -0
- package/dist/index.d.ts +1 -82
- package/dist/index.esm.js +1608 -11
- package/dist/src/components/AspectRatio/AspectRatio.d.ts +36 -0
- package/dist/src/components/AspectRatio/AspectRatio.d.ts.map +1 -0
- package/dist/src/components/AspectRatio/aspectRatio.types.d.ts +50 -0
- package/dist/src/components/AspectRatio/aspectRatio.types.d.ts.map +1 -0
- package/dist/src/components/Box/Box.d.ts +36 -0
- package/dist/src/components/Box/Box.d.ts.map +1 -0
- package/dist/src/components/Box/box.types.d.ts +54 -0
- package/dist/src/components/Box/box.types.d.ts.map +1 -0
- package/dist/src/components/Box/box.variants.d.ts +402 -0
- package/dist/src/components/Box/box.variants.d.ts.map +1 -0
- package/dist/src/components/Button/Button.d.ts.map +1 -1
- package/dist/src/components/Checkbox/Checkbox.d.ts.map +1 -1
- package/dist/src/components/Container/Container.d.ts +35 -0
- package/dist/src/components/Container/Container.d.ts.map +1 -0
- package/dist/src/components/Container/container.types.d.ts +41 -0
- package/dist/src/components/Container/container.types.d.ts.map +1 -0
- package/dist/src/components/Container/container.variants.d.ts +93 -0
- package/dist/src/components/Container/container.variants.d.ts.map +1 -0
- package/dist/src/components/Divider/Divider.d.ts +50 -0
- package/dist/src/components/Divider/Divider.d.ts.map +1 -0
- package/dist/src/components/Divider/divider.types.d.ts +47 -0
- package/dist/src/components/Divider/divider.types.d.ts.map +1 -0
- package/dist/src/components/Divider/divider.variants.d.ts +129 -0
- package/dist/src/components/Divider/divider.variants.d.ts.map +1 -0
- package/dist/src/components/Grid/Grid.d.ts +32 -0
- package/dist/src/components/Grid/Grid.d.ts.map +1 -0
- package/dist/src/components/Grid/grid.types.d.ts +103 -0
- package/dist/src/components/Grid/grid.types.d.ts.map +1 -0
- package/dist/src/components/Grid/grid.variants.d.ts +453 -0
- package/dist/src/components/Grid/grid.variants.d.ts.map +1 -0
- package/dist/src/components/NumberField/NumberField.d.ts.map +1 -1
- package/dist/src/components/RadioGroup/RadioGroup.d.ts.map +1 -1
- package/dist/src/components/Stack/Stack.d.ts +24 -0
- package/dist/src/components/Stack/Stack.d.ts.map +1 -0
- package/dist/src/components/Stack/stack.types.d.ts +61 -0
- package/dist/src/components/Stack/stack.types.d.ts.map +1 -0
- package/dist/src/components/Stack/stack.variants.d.ts +163 -0
- package/dist/src/components/Stack/stack.variants.d.ts.map +1 -0
- package/dist/src/components/Typography/Typography.d.ts +42 -0
- package/dist/src/components/Typography/Typography.d.ts.map +1 -0
- package/dist/src/components/Typography/typography.types.d.ts +61 -0
- package/dist/src/components/Typography/typography.types.d.ts.map +1 -0
- package/dist/src/components/Typography/typography.variants.d.ts +167 -0
- package/dist/src/components/Typography/typography.variants.d.ts.map +1 -0
- package/dist/src/components/VisuallyHidden/VisuallyHidden.d.ts +42 -0
- package/dist/src/components/VisuallyHidden/VisuallyHidden.d.ts.map +1 -0
- package/dist/src/components/VisuallyHidden/visuallyHidden.types.d.ts +42 -0
- package/dist/src/components/VisuallyHidden/visuallyHidden.types.d.ts.map +1 -0
- package/dist/src/index.d.ts +23 -1
- package/dist/src/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/components/AspectRatio/AspectRatio.test.tsx +173 -0
- package/src/components/AspectRatio/AspectRatio.tsx +73 -0
- package/src/components/AspectRatio/aspectRatio.types.ts +54 -0
- package/src/components/Box/Box.test.tsx +349 -0
- package/src/components/Box/Box.tsx +83 -0
- package/src/components/Box/box.types.ts +61 -0
- package/src/components/Box/box.variants.ts +211 -0
- package/src/components/Button/Button.tsx +11 -0
- package/src/components/Checkbox/Checkbox.tsx +26 -2
- package/src/components/Container/Container.test.tsx +209 -0
- package/src/components/Container/Container.tsx +74 -0
- package/src/components/Container/container.types.ts +45 -0
- package/src/components/Container/container.variants.ts +81 -0
- package/src/components/Divider/Divider.test.tsx +241 -0
- package/src/components/Divider/Divider.tsx +140 -0
- package/src/components/Divider/divider.types.ts +52 -0
- package/src/components/Divider/divider.variants.ts +115 -0
- package/src/components/Grid/Grid.test.tsx +321 -0
- package/src/components/Grid/Grid.tsx +148 -0
- package/src/components/Grid/grid.types.ts +112 -0
- package/src/components/Grid/grid.variants.ts +133 -0
- package/src/components/NumberField/NumberField.tsx +30 -2
- package/src/components/RadioGroup/RadioGroup.tsx +23 -1
- package/src/components/Stack/Stack.test.tsx +309 -0
- package/src/components/Stack/Stack.tsx +115 -0
- package/src/components/Stack/stack.types.ts +68 -0
- package/src/components/Stack/stack.variants.ts +80 -0
- package/src/components/Typography/Typography.test.tsx +230 -0
- package/src/components/Typography/Typography.tsx +112 -0
- package/src/components/Typography/typography.types.ts +65 -0
- package/src/components/Typography/typography.variants.ts +113 -0
- package/src/components/VisuallyHidden/VisuallyHidden.test.tsx +86 -0
- package/src/components/VisuallyHidden/VisuallyHidden.tsx +59 -0
- package/src/components/VisuallyHidden/visuallyHidden.types.ts +45 -0
- package/src/index.ts +50 -1
- package/LICENSE +0 -21
- package/dist/components/AppShell/AppShell.d.ts +0 -32
- package/dist/components/AppShell/AppShell.d.ts.map +0 -1
- package/dist/components/AppShell/appShell.types.d.ts +0 -62
- package/dist/components/AppShell/appShell.types.d.ts.map +0 -1
- package/dist/components/AppShell/appShell.variants.d.ts +0 -65
- package/dist/components/AppShell/appShell.variants.d.ts.map +0 -1
- package/dist/components/Autocomplete/Autocomplete.d.ts +0 -32
- package/dist/components/Autocomplete/Autocomplete.d.ts.map +0 -1
- package/dist/components/Autocomplete/autocomplete.types.d.ts +0 -214
- package/dist/components/Autocomplete/autocomplete.types.d.ts.map +0 -1
- package/dist/components/Autocomplete/autocomplete.variants.d.ts +0 -214
- package/dist/components/Autocomplete/autocomplete.variants.d.ts.map +0 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +0 -23
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts.map +0 -1
- package/dist/components/Breadcrumbs/breadcrumbs.types.d.ts +0 -98
- package/dist/components/Breadcrumbs/breadcrumbs.types.d.ts.map +0 -1
- package/dist/components/Breadcrumbs/breadcrumbs.variants.d.ts +0 -85
- package/dist/components/Breadcrumbs/breadcrumbs.variants.d.ts.map +0 -1
- package/dist/components/Button/Button.d.ts +0 -44
- package/dist/components/Button/Button.d.ts.map +0 -1
- package/dist/components/Button/button.types.d.ts +0 -66
- package/dist/components/Button/button.types.d.ts.map +0 -1
- package/dist/components/Button/button.variants.d.ts +0 -104
- package/dist/components/Button/button.variants.d.ts.map +0 -1
- package/dist/components/Checkbox/Checkbox.d.ts +0 -31
- package/dist/components/Checkbox/Checkbox.d.ts.map +0 -1
- package/dist/components/Checkbox/checkbox.types.d.ts +0 -86
- package/dist/components/Checkbox/checkbox.types.d.ts.map +0 -1
- package/dist/components/Checkbox/checkbox.variants.d.ts +0 -109
- package/dist/components/Checkbox/checkbox.variants.d.ts.map +0 -1
- package/dist/components/ConfirmDialog/ConfirmDialog.d.ts +0 -38
- package/dist/components/ConfirmDialog/ConfirmDialog.d.ts.map +0 -1
- package/dist/components/ConfirmDialog/confirmDialog.types.d.ts +0 -80
- package/dist/components/ConfirmDialog/confirmDialog.types.d.ts.map +0 -1
- package/dist/components/ConfirmDialog/confirmDialog.variants.d.ts +0 -90
- package/dist/components/ConfirmDialog/confirmDialog.variants.d.ts.map +0 -1
- package/dist/components/DateTimePicker/DateTimePicker.d.ts +0 -49
- package/dist/components/DateTimePicker/DateTimePicker.d.ts.map +0 -1
- package/dist/components/DateTimePicker/dateTimePicker.types.d.ts +0 -95
- package/dist/components/DateTimePicker/dateTimePicker.types.d.ts.map +0 -1
- package/dist/components/DateTimePicker/dateTimePicker.variants.d.ts +0 -165
- package/dist/components/DateTimePicker/dateTimePicker.variants.d.ts.map +0 -1
- package/dist/components/LeftNav/LeftNav.d.ts +0 -34
- package/dist/components/LeftNav/LeftNav.d.ts.map +0 -1
- package/dist/components/LeftNav/leftNav.types.d.ts +0 -136
- package/dist/components/LeftNav/leftNav.types.d.ts.map +0 -1
- package/dist/components/LeftNav/leftNav.variants.d.ts +0 -143
- package/dist/components/LeftNav/leftNav.variants.d.ts.map +0 -1
- package/dist/components/NumberField/NumberField.d.ts +0 -18
- package/dist/components/NumberField/NumberField.d.ts.map +0 -1
- package/dist/components/NumberField/numberField.types.d.ts +0 -79
- package/dist/components/NumberField/numberField.types.d.ts.map +0 -1
- package/dist/components/NumberField/numberField.variants.d.ts +0 -169
- package/dist/components/NumberField/numberField.variants.d.ts.map +0 -1
- package/dist/components/OTPField/OTPField.d.ts +0 -25
- package/dist/components/OTPField/OTPField.d.ts.map +0 -1
- package/dist/components/OTPField/otpField.types.d.ts +0 -74
- package/dist/components/OTPField/otpField.types.d.ts.map +0 -1
- package/dist/components/OTPField/otpField.variants.d.ts +0 -105
- package/dist/components/OTPField/otpField.variants.d.ts.map +0 -1
- package/dist/components/RadioGroup/RadioGroup.d.ts +0 -35
- package/dist/components/RadioGroup/RadioGroup.d.ts.map +0 -1
- package/dist/components/RadioGroup/radioGroup.types.d.ts +0 -103
- package/dist/components/RadioGroup/radioGroup.types.d.ts.map +0 -1
- package/dist/components/RadioGroup/radioGroup.variants.d.ts +0 -166
- package/dist/components/RadioGroup/radioGroup.variants.d.ts.map +0 -1
- package/dist/components/Snackbar/Snackbar.d.ts +0 -37
- package/dist/components/Snackbar/Snackbar.d.ts.map +0 -1
- package/dist/components/Snackbar/snackbar.types.d.ts +0 -86
- package/dist/components/Snackbar/snackbar.types.d.ts.map +0 -1
- package/dist/components/Snackbar/snackbar.variants.d.ts +0 -153
- package/dist/components/Snackbar/snackbar.variants.d.ts.map +0 -1
- package/dist/components/Switch/Switch.d.ts +0 -15
- package/dist/components/Switch/Switch.d.ts.map +0 -1
- package/dist/components/Switch/switch.types.d.ts +0 -47
- package/dist/components/Switch/switch.types.d.ts.map +0 -1
- package/dist/components/Switch/switch.variants.d.ts +0 -105
- package/dist/components/Switch/switch.variants.d.ts.map +0 -1
- package/dist/components/TextField/TextField.d.ts +0 -25
- package/dist/components/TextField/TextField.d.ts.map +0 -1
- package/dist/components/TextField/textField.types.d.ts +0 -72
- package/dist/components/TextField/textField.types.d.ts.map +0 -1
- package/dist/components/TextField/textField.variants.d.ts +0 -160
- package/dist/components/TextField/textField.variants.d.ts.map +0 -1
- package/dist/components/Textarea/Textarea.d.ts +0 -16
- package/dist/components/Textarea/Textarea.d.ts.map +0 -1
- package/dist/components/Textarea/textarea.types.d.ts +0 -63
- package/dist/components/Textarea/textarea.types.d.ts.map +0 -1
- package/dist/components/Textarea/textarea.variants.d.ts +0 -197
- package/dist/components/Textarea/textarea.variants.d.ts.map +0 -1
- package/dist/components/TopBar/TopBar.d.ts +0 -33
- package/dist/components/TopBar/TopBar.d.ts.map +0 -1
- package/dist/components/TopBar/topBar.types.d.ts +0 -49
- package/dist/components/TopBar/topBar.types.d.ts.map +0 -1
- package/dist/components/TopBar/topBar.variants.d.ts +0 -79
- package/dist/components/TopBar/topBar.variants.d.ts.map +0 -1
- package/dist/components/_shared/resolveValidationState.d.ts +0 -42
- package/dist/components/_shared/resolveValidationState.d.ts.map +0 -1
- package/dist/hooks/useAccessState.d.ts +0 -37
- package/dist/hooks/useAccessState.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/tsconfig.lib.tsbuildinfo +0 -1
- package/dist/utils/cn.d.ts +0 -26
- package/dist/utils/cn.d.ts.map +0 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { ElementType, HTMLAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Grid types — discriminated union for container vs item role.
|
|
5
|
+
*
|
|
6
|
+
* Pattern is MUI v2: a single `<Grid>` component that switches role
|
|
7
|
+
* based on the `container` prop. Container exposes layout axes
|
|
8
|
+
* (cols, spacing, autoFlow). Item exposes per-breakpoint span axes
|
|
9
|
+
* (xs/sm/md/lg/xl).
|
|
10
|
+
*
|
|
11
|
+
* TypeScript-level enforcement (the key win over MUI):
|
|
12
|
+
* • `<Grid container xs={6}>` is a TYPE ERROR — `xs` doesn't exist
|
|
13
|
+
* on the container shape.
|
|
14
|
+
* • `<Grid xs={6} spacing={4}>` is a TYPE ERROR — `spacing` doesn't
|
|
15
|
+
* exist on the item shape.
|
|
16
|
+
* IntelliSense filters suggestions per role, so the developer never
|
|
17
|
+
* sees props that don't apply.
|
|
18
|
+
*
|
|
19
|
+
* Type-only file (no runtime). Lives separate from the variants so the
|
|
20
|
+
* union doesn't widen with the variant catalogue's enum unions.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Valid column-span values for a grid item, at any breakpoint.
|
|
25
|
+
* • 1..12 — explicit span count
|
|
26
|
+
* • 'auto' — content-sized (CSS Grid auto-track)
|
|
27
|
+
* • 'full' — `col-span-full` (spans all columns regardless of count)
|
|
28
|
+
*/
|
|
29
|
+
export type ColSpan =
|
|
30
|
+
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12
|
|
31
|
+
| 'auto'
|
|
32
|
+
| 'full';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Token-scale spacing step. Mirror of Box.p / Stack.gap so the value
|
|
36
|
+
* space across primitives is identical — `<Grid container spacing={4}>`
|
|
37
|
+
* and `<Stack gap={4}>` produce visually equivalent gaps.
|
|
38
|
+
*/
|
|
39
|
+
export type GridSpacingStep =
|
|
40
|
+
| 0 | '0.5' | 1 | 2 | 3 | 4 | 6 | 8 | 12 | 16 | 24;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Container-role props. Discriminated on `container: true`.
|
|
44
|
+
*
|
|
45
|
+
* NOTE on `cols`: defaults to 12 in the component implementation
|
|
46
|
+
* (not in TV) — the MUI v2 convention. Override to 6/4/3/2/1 for
|
|
47
|
+
* dense dashboard layouts.
|
|
48
|
+
*/
|
|
49
|
+
export interface GridContainerProps {
|
|
50
|
+
/** Discriminator — `true` makes this a grid container. */
|
|
51
|
+
container: true;
|
|
52
|
+
/** Number of columns. Default 12. */
|
|
53
|
+
cols?: 1 | 2 | 3 | 4 | 6 | 12;
|
|
54
|
+
/** Gap between cells. Shorthand for spacingX + spacingY. */
|
|
55
|
+
spacing?: GridSpacingStep;
|
|
56
|
+
/** Horizontal gap override (wins over `spacing`). */
|
|
57
|
+
spacingX?: GridSpacingStep;
|
|
58
|
+
/** Vertical gap override (wins over `spacing`). */
|
|
59
|
+
spacingY?: GridSpacingStep;
|
|
60
|
+
/** `grid-auto-flow` — useful for dense or column-major packing. */
|
|
61
|
+
autoFlow?: 'row' | 'col' | 'dense' | 'row-dense' | 'col-dense';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Item-role props. Discriminated on `container: false | undefined`.
|
|
66
|
+
*
|
|
67
|
+
* Each breakpoint accepts a `ColSpan`. The cascade is Tailwind-native
|
|
68
|
+
* mobile-first: `xs` is the base (no media query), `sm/md/lg/xl`
|
|
69
|
+
* override at the corresponding min-width.
|
|
70
|
+
*
|
|
71
|
+
* Default behaviour when no breakpoint is set: spans `full` — the
|
|
72
|
+
* "comfortable default" so a forgotten prop doesn't collapse the cell
|
|
73
|
+
* to 1/12th of a row.
|
|
74
|
+
*/
|
|
75
|
+
export interface GridItemProps {
|
|
76
|
+
/** Discriminator — absent (or `false`) makes this a grid item. */
|
|
77
|
+
container?: false;
|
|
78
|
+
/** Base breakpoint (no media query). Default `'full'`. */
|
|
79
|
+
xs?: ColSpan;
|
|
80
|
+
/** Span at sm breakpoint and up. */
|
|
81
|
+
sm?: ColSpan;
|
|
82
|
+
/** Span at md breakpoint and up. */
|
|
83
|
+
md?: ColSpan;
|
|
84
|
+
/** Span at lg breakpoint and up. */
|
|
85
|
+
lg?: ColSpan;
|
|
86
|
+
/** Span at xl breakpoint and up. */
|
|
87
|
+
xl?: ColSpan;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Common props shared by both roles. Kept in a separate intersection
|
|
92
|
+
* so the discriminated union stays narrow and IntelliSense fast.
|
|
93
|
+
*/
|
|
94
|
+
interface GridCommonProps extends Omit<HTMLAttributes<HTMLDivElement>, 'className'> {
|
|
95
|
+
/** Override the rendered HTML tag. Default `'div'`. Ignored under `asChild`. */
|
|
96
|
+
as?: ElementType;
|
|
97
|
+
/**
|
|
98
|
+
* Render via Radix Slot onto the single child. Wins over `as`.
|
|
99
|
+
* Note: container Grids using `asChild` don't make sense for most
|
|
100
|
+
* cases — the Slot pattern collapses our wrapper, but Grid's
|
|
101
|
+
* `display:grid` only applies to direct children, so the child
|
|
102
|
+
* needs to BE a container with the right children.
|
|
103
|
+
*/
|
|
104
|
+
asChild?: boolean;
|
|
105
|
+
/** Utility-class override, merged via tailwind-merge. */
|
|
106
|
+
sx?: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* `<Grid>` props — discriminated union: container OR item, never both.
|
|
111
|
+
*/
|
|
112
|
+
export type GridProps = (GridContainerProps | GridItemProps) & GridCommonProps;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { tv, type VariantProps } from 'tailwind-variants';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `gridVariants` — CSS Grid container + item, polymorphic in role.
|
|
5
|
+
*
|
|
6
|
+
* Architectural choice (planned with the user — F9 deep dive):
|
|
7
|
+
*
|
|
8
|
+
* Pattern is MUI Grid v2 from the API side (`<Grid container>` +
|
|
9
|
+
* `<Grid xs={6}>`), but engine is REAL CSS Grid under the hood
|
|
10
|
+
* (`display: grid` + `grid-template-columns: repeat(N, 1fr)` +
|
|
11
|
+
* `col-span-*`). MUI v2 uses flexbox + basis percentages — historical
|
|
12
|
+
* IE11 reasons. In 2026, CSS Grid is universally supported AND
|
|
13
|
+
* Tailwind ships `grid-cols-*` / `col-span-*` natively, so flexbox
|
|
14
|
+
* would be a downgrade.
|
|
15
|
+
*
|
|
16
|
+
* Two distinct shapes coexist in the same TV recipe:
|
|
17
|
+
*
|
|
18
|
+
* • container=true — display:grid + cols + gap + autoFlow
|
|
19
|
+
* • container=false — col-span at each breakpoint (xs/sm/md/lg/xl)
|
|
20
|
+
*
|
|
21
|
+
* The discriminated union lives in grid.types.ts (TypeScript-level);
|
|
22
|
+
* here the TV catalogue exposes every axis so the consumer's choice
|
|
23
|
+
* triggers the right classes regardless of which role the component
|
|
24
|
+
* is playing. Unused axes produce no classes (TV silently drops
|
|
25
|
+
* undefined variants), so a container Grid never accidentally emits
|
|
26
|
+
* `col-span-6` and an item Grid never accidentally emits `grid`.
|
|
27
|
+
*
|
|
28
|
+
* Mapping table size:
|
|
29
|
+
* • cols : 6 entries (12, 6, 4, 3, 2, 1)
|
|
30
|
+
* • autoFlow : 5 entries
|
|
31
|
+
* • span axes (5×14) : 70 entries (xs/sm/md/lg/xl × {1..12, auto, full})
|
|
32
|
+
* • gap / gapX / gapY : 33 entries (11 steps × 3 axes)
|
|
33
|
+
*
|
|
34
|
+
* Total: ~115 literal class names. All explicit, all Tailwind-scannable.
|
|
35
|
+
* Bundle CSS impact when fully exercised: ~3 KB gz (mostly the
|
|
36
|
+
* responsive col-span set).
|
|
37
|
+
*/
|
|
38
|
+
export const gridVariants = tv({
|
|
39
|
+
base: '',
|
|
40
|
+
|
|
41
|
+
variants: {
|
|
42
|
+
// ─── CONTAINER role ────────────────────────────────────────────────
|
|
43
|
+
container: { true: 'grid' },
|
|
44
|
+
|
|
45
|
+
cols: {
|
|
46
|
+
1: 'grid-cols-1',
|
|
47
|
+
2: 'grid-cols-2',
|
|
48
|
+
3: 'grid-cols-3',
|
|
49
|
+
4: 'grid-cols-4',
|
|
50
|
+
6: 'grid-cols-6',
|
|
51
|
+
12: 'grid-cols-12',
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
autoFlow: {
|
|
55
|
+
row: 'grid-flow-row',
|
|
56
|
+
col: 'grid-flow-col',
|
|
57
|
+
dense: 'grid-flow-dense',
|
|
58
|
+
'row-dense':'grid-flow-row-dense',
|
|
59
|
+
'col-dense':'grid-flow-col-dense',
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
* Container gap — token-scale step. Same set as Box/Stack so muscle
|
|
64
|
+
* memory carries across primitives.
|
|
65
|
+
*/
|
|
66
|
+
spacing: {
|
|
67
|
+
0: 'gap-0', '0.5': 'gap-0.5', 1: 'gap-1', 2: 'gap-2', 3: 'gap-3',
|
|
68
|
+
4: 'gap-4', 6: 'gap-6', 8: 'gap-8', 12: 'gap-12', 16: 'gap-16',
|
|
69
|
+
24: 'gap-24',
|
|
70
|
+
},
|
|
71
|
+
spacingX: {
|
|
72
|
+
0: 'gap-x-0', '0.5': 'gap-x-0.5', 1: 'gap-x-1', 2: 'gap-x-2', 3: 'gap-x-3',
|
|
73
|
+
4: 'gap-x-4', 6: 'gap-x-6', 8: 'gap-x-8', 12: 'gap-x-12', 16: 'gap-x-16',
|
|
74
|
+
24: 'gap-x-24',
|
|
75
|
+
},
|
|
76
|
+
spacingY: {
|
|
77
|
+
0: 'gap-y-0', '0.5': 'gap-y-0.5', 1: 'gap-y-1', 2: 'gap-y-2', 3: 'gap-y-3',
|
|
78
|
+
4: 'gap-y-4', 6: 'gap-y-6', 8: 'gap-y-8', 12: 'gap-y-12', 16: 'gap-y-16',
|
|
79
|
+
24: 'gap-y-24',
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
// ─── ITEM role — col-span at each breakpoint ──────────────────────
|
|
83
|
+
/*
|
|
84
|
+
* `xs` is the base breakpoint (no prefix) — Tailwind's mobile-first
|
|
85
|
+
* convention. `sm/md/lg/xl` cascade up from there.
|
|
86
|
+
*
|
|
87
|
+
* Special values:
|
|
88
|
+
* • 'auto' → col-auto (content-sized)
|
|
89
|
+
* • 'full' → col-span-full (span all columns regardless of count)
|
|
90
|
+
*/
|
|
91
|
+
xs: {
|
|
92
|
+
1: 'col-span-1', 2: 'col-span-2', 3: 'col-span-3', 4: 'col-span-4',
|
|
93
|
+
5: 'col-span-5', 6: 'col-span-6', 7: 'col-span-7', 8: 'col-span-8',
|
|
94
|
+
9: 'col-span-9', 10: 'col-span-10', 11: 'col-span-11', 12: 'col-span-12',
|
|
95
|
+
auto: 'col-auto', full: 'col-span-full',
|
|
96
|
+
},
|
|
97
|
+
sm: {
|
|
98
|
+
1: 'sm:col-span-1', 2: 'sm:col-span-2', 3: 'sm:col-span-3', 4: 'sm:col-span-4',
|
|
99
|
+
5: 'sm:col-span-5', 6: 'sm:col-span-6', 7: 'sm:col-span-7', 8: 'sm:col-span-8',
|
|
100
|
+
9: 'sm:col-span-9', 10: 'sm:col-span-10', 11: 'sm:col-span-11', 12: 'sm:col-span-12',
|
|
101
|
+
auto: 'sm:col-auto', full: 'sm:col-span-full',
|
|
102
|
+
},
|
|
103
|
+
md: {
|
|
104
|
+
1: 'md:col-span-1', 2: 'md:col-span-2', 3: 'md:col-span-3', 4: 'md:col-span-4',
|
|
105
|
+
5: 'md:col-span-5', 6: 'md:col-span-6', 7: 'md:col-span-7', 8: 'md:col-span-8',
|
|
106
|
+
9: 'md:col-span-9', 10: 'md:col-span-10', 11: 'md:col-span-11', 12: 'md:col-span-12',
|
|
107
|
+
auto: 'md:col-auto', full: 'md:col-span-full',
|
|
108
|
+
},
|
|
109
|
+
lg: {
|
|
110
|
+
1: 'lg:col-span-1', 2: 'lg:col-span-2', 3: 'lg:col-span-3', 4: 'lg:col-span-4',
|
|
111
|
+
5: 'lg:col-span-5', 6: 'lg:col-span-6', 7: 'lg:col-span-7', 8: 'lg:col-span-8',
|
|
112
|
+
9: 'lg:col-span-9', 10: 'lg:col-span-10', 11: 'lg:col-span-11', 12: 'lg:col-span-12',
|
|
113
|
+
auto: 'lg:col-auto', full: 'lg:col-span-full',
|
|
114
|
+
},
|
|
115
|
+
xl: {
|
|
116
|
+
1: 'xl:col-span-1', 2: 'xl:col-span-2', 3: 'xl:col-span-3', 4: 'xl:col-span-4',
|
|
117
|
+
5: 'xl:col-span-5', 6: 'xl:col-span-6', 7: 'xl:col-span-7', 8: 'xl:col-span-8',
|
|
118
|
+
9: 'xl:col-span-9', 10: 'xl:col-span-10', 11: 'xl:col-span-11', 12: 'xl:col-span-12',
|
|
119
|
+
auto: 'xl:col-auto', full: 'xl:col-span-full',
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
/*
|
|
124
|
+
* No `defaultVariants`. The default semantics are role-dependent:
|
|
125
|
+
* • container Grid defaults to cols=12 (set in Grid.tsx)
|
|
126
|
+
* • item Grid defaults to xs="full" — full-width until a breakpoint
|
|
127
|
+
* prop overrides (also set in Grid.tsx)
|
|
128
|
+
* Encoding these defaults at the TV level would emit them even when
|
|
129
|
+
* irrelevant (e.g. an item Grid never wants `grid grid-cols-12`).
|
|
130
|
+
*/
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
export type GridVariants = VariantProps<typeof gridVariants>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useContext, useEffect, useId, useRef } from 'react';
|
|
1
|
+
import { useCallback, useContext, useEffect, useId, useRef, useState } from 'react';
|
|
2
2
|
import { DashFormContext, useEngineVisibility } from '@dashforge/ui-core';
|
|
3
3
|
import type { DashFormBridge, FieldRegistration } from '@dashforge/ui-core';
|
|
4
4
|
import { useDashFieldMeta } from '@dashforge/forms';
|
|
@@ -98,6 +98,22 @@ export function NumberField(props: NumberFieldProps) {
|
|
|
98
98
|
const accessState = useAccessState(access);
|
|
99
99
|
|
|
100
100
|
const inputId = useId();
|
|
101
|
+
|
|
102
|
+
/*
|
|
103
|
+
* Local state for the STANDALONE UNCONTROLLED case (no bridge, no
|
|
104
|
+
* `value` prop, only `defaultValue`). Mirrors OTPField. Without this,
|
|
105
|
+
* `resolvedDisplayValue` would be a snapshot computed ONCE from
|
|
106
|
+
* `defaultValue` and the controlled `<input value={...}>` would
|
|
107
|
+
* snap user input back on every keystroke / stepper click — same
|
|
108
|
+
* trap that hit Checkbox + RadioGroup in this package.
|
|
109
|
+
*
|
|
110
|
+
* In form mode the bridge owns state. In standalone CONTROLLED mode
|
|
111
|
+
* (consumer passes `value`) the consumer owns state. Only this
|
|
112
|
+
* branch needs the local hook.
|
|
113
|
+
*/
|
|
114
|
+
const [uncontrolledValue, setUncontrolledValue] = useState<string>(() =>
|
|
115
|
+
formatForDisplay(defaultValue)
|
|
116
|
+
);
|
|
101
117
|
const helperId = `${inputId}-help`;
|
|
102
118
|
|
|
103
119
|
// StrictMode-safe unregister-on-unmount
|
|
@@ -140,7 +156,7 @@ export function NumberField(props: NumberFieldProps) {
|
|
|
140
156
|
resolvedDisplayValue =
|
|
141
157
|
userValue !== undefined
|
|
142
158
|
? formatForDisplay(userValue)
|
|
143
|
-
:
|
|
159
|
+
: uncontrolledValue;
|
|
144
160
|
}
|
|
145
161
|
|
|
146
162
|
const writeToBridge = (parsed: number | null | undefined) => {
|
|
@@ -157,6 +173,13 @@ export function NumberField(props: NumberFieldProps) {
|
|
|
157
173
|
// internal logic still sees the raw string change.
|
|
158
174
|
void registration.onChange(e);
|
|
159
175
|
}
|
|
176
|
+
// Standalone uncontrolled mode: mirror the raw input string so the
|
|
177
|
+
// controlled `<input value={...}>` reflects what the user typed.
|
|
178
|
+
// Partial states (e.g. "-", "1.") are kept verbatim — `parseFromInput`
|
|
179
|
+
// returns `undefined` for them so `writeToBridge` is a no-op above.
|
|
180
|
+
if (!isFormMode && userValue === undefined) {
|
|
181
|
+
setUncontrolledValue(e.target.value);
|
|
182
|
+
}
|
|
160
183
|
userOnChange?.(e);
|
|
161
184
|
};
|
|
162
185
|
|
|
@@ -176,6 +199,11 @@ export function NumberField(props: NumberFieldProps) {
|
|
|
176
199
|
if (typeof min === 'number') next = Math.max(min, next);
|
|
177
200
|
if (typeof max === 'number') next = Math.min(max, next);
|
|
178
201
|
writeToBridge(next);
|
|
202
|
+
// Standalone uncontrolled: also persist the new value to local
|
|
203
|
+
// state so the visible display tracks the stepper click.
|
|
204
|
+
if (!isFormMode && userValue === undefined) {
|
|
205
|
+
setUncontrolledValue(formatForDisplay(next));
|
|
206
|
+
}
|
|
179
207
|
};
|
|
180
208
|
|
|
181
209
|
const canIncrement =
|
|
@@ -200,9 +200,31 @@ export function RadioGroup(props: RadioGroupProps) {
|
|
|
200
200
|
</div>
|
|
201
201
|
)}
|
|
202
202
|
|
|
203
|
+
{/*
|
|
204
|
+
* Radix RadioGroup mode discrimination — mirrors the same fix
|
|
205
|
+
* applied to <Checkbox>:
|
|
206
|
+
*
|
|
207
|
+
* - Form mode (bridge.register present): controlled — `value`
|
|
208
|
+
* comes from the reactive bridge snapshot, `handleValueChange`
|
|
209
|
+
* writes back through bridge.setValue.
|
|
210
|
+
* - Standalone controlled (consumer passes `value`): controlled —
|
|
211
|
+
* consumer owns state, `handleValueChange` forwards via
|
|
212
|
+
* `onValueChange`.
|
|
213
|
+
* - Standalone uncontrolled (only `defaultValue`): UNCONTROLLED —
|
|
214
|
+
* Radix owns the state. Previously this code passed
|
|
215
|
+
* `value={resolvedValue}` in this branch too, putting Radix
|
|
216
|
+
* in controlled mode with a stale snapshot that never updated,
|
|
217
|
+
* so user clicks fired Radix's onValueChange but the controlled
|
|
218
|
+
* prop never changed and the selection snapped right back.
|
|
219
|
+
*
|
|
220
|
+
* Picking exactly one of `{ value, ... }` or `{ defaultValue, ... }`
|
|
221
|
+
* lets Radix track its own state correctly when nobody else can.
|
|
222
|
+
*/}
|
|
203
223
|
<RadixRadioGroup.Root
|
|
204
224
|
name={name}
|
|
205
|
-
|
|
225
|
+
{...(isFormMode || explicitValue !== undefined
|
|
226
|
+
? { value: resolvedValue }
|
|
227
|
+
: { defaultValue: defaultValue ?? undefined })}
|
|
206
228
|
onValueChange={handleValueChange}
|
|
207
229
|
onBlur={handleBlur}
|
|
208
230
|
disabled={groupEffectiveDisabled}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { describe, it, expect } from 'vitest';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
import { Stack } from './Stack.js';
|
|
5
|
+
|
|
6
|
+
describe('<Stack>', () => {
|
|
7
|
+
// ─── Default rendering ──────────────────────────────────────────────
|
|
8
|
+
describe('default rendering', () => {
|
|
9
|
+
it('renders a <div> by default', () => {
|
|
10
|
+
const { container } = render(<Stack>x</Stack>);
|
|
11
|
+
expect(container.firstElementChild?.tagName).toBe('DIV');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('has flex + flex-col by default', () => {
|
|
15
|
+
const { container } = render(<Stack>x</Stack>);
|
|
16
|
+
const cls = container.firstElementChild?.className ?? '';
|
|
17
|
+
expect(cls).toContain('flex');
|
|
18
|
+
expect(cls).toContain('flex-col');
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// ─── Direction ──────────────────────────────────────────────────────
|
|
23
|
+
describe('direction', () => {
|
|
24
|
+
it('row', () => {
|
|
25
|
+
const { container } = render(<Stack direction="row">x</Stack>);
|
|
26
|
+
expect(container.firstElementChild?.className).toContain('flex-row');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('row-reverse', () => {
|
|
30
|
+
const { container } = render(<Stack direction="row-reverse">x</Stack>);
|
|
31
|
+
expect(container.firstElementChild?.className).toContain('flex-row-reverse');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// ─── Align + justify ────────────────────────────────────────────────
|
|
36
|
+
describe('align + justify', () => {
|
|
37
|
+
it('align="center" + justify="between"', () => {
|
|
38
|
+
const { container } = render(
|
|
39
|
+
<Stack align="center" justify="between">x</Stack>,
|
|
40
|
+
);
|
|
41
|
+
const cls = container.firstElementChild?.className ?? '';
|
|
42
|
+
expect(cls).toContain('items-center');
|
|
43
|
+
expect(cls).toContain('justify-between');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('align="baseline"', () => {
|
|
47
|
+
const { container } = render(<Stack align="baseline">x</Stack>);
|
|
48
|
+
expect(container.firstElementChild?.className).toContain('items-baseline');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// ─── Gap + wrap + sizing ────────────────────────────────────────────
|
|
53
|
+
describe('gap + wrap + sizing', () => {
|
|
54
|
+
it('gap={4} emits gap-4', () => {
|
|
55
|
+
const { container } = render(<Stack gap={4}>x</Stack>);
|
|
56
|
+
expect(container.firstElementChild?.className).toContain('gap-4');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('gap={"0.5"} emits gap-0.5', () => {
|
|
60
|
+
const { container } = render(<Stack gap="0.5">x</Stack>);
|
|
61
|
+
expect(container.firstElementChild?.className).toContain('gap-0.5');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('wrap emits flex-wrap', () => {
|
|
65
|
+
const { container } = render(<Stack wrap>x</Stack>);
|
|
66
|
+
expect(container.firstElementChild?.className).toContain('flex-wrap');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('fullWidth + fullHeight', () => {
|
|
70
|
+
const { container } = render(<Stack fullWidth fullHeight>x</Stack>);
|
|
71
|
+
const cls = container.firstElementChild?.className ?? '';
|
|
72
|
+
expect(cls).toContain('w-full');
|
|
73
|
+
expect(cls).toContain('h-full');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// ─── Divider ─────────────────────────────────────────────────────────
|
|
78
|
+
describe('divider', () => {
|
|
79
|
+
it('inserts N-1 dividers between N children', () => {
|
|
80
|
+
const { container } = render(
|
|
81
|
+
<Stack divider={<hr data-testid="div" />}>
|
|
82
|
+
<span>a</span>
|
|
83
|
+
<span>b</span>
|
|
84
|
+
<span>c</span>
|
|
85
|
+
</Stack>,
|
|
86
|
+
);
|
|
87
|
+
// 3 children + 2 dividers
|
|
88
|
+
expect(container.firstElementChild?.children.length).toBe(5);
|
|
89
|
+
const dividers = container.querySelectorAll('[data-testid="div"]');
|
|
90
|
+
expect(dividers.length).toBe(2);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('does NOT insert dividers when there is only one child', () => {
|
|
94
|
+
const { container } = render(
|
|
95
|
+
<Stack divider={<hr data-testid="div" />}>
|
|
96
|
+
<span>only</span>
|
|
97
|
+
</Stack>,
|
|
98
|
+
);
|
|
99
|
+
expect(container.firstElementChild?.children.length).toBe(1);
|
|
100
|
+
expect(container.querySelectorAll('[data-testid="div"]').length).toBe(0);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('treats a Fragment as a single child for divider boundary counting', () => {
|
|
104
|
+
const { container } = render(
|
|
105
|
+
<Stack divider={<hr data-testid="div" />}>
|
|
106
|
+
<>
|
|
107
|
+
<span>a</span>
|
|
108
|
+
<span>b</span>
|
|
109
|
+
</>
|
|
110
|
+
<span>c</span>
|
|
111
|
+
</Stack>,
|
|
112
|
+
);
|
|
113
|
+
// React.Children.toArray does NOT recursively flatten fragments — it
|
|
114
|
+
// treats them as opaque single children. Documented behaviour: 2
|
|
115
|
+
// top-level children → 1 divider between them. If you need a divider
|
|
116
|
+
// BETWEEN the items inside the fragment, hoist them out of it.
|
|
117
|
+
expect(container.querySelectorAll('[data-testid="div"]').length).toBe(1);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('renders string/number divider correctly', () => {
|
|
121
|
+
const { container } = render(
|
|
122
|
+
<Stack divider=" · ">
|
|
123
|
+
<span>a</span>
|
|
124
|
+
<span>b</span>
|
|
125
|
+
<span>c</span>
|
|
126
|
+
</Stack>,
|
|
127
|
+
);
|
|
128
|
+
expect(container.firstElementChild?.textContent).toBe('a · b · c');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('asChild silently ignores divider', () => {
|
|
132
|
+
const { container } = render(
|
|
133
|
+
<Stack asChild divider={<hr data-testid="div" />}>
|
|
134
|
+
<nav>
|
|
135
|
+
<a href="#">link</a>
|
|
136
|
+
</nav>
|
|
137
|
+
</Stack>,
|
|
138
|
+
);
|
|
139
|
+
// Slot wraps a single child — divider has nowhere to go
|
|
140
|
+
expect(container.firstElementChild?.tagName).toBe('NAV');
|
|
141
|
+
expect(container.querySelectorAll('[data-testid="div"]').length).toBe(0);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// ─── Override + sx ──────────────────────────────────────────────────
|
|
146
|
+
describe('override', () => {
|
|
147
|
+
it('sx wins over variant defaults', () => {
|
|
148
|
+
const { container } = render(
|
|
149
|
+
<Stack direction="row" sx="flex-col">x</Stack>,
|
|
150
|
+
);
|
|
151
|
+
const cls = container.firstElementChild?.className ?? '';
|
|
152
|
+
expect(cls).toContain('flex-col');
|
|
153
|
+
expect(cls).not.toContain('flex-row');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('sx can add utilities Stack does not expose (overflow)', () => {
|
|
157
|
+
const { container } = render(<Stack sx="overflow-x-auto">x</Stack>);
|
|
158
|
+
expect(container.firstElementChild?.className).toContain('overflow-x-auto');
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// ─── Polymorphism ───────────────────────────────────────────────────
|
|
163
|
+
describe('polymorphism', () => {
|
|
164
|
+
it('as="nav" renders a <nav>', () => {
|
|
165
|
+
const { container } = render(<Stack as="nav">x</Stack>);
|
|
166
|
+
expect(container.firstElementChild?.tagName).toBe('NAV');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('asChild wins over as', () => {
|
|
170
|
+
const { container } = render(
|
|
171
|
+
<Stack as="nav" asChild>
|
|
172
|
+
<header>x</header>
|
|
173
|
+
</Stack>,
|
|
174
|
+
);
|
|
175
|
+
expect(container.firstElementChild?.tagName).toBe('HEADER');
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// ─── Pass-through ────────────────────────────────────────────────────
|
|
180
|
+
it('forwards data-* + aria-*', () => {
|
|
181
|
+
const { container } = render(
|
|
182
|
+
<Stack data-testid="s" aria-label="settings">x</Stack>,
|
|
183
|
+
);
|
|
184
|
+
const el = container.firstElementChild;
|
|
185
|
+
expect(el?.getAttribute('data-testid')).toBe('s');
|
|
186
|
+
expect(el?.getAttribute('aria-label')).toBe('settings');
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// ─── F11-bis edge cases: divider with array / null / mixed children ─
|
|
190
|
+
describe('divider edge cases', () => {
|
|
191
|
+
it('children passed as an array still gets N-1 dividers', () => {
|
|
192
|
+
// Children.toArray handles arrays the same as iterated siblings —
|
|
193
|
+
// the divider count is items.length - 1 regardless of how the
|
|
194
|
+
// children were passed in.
|
|
195
|
+
const items = ['a', 'b', 'c', 'd'];
|
|
196
|
+
const { container } = render(
|
|
197
|
+
<Stack divider={<hr data-testid="div" />}>
|
|
198
|
+
{items.map((t) => <span key={t}>{t}</span>)}
|
|
199
|
+
</Stack>,
|
|
200
|
+
);
|
|
201
|
+
expect(container.querySelectorAll('[data-testid="div"]').length).toBe(3);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('null children are stripped before divider insertion', () => {
|
|
205
|
+
// React's Children.toArray filters out null/undefined/false before
|
|
206
|
+
// returning the flat array — so a conditional child collapses to
|
|
207
|
+
// nothing and dividers are sized to the remaining set.
|
|
208
|
+
const showB = false;
|
|
209
|
+
const { container } = render(
|
|
210
|
+
<Stack divider={<hr data-testid="div" />}>
|
|
211
|
+
<span>a</span>
|
|
212
|
+
{showB && <span>b</span>}
|
|
213
|
+
<span>c</span>
|
|
214
|
+
</Stack>,
|
|
215
|
+
);
|
|
216
|
+
// After stripping `false`: 2 effective children → 1 divider
|
|
217
|
+
expect(container.querySelectorAll('[data-testid="div"]').length).toBe(1);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('mixed text + element children — divider between EVERY pair', () => {
|
|
221
|
+
const { container } = render(
|
|
222
|
+
<Stack divider={<hr data-testid="div" />}>
|
|
223
|
+
{'plain string'}
|
|
224
|
+
<span>element child</span>
|
|
225
|
+
{42}
|
|
226
|
+
<span>last</span>
|
|
227
|
+
</Stack>,
|
|
228
|
+
);
|
|
229
|
+
// 4 effective children (Children.toArray wraps primitives) → 3 dividers
|
|
230
|
+
expect(container.querySelectorAll('[data-testid="div"]').length).toBe(3);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('nested Stack inside Stack with divider — inner Stack counts as 1 child', () => {
|
|
234
|
+
const { container } = render(
|
|
235
|
+
<Stack gap={2} divider={<hr data-testid="outer-div" />}>
|
|
236
|
+
<span>top</span>
|
|
237
|
+
<Stack gap={1} direction="row">
|
|
238
|
+
<span>nested-a</span>
|
|
239
|
+
<span>nested-b</span>
|
|
240
|
+
</Stack>
|
|
241
|
+
<span>bottom</span>
|
|
242
|
+
</Stack>,
|
|
243
|
+
);
|
|
244
|
+
// Outer has 3 effective children → 2 outer dividers
|
|
245
|
+
expect(container.querySelectorAll('[data-testid="outer-div"]').length).toBe(2);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('divider key is stable across re-renders (no key warning)', () => {
|
|
249
|
+
// Re-rendering with the same children + divider shouldn't produce
|
|
250
|
+
// React key warnings. We assert nothing throws + the structure is
|
|
251
|
+
// identical to a single render.
|
|
252
|
+
const { container, rerender } = render(
|
|
253
|
+
<Stack divider={<hr data-testid="d" />}>
|
|
254
|
+
<span>a</span>
|
|
255
|
+
<span>b</span>
|
|
256
|
+
</Stack>,
|
|
257
|
+
);
|
|
258
|
+
const firstRender = container.innerHTML;
|
|
259
|
+
rerender(
|
|
260
|
+
<Stack divider={<hr data-testid="d" />}>
|
|
261
|
+
<span>a</span>
|
|
262
|
+
<span>b</span>
|
|
263
|
+
</Stack>,
|
|
264
|
+
);
|
|
265
|
+
expect(container.innerHTML).toBe(firstRender);
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
// ─── F11-bis edge cases: gap value coverage ─────────────────────────
|
|
270
|
+
describe('gap — every token step', () => {
|
|
271
|
+
const GAPS = [0, '0.5', 1, 2, 3, 4, 6, 8, 12, 16, 24] as const;
|
|
272
|
+
it.each(GAPS)('gap=%s emits gap-%s', (g) => {
|
|
273
|
+
const { container } = render(<Stack gap={g}>x</Stack>);
|
|
274
|
+
expect(container.firstElementChild?.className).toContain(`gap-${g}`);
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
// ─── F11-bis edge cases: align / justify all values ─────────────────
|
|
279
|
+
describe('align + justify — all valid values', () => {
|
|
280
|
+
const ALIGNS = ['start', 'center', 'end', 'stretch', 'baseline'] as const;
|
|
281
|
+
const JUSTIFIES = ['start', 'center', 'end', 'between', 'around', 'evenly'] as const;
|
|
282
|
+
|
|
283
|
+
it.each(ALIGNS)('align="%s"', (v) => {
|
|
284
|
+
const { container } = render(<Stack align={v}>x</Stack>);
|
|
285
|
+
expect(container.firstElementChild?.className).toContain(`items-${v}`);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it.each(JUSTIFIES)('justify="%s"', (v) => {
|
|
289
|
+
const { container } = render(<Stack justify={v}>x</Stack>);
|
|
290
|
+
expect(container.firstElementChild?.className).toContain(`justify-${v}`);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// ─── F11-bis edge cases: empty Stack ────────────────────────────────
|
|
295
|
+
describe('empty Stack', () => {
|
|
296
|
+
it('renders an empty div with flex classes', () => {
|
|
297
|
+
const { container } = render(<Stack gap={4} />);
|
|
298
|
+
const el = container.firstElementChild;
|
|
299
|
+
expect(el?.children.length).toBe(0);
|
|
300
|
+
expect(el?.className).toContain('flex');
|
|
301
|
+
expect(el?.className).toContain('gap-4');
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('empty Stack with divider does NOT render the divider', () => {
|
|
305
|
+
const { container } = render(<Stack divider={<hr data-testid="d" />} />);
|
|
306
|
+
expect(container.querySelectorAll('[data-testid="d"]').length).toBe(0);
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
});
|