@mistriwork/ui 1.0.0-rc.39 → 1.0.0-rc.40

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.
Files changed (47) hide show
  1. package/dist/Avatar.d.ts +3 -1
  2. package/dist/Avatar.js +4 -1
  3. package/dist/Button.d.ts +13 -3
  4. package/dist/Button.js +9 -1
  5. package/dist/Choices.d.ts +11 -5
  6. package/dist/Choices.js +12 -5
  7. package/dist/DateField.d.ts +3 -1
  8. package/dist/DateField.js +4 -1
  9. package/dist/Drawer.d.ts +2 -1
  10. package/dist/Drawer.js +4 -1
  11. package/dist/DropMenu.d.ts +8 -4
  12. package/dist/DropMenu.js +10 -4
  13. package/dist/Dropdown.d.ts +4 -2
  14. package/dist/Dropdown.js +6 -2
  15. package/dist/Modal.d.ts +2 -1
  16. package/dist/Modal.js +4 -1
  17. package/dist/Pagination.d.ts +2 -1
  18. package/dist/Pagination.js +4 -1
  19. package/dist/Popover.d.ts +3 -1
  20. package/dist/Popover.js +4 -1
  21. package/dist/Select.d.ts +4 -2
  22. package/dist/Select.js +6 -2
  23. package/dist/SensitiveField.d.ts +3 -1
  24. package/dist/SensitiveField.js +4 -1
  25. package/dist/Slider.d.ts +3 -1
  26. package/dist/Slider.js +4 -1
  27. package/dist/Switch.d.ts +3 -1
  28. package/dist/Switch.js +4 -1
  29. package/dist/Tabs.d.ts +3 -1
  30. package/dist/Tabs.js +4 -1
  31. package/dist/TextField.d.ts +7 -3
  32. package/dist/TextField.js +8 -3
  33. package/dist/Tooltip.d.ts +3 -1
  34. package/dist/Tooltip.js +4 -1
  35. package/dist/Typeahead.d.ts +3 -2
  36. package/dist/Typeahead.js +4 -1
  37. package/dist/UiKit.d.ts +86 -0
  38. package/dist/UiKit.js +32 -0
  39. package/dist/conformance.d.ts +9 -0
  40. package/dist/conformance.js +470 -0
  41. package/dist/index.d.ts +3 -2
  42. package/dist/index.js +3 -1
  43. package/dist/internal/uiKitContext.d.ts +15 -0
  44. package/dist/internal/uiKitContext.js +23 -0
  45. package/dist/uiKitSlots.d.ts +13 -0
  46. package/dist/uiKitSlots.js +83 -0
  47. package/package.json +4 -1
@@ -29,7 +29,7 @@ export interface TextFieldProps extends FieldFrame {
29
29
  /** Something drawn under the box: a computed line, say. */
30
30
  after?: ReactNode;
31
31
  }
32
- export declare function TextField(props: TextFieldProps): ReactNode;
32
+ declare function DefaultTextField(props: TextFieldProps): ReactNode;
33
33
  export interface MaskedFieldProps extends Omit<TextFieldProps, 'value' | 'onChange'> {
34
34
  mask: Mask;
35
35
  /** The raw value: the digits, usually. */
@@ -37,8 +37,12 @@ export interface MaskedFieldProps extends Omit<TextFieldProps, 'value' | 'onChan
37
37
  onChange: (raw: string) => void;
38
38
  }
39
39
  /** A box that shows its value through a mask and keeps the raw one: `masks.phone`, `masks.date` (typed MM/DD/YYYY), `masks.ssn`… */
40
- export declare function MaskedField({ mask, value, onChange, ...rest }: MaskedFieldProps): ReactNode;
40
+ declare function DefaultMaskedField({ mask, value, onChange, ...rest }: MaskedFieldProps): ReactNode;
41
41
  /** Whole money, drawn `$2,500` (or `25,000` with `symbol=""`). The value is the digits. */
42
- export declare function MoneyField({ symbol, ...rest }: Omit<MaskedFieldProps, 'mask'> & {
42
+ declare function DefaultMoneyField({ symbol, ...rest }: Omit<MaskedFieldProps, 'mask'> & {
43
43
  symbol?: string;
44
44
  }): ReactNode;
45
+ export declare const TextField: typeof DefaultTextField;
46
+ export declare const MaskedField: typeof DefaultMaskedField;
47
+ export declare const MoneyField: typeof DefaultMoneyField;
48
+ export {};
package/dist/TextField.js CHANGED
@@ -2,18 +2,23 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
2
2
  import { Field } from './Field.js';
3
3
  import { frameOf } from './fieldFrame.js';
4
4
  import { masks } from './masks.js';
5
+ import { slotted } from './internal/uiKitContext.js';
5
6
  /** The mark at a box's inline end: drawn in CSS unless a picture is lent. Decorative: validity is `aria-invalid`'s to say. */
6
7
  export function ValidMark({ icon }) {
7
8
  return (_jsx("span", { className: "field-mark", "aria-hidden": "true", children: icon }));
8
9
  }
9
- export function TextField(props) {
10
+ function DefaultTextField(props) {
10
11
  return (_jsx(Field, { ...frameOf(props), children: (control) => (_jsxs(_Fragment, { children: [_jsxs("div", { className: `field-box${props.valid === undefined ? '' : ' has-mark'}`, children: [_jsx("input", { ...control, ref: props.inputRef, className: "field-control", type: props.type ?? 'text', name: props.name, value: props.value, inputMode: props.inputMode, autoComplete: props.autoComplete ?? 'off', placeholder: props.placeholder, disabled: props.disabled, readOnly: props.readOnly, onChange: (e) => props.onChange(e.target.value), onBlur: props.onBlur }), props.valid ? _jsx(ValidMark, { icon: props.validIcon }) : null] }), props.after] })) }));
11
12
  }
12
13
  /** A box that shows its value through a mask and keeps the raw one: `masks.phone`, `masks.date` (typed MM/DD/YYYY), `masks.ssn`… */
13
- export function MaskedField({ mask, value, onChange, ...rest }) {
14
+ function DefaultMaskedField({ mask, value, onChange, ...rest }) {
14
15
  return (_jsx(TextField, { ...rest, value: mask.format(value), onChange: (typed) => onChange(mask.parse(typed)), inputMode: rest.inputMode ?? mask.inputMode, placeholder: rest.placeholder ?? mask.placeholder }));
15
16
  }
16
17
  /** Whole money, drawn `$2,500` (or `25,000` with `symbol=""`). The value is the digits. */
17
- export function MoneyField({ symbol = '$', ...rest }) {
18
+ function DefaultMoneyField({ symbol = '$', ...rest }) {
18
19
  return _jsx(MaskedField, { kind: "money", ...rest, mask: masks.money(symbol) });
19
20
  }
21
+ /* Slotted (UiKit.tsx): an App's control kit may draw its own in place of the default, with the same props. */
22
+ export const TextField = slotted('TextField', DefaultTextField);
23
+ export const MaskedField = slotted('MaskedField', DefaultMaskedField);
24
+ export const MoneyField = slotted('MoneyField', DefaultMoneyField);
package/dist/Tooltip.d.ts CHANGED
@@ -29,4 +29,6 @@ export interface TooltipProps {
29
29
  onOpenChange?: (open: boolean) => void;
30
30
  className?: string;
31
31
  }
32
- export declare function Tooltip({ trigger, children, open, defaultOpen, onOpenChange, className }: TooltipProps): import("react").JSX.Element;
32
+ declare function DefaultTooltip({ trigger, children, open, defaultOpen, onOpenChange, className }: TooltipProps): import("react").JSX.Element;
33
+ export declare const Tooltip: typeof DefaultTooltip;
34
+ export {};
package/dist/Tooltip.js CHANGED
@@ -24,7 +24,8 @@ import { Tooltip as BaseTooltip } from '@base-ui/react/tooltip';
24
24
  import { layoutViewport, zoomAnchor } from './internal/anchor.js';
25
25
  import { ComponentStyleScope } from './internal/ComponentStyleScope.js';
26
26
  import { popupContainer, useDialogContainer } from './internal/popups.js';
27
- export function Tooltip({ trigger, children, open, defaultOpen, onOpenChange, className }) {
27
+ import { slotted } from './internal/uiKitContext.js';
28
+ function DefaultTooltip({ trigger, children, open, defaultOpen, onOpenChange, className }) {
28
29
  const tooltipId = useId();
29
30
  const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen ?? false);
30
31
  const isOpen = open ?? uncontrolledOpen;
@@ -47,3 +48,5 @@ export function Tooltip({ trigger, children, open, defaultOpen, onOpenChange, cl
47
48
  void details;
48
49
  }, children: [_jsx(BaseTooltip.Trigger, { className: "ui-tooltip-trigger", render: triggerElement, ref: anchor }), _jsx(BaseTooltip.Portal, { container: container ?? popupContainer(), children: _jsx(BaseTooltip.Positioner, { anchor: () => (anchor.current ? zoomAnchor(anchor.current) : null), positionMethod: "fixed", sideOffset: 8, collisionBoundary: layoutViewport(), collisionPadding: 8, children: _jsx(BaseTooltip.Popup, { "data-component": componentScope, id: tooltipId, role: "tooltip", className: ['ui-tooltip', className].filter(Boolean).join(' '), children: children }) }) })] }));
49
50
  }
51
+ /* Slotted (UiKit.tsx): an App's control kit may draw its own in place of the default, with the same props. */
52
+ export const Tooltip = slotted('Tooltip', DefaultTooltip);
@@ -19,7 +19,7 @@
19
19
  * the enclosing dialog when there is one.
20
20
  */
21
21
  import { type InputHTMLAttributes, type ReactNode, type Ref, type RefObject } from 'react';
22
- interface TypeaheadProps<T> {
22
+ export interface TypeaheadProps<T> {
23
23
  text: string;
24
24
  onText: (text: string) => void;
25
25
  /** Already ranked and bounded; drawn in this order. */
@@ -59,5 +59,6 @@ interface TypeaheadProps<T> {
59
59
  /** Hears the row lit by the keys or the pointer, and undefined when none is. */
60
60
  onHighlight?: (item: T | undefined) => void;
61
61
  }
62
- export declare function Typeahead<T>({ text, onText, items, itemKey, itemLabel, itemClassName, renderItem, onPick, open, onOpenChange, inputProps, inputRef, popupRef, anchorRef, fit, popupClassName, listClassName, empty, emptyClassName, portal, autoHighlight, onHighlight, }: TypeaheadProps<T>): import("react").JSX.Element;
62
+ declare function DefaultTypeahead<T>({ text, onText, items, itemKey, itemLabel, itemClassName, renderItem, onPick, open, onOpenChange, inputProps, inputRef, popupRef, anchorRef, fit, popupClassName, listClassName, empty, emptyClassName, portal, autoHighlight, onHighlight, }: TypeaheadProps<T>): import("react").JSX.Element;
63
+ export declare const Typeahead: typeof DefaultTypeahead;
63
64
  export {};
package/dist/Typeahead.js CHANGED
@@ -24,7 +24,8 @@ import { Autocomplete } from '@base-ui/react/autocomplete';
24
24
  import { viewportBox } from './internal/ruler.js';
25
25
  import { layoutViewport, zoomAnchor } from './internal/anchor.js';
26
26
  import { popupContainer } from './internal/popups.js';
27
- export function Typeahead({ text, onText, items, itemKey, itemLabel, itemClassName, renderItem, onPick, open, onOpenChange, inputProps, inputRef, popupRef, anchorRef, fit = 'min-width', popupClassName, listClassName, empty, emptyClassName, portal = 'dialog', autoHighlight = true, onHighlight, }) {
27
+ import { slotted } from './internal/uiKitContext.js';
28
+ function DefaultTypeahead({ text, onText, items, itemKey, itemLabel, itemClassName, renderItem, onPick, open, onOpenChange, inputProps, inputRef, popupRef, anchorRef, fit = 'min-width', popupClassName, listClassName, empty, emptyClassName, portal = 'dialog', autoHighlight = true, onHighlight, }) {
28
29
  const input = useRef(null);
29
30
  const [container, setContainer] = useState(null);
30
31
  useEffect(() => {
@@ -88,3 +89,5 @@ export function Typeahead({ text, onText, items, itemKey, itemLabel, itemClassNa
88
89
  ...(fit === 'width' ? { width: '100%' } : { minWidth: 'var(--anchor-width)', maxWidth: 'var(--available-width)' }),
89
90
  }, children: _jsxs(Autocomplete.List, { className: listClassName, children: [empty !== undefined ? _jsx(Autocomplete.Empty, { className: emptyClassName, children: empty }) : null, items.map((item) => (_jsx(Autocomplete.Item, { value: item, className: (s) => itemClassName(item, s.highlighted), onClick: () => onPick(item), children: renderItem(item) }, itemKey(item))))] }) }) }) })] }));
90
91
  }
92
+ /* Slotted (UiKit.tsx): an App's control kit may draw its own in place of the default, with the same props. */
93
+ export const Typeahead = slotted('Typeahead', DefaultTypeahead);
@@ -0,0 +1,86 @@
1
+ /**
2
+ * A control kit (Preview): another drawing of the primitives here, slot by slot. Every slotted primitive reads the
3
+ * kit in place (internal/uiKitContext.ts) and draws the kit's component for its slot with the very props it was given,
4
+ * its own otherwise, so a kit that draws only the button leaves every other control as it was and no screen that
5
+ * imports a primitive changes. The page itself (a grid, a record's layout, the navigation) stays the platform's;
6
+ * what a kit replaces is the controls on it.
7
+ *
8
+ * The contract is each slot's props type below, plus the behavior the conformance suite holds a kit to
9
+ * (`@mistriwork/ui/conformance.js`): a value and its change, disabled, the words a slot is handed, a modal's handle and
10
+ * where its focus goes back to, a menu's and a listbox's keys, a popup drawn inside the dialog that opened it.
11
+ *
12
+ * Nothing here imports a primitive's module, only its types: a kit compiled apart from the page reads this file for
13
+ * `defineUiKit`, and the defaults arrive in `defaultUiKit` as the page loads them.
14
+ */
15
+ import { type ComponentProps, type ComponentType, type ReactNode } from 'react';
16
+ import type { Avatar } from './Avatar.js';
17
+ import type { Button, ButtonLink } from './Button.js';
18
+ import type { CheckCards, Checkbox, ChoiceCards, Consent, YesNo } from './Choices.js';
19
+ import type { DateField } from './DateField.js';
20
+ import type { Drawer } from './Drawer.js';
21
+ import type { DropGroup, DropItem, DropMenu, DropSeparator } from './DropMenu.js';
22
+ import type { Dropdown, MultiDropdown } from './Dropdown.js';
23
+ import type { Modal } from './Modal.js';
24
+ import type { Pagination } from './Pagination.js';
25
+ import type { Popover } from './Popover.js';
26
+ import type { MultiSelect, Select } from './Select.js';
27
+ import type { SensitiveField } from './SensitiveField.js';
28
+ import type { Slider } from './Slider.js';
29
+ import type { Switch } from './Switch.js';
30
+ import type { Tabs } from './Tabs.js';
31
+ import type { MaskedField, MoneyField, TextField } from './TextField.js';
32
+ import type { Tooltip } from './Tooltip.js';
33
+ import type { TypeaheadProps } from './Typeahead.js';
34
+ import { installUiKit } from './internal/uiKitContext.js';
35
+ import { SLOT_NAMES, uiKitProblems, type SlotName } from './uiKitSlots.js';
36
+ type Slot<C extends ComponentType<any>> = ComponentType<ComponentProps<C>>;
37
+ /** Each slot's component, typed by the props the platform draws it with. */
38
+ export interface UiKitSlots {
39
+ Button: Slot<typeof Button>;
40
+ /** A link dressed as a button: a download, another page. */
41
+ ButtonLink: Slot<typeof ButtonLink>;
42
+ TextField: Slot<typeof TextField>;
43
+ MaskedField: Slot<typeof MaskedField>;
44
+ MoneyField: Slot<typeof MoneyField>;
45
+ SensitiveField: Slot<typeof SensitiveField>;
46
+ Select: Slot<typeof Select>;
47
+ MultiSelect: Slot<typeof MultiSelect>;
48
+ Dropdown: Slot<typeof Dropdown>;
49
+ MultiDropdown: Slot<typeof MultiDropdown>;
50
+ /** Generic in the item it lists, as the default is. */
51
+ Typeahead: <T>(props: TypeaheadProps<T>) => ReactNode;
52
+ DateField: Slot<typeof DateField>;
53
+ Checkbox: Slot<typeof Checkbox>;
54
+ YesNo: Slot<typeof YesNo>;
55
+ ChoiceCards: Slot<typeof ChoiceCards>;
56
+ CheckCards: Slot<typeof CheckCards>;
57
+ Consent: Slot<typeof Consent>;
58
+ Switch: Slot<typeof Switch>;
59
+ Slider: Slot<typeof Slider>;
60
+ /** Open from mount; `onClose` heard once however it closed; `ref` takes the handle that closes it. */
61
+ Modal: Slot<typeof Modal>;
62
+ Drawer: Slot<typeof Drawer>;
63
+ Popover: Slot<typeof Popover>;
64
+ Tooltip: Slot<typeof Tooltip>;
65
+ /** A menu's four parts share the menu's state, so a kit draws all four or none. */
66
+ DropMenu: Slot<typeof DropMenu>;
67
+ DropGroup: Slot<typeof DropGroup>;
68
+ DropItem: Slot<typeof DropItem>;
69
+ DropSeparator: Slot<typeof DropSeparator>;
70
+ Tabs: Slot<typeof Tabs>;
71
+ Pagination: Slot<typeof Pagination>;
72
+ Avatar: Slot<typeof Avatar>;
73
+ }
74
+ /** A kit: any of the slots; the rest draw as they always have. */
75
+ export type UiKit = Readonly<Partial<UiKitSlots>>;
76
+ /** Declares a kit, refusing a slot it does not have in words: `export default defineUiKit({ Button, Modal })`. */
77
+ export declare function defineUiKit(kit: UiKit): UiKit;
78
+ /** The primitives' own drawing, by slot, for a kit that dresses a default rather than replacing it. Filled as the
79
+ page loads each primitive, so read it when drawing, not when the kit is defined. */
80
+ export declare const defaultUiKit: Readonly<Partial<UiKitSlots>>;
81
+ /** Draws everything inside it with this kit; a page with one kit installs it once instead (`installUiKit`). */
82
+ export declare function UiKitProvider({ kit, children }: {
83
+ kit: UiKit;
84
+ children?: ReactNode;
85
+ }): import("react").FunctionComponentElement<import("react").ProviderProps<Record<string, (import("react").ComponentClass<any, any> | import("react").FunctionComponent<any>) | undefined>>>;
86
+ export { installUiKit, SLOT_NAMES, uiKitProblems, type SlotName };
package/dist/UiKit.js ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * A control kit (Preview): another drawing of the primitives here, slot by slot. Every slotted primitive reads the
3
+ * kit in place (internal/uiKitContext.ts) and draws the kit's component for its slot with the very props it was given,
4
+ * its own otherwise, so a kit that draws only the button leaves every other control as it was and no screen that
5
+ * imports a primitive changes. The page itself (a grid, a record's layout, the navigation) stays the platform's;
6
+ * what a kit replaces is the controls on it.
7
+ *
8
+ * The contract is each slot's props type below, plus the behavior the conformance suite holds a kit to
9
+ * (`@mistriwork/ui/conformance.js`): a value and its change, disabled, the words a slot is handed, a modal's handle and
10
+ * where its focus goes back to, a menu's and a listbox's keys, a popup drawn inside the dialog that opened it.
11
+ *
12
+ * Nothing here imports a primitive's module, only its types: a kit compiled apart from the page reads this file for
13
+ * `defineUiKit`, and the defaults arrive in `defaultUiKit` as the page loads them.
14
+ */
15
+ import { createElement } from 'react';
16
+ import { UiKitContext, defaultSlots, installUiKit } from './internal/uiKitContext.js';
17
+ import { SLOT_NAMES, uiKitProblems } from './uiKitSlots.js';
18
+ /** Declares a kit, refusing a slot it does not have in words: `export default defineUiKit({ Button, Modal })`. */
19
+ export function defineUiKit(kit) {
20
+ const problems = uiKitProblems(kit);
21
+ if (problems.length)
22
+ throw new Error(`The UI kit ${problems.join(' It ')}`);
23
+ return Object.freeze({ ...kit });
24
+ }
25
+ /** The primitives' own drawing, by slot, for a kit that dresses a default rather than replacing it. Filled as the
26
+ page loads each primitive, so read it when drawing, not when the kit is defined. */
27
+ export const defaultUiKit = defaultSlots;
28
+ /** Draws everything inside it with this kit; a page with one kit installs it once instead (`installUiKit`). */
29
+ export function UiKitProvider({ kit, children }) {
30
+ return createElement(UiKitContext.Provider, { value: kit }, children);
31
+ }
32
+ export { installUiKit, SLOT_NAMES, uiKitProblems };
@@ -0,0 +1,9 @@
1
+ import { type UiKit } from './UiKit.js';
2
+ /** The runner's `test` (Vitest's, Jest's, node:test's): a name and an async body. */
3
+ type ConformanceTest = (name: string, body: () => Promise<void>) => unknown;
4
+ /**
5
+ * Registers the conformance checks for `kit` with the runner's `test`. Each check names the slot and the promise it
6
+ * holds the slot to; a slot the kit leaves out is checked as the platform draws it.
7
+ */
8
+ export declare function uiKitConformance(kit: UiKit, test: ConformanceTest): void;
9
+ export {};