@tristan2828/ui-foundation 3.4.0 → 3.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.
package/README.md CHANGED
@@ -18,7 +18,7 @@ than installing this by hand:
18
18
 
19
19
  | Import | What |
20
20
  |---|---|
21
- | `@tristan2828/ui-foundation` | `AppShell`, `DataTable`, `EntityForm`, `ErrorState`, `MultiChoice`, `PasswordInput`, `RouteErrorBoundary`, `FoundationProviders`, `LoginRoute`, `RegisterRoute`, `useAuth`, `useTableUrlState`, `useDebouncedValue`, `createQueryClient`, `cn`; types `Page`, `AppError`, `QuerySpec` |
21
+ | `@tristan2828/ui-foundation` | `AppShell`, `DataTable`, `EntityForm`, `ErrorState`, `MultiChoice`, `MultiReference`, `PasswordInput`, `RouteErrorBoundary`, `FoundationProviders`, `LoginRoute`, `RegisterRoute`, `useAuth`, `useTableUrlState`, `useDebouncedValue`, `createQueryClient`, `cn`; types `Page`, `AppError`, `QuerySpec` |
22
22
  | `@tristan2828/ui-foundation/ui/<name>` | shadcn primitives: badge, button, calendar, card, combobox, dialog, empty, field, input, input-group, label, popover, select, separator, sheet, sidebar, skeleton, sonner, spinner, switch, table, textarea, tooltip |
23
23
  | `@tristan2828/ui-foundation/gateway` | `safeFetch`, `toAppError`, `networkError` — for an app's `src/api/gateway/` only |
24
24
  | `@tristan2828/ui-foundation/mocks` | MSW: `authHandlers`, `resetMockAuth`, `getMockCurrentUser`, `MOCK_USER`, `exposeMswForE2E` |
@@ -85,7 +85,17 @@ is a filled-in example while the Widgets demo is still here).
85
85
  `<MultiChoice>` control from the foundation on the
86
86
  form and as a toolbar filter via `useTableUrlState`'s multi filters,
87
87
  badges in the table, and a `filters` array the gateway sends as a
88
- repeated parameter):
88
+ repeated parameter — and a `multi reference` copies Extra Categories:
89
+ the `<MultiReference>` control on the form and as a toolbar filter, an
90
+ array of ids on the wire, a repeated any-of list filter, and names from
91
+ a **lookup by id** on the referenced entity
92
+ (`GET /categories?ids=1&ids=3`, `getCategoriesByIds`,
93
+ `useCategoriesByIdsQuery`). Add that `ids` parameter to the referenced
94
+ entity's list endpoint if it lacks one. Never name a picked id from
95
+ search results alone: a saved pick the current search doesn't return
96
+ would show without a name. The table looks up every id on its page in
97
+ one request; the backend rejects an unknown id as a 422 on the field,
98
+ never a foreign-key 500):
89
99
  - `src/routes/widgets/use-widgets.ts`, `use-categories.ts` →
90
100
  `src/routes/<entity>/use-<entity>.ts` (TanStack Query hooks over the
91
101
  new gateway module)
@@ -30,7 +30,10 @@ One or two sentences: what one record is, and who uses the screens.
30
30
  order; see the note below if it is *optional*), `multi choice` (list
31
31
  the options; any number can be picked —
32
32
  chips on the form, badges in the table, an any-of filter), `reference`
33
- (to another entity — name it; a searchable combobox).
33
+ (to another entity — name it; a searchable combobox), `multi reference`
34
+ (to any number of records of another entity — name it; chips with a
35
+ searchable dropdown, names as badges in the table, an any-of filter;
36
+ the other entity's list endpoint must also accept `ids`).
34
37
  - *Close variants* (built by a small, stated change to the nearest
35
38
  pattern): `integer` (from decimal), `url` (from email — a format
36
39
  check), `date` (from date-time — no time part).
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+ export declare function MultiReference<Id extends string | number>({ options, value, onValueChange, getLabel, onSearchChange, id, placeholder, emptyText, 'aria-label': ariaLabel, 'aria-invalid': ariaInvalid, className, }: {
3
+ /** The records the current search returned, in display order. */
4
+ options: readonly {
5
+ id: Id;
6
+ label: string;
7
+ }[];
8
+ /** The picked ids. */
9
+ value: Id[];
10
+ onValueChange: (value: Id[]) => void;
11
+ /**
12
+ * The name of any id: a picked one (from the app's lookup by ids) or an
13
+ * option. `undefined` while it's still loading.
14
+ */
15
+ getLabel: (id: Id) => string | undefined;
16
+ /** Called with the typed text; the app feeds it to its search query. */
17
+ onSearchChange: (search: string) => void;
18
+ /** Id for the text input, so a <FieldLabel htmlFor> labels it. */
19
+ id?: string;
20
+ placeholder?: string;
21
+ /** Shown in the dropdown when the search matches nothing. */
22
+ emptyText?: string;
23
+ /** For use without a visible label (e.g. a table toolbar filter). */
24
+ 'aria-label'?: string;
25
+ 'aria-invalid'?: boolean;
26
+ className?: string;
27
+ }): React.JSX.Element;
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // A multi-reference picker: links to several records of another entity,
3
+ // shown as removable chips, with the rest found by typing. The one control
4
+ // for every "multi reference" field (conventions/docs/entity-plan-template.md),
5
+ // on a form (Widget Extra Categories) and as a table filter.
6
+ //
7
+ // MultiChoice's sibling, for values that are record ids rather than enum
8
+ // strings. Two differences follow from that:
9
+ // - A chip needs a *name* for an id the current search may not include
10
+ // (editing a saved record, a filter from a shared link). The app fetches
11
+ // names for exactly the picked ids (Widget: GET /categories?ids=...) and
12
+ // passes `getLabel`; this component never guesses one.
13
+ // - Matching happens on the server: `onSearchChange` reports what was typed
14
+ // and `options` is whatever the app's search query returned, so nothing
15
+ // is filtered here (filter={null}).
16
+ import * as React from 'react';
17
+ import { Combobox, ComboboxChip, ComboboxChips, ComboboxChipsInput, ComboboxContent, ComboboxEmpty, ComboboxItem, ComboboxList, ComboboxValue, useComboboxAnchor, } from '../ui/combobox.js';
18
+ /** Shown on a chip whose name hasn't loaded yet, instead of a bare id. */
19
+ const PENDING_LABEL = '…';
20
+ export function MultiReference({ options, value, onValueChange, getLabel, onSearchChange, id, placeholder, emptyText = 'No matches.', 'aria-label': ariaLabel, 'aria-invalid': ariaInvalid, className, }) {
21
+ const anchor = useComboboxAnchor();
22
+ const label = (option) => getLabel(option) ?? PENDING_LABEL;
23
+ return (_jsxs(Combobox, { multiple: true, autoHighlight: true,
24
+ // Ids, not {id,label} objects: Base UI compares items to the value
25
+ // with Object.is, so the items must have the value's own shape.
26
+ items: options.map((option) => option.id), value: value, onValueChange: (next) => onValueChange(next), onInputValueChange: onSearchChange, itemToStringLabel: label, filter: null, children: [_jsx(ComboboxChips, { ref: anchor, className: className, children: _jsx(ComboboxValue, { children: (selected) => (_jsxs(React.Fragment, { children: [selected.map((option) => (_jsx(ComboboxChip, { children: label(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: emptyText }), _jsx(ComboboxList, { children: (option) => (_jsx(ComboboxItem, { value: option, children: label(option) }, option)) })] })] }));
27
+ }
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export { ErrorState } from './components/app/error-state.js';
5
5
  export { FoundationProviders } from './components/app/foundation-providers.js';
6
6
  export { MockModeBanner } from './components/app/mock-mode-banner.js';
7
7
  export { MultiChoice } from './components/app/multi-choice.js';
8
+ export { MultiReference } from './components/app/multi-reference.js';
8
9
  export { PasswordInput } from './components/app/password-input.js';
9
10
  export { RouteErrorBoundary } from './components/app/route-error-boundary.js';
10
11
  export { ThemeProvider } from './components/theme-provider.js';
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ export { ErrorState } from './components/app/error-state.js';
10
10
  export { FoundationProviders } from './components/app/foundation-providers.js';
11
11
  export { MockModeBanner } from './components/app/mock-mode-banner.js';
12
12
  export { MultiChoice } from './components/app/multi-choice.js';
13
+ export { MultiReference } from './components/app/multi-reference.js';
13
14
  export { PasswordInput } from './components/app/password-input.js';
14
15
  export { RouteErrorBoundary } from './components/app/route-error-boundary.js';
15
16
  export { ThemeProvider } from './components/theme-provider.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "3.4.0",
3
+ "version": "3.5.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": {