@snap-rail/ui 0.1.0 → 0.2.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.
Files changed (49) hide show
  1. package/lib/charts.js +6 -29
  2. package/lib/contract.js +119 -78
  3. package/lib/fallback.js +11 -1
  4. package/lib/index.js +2466 -735
  5. package/lib/runtime.js +1552 -490
  6. package/lib/settings.js +1162 -244
  7. package/lib/skins.js +163 -189
  8. package/lib/types/charts.d.ts +1 -1
  9. package/lib/types/charts.js +5 -5
  10. package/lib/types/components/alert.d.ts +57 -0
  11. package/lib/types/components/alert.js +46 -0
  12. package/lib/types/components/controls.d.ts +74 -11
  13. package/lib/types/components/controls.js +60 -17
  14. package/lib/types/components/dialog.d.ts +5 -5
  15. package/lib/types/components/dialog.js +2 -2
  16. package/lib/types/components/form-rhf.d.ts +56 -0
  17. package/lib/types/components/form-rhf.js +74 -0
  18. package/lib/types/components/form.d.ts +33 -5
  19. package/lib/types/components/form.js +22 -6
  20. package/lib/types/components/index.d.ts +7 -0
  21. package/lib/types/components/index.js +7 -0
  22. package/lib/types/components/input.d.ts +16 -7
  23. package/lib/types/components/input.js +39 -9
  24. package/lib/types/components/layout.d.ts +32 -7
  25. package/lib/types/components/layout.js +88 -15
  26. package/lib/types/components/overlay.d.ts +95 -0
  27. package/lib/types/components/overlay.js +138 -0
  28. package/lib/types/components/schema-form.d.ts +16 -4
  29. package/lib/types/components/schema-form.js +69 -40
  30. package/lib/types/components/slider.d.ts +18 -0
  31. package/lib/types/components/slider.js +15 -0
  32. package/lib/types/contract.d.ts +49 -37
  33. package/lib/types/contract.js +49 -33
  34. package/lib/types/fallback.js +1 -1
  35. package/lib/types/runtime.d.ts +23 -1
  36. package/lib/types/runtime.js +77 -20
  37. package/lib/types/settings-pages/appearance.d.ts +6 -4
  38. package/lib/types/settings-pages/appearance.js +33 -36
  39. package/lib/types/settings-pages/plugin-feed.d.ts +17 -0
  40. package/lib/types/settings-pages/plugin-feed.js +66 -0
  41. package/lib/types/settings-pages/plugins.d.ts +10 -5
  42. package/lib/types/settings-pages/plugins.js +284 -21
  43. package/lib/types/settings.d.ts +1 -0
  44. package/lib/types/settings.js +14 -8
  45. package/lib/types/skins.d.ts +38 -44
  46. package/lib/types/skins.js +172 -169
  47. package/package.json +16 -9
  48. package/src/styles/base.css +251 -5
  49. package/src/styles/default.css +315 -136
@@ -8,13 +8,14 @@
8
8
  import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
9
9
  import * as LabelPrimitive from '@radix-ui/react-label';
10
10
  import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
11
+ import * as SelectPrimitive from '@radix-ui/react-select';
11
12
  import * as SwitchPrimitive from '@radix-ui/react-switch';
12
13
  import * as TabsPrimitive from '@radix-ui/react-tabs';
13
14
  import { type ComponentPropsWithoutRef, type ReactNode } from 'react';
14
15
  /** A form label. */
15
16
  export declare function Label({ className, children, ...props }: ComponentPropsWithoutRef<typeof LabelPrimitive.Root>): ReactNode;
16
17
  /** The tabs root. */
17
- export declare const Tabs: import("react").ForwardRefExoticComponent<TabsPrimitive.TabsProps & import("react").RefAttributes<HTMLDivElement>>;
18
+ export declare function Tabs({ className, children, ...props }: ComponentPropsWithoutRef<typeof TabsPrimitive.Root>): ReactNode;
18
19
  /** The tabs list. */
19
20
  export declare function TabsList({ className, children, ...props }: ComponentPropsWithoutRef<typeof TabsPrimitive.List>): ReactNode;
20
21
  /** A tab trigger. */
@@ -24,17 +25,36 @@ export declare function TabsContent({ className, children, ...props }: Component
24
25
  /** Props of {@link Switch}. */
25
26
  export interface SwitchProps extends Omit<ComponentPropsWithoutRef<typeof SwitchPrimitive.Root>, 'children'> {
26
27
  label?: ReactNode;
28
+ /** Which side of the switch the label sits on (default `end`). */
29
+ labelPosition?: 'start' | 'end';
30
+ /** Helper text under the label row. */
31
+ description?: ReactNode;
32
+ /** Escape hatch for the outermost wrapper (only rendered with `description`). */
33
+ containerClassName?: string;
27
34
  }
28
- /** A boolean switch. */
29
- export declare function Switch({ className, label, ...props }: SwitchProps): ReactNode;
35
+ /** A boolean switch with an optional label on either side. */
36
+ export declare function Switch({ className, label, labelPosition, description, containerClassName, ...props }: SwitchProps): ReactNode;
30
37
  /** Props of {@link Checkbox}. */
31
38
  export interface CheckboxProps extends Omit<ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>, 'children'> {
32
39
  label?: ReactNode;
40
+ /** Which side of the checkbox the label sits on (default `end`). */
41
+ labelPosition?: 'start' | 'end';
42
+ /** Helper text under the label row. */
43
+ description?: ReactNode;
44
+ /** Escape hatch for the outermost wrapper (only rendered with `description`). */
45
+ containerClassName?: string;
33
46
  }
34
- /** A tri-state checkbox with an inline indicator. */
35
- export declare function Checkbox({ className, label, ...props }: CheckboxProps): ReactNode;
36
- /** The radio group root. */
37
- export declare function RadioGroup({ className, children, ...props }: ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>): ReactNode;
47
+ /** A tri-state checkbox with an optional label on either side. */
48
+ export declare function Checkbox({ className, label, labelPosition, description, containerClassName, ...props }: CheckboxProps): ReactNode;
49
+ /** Props of {@link RadioGroup}. */
50
+ export interface RadioGroupProps extends ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root> {
51
+ /** A label above the group; linked via `aria-labelledby`. */
52
+ label?: ReactNode;
53
+ /** Helper text below the group. */
54
+ description?: ReactNode;
55
+ }
56
+ /** A labelled group of radio items. */
57
+ export declare function RadioGroup({ className, label, description, children, ...props }: RadioGroupProps): ReactNode;
38
58
  /** One radio item. */
39
59
  export declare function RadioGroupItem({ className, ...props }: ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>): ReactNode;
40
60
  /** One option in a {@link Select} or {@link TouchSelect}. */
@@ -43,24 +63,67 @@ export interface SelectOption {
43
63
  label: ReactNode;
44
64
  disabled?: boolean;
45
65
  }
66
+ /** The popper side the select content opens to. */
67
+ export type SelectSide = 'top' | 'right' | 'bottom' | 'left';
46
68
  /** Props of {@link Select}. */
47
69
  export interface SelectProps {
70
+ /** Controlled value. */
48
71
  value?: string;
72
+ /** Uncontrolled initial value. */
73
+ defaultValue?: string;
49
74
  onValueChange?: (value: string) => void;
50
- options: readonly SelectOption[];
75
+ /** Data-driven options; mutually exclusive with `children` (children win). */
76
+ options?: readonly SelectOption[];
77
+ /** Composite mode: build the content from {@link SelectItem} children. */
78
+ children?: ReactNode;
51
79
  placeholder?: string;
52
80
  disabled?: boolean;
53
81
  invalid?: boolean;
82
+ /** Associates a hidden native select for form submission. */
83
+ name?: string;
84
+ required?: boolean;
85
+ /** The trigger's id; also wires the label's `htmlFor`. */
86
+ id?: string;
54
87
  size?: 'sm' | 'md' | 'lg';
88
+ /** Content placement (default `bottom`). */
89
+ side?: SelectSide;
90
+ /** Content alignment against the trigger (default `start`). */
91
+ align?: 'start' | 'center' | 'end';
92
+ /** Content offset from the trigger in px (default 4). */
93
+ sideOffset?: number;
55
94
  className?: string;
95
+ contentClassName?: string;
56
96
  'aria-label'?: string;
57
97
  }
58
98
  /** Props of {@link TouchSelect}: a modal list for gloved/touch operation. */
59
- export interface TouchSelectProps extends SelectProps {
99
+ export interface TouchSelectProps extends Omit<SelectProps, 'options' | 'children'> {
100
+ options: readonly SelectOption[];
60
101
  title?: ReactNode;
61
102
  }
62
103
  /** A modal option list; use on touch terminals in place of the popover select. */
63
104
  export declare function TouchSelect({ value, onValueChange, options, placeholder, disabled, invalid, size, className, 'aria-label': ariaLabel, title, }: TouchSelectProps): ReactNode;
64
- /** A popover select. */
65
- export declare function Select({ value, onValueChange, options, placeholder, disabled, invalid, size, className, 'aria-label': ariaLabel, }: SelectProps): ReactNode;
105
+ /** The select trigger; composes a {@link SelectValue} inside. */
106
+ export declare function SelectTrigger({ className, size, invalid, disabled, children, ...props }: ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger> & {
107
+ size?: 'sm' | 'md' | 'lg';
108
+ invalid?: boolean;
109
+ }): ReactNode;
110
+ /** The selected-value slot of a trigger. */
111
+ export declare function SelectValue(props: ComponentPropsWithoutRef<typeof SelectPrimitive.Value>): ReactNode;
112
+ /** Props of {@link SelectContent}. */
113
+ export interface SelectContentProps extends ComponentPropsWithoutRef<typeof SelectPrimitive.Content> {
114
+ side?: SelectSide;
115
+ align?: 'start' | 'center' | 'end';
116
+ sideOffset?: number;
117
+ }
118
+ /** The portalled option list. */
119
+ export declare function SelectContent({ side, align, sideOffset, className, children, ...props }: SelectContentProps): ReactNode;
120
+ /** One option row. */
121
+ export declare function SelectItem({ className, children, ...props }: ComponentPropsWithoutRef<typeof SelectPrimitive.Item>): ReactNode;
122
+ /** A labelled group of options. */
123
+ export declare function SelectGroup(props: ComponentPropsWithoutRef<typeof SelectPrimitive.Group>): ReactNode;
124
+ /** A group heading. */
125
+ export declare function SelectLabel({ className, ...props }: ComponentPropsWithoutRef<typeof SelectPrimitive.Label>): ReactNode;
126
+ /** A popover select: data-driven via `options`, or composed from
127
+ * {@link SelectItem} children for full layout control. */
128
+ export declare function Select({ value, defaultValue, onValueChange, options, children, placeholder, disabled, invalid, required, name, id, size, side, align, sideOffset, className, contentClassName, 'aria-label': ariaLabel, }: SelectProps): ReactNode;
66
129
  //# sourceMappingURL=controls.d.ts.map
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /**
3
3
  * Selection and toggle semantics over Radix: tabs, select, switch, checkbox,
4
4
  * and radio groups. All behaviour/keyboard handling stays here; skins target
@@ -12,7 +12,7 @@ import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
12
12
  import * as SelectPrimitive from '@radix-ui/react-select';
13
13
  import * as SwitchPrimitive from '@radix-ui/react-switch';
14
14
  import * as TabsPrimitive from '@radix-ui/react-tabs';
15
- import { useState } from 'react';
15
+ import { useId, useState } from 'react';
16
16
  import { cn, part } from "../utils.js";
17
17
  import { Button } from "./button.js";
18
18
  import { Dialog, DialogContent, DialogHeader, DialogTitle } from "./dialog.js";
@@ -21,7 +21,9 @@ export function Label({ className, children, ...props }) {
21
21
  return _jsx(LabelPrimitive.Root, { className: cn('snap-label', className), ...props, children: children });
22
22
  }
23
23
  /** The tabs root. */
24
- export const Tabs = TabsPrimitive.Root;
24
+ export function Tabs({ className, children, ...props }) {
25
+ return _jsx(TabsPrimitive.Root, { ...part('tabs', 'root'), className: cn('snap-tabs', className), ...props, children: children });
26
+ }
25
27
  /** The tabs list. */
26
28
  export function TabsList({ className, children, ...props }) {
27
29
  return _jsx(TabsPrimitive.List, { ...part('tabs', 'list'), className: cn('snap-tabs-list', className), ...props, children: children });
@@ -34,17 +36,29 @@ export function TabsTrigger({ className, children, ...props }) {
34
36
  export function TabsContent({ className, children, ...props }) {
35
37
  return _jsx(TabsPrimitive.Content, { ...part('tabs', 'content'), className: cn('snap-tabs-content', className), ...props, children: children });
36
38
  }
37
- /** A boolean switch. */
38
- export function Switch({ className, label, ...props }) {
39
- return (_jsxs("label", { className: "snap-switch-label", children: [_jsx(SwitchPrimitive.Root, { ...part('switch', 'root'), className: cn('snap-switch', className), ...props, children: _jsx(SwitchPrimitive.Thumb, { ...part('switch', 'thumb'), className: "snap-switch-thumb" }) }), label !== undefined && _jsx("span", { ...part('switch', 'label'), children: label })] }));
39
+ /** A boolean switch with an optional label on either side. */
40
+ export function Switch({ className, label, labelPosition = 'end', description, containerClassName, ...props }) {
41
+ const labelNode = label !== undefined && _jsx("span", { ...part('switch', 'label'), children: label });
42
+ const row = (_jsxs("label", { className: "snap-switch-label", children: [labelPosition === 'start' && labelNode, _jsx(SwitchPrimitive.Root, { ...part('switch', 'root'), className: cn('snap-switch', className), ...props, children: _jsx(SwitchPrimitive.Thumb, { ...part('switch', 'thumb'), className: "snap-switch-thumb" }) }), labelPosition === 'end' && labelNode] }));
43
+ if (description === undefined)
44
+ return row;
45
+ return (_jsxs("span", { ...part('switch', 'field'), className: cn('snap-switch-field', containerClassName), children: [row, _jsx("span", { ...part('switch', 'description'), className: "snap-field-help", children: description })] }));
40
46
  }
41
- /** A tri-state checkbox with an inline indicator. */
42
- export function Checkbox({ className, label, ...props }) {
43
- return (_jsxs("label", { className: "snap-checkbox-label", children: [_jsx(CheckboxPrimitive.Root, { ...part('checkbox', 'root'), className: cn('snap-checkbox', className), ...props, children: _jsx(CheckboxPrimitive.Indicator, { ...part('checkbox', 'indicator'), className: "snap-checkbox-indicator", children: "\u2713" }) }), label !== undefined && _jsx("span", { ...part('checkbox', 'label'), children: label })] }));
47
+ /** A tri-state checkbox with an optional label on either side. */
48
+ export function Checkbox({ className, label, labelPosition = 'end', description, containerClassName, ...props }) {
49
+ const labelNode = label !== undefined && _jsx("span", { ...part('checkbox', 'label'), children: label });
50
+ const row = (_jsxs("label", { className: "snap-checkbox-label", children: [labelPosition === 'start' && labelNode, _jsx(CheckboxPrimitive.Root, { ...part('checkbox', 'root'), className: cn('snap-checkbox', className), ...props, children: _jsx(CheckboxPrimitive.Indicator, { ...part('checkbox', 'indicator'), className: "snap-checkbox-indicator", children: "\u2713" }) }), labelPosition === 'end' && labelNode] }));
51
+ if (description === undefined)
52
+ return row;
53
+ return (_jsxs("span", { ...part('checkbox', 'field'), className: cn('snap-checkbox-field', containerClassName), children: [row, _jsx("span", { ...part('checkbox', 'description'), className: "snap-field-help", children: description })] }));
44
54
  }
45
- /** The radio group root. */
46
- export function RadioGroup({ className, children, ...props }) {
47
- return _jsx(RadioGroupPrimitive.Root, { ...part('radio-group', 'root'), className: cn('snap-radio-group', className), ...props, children: children });
55
+ /** A labelled group of radio items. */
56
+ export function RadioGroup({ className, label, description, children, ...props }) {
57
+ const labelId = useId();
58
+ const group = (_jsx(RadioGroupPrimitive.Root, { ...part('radio-group', 'root'), className: cn('snap-radio-group', className), ...label !== undefined ? { 'aria-labelledby': labelId } : {}, ...props, children: children }));
59
+ if (label === undefined && description === undefined)
60
+ return group;
61
+ return (_jsxs("div", { ...part('radio-group', 'block'), className: "snap-radio-group-block", children: [label !== undefined && _jsx(Label, { id: labelId, ...part('radio-group', 'label'), children: label }), group, description !== undefined && _jsx("div", { ...part('radio-group', 'description'), className: "snap-field-help", children: description })] }));
48
62
  }
49
63
  /** One radio item. */
50
64
  export function RadioGroupItem({ className, ...props }) {
@@ -54,13 +68,42 @@ export function RadioGroupItem({ className, ...props }) {
54
68
  export function TouchSelect({ value, onValueChange, options, placeholder = '请选择', disabled = false, invalid = false, size = 'md', className, 'aria-label': ariaLabel, title, }) {
55
69
  const [open, setOpen] = useState(false);
56
70
  const selected = options.find(option => option.value === value);
57
- return (_jsxs(_Fragment, { children: [_jsxs(Button, { type: "button", size: size, emphasis: "outline", className: className, disabled: disabled, "aria-label": ariaLabel, "aria-invalid": invalid || undefined, "aria-haspopup": "dialog", onClick: () => setOpen(true), children: [_jsx("span", { style: { flex: 1, textAlign: 'left' }, children: selected?.label ?? placeholder }), _jsx("span", { "aria-hidden": "true", children: "\u25BE" })] }), _jsx(Dialog, { open: open, onOpenChange: setOpen, children: _jsxs(DialogContent, { presentation: "modal", size: "sm", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: title ?? ariaLabel ?? '请选择' }) }), _jsxs("div", { ...part('touch-select', 'options'), style: { display: 'flex', flexDirection: 'column', gap: 'var(--snap-space-sm)' }, children: [options.map(option => (_jsx(Button, { type: "button", size: "lg", emphasis: option.value === value ? 'solid' : 'outline', intent: option.value === value ? 'primary' : 'neutral', disabled: option.disabled === true, onClick: () => {
71
+ return (_jsxs("span", { ...part('touch-select', 'root'), className: "snap-touch-select", children: [_jsxs(Button, { type: "button", size: size, emphasis: "outline", className: className, disabled: disabled, "aria-label": ariaLabel, "aria-invalid": invalid || undefined, "aria-haspopup": "dialog", onClick: () => setOpen(true), ...part('touch-select', 'trigger'), children: [_jsx("span", { style: { flex: 1, textAlign: 'left' }, children: selected?.label ?? placeholder }), _jsx("span", { "aria-hidden": "true", children: "\u25BE" })] }), _jsx(Dialog, { open: open, onOpenChange: setOpen, children: _jsxs(DialogContent, { presentation: "modal", size: "sm", ...part('touch-select', 'sheet'), children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: title ?? ariaLabel ?? '请选择' }) }), _jsxs("div", { ...part('touch-select', 'options'), style: { display: 'flex', flexDirection: 'column', gap: 'var(--snap-space-sm)' }, children: [options.map(option => (_jsx(Button, { type: "button", size: "lg", emphasis: option.value === value ? 'solid' : 'outline', intent: option.value === value ? 'primary' : 'neutral', disabled: option.disabled === true, onClick: () => {
58
72
  onValueChange?.(option.value);
59
73
  setOpen(false);
60
- }, children: option.label }, option.value))), options.length === 0 && _jsx("span", { style: { color: 'var(--snap-color-muted)' }, children: "\u65E0\u53EF\u9009\u9879" })] })] }) })] }));
74
+ }, ...part('touch-select', 'option'), children: option.label }, option.value))), options.length === 0 && _jsx("span", { style: { color: 'var(--snap-color-muted)' }, children: "\u65E0\u53EF\u9009\u9879" })] })] }) })] }));
75
+ }
76
+ /** The select trigger; composes a {@link SelectValue} inside. */
77
+ export function SelectTrigger({ className, size = 'md', invalid = false, disabled = false, children, ...props }) {
78
+ return (_jsxs(SelectPrimitive.Trigger, { ...part('select', 'trigger'), className: cn('snap-select-trigger', className), "data-size": size, "data-invalid": invalid || undefined, "data-disabled": disabled || undefined, "aria-invalid": invalid || undefined, ...props, children: [children, _jsx(SelectPrimitive.Icon, { ...part('select', 'chevron'), className: "snap-select-chevron", children: "\u25BE" })] }));
79
+ }
80
+ /** The selected-value slot of a trigger. */
81
+ export function SelectValue(props) {
82
+ return _jsx(SelectPrimitive.Value, { ...part('select', 'value'), ...props });
83
+ }
84
+ /** The portalled option list. */
85
+ export function SelectContent({ side = 'bottom', align = 'start', sideOffset = 4, className, children, ...props }) {
86
+ return (_jsx(SelectPrimitive.Portal, { children: _jsx(SelectPrimitive.Content, { ...part('select', 'content'), className: cn('snap-select-content', className), position: "popper", side: side, align: align, sideOffset: sideOffset, ...props, children: _jsx(SelectPrimitive.Viewport, { children: children }) }) }));
87
+ }
88
+ /** One option row. */
89
+ export function SelectItem({ className, children, ...props }) {
90
+ return (_jsxs(SelectPrimitive.Item, { ...part('select', 'item'), className: cn('snap-select-item', className), ...props, children: [_jsx(SelectPrimitive.ItemText, { children: children }), _jsx(SelectPrimitive.ItemIndicator, { ...part('select', 'item-indicator'), className: "snap-select-item-indicator", children: "\u2713" })] }));
91
+ }
92
+ /** A labelled group of options. */
93
+ export function SelectGroup(props) {
94
+ return _jsx(SelectPrimitive.Group, { ...props });
95
+ }
96
+ /** A group heading. */
97
+ export function SelectLabel({ className, ...props }) {
98
+ return _jsx(SelectPrimitive.Label, { className: cn('snap-select-label', className), ...props });
61
99
  }
62
- /** A popover select. */
63
- export function Select({ value, onValueChange, options, placeholder = '请选择', disabled = false, invalid = false, size = 'md', className, 'aria-label': ariaLabel, }) {
64
- return (_jsxs(SelectPrimitive.Root, { ...value !== undefined ? { value } : {}, ...onValueChange !== undefined ? { onValueChange } : {}, disabled: disabled, children: [_jsxs(SelectPrimitive.Trigger, { ...part('select', 'trigger'), className: cn('snap-select-trigger', className), "data-size": size, "data-invalid": invalid || undefined, "data-disabled": disabled || undefined, "aria-label": ariaLabel, "aria-invalid": invalid || undefined, children: [_jsx(SelectPrimitive.Value, { ...part('select', 'value'), placeholder: placeholder }), _jsx(SelectPrimitive.Icon, { ...part('select', 'chevron'), className: "snap-select-chevron", children: "\u25BE" })] }), _jsx(SelectPrimitive.Portal, { children: _jsx(SelectPrimitive.Content, { ...part('select', 'content'), className: "snap-select-content", position: "popper", sideOffset: 4, children: _jsxs(SelectPrimitive.Viewport, { children: [options.map(option => (_jsxs(SelectPrimitive.Item, { ...part('select', 'item'), className: "snap-select-item", value: option.value, disabled: option.disabled === true, children: [_jsx(SelectPrimitive.ItemText, { children: option.label }), _jsx(SelectPrimitive.ItemIndicator, { ...part('select', 'item-indicator'), className: "snap-select-item-indicator", children: "\u2713" })] }, option.value))), options.length === 0 && _jsx("div", { ...part('select', 'empty'), className: "snap-select-empty", children: "\u65E0\u53EF\u9009\u9879" })] }) }) })] }));
100
+ /** A popover select: data-driven via `options`, or composed from
101
+ * {@link SelectItem} children for full layout control. */
102
+ export function Select({ value, defaultValue, onValueChange, options, children, placeholder = '请选择', disabled = false, invalid = false, required, name, id, size = 'md', side = 'bottom', align = 'start', sideOffset = 4, className, contentClassName, 'aria-label': ariaLabel, }) {
103
+ const composite = children !== undefined;
104
+ const empty = !composite && (options ?? []).length === 0;
105
+ return (_jsx("span", { ...part('select', 'root'), className: "snap-select", children: _jsxs(SelectPrimitive.Root, { ...value !== undefined ? { value } : {}, ...defaultValue !== undefined ? { defaultValue } : {}, ...onValueChange !== undefined ? { onValueChange } : {}, disabled: disabled, ...name !== undefined ? { name } : {}, ...required !== undefined ? { required } : {}, children: [_jsx(SelectTrigger, { id: id, size: size, invalid: invalid, disabled: disabled, className: className, "aria-label": ariaLabel, children: _jsx(SelectValue, { placeholder: placeholder }) }), _jsxs(SelectContent, { side: side, align: align, sideOffset: sideOffset, className: contentClassName, children: [composite
106
+ ? children
107
+ : (options ?? []).map(option => (_jsx(SelectItem, { value: option.value, disabled: option.disabled === true, children: option.label }, option.value))), empty && _jsx("div", { ...part('select', 'empty'), className: "snap-select-empty", children: "\u65E0\u53EF\u9009\u9879" })] })] }) }));
65
108
  }
66
109
  //# sourceMappingURL=controls.js.map
@@ -6,12 +6,12 @@
6
6
  * @module @snap-rail/ui/components/dialog
7
7
  */
8
8
  import * as DialogPrimitive from '@radix-ui/react-dialog';
9
- import type { ReactNode } from 'react';
9
+ import type { HTMLAttributes, ReactNode } from 'react';
10
10
  /** The presentation variants the core implements for overlays. */
11
11
  export type DialogPresentation = 'modal' | 'sheet' | 'fullscreen';
12
- /** Props of {@link DialogContent}. */
13
- export interface DialogContentProps {
14
- children?: ReactNode;
12
+ /** Props of {@link DialogContent}. Panel-level attributes (drag handlers,
13
+ * `aria-describedby`, tests hooks) ride through to the dialog panel. */
14
+ export interface DialogContentProps extends HTMLAttributes<HTMLDivElement> {
15
15
  className?: string;
16
16
  /** `auto` currently resolves to the skin default; explicit values win. */
17
17
  presentation?: DialogPresentation | 'auto';
@@ -25,7 +25,7 @@ export declare const DialogTrigger: import("react").ForwardRefExoticComponent<Di
25
25
  /** The dialog close. */
26
26
  export declare const DialogClose: import("react").ForwardRefExoticComponent<DialogPrimitive.DialogCloseProps & import("react").RefAttributes<HTMLButtonElement>>;
27
27
  /** The portalled dialog content. */
28
- export declare function DialogContent({ children, className, presentation, size, showClose, }: DialogContentProps): ReactNode;
28
+ export declare function DialogContent({ children, className, presentation, size, showClose, ...rest }: DialogContentProps): ReactNode;
29
29
  /** The dialog header. */
30
30
  export declare function DialogHeader({ children, className }: {
31
31
  children?: ReactNode;
@@ -15,9 +15,9 @@ export const DialogTrigger = DialogPrimitive.Trigger;
15
15
  /** The dialog close. */
16
16
  export const DialogClose = DialogPrimitive.Close;
17
17
  /** The portalled dialog content. */
18
- export function DialogContent({ children, className, presentation = 'auto', size = 'md', showClose = true, }) {
18
+ export function DialogContent({ children, className, presentation = 'auto', size = 'md', showClose = true, ...rest }) {
19
19
  const resolved = presentation === 'auto' ? 'modal' : presentation;
20
- return (_jsxs(DialogPrimitive.Portal, { children: [_jsx(DialogPrimitive.Overlay, { ...part('dialog', 'overlay'), className: "snap-dialog-overlay" }), _jsxs(DialogPrimitive.Content, { ...part('dialog', 'panel'), className: cn('snap-dialog-panel', className), "data-presentation": resolved, "data-size": size, children: [children, showClose && (_jsx(DialogPrimitive.Close, { ...part('dialog', 'close'), className: "snap-dialog-close", "aria-label": "\u5173\u95ED", children: "\u00D7" }))] })] }));
20
+ return (_jsxs(DialogPrimitive.Portal, { children: [_jsx(DialogPrimitive.Overlay, { ...part('dialog', 'overlay'), className: "snap-dialog-overlay" }), _jsxs(DialogPrimitive.Content, { ...part('dialog', 'panel'), className: cn('snap-dialog-panel', className), "data-presentation": resolved, "data-size": size, ...rest, children: [children, showClose && (_jsx(DialogPrimitive.Close, { ...part('dialog', 'close'), className: "snap-dialog-close", "aria-label": "\u5173\u95ED", children: "\u00D7" }))] })] }));
21
21
  }
22
22
  /** The dialog header. */
23
23
  export function DialogHeader({ children, className }) {
@@ -0,0 +1,56 @@
1
+ /**
2
+ * React Hook Form integration in the shadcn composite shape: `FormField`
3
+ * binds a controller, `FormItem`/`FormLabel`/`FormControl`/
4
+ * `FormDescription`/`FormMessage` render the same `field.*` anatomy the plain
5
+ * {@link Field} uses, driven by the form state. The RHF hooks and
6
+ * `zodResolver` are re-exported so plugin bundles consume the seed's single
7
+ * module instance — RHF context is module-scoped, and a copy bundled inside a
8
+ * plugin zip would never see the form state.
9
+ *
10
+ * @module @snap-rail/ui/components/form-rhf
11
+ */
12
+ import { type ControllerProps, type FieldPath, type FieldValues } from 'react-hook-form';
13
+ import { type ReactNode } from 'react';
14
+ import type { FieldOrientation } from './form.tsx';
15
+ export { Controller, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch, } from 'react-hook-form';
16
+ export type { Control, DefaultValues, FieldError, FieldPath, FieldValues, Path, PathValue, Resolver, SubmitErrorHandler, SubmitHandler, UseFormReturn, } from 'react-hook-form';
17
+ export { zodResolver } from '@hookform/resolvers/zod';
18
+ /** Props of {@link FormField}. */
19
+ export interface FormFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends Omit<ControllerProps<TFieldValues, TName>, 'render'> {
20
+ render: ControllerProps<TFieldValues, TName>['render'];
21
+ }
22
+ /** Bind a controller and expose its name to the anatomy parts inside. */
23
+ export declare function FormField<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(props: FormFieldProps<TFieldValues, TName>): ReactNode;
24
+ /** Props of {@link FormItem}. */
25
+ export interface FormItemProps {
26
+ children?: ReactNode;
27
+ className?: string;
28
+ /** Place the label beside the control (default `vertical`, label on top). */
29
+ orientation?: FieldOrientation;
30
+ }
31
+ /** The field row: owns the shared id every aria attribute anchors to. */
32
+ export declare function FormItem({ children, className, orientation }: FormItemProps): ReactNode;
33
+ /** The field label; carries `data-invalid` when the field has an error. */
34
+ export declare function FormLabel({ className, children }: {
35
+ className?: string;
36
+ children?: ReactNode;
37
+ }): ReactNode;
38
+ /** Merges the field binding onto the single control child it wraps. */
39
+ export declare function FormControl({ children }: {
40
+ children: ReactNode;
41
+ }): ReactNode;
42
+ /** Helper text under the control; linked as `aria-describedby`. */
43
+ export declare function FormDescription({ className, children }: {
44
+ className?: string;
45
+ children?: ReactNode;
46
+ }): ReactNode;
47
+ /** Props of {@link FormMessage}. */
48
+ export interface FormMessageProps {
49
+ /** Overrides the error text from the form state. */
50
+ message?: ReactNode;
51
+ children?: ReactNode;
52
+ className?: string;
53
+ }
54
+ /** The validation message for the bound field. */
55
+ export declare function FormMessage({ message, children, className }: FormMessageProps): ReactNode;
56
+ //# sourceMappingURL=form-rhf.d.ts.map
@@ -0,0 +1,74 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * React Hook Form integration in the shadcn composite shape: `FormField`
4
+ * binds a controller, `FormItem`/`FormLabel`/`FormControl`/
5
+ * `FormDescription`/`FormMessage` render the same `field.*` anatomy the plain
6
+ * {@link Field} uses, driven by the form state. The RHF hooks and
7
+ * `zodResolver` are re-exported so plugin bundles consume the seed's single
8
+ * module instance — RHF context is module-scoped, and a copy bundled inside a
9
+ * plugin zip would never see the form state.
10
+ *
11
+ * @module @snap-rail/ui/components/form-rhf
12
+ */
13
+ import { Slot } from '@radix-ui/react-slot';
14
+ import { Controller, useFormState } from 'react-hook-form';
15
+ import { createContext, useContext, useId } from 'react';
16
+ import { cn, part } from "../utils.js";
17
+ import { Label } from "./controls.js";
18
+ export { Controller, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch, } from 'react-hook-form';
19
+ export { zodResolver } from '@hookform/resolvers/zod';
20
+ const FormFieldContext = createContext(null);
21
+ const FormItemContext = createContext(null);
22
+ /** Read the enclosing field binding; fails loud outside a {@link FormField}. */
23
+ function useFormField() {
24
+ const field = useContext(FormFieldContext);
25
+ const item = useContext(FormItemContext);
26
+ if (field === null || item === null)
27
+ throw new Error('表单字段部件必须渲染在 FormField 内');
28
+ return { id: item.id, name: field.name };
29
+ }
30
+ /** Bind a controller and expose its name to the anatomy parts inside. */
31
+ export function FormField(props) {
32
+ const name = props.name;
33
+ return (_jsx(FormFieldContext.Provider, { value: { name }, children: _jsx(Controller, { ...props, name: name, render: props.render }) }));
34
+ }
35
+ /** The field row: owns the shared id every aria attribute anchors to. */
36
+ export function FormItem({ children, className, orientation = 'vertical' }) {
37
+ const id = useId();
38
+ return (_jsx(FormItemContext.Provider, { value: { id }, children: _jsx("div", { ...part('field', 'root'), className: cn('snap-field', className), "data-orientation": orientation, children: children }) }));
39
+ }
40
+ /** The field label; carries `data-invalid` when the field has an error. */
41
+ export function FormLabel({ className, children }) {
42
+ const { id, name } = useFormField();
43
+ const formState = useFormState({ name });
44
+ const invalid = formState.errors[name] !== undefined;
45
+ return (_jsx(Label, { htmlFor: id, ...part('field', 'label'), className: cn('snap-form-label', className), "data-invalid": invalid || undefined, children: children }));
46
+ }
47
+ /** Merges the field binding onto the single control child it wraps. */
48
+ export function FormControl({ children }) {
49
+ const { id, name } = useFormField();
50
+ const formState = useFormState({ name });
51
+ const invalid = formState.errors[name] !== undefined;
52
+ return (_jsx(Slot, { id: id, "aria-invalid": invalid || undefined, "aria-describedby": `${id}-description ${id}-message`, children: children }));
53
+ }
54
+ /** Helper text under the control; linked as `aria-describedby`. */
55
+ export function FormDescription({ className, children }) {
56
+ const { id } = useFormField();
57
+ return (_jsx("div", { ...part('field', 'help'), id: `${id}-description`, className: cn('snap-field-help', className), children: children }));
58
+ }
59
+ /** The validation message for the bound field. */
60
+ export function FormMessage({ message, children, className }) {
61
+ const { id, name } = useFormField();
62
+ const formState = useFormState({ name });
63
+ const error = formState.errors[name];
64
+ // A nested field's error carries a FieldError tree, not renderable text —
65
+ // fall back to `children` in that case.
66
+ const raw = error?.message;
67
+ const body = message
68
+ ?? (typeof raw === 'string' || typeof raw === 'number' || typeof raw === 'bigint' || typeof raw === 'boolean' ? String(raw) : undefined)
69
+ ?? children;
70
+ if (body === undefined || body === '')
71
+ return null;
72
+ return (_jsx("div", { ...part('field', 'error'), id: `${id}-message`, className: cn('snap-field-error', className), role: "alert", children: body }));
73
+ }
74
+ //# sourceMappingURL=form-rhf.js.map
@@ -1,11 +1,15 @@
1
1
  /**
2
2
  * Form semantics: a field owns its label/control/help/error anatomy; a form
3
3
  * owns its fields/actions regions. Validation stays with the page (or a
4
- * schema renderer); the parts carry `data-invalid` for the skin.
4
+ * schema renderer); the parts carry `data-invalid` for the skin. React Hook
5
+ * Form wiring lives in `./form-rhf.tsx`.
5
6
  *
6
7
  * @module @snap-rail/ui/components/form
7
8
  */
8
- import type { FormEvent, ReactNode } from 'react';
9
+ import type { CSSProperties, FormEvent, ReactNode } from 'react';
10
+ import { type FieldValues, type SubmitErrorHandler, type SubmitHandler, type UseFormReturn } from 'react-hook-form';
11
+ /** Which side of the control the label and its message column occupy. */
12
+ export type FieldOrientation = 'vertical' | 'horizontal';
9
13
  /** Props of {@link Field}. */
10
14
  export interface FieldProps {
11
15
  label?: ReactNode;
@@ -14,18 +18,42 @@ export interface FieldProps {
14
18
  error?: ReactNode;
15
19
  invalid?: boolean;
16
20
  required?: boolean;
21
+ /** Place the label beside the control (default `vertical`, label on top). */
22
+ orientation?: FieldOrientation;
23
+ /** In horizontal orientation, the label column's width (px or any CSS width). */
24
+ labelWidth?: number | string;
25
+ /** In horizontal orientation, the label's text alignment (default `start`). */
26
+ labelAlign?: 'start' | 'end';
17
27
  children: ReactNode;
18
28
  className?: string;
29
+ style?: CSSProperties;
19
30
  }
20
31
  /** A labelled form row. */
21
- export declare function Field({ label, htmlFor, help, error, invalid, required, children, className, }: FieldProps): ReactNode;
32
+ export declare function Field({ label, htmlFor, help, error, invalid, required, orientation, labelWidth, labelAlign, children, className, style, }: FieldProps): ReactNode;
33
+ /** How a {@link Form} lays out its fields region. */
34
+ export type FormOrientation = 'stack' | 'inline' | 'grid';
22
35
  /** Props of {@link Form}. */
23
- export interface FormProps {
36
+ export interface FormProps<TFieldValues extends FieldValues = FieldValues> {
24
37
  children?: ReactNode;
25
38
  actions?: ReactNode;
26
39
  onSubmit?: (event: FormEvent<HTMLFormElement>) => void;
27
40
  className?: string;
41
+ /** `stack` (default) flows fields vertically; `inline` wraps them in a row
42
+ * with the actions inlined at the end; `grid` arranges them in `columns`. */
43
+ orientation?: FormOrientation;
44
+ /** The gap token between fields (default `md`). */
45
+ gap?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
46
+ /** In `grid` orientation, the column count (default 2). */
47
+ columns?: number;
48
+ /** Provide a React Hook Form instance to publish its context (so
49
+ * `FormField` and friends work) and wire submission through
50
+ * `form.handleSubmit`. */
51
+ form?: UseFormReturn<TFieldValues>;
52
+ /** With `form`, called with the validated values on submit. */
53
+ onValid?: SubmitHandler<TFieldValues>;
54
+ /** With `form`, called with the validation errors when submit fails. */
55
+ onInvalid?: SubmitErrorHandler<TFieldValues>;
28
56
  }
29
57
  /** A form with a fields region and an actions region. */
30
- export declare function Form({ children, actions, onSubmit, className }: FormProps): ReactNode;
58
+ export declare function Form<TFieldValues extends FieldValues = FieldValues>({ children, actions, onSubmit, className, orientation, gap, columns, form, onValid, onInvalid, }: FormProps<TFieldValues>): ReactNode;
31
59
  //# sourceMappingURL=form.d.ts.map
@@ -1,13 +1,29 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { cn, part } from "../utils.js";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { FormProvider } from 'react-hook-form';
3
+ import { cn, part, space } from "../utils.js";
3
4
  import { Label } from "./controls.js";
4
5
  /** A labelled form row. */
5
- export function Field({ label, htmlFor, help, error, invalid = false, required = false, children, className, }) {
6
+ export function Field({ label, htmlFor, help, error, invalid = false, required = false, orientation = 'vertical', labelWidth, labelAlign = 'start', children, className, style, }) {
6
7
  const bad = invalid || error !== undefined;
7
- return (_jsxs("div", { ...part('field', 'root'), className: cn('snap-field', className), "data-invalid": bad || undefined, "data-required": required || undefined, children: [label !== undefined && (_jsxs(Label, { ...htmlFor !== undefined ? { htmlFor } : {}, ...part('field', 'label'), children: [label, required && _jsx("span", { "aria-hidden": "true", children: " *" })] })), _jsx("div", { ...part('field', 'control'), children: children }), help !== undefined && error === undefined && _jsx("div", { ...part('field', 'help'), className: "snap-field-help", children: help }), error !== undefined && _jsx("div", { ...part('field', 'error'), className: "snap-field-error", role: "alert", children: error })] }));
8
+ return (_jsxs("div", { ...part('field', 'root'), className: cn('snap-field', className), "data-invalid": bad || undefined, "data-required": required || undefined, "data-orientation": orientation, style: style, children: [label !== undefined && (_jsxs(Label, { ...htmlFor !== undefined ? { htmlFor } : {}, ...part('field', 'label'), style: {
9
+ ...labelWidth !== undefined ? { width: typeof labelWidth === 'number' ? `${labelWidth}px` : labelWidth, flexShrink: 0 } : {},
10
+ ...labelAlign !== 'start' ? { textAlign: labelAlign } : {},
11
+ }, children: [label, required && _jsx("span", { "aria-hidden": "true", children: " *" })] })), _jsx("div", { ...part('field', 'control'), children: children }), help !== undefined && error === undefined && _jsx("div", { ...part('field', 'help'), className: "snap-field-help", children: help }), error !== undefined && _jsx("div", { ...part('field', 'error'), className: "snap-field-error", role: "alert", children: error })] }));
8
12
  }
9
13
  /** A form with a fields region and an actions region. */
10
- export function Form({ children, actions, onSubmit, className }) {
11
- return (_jsxs("form", { ...part('form', 'root'), className: cn('snap-form', className), onSubmit: onSubmit, children: [_jsx("div", { ...part('form', 'fields'), className: "snap-form-fields", children: children }), actions !== undefined && _jsx("div", { ...part('form', 'actions'), className: "snap-form-actions", children: actions })] }));
14
+ export function Form({ children, actions, onSubmit, className, orientation = 'stack', gap = 'md', columns = 2, form, onValid, onInvalid, }) {
15
+ const fieldsStyle = orientation === 'grid'
16
+ ? { display: 'grid', gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`, gap: space(gap) }
17
+ : orientation === 'inline'
18
+ ? { display: 'flex', flexDirection: 'row', flexWrap: 'wrap', gap: space(gap) }
19
+ : { display: 'flex', flexDirection: 'column', gap: space(gap) };
20
+ const body = (_jsxs(_Fragment, { children: [_jsx("div", { ...part('form', 'fields'), className: "snap-form-fields", style: fieldsStyle, children: children }), actions !== undefined && _jsx("div", { ...part('form', 'actions'), className: "snap-form-actions", children: actions })] }));
21
+ const submit = form !== undefined && onValid !== undefined
22
+ ? form.handleSubmit(onValid, onInvalid)
23
+ : onSubmit;
24
+ if (form === undefined) {
25
+ return (_jsx("form", { ...part('form', 'root'), className: cn('snap-form', className), "data-orientation": orientation, onSubmit: submit, children: body }));
26
+ }
27
+ return (_jsx(FormProvider, { ...form, children: _jsx("form", { ...part('form', 'root'), className: cn('snap-form', className), "data-orientation": orientation, onSubmit: submit, children: body }) }));
12
28
  }
13
29
  //# sourceMappingURL=form.js.map
@@ -1,15 +1,22 @@
1
1
  /**
2
2
  * The semantic component set. Pages import from here; skins style the parts.
3
+ * The anatomy helpers (`part`/`cn`/`space`) ride along so extension authors
4
+ * can tag their own components for skin coverage.
3
5
  *
4
6
  * @module @snap-rail/ui/components
5
7
  */
8
+ export * from '../utils.ts';
9
+ export * from './alert.tsx';
6
10
  export * from './button.tsx';
7
11
  export * from './controls.tsx';
8
12
  export * from './dialog.tsx';
9
13
  export * from './feedback.tsx';
10
14
  export * from './form.tsx';
15
+ export * from './form-rhf.tsx';
11
16
  export * from './input.tsx';
12
17
  export * from './layout.tsx';
18
+ export * from './overlay.tsx';
13
19
  export * from './schema-form.tsx';
20
+ export * from './slider.tsx';
14
21
  export * from './surface.tsx';
15
22
  //# sourceMappingURL=index.d.ts.map
@@ -1,15 +1,22 @@
1
1
  /**
2
2
  * The semantic component set. Pages import from here; skins style the parts.
3
+ * The anatomy helpers (`part`/`cn`/`space`) ride along so extension authors
4
+ * can tag their own components for skin coverage.
3
5
  *
4
6
  * @module @snap-rail/ui/components
5
7
  */
8
+ export * from "../utils.js";
9
+ export * from "./alert.js";
6
10
  export * from "./button.js";
7
11
  export * from "./controls.js";
8
12
  export * from "./dialog.js";
9
13
  export * from "./feedback.js";
10
14
  export * from "./form.js";
15
+ export * from "./form-rhf.js";
11
16
  export * from "./input.js";
12
17
  export * from "./layout.js";
18
+ export * from "./overlay.js";
13
19
  export * from "./schema-form.js";
20
+ export * from "./slider.js";
14
21
  export * from "./surface.js";
15
22
  //# sourceMappingURL=index.js.map