@gears-frontx/ui-kit 0.4.10 → 0.5.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.
@@ -0,0 +1 @@
1
+ ._root_pa68e_9{container:fx-grid / inline-size;min-inline-size:0}._grid_pa68e_20{display:grid;min-inline-size:0}._item_pa68e_31{display:grid;grid-template-columns:minmax(0,1fr);min-inline-size:0;min-block-size:0;overflow:auto}@media print{._grid_pa68e_20{display:block}._item_pa68e_31{display:block;overflow:visible;margin-block-end:var(--space-4)}}:where([data-fx-grid=default])>:where([data-fx-grid-item]){grid-column:var(--_grid-col-base, auto);grid-row:var(--_grid-row-base, auto)}:where([data-fx-grid=default]){grid-template-columns:repeat(var(--_grid-columns, 12),minmax(0,1fr));grid-auto-rows:var(--grid-row-height, 10rem);gap:var(--grid-gap, var(--space-4))}@container fx-grid (min-width: 480px){:where([data-fx-grid=default])>:where([data-fx-grid-item]){grid-column:var(--_grid-col-sm, auto);grid-row:var(--_grid-row-sm, auto)}:where([data-fx-grid=default]){gap:var(--grid-gap, var(--space-4))}}@container fx-grid (min-width: 768px){:where([data-fx-grid=default])>:where([data-fx-grid-item]){grid-column:var(--_grid-col-md, auto);grid-row:var(--_grid-row-md, auto)}:where([data-fx-grid=default]){gap:var(--grid-gap, var(--space-6))}}@container fx-grid (min-width: 1200px){:where([data-fx-grid=default])>:where([data-fx-grid-item]){grid-column:var(--_grid-col-lg, auto);grid-row:var(--_grid-row-lg, auto)}:where([data-fx-grid=default]){gap:var(--grid-gap, var(--space-6))}}
@@ -0,0 +1 @@
1
+ ._switch_1l0he_6{box-sizing:border-box;position:relative;display:inline-flex;align-items:center;flex-shrink:0;padding:0;border:var(--border-width) solid transparent;border-radius:var(--radius-full);outline:none;transition:background-color .15s ease,border-color .15s ease,box-shadow .15s ease}._switch_1l0he_6:after{content:"";position:absolute;inset:calc(-1 * var(--space-2)) calc(-1 * var(--space-3))}._switch_1l0he_6[data-checked]{background-color:var(--primary)}._switch_1l0he_6[data-unchecked]{background-color:var(--input)}._switch_1l0he_6:focus-visible{outline:var(--border-width-focus) solid var(--ring);outline-offset:2px}@media(forced-colors:active){._switch_1l0he_6:focus-visible{outline:2px solid Highlight;outline-offset:2px}}._switch_1l0he_6[data-disabled]{cursor:not-allowed;opacity:var(--opacity-disabled)}._switch_1l0he_6[aria-invalid=true]{border-color:var(--destructive)}._sizeDefault_1l0he_10{height:1.375rem;width:2.375rem}._sizeSm_1l0he_10{height:.875rem;width:1.5rem}._thumb_1l0he_87{pointer-events:none;display:block;border-radius:var(--radius-full);background-color:var(--primary-foreground);transition:transform .15s ease}@media(prefers-reduced-motion:reduce){._thumb_1l0he_87{transition:none}}._sizeDefault_1l0he_10 ._thumb_1l0he_87{width:1rem;height:1rem;margin-inline-start:2px}._sizeDefault_1l0he_10 ._thumb_1l0he_87[data-checked]{transform:translate(100%)}._sizeDefault_1l0he_10 ._thumb_1l0he_87[data-checked]:dir(rtl){transform:translate(-100%)}._sizeSm_1l0he_10 ._thumb_1l0he_87{width:.75rem;height:.75rem}._thumb_1l0he_87[data-checked]{transform:translate(calc(100% - 2px))}._thumb_1l0he_87[data-checked]:dir(rtl){transform:translate(calc(2px - 100%))}._thumb_1l0he_87[data-unchecked]{transform:translate(0)}
@@ -0,0 +1,29 @@
1
+ export type GridSizeClass = 'small' | 'medium' | 'large';
2
+ export type GridHeightClass = 'low' | 'high';
3
+ export interface GridSpanRange {
4
+ min: number;
5
+ preferred: number;
6
+ max: number;
7
+ }
8
+ export interface GridStep {
9
+ name: string;
10
+ minWidth: number;
11
+ gap: string;
12
+ }
13
+ export interface GridConfig {
14
+ name: string;
15
+ columns: number;
16
+ rowHeight: string;
17
+ steps: GridStep[];
18
+ sizes: Record<GridSizeClass, Record<string, GridSpanRange>>;
19
+ }
20
+ export declare const defaultGridConfig: GridConfig;
21
+ export { SIZE_CLASSES } from './grid-config-check.mjs';
22
+ /**
23
+ * Throws with a plain message when a config cannot drive the solver or the
24
+ * generated CSS. One validator with the CSS command (grid-config-check.mjs);
25
+ * the reserved `default` scope is admitted here because defaultGridConfig
26
+ * itself carries it, and Grid refuses it for any other config object.
27
+ */
28
+ export declare function validateGridConfig(config: GridConfig): void;
29
+ //# sourceMappingURL=grid-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grid-config.d.ts","sourceRoot":"","sources":["../../../src/components/grid/grid-config.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AACzD,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,MAAM,CAAC;AAO7C,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;CACb;AAOD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb;AAUD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;CAC7D;AAcD,eAAO,MAAM,iBAAiB,EAAE,UAAuD,CAAC;AAIxF,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAE3D"}
@@ -0,0 +1,19 @@
1
+ declare const _default: {
2
+ "name": "default",
3
+ "columns": 12,
4
+ "rowHeight": "10rem",
5
+ "steps": [
6
+ { "name": "base", "minWidth": 0, "gap": "--space-4" },
7
+ { "name": "sm", "minWidth": 480, "gap": "--space-4" },
8
+ { "name": "md", "minWidth": 768, "gap": "--space-6" },
9
+ { "name": "lg", "minWidth": 1200, "gap": "--space-6" }
10
+ ],
11
+ "sizes": {
12
+ "small": { "base": { "min": 6, "preferred": 6, "max": 6 }, "sm": { "min": 4, "preferred": 6, "max": 6 }, "md": { "min": 3, "preferred": 3, "max": 4 }, "lg": { "min": 2, "preferred": 3, "max": 4 } },
13
+ "medium": { "base": { "min": 12, "preferred": 12, "max": 12 }, "sm": { "min": 6, "preferred": 6, "max": 12 }, "md": { "min": 4, "preferred": 6, "max": 8 }, "lg": { "min": 4, "preferred": 6, "max": 8 } },
14
+ "large": { "base": { "min": 12, "preferred": 12, "max": 12 }, "sm": { "min": 12, "preferred": 12, "max": 12 }, "md": { "min": 8, "preferred": 12, "max": 12 }, "lg": { "min": 7, "preferred": 12, "max": 12 } }
15
+ }
16
+ }
17
+ ;
18
+
19
+ export default _default;
@@ -0,0 +1,30 @@
1
+ import { GridConfig, GridHeightClass, GridSizeClass } from './grid-config.js';
2
+ export interface GridItemSpec {
3
+ layoutId: string;
4
+ size: GridSizeClass;
5
+ height?: GridHeightClass;
6
+ }
7
+ export interface GridPlacement {
8
+ colStart: number;
9
+ colSpan: number;
10
+ rowStart: number;
11
+ rowSpan: number;
12
+ }
13
+ export interface GridStepLayout {
14
+ placements: Record<string, GridPlacement>;
15
+ rows: number;
16
+ holes: number;
17
+ }
18
+ export interface GridLayout {
19
+ steps: Record<string, GridStepLayout>;
20
+ }
21
+ export interface GridSolveOptions {
22
+ flexible?: boolean;
23
+ }
24
+ /**
25
+ * Places ordered items for every step of a config. Pure: no DOM, no
26
+ * measurement, the same input always gives the same output. Throws on an
27
+ * invalid config, a duplicate `layoutId` or an unknown size or height.
28
+ */
29
+ export declare function solveGridLayout(items: GridItemSpec[], config?: GridConfig, { flexible }?: GridSolveOptions): GridLayout;
30
+ //# sourceMappingURL=grid-solver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grid-solver.d.ts","sourceRoot":"","sources":["../../../src/components/grid/grid-solver.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,aAAa,EAEnB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CACvC;AAQD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAoND;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,YAAY,EAAE,EACrB,MAAM,GAAE,UAA8B,EACtC,EAAE,QAAgB,EAAE,GAAE,gBAAqB,GAC1C,UAAU,CAMZ"}
@@ -0,0 +1,24 @@
1
+ import { ComponentProps, ReactNode } from 'react';
2
+ import { GridConfig, GridHeightClass, GridSizeClass } from './grid-config.js';
3
+ export interface GridItemProps extends ComponentProps<'div'> {
4
+ /** Placement identity, unique within one Grid. Separate from the HTML id. */
5
+ layoutId: string;
6
+ /** The span range the item takes at every step: small, medium or large. */
7
+ size: GridSizeClass;
8
+ /** `low` is one row track, `high` is two tracks and the row gap between them. @default 'low' */
9
+ height?: GridHeightClass;
10
+ }
11
+ export declare function GridItem({ layoutId: _layoutId, size: _size, height: _height, className, ...props }: GridItemProps): import("react").JSX.Element;
12
+ export interface GridProps extends ComponentProps<'div'> {
13
+ /**
14
+ * The config the step CSS is generated from; a custom config needs the
15
+ * stylesheet the `frontx-ui-grid-css` command writes for it.
16
+ * @default defaultGridConfig
17
+ */
18
+ config?: GridConfig;
19
+ /** Lets spans move inside each size class's range to fill rows. Off: preferred spans only. @default false */
20
+ flexible?: boolean;
21
+ children?: ReactNode;
22
+ }
23
+ export declare function Grid({ config, flexible, children, className, ...props }: GridProps): import("react").JSX.Element;
24
+ //# sourceMappingURL=grid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../../src/components/grid/grid.tsx"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,cAAc,EAGnB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,EAAqB,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGhH,OAAO,kBAAkB,CAAC;AAY1B,MAAM,WAAW,aAAc,SAAQ,cAAc,CAAC,KAAK,CAAC;IAC1D,6EAA6E;IAC7E,QAAQ,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,IAAI,EAAE,aAAa,CAAC;IACpB,gGAAgG;IAChG,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B;AAED,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,OAAe,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,aAAa,+BAEzH;AAED,MAAM,WAAW,SAAU,SAAQ,cAAc,CAAC,KAAK,CAAC;IACtD;;;;OAIG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,6GAA6G;IAC7G,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAoBD,wBAAgB,IAAI,CAAC,EAAE,MAA0B,EAAE,QAAgB,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,SAAS,+BAyC9G"}
@@ -0,0 +1,5 @@
1
+ export { Grid, GridItem } from './grid.js';
2
+ export type { GridProps, GridItemProps } from './grid.js';
3
+ export { defaultGridConfig } from './grid-config.js';
4
+ export type { GridConfig, GridStep, GridSpanRange, GridSizeClass, GridHeightClass } from './grid-config.js';
5
+ //# sourceMappingURL=public.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../../src/components/grid/public.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,127 @@
1
+ # Grid
2
+
3
+ ## When to use
4
+
5
+ Use `Grid` for an ordered group of blocks whose widths follow size classes. Use one `Grid` per group. Each `GridItem` declares a unique `layoutId`, a size class, and an optional height class. The solver keeps DOM, focus, and segment order equal to input order.
6
+
7
+ ## When not to use
8
+
9
+ Use a plain CSS grid when callers already know exact spans or need manual placement. Grid does not render dashboard data or support drag and resize editing.
10
+
11
+ ## Props
12
+
13
+ | Component | Prop | Meaning |
14
+ | --- | --- | --- |
15
+ | Grid | `config` | `GridConfig` shared with the generated step CSS. Defaults to `defaultGridConfig`. |
16
+ | Grid | `flexible` | `false` (default): every item takes its size class's preferred span. `true`: spans may move inside each class's range to fill rows. |
17
+ | Grid | `className`, div props | Applied to the named container wrapper. |
18
+ | GridItem | `layoutId` | Required placement identity, unique within this Grid. Separate from HTML `id`. |
19
+ | GridItem | `size` | `small`, `medium`, or `large`. |
20
+ | GridItem | `height` | `low` (default, one row track) or `high` (two row tracks). |
21
+ | GridItem | `className`, div props | Applied to the item. Caller style is preserved; placement variables win on conflict. |
22
+
23
+ `Grid` accepts direct `GridItem` elements, arrays, and empty conditional entries (`null`, `undefined`, booleans). Fragments, wrappers, portals, and text throw. Keep a stable `layoutId` when content changes: a `key` on a GridItem is ignored, because Grid keys items by `layoutId`, and changing `layoutId` is what remounts an item. The solver is pure and runs during rendering, so the server and client get the same layout.
24
+
25
+ ## Names
26
+
27
+ The step CSS is a global stylesheet matched by attribute, so its selectors and the container keep the `fx-` prefix: `data-fx-grid`, `data-fx-grid-item`, `data-fx-grid-flexible`, and the `fx-grid` container name. An unprefixed `data-grid` is already in use by other libraries (react-grid-layout puts `data-grid` on its children), and a global rule that matched it would style foreign markup. The custom properties need no prefix: Grid sets `--_grid-columns` and the per-step `--_grid-col-<step>` / `--_grid-row-<step>` only on its own elements. `--grid-gap` and `--grid-row-height` are consumer hooks that Grid only reads, and they inherit like any custom property, so a value declared on any ancestor, `:root` included, applies to every Grid below it.
28
+
29
+ ## Layout and styling
30
+
31
+ The default config has 12 columns and four container steps: base 0px, sm 480px, md 768px, lg 1200px. Each size class has a preferred span per step, and with the default config every span is 12, 6 or 3 columns:
32
+
33
+ | Size | base | sm | md | lg |
34
+ | --- | --- | --- | --- | --- |
35
+ | `small` | 6 | 6 | 3 | 3 |
36
+ | `medium` | 12 | 6 | 6 | 6 |
37
+ | `large` | 12 | 12 | 12 | 12 |
38
+
39
+ By default a Grid places exactly these spans; a row they do not fill keeps its hole at the inline end, so `medium` + `small` at lg is 6 + 3 with three empty columns. A `flexible` Grid lets each span move inside its class's range in `defaultGridConfig` (at lg `small` 2..4, `medium` 4..8, `large` 7..12) to fill rows, so the same pair becomes 8 + 4. Flexible is set per Grid, that is per group. In both modes the solver minimizes internal holes, final holes, width deviation, and band count in that order, never reorders items, and leaves empty columns at the inline end.
40
+
41
+ ### Row tracks and heights
42
+
43
+ Heights are fixed by the model. Row tracks have the size of the config's `rowHeight`, a positive length in px, rem or em (`10rem` in the default config): a `low` item is one track, a `high` item is two tracks and the row gap between them, so a high item is exactly as tall as two stacked lows with their gap. A two-track band holds high items and pairs of adjacent lows stacked in one column beside them; a low never stretches over two tracks, and a low that finds no partner beside a high goes to the next band. With the default config a high `medium` takes two smalls stacked beside it from sm on, and four smalls as two stacks at md and lg (`6 + 3 + 3`). An item is a one-column grid, so a single child (a Card) fills it.
44
+
45
+ ### Scrolling and clipping
46
+
47
+ Content taller than its item scrolls inside the item and never overlaps a neighbour. The item is a scroll container, so it also clips what a child draws outside its own box (an outer shadow or outline). The default kit Card draws neither and its focus ring is inset; the `panel` Card's outer shadow and the forced-colors focus outline of an interactive Card are clipped at the item edge.
48
+
49
+ ### Track override
50
+
51
+ The track size and the spans of the default config are not final; the config is the single place to change them (`rowHeight` for the track), and `--grid-row-height` overrides the track at runtime.
52
+
53
+ ### Direction
54
+
55
+ Direction follows CSS grid lines, so `dir="rtl"` mirrors the layout without changing DOM order.
56
+
57
+ The wrapper is the named inline-size container. Size containment gives it no width of its own content, so it needs a width from outside: a block in normal flow or a stretched flex or grid child gets one; inside a shrink-to-fit box (an inline-block, a float, a `max-content` track, a flex item that does not grow) give the Grid a width. The grid element carries `data-fx-grid="<config.name>"`; each item carries `data-fx-grid-item`; a flexible Grid's grid element also carries `data-fx-grid-flexible`. The default generated CSS ships with the component, and nested Grids query their nearest `fx-grid` wrapper. Print uses block flow and a token gap.
58
+
59
+ ## Config
60
+
61
+ A custom config starts from a copy of the shipped default config, `@gears-frontx/ui-kit/grid-default-config.json` in the install (`node_modules/@gears-frontx/ui-kit/dist/grid-default-config.json`), written as JSON:
62
+
63
+ ```json
64
+ {
65
+ "name": "report",
66
+ "columns": 8,
67
+ "rowHeight": "120px",
68
+ "steps": [
69
+ { "name": "base", "minWidth": 0, "gap": "--space-4" },
70
+ { "name": "wide", "minWidth": 960, "gap": "--space-6" }
71
+ ],
72
+ "sizes": {
73
+ "small": { "base": { "min": 2, "preferred": 2, "max": 4 }, "wide": { "min": 1, "preferred": 2, "max": 2 } },
74
+ "medium": { "base": { "min": 4, "preferred": 4, "max": 8 }, "wide": { "min": 2, "preferred": 4, "max": 4 } },
75
+ "large": { "base": { "min": 8, "preferred": 8, "max": 8 }, "wide": { "min": 4, "preferred": 8, "max": 8 } }
76
+ }
77
+ }
78
+ ```
79
+
80
+ The example is valid JSON and passes the config validator unchanged:
81
+
82
+ - `name` is a lowercase CSS-safe name and not `default`, which is the kit's own scope and Grid refuses for any other config object.
83
+ - `columns` is an integer from 1 to 48.
84
+ - `rowHeight` is a positive length in px, rem or em.
85
+ - `steps[]` carries `name`, `minWidth` in px with the first step at 0 and the widths strictly increasing, and `gap`, a spacing token name such as `--space-4`.
86
+ - `sizes.<small|medium|large>.<step>` carries the span range with `1 <= min <= preferred <= max <= columns`.
87
+
88
+ Generate the step CSS and import it once beside the kit's own:
89
+
90
+ ```sh
91
+ frontx-ui-grid-css ./grid-config.json ./grid-steps.css
92
+ ```
93
+
94
+ The command also reads a `.mjs` or `.js` module with a default export. A `.js` config is loaded with `import()`, so Node decides its module type from the nearest `package.json` `"type"` field, or by syntax detection when there is none; a CommonJS `module.exports` object is accepted as the default export. Use `.mjs` or `.json` when unsure. The output path must not be the config file, under any name.
95
+
96
+ Pass that same config object to `Grid`. CSS selectors are scoped by config name, so two configs can coexist, and a custom stylesheet is needed for each custom config. The generated CSS and the passed config must use the same name and steps. The CSS has no viewport queries and resizing does not run JavaScript. For Shadow DOM, include the kit component CSS and generated CSS inside the shadow root.
97
+
98
+ `--grid-gap` overrides the configured spacing token at every step, and `--grid-row-height` the configured row track. `--_grid-columns` and the per-step `--_grid-col-<step>` / `--_grid-row-<step>` are set by Grid.
99
+
100
+ ## Accessibility
101
+
102
+ Grid adds no role or focus behavior. Put meaningful content inside each item. DOM and focus order remain the input order. A paired stack reads as the first low followed by the second low. An item whose content overflows is a scroll container and becomes a tab stop in browsers with focusable scrollers, so content that must stay reachable everywhere should fit or carry its own focusable control.
103
+
104
+ ## Anti-patterns
105
+
106
+ - A fragment or wrapper between Grid and GridItem: Grid throws instead of dropping items.
107
+ - A reused `layoutId` in one Grid: Grid throws (`Duplicate Grid layoutId: <layoutId>`).
108
+ - A custom config without its generated CSS loaded: nothing reads the placement variables, and the browser auto-places the items.
109
+
110
+ ## Examples
111
+
112
+ ```tsx
113
+ <Grid>
114
+ <GridItem layoutId="summary" size="medium" height="high">Summary</GridItem>
115
+ <GridItem layoutId="trend" size="small">Trend</GridItem>
116
+ <GridItem layoutId="alerts" size="small">Alerts</GridItem>
117
+ </Grid>
118
+ ```
119
+
120
+ With a custom config and the stylesheet generated for it imported once:
121
+
122
+ ```tsx
123
+ <Grid config={reportConfig}>
124
+ <GridItem layoutId="table" size="large">Table</GridItem>
125
+ <GridItem layoutId="notes" size="small">Notes</GridItem>
126
+ </Grid>
127
+ ```
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ * frontx-ui-grid-css: writes the Grid step rules for a config.
4
+ *
5
+ * frontx-ui-grid-css [--kit-default] <config.json|config.mjs|config.js> <output.css>
6
+ *
7
+ * `@container` conditions cannot read `var()`, so every container step width
8
+ * has to be a literal in CSS; this command turns a GridConfig into those
9
+ * rules. The kit's grid-steps.css is this command's output for the default
10
+ * config, regenerated by `npm run grid:css -w @gears-frontx/ui-kit` and kept
11
+ * equal by a test. Rules are scoped by the config name through `data-fx-grid`,
12
+ * never by a CSS Module class, so a custom config's CSS coexists with the
13
+ * default.
14
+ *
15
+ * `default` is the kit's own scope: the command refuses a config under that
16
+ * name unless --kit-default is given. The flag is public on the installed bin
17
+ * and is meant for regenerating the kit's own stylesheet, which the kit's
18
+ * `grid:css` script and the consumer acceptance do; it guards against a
19
+ * custom config accidentally shadowing the shipped rules, not against doing
20
+ * so on purpose.
21
+ *
22
+ * The generator and the config checks it runs live in the component
23
+ * directory. The build copies grid-css.mjs and grid-config-check.mjs flat
24
+ * into dist/ beside the bin and rewrites the one import specifier below to
25
+ * './grid-css.mjs', a rewrite buildPlugin.ts guards by refusing to copy when
26
+ * this specifier text moves, so the specifier stays as written unless the
27
+ * copy step changes with it. The command stays in scripts/ because it alone
28
+ * needs the Node builtins the component source may not import.
29
+ */
30
+ import { readFile, stat, writeFile } from 'node:fs/promises';
31
+ import { extname, resolve } from 'node:path';
32
+ import { pathToFileURL } from 'node:url';
33
+
34
+ import { generateGridCss } from './grid-css.mjs';
35
+
36
+ const USAGE = 'Usage: frontx-ui-grid-css [--kit-default] <config.json|config.mjs|config.js> <output.css>';
37
+
38
+ async function main() {
39
+ const args = process.argv.slice(2);
40
+ const kitDefault = args.includes('--kit-default');
41
+ const positionals = args.filter(argument => argument !== '--kit-default');
42
+ // An explicit help request succeeds: the usage text on stdout, exit 0.
43
+ if (args.includes('--help') || args.includes('-h')) {
44
+ console.log(USAGE);
45
+ return;
46
+ }
47
+ // One option and two positionals: any other --word is a mistyped invocation,
48
+ // and any other arity has no reading, so both stop here instead of surfacing
49
+ // later as a missing or misread file. Apart from -h, a single dash stays a
50
+ // path character; a path that starts with -- is passed as ./--name.
51
+ if (args.some(argument => argument.startsWith('--') && argument !== '--kit-default') || positionals.length !== 2) {
52
+ throw new Error(USAGE);
53
+ }
54
+ const [input, output] = positionals;
55
+ const path = resolve(input);
56
+ // The output is written as CSS: the same file would replace the config.
57
+ // Checked before anything is read or written: by path, and for an existing
58
+ // output by filesystem identity (dev + ino), which catches a symlink, a hard
59
+ // link or a case alias. A missing output cannot be the config.
60
+ const sameFileError = new Error(`Output path ${output} is the config file; give the CSS its own path`);
61
+ if (path === resolve(output)) throw sameFileError;
62
+ const [configStat, outputStat] = await Promise.all([stat(path).catch(() => null), stat(resolve(output)).catch(() => null)]);
63
+ if (configStat && outputStat && configStat.dev === outputStat.dev && configStat.ino === outputStat.ino) throw sameFileError;
64
+ const extension = extname(path);
65
+ if (extension !== '.json' && extension !== '.mjs' && extension !== '.js') {
66
+ throw new Error('Grid config must be a .json file or an ES module (.mjs, .js) with a default export');
67
+ }
68
+ let config;
69
+ if (extension === '.json') {
70
+ config = JSON.parse(await readFile(path, 'utf8'));
71
+ } else {
72
+ const module = await import(pathToFileURL(path).href);
73
+ if (!('default' in module)) throw new Error(`Grid config module ${input} has no default export`);
74
+ config = module.default;
75
+ }
76
+ await writeFile(resolve(output), generateGridCss(config, { allowDefaultName: kitDefault }));
77
+ }
78
+
79
+ main().catch(error => {
80
+ console.error(error instanceof Error ? error.message : String(error));
81
+ process.exitCode = 1;
82
+ });
@@ -0,0 +1,78 @@
1
+ /*
2
+ * The one Grid config validator: grid-config.ts and the generator
3
+ * (grid-css.mjs, behind the frontx-ui-grid-css command) both import it, so a
4
+ * config object and the stylesheet generated from it cannot disagree. The
5
+ * build copies this module flat into dist/ next to the command. Plain
6
+ * dependency-free ESM, so the command runs in plain Node without loading any
7
+ * component code (the built entries import CSS).
8
+ *
9
+ * Types: grid-config-check.d.mts.
10
+ */
11
+
12
+ export const SIZE_CLASSES = ['small', 'medium', 'large'];
13
+ // Bounds the solver's width loops, which run per column.
14
+ const MAX_COLUMNS = 48;
15
+ const NAME_PATTERN = /^[a-z][a-z0-9-]*$/;
16
+ const TOKEN_PATTERN = /^--[a-z][a-z0-9-]*$/;
17
+ const LENGTH_PATTERN = /^(?:\d+(?:\.\d+)?|\.\d+)(?:px|rem|em)$/;
18
+
19
+ function validRange(range, columns) {
20
+ return (
21
+ !!range &&
22
+ Number.isSafeInteger(range.min) &&
23
+ Number.isSafeInteger(range.preferred) &&
24
+ Number.isSafeInteger(range.max) &&
25
+ range.min >= 1 &&
26
+ range.min <= range.preferred &&
27
+ range.preferred <= range.max &&
28
+ range.max <= columns
29
+ );
30
+ }
31
+
32
+ /**
33
+ * Throws with a plain message when a config cannot drive the solver or the
34
+ * generated CSS. `allowDefaultName` admits the reserved `default` scope, which
35
+ * belongs to the kit's own defaultGridConfig and its shipped stylesheet; every
36
+ * other caller refuses it.
37
+ */
38
+ export function validateGridConfig(config, { allowDefaultName = false } = {}) {
39
+ if (!config || typeof config !== 'object') throw new Error('Grid config must be an object');
40
+ if (typeof config.name !== 'string' || !NAME_PATTERN.test(config.name)) {
41
+ throw new Error('Grid config name must be a lowercase CSS-safe name');
42
+ }
43
+ if (!allowDefaultName && config.name === 'default') {
44
+ throw new Error('Grid config name "default" belongs to defaultGridConfig; give a custom config its own name');
45
+ }
46
+ if (!Number.isSafeInteger(config.columns) || config.columns < 1 || config.columns > MAX_COLUMNS) {
47
+ throw new Error(`Grid columns must be an integer from 1 to ${MAX_COLUMNS}`);
48
+ }
49
+ if (typeof config.rowHeight !== 'string' || !LENGTH_PATTERN.test(config.rowHeight) || parseFloat(config.rowHeight) <= 0) {
50
+ throw new Error('Grid rowHeight must be a positive CSS length in px, rem or em');
51
+ }
52
+ if (!Array.isArray(config.steps) || config.steps.length === 0) throw new Error('Grid steps must be nonempty');
53
+ const names = new Set();
54
+ let previousWidth = -1;
55
+ for (const step of config.steps) {
56
+ if (!step || typeof step.name !== 'string' || !NAME_PATTERN.test(step.name) || names.has(step.name)) {
57
+ throw new Error('Grid step names must be unique lowercase CSS-safe names');
58
+ }
59
+ if (!Number.isFinite(step.minWidth) || step.minWidth < 0 || step.minWidth <= previousWidth) {
60
+ throw new Error('Grid step widths must be finite, nonnegative, and strictly increasing');
61
+ }
62
+ if (typeof step.gap !== 'string' || !TOKEN_PATTERN.test(step.gap)) {
63
+ throw new Error(`Grid step ${step.name} gap must be a CSS token reference`);
64
+ }
65
+ names.add(step.name);
66
+ previousWidth = step.minWidth;
67
+ }
68
+ if (config.steps[0].minWidth !== 0) throw new Error('Grid first step must start at 0');
69
+ for (const size of SIZE_CLASSES) {
70
+ const steps = config.sizes?.[size];
71
+ if (!steps || typeof steps !== 'object') throw new Error(`Grid size ${size} is missing`);
72
+ for (const name of names) {
73
+ if (!validRange(steps[name], config.columns)) {
74
+ throw new Error(`Grid size ${size} step ${name} needs 1 <= min <= preferred <= max <= columns`);
75
+ }
76
+ }
77
+ }
78
+ }
@@ -0,0 +1,32 @@
1
+ /*
2
+ * The Grid step-rule generator: turns a GridConfig into the stylesheet the
3
+ * component imports. The frontx-ui-grid-css command is a thin executable over
4
+ * this module, and the tests read generateGridCss from it in process, so the
5
+ * module carries no CLI of its own - a file a test imports cannot carry the
6
+ * executable's shebang.
7
+ *
8
+ * The config checks are grid-config-check.mjs, imported by this relative path
9
+ * both from this directory in the repository and from dist/, where the build
10
+ * copies it beside the command and this module.
11
+ */
12
+ import { validateGridConfig } from './grid-config-check.mjs';
13
+
14
+ export function generateGridCss(config, { allowDefaultName = false } = {}) {
15
+ validateGridConfig(config, { allowDefaultName });
16
+ const grid = `:where([data-fx-grid="${config.name}"])`;
17
+ const item = `${grid} > :where([data-fx-grid-item])`;
18
+ const rules = config.steps.map(step => {
19
+ // Columns and the fixed row track are set once, in the base rule; only the gap changes per step.
20
+ const columns =
21
+ step.minWidth === 0
22
+ ? ` grid-template-columns: repeat(var(--_grid-columns, ${config.columns}), minmax(0, 1fr)); grid-auto-rows: var(--grid-row-height, ${config.rowHeight});`
23
+ : '';
24
+ const lines = [
25
+ `${item} { grid-column: var(--_grid-col-${step.name}, auto); grid-row: var(--_grid-row-${step.name}, auto); }`,
26
+ `${grid} {${columns} gap: var(--grid-gap, var(${step.gap})); }`,
27
+ ];
28
+ if (step.minWidth === 0) return lines.join('\n');
29
+ return `@container fx-grid (min-width: ${step.minWidth}px) {\n${lines.map(line => ` ${line}`).join('\n')}\n}`;
30
+ });
31
+ return `/* Generated by frontx-ui-grid-css, format 1. Regenerate with frontx-ui-grid-css after a breaking ui-kit release. */\n${rules.join('\n\n')}\n`;
32
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "default",
3
+ "columns": 12,
4
+ "rowHeight": "10rem",
5
+ "steps": [
6
+ { "name": "base", "minWidth": 0, "gap": "--space-4" },
7
+ { "name": "sm", "minWidth": 480, "gap": "--space-4" },
8
+ { "name": "md", "minWidth": 768, "gap": "--space-6" },
9
+ { "name": "lg", "minWidth": 1200, "gap": "--space-6" }
10
+ ],
11
+ "sizes": {
12
+ "small": { "base": { "min": 6, "preferred": 6, "max": 6 }, "sm": { "min": 4, "preferred": 6, "max": 6 }, "md": { "min": 3, "preferred": 3, "max": 4 }, "lg": { "min": 2, "preferred": 3, "max": 4 } },
13
+ "medium": { "base": { "min": 12, "preferred": 12, "max": 12 }, "sm": { "min": 6, "preferred": 6, "max": 12 }, "md": { "min": 4, "preferred": 6, "max": 8 }, "lg": { "min": 4, "preferred": 6, "max": 8 } },
14
+ "large": { "base": { "min": 12, "preferred": 12, "max": 12 }, "sm": { "min": 12, "preferred": 12, "max": 12 }, "md": { "min": 8, "preferred": 12, "max": 12 }, "lg": { "min": 7, "preferred": 12, "max": 12 } }
15
+ }
16
+ }
package/dist/grid.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './components/grid/public.js'