@tristan2828/ui-foundation 4.84.0 → 4.86.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.
- package/README.md +1 -1
- package/conventions/docs/add-an-entity.md +72 -24
- package/conventions/docs/cell-patterns.md +165 -37
- package/conventions/docs/design-language.md +24 -17
- package/dist/components/app/data-table-tools.d.ts +98 -0
- package/dist/components/app/data-table-tools.js +59 -0
- package/dist/components/app/data-table.d.ts +60 -2
- package/dist/components/app/data-table.js +97 -20
- package/dist/components/app/entity-form.d.ts +27 -3
- package/dist/components/app/entity-form.js +124 -3
- package/dist/components/app/filter-bar.d.ts +55 -0
- package/dist/components/app/filter-bar.js +28 -0
- package/dist/components/app/form-dialog.js +16 -4
- package/dist/components/app/form-leave-guard.d.ts +4 -0
- package/dist/components/app/form-leave-guard.js +42 -0
- package/dist/components/app/form-section.d.ts +9 -0
- package/dist/components/app/form-section.js +15 -0
- package/dist/components/app/multi-choice.d.ts +9 -1
- package/dist/components/app/multi-choice.js +3 -3
- package/dist/components/app/option-select.d.ts +30 -0
- package/dist/components/app/option-select.js +21 -0
- package/dist/components/app/pill-filter.d.ts +3 -1
- package/dist/components/app/pill-filter.js +3 -2
- package/dist/components/app/related-table.d.ts +11 -0
- package/dist/components/app/related-table.js +28 -0
- package/dist/components/app/secondary-filters.d.ts +3 -1
- package/dist/components/app/secondary-filters.js +5 -4
- package/dist/components/app/table-columns.d.ts +15 -0
- package/dist/components/app/table-columns.js +50 -0
- package/dist/components/ui/button.js +1 -1
- package/dist/components/ui/combobox.js +1 -1
- package/dist/components/ui/field.d.ts +28 -3
- package/dist/components/ui/field.js +116 -8
- package/dist/components/ui/input-group.js +1 -1
- package/dist/components/ui/input.js +1 -1
- package/dist/components/ui/select.js +1 -1
- package/dist/hooks/table-url-changes.d.ts +2 -0
- package/dist/hooks/use-columns-pick.d.ts +3 -0
- package/dist/hooks/use-columns-pick.js +18 -0
- package/dist/hooks/use-is-phone.d.ts +1 -0
- package/dist/hooks/use-is-phone.js +18 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/lib/field-rows.d.ts +18 -0
- package/dist/lib/field-rows.js +53 -0
- package/dist/lib/form-errors.d.ts +6 -0
- package/dist/lib/form-errors.js +19 -0
- package/package.json +1 -1
- package/styles/index.css +60 -0
|
@@ -1,22 +1,106 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useMemo } from "react";
|
|
2
|
+
import { useLayoutEffect, useMemo, useRef } from "react";
|
|
3
3
|
import { cva } from "class-variance-authority";
|
|
4
4
|
import { cn } from "cn";
|
|
5
5
|
import { Label } from "./label.js";
|
|
6
6
|
import { Separator } from "./separator.js";
|
|
7
|
+
import { fieldRows } from "../../lib/field-rows.js";
|
|
8
|
+
// The foundation's additions to shadcn's Field (4.85, the form standard):
|
|
9
|
+
//
|
|
10
|
+
// - FieldGroup lays its fields out itself: consecutive short fields
|
|
11
|
+
// (`<Field size="s" | "m" | "l">`) share a row, up to three, each as
|
|
12
|
+
// wide as its size; `<Field solo>` keeps a short one alone
|
|
13
|
+
// (lib/field-rows.ts has the rule). Below 48rem each takes its own row
|
|
14
|
+
// but two dates or two numbers. The rows are worked out from the DOM, so
|
|
15
|
+
// a Field inside the app's own component still counts.
|
|
16
|
+
// - Compact: 14px between fields and 32px controls (40px under 48rem or
|
|
17
|
+
// on a touch screen), from `--control-height`, which FieldGroup sets
|
|
18
|
+
// and the inputs, selects and buttons read (styles/index.css).
|
|
19
|
+
// - `<FieldLabel required>`: an asterisk in the destructive text tone,
|
|
20
|
+
// hidden from screen readers, and `aria-required` on the control it
|
|
21
|
+
// names, which says it instead.
|
|
7
22
|
function FieldSet({ className, ...props }) {
|
|
8
23
|
return (_jsx("fieldset", { "data-slot": "field-set", className: cn("flex flex-col gap-4 has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3", className), ...props }));
|
|
9
24
|
}
|
|
10
25
|
function FieldLegend({ className, variant = "legend", ...props }) {
|
|
11
26
|
return (_jsx("legend", { "data-slot": "field-legend", "data-variant": variant, className: cn("mb-1.5 font-medium data-[variant=label]:text-sm data-[variant=legend]:text-base", className), ...props }));
|
|
12
27
|
}
|
|
13
|
-
|
|
14
|
-
|
|
28
|
+
// What a Field holds, when it doesn't say (`kind`): a date or a number
|
|
29
|
+
// box keeps its partner on a phone.
|
|
30
|
+
const DATE_CONTROL = "input[type=date]";
|
|
31
|
+
const NUMBER_CONTROL = "input[type=number], input[inputmode=numeric], input[inputmode=decimal]";
|
|
32
|
+
function kindOf(field) {
|
|
33
|
+
const said = field.dataset.kind;
|
|
34
|
+
if (said === "date" || said === "number")
|
|
35
|
+
return said;
|
|
36
|
+
if (field.querySelector(DATE_CONTROL))
|
|
37
|
+
return "date";
|
|
38
|
+
if (field.querySelector(NUMBER_CONTROL))
|
|
39
|
+
return "number";
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const SIZES = new Set(["s", "m", "l", "full"]);
|
|
43
|
+
/** Puts each of the group's own fields in its row (lib/field-rows.ts). */
|
|
44
|
+
function layOut(group) {
|
|
45
|
+
const children = Array.from(group.children);
|
|
46
|
+
const items = children.map((child) => {
|
|
47
|
+
const isField = child.dataset.slot === "field";
|
|
48
|
+
const size = isField ? child.dataset.size : undefined;
|
|
49
|
+
return {
|
|
50
|
+
size: (size && SIZES.has(size) ? size : "full"),
|
|
51
|
+
solo: child.dataset.solo !== undefined,
|
|
52
|
+
kind: isField ? kindOf(child) : null,
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
fieldRows(items).forEach((place, at) => {
|
|
56
|
+
const child = children[at];
|
|
57
|
+
if (place.share === null) {
|
|
58
|
+
child.style.removeProperty("--field-share");
|
|
59
|
+
child.style.removeProperty("--field-gaps");
|
|
60
|
+
delete child.dataset.fieldRow;
|
|
61
|
+
delete child.dataset.phonePair;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
child.style.setProperty("--field-share", String(place.share));
|
|
65
|
+
child.style.setProperty("--field-gaps", String(place.gaps));
|
|
66
|
+
child.dataset.fieldRow = "";
|
|
67
|
+
if (place.phonePair)
|
|
68
|
+
child.dataset.phonePair = "";
|
|
69
|
+
else
|
|
70
|
+
delete child.dataset.phonePair;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function FieldGroup({ className, ref, ...props }) {
|
|
74
|
+
const own = useRef(null);
|
|
75
|
+
useLayoutEffect(() => {
|
|
76
|
+
const group = own.current;
|
|
77
|
+
if (!group)
|
|
78
|
+
return;
|
|
79
|
+
layOut(group);
|
|
80
|
+
// Fields come and go (a conditional field, an error line), and a
|
|
81
|
+
// field's size can change: lay it out again. Only what layOut reads
|
|
82
|
+
// is watched, so its own writes don't wake it.
|
|
83
|
+
const observer = new MutationObserver(() => layOut(group));
|
|
84
|
+
observer.observe(group, {
|
|
85
|
+
childList: true,
|
|
86
|
+
subtree: true,
|
|
87
|
+
attributes: true,
|
|
88
|
+
attributeFilter: ["data-size", "data-solo", "data-kind", "type", "inputmode"],
|
|
89
|
+
});
|
|
90
|
+
return () => observer.disconnect();
|
|
91
|
+
}, []);
|
|
92
|
+
return (_jsx("div", { ref: (node) => {
|
|
93
|
+
own.current = node;
|
|
94
|
+
if (typeof ref === "function")
|
|
95
|
+
return ref(node);
|
|
96
|
+
if (ref)
|
|
97
|
+
ref.current = node;
|
|
98
|
+
}, "data-slot": "field-group", className: cn("group/field-group @container/field-group flex w-full flex-wrap gap-x-3 gap-y-3.5 data-[slot=checkbox-group]:gap-3 *:data-[slot=field-group]:gap-y-3.5 has-[>[data-slot=form-section]]:gap-y-6", className), ...props }));
|
|
15
99
|
}
|
|
16
100
|
const fieldVariants = cva("group/field flex w-full gap-2 data-[invalid=true]:text-destructive-text", {
|
|
17
101
|
variants: {
|
|
18
102
|
orientation: {
|
|
19
|
-
vertical: "flex-col *:w-full [&>.sr-only]:w-auto",
|
|
103
|
+
vertical: "flex-col gap-1.5 *:w-full [&>.sr-only]:w-auto",
|
|
20
104
|
horizontal: "flex-row items-center has-[>[data-slot=field-content]]:items-start *:data-[slot=field-label]:flex-auto has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",
|
|
21
105
|
responsive: "flex-col *:w-full @md/field-group:flex-row @md/field-group:items-center @md/field-group:*:w-auto @md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:*:data-[slot=field-label]:flex-auto [&>.sr-only]:w-auto @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",
|
|
22
106
|
},
|
|
@@ -25,14 +109,38 @@ const fieldVariants = cva("group/field flex w-full gap-2 data-[invalid=true]:tex
|
|
|
25
109
|
orientation: "vertical",
|
|
26
110
|
},
|
|
27
111
|
});
|
|
28
|
-
function Field({ className, orientation = "vertical", ...props }) {
|
|
29
|
-
return (_jsx("div", { role: "group", "data-slot": "field", "data-orientation": orientation, className: cn(fieldVariants({ orientation }), className), ...props }));
|
|
112
|
+
function Field({ className, orientation = "vertical", size, solo = false, kind, ...props }) {
|
|
113
|
+
return (_jsx("div", { role: "group", "data-slot": "field", "data-orientation": orientation, "data-size": size, "data-solo": solo ? "" : undefined, "data-kind": kind, className: cn(fieldVariants({ orientation }), className), ...props }));
|
|
30
114
|
}
|
|
31
115
|
function FieldContent({ className, ...props }) {
|
|
32
116
|
return (_jsx("div", { "data-slot": "field-content", className: cn("group/field-content flex flex-1 flex-col gap-0.5 leading-snug", className), ...props }));
|
|
33
117
|
}
|
|
34
|
-
|
|
35
|
-
|
|
118
|
+
const REQUIRABLE_ROLES = new Set(["combobox", "textbox", "listbox", "radiogroup", "spinbutton", "searchbox", "gridcell", "tree", "treegrid", "checkbox", "switch"]);
|
|
119
|
+
/** Whether `aria-required` is allowed on it: a form control, or a role that takes it. */
|
|
120
|
+
function takesRequired(control) {
|
|
121
|
+
const role = control.getAttribute("role");
|
|
122
|
+
if (role)
|
|
123
|
+
return REQUIRABLE_ROLES.has(role);
|
|
124
|
+
if (control instanceof HTMLTextAreaElement || control instanceof HTMLSelectElement)
|
|
125
|
+
return true;
|
|
126
|
+
if (control instanceof HTMLInputElement)
|
|
127
|
+
return !["button", "submit", "reset", "image", "hidden"].includes(control.type);
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
function FieldLabel({ className, required = false, children, ...props }) {
|
|
131
|
+
const { htmlFor } = props;
|
|
132
|
+
useLayoutEffect(() => {
|
|
133
|
+
if (!required || !htmlFor)
|
|
134
|
+
return;
|
|
135
|
+
const control = document.getElementById(htmlFor);
|
|
136
|
+
// Only where the control's role takes it (ARIA): a box, a list or a
|
|
137
|
+
// group of choices, not a button (a date picker's trigger).
|
|
138
|
+
if (!control || !takesRequired(control))
|
|
139
|
+
return;
|
|
140
|
+
control.setAttribute("aria-required", "true");
|
|
141
|
+
return () => control.removeAttribute("aria-required");
|
|
142
|
+
}, [required, htmlFor]);
|
|
143
|
+
return (_jsxs(Label, { "data-slot": "field-label", "data-required": required ? "" : undefined, className: cn("group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50 has-data-checked:border-primary/30 has-data-checked:bg-primary/5 has-[>[data-slot=field]]:rounded-lg has-[>[data-slot=field]]:border has-[>[data-slot=field]]:not-has-[:disabled,[data-disabled]]:hover:bg-muted/50 has-[>[data-slot=field]]:has-[:focus-visible]:border-ring has-[>[data-slot=field]]:has-[:focus-visible]:ring-3 has-[>[data-slot=field]]:has-[:focus-visible]:ring-ring/50 *:data-[slot=field]:p-2.5 dark:has-data-checked:border-primary/20 dark:has-data-checked:bg-primary/10", "has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col", className), ...props, children: [children, required && (_jsx("span", { "aria-hidden": "true", "data-slot": "field-required", className: "-ml-1.5 text-destructive-text", children: "*" }))] }));
|
|
36
144
|
}
|
|
37
145
|
function FieldTitle({ className, ...props }) {
|
|
38
146
|
return (_jsx("div", { "data-slot": "field-label", className: cn("flex w-fit items-center gap-2 text-sm font-medium group-data-[disabled=true]/field:opacity-50", className), ...props }));
|
|
@@ -6,7 +6,7 @@ import { Button } from "./button.js";
|
|
|
6
6
|
import { Input } from "./input.js";
|
|
7
7
|
import { Textarea } from "./textarea.js";
|
|
8
8
|
function InputGroup({ className, ...props }) {
|
|
9
|
-
return (_jsx("div", { "data-slot": "input-group", role: "group", className: cn("group/input-group relative flex h-9 w-full min-w-0 items-center rounded-md border border-input transition-colors outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-disabled:bg-input/50 has-disabled:opacity-50 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-3 has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-3 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto dark:bg-input/30 dark:has-disabled:bg-input/80 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5", className), ...props }));
|
|
9
|
+
return (_jsx("div", { "data-slot": "input-group", role: "group", className: cn("group/input-group relative flex h-[var(--control-height,--spacing(9))] w-full min-w-0 items-center rounded-md border border-input transition-colors outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-disabled:bg-input/50 has-disabled:opacity-50 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-3 has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-3 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto dark:bg-input/30 dark:has-disabled:bg-input/80 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5", className), ...props }));
|
|
10
10
|
}
|
|
11
11
|
const inputGroupAddonVariants = cva("flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4", {
|
|
12
12
|
variants: {
|
|
@@ -3,6 +3,6 @@ import * as React from "react";
|
|
|
3
3
|
import { Input as InputPrimitive } from "@base-ui/react/input";
|
|
4
4
|
import { cn } from "cn";
|
|
5
5
|
function Input({ className, type, ...props }) {
|
|
6
|
-
return (_jsx(InputPrimitive, { type: type, "data-slot": "input", className: cn("h-9 w-full min-w-0 rounded-md border border-input bg-transparent palette:text-foreground px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40", className), ...props }));
|
|
6
|
+
return (_jsx(InputPrimitive, { type: type, "data-slot": "input", className: cn("h-[var(--control-height,--spacing(9))] w-full min-w-0 rounded-md border border-input bg-transparent palette:text-foreground px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40", className), ...props }));
|
|
7
7
|
}
|
|
8
8
|
export { Input };
|
|
@@ -12,7 +12,7 @@ function SelectValue({ className, ...props }) {
|
|
|
12
12
|
return (_jsx(SelectPrimitive.Value, { "data-slot": "select-value", className: cn("flex flex-1 text-left", className), ...props }));
|
|
13
13
|
}
|
|
14
14
|
function SelectTrigger({ className, size = "default", children, ...props }) {
|
|
15
|
-
return (_jsxs(SelectPrimitive.Trigger, { "data-slot": "select-trigger", "data-size": size, className: cn("flex w-fit items-center justify-between gap-1.5 rounded-md border border-input bg-transparent palette:text-foreground py-2 pr-2 pl-2.5 text-sm whitespace-nowrap transition-colors outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-placeholder:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 data-[size=sm]:rounded-[min(var(--radius-md),10px)] *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className), ...props, children: [children, _jsx(SelectPrimitive.Icon, { render: _jsx(ChevronDownIcon, { className: "pointer-events-none size-4 text-muted-foreground" }) })] }));
|
|
15
|
+
return (_jsxs(SelectPrimitive.Trigger, { "data-slot": "select-trigger", "data-size": size, className: cn("flex w-fit items-center justify-between gap-1.5 rounded-md border border-input bg-transparent palette:text-foreground py-2 pr-2 pl-2.5 text-sm whitespace-nowrap transition-colors outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-placeholder:text-muted-foreground data-[size=default]:h-[var(--control-height,--spacing(9))] data-[size=sm]:h-8 data-[size=sm]:rounded-[min(var(--radius-md),10px)] *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className), ...props, children: [children, _jsx(SelectPrimitive.Icon, { render: _jsx(ChevronDownIcon, { className: "pointer-events-none size-4 text-muted-foreground" }) })] }));
|
|
16
16
|
}
|
|
17
17
|
function SelectContent({ className, children, side = "bottom", sideOffset = 4, align = "center", alignOffset = 0, alignItemWithTrigger = true, ...props }) {
|
|
18
18
|
return (_jsx(SelectPrimitive.Portal, { children: _jsx(SelectPrimitive.Positioner, { side: side, sideOffset: sideOffset, align: align, alignOffset: alignOffset, alignItemWithTrigger: alignItemWithTrigger, className: "isolate z-50", children: _jsxs(SelectPrimitive.Popup, { "data-slot": "select-content", "data-align-trigger": alignItemWithTrigger, className: cn("relative isolate z-50 max-h-(--available-height) w-(--anchor-width) min-w-36 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[align-trigger=true]:animate-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", className), ...props, children: [_jsx(SelectScrollUpButton, {}), _jsx(SelectPrimitive.List, { children: children }), _jsx(SelectScrollDownButton, {})] }) }) }));
|
|
@@ -4,6 +4,8 @@ type Sort = readonly {
|
|
|
4
4
|
}[];
|
|
5
5
|
export type UrlChanges = Record<string, string | string[] | null>;
|
|
6
6
|
export type TableView<F extends string, M extends string> = {
|
|
7
|
+
/** Its pill's word in DataTable's `views` ("Current"); the view's id unless set. */
|
|
8
|
+
label?: string;
|
|
7
9
|
filters?: Partial<Record<F, string>>;
|
|
8
10
|
multiFilters?: Partial<Record<M, string[]>>;
|
|
9
11
|
sort?: Sort;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type ColumnsPick } from '../components/app/table-columns.js';
|
|
2
|
+
/** The pick stored under `key`, read and written through the device's store. */
|
|
3
|
+
export declare function useColumnsPick(key: string | undefined): readonly [ColumnsPick | null, (next: ColumnsPick | null) => void];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// DataTable's Columns menu pick (`columnsMenu`), remembered on this device
|
|
2
|
+
// under the list's `storageKey` in the same store as a table's layout and
|
|
3
|
+
// grouping (use-table-layout.ts). The format is table-columns.ts's.
|
|
4
|
+
import { useCallback, useSyncExternalStore } from 'react';
|
|
5
|
+
import { parseColumnsPick } from '../components/app/table-columns.js';
|
|
6
|
+
import { browserStore } from './use-table-layout.js';
|
|
7
|
+
/** The pick stored under `key`, read and written through the device's store. */
|
|
8
|
+
export function useColumnsPick(key) {
|
|
9
|
+
const subscribe = useCallback((listener) => (key === undefined ? () => { } : browserStore.subscribe(key, listener)), [key]);
|
|
10
|
+
const raw = useSyncExternalStore(subscribe, () => (key === undefined ? null : browserStore.get(key)), () => null);
|
|
11
|
+
const pick = parseColumnsPick(raw);
|
|
12
|
+
const setPick = (next) => {
|
|
13
|
+
if (key === undefined)
|
|
14
|
+
return;
|
|
15
|
+
browserStore.set(key, next === null ? '' : JSON.stringify(next));
|
|
16
|
+
};
|
|
17
|
+
return [pick, setPick];
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useIsPhone(): boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useSyncExternalStore } from 'react';
|
|
2
|
+
// Whether the screen is under 48rem (useIsMobile's 768px), read through
|
|
3
|
+
// matchMedia as a store, so rendering on the server or where matchMedia is
|
|
4
|
+
// missing (a test's DOM) gives "not a phone" instead of failing on
|
|
5
|
+
// `window`. DataTable's row list, FilterBar and SecondaryFilters' sheet
|
|
6
|
+
// read it, so they always agree.
|
|
7
|
+
const PHONE_QUERY = '(max-width: 767px)';
|
|
8
|
+
const canMatchMedia = () => typeof window !== 'undefined' && typeof window.matchMedia === 'function';
|
|
9
|
+
function subscribe(listener) {
|
|
10
|
+
if (!canMatchMedia())
|
|
11
|
+
return () => { };
|
|
12
|
+
const query = window.matchMedia(PHONE_QUERY);
|
|
13
|
+
query.addEventListener('change', listener);
|
|
14
|
+
return () => query.removeEventListener('change', listener);
|
|
15
|
+
}
|
|
16
|
+
export function useIsPhone() {
|
|
17
|
+
return useSyncExternalStore(subscribe, () => canMatchMedia() && window.matchMedia(PHONE_QUERY).matches, () => false);
|
|
18
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,9 +10,15 @@ export { ColorSwatch, type ColorSwatchProps } from './components/app/color-swatc
|
|
|
10
10
|
export { storedColor } from './lib/stored-color.js';
|
|
11
11
|
export { CountLink, type CountLinkProps } from './components/app/count-link.js';
|
|
12
12
|
export { DataTable, type DataTableCardLayout, type DataTableOpens, type DataTableOpensKind, type DataTableGrouping, type DataTableProps, type DataTableTotals, type DataTableWidth, type SortingState, } from './components/app/data-table.js';
|
|
13
|
+
export { type DataTableColumnsMenu, type DataTablePhoneRow, type DataTableRowAction, type DataTableView, type DataTableViewAll, } from './components/app/data-table-tools.js';
|
|
14
|
+
export { RelatedTable, type RelatedTableProps } from './components/app/related-table.js';
|
|
13
15
|
export { type RowGroup } from './components/app/table-groups.js';
|
|
14
16
|
export { byDay, type ByDayOptions } from './lib/group-by-day.js';
|
|
15
17
|
export { EntityForm, type EntityFormProps } from './components/app/entity-form.js';
|
|
18
|
+
export { countFormErrors } from './lib/form-errors.js';
|
|
19
|
+
export { FormSection, type FormSectionProps } from './components/app/form-section.js';
|
|
20
|
+
export { OptionSelect, type OptionSelectOption, type OptionSelectProps } from './components/app/option-select.js';
|
|
21
|
+
export { fieldRows, type FieldKind, type FieldRowItem, type FieldRowPlace, type FieldSize } from './lib/field-rows.js';
|
|
16
22
|
export { KeyStats, type KeyStat, type KeyStatsProps } from './components/app/key-stats.js';
|
|
17
23
|
export { IconAction, type IconActionProps } from './components/app/icon-action.js';
|
|
18
24
|
export { EntityView, type EntityViewEmptyFields, type EntityViewField, type EntityViewLayout, type EntityViewMobileOrder, type EntityViewPlacement, type EntityViewProps, type EntityViewRailFields, type EntityViewSection, } from './components/app/entity-view.js';
|
|
@@ -45,6 +51,7 @@ export { RichTextEditor, type RichTextEditorProps } from './components/app/rich-
|
|
|
45
51
|
export { RouteErrorBoundary } from './components/app/route-error-boundary.js';
|
|
46
52
|
export { PillFilter, type PillFilterOption, type PillFilterProps } from './components/app/pill-filter.js';
|
|
47
53
|
export { SecondaryFilters, type ActiveFilter, type SecondaryFiltersProps } from './components/app/secondary-filters.js';
|
|
54
|
+
export { FilterBar, FilterSelect, type FilterBarProps, type FilterBarSearch, type FilterSelectOption, type FilterSelectProps, } from './components/app/filter-bar.js';
|
|
48
55
|
export { SessionStage, SessionView, sessionStageLit, sessionStageMain, sessionStageQuiet, type SessionStageProps, type SessionStageTone, type SessionViewProps, } from './components/app/session-view.js';
|
|
49
56
|
export { AllowReminders, type AllowRemindersProps } from './components/app/allow-reminders.js';
|
|
50
57
|
export { StageCircle, type StageCircleProps, type StageCircleStage, type StageCircleTone, } from './components/app/stage-circle.js';
|
package/dist/index.js
CHANGED
|
@@ -14,9 +14,15 @@ export { ColorSwatch } from './components/app/color-swatch.js';
|
|
|
14
14
|
export { storedColor } from './lib/stored-color.js';
|
|
15
15
|
export { CountLink } from './components/app/count-link.js';
|
|
16
16
|
export { DataTable, } from './components/app/data-table.js';
|
|
17
|
+
export {} from './components/app/data-table-tools.js';
|
|
18
|
+
export { RelatedTable } from './components/app/related-table.js';
|
|
17
19
|
export {} from './components/app/table-groups.js';
|
|
18
20
|
export { byDay } from './lib/group-by-day.js';
|
|
19
21
|
export { EntityForm } from './components/app/entity-form.js';
|
|
22
|
+
export { countFormErrors } from './lib/form-errors.js';
|
|
23
|
+
export { FormSection } from './components/app/form-section.js';
|
|
24
|
+
export { OptionSelect } from './components/app/option-select.js';
|
|
25
|
+
export { fieldRows } from './lib/field-rows.js';
|
|
20
26
|
export { KeyStats } from './components/app/key-stats.js';
|
|
21
27
|
export { IconAction } from './components/app/icon-action.js';
|
|
22
28
|
export { EntityView, } from './components/app/entity-view.js';
|
|
@@ -47,6 +53,7 @@ export { RichTextEditor } from './components/app/rich-text-editor.js';
|
|
|
47
53
|
export { RouteErrorBoundary } from './components/app/route-error-boundary.js';
|
|
48
54
|
export { PillFilter } from './components/app/pill-filter.js';
|
|
49
55
|
export { SecondaryFilters } from './components/app/secondary-filters.js';
|
|
56
|
+
export { FilterBar, FilterSelect, } from './components/app/filter-bar.js';
|
|
50
57
|
export { SessionStage, SessionView, sessionStageLit, sessionStageMain, sessionStageQuiet, } from './components/app/session-view.js';
|
|
51
58
|
export { AllowReminders } from './components/app/allow-reminders.js';
|
|
52
59
|
export { StageCircle, } from './components/app/stage-circle.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type FieldSize = 's' | 'm' | 'l' | 'full';
|
|
2
|
+
export type FieldKind = 'date' | 'number';
|
|
3
|
+
export type FieldRowItem = {
|
|
4
|
+
size: FieldSize;
|
|
5
|
+
solo?: boolean;
|
|
6
|
+
kind?: FieldKind | null;
|
|
7
|
+
};
|
|
8
|
+
export type FieldRowPlace = {
|
|
9
|
+
/** Its share of the row's width (after the gaps), or null for a row of its own. */
|
|
10
|
+
share: number | null;
|
|
11
|
+
/** How many gaps its row has (fields in it, less one). */
|
|
12
|
+
gaps: number;
|
|
13
|
+
/** Stays beside its partner on a phone: two dates or two numbers. */
|
|
14
|
+
phonePair: boolean;
|
|
15
|
+
};
|
|
16
|
+
/** The most fields one row holds. */
|
|
17
|
+
export declare const FIELDS_PER_ROW = 3;
|
|
18
|
+
export declare function fieldRows(items: readonly FieldRowItem[]): FieldRowPlace[];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Which fields of a form share a row (4.85, the form standard's F1),
|
|
2
|
+
// worked out from their order, never listed by hand. A field says how
|
|
3
|
+
// much it holds (`Field size`); consecutive short ones share a row, up to
|
|
4
|
+
// three, each as wide as its size: s 1, m 1.4, l 2.6 parts of the row.
|
|
5
|
+
// A long box (`l`) takes one short partner at most (a series and its
|
|
6
|
+
// number), never another long one, so the row ends with the pair and the
|
|
7
|
+
// next short fields start their own (Started, Finished, Rating). `full`
|
|
8
|
+
// (a field with no size), a `solo` field and anything that isn't a Field
|
|
9
|
+
// take a row of their own.
|
|
10
|
+
//
|
|
11
|
+
// Below 48rem every field takes its own row, except two dates or two
|
|
12
|
+
// numbers next to each other in a row, which stay side by side
|
|
13
|
+
// (`phonePair`).
|
|
14
|
+
const PARTS = { s: 1, m: 1.4, l: 2.6 };
|
|
15
|
+
/** The most fields one row holds. */
|
|
16
|
+
export const FIELDS_PER_ROW = 3;
|
|
17
|
+
export function fieldRows(items) {
|
|
18
|
+
const places = items.map(() => ({ share: null, gaps: 0, phonePair: false }));
|
|
19
|
+
let row = [];
|
|
20
|
+
const close = () => {
|
|
21
|
+
if (row.length > 1) {
|
|
22
|
+
const parts = row.map((at) => PARTS[items[at].size]);
|
|
23
|
+
const total = parts.reduce((sum, part) => sum + part, 0);
|
|
24
|
+
row.forEach((at, index) => {
|
|
25
|
+
places[at] = { share: parts[index] / total, gaps: row.length - 1, phonePair: false };
|
|
26
|
+
});
|
|
27
|
+
for (let index = 0; index + 1 < row.length; index++) {
|
|
28
|
+
const a = items[row[index]].kind;
|
|
29
|
+
const b = items[row[index + 1]].kind;
|
|
30
|
+
if (a && a === b && !places[row[index]].phonePair) {
|
|
31
|
+
places[row[index]].phonePair = true;
|
|
32
|
+
places[row[index + 1]].phonePair = true;
|
|
33
|
+
index++;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
row = [];
|
|
38
|
+
};
|
|
39
|
+
items.forEach((item, at) => {
|
|
40
|
+
const shares = item.size !== 'full' && !item.solo;
|
|
41
|
+
if (!shares) {
|
|
42
|
+
close();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const hasLong = row.some((index) => items[index].size === 'l');
|
|
46
|
+
const full = row.length >= (hasLong || item.size === 'l' ? 2 : FIELDS_PER_ROW);
|
|
47
|
+
if (full || (item.size === 'l' && hasLong))
|
|
48
|
+
close();
|
|
49
|
+
row.push(at);
|
|
50
|
+
});
|
|
51
|
+
close();
|
|
52
|
+
return places;
|
|
53
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How many problems react-hook-form's `formState.errors` hold: one per
|
|
3
|
+
* field, one per list's own (`root`), however deep (4.85, EntityForm's
|
|
4
|
+
* "N to fix").
|
|
5
|
+
*/
|
|
6
|
+
export function countFormErrors(errors) {
|
|
7
|
+
if (!errors || typeof errors !== 'object')
|
|
8
|
+
return 0;
|
|
9
|
+
const entry = errors;
|
|
10
|
+
if (typeof entry.type === 'string' || typeof entry.message === 'string')
|
|
11
|
+
return 1;
|
|
12
|
+
let count = 0;
|
|
13
|
+
for (const [key, value] of Object.entries(entry)) {
|
|
14
|
+
if (key === 'ref')
|
|
15
|
+
continue;
|
|
16
|
+
count += countFormErrors(value);
|
|
17
|
+
}
|
|
18
|
+
return count;
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.86.0",
|
|
4
4
|
"description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/styles/index.css
CHANGED
|
@@ -615,3 +615,63 @@
|
|
|
615
615
|
.page-removed .page-removed-note {
|
|
616
616
|
margin-inline: 0;
|
|
617
617
|
}
|
|
618
|
+
|
|
619
|
+
/* Forms (4.85, the form standard; field.tsx and entity-form.tsx).
|
|
620
|
+
Compact: controls inside a FieldGroup and on a form's bar read
|
|
621
|
+
--control-height (Input, SelectTrigger, InputGroup, the combobox's chips
|
|
622
|
+
box and a default Button), 32px, or 40px under 48rem or on a touch
|
|
623
|
+
screen, for the finger. Anywhere else they keep their 36px. Each is a
|
|
624
|
+
calc of --spacing, resolved here, so the large density grows it. */
|
|
625
|
+
[data-slot="field-group"],
|
|
626
|
+
[data-slot="entity-form-bar"],
|
|
627
|
+
[data-slot="form-dialog-bar"] {
|
|
628
|
+
--control-height: calc(var(--spacing) * 8);
|
|
629
|
+
}
|
|
630
|
+
@media (width < 48rem), (pointer: coarse) {
|
|
631
|
+
[data-slot="field-group"],
|
|
632
|
+
[data-slot="entity-form-bar"],
|
|
633
|
+
[data-slot="form-dialog-bar"] {
|
|
634
|
+
--control-height: calc(var(--spacing) * 10);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/* Short fields side by side (FieldGroup's layOut sets --field-share and
|
|
639
|
+
--field-gaps on each field of a shared row; lib/field-rows.ts): its
|
|
640
|
+
share of what the row's gaps leave. A hair under, so rounding never
|
|
641
|
+
pushes the last one onto the next line. Under 48rem every field takes
|
|
642
|
+
the row but two dates or two numbers. */
|
|
643
|
+
/* Everything else in a group takes the row, as it did when the group was
|
|
644
|
+
a column (a button, a fieldset, a line of text). In the base layer, so
|
|
645
|
+
a width utility on the child still wins. */
|
|
646
|
+
@layer base {
|
|
647
|
+
[data-slot="field-group"] > * {
|
|
648
|
+
width: 100%;
|
|
649
|
+
min-width: 0;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
[data-slot="field-group"] > [data-field-row] {
|
|
653
|
+
flex: 0 0 auto;
|
|
654
|
+
width: calc((100% - var(--field-gaps) * var(--spacing) * 3) * var(--field-share) - 0.05px);
|
|
655
|
+
}
|
|
656
|
+
@media (width < 48rem) {
|
|
657
|
+
[data-slot="field-group"] > [data-field-row] {
|
|
658
|
+
width: 100%;
|
|
659
|
+
}
|
|
660
|
+
[data-slot="field-group"] > [data-field-row][data-phone-pair] {
|
|
661
|
+
width: calc((100% - var(--spacing) * 3) / 2 - 0.05px);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
/* EntityForm's bar, stuck to the bottom of the window while the form is
|
|
666
|
+
taller than it. Above the shell's bottom bar on a phone, which then
|
|
667
|
+
has the safe area under it already. */
|
|
668
|
+
[data-slot="entity-form-bar"] {
|
|
669
|
+
bottom: var(--form-bar-bottom, 0px);
|
|
670
|
+
padding-bottom: calc(var(--spacing) * 3 + var(--form-bar-safe-area, env(safe-area-inset-bottom)));
|
|
671
|
+
}
|
|
672
|
+
@media (width < 48rem) {
|
|
673
|
+
:root:has([data-slot="app-shell-bottom-bar"]) {
|
|
674
|
+
--form-bar-bottom: calc(var(--spacing) * 16 + 1px + env(safe-area-inset-bottom));
|
|
675
|
+
--form-bar-safe-area: 0px;
|
|
676
|
+
}
|
|
677
|
+
}
|