@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
|
@@ -15,17 +15,20 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
15
15
|
//
|
|
16
16
|
// `dirty` (react-hook-form's `formState.isDirty`) makes Esc, the close
|
|
17
17
|
// button, a click outside and Cancel ask "Discard your changes?" first.
|
|
18
|
+
// As a list's `new` route, `dirty` also guards leaving by a link, Back or
|
|
19
|
+
// the sidebar (FormLeaveGuard, 4.85), as EntityForm's does.
|
|
18
20
|
// A failed save is a Notice above the buttons with Try again, which
|
|
19
21
|
// submits again unless `onRetry` says otherwise; what was typed stays.
|
|
20
22
|
//
|
|
21
23
|
// The form is the app's: its fields, its schema and its react-hook-form
|
|
22
24
|
// wiring, as with EntityForm. This draws the chrome around them.
|
|
23
|
-
import { useId, useRef } from 'react';
|
|
25
|
+
import { useId, useLayoutEffect, useRef } from 'react';
|
|
24
26
|
import { cn } from 'cn';
|
|
25
27
|
import { Button } from '../ui/button.js';
|
|
26
28
|
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogTitle } from '../ui/dialog.js';
|
|
27
29
|
import { FieldGroup } from '../ui/field.js';
|
|
28
30
|
import { Spinner } from '../ui/spinner.js';
|
|
31
|
+
import { FormLeaveGuard } from './form-leave-guard.js';
|
|
29
32
|
import { Notice } from './notice.js';
|
|
30
33
|
import { useNewRecordDialog } from './record-dialog-context.js';
|
|
31
34
|
export function FormDialog({ title, description, open, onOpenChange, onSubmit, isSubmitting, submitLabel, submitError, onRetry, dirty = false, children, className, }) {
|
|
@@ -33,10 +36,19 @@ export function FormDialog({ title, description, open, onOpenChange, onSubmit, i
|
|
|
33
36
|
const form = useRef(null);
|
|
34
37
|
const formId = useId();
|
|
35
38
|
const isOpen = open ?? route !== null;
|
|
36
|
-
|
|
39
|
+
// The route guard lets through the dialog's own close (it has asked
|
|
40
|
+
// already) and the save's move to the new record.
|
|
41
|
+
const leaving = useRef(false);
|
|
42
|
+
const submitting = useRef(isSubmitting);
|
|
43
|
+
useLayoutEffect(() => {
|
|
44
|
+
submitting.current = isSubmitting;
|
|
45
|
+
});
|
|
46
|
+
return (_jsxs(Dialog, { open: isOpen, onOpenChange: (next) => {
|
|
37
47
|
if (onOpenChange)
|
|
38
48
|
onOpenChange(next);
|
|
39
|
-
else if (!next)
|
|
49
|
+
else if (!next) {
|
|
50
|
+
leaving.current = true;
|
|
40
51
|
route?.close();
|
|
41
|
-
|
|
52
|
+
}
|
|
53
|
+
}, children: [_jsxs(DialogContent, { size: "form", dirty: dirty, "data-slot": "form-dialog", className: cn('gap-0 p-0', className), children: [_jsxs("div", { "data-slot": "form-dialog-header", className: "flex flex-col gap-1 px-4 pt-4 pb-2 pr-12 md:px-6 md:pt-5 md:pr-14", children: [_jsx(DialogTitle, { className: "type-section-title", children: title }), description && _jsx(DialogDescription, { children: description })] }), _jsxs("form", { ref: form, id: formId, onSubmit: onSubmit, noValidate: true, className: "flex min-h-0 flex-1 flex-col", children: [_jsx("div", { "data-slot": "form-dialog-body", className: "min-h-0 flex-1 overflow-y-auto px-4 py-4 md:px-6", children: _jsx(FieldGroup, { children: children }) }), _jsxs("div", { "data-slot": "form-dialog-bar", className: "flex flex-col gap-3 border-t px-4 py-3 pb-[calc(0.75rem+env(safe-area-inset-bottom))] md:px-6 md:pb-3", children: [_jsx("div", { role: "status", className: "empty:hidden", children: submitError && (_jsx(Notice, { tone: "destructive", action: _jsx(Button, { type: "button", size: "sm", variant: "outline", disabled: isSubmitting, onClick: () => (onRetry ? onRetry() : form.current?.requestSubmit()), children: "Try again" }), children: submitError.message })) }), _jsxs("div", { className: "flex justify-end gap-2 max-md:[&>*]:h-10 max-md:[&>*]:flex-1", children: [_jsx(DialogClose, { render: _jsx(Button, { type: "button", variant: "outline", disabled: isSubmitting }), children: "Cancel" }), _jsxs(Button, { type: "submit", disabled: isSubmitting, children: [isSubmitting && _jsx(Spinner, { className: "size-4" }), submitLabel] })] })] })] })] }), route && open === undefined && (_jsx(FormLeaveGuard, { dirty: dirty, letThrough: () => leaving.current || submitting.current }))] }));
|
|
42
54
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Leaving a form with something typed (4.85, the form standard's F8):
|
|
3
|
+
// "Discard your changes?" (Keep editing, Discard), the prompt a dialog
|
|
4
|
+
// and a value edited in place ask with, before a link, Back or the
|
|
5
|
+
// sidebar moves to another page; the browser's own prompt before a reload
|
|
6
|
+
// or closing the tab. Nothing typed, nothing asked.
|
|
7
|
+
//
|
|
8
|
+
// EntityForm renders it when it's given `dirty`, and FormDialog when it
|
|
9
|
+
// is a list's `new` route. React Router's useBlocker, so it needs a data
|
|
10
|
+
// router (createBrowserRouter), as EditableValue's guard does.
|
|
11
|
+
//
|
|
12
|
+
// `letThrough` is read when a move starts: true while the form is saving
|
|
13
|
+
// (the save's own navigate to the new record must not ask), and once the
|
|
14
|
+
// form has already asked (its Cancel) or the move is its own close.
|
|
15
|
+
import { useEffect, useLayoutEffect, useRef } from 'react';
|
|
16
|
+
import { useBlocker } from 'react-router';
|
|
17
|
+
import { DiscardChangesDialog } from '../ui/dialog.js';
|
|
18
|
+
export function FormLeaveGuard({ dirty, letThrough }) {
|
|
19
|
+
const latest = useRef({ dirty, letThrough });
|
|
20
|
+
useLayoutEffect(() => {
|
|
21
|
+
latest.current = { dirty, letThrough };
|
|
22
|
+
});
|
|
23
|
+
const blocker = useBlocker(({ currentLocation, nextLocation }) => latest.current.dirty && !latest.current.letThrough() && currentLocation.pathname !== nextLocation.pathname);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!dirty)
|
|
26
|
+
return;
|
|
27
|
+
const onBeforeUnload = (event) => {
|
|
28
|
+
if (latest.current.letThrough())
|
|
29
|
+
return;
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
};
|
|
32
|
+
window.addEventListener('beforeunload', onBeforeUnload);
|
|
33
|
+
return () => window.removeEventListener('beforeunload', onBeforeUnload);
|
|
34
|
+
}, [dirty]);
|
|
35
|
+
return (_jsx(DiscardChangesDialog, { open: blocker.state === 'blocked', "data-form-leave-guard": "", onKeepEditing: () => {
|
|
36
|
+
if (blocker.state === 'blocked')
|
|
37
|
+
blocker.reset();
|
|
38
|
+
}, onDiscard: () => {
|
|
39
|
+
if (blocker.state === 'blocked')
|
|
40
|
+
blocker.proceed();
|
|
41
|
+
} }));
|
|
42
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export type FormSectionProps = {
|
|
3
|
+
/** What the group is ("Reading", "Details"): sentence case, a word or two. */
|
|
4
|
+
title: string;
|
|
5
|
+
/** The group's fields. */
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
className?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function FormSection({ title, children, className }: FormSectionProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// A group of a form's fields in a card (4.85, the form standard's F2),
|
|
3
|
+
// drawn as a record's section is (EntityView): the card surface, its title
|
|
4
|
+
// on the heading band. Only on a form of eight fields or more, and never
|
|
5
|
+
// in a dialog; a short form is one run of fields. Its fields are a
|
|
6
|
+
// FieldGroup of their own, so short ones share rows inside it as they do
|
|
7
|
+
// on the form.
|
|
8
|
+
import { useId } from 'react';
|
|
9
|
+
import { cn } from 'cn';
|
|
10
|
+
import { Card, CardContent, CardHeader } from '../ui/card.js';
|
|
11
|
+
import { FieldGroup } from '../ui/field.js';
|
|
12
|
+
export function FormSection({ title, children, className }) {
|
|
13
|
+
const headingId = useId();
|
|
14
|
+
return (_jsx("section", { "aria-labelledby": headingId, "data-slot": "form-section", className: cn('w-full', className), children: _jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx("h2", { id: headingId, className: "type-section-title text-foreground", children: title }) }), _jsx(CardContent, { children: _jsx(FieldGroup, { children: children }) })] }) }));
|
|
15
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
export declare function MultiChoice<T extends string>({ options, value, onValueChange, getLabel, id, placeholder, 'aria-label': ariaLabel, 'aria-invalid': ariaInvalid, className, }: {
|
|
2
|
+
export declare function MultiChoice<T extends string>({ options, value, onValueChange, getLabel, id, placeholder, label, 'aria-label': ariaLabel, 'aria-invalid': ariaInvalid, className, }: {
|
|
3
3
|
/** Every allowed option, in display order. */
|
|
4
4
|
options: readonly T[];
|
|
5
5
|
value: T[];
|
|
@@ -12,6 +12,14 @@ export declare function MultiChoice<T extends string>({ options, value, onValueC
|
|
|
12
12
|
/** Id for the text input, so a <FieldLabel htmlFor> labels it. */
|
|
13
13
|
id?: string;
|
|
14
14
|
placeholder?: string;
|
|
15
|
+
/**
|
|
16
|
+
* A toolbar filter that names itself (the list page standard, L4): with
|
|
17
|
+
* picks it shows "<label>: <first> +N" in place of a chip per pick, so
|
|
18
|
+
* it stays one line; with none, the `placeholder` ("Any status"). Picks
|
|
19
|
+
* come off in the list, or with Backspace. Leave it out on a form, where
|
|
20
|
+
* every pick is its own chip.
|
|
21
|
+
*/
|
|
22
|
+
label?: string;
|
|
15
23
|
/** For use without a visible label (e.g. a table toolbar filter). */
|
|
16
24
|
'aria-label'?: string;
|
|
17
25
|
'aria-invalid'?: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
// A multi-choice picker: selected options as removable chips, the rest in a
|
|
3
3
|
// filterable dropdown. The one control for every "multi choice" field
|
|
4
4
|
// (conventions/docs/entity-plan-template.md) — on a form (Widget Tags) and as a table
|
|
@@ -11,7 +11,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
11
11
|
// typed-text match all use the label, and the value is what's emitted.
|
|
12
12
|
import * as React from 'react';
|
|
13
13
|
import { Combobox, ComboboxChip, ComboboxChips, ComboboxChipsInput, ComboboxContent, ComboboxEmpty, ComboboxItem, ComboboxList, ComboboxValue, useComboboxAnchor, } from '../ui/combobox.js';
|
|
14
|
-
export function MultiChoice({ options, value, onValueChange, getLabel = String, id, placeholder, 'aria-label': ariaLabel, 'aria-invalid': ariaInvalid, className, }) {
|
|
14
|
+
export function MultiChoice({ options, value, onValueChange, getLabel = String, id, placeholder, label, 'aria-label': ariaLabel, 'aria-invalid': ariaInvalid, className, }) {
|
|
15
15
|
const anchor = useComboboxAnchor();
|
|
16
16
|
return (_jsxs(Combobox, { multiple: true, autoHighlight: true, items: options, value: value, onValueChange: (next, details) => {
|
|
17
17
|
// Base UI empties the value on Escape while the list is closed, so
|
|
@@ -25,5 +25,5 @@ export function MultiChoice({ options, value, onValueChange, getLabel = String,
|
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
onValueChange(next);
|
|
28
|
-
}, itemToStringLabel: getLabel, children: [_jsx(ComboboxChips, { ref: anchor, className: className, children: _jsx(ComboboxValue, { children: (selected) => (_jsxs(React.Fragment, { children: [selected.map((option) => (_jsx(ComboboxChip, { children: getLabel(option) }, option))), _jsx(ComboboxChipsInput, { id: id, "aria-label": ariaLabel, "aria-invalid": ariaInvalid, placeholder: selected.length === 0 ? placeholder : undefined })] })) }) }), _jsxs(ComboboxContent, { anchor: anchor, children: [_jsx(ComboboxEmpty, { children: "No options found." }), _jsx(ComboboxList, { children: (option) => (_jsx(ComboboxItem, { value: option, children: getLabel(option) }, option)) })] })] }));
|
|
28
|
+
}, itemToStringLabel: getLabel, children: [_jsx(ComboboxChips, { ref: anchor, className: className, children: _jsx(ComboboxValue, { children: (selected) => (_jsxs(React.Fragment, { children: [label !== undefined && selected.length > 0 ? (_jsxs("span", { "data-slot": "multi-choice-summary", className: "min-w-0 truncate pl-1 type-body text-foreground", children: [label, ": ", getLabel(selected[0]), selected.length > 1 && _jsxs("span", { className: "text-muted-foreground", children: [" +", selected.length - 1] })] })) : null, (label === undefined ? selected : []).map((option) => (_jsx(ComboboxChip, { children: getLabel(option) }, option))), _jsx(ComboboxChipsInput, { id: id, "aria-label": ariaLabel, "aria-invalid": ariaInvalid, placeholder: selected.length === 0 ? placeholder : undefined })] })) }) }), _jsxs(ComboboxContent, { anchor: anchor, children: [_jsx(ComboboxEmpty, { children: "No options found." }), _jsx(ComboboxList, { children: (option) => (_jsx(ComboboxItem, { value: option, children: getLabel(option) }, option)) })] })] }));
|
|
29
29
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export type OptionSelectOption<T> = {
|
|
3
|
+
value: T;
|
|
4
|
+
label: string;
|
|
5
|
+
};
|
|
6
|
+
export type OptionSelectProps<T extends string | number> = {
|
|
7
|
+
id?: string;
|
|
8
|
+
/** Every option, in the order the list shows them. */
|
|
9
|
+
options: readonly OptionSelectOption<T>[];
|
|
10
|
+
value: T | null;
|
|
11
|
+
onValueChange: (value: T | null) => void;
|
|
12
|
+
/** How an option reads on the trigger and in the list (a badge). Defaults to its label. */
|
|
13
|
+
render?: (value: T, label: string) => ReactNode;
|
|
14
|
+
/** No "Not set" option: one of the list must be picked. */
|
|
15
|
+
required?: boolean;
|
|
16
|
+
/** The "Not set" option's words. */
|
|
17
|
+
emptyLabel?: string;
|
|
18
|
+
/** The trigger's words while nothing is picked (a required one). */
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
invalid?: boolean;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
defaultOpen?: boolean;
|
|
23
|
+
onOpenChange?: (open: boolean) => void;
|
|
24
|
+
modal?: boolean;
|
|
25
|
+
className?: string;
|
|
26
|
+
'aria-label'?: string;
|
|
27
|
+
'aria-labelledby'?: string;
|
|
28
|
+
'aria-describedby'?: string;
|
|
29
|
+
};
|
|
30
|
+
export declare function OptionSelect<T extends string | number>({ id, options, value, onValueChange, render, required, emptyLabel, placeholder, invalid, disabled, defaultOpen, onOpenChange, modal, className, ...aria }: OptionSelectProps<T>): import("react").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from 'cn';
|
|
3
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select.js';
|
|
4
|
+
const NONE = '__none__';
|
|
5
|
+
export function OptionSelect({ id, options, value, onValueChange, render, required = false, emptyLabel = 'Not set', placeholder = 'Pick one', invalid = false, disabled, defaultOpen, onOpenChange, modal, className, ...aria }) {
|
|
6
|
+
const shown = (option) => (render ? render(option.value, option.label) : option.label);
|
|
7
|
+
const at = value == null ? -1 : options.findIndex((option) => option.value === value);
|
|
8
|
+
const key = at === -1 ? (required ? null : NONE) : String(at);
|
|
9
|
+
return (_jsxs(Select, { value: key, onValueChange: (next) => {
|
|
10
|
+
if (next === null)
|
|
11
|
+
return;
|
|
12
|
+
onValueChange(next === NONE ? null : (options[Number(next)]?.value ?? null));
|
|
13
|
+
}, disabled: disabled, defaultOpen: defaultOpen, onOpenChange: onOpenChange, modal: modal, children: [_jsx(SelectTrigger, { id: id, "aria-invalid": invalid || undefined, className: cn('w-full', className), ...aria, children: _jsx(SelectValue, { placeholder: placeholder, children: (picked) => {
|
|
14
|
+
if (picked === null)
|
|
15
|
+
return placeholder;
|
|
16
|
+
if (picked === NONE)
|
|
17
|
+
return _jsx("span", { className: "text-muted-foreground", children: emptyLabel });
|
|
18
|
+
const option = options[Number(picked)];
|
|
19
|
+
return option ? shown(option) : placeholder;
|
|
20
|
+
} }) }), _jsxs(SelectContent, { children: [!required && _jsx(SelectItem, { value: NONE, children: emptyLabel }), options.map((option, index) => (_jsx(SelectItem, { value: String(index), children: shown(option) }, String(option.value))))] })] }));
|
|
21
|
+
}
|
|
@@ -11,5 +11,7 @@ export type PillFilterProps = {
|
|
|
11
11
|
onValueChange: (value: string) => void;
|
|
12
12
|
/** The first pill, which clears the filter. null leaves it out, for a filter that always has a value. */
|
|
13
13
|
allLabel?: string | null;
|
|
14
|
+
/** On the group: `flex-nowrap` (with a scrolling parent) keeps the pills on one line. */
|
|
15
|
+
className?: string;
|
|
14
16
|
};
|
|
15
|
-
export declare function PillFilter({ label, options, value, onValueChange, allLabel }: PillFilterProps): import("react").JSX.Element;
|
|
17
|
+
export declare function PillFilter({ label, options, value, onValueChange, allLabel, className }: PillFilterProps): import("react").JSX.Element;
|
|
@@ -10,6 +10,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
10
10
|
// with `setFilter`. Built on shadcn's ToggleGroup (Base UI): a group named
|
|
11
11
|
// by `label`, one tab stop, the arrow keys along it, each pill a toggle
|
|
12
12
|
// button with aria-pressed.
|
|
13
|
+
import { cn } from 'cn';
|
|
13
14
|
import { ToggleGroup, ToggleGroupItem } from '../ui/toggle-group.js';
|
|
14
15
|
// The All pill's value inside the group: Base UI's toggles need one that
|
|
15
16
|
// isn't empty, and '' is what the app's filter calls All.
|
|
@@ -18,10 +19,10 @@ const ALL = '__all__';
|
|
|
18
19
|
// (bg-muted) is ~3% off the page, too faint to say which one is on.
|
|
19
20
|
const PILL_CLASS = 'rounded-full px-3 aria-pressed:border-primary aria-pressed:bg-primary aria-pressed:text-primary-foreground ' +
|
|
20
21
|
'aria-pressed:hover:bg-primary/90 aria-pressed:hover:text-primary-foreground';
|
|
21
|
-
export function PillFilter({ label, options, value, onValueChange, allLabel = 'All' }) {
|
|
22
|
+
export function PillFilter({ label, options, value, onValueChange, allLabel = 'All', className }) {
|
|
22
23
|
const pills = allLabel === null ? options : [{ value: ALL, label: allLabel }, ...options];
|
|
23
24
|
const pressed = value === '' && allLabel !== null ? ALL : value;
|
|
24
|
-
return (_jsx(ToggleGroup, { "aria-label": label, variant: "outline", size: "sm", spacing: 1, className:
|
|
25
|
+
return (_jsx(ToggleGroup, { "aria-label": label, variant: "outline", size: "sm", spacing: 1, className: cn('flex-wrap', className), value: [pressed], onValueChange: (next) => {
|
|
25
26
|
// [] is the pressed pill pressed again: it stays on.
|
|
26
27
|
const chosen = next[0];
|
|
27
28
|
if (chosen === undefined || chosen === pressed)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type DataTableOpens, type DataTableProps } from './data-table.js';
|
|
2
|
+
import type { DataTableViewAll } from './data-table-tools.js';
|
|
3
|
+
export type RelatedTableProps<TData extends Record<string, unknown>> = Pick<DataTableProps<TData>, 'columns' | 'data' | 'total' | 'isLoading' | 'error' | 'onRetry' | 'emptyTitle' | 'emptyDescription' | 'emptyAction' | 'getRowId' | 'visibleColumns' | 'highlightRow' | 'rowActions' | 'phoneRow' | 'onRowClick' | 'width'> & {
|
|
4
|
+
/** How a row opens its record, as on every list. */
|
|
5
|
+
opens: DataTableOpens<TData>;
|
|
6
|
+
/** The most rows shown: 10 unless set. */
|
|
7
|
+
limit?: number;
|
|
8
|
+
/** The whole list, filtered to this record: shown when `total` is over `limit`. */
|
|
9
|
+
viewAll?: DataTableViewAll;
|
|
10
|
+
};
|
|
11
|
+
export declare function RelatedTable<TData extends Record<string, unknown>>({ columns, limit, ...props }: RelatedTableProps<TData>): import("react").JSX.Element;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// A record's list of related records (the record page standard, R8): the
|
|
3
|
+
// ten newest under a section's heading, then View all N to the whole list
|
|
4
|
+
// filtered to this record, so a long care log doesn't push the rest of the
|
|
5
|
+
// record away. A DataTable with `limit` and `viewAll` and nothing to page or
|
|
6
|
+
// sort: the app's query asks for `limit` rows, newest first, and the total.
|
|
7
|
+
//
|
|
8
|
+
// <RelatedTable
|
|
9
|
+
// columns={VISIT_COLUMNS}
|
|
10
|
+
// opens={{ kind: 'dialog', to: (visit) => `/health/visits/${visit.id}` }}
|
|
11
|
+
// data={visits.data?.items ?? []}
|
|
12
|
+
// total={visits.data?.total ?? 0}
|
|
13
|
+
// isLoading={visits.isLoading}
|
|
14
|
+
// error={visits.error}
|
|
15
|
+
// onRetry={() => visits.refetch()}
|
|
16
|
+
// emptyTitle="No visits yet"
|
|
17
|
+
// viewAll={{ to: `/health/visits?provider=${provider.id}` }}
|
|
18
|
+
// />
|
|
19
|
+
import { useMemo } from 'react';
|
|
20
|
+
import { DataTable } from './data-table.js';
|
|
21
|
+
const noop = () => { };
|
|
22
|
+
const NO_SORT = [];
|
|
23
|
+
export function RelatedTable({ columns, limit = 10, ...props }) {
|
|
24
|
+
// The headers aren't sort buttons: the newest come first, and View all
|
|
25
|
+
// has the list's own sorting.
|
|
26
|
+
const unsorted = useMemo(() => columns.map((column) => ({ ...column, enableSorting: false })), [columns]);
|
|
27
|
+
return (_jsx(DataTable, { ...props, columns: unsorted, limit: limit, page: 1, pageSize: limit, onPageChange: noop, sorting: NO_SORT, onSortingChange: noop }));
|
|
28
|
+
}
|
|
@@ -14,5 +14,7 @@ export type SecondaryFiltersProps = {
|
|
|
14
14
|
onClear: () => void;
|
|
15
15
|
/** The button's text. */
|
|
16
16
|
label?: string;
|
|
17
|
+
/** On the wrapper of the button and the chips (`contents`, to put them in a row of the parent's). */
|
|
18
|
+
className?: string;
|
|
17
19
|
};
|
|
18
|
-
export declare function SecondaryFilters({ children, active, onClear, label }: SecondaryFiltersProps): import("react").JSX.Element;
|
|
20
|
+
export declare function SecondaryFilters({ children, active, onClear, label, className }: SecondaryFiltersProps): import("react").JSX.Element;
|
|
@@ -18,15 +18,16 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
18
18
|
// their Esc); the next one closes the panel.
|
|
19
19
|
import { useState } from 'react';
|
|
20
20
|
import { SlidersHorizontalIcon, XIcon } from 'lucide-react';
|
|
21
|
+
import { cn } from 'cn';
|
|
21
22
|
import { Button } from '../ui/button.js';
|
|
22
23
|
import { Popover, PopoverContent, PopoverTitle, PopoverTrigger } from '../ui/popover.js';
|
|
23
24
|
import { Sheet, SheetContent, SheetFooter, SheetHeader, SheetTitle, SheetTrigger } from '../ui/sheet.js';
|
|
24
|
-
import {
|
|
25
|
-
export function SecondaryFilters({ children, active, onClear, label = 'Filters' }) {
|
|
26
|
-
const isMobile =
|
|
25
|
+
import { useIsPhone } from '../../hooks/use-is-phone.js';
|
|
26
|
+
export function SecondaryFilters({ children, active, onClear, label = 'Filters', className }) {
|
|
27
|
+
const isMobile = useIsPhone();
|
|
27
28
|
const [open, setOpen] = useState(false);
|
|
28
29
|
const count = active.length;
|
|
29
30
|
const trigger = (_jsxs(Button, { variant: "outline", children: [_jsx(SlidersHorizontalIcon, { "aria-hidden": "true" }), _jsxs("span", { children: [label, count > 0 && _jsx("span", { className: "text-[0px]", children: "," })] }), count > 0 && (_jsxs(_Fragment, { children: [_jsx("span", { className: "rounded-full bg-primary px-1.5 type-caption text-primary-foreground tabular-nums", children: count }), _jsx("span", { className: "sr-only", children: " active" })] }))] }));
|
|
30
31
|
const footer = (_jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { variant: "ghost", size: "sm", disabled: count === 0, onClick: onClear, children: "Clear filters" }), _jsx(Button, { size: "sm", onClick: () => setOpen(false), children: "Done" })] }));
|
|
31
|
-
return (_jsxs("div", { "data-slot": "secondary-filters", className:
|
|
32
|
+
return (_jsxs("div", { "data-slot": "secondary-filters", className: cn('flex flex-wrap items-center gap-2', className), children: [isMobile ? (_jsxs(Sheet, { open: open, onOpenChange: setOpen, children: [_jsx(SheetTrigger, { render: trigger }), _jsxs(SheetContent, { side: "bottom", className: "max-h-[85svh] overflow-y-auto", children: [_jsx(SheetHeader, { children: _jsx(SheetTitle, { children: label }) }), _jsx("div", { className: "flex flex-col gap-3 px-4 [&>*]:w-full", children: children }), _jsx(SheetFooter, { children: footer })] })] })) : (_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { render: trigger }), _jsxs(PopoverContent, { align: "start", className: "w-auto min-w-64 gap-3 p-3", children: [_jsx(PopoverTitle, { children: label }), _jsx("div", { className: "flex flex-col gap-3", children: children }), footer] })] })), active.map((filter) => (_jsxs("span", { "data-slot": "secondary-filter-chip", className: "inline-flex h-7 items-center gap-0.5 rounded-md bg-muted pr-0.5 pl-2 type-caption text-foreground", children: [filter.label, _jsx(Button, { variant: "ghost", size: "icon-xs", "aria-label": `Remove filter: ${filter.label}`, onClick: filter.onRemove, children: _jsx(XIcon, { "aria-hidden": "true" }) })] }, filter.id))), count > 1 && (_jsx(Button, { variant: "ghost", size: "sm", onClick: onClear, children: "Clear filters" }))] }));
|
|
32
33
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const ROW_ACTIONS_COLUMN_ID = "__row-actions";
|
|
2
|
+
export type ColumnsPick = {
|
|
3
|
+
order: string[];
|
|
4
|
+
hidden: string[];
|
|
5
|
+
};
|
|
6
|
+
/** The stored pick, or null when there's none or it can't be read. */
|
|
7
|
+
export declare function parseColumnsPick(raw: string | null): ColumnsPick | null;
|
|
8
|
+
/** The ids to show under `pick`: every column of `ids` it doesn't hide, in `ids`' order, `fixed` always. */
|
|
9
|
+
export declare function visibleFromPick(ids: readonly string[], pick: ColumnsPick, fixed: readonly string[]): string[];
|
|
10
|
+
/**
|
|
11
|
+
* The pick after `id` is ticked (`shown`) or unticked, starting from what
|
|
12
|
+
* shows now (`visible`): every column in `ids` is in `order`, the ones not
|
|
13
|
+
* showing in `hidden`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function togglePick(ids: readonly string[], visible: readonly string[], id: string, shown: boolean, previous: ColumnsPick | null): ColumnsPick;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// The Columns menu's pick (DataTable `columnsMenu`), kept free of React so
|
|
2
|
+
// tests/ can unit-test it. It's stored on this device per list as JSON:
|
|
3
|
+
// every column's id in order, and the ones unticked:
|
|
4
|
+
//
|
|
5
|
+
// {"order":["name","status","dose","since"],"hidden":["since"]}
|
|
6
|
+
//
|
|
7
|
+
// `order` is there for reordering, a later addition to the same value; for
|
|
8
|
+
// now it's written and kept, never applied. A column the list gained after
|
|
9
|
+
// the pick was stored isn't in `hidden`, so it shows.
|
|
10
|
+
// The id of the column DataTable adds for `rowActions`, pinned last: never
|
|
11
|
+
// in the Columns menu.
|
|
12
|
+
export const ROW_ACTIONS_COLUMN_ID = '__row-actions';
|
|
13
|
+
/** The stored pick, or null when there's none or it can't be read. */
|
|
14
|
+
export function parseColumnsPick(raw) {
|
|
15
|
+
if (raw === null)
|
|
16
|
+
return null;
|
|
17
|
+
try {
|
|
18
|
+
const value = JSON.parse(raw);
|
|
19
|
+
if (typeof value !== 'object' || value === null)
|
|
20
|
+
return null;
|
|
21
|
+
const { order, hidden } = value;
|
|
22
|
+
const strings = (list) => (Array.isArray(list) ? list.filter((id) => typeof id === 'string') : null);
|
|
23
|
+
const orderIds = strings(order);
|
|
24
|
+
const hiddenIds = strings(hidden);
|
|
25
|
+
return orderIds && hiddenIds ? { order: orderIds, hidden: hiddenIds } : null;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** The ids to show under `pick`: every column of `ids` it doesn't hide, in `ids`' order, `fixed` always. */
|
|
32
|
+
export function visibleFromPick(ids, pick, fixed) {
|
|
33
|
+
const hidden = new Set(pick.hidden);
|
|
34
|
+
return ids.filter((id) => fixed.includes(id) || !hidden.has(id));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The pick after `id` is ticked (`shown`) or unticked, starting from what
|
|
38
|
+
* shows now (`visible`): every column in `ids` is in `order`, the ones not
|
|
39
|
+
* showing in `hidden`.
|
|
40
|
+
*/
|
|
41
|
+
export function togglePick(ids, visible, id, shown, previous) {
|
|
42
|
+
const next = new Set(visible);
|
|
43
|
+
if (shown)
|
|
44
|
+
next.add(id);
|
|
45
|
+
else
|
|
46
|
+
next.delete(id);
|
|
47
|
+
// Keep an order already stored (reordering, later), with new columns after.
|
|
48
|
+
const order = previous ? [...previous.order.filter((each) => ids.includes(each)), ...ids.filter((each) => !previous.order.includes(each))] : [...ids];
|
|
49
|
+
return { order, hidden: ids.filter((each) => !next.has(each)) };
|
|
50
|
+
}
|
|
@@ -13,7 +13,7 @@ const buttonVariants = cva("group/button inline-flex shrink-0 items-center justi
|
|
|
13
13
|
link: "text-link underline-offset-4 hover:underline",
|
|
14
14
|
},
|
|
15
15
|
size: {
|
|
16
|
-
default: "h-9 gap-1.5 px-4 has-data-[icon=inline-end]:pr-3 has-data-[icon=inline-start]:pl-3",
|
|
16
|
+
default: "h-[var(--control-height,--spacing(9))] gap-1.5 px-4 has-data-[icon=inline-end]:pr-3 has-data-[icon=inline-start]:pl-3",
|
|
17
17
|
xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
|
|
18
18
|
sm: "h-8 gap-1 rounded-[min(var(--radius-md),12px)] px-3 text-(length:--control-text-sm) in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
|
|
19
19
|
lg: "h-10 gap-1.5 px-5 has-data-[icon=inline-end]:pr-4 has-data-[icon=inline-start]:pl-4",
|
|
@@ -44,7 +44,7 @@ function ComboboxSeparator({ className, ...props }) {
|
|
|
44
44
|
return (_jsx(ComboboxPrimitive.Separator, { "data-slot": "combobox-separator", className: cn("-mx-1 my-1 h-px bg-border", className), ...props }));
|
|
45
45
|
}
|
|
46
46
|
function ComboboxChips({ className, ...props }) {
|
|
47
|
-
return (_jsx(ComboboxPrimitive.Chips, { "data-slot": "combobox-chips", className: cn("flex min-h-9 flex-wrap items-center gap-1 rounded-md border border-input bg-transparent bg-clip-padding px-2.5 py-1 text-sm transition-colors focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50 has-aria-invalid:border-destructive has-aria-invalid:ring-3 has-aria-invalid:ring-destructive/20 has-data-[slot=combobox-chip]:px-1 dark:bg-input/30 dark:has-aria-invalid:border-destructive/50 dark:has-aria-invalid:ring-destructive/40", className), ...props }));
|
|
47
|
+
return (_jsx(ComboboxPrimitive.Chips, { "data-slot": "combobox-chips", className: cn("flex min-h-[var(--control-height,--spacing(9))] flex-wrap items-center gap-1 rounded-md border border-input bg-transparent bg-clip-padding px-2.5 py-1 text-sm transition-colors focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50 has-aria-invalid:border-destructive has-aria-invalid:ring-3 has-aria-invalid:ring-destructive/20 has-data-[slot=combobox-chip]:px-1 dark:bg-input/30 dark:has-aria-invalid:border-destructive/50 dark:has-aria-invalid:ring-destructive/40", className), ...props }));
|
|
48
48
|
}
|
|
49
49
|
function ComboboxChip({ className, children, showRemove = true, ...props }) {
|
|
50
50
|
return (_jsxs(ComboboxPrimitive.Chip, { "data-slot": "combobox-chip", className: cn("flex h-[calc(--spacing(5.25))] w-fit items-center justify-center gap-1 rounded-sm bg-muted px-1.5 text-xs font-medium whitespace-nowrap text-foreground has-disabled:pointer-events-none has-disabled:cursor-not-allowed has-disabled:opacity-50 has-data-[slot=combobox-chip-remove]:pr-0", className), ...props, children: [children, showRemove && (_jsx(ComboboxPrimitive.ChipRemove
|
|
@@ -1,16 +1,41 @@
|
|
|
1
1
|
import { type VariantProps } from "class-variance-authority";
|
|
2
2
|
import { Label } from "./label.js";
|
|
3
|
+
import { type FieldKind, type FieldSize } from "../../lib/field-rows.js";
|
|
3
4
|
declare function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">): import("react").JSX.Element;
|
|
4
5
|
declare function FieldLegend({ className, variant, ...props }: React.ComponentProps<"legend"> & {
|
|
5
6
|
variant?: "legend" | "label";
|
|
6
7
|
}): import("react").JSX.Element;
|
|
7
|
-
declare function FieldGroup({ className, ...props }: React.ComponentProps<"div">): import("react").JSX.Element;
|
|
8
|
+
declare function FieldGroup({ className, ref, ...props }: React.ComponentProps<"div">): import("react").JSX.Element;
|
|
8
9
|
declare const fieldVariants: (props?: ({
|
|
9
10
|
orientation?: "horizontal" | "vertical" | "responsive" | null | undefined;
|
|
10
11
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
11
|
-
declare function Field({ className, orientation, ...props }: React.ComponentProps<"div"> & VariantProps<typeof fieldVariants>
|
|
12
|
+
declare function Field({ className, orientation, size, solo, kind, ...props }: React.ComponentProps<"div"> & VariantProps<typeof fieldVariants> & {
|
|
13
|
+
/**
|
|
14
|
+
* How much it holds, so FieldGroup can put short fields side by side:
|
|
15
|
+
* `s` a number or a short code, `m` a date, a status, a choice of two
|
|
16
|
+
* to four or a rating, `l` a name or a pick of a record, `full` (the
|
|
17
|
+
* default) long text, a list or anything that needs the row.
|
|
18
|
+
*/
|
|
19
|
+
size?: FieldSize;
|
|
20
|
+
/** Keep this short field on a row of its own, where a pairing would read wrong. */
|
|
21
|
+
solo?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* A date or a number: two of a kind stay side by side on a phone.
|
|
24
|
+
* Found by itself for a date or number `<input>`; say it for a
|
|
25
|
+
* control of your own (DateField's button).
|
|
26
|
+
*/
|
|
27
|
+
kind?: FieldKind;
|
|
28
|
+
}): import("react").JSX.Element;
|
|
12
29
|
declare function FieldContent({ className, ...props }: React.ComponentProps<"div">): import("react").JSX.Element;
|
|
13
|
-
declare function FieldLabel({ className, ...props }: React.ComponentProps<typeof Label>
|
|
30
|
+
declare function FieldLabel({ className, required, children, ...props }: React.ComponentProps<typeof Label> & {
|
|
31
|
+
/**
|
|
32
|
+
* A field that must be filled: an asterisk after the words, and
|
|
33
|
+
* `aria-required` on the control `htmlFor` names where its role takes
|
|
34
|
+
* it (a box, a select, a combobox; not a date picker's button). Nothing
|
|
35
|
+
* marks an optional one (no "(optional)").
|
|
36
|
+
*/
|
|
37
|
+
required?: boolean;
|
|
38
|
+
}): import("react").JSX.Element;
|
|
14
39
|
declare function FieldTitle({ className, ...props }: React.ComponentProps<"div">): import("react").JSX.Element;
|
|
15
40
|
declare function FieldDescription({ className, ...props }: React.ComponentProps<"p">): import("react").JSX.Element;
|
|
16
41
|
declare function FieldSeparator({ children, className, ...props }: React.ComponentProps<"div"> & {
|