@snap-rail/ui 0.2.0 → 0.4.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.
@@ -8,6 +8,7 @@
8
8
  export * from '../utils.ts';
9
9
  export * from './alert.tsx';
10
10
  export * from './button.tsx';
11
+ export * from './combobox.tsx';
11
12
  export * from './controls.tsx';
12
13
  export * from './dialog.tsx';
13
14
  export * from './feedback.tsx';
@@ -8,6 +8,7 @@
8
8
  export * from "../utils.js";
9
9
  export * from "./alert.js";
10
10
  export * from "./button.js";
11
+ export * from "./combobox.js";
11
12
  export * from "./controls.js";
12
13
  export * from "./dialog.js";
13
14
  export * from "./feedback.js";
@@ -11,12 +11,12 @@ import { cn, part } from "../utils.js";
11
11
  * `style`/`className` dress the wrapper — the visible control; the native
12
12
  * field already stretches inside it. */
13
13
  export function Input({ size = 'md', invalid = false, prefix, suffix, onClear, fieldClassName, componentName = 'input', className, style, disabled, ...props }) {
14
- return (_jsxs("div", { ...part(componentName, 'root'), className: cn('snap-input', className), style: style, "data-size": size, "data-invalid": invalid || undefined, "data-disabled": disabled === true || undefined, children: [prefix !== undefined && _jsx("span", { ...part(componentName, 'prefix'), children: prefix }), _jsx("input", { ...part(componentName, 'field'), className: cn('snap-input-field', fieldClassName), disabled: disabled, "aria-invalid": invalid || undefined, ...props }), onClear !== undefined && typeof props.value === 'string' && props.value !== '' && (_jsx("button", { ...part(componentName, 'clear'), type: "button", className: "snap-input-clear", "aria-label": "\u6E05\u9664", onClick: onClear, children: "\u00D7" })), suffix !== undefined && _jsx("span", { ...part(componentName, 'suffix'), children: suffix })] }));
14
+ return (_jsxs("div", { ...part(componentName, 'root'), className: cn('snap-input', className), style: style, "data-size": size, "data-invalid": invalid || undefined, "data-disabled": disabled === true || undefined, children: [prefix !== undefined && _jsx("span", { ...part(componentName, 'prefix'), children: prefix }), _jsx("input", { className: cn('snap-input-field', fieldClassName), disabled: disabled, "aria-invalid": invalid || undefined, ...props, ...part(componentName, 'field') }), onClear !== undefined && typeof props.value === 'string' && props.value !== '' && (_jsx("button", { ...part(componentName, 'clear'), type: "button", className: "snap-input-clear", "aria-label": "\u6E05\u9664", onClick: onClear, children: "\u00D7" })), suffix !== undefined && _jsx("span", { ...part(componentName, 'suffix'), children: suffix })] }));
15
15
  }
16
16
  /** A multi-line text field. Like {@link Input}, layout `style`/`className`
17
17
  * dress the wrapper; the field stretches inside it. */
18
18
  export function Textarea({ size = 'md', invalid = false, fieldClassName, className, style, disabled, ...props }) {
19
- return (_jsx("div", { ...part('textarea', 'root'), className: cn('snap-textarea', className), style: style, "data-size": size, "data-invalid": invalid || undefined, "data-disabled": disabled === true || undefined, children: _jsx("textarea", { ...part('textarea', 'field'), className: cn('snap-textarea-field', fieldClassName), disabled: disabled, "aria-invalid": invalid || undefined, ...props }) }));
19
+ return (_jsx("div", { ...part('textarea', 'root'), className: cn('snap-textarea', className), style: style, "data-size": size, "data-invalid": invalid || undefined, "data-disabled": disabled === true || undefined, children: _jsx("textarea", { className: cn('snap-textarea-field', fieldClassName), disabled: disabled, "aria-invalid": invalid || undefined, ...props, ...part('textarea', 'field') }) }));
20
20
  }
21
21
  /** A numeric field with touch steppers: `step-up`/`step-down` commit through
22
22
  * the normal `onChange` (a native input event on the field), clamped to
@@ -40,6 +40,6 @@ export function NumberInput({ min, max, step = 1, size = 'md', invalid = false,
40
40
  setter?.call(field, String(next));
41
41
  field.dispatchEvent(new Event('input', { bubbles: true }));
42
42
  };
43
- return (_jsxs("div", { ...part('number-input', 'root'), className: cn('snap-input', 'snap-number-input', className), style: style, "data-size": size, "data-invalid": invalid || undefined, "data-disabled": disabled === true || undefined, children: [_jsx("input", { ref: fieldRef, ...part('number-input', 'field'), className: cn('snap-input-field', fieldClassName), type: "number", inputMode: "decimal", disabled: disabled, "aria-invalid": invalid || undefined, value: value, onChange: onChange, ...min !== undefined ? { min } : {}, ...max !== undefined ? { max } : {}, ...step !== undefined ? { step } : {}, ...props }), _jsxs("span", { className: "snap-number-input-steps", children: [_jsx("button", { ...part('number-input', 'step-up'), type: "button", tabIndex: -1, className: "snap-number-input-step", "aria-label": "\u589E\u5927", disabled: disabled === true || (current !== undefined && max !== undefined && current >= max), onClick: () => stepBy(1), children: "\uFF0B" }), _jsx("button", { ...part('number-input', 'step-down'), type: "button", tabIndex: -1, className: "snap-number-input-step", "aria-label": "\u51CF\u5C0F", disabled: disabled === true || (current !== undefined && min !== undefined && current <= min), onClick: () => stepBy(-1), children: "\uFF0D" })] })] }));
43
+ return (_jsxs("div", { ...part('number-input', 'root'), className: cn('snap-input', 'snap-number-input', className), style: style, "data-size": size, "data-invalid": invalid || undefined, "data-disabled": disabled === true || undefined, children: [_jsx("input", { ref: fieldRef, className: cn('snap-input-field', fieldClassName), type: "number", inputMode: "decimal", disabled: disabled, "aria-invalid": invalid || undefined, value: value, onChange: onChange, ...min !== undefined ? { min } : {}, ...max !== undefined ? { max } : {}, ...step !== undefined ? { step } : {}, ...props, ...part('number-input', 'field') }), _jsxs("span", { className: "snap-number-input-steps", children: [_jsx("button", { ...part('number-input', 'step-up'), type: "button", tabIndex: -1, className: "snap-number-input-step", "aria-label": "\u589E\u5927", disabled: disabled === true || (current !== undefined && max !== undefined && current >= max), onClick: () => stepBy(1), children: "\uFF0B" }), _jsx("button", { ...part('number-input', 'step-down'), type: "button", tabIndex: -1, className: "snap-number-input-step", "aria-label": "\u51CF\u5C0F", disabled: disabled === true || (current !== undefined && min !== undefined && current <= min), onClick: () => stepBy(-1), children: "\uFF0D" })] })] }));
44
44
  }
45
45
  //# sourceMappingURL=input.js.map
@@ -1,7 +1,8 @@
1
1
  /**
2
- * Overlay semantics over Radix: tooltips, popovers, dropdown menus, and
3
- * toasts. Behaviour/keyboard/focus handling stays here; skins target the
4
- * stable parts (`tooltip.*`, `popover.*`, `menu.*`, `toast.*`) and state
2
+ * Overlay semantics over Radix: tooltips, popovers, and dropdown menus; the
3
+ * toast queue runs on Sonner (the Radix toast primitive is deprecated
4
+ * upstream). Behaviour/keyboard/focus handling stays here; skins target the
5
+ * stable parts (`tooltip.*`, `popover.*`, `menu.*`) and Sonner's toast data
5
6
  * attributes. The imperative toast() helper pairs with the <Toaster/> the
6
7
  * runtime mounts in every surface root.
7
8
  *
@@ -9,7 +10,6 @@
9
10
  */
10
11
  import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
11
12
  import * as PopoverPrimitive from '@radix-ui/react-popover';
12
- import * as ToastPrimitive from '@radix-ui/react-toast';
13
13
  import * as TooltipPrimitive from '@radix-ui/react-tooltip';
14
14
  import { type ComponentPropsWithoutRef, type ReactNode } from 'react';
15
15
  /** The tooltip root; wraps `TooltipTrigger`/`TooltipContent` and owns delay. */
@@ -39,9 +39,24 @@ export interface PopoverContentProps extends ComponentPropsWithoutRef<typeof Pop
39
39
  side?: 'top' | 'right' | 'bottom' | 'left';
40
40
  align?: 'start' | 'center' | 'end';
41
41
  sideOffset?: number;
42
+ /** Overrides the open-focus heuristic. Default: a panel opened from an
43
+ * editable element (anchored combobox typing into a field) keeps the focus
44
+ * in it; otherwise the panel takes focus as Radix does. `false` never
45
+ * moves focus into the panel, `true` always lets the FocusScope run. */
46
+ autoFocusOnOpen?: boolean;
42
47
  }
43
- /** The portalled popover panel. */
44
- export declare function PopoverContent({ side, align, sideOffset, className, children, ...props }: PopoverContentProps): ReactNode;
48
+ /**
49
+ * The portalled popover panel, with the two focus dead ends Radix leaves
50
+ * open in anchored mode: on open, the FocusScope default steals the focus
51
+ * from the field a combobox is typing into; on close, the default handler
52
+ * focuses the trigger ref — which is `null` without a `PopoverTrigger`, so
53
+ * focus strands on `body` and every keystroke dies. The wrapper remembers
54
+ * the element that opened the panel and returns focus there; when that
55
+ * element is editable it also keeps the focus in it while the panel is
56
+ * open. Trigger-mode popovers behave exactly as Radix does (the opener IS
57
+ * the trigger).
58
+ */
59
+ export declare function PopoverContent({ side, align, sideOffset, autoFocusOnOpen, className, children, onOpenAutoFocus, onCloseAutoFocus, onInteractOutside, ...props }: PopoverContentProps): ReactNode;
45
60
  /** The dropdown menu root. */
46
61
  export declare const Menu: import("react").FC<DropdownMenuPrimitive.DropdownMenuProps>;
47
62
  /** The menu trigger; wraps its child and toggles the dropdown. */
@@ -73,23 +88,14 @@ export interface ToastEntry {
73
88
  * (default 5000). */
74
89
  duration?: number;
75
90
  }
76
- /** Enqueue a toast on the runtime-mounted {@link Toaster}s. */
91
+ /** Enqueue a toast on the runtime-mounted {@link Toaster}s. Backed by Sonner
92
+ * (the Radix toast primitive is deprecated upstream): `success`/`warning`/
93
+ * `danger` map to the typed emitters, `neutral`/`primary` ride the plain one,
94
+ * and every toast carries an `snap-intent-*` class the skins target. */
77
95
  export declare function toast(entry: ToastEntry): number;
78
96
  /** Dismiss a queued toast by id. */
79
97
  export declare function dismissToast(id: number): void;
80
98
  /** The runtime-mounted viewport: renders the shared toast queue. Pages never
81
99
  * mount this themselves — the runtime provides one per surface root. */
82
- export declare function Toaster(props: Omit<ComponentPropsWithoutRef<typeof ToastPrimitive.Provider>, 'duration'>): ReactNode;
83
- /** The raw toast root for pages that manage their own open state. */
84
- export declare const Toast: import("react").ForwardRefExoticComponent<ToastPrimitive.ToastProps & import("react").RefAttributes<HTMLLIElement>>;
85
- /** A toast title with its part tag. */
86
- export declare function ToastTitle({ className, children, ...props }: ComponentPropsWithoutRef<typeof ToastPrimitive.Title>): ReactNode;
87
- /** A toast description with its part tag. */
88
- export declare function ToastDescription({ className, children, ...props }: ComponentPropsWithoutRef<typeof ToastPrimitive.Description>): ReactNode;
89
- /** An interactive toast action (confirm/retry affordances). */
90
- export declare function ToastAction({ className, children, ...props }: ComponentPropsWithoutRef<typeof ToastPrimitive.Action>): ReactNode;
91
- /** A toast dismissal button. */
92
- export declare function ToastClose({ className, children, ...props }: ComponentPropsWithoutRef<typeof ToastPrimitive.Close>): ReactNode;
93
- /** The toast viewport; only the runtime's {@link Toaster} mounts one. */
94
- export declare function ToastViewport({ className, ...props }: ComponentPropsWithoutRef<typeof ToastPrimitive.Viewport>): ReactNode;
100
+ export declare function Toaster(): ReactNode;
95
101
  //# sourceMappingURL=overlay.d.ts.map
@@ -1,8 +1,9 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  /**
3
- * Overlay semantics over Radix: tooltips, popovers, dropdown menus, and
4
- * toasts. Behaviour/keyboard/focus handling stays here; skins target the
5
- * stable parts (`tooltip.*`, `popover.*`, `menu.*`, `toast.*`) and state
3
+ * Overlay semantics over Radix: tooltips, popovers, and dropdown menus; the
4
+ * toast queue runs on Sonner (the Radix toast primitive is deprecated
5
+ * upstream). Behaviour/keyboard/focus handling stays here; skins target the
6
+ * stable parts (`tooltip.*`, `popover.*`, `menu.*`) and Sonner's toast data
6
7
  * attributes. The imperative toast() helper pairs with the <Toaster/> the
7
8
  * runtime mounts in every surface root.
8
9
  *
@@ -10,9 +11,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
10
11
  */
11
12
  import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
12
13
  import * as PopoverPrimitive from '@radix-ui/react-popover';
13
- import * as ToastPrimitive from '@radix-ui/react-toast';
14
14
  import * as TooltipPrimitive from '@radix-ui/react-tooltip';
15
- import { useSyncExternalStore, } from 'react';
15
+ import { Toaster as SonnerToaster, toast as sonnerToast } from 'sonner';
16
+ import { useRef, } from 'react';
16
17
  import { cn, part } from "../utils.js";
17
18
  /* ------------------------------------------------------------------ Tooltip */
18
19
  /** The tooltip root; wraps `TooltipTrigger`/`TooltipContent` and owns delay. */
@@ -25,18 +26,18 @@ export function TooltipProvider(props) {
25
26
  }
26
27
  /** The tooltip trigger; wraps its child and anchors the bubble. */
27
28
  export function TooltipTrigger(props) {
28
- return _jsx(TooltipPrimitive.Trigger, { ...part('tooltip', 'trigger'), ...props });
29
+ return _jsx(TooltipPrimitive.Trigger, { ...props, ...part('tooltip', 'trigger') });
29
30
  }
30
31
  /** The portalled tooltip bubble. */
31
32
  export function TooltipContent({ side = 'top', sideOffset = 6, className, children, ...props }) {
32
- return (_jsx(TooltipPrimitive.Portal, { children: _jsx(TooltipPrimitive.Content, { ...part('tooltip', 'content'), className: cn('snap-tooltip', className), side: side, sideOffset: sideOffset, ...props, children: children }) }));
33
+ return (_jsx(TooltipPrimitive.Portal, { children: _jsx(TooltipPrimitive.Content, { className: cn('snap-tooltip', className), side: side, sideOffset: sideOffset, ...props, ...part('tooltip', 'content'), children: children }) }));
33
34
  }
34
35
  /* ------------------------------------------------------------------ Popover */
35
36
  /** The popover root. */
36
37
  export const Popover = PopoverPrimitive.Root;
37
38
  /** The popover trigger; wraps its child and toggles the panel. */
38
39
  export function PopoverTrigger(props) {
39
- return _jsx(PopoverPrimitive.Trigger, { ...part('popover', 'trigger'), ...props });
40
+ return _jsx(PopoverPrimitive.Trigger, { ...props, ...part('popover', 'trigger') });
40
41
  }
41
42
  /** An element the panel positions against without toggling it. */
42
43
  export const PopoverAnchor = PopoverPrimitive.Anchor;
@@ -44,32 +45,79 @@ export const PopoverAnchor = PopoverPrimitive.Anchor;
44
45
  export function PopoverClose(props) {
45
46
  return _jsx(PopoverPrimitive.Close, { ...props });
46
47
  }
47
- /** The portalled popover panel. */
48
- export function PopoverContent({ side = 'bottom', align = 'center', sideOffset = 6, className, children, ...props }) {
49
- return (_jsx(PopoverPrimitive.Portal, { children: _jsx(PopoverPrimitive.Content, { ...part('popover', 'content'), className: cn('snap-popover', className), side: side, align: align, sideOffset: sideOffset, ...props, children: children }) }));
48
+ /** Whether the element can hold a text caret (the anchored-combobox opener). */
49
+ function isEditableElement(element) {
50
+ if (element === null || !(element instanceof HTMLElement))
51
+ return false;
52
+ return element.tagName === 'INPUT' || element.tagName === 'TEXTAREA' || element.isContentEditable;
53
+ }
54
+ /**
55
+ * The portalled popover panel, with the two focus dead ends Radix leaves
56
+ * open in anchored mode: on open, the FocusScope default steals the focus
57
+ * from the field a combobox is typing into; on close, the default handler
58
+ * focuses the trigger ref — which is `null` without a `PopoverTrigger`, so
59
+ * focus strands on `body` and every keystroke dies. The wrapper remembers
60
+ * the element that opened the panel and returns focus there; when that
61
+ * element is editable it also keeps the focus in it while the panel is
62
+ * open. Trigger-mode popovers behave exactly as Radix does (the opener IS
63
+ * the trigger).
64
+ */
65
+ export function PopoverContent({ side = 'bottom', align = 'center', sideOffset = 6, autoFocusOnOpen, className, children, onOpenAutoFocus, onCloseAutoFocus, onInteractOutside, ...props }) {
66
+ const openerRef = useRef(null);
67
+ const interactedOutsideRef = useRef(false);
68
+ const handleOpenAutoFocus = (event) => {
69
+ // Radix dispatches this while the opener still holds focus; record it
70
+ // before anything can move focus — the close path returns to it.
71
+ openerRef.current = document.activeElement;
72
+ interactedOutsideRef.current = false;
73
+ onOpenAutoFocus?.(event);
74
+ if (event.defaultPrevented)
75
+ return;
76
+ const exempt = autoFocusOnOpen === false
77
+ || (autoFocusOnOpen === undefined && isEditableElement(openerRef.current));
78
+ if (exempt)
79
+ event.preventDefault();
80
+ };
81
+ const handleCloseAutoFocus = (event) => {
82
+ onCloseAutoFocus?.(event);
83
+ if (event.defaultPrevented)
84
+ return;
85
+ if (interactedOutsideRef.current)
86
+ return;
87
+ const opener = openerRef.current;
88
+ if (opener !== null && opener !== document.body && opener.isConnected) {
89
+ event.preventDefault();
90
+ opener.focus({ preventScroll: true });
91
+ }
92
+ };
93
+ const handleInteractOutside = (event) => {
94
+ interactedOutsideRef.current = true;
95
+ onInteractOutside?.(event);
96
+ };
97
+ return (_jsx(PopoverPrimitive.Portal, { children: _jsx(PopoverPrimitive.Content, { className: cn('snap-popover', className), side: side, align: align, sideOffset: sideOffset, onOpenAutoFocus: handleOpenAutoFocus, onCloseAutoFocus: handleCloseAutoFocus, onInteractOutside: handleInteractOutside, ...props, ...part('popover', 'content'), children: children }) }));
50
98
  }
51
99
  /* -------------------------------------------------------------------- Menu */
52
100
  /** The dropdown menu root. */
53
101
  export const Menu = DropdownMenuPrimitive.Root;
54
102
  /** The menu trigger; wraps its child and toggles the dropdown. */
55
103
  export function MenuTrigger(props) {
56
- return _jsx(DropdownMenuPrimitive.Trigger, { ...part('menu', 'trigger'), ...props });
104
+ return _jsx(DropdownMenuPrimitive.Trigger, { ...props, ...part('menu', 'trigger') });
57
105
  }
58
106
  /** The portalled dropdown list. */
59
107
  export function MenuContent({ side = 'bottom', align = 'start', sideOffset = 4, className, children, ...props }) {
60
- return (_jsx(DropdownMenuPrimitive.Portal, { children: _jsx(DropdownMenuPrimitive.Content, { ...part('menu', 'content'), className: cn('snap-menu', className), side: side, align: align, sideOffset: sideOffset, ...props, children: children }) }));
108
+ return (_jsx(DropdownMenuPrimitive.Portal, { children: _jsx(DropdownMenuPrimitive.Content, { className: cn('snap-menu', className), side: side, align: align, sideOffset: sideOffset, ...props, ...part('menu', 'content'), children: children }) }));
61
109
  }
62
110
  /** One menu action. */
63
111
  export function MenuItem({ className, children, ...props }) {
64
- return (_jsx(DropdownMenuPrimitive.Item, { ...part('menu', 'item'), className: cn('snap-menu-item', className), ...props, children: children }));
112
+ return (_jsx(DropdownMenuPrimitive.Item, { className: cn('snap-menu-item', className), ...props, ...part('menu', 'item'), children: children }));
65
113
  }
66
114
  /** A checkable menu action with an indicator slot. */
67
115
  export function MenuCheckboxItem({ className, children, ...props }) {
68
- return (_jsxs(DropdownMenuPrimitive.CheckboxItem, { ...part('menu', 'checkbox-item'), className: cn('snap-menu-item', className), ...props, children: [_jsx(DropdownMenuPrimitive.ItemIndicator, { ...part('menu', 'item-indicator'), className: "snap-menu-indicator", children: "\u2713" }), children] }));
116
+ return (_jsxs(DropdownMenuPrimitive.CheckboxItem, { className: cn('snap-menu-item', className), ...props, ...part('menu', 'checkbox-item'), children: [_jsx(DropdownMenuPrimitive.ItemIndicator, { ...part('menu', 'item-indicator'), className: "snap-menu-indicator", children: "\u2713" }), children] }));
69
117
  }
70
118
  /** A non-interactive group heading. */
71
119
  export function MenuLabel({ className, children, ...props }) {
72
- return _jsx(DropdownMenuPrimitive.Label, { className: cn('snap-menu-label', className), ...props, children: children });
120
+ return _jsx(DropdownMenuPrimitive.Label, { className: cn('snap-menu-label', className), ...props, ...part('menu', 'label'), children: children });
73
121
  }
74
122
  /** A group container for items. */
75
123
  export function MenuGroup(props) {
@@ -77,62 +125,46 @@ export function MenuGroup(props) {
77
125
  }
78
126
  /** A horizontal rule between menu sections. */
79
127
  export function MenuSeparator({ className, ...props }) {
80
- return _jsx(DropdownMenuPrimitive.Separator, { ...part('menu', 'separator'), className: cn('snap-menu-separator', className), ...props });
81
- }
82
- let toastNextId = 1;
83
- let toastRecords = [];
84
- const toastListeners = new Set();
85
- function toastEmit() {
86
- for (const listener of toastListeners)
87
- listener();
88
- }
89
- function toastDismiss(id) {
90
- toastRecords = toastRecords.filter(record => record.id !== id);
91
- toastEmit();
92
- }
93
- /** Enqueue a toast on the runtime-mounted {@link Toaster}s. */
128
+ return _jsx(DropdownMenuPrimitive.Separator, { className: cn('snap-menu-separator', className), ...props, ...part('menu', 'separator') });
129
+ }
130
+ /** Stroke glyphs per intent (lucide-style 24-box, `currentColor`); the skin
131
+ * colours them through the toast's `[data-icon]`. */
132
+ const TOAST_INTENT_PATHS = {
133
+ neutral: (_jsxs(_Fragment, { children: [_jsx("circle", { cx: "12", cy: "12", r: "10" }), _jsx("path", { d: "M12 16v-4" }), _jsx("path", { d: "M12 8h.01" })] })),
134
+ primary: (_jsxs(_Fragment, { children: [_jsx("circle", { cx: "12", cy: "12", r: "10" }), _jsx("path", { d: "M12 16v-4" }), _jsx("path", { d: "M12 8h.01" })] })),
135
+ success: (_jsxs(_Fragment, { children: [_jsx("circle", { cx: "12", cy: "12", r: "10" }), _jsx("path", { d: "m9 12 2 2 4-4" })] })),
136
+ warning: (_jsxs(_Fragment, { children: [_jsx("path", { d: "m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z" }), _jsx("path", { d: "M12 9v4" }), _jsx("path", { d: "M12 17h.01" })] })),
137
+ danger: (_jsxs(_Fragment, { children: [_jsx("circle", { cx: "12", cy: "12", r: "10" }), _jsx("path", { d: "m15 9-6 6" }), _jsx("path", { d: "m9 9 6 6" })] })),
138
+ };
139
+ function toastIcon(intent) {
140
+ return (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: TOAST_INTENT_PATHS[intent] }));
141
+ }
142
+ /** Enqueue a toast on the runtime-mounted {@link Toaster}s. Backed by Sonner
143
+ * (the Radix toast primitive is deprecated upstream): `success`/`warning`/
144
+ * `danger` map to the typed emitters, `neutral`/`primary` ride the plain one,
145
+ * and every toast carries an `snap-intent-*` class the skins target. */
94
146
  export function toast(entry) {
95
- const id = toastNextId++;
96
- toastRecords = [...toastRecords, { ...entry, id }];
97
- toastEmit();
98
- return id;
147
+ const intent = entry.intent ?? 'neutral';
148
+ const options = {
149
+ description: entry.description,
150
+ icon: toastIcon(intent),
151
+ duration: entry.duration === 0 ? Number.POSITIVE_INFINITY : (entry.duration ?? 5000),
152
+ className: `snap-intent-${intent}`,
153
+ };
154
+ switch (intent) {
155
+ case 'success': return sonnerToast.success(entry.title, options);
156
+ case 'warning': return sonnerToast.warning(entry.title, options);
157
+ case 'danger': return sonnerToast.error(entry.title, options);
158
+ default: return sonnerToast(entry.title, options);
159
+ }
99
160
  }
100
161
  /** Dismiss a queued toast by id. */
101
162
  export function dismissToast(id) {
102
- toastDismiss(id);
163
+ sonnerToast.dismiss(id);
103
164
  }
104
165
  /** The runtime-mounted viewport: renders the shared toast queue. Pages never
105
166
  * mount this themselves — the runtime provides one per surface root. */
106
- export function Toaster(props) {
107
- const records = useSyncExternalStore((onStoreChange) => {
108
- toastListeners.add(onStoreChange);
109
- return () => toastListeners.delete(onStoreChange);
110
- }, () => toastRecords, () => toastRecords);
111
- return (_jsxs(ToastPrimitive.Provider, { ...props, children: [records.map(record => (_jsxs(ToastPrimitive.Root, { ...part('toast', 'root'), className: "snap-toast", "data-intent": record.intent ?? 'neutral', duration: record.duration ?? 5000, onOpenChange: (open) => {
112
- if (!open)
113
- toastDismiss(record.id);
114
- }, children: [_jsx(ToastTitle, { children: record.title }), record.description !== undefined && _jsx(ToastDescription, { children: record.description }), _jsx(ToastClose, { "aria-label": "\u5173\u95ED" })] }, record.id))), _jsx(ToastViewport, {})] }));
115
- }
116
- /** The raw toast root for pages that manage their own open state. */
117
- export const Toast = ToastPrimitive.Root;
118
- /** A toast title with its part tag. */
119
- export function ToastTitle({ className, children, ...props }) {
120
- return _jsx(ToastPrimitive.Title, { ...part('toast', 'title'), className: cn('snap-toast-title', className), ...props, children: children });
121
- }
122
- /** A toast description with its part tag. */
123
- export function ToastDescription({ className, children, ...props }) {
124
- return _jsx(ToastPrimitive.Description, { ...part('toast', 'description'), className: cn('snap-toast-description', className), ...props, children: children });
125
- }
126
- /** An interactive toast action (confirm/retry affordances). */
127
- export function ToastAction({ className, children, ...props }) {
128
- return _jsx(ToastPrimitive.Action, { ...part('toast', 'action'), className: cn('snap-toast-action', className), ...props, children: children });
129
- }
130
- /** A toast dismissal button. */
131
- export function ToastClose({ className, children, ...props }) {
132
- return _jsx(ToastPrimitive.Close, { ...part('toast', 'close'), className: cn('snap-toast-close', className), ...props, children: children ?? _jsx("span", { "aria-hidden": "true", children: "\u00D7" }) });
133
- }
134
- /** The toast viewport; only the runtime's {@link Toaster} mounts one. */
135
- export function ToastViewport({ className, ...props }) {
136
- return _jsx(ToastPrimitive.Viewport, { ...part('toast', 'viewport'), className: cn('snap-toast-viewport', className), ...props });
167
+ export function Toaster() {
168
+ return _jsx(SonnerToaster, { position: "bottom-right", closeButton: true });
137
169
  }
138
170
  //# sourceMappingURL=overlay.js.map
@@ -10,6 +10,6 @@ import * as SliderPrimitive from '@radix-ui/react-slider';
10
10
  import { cn, part } from "../utils.js";
11
11
  /** A ranged control with a large touch target and keyboard stepping. */
12
12
  export function Slider({ label, className, children, ...props }) {
13
- return (_jsxs(SliderPrimitive.Root, { ...part('slider', 'root'), className: cn('snap-slider', className), "aria-label": label, ...props, children: [_jsx(SliderPrimitive.Track, { ...part('slider', 'track'), className: "snap-slider-track", children: _jsx(SliderPrimitive.Range, { ...part('slider', 'range'), className: "snap-slider-range" }) }), _jsx(SliderPrimitive.Thumb, { ...part('slider', 'thumb'), className: "snap-slider-thumb", "aria-label": label }), children] }));
13
+ return (_jsxs(SliderPrimitive.Root, { className: cn('snap-slider', className), "aria-label": label, ...props, ...part('slider', 'root'), children: [_jsx(SliderPrimitive.Track, { ...part('slider', 'track'), className: "snap-slider-track", children: _jsx(SliderPrimitive.Range, { ...part('slider', 'range'), className: "snap-slider-range" }) }), _jsx(SliderPrimitive.Thumb, { ...part('slider', 'thumb'), className: "snap-slider-thumb", "aria-label": label }), children] }));
14
14
  }
15
15
  //# sourceMappingURL=slider.js.map
@@ -2,31 +2,31 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { cn, part } from "../utils.js";
3
3
  /** A content card. */
4
4
  export function Card({ className, children, ...props }) {
5
- return _jsx("div", { ...part('card', 'root'), className: cn('snap-card', className), ...props, children: children });
5
+ return _jsx("div", { className: cn('snap-card', className), ...props, ...part('card', 'root'), children: children });
6
6
  }
7
7
  /** The card header region. */
8
8
  export function CardHeader({ className, children, ...props }) {
9
- return _jsx("div", { ...part('card', 'header'), className: cn('snap-card-header', className), ...props, children: children });
9
+ return _jsx("div", { className: cn('snap-card-header', className), ...props, ...part('card', 'header'), children: children });
10
10
  }
11
11
  /** The card title. */
12
12
  export function CardTitle({ className, children, ...props }) {
13
- return _jsx("div", { ...part('card', 'title'), className: cn('snap-card-title', className), ...props, children: children });
13
+ return _jsx("div", { className: cn('snap-card-title', className), ...props, ...part('card', 'title'), children: children });
14
14
  }
15
15
  /** The card description. */
16
16
  export function CardDescription({ className, children, ...props }) {
17
- return _jsx("div", { ...part('card', 'description'), className: cn('snap-card-description', className), ...props, children: children });
17
+ return _jsx("div", { className: cn('snap-card-description', className), ...props, ...part('card', 'description'), children: children });
18
18
  }
19
19
  /** The card body. */
20
20
  export function CardContent({ className, children, ...props }) {
21
- return _jsx("div", { ...part('card', 'body'), className: cn('snap-card-content', className), ...props, children: children });
21
+ return _jsx("div", { className: cn('snap-card-content', className), ...props, ...part('card', 'body'), children: children });
22
22
  }
23
23
  /** The card footer. */
24
24
  export function CardFooter({ className, children, ...props }) {
25
- return _jsx("div", { ...part('card', 'footer'), className: cn('snap-card-footer', className), ...props, children: children });
25
+ return _jsx("div", { className: cn('snap-card-footer', className), ...props, ...part('card', 'footer'), children: children });
26
26
  }
27
27
  /** A bounded panel with optional header/footer. */
28
28
  export function Panel({ title, actions, footer, className, children, ...props }) {
29
- return (_jsxs("div", { ...part('panel', 'root'), className: cn('snap-panel', className), ...props, children: [(title !== undefined || actions !== undefined) && (_jsxs("div", { ...part('panel', 'header'), className: "snap-panel-header", children: [_jsx("div", { ...part('panel', 'title'), children: title }), actions !== undefined && _jsx("div", { children: actions })] })), _jsx("div", { ...part('panel', 'body'), className: "snap-panel-body", children: children }), footer !== undefined && _jsx("div", { ...part('panel', 'footer'), className: "snap-panel-footer", children: footer })] }));
29
+ return (_jsxs("div", { className: cn('snap-panel', className), ...props, ...part('panel', 'root'), children: [(title !== undefined || actions !== undefined) && (_jsxs("div", { ...part('panel', 'header'), className: "snap-panel-header", children: [_jsx("div", { ...part('panel', 'title'), children: title }), actions !== undefined && _jsx("div", { children: actions })] })), _jsx("div", { ...part('panel', 'body'), className: "snap-panel-body", children: children }), footer !== undefined && _jsx("div", { ...part('panel', 'footer'), className: "snap-panel-footer", children: footer })] }));
30
30
  }
31
31
  /** A semantic table. */
32
32
  export function Table({ className, children, ...props }) {
@@ -34,23 +34,23 @@ export function Table({ className, children, ...props }) {
34
34
  }
35
35
  /** The table head. */
36
36
  export function TableHeader({ className, children, ...props }) {
37
- return _jsx("thead", { ...part('table', 'header'), className: cn('snap-table-header', className), ...props, children: children });
37
+ return _jsx("thead", { className: cn('snap-table-header', className), ...props, ...part('table', 'header'), children: children });
38
38
  }
39
39
  /** The table body. */
40
40
  export function TableBody({ className, children, ...props }) {
41
- return _jsx("tbody", { ...part('table', 'body'), className: cn('snap-table-body', className), ...props, children: children });
41
+ return _jsx("tbody", { className: cn('snap-table-body', className), ...props, ...part('table', 'body'), children: children });
42
42
  }
43
43
  /** A table row. */
44
44
  export function TableRow({ className, children, ...props }) {
45
- return _jsx("tr", { ...part('table', 'row'), className: cn('snap-table-row', className), ...props, children: children });
45
+ return _jsx("tr", { className: cn('snap-table-row', className), ...props, ...part('table', 'row'), children: children });
46
46
  }
47
47
  /** A table header cell. */
48
48
  export function TableHead({ className, children, ...props }) {
49
- return _jsx("th", { ...part('table', 'head'), className: cn('snap-table-head', className), ...props, children: children });
49
+ return _jsx("th", { className: cn('snap-table-head', className), ...props, ...part('table', 'head'), children: children });
50
50
  }
51
51
  /** A table body cell. */
52
52
  export function TableCell({ className, children, ...props }) {
53
- return _jsx("td", { ...part('table', 'cell'), className: cn('snap-table-cell', className), ...props, children: children });
53
+ return _jsx("td", { className: cn('snap-table-cell', className), ...props, ...part('table', 'cell'), children: children });
54
54
  }
55
55
  /** A full-width empty row. */
56
56
  export function TableEmpty({ colSpan, children }) {
@@ -204,9 +204,14 @@ export declare const UI_COMPONENTS: {
204
204
  readonly props: readonly ["size", "invalid", "disabled", "defaultValue", "side", "align"];
205
205
  };
206
206
  readonly 'touch-select': {
207
- readonly parts: readonly ["touch-select.root", "touch-select.trigger", "touch-select.sheet", "touch-select.option"];
207
+ readonly parts: readonly ["touch-select.root", "touch-select.trigger", "touch-select.sheet", "touch-select.options"];
208
208
  readonly props: readonly ["invalid", "disabled"];
209
209
  };
210
+ readonly combobox: {
211
+ readonly parts: readonly ["combobox.root", "combobox.anchor", "combobox.list", "combobox.option", "combobox.empty"];
212
+ readonly slots: readonly ["empty"];
213
+ readonly props: readonly ["value", "options", "size", "invalid", "disabled", "loading", "onInputValueChange"];
214
+ };
210
215
  readonly checkbox: {
211
216
  readonly parts: readonly ["checkbox.root", "checkbox.indicator", "checkbox.label", "checkbox.field", "checkbox.description"];
212
217
  readonly slots: readonly ["label", "description"];
@@ -260,10 +265,6 @@ export declare const UI_COMPONENTS: {
260
265
  readonly parts: readonly ["menu.trigger", "menu.content", "menu.item", "menu.checkbox-item", "menu.item-indicator", "menu.separator"];
261
266
  readonly slots: readonly ["trigger", "content"];
262
267
  };
263
- readonly toast: {
264
- readonly parts: readonly ["toast.root", "toast.title", "toast.description", "toast.action", "toast.close", "toast.viewport"];
265
- readonly slots: readonly ["action"];
266
- };
267
268
  readonly progress: {
268
269
  readonly parts: readonly ["progress.root", "progress.track", "progress.indicator"];
269
270
  };
@@ -92,9 +92,14 @@ export const UI_COMPONENTS = {
92
92
  props: ['size', 'invalid', 'disabled', 'defaultValue', 'side', 'align'],
93
93
  },
94
94
  'touch-select': {
95
- parts: ['touch-select.root', 'touch-select.trigger', 'touch-select.sheet', 'touch-select.option'],
95
+ parts: ['touch-select.root', 'touch-select.trigger', 'touch-select.sheet', 'touch-select.options'],
96
96
  props: ['invalid', 'disabled'],
97
97
  },
98
+ combobox: {
99
+ parts: ['combobox.root', 'combobox.anchor', 'combobox.list', 'combobox.option', 'combobox.empty'],
100
+ slots: ['empty'],
101
+ props: ['value', 'options', 'size', 'invalid', 'disabled', 'loading', 'onInputValueChange'],
102
+ },
98
103
  checkbox: {
99
104
  parts: ['checkbox.root', 'checkbox.indicator', 'checkbox.label', 'checkbox.field', 'checkbox.description'],
100
105
  slots: ['label', 'description'],
@@ -148,10 +153,6 @@ export const UI_COMPONENTS = {
148
153
  parts: ['menu.trigger', 'menu.content', 'menu.item', 'menu.checkbox-item', 'menu.item-indicator', 'menu.separator'],
149
154
  slots: ['trigger', 'content'],
150
155
  },
151
- toast: {
152
- parts: ['toast.root', 'toast.title', 'toast.description', 'toast.action', 'toast.close', 'toast.viewport'],
153
- slots: ['action'],
154
- },
155
156
  progress: {
156
157
  parts: ['progress.root', 'progress.track', 'progress.indicator'],
157
158
  },
@@ -6,7 +6,13 @@
6
6
  */
7
7
  /** Join truthy class names. */
8
8
  export declare function cn(...values: ReadonlyArray<string | false | null | undefined>): string;
9
- /** The anatomy attributes every semantic component renders. */
9
+ /**
10
+ * The anatomy attributes every semantic component renders. The identity is
11
+ * component-owned: components spread these AFTER caller props so a composite
12
+ * can never mask a host part (a masked `button.root` loses every skin rule
13
+ * and falls back to the UA default look). Composites tag their own wrappers
14
+ * instead of pushing `part()` into a child component's props.
15
+ */
10
16
  export declare function part(component: string, name: string): Record<string, string>;
11
17
  /** Map a semantic size token to a control-height CSS variable. */
12
18
  export declare function controlHeight(size: 'sm' | 'md' | 'lg'): string;
@@ -8,7 +8,13 @@
8
8
  export function cn(...values) {
9
9
  return values.filter((value) => typeof value === 'string' && value.length > 0).join(' ');
10
10
  }
11
- /** The anatomy attributes every semantic component renders. */
11
+ /**
12
+ * The anatomy attributes every semantic component renders. The identity is
13
+ * component-owned: components spread these AFTER caller props so a composite
14
+ * can never mask a host part (a masked `button.root` loses every skin rule
15
+ * and falls back to the UA default look). Composites tag their own wrappers
16
+ * instead of pushing `part()` into a child component's props.
17
+ */
12
18
  export function part(component, name) {
13
19
  return {
14
20
  'data-snap-component': component,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@snap-rail/ui",
3
3
  "description": "The built-in UI substrate: semantic components, typed region slots, skins, settings and renderer runtime",
4
- "version": "0.2.0",
4
+ "version": "0.4.0",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/types/index.d.ts",
@@ -76,18 +76,18 @@
76
76
  "@radix-ui/react-slot": "^1.3.3",
77
77
  "@radix-ui/react-switch": "^1.3.7",
78
78
  "@radix-ui/react-tabs": "^1.1.13",
79
- "@radix-ui/react-toast": "^1.3.1",
80
79
  "@radix-ui/react-tooltip": "^1.2.16",
81
- "react-hook-form": "^7.91.0"
80
+ "react-hook-form": "^7.91.0",
81
+ "sonner": "^2.0.8"
82
82
  },
83
83
  "peerDependencies": {
84
84
  "react": ">=19",
85
85
  "react-dom": ">=19",
86
86
  "zod": "^4.4.3",
87
- "@snap-rail/connection": "^0.1.0",
88
87
  "@snap-rail/cordis": "^4.0.3",
89
88
  "@snap-rail/protocol": "^0.1.3",
90
- "@snap-rail/shell": "^0.2.3"
89
+ "@snap-rail/shell": "^0.2.4",
90
+ "@snap-rail/connection": "^0.1.0"
91
91
  },
92
92
  "devDependencies": {
93
93
  "@types/react": "^19.2.14",
@@ -99,14 +99,14 @@
99
99
  "typescript": "^6.0.3",
100
100
  "vitest": "^4.1.8",
101
101
  "zod": "^4.4.3",
102
+ "@snap-rail/app-boot": "^0.1.3",
103
+ "@snap-rail/client-kernel": "^0.1.2",
102
104
  "@snap-rail/connection": "^0.1.0",
103
105
  "@snap-rail/cordis": "^4.0.3",
104
- "@snap-rail/app-boot": "^0.1.3",
105
106
  "@snap-rail/cordis-plugin-timer": "^1.1.3",
106
- "@snap-rail/client-kernel": "^0.1.2",
107
107
  "@snap-rail/protocol": "^0.1.3",
108
- "@snap-rail/station-rpc": "^0.1.0",
109
- "@snap-rail/shell": "^0.2.3"
108
+ "@snap-rail/shell": "^0.2.4",
109
+ "@snap-rail/station-rpc": "^0.1.0"
110
110
  },
111
111
  "snapRail": {
112
112
  "layer": "base",