@gemologic/sheen 0.1.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/README.md +32 -0
- package/dist/core.d.ts +52 -0
- package/dist/core.js +29 -0
- package/dist/formisch.d.ts +5 -0
- package/dist/formisch.js +22 -0
- package/dist/forms.d.ts +34 -0
- package/dist/forms.js +18 -0
- package/dist/index.d.ts +144 -0
- package/dist/index.js +75 -0
- package/dist/layout/Layout.d.ts +28 -0
- package/dist/layout/Layout.js +121 -0
- package/dist/metadata.d.ts +46 -0
- package/dist/metadata.js +47 -0
- package/dist/navigation.d.ts +30 -0
- package/dist/navigation.js +16 -0
- package/dist/overlays.d.ts +28 -0
- package/dist/overlays.js +15 -0
- package/dist/primitives/Accordion.d.ts +16 -0
- package/dist/primitives/Accordion.js +223 -0
- package/dist/primitives/ActivityTimeline.d.ts +20 -0
- package/dist/primitives/ActivityTimeline.js +104 -0
- package/dist/primitives/AlertDialog.d.ts +7 -0
- package/dist/primitives/AlertDialog.js +8 -0
- package/dist/primitives/Avatar.d.ts +22 -0
- package/dist/primitives/Avatar.js +115 -0
- package/dist/primitives/Breadcrumb.d.ts +11 -0
- package/dist/primitives/Breadcrumb.js +66 -0
- package/dist/primitives/Button.d.ts +11 -0
- package/dist/primitives/Button.js +59 -0
- package/dist/primitives/ButtonGroup.d.ts +7 -0
- package/dist/primitives/ButtonGroup.js +33 -0
- package/dist/primitives/Checkbox.d.ts +22 -0
- package/dist/primitives/Checkbox.js +93 -0
- package/dist/primitives/CheckboxGroup.d.ts +18 -0
- package/dist/primitives/CheckboxGroup.js +122 -0
- package/dist/primitives/Collapsible.d.ts +9 -0
- package/dist/primitives/Collapsible.js +72 -0
- package/dist/primitives/Combobox.d.ts +41 -0
- package/dist/primitives/Combobox.js +684 -0
- package/dist/primitives/CommandPalette.d.ts +42 -0
- package/dist/primitives/CommandPalette.js +319 -0
- package/dist/primitives/ConfirmDialog.d.ts +11 -0
- package/dist/primitives/ConfirmDialog.js +42 -0
- package/dist/primitives/ContextMenu.d.ts +16 -0
- package/dist/primitives/ContextMenu.js +132 -0
- package/dist/primitives/DescriptionList.d.ts +11 -0
- package/dist/primitives/DescriptionList.js +44 -0
- package/dist/primitives/Dialog.d.ts +21 -0
- package/dist/primitives/Dialog.js +141 -0
- package/dist/primitives/Drawer.d.ts +9 -0
- package/dist/primitives/Drawer.js +21 -0
- package/dist/primitives/DropdownMenu.d.ts +59 -0
- package/dist/primitives/DropdownMenu.js +441 -0
- package/dist/primitives/EditableTextField.d.ts +11 -0
- package/dist/primitives/EditableTextField.js +126 -0
- package/dist/primitives/EmptyState.d.ts +7 -0
- package/dist/primitives/EmptyState.js +45 -0
- package/dist/primitives/Field.d.ts +18 -0
- package/dist/primitives/Field.js +72 -0
- package/dist/primitives/FileDropzone.d.ts +40 -0
- package/dist/primitives/FileDropzone.js +261 -0
- package/dist/primitives/IconButton.d.ts +8 -0
- package/dist/primitives/IconButton.js +34 -0
- package/dist/primitives/Input.d.ts +7 -0
- package/dist/primitives/Input.js +55 -0
- package/dist/primitives/InputGroup.d.ts +7 -0
- package/dist/primitives/InputGroup.js +73 -0
- package/dist/primitives/Link.d.ts +7 -0
- package/dist/primitives/Link.js +35 -0
- package/dist/primitives/LinkTooltip.d.ts +11 -0
- package/dist/primitives/LinkTooltip.js +88 -0
- package/dist/primitives/NavList.d.ts +17 -0
- package/dist/primitives/NavList.js +143 -0
- package/dist/primitives/Notice.d.ts +8 -0
- package/dist/primitives/Notice.js +64 -0
- package/dist/primitives/NumberField.d.ts +22 -0
- package/dist/primitives/NumberField.js +177 -0
- package/dist/primitives/Pagination.d.ts +12 -0
- package/dist/primitives/Pagination.js +127 -0
- package/dist/primitives/Popover.d.ts +12 -0
- package/dist/primitives/Popover.js +103 -0
- package/dist/primitives/Progress.d.ts +17 -0
- package/dist/primitives/Progress.js +98 -0
- package/dist/primitives/RadioGroup.d.ts +19 -0
- package/dist/primitives/RadioGroup.js +173 -0
- package/dist/primitives/Resizable.d.ts +36 -0
- package/dist/primitives/Resizable.js +196 -0
- package/dist/primitives/ScrollArea.d.ts +6 -0
- package/dist/primitives/ScrollArea.js +178 -0
- package/dist/primitives/SearchInput.d.ts +12 -0
- package/dist/primitives/SearchInput.js +89 -0
- package/dist/primitives/SegmentedControl.d.ts +25 -0
- package/dist/primitives/SegmentedControl.js +188 -0
- package/dist/primitives/Select.d.ts +24 -0
- package/dist/primitives/Select.js +320 -0
- package/dist/primitives/Separator.d.ts +6 -0
- package/dist/primitives/Separator.js +31 -0
- package/dist/primitives/ShortcutPending.d.ts +6 -0
- package/dist/primitives/ShortcutPending.js +40 -0
- package/dist/primitives/ShortcutProvider.d.ts +32 -0
- package/dist/primitives/ShortcutProvider.js +172 -0
- package/dist/primitives/ShortcutScope.d.ts +6 -0
- package/dist/primitives/ShortcutScope.js +29 -0
- package/dist/primitives/ShortcutSheet.d.ts +5 -0
- package/dist/primitives/ShortcutSheet.js +87 -0
- package/dist/primitives/Skeleton.d.ts +5 -0
- package/dist/primitives/Skeleton.js +23 -0
- package/dist/primitives/Slider.d.ts +35 -0
- package/dist/primitives/Slider.js +210 -0
- package/dist/primitives/Spinner.d.ts +7 -0
- package/dist/primitives/Spinner.js +44 -0
- package/dist/primitives/Status.d.ts +15 -0
- package/dist/primitives/Status.js +78 -0
- package/dist/primitives/Stepper.d.ts +32 -0
- package/dist/primitives/Stepper.js +147 -0
- package/dist/primitives/Surface.d.ts +11 -0
- package/dist/primitives/Surface.js +58 -0
- package/dist/primitives/Switch.d.ts +4 -0
- package/dist/primitives/Switch.js +7 -0
- package/dist/primitives/Table.d.ts +23 -0
- package/dist/primitives/Table.js +101 -0
- package/dist/primitives/Tabs.d.ts +17 -0
- package/dist/primitives/Tabs.js +157 -0
- package/dist/primitives/TagInput.d.ts +33 -0
- package/dist/primitives/TagInput.js +288 -0
- package/dist/primitives/Textarea.d.ts +8 -0
- package/dist/primitives/Textarea.js +106 -0
- package/dist/primitives/Toast.d.ts +10 -0
- package/dist/primitives/Toast.js +78 -0
- package/dist/primitives/Toaster.d.ts +9 -0
- package/dist/primitives/Toaster.js +183 -0
- package/dist/primitives/Tooltip.d.ts +13 -0
- package/dist/primitives/Tooltip.js +84 -0
- package/dist/primitives/Tree.d.ts +23 -0
- package/dist/primitives/Tree.js +275 -0
- package/dist/primitives/Typography.d.ts +16 -0
- package/dist/primitives/Typography.js +82 -0
- package/dist/primitives/boolean-input-state.d.ts +14 -0
- package/dist/primitives/boolean-input-state.js +39 -0
- package/dist/primitives/button-variants.d.ts +9 -0
- package/dist/primitives/button-variants.js +7 -0
- package/dist/primitives/choice-options.d.ts +7 -0
- package/dist/primitives/choice-options.js +35 -0
- package/dist/primitives/create-confirm.d.ts +15 -0
- package/dist/primitives/create-confirm.js +49 -0
- package/dist/primitives/create-toaster.d.ts +51 -0
- package/dist/primitives/create-toaster.js +87 -0
- package/dist/primitives/link-focus.d.ts +2 -0
- package/dist/primitives/link-focus.js +38 -0
- package/dist/primitives/menu-focus.d.ts +3 -0
- package/dist/primitives/menu-focus.js +32 -0
- package/dist/primitives/tooltip-layer.d.ts +14 -0
- package/dist/primitives/tooltip-layer.js +84 -0
- package/dist/theme/ThemeProvider.d.ts +59 -0
- package/dist/theme/ThemeProvider.js +239 -0
- package/dist/theme/intl.d.ts +6 -0
- package/dist/theme/intl.js +13 -0
- package/dist/theme/keyboard-script.d.ts +2 -0
- package/dist/theme/keyboard-script.js +6 -0
- package/dist/theme/layers.d.ts +7 -0
- package/dist/theme/layers.js +23 -0
- package/dist/theme/messages.d.ts +235 -0
- package/dist/theme/messages.js +115 -0
- package/dist/theme/script.d.ts +9 -0
- package/dist/theme/script.js +49 -0
- package/dist/theme/state.d.ts +27 -0
- package/dist/theme/state.js +55 -0
- package/dist/utils/browser-status.d.ts +5 -0
- package/dist/utils/browser-status.js +22 -0
- package/dist/utils/cn.d.ts +3 -0
- package/dist/utils/cn.js +7 -0
- package/dist/utils/optimistic.d.ts +6 -0
- package/dist/utils/optimistic.js +16 -0
- package/dist/utils/polymorphic.d.ts +1 -0
- package/dist/utils/shortcut-platform.d.ts +2 -0
- package/dist/utils/shortcut-platform.js +10 -0
- package/dist/utils/shortcut-registry.d.ts +61 -0
- package/dist/utils/shortcut-registry.js +186 -0
- package/package.json +100 -0
- package/src/core.ts +55 -0
- package/src/formisch.ts +28 -0
- package/src/forms.ts +34 -0
- package/src/index.ts +144 -0
- package/src/layout/Layout.tsx +43 -0
- package/src/metadata.d.ts +46 -0
- package/src/metadata.ts +66 -0
- package/src/navigation.ts +30 -0
- package/src/overlays.ts +28 -0
- package/src/primitives/Accordion.tsx +145 -0
- package/src/primitives/ActivityTimeline.tsx +72 -0
- package/src/primitives/AlertDialog.tsx +8 -0
- package/src/primitives/Avatar.tsx +85 -0
- package/src/primitives/Breadcrumb.tsx +41 -0
- package/src/primitives/Button.tsx +27 -0
- package/src/primitives/ButtonGroup.tsx +18 -0
- package/src/primitives/Checkbox.tsx +51 -0
- package/src/primitives/CheckboxGroup.tsx +73 -0
- package/src/primitives/Collapsible.tsx +43 -0
- package/src/primitives/Combobox.tsx +402 -0
- package/src/primitives/CommandPalette.tsx +234 -0
- package/src/primitives/ConfirmDialog.tsx +25 -0
- package/src/primitives/ContextMenu.tsx +100 -0
- package/src/primitives/DescriptionList.tsx +26 -0
- package/src/primitives/Dialog.tsx +81 -0
- package/src/primitives/Drawer.tsx +26 -0
- package/src/primitives/DropdownMenu.tsx +221 -0
- package/src/primitives/EditableTextField.tsx +91 -0
- package/src/primitives/EmptyState.tsx +21 -0
- package/src/primitives/Field.tsx +38 -0
- package/src/primitives/FileDropzone.tsx +189 -0
- package/src/primitives/IconButton.tsx +22 -0
- package/src/primitives/Input.tsx +17 -0
- package/src/primitives/InputGroup.tsx +23 -0
- package/src/primitives/Link.tsx +19 -0
- package/src/primitives/LinkTooltip.tsx +31 -0
- package/src/primitives/NavList.tsx +58 -0
- package/src/primitives/Notice.tsx +25 -0
- package/src/primitives/NumberField.tsx +168 -0
- package/src/primitives/Pagination.tsx +64 -0
- package/src/primitives/Popover.tsx +44 -0
- package/src/primitives/Progress.tsx +62 -0
- package/src/primitives/RadioGroup.tsx +104 -0
- package/src/primitives/Resizable.tsx +170 -0
- package/src/primitives/ScrollArea.tsx +115 -0
- package/src/primitives/SearchInput.tsx +98 -0
- package/src/primitives/SegmentedControl.tsx +140 -0
- package/src/primitives/Select.tsx +171 -0
- package/src/primitives/Separator.tsx +13 -0
- package/src/primitives/ShortcutPending.tsx +21 -0
- package/src/primitives/ShortcutProvider.tsx +179 -0
- package/src/primitives/ShortcutScope.tsx +17 -0
- package/src/primitives/ShortcutSheet.tsx +35 -0
- package/src/primitives/Skeleton.tsx +12 -0
- package/src/primitives/Slider.tsx +153 -0
- package/src/primitives/Spinner.tsx +19 -0
- package/src/primitives/Status.tsx +33 -0
- package/src/primitives/Stepper.tsx +106 -0
- package/src/primitives/Surface.tsx +21 -0
- package/src/primitives/Switch.tsx +9 -0
- package/src/primitives/Table.tsx +57 -0
- package/src/primitives/Tabs.tsx +96 -0
- package/src/primitives/TagInput.tsx +282 -0
- package/src/primitives/Textarea.tsx +77 -0
- package/src/primitives/Toast.tsx +36 -0
- package/src/primitives/Toaster.tsx +175 -0
- package/src/primitives/Tooltip.tsx +41 -0
- package/src/primitives/Tree.tsx +256 -0
- package/src/primitives/Typography.tsx +39 -0
- package/src/primitives/boolean-input-state.ts +65 -0
- package/src/primitives/button-variants.ts +20 -0
- package/src/primitives/choice-options.ts +39 -0
- package/src/primitives/create-confirm.tsx +56 -0
- package/src/primitives/create-toaster.ts +128 -0
- package/src/primitives/link-focus.ts +38 -0
- package/src/primitives/menu-focus.ts +43 -0
- package/src/primitives/tooltip-layer.tsx +53 -0
- package/src/styles.css +655 -0
- package/src/theme/ThemeProvider.tsx +215 -0
- package/src/theme/intl.ts +14 -0
- package/src/theme/keyboard-script.ts +4 -0
- package/src/theme/layers.ts +16 -0
- package/src/theme/messages.ts +157 -0
- package/src/theme/script.ts +70 -0
- package/src/theme/state.ts +48 -0
- package/src/utils/browser-status.ts +36 -0
- package/src/utils/cn.ts +5 -0
- package/src/utils/optimistic.ts +22 -0
- package/src/utils/polymorphic.ts +1 -0
- package/src/utils/shortcut-platform.ts +4 -0
- package/src/utils/shortcut-registry.ts +216 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Show, splitProps } from "solid-js";
|
|
2
|
+
import type { JSX } from "solid-js";
|
|
3
|
+
import { cn } from "../utils/cn.ts";
|
|
4
|
+
import { Button } from "./Button.tsx";
|
|
5
|
+
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
6
|
+
|
|
7
|
+
export type StatusTone = "neutral" | "accent" | "info" | "success" | "warning" | "danger" | "market-up" | "market-down" | "market-flat";
|
|
8
|
+
export interface BadgeProps extends JSX.HTMLAttributes<HTMLSpanElement> {
|
|
9
|
+
tone?: StatusTone;
|
|
10
|
+
variant?: "soft" | "solid" | "outline";
|
|
11
|
+
size?: "sm" | "md";
|
|
12
|
+
}
|
|
13
|
+
export function Badge(props: BadgeProps): JSX.Element {
|
|
14
|
+
const [local, others] = splitProps(props, ["class", "tone", "variant", "size"]);
|
|
15
|
+
return <span {...others} class={cn("sheen-badge", local.class)} data-tone={local.tone ?? "neutral"} data-variant={local.variant ?? "soft"} data-size={local.size ?? "sm"} />;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface TagProps extends BadgeProps {
|
|
19
|
+
label: string;
|
|
20
|
+
onRemove?: () => void;
|
|
21
|
+
removeLabel?: string;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export function Tag(props: TagProps): JSX.Element {
|
|
25
|
+
const theme = useTheme();
|
|
26
|
+
const [local, others] = splitProps(props, ["class", "label", "children", "onRemove", "removeLabel", "disabled"]);
|
|
27
|
+
return <Badge {...others} class={cn("sheen-tag", local.class)} data-disabled={local.disabled || undefined}>
|
|
28
|
+
<span>{local.children ?? local.label}</span>
|
|
29
|
+
<Show when={local.onRemove}>
|
|
30
|
+
<Button class="sheen-tag-remove" size="xs" disabled={local.disabled} aria-label={local.removeLabel ?? `${theme.messages().remove} ${local.label}`} onClick={() => local.onRemove?.()}>{theme.messages().remove}</Button>
|
|
31
|
+
</Show>
|
|
32
|
+
</Badge>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { For, Show, createMemo, splitProps } from "solid-js";
|
|
2
|
+
import type { Accessor, JSX } from "solid-js";
|
|
3
|
+
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
4
|
+
import { cn } from "../utils/cn.ts";
|
|
5
|
+
import { Button } from "./Button.tsx";
|
|
6
|
+
import { Link } from "./Link.tsx";
|
|
7
|
+
import type { WorkflowState } from "./ActivityTimeline.tsx";
|
|
8
|
+
|
|
9
|
+
interface StepperStepBase {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly label: string;
|
|
12
|
+
readonly description?: string;
|
|
13
|
+
readonly state: WorkflowState;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface StepperStatusStep extends StepperStepBase {
|
|
17
|
+
readonly kind: "status";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface StepperLinkStep extends StepperStepBase {
|
|
21
|
+
readonly kind: "link";
|
|
22
|
+
readonly href: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface StepperActionStep extends StepperStepBase {
|
|
26
|
+
readonly kind: "action";
|
|
27
|
+
readonly onSelect: () => void;
|
|
28
|
+
readonly disabled?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type StepperStep = StepperStatusStep | StepperLinkStep | StepperActionStep;
|
|
32
|
+
|
|
33
|
+
export interface StepperProps extends Omit<JSX.HTMLAttributes<HTMLElement>, "children" | "ref"> {
|
|
34
|
+
ref?: HTMLElement | ((element: HTMLElement) => void);
|
|
35
|
+
label: string;
|
|
36
|
+
steps: readonly StepperStep[];
|
|
37
|
+
orientation?: "horizontal" | "vertical";
|
|
38
|
+
density?: "compact" | "default";
|
|
39
|
+
refreshing?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function StepLabel(props: { readonly step: Accessor<StepperStep> }): JSX.Element {
|
|
43
|
+
const href = (): string => {
|
|
44
|
+
const step = props.step();
|
|
45
|
+
return step.kind === "link" ? step.href : "";
|
|
46
|
+
};
|
|
47
|
+
const actionDisabled = (): boolean => {
|
|
48
|
+
const step = props.step();
|
|
49
|
+
return step.kind === "action" && Boolean(step.disabled);
|
|
50
|
+
};
|
|
51
|
+
const select = (): void => {
|
|
52
|
+
const step = props.step();
|
|
53
|
+
if (step.kind === "action" && !step.disabled) step.onSelect();
|
|
54
|
+
};
|
|
55
|
+
return <Show when={props.step().kind === "link"} fallback={<Show when={props.step().kind === "action"} fallback={<strong>{props.step().label}</strong>}>
|
|
56
|
+
<Button variant="link" disabled={actionDisabled()} onClick={select}>{props.step().label}</Button>
|
|
57
|
+
</Show>}><Link href={href()}>{props.step().label}</Link></Show>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** A semantic workflow progress list with native link and action variants. */
|
|
61
|
+
export function Stepper(props: StepperProps): JSX.Element {
|
|
62
|
+
const theme = useTheme();
|
|
63
|
+
const [local, others] = splitProps(props, ["ref", "class", "label", "steps", "orientation", "density", "refreshing", "aria-label"]);
|
|
64
|
+
const byId = createMemo(() => {
|
|
65
|
+
const result = new Map<string, StepperStep>();
|
|
66
|
+
let currentCount = 0;
|
|
67
|
+
for (const step of local.steps) {
|
|
68
|
+
if (!step.id.trim()) throw new Error("Stepper: step IDs must be nonempty");
|
|
69
|
+
if (result.has(step.id)) throw new Error(`Stepper: duplicate step ID ${JSON.stringify(step.id)}`);
|
|
70
|
+
if (!step.label.trim()) throw new Error(`Stepper: label must be nonempty for ${JSON.stringify(step.id)}`);
|
|
71
|
+
if (step.state === "current") currentCount += 1;
|
|
72
|
+
if (step.kind === "link" && !step.href.trim()) throw new Error(`Stepper: href must be nonempty for ${JSON.stringify(step.id)}`);
|
|
73
|
+
result.set(step.id, step);
|
|
74
|
+
}
|
|
75
|
+
if (currentCount > 1) throw new Error("Stepper: only one step may be current");
|
|
76
|
+
return result;
|
|
77
|
+
});
|
|
78
|
+
const ids = createMemo(() => [...byId().keys()]);
|
|
79
|
+
const completed = createMemo(() => [...byId().values()].filter(step => step.state === "completed").length);
|
|
80
|
+
const stateText = (state: WorkflowState): string => {
|
|
81
|
+
if (state === "completed") return theme.messages().workflowCompleted;
|
|
82
|
+
if (state === "current") return theme.messages().workflowCurrent;
|
|
83
|
+
if (state === "error") return theme.messages().workflowError;
|
|
84
|
+
return theme.messages().workflowUpcoming;
|
|
85
|
+
};
|
|
86
|
+
const marker = (state: WorkflowState, index: number): string => {
|
|
87
|
+
if (state === "completed") return "✓";
|
|
88
|
+
if (state === "current") return "●";
|
|
89
|
+
if (state === "error") return "!";
|
|
90
|
+
return String(index + 1);
|
|
91
|
+
};
|
|
92
|
+
return <nav {...others} ref={element => { if (typeof local.ref === "function") local.ref(element); }} class={cn("sheen-stepper", local.class)} aria-label={local["aria-label"] ?? local.label}
|
|
93
|
+
aria-busy={local.refreshing || undefined} data-orientation={local.orientation ?? "horizontal"} data-density={local.density ?? "default"} data-refreshing={local.refreshing || undefined}>
|
|
94
|
+
<progress class="sheen-stepper-progress" max={Math.max(1, ids().length)} value={completed()} aria-label={theme.messages().stepperProgress.replaceAll("{label}", local.label)} />
|
|
95
|
+
<ol class="sheen-stepper-list"><For each={ids()}>{(id, index) => {
|
|
96
|
+
const step = () => byId().get(id);
|
|
97
|
+
return <Show when={step()}>{current => <li class="sheen-stepper-step" data-step-id={id} data-state={current().state} aria-current={current().state === "current" ? "step" : undefined}>
|
|
98
|
+
<span class="sheen-workflow-marker" data-state={current().state} aria-hidden="true">{marker(current().state, index())}</span>
|
|
99
|
+
<div class="sheen-stepper-copy"><StepLabel step={current} />
|
|
100
|
+
<span class="sheen-workflow-state">{stateText(current().state)}</span>
|
|
101
|
+
<Show when={current().description}>{description => <span class="sheen-stepper-description">{description()}</span>}</Show>
|
|
102
|
+
</div>
|
|
103
|
+
</li>}</Show>;
|
|
104
|
+
}}</For></ol>
|
|
105
|
+
</nav>;
|
|
106
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { splitProps } from "solid-js";
|
|
2
|
+
import type { JSX } from "solid-js";
|
|
3
|
+
import { cn } from "../utils/cn.ts";
|
|
4
|
+
import type { Spacing } from "../layout/Layout.tsx";
|
|
5
|
+
|
|
6
|
+
export interface SurfaceProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
7
|
+
variant?: "base" | "subtle" | "raised" | "inset";
|
|
8
|
+
padding?: Spacing;
|
|
9
|
+
bordered?: boolean;
|
|
10
|
+
elevated?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export function Surface(props: SurfaceProps): JSX.Element {
|
|
13
|
+
const [local, others] = splitProps(props, ["class", "variant", "padding", "bordered", "elevated"]);
|
|
14
|
+
return <div {...others} class={cn("sheen-layout sheen-surface", local.class)} data-surface={local.variant ?? "base"} data-gap={local.padding ?? "none"} data-bordered={local.bordered || undefined} data-elevated={local.elevated || undefined} />;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type CardProps = SurfaceProps;
|
|
18
|
+
export function Card(props: CardProps): JSX.Element {
|
|
19
|
+
const [local, others] = splitProps(props, ["class", "variant", "padding", "bordered"]);
|
|
20
|
+
return <Surface {...others} class={cn("sheen-card", local.class)} variant={local.variant ?? "raised"} padding={local.padding ?? "lg"} bordered={local.bordered ?? true} />;
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { JSX } from "solid-js";
|
|
2
|
+
import { createNativeBooleanControl } from "./Checkbox.tsx";
|
|
3
|
+
import type { CheckboxProps } from "./Checkbox.tsx";
|
|
4
|
+
|
|
5
|
+
export type SwitchProps = Omit<CheckboxProps, "indeterminate">;
|
|
6
|
+
|
|
7
|
+
export function Switch(props: SwitchProps): JSX.Element {
|
|
8
|
+
return createNativeBooleanControl(props, "switch");
|
|
9
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { splitProps } from "solid-js";
|
|
2
|
+
import type { JSX } from "solid-js";
|
|
3
|
+
import { cn } from "../utils/cn.ts";
|
|
4
|
+
|
|
5
|
+
export interface TableProps extends JSX.HTMLAttributes<HTMLTableElement> {
|
|
6
|
+
striped?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export function Table(props: TableProps): JSX.Element {
|
|
9
|
+
const [local, others] = splitProps(props, ["class", "striped"]);
|
|
10
|
+
return <table {...others} class={cn("sheen-table", local.class)} data-striped={local.striped || undefined} />;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type TableCaptionProps = JSX.HTMLAttributes<HTMLTableCaptionElement>;
|
|
14
|
+
export function TableCaption(props: TableCaptionProps): JSX.Element {
|
|
15
|
+
const [local, others] = splitProps(props, ["class"]);
|
|
16
|
+
return <caption {...others} class={cn("sheen-table-caption", local.class)} />;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type TableHeadProps = JSX.HTMLAttributes<HTMLTableSectionElement>;
|
|
20
|
+
export function TableHead(props: TableHeadProps): JSX.Element {
|
|
21
|
+
const [local, others] = splitProps(props, ["class"]);
|
|
22
|
+
return <thead {...others} class={cn("sheen-table-thead", local.class)} />;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type TableBodyProps = JSX.HTMLAttributes<HTMLTableSectionElement>;
|
|
26
|
+
export function TableBody(props: TableBodyProps): JSX.Element {
|
|
27
|
+
const [local, others] = splitProps(props, ["class"]);
|
|
28
|
+
return <tbody {...others} class={cn("sheen-table-tbody", local.class)} />;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type TableFootProps = JSX.HTMLAttributes<HTMLTableSectionElement>;
|
|
32
|
+
export function TableFoot(props: TableFootProps): JSX.Element {
|
|
33
|
+
const [local, others] = splitProps(props, ["class"]);
|
|
34
|
+
return <tfoot {...others} class={cn("sheen-table-tfoot", local.class)} />;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type TableRowProps = JSX.HTMLAttributes<HTMLTableRowElement>;
|
|
38
|
+
export function TableRow(props: TableRowProps): JSX.Element {
|
|
39
|
+
const [local, others] = splitProps(props, ["class"]);
|
|
40
|
+
return <tr {...others} class={cn("sheen-table-tr", local.class)} />;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface TableHeaderCellProps extends JSX.ThHTMLAttributes<HTMLTableCellElement> {
|
|
44
|
+
numeric?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export function TableHeaderCell(props: TableHeaderCellProps): JSX.Element {
|
|
47
|
+
const [local, others] = splitProps(props, ["class", "numeric", "scope"]);
|
|
48
|
+
return <th {...others} class={cn("sheen-table-th", local.class)} scope={local.scope ?? "col"} data-numeric={local.numeric || undefined} />;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface TableCellProps extends JSX.TdHTMLAttributes<HTMLTableCellElement> {
|
|
52
|
+
numeric?: boolean;
|
|
53
|
+
}
|
|
54
|
+
export function TableCell(props: TableCellProps): JSX.Element {
|
|
55
|
+
const [local, others] = splitProps(props, ["class", "numeric"]);
|
|
56
|
+
return <td {...others} class={cn("sheen-table-td", local.class)} data-numeric={local.numeric || undefined} />;
|
|
57
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import * as Primitive from "@kobalte/core/tabs";
|
|
2
|
+
import { For, createEffect, createMemo, createSignal, createUniqueId, onCleanup, splitProps } from "solid-js";
|
|
3
|
+
import type { JSX } from "solid-js";
|
|
4
|
+
import { Button } from "./Button.tsx";
|
|
5
|
+
import { cn } from "../utils/cn.ts";
|
|
6
|
+
|
|
7
|
+
export interface TabOption {
|
|
8
|
+
readonly value: string;
|
|
9
|
+
readonly label: string;
|
|
10
|
+
readonly disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface TabsProps extends Omit<JSX.HTMLAttributes<HTMLDivElement>, "children" | "onChange"> {
|
|
14
|
+
label: string;
|
|
15
|
+
items: readonly TabOption[];
|
|
16
|
+
value?: string;
|
|
17
|
+
defaultValue?: string;
|
|
18
|
+
onValueChange?: (value: string) => void;
|
|
19
|
+
orientation?: "horizontal" | "vertical";
|
|
20
|
+
activationMode?: "automatic" | "manual";
|
|
21
|
+
children: (value: string) => JSX.Element;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function Trigger(props: { value: string; id: string; label: string; disabled: boolean; selected: boolean }): JSX.Element {
|
|
25
|
+
const context = Primitive.useTabsContext();
|
|
26
|
+
const tabIndex = () => props.disabled ? -1 : (context.listState().selectionManager().focusedKey() ?? (props.selected ? props.value : undefined)) === props.value ? 0 : -1;
|
|
27
|
+
return <Primitive.Trigger as={Button} value={props.value} id={`${props.id}-tab`} aria-controls={`${props.id}-panel`} disabled={props.disabled} tabIndex={tabIndex()} class="sheen-tabs-trigger">{props.label}</Primitive.Trigger>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function Tabs(props: TabsProps): JSX.Element {
|
|
31
|
+
const [local, others] = splitProps(props, ["label", "items", "value", "defaultValue", "onValueChange", "orientation", "activationMode", "children", "class", "id", "ref"]);
|
|
32
|
+
const generatedId = createUniqueId();
|
|
33
|
+
const id = () => local.id ?? `sheen-tabs-${generatedId}`;
|
|
34
|
+
let root: HTMLDivElement | undefined;
|
|
35
|
+
let disposed = false;
|
|
36
|
+
onCleanup(() => { disposed = true; });
|
|
37
|
+
const preserveFocus = () => {
|
|
38
|
+
const element = root;
|
|
39
|
+
const focused = element?.ownerDocument.activeElement;
|
|
40
|
+
if (!element || !(focused instanceof HTMLElement) || !element.contains(focused)) return;
|
|
41
|
+
element.ownerDocument.defaultView?.queueMicrotask(() => {
|
|
42
|
+
if (disposed || !element.isConnected) return;
|
|
43
|
+
const active = element.ownerDocument.activeElement;
|
|
44
|
+
if (active !== element.ownerDocument.body && active !== focused) return;
|
|
45
|
+
const eligible = (target: HTMLElement) => target.isConnected && !target.matches(":disabled") && !target.closest("[hidden], [inert]");
|
|
46
|
+
const retained = element.contains(focused) && eligible(focused) ? focused : undefined;
|
|
47
|
+
const selectedTab = [...element.querySelectorAll<HTMLButtonElement>('[role="tab"][aria-selected="true"]')]
|
|
48
|
+
.find(tab => tab.closest(".sheen-tabs") === element && eligible(tab));
|
|
49
|
+
(retained ?? selectedTab ?? element).focus({ preventScroll: true });
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
const entries = createMemo(() => {
|
|
53
|
+
if (!local.label.trim()) throw new Error("Tabs requires a nonempty accessible label");
|
|
54
|
+
const result = new Map<string, TabOption>();
|
|
55
|
+
for (const item of local.items) {
|
|
56
|
+
if (!item.value.trim() || !item.label.trim()) throw new Error("Tabs requires nonempty item values and labels");
|
|
57
|
+
if (result.has(item.value)) throw new Error(`Tabs duplicate item value: ${item.value}`);
|
|
58
|
+
result.set(item.value, item);
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
});
|
|
62
|
+
const [draft, setDraft] = createSignal(local.defaultValue);
|
|
63
|
+
let previousKeys: string[] = [];
|
|
64
|
+
const selected = createMemo(() => {
|
|
65
|
+
preserveFocus();
|
|
66
|
+
const current = entries();
|
|
67
|
+
const keys = [...current.keys()];
|
|
68
|
+
const requested = local.value ?? draft();
|
|
69
|
+
const index = Math.max(0, requested === undefined ? 0 : previousKeys.indexOf(requested));
|
|
70
|
+
previousKeys = keys;
|
|
71
|
+
if (local.value !== undefined && (!current.has(local.value) || current.get(local.value)?.disabled)) throw new Error("Tabs controlled value must identify an enabled item");
|
|
72
|
+
if (requested !== undefined && current.has(requested) && !current.get(requested)?.disabled) return requested;
|
|
73
|
+
const enabled = (value: string) => !current.get(value)?.disabled;
|
|
74
|
+
return keys.slice(index).find(enabled) ?? keys.slice(0, index).reverse().find(enabled);
|
|
75
|
+
});
|
|
76
|
+
createEffect(() => {
|
|
77
|
+
if (local.value !== undefined) return;
|
|
78
|
+
const previous = draft();
|
|
79
|
+
const next = selected();
|
|
80
|
+
if (previous === next) return;
|
|
81
|
+
setDraft(next);
|
|
82
|
+
if (previous !== undefined && next !== undefined) local.onValueChange?.(next);
|
|
83
|
+
});
|
|
84
|
+
const change = (encoded: string) => {
|
|
85
|
+
const next = decodeURIComponent(encoded);
|
|
86
|
+
if (!entries().has(next) || entries().get(next)?.disabled || next === selected()) return;
|
|
87
|
+
if (local.value === undefined) setDraft(next);
|
|
88
|
+
local.onValueChange?.(next);
|
|
89
|
+
};
|
|
90
|
+
return <Primitive.Root {...others} ref={element => { root = element; if (typeof local.ref === "function") local.ref(element); }} tabIndex={others.tabIndex ?? -1} id={id()} class={cn("sheen-tabs", local.class)} value={encodeURIComponent(selected() ?? "")} onChange={change} orientation={local.orientation ?? "horizontal"} activationMode={local.activationMode ?? "automatic"}>
|
|
91
|
+
<Primitive.List aria-label={local.label} class="sheen-tabs-list">
|
|
92
|
+
<For each={[...entries().keys()]}>{value => <Trigger value={encodeURIComponent(value)} id={`${id()}-${encodeURIComponent(value)}`} label={entries().get(value)?.label ?? ""} disabled={entries().get(value)?.disabled ?? false} selected={selected() === value} />}</For>
|
|
93
|
+
</Primitive.List>
|
|
94
|
+
<For each={[...entries().keys()]}>{value => <div role="tabpanel" id={`${id()}-${encodeURIComponent(value)}-panel`} aria-labelledby={`${id()}-${encodeURIComponent(value)}-tab`} hidden={selected() !== value} inert={selected() !== value} tabIndex={0} class="sheen-tabs-panel">{local.children(value)}</div>}</For>
|
|
95
|
+
</Primitive.Root>;
|
|
96
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { For, Show, createEffect, createSignal, createUniqueId, onCleanup, onMount, splitProps } from "solid-js";
|
|
2
|
+
import type { JSX } from "solid-js";
|
|
3
|
+
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
4
|
+
import { cn } from "../utils/cn.ts";
|
|
5
|
+
import { Button } from "./Button.tsx";
|
|
6
|
+
|
|
7
|
+
export interface TagInputValidationContext {
|
|
8
|
+
readonly values: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type TagInputValidationResult =
|
|
12
|
+
| { readonly kind: "accepted"; readonly value?: string }
|
|
13
|
+
| { readonly kind: "rejected"; readonly message: string };
|
|
14
|
+
|
|
15
|
+
export interface TagInputProps extends Omit<JSX.HTMLAttributes<HTMLDivElement>, "children" | "onChange" | "onInput" | "ref"> {
|
|
16
|
+
ref?: HTMLDivElement | ((element: HTMLDivElement) => void);
|
|
17
|
+
inputRef?: HTMLInputElement | ((element: HTMLInputElement) => void);
|
|
18
|
+
label: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
form?: string;
|
|
21
|
+
value?: readonly string[];
|
|
22
|
+
defaultValue?: readonly string[];
|
|
23
|
+
onValueChange?: (value: readonly string[]) => void;
|
|
24
|
+
validate?: (candidate: string, context: TagInputValidationContext, signal: AbortSignal) => TagInputValidationResult | Promise<TagInputValidationResult>;
|
|
25
|
+
onValidationError?: (error: unknown) => void;
|
|
26
|
+
normalize?: (draft: string) => string;
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
error?: string;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
readOnly?: boolean;
|
|
32
|
+
required?: boolean;
|
|
33
|
+
commitKeys?: readonly string[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function validateValues(values: readonly string[], owner: string): void {
|
|
37
|
+
const seen = new Set<string>();
|
|
38
|
+
for (const value of values) {
|
|
39
|
+
if (!value.trim()) throw new Error(`${owner}: values must be nonempty`);
|
|
40
|
+
if (seen.has(value)) throw new Error(`${owner}: duplicate value ${JSON.stringify(value)}`);
|
|
41
|
+
seen.add(value);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function sameValues(first: readonly string[], second: readonly string[]): boolean {
|
|
46
|
+
return first.length === second.length && first.every((value, index) => value === second[index]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** An ordered free-form tag editor with native multi-value form projection. */
|
|
50
|
+
export function TagInput(props: TagInputProps): JSX.Element {
|
|
51
|
+
const theme = useTheme();
|
|
52
|
+
const generatedId = createUniqueId();
|
|
53
|
+
const [local, others] = splitProps(props, ["id", "ref", "inputRef", "class", "label", "name", "form", "value", "defaultValue", "onValueChange", "validate", "onValidationError", "normalize", "placeholder", "description", "error", "disabled", "readOnly", "required", "commitKeys", "aria-describedby", "aria-label", "aria-labelledby"]);
|
|
54
|
+
const initial = [...(local.defaultValue ?? [])];
|
|
55
|
+
validateValues(initial, "TagInput defaultValue");
|
|
56
|
+
const [uncontrolled, setUncontrolled] = createSignal<readonly string[]>(initial);
|
|
57
|
+
const [draft, setDraft] = createSignal("");
|
|
58
|
+
const [composition, setComposition] = createSignal(false);
|
|
59
|
+
const [pending, setPending] = createSignal(false);
|
|
60
|
+
const [validationError, setValidationError] = createSignal<string>();
|
|
61
|
+
const [announcement, setAnnouncement] = createSignal("");
|
|
62
|
+
let input: HTMLInputElement | undefined;
|
|
63
|
+
let native: HTMLSelectElement | undefined;
|
|
64
|
+
let disposed = false;
|
|
65
|
+
let validationRevision = 0;
|
|
66
|
+
let validationController: AbortController | undefined;
|
|
67
|
+
const removeButtons = new Map<string, HTMLButtonElement>();
|
|
68
|
+
const values = (): readonly string[] => {
|
|
69
|
+
const result = local.value === undefined ? uncontrolled() : local.value;
|
|
70
|
+
validateValues(result, "TagInput value");
|
|
71
|
+
return result;
|
|
72
|
+
};
|
|
73
|
+
const describedBy = () => [local.description ? `${generatedId}-description` : "", local.error || validationError() ? `${generatedId}-error` : "", local["aria-describedby"]].filter(Boolean).join(" ") || undefined;
|
|
74
|
+
const publish = (next: readonly string[]): void => {
|
|
75
|
+
validateValues(next, "TagInput value");
|
|
76
|
+
if (sameValues(next, values())) return;
|
|
77
|
+
if (local.value === undefined) setUncontrolled([...next]);
|
|
78
|
+
local.onValueChange?.([...next]);
|
|
79
|
+
};
|
|
80
|
+
const cancelValidation = (): void => {
|
|
81
|
+
validationRevision += 1;
|
|
82
|
+
validationController?.abort();
|
|
83
|
+
validationController = undefined;
|
|
84
|
+
setPending(false);
|
|
85
|
+
};
|
|
86
|
+
const setInputValue = (next: string): void => {
|
|
87
|
+
if (next !== draft()) setDraft(next);
|
|
88
|
+
if (input && input.value !== next) input.value = next;
|
|
89
|
+
};
|
|
90
|
+
const announce = (template: string, value: string): void => {
|
|
91
|
+
setAnnouncement("");
|
|
92
|
+
queueMicrotask(() => { if (!disposed) setAnnouncement(template.replaceAll("{value}", value)); });
|
|
93
|
+
};
|
|
94
|
+
const remove = (value: string, restoreFocus: boolean): void => {
|
|
95
|
+
if (local.disabled || local.readOnly) return;
|
|
96
|
+
const current = values();
|
|
97
|
+
const index = current.indexOf(value);
|
|
98
|
+
if (index < 0) return;
|
|
99
|
+
cancelValidation();
|
|
100
|
+
publish(current.filter(candidate => candidate !== value));
|
|
101
|
+
announce(theme.messages().tagRemoved, value);
|
|
102
|
+
if (restoreFocus) queueMicrotask(() => {
|
|
103
|
+
const next = values()[Math.min(index, Math.max(0, values().length - 1))];
|
|
104
|
+
if (next) removeButtons.get(next)?.focus({ preventScroll: true });
|
|
105
|
+
else input?.focus({ preventScroll: true });
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
const move = (value: string, destination: number): void => {
|
|
109
|
+
if (local.disabled || local.readOnly) return;
|
|
110
|
+
const current = [...values()];
|
|
111
|
+
const from = current.indexOf(value);
|
|
112
|
+
if (from < 0) return;
|
|
113
|
+
const to = Math.max(0, Math.min(current.length - 1, destination));
|
|
114
|
+
if (from === to) return;
|
|
115
|
+
cancelValidation();
|
|
116
|
+
current.splice(from, 1);
|
|
117
|
+
current.splice(to, 0, value);
|
|
118
|
+
publish(current);
|
|
119
|
+
announce(theme.messages().tagMoved, value);
|
|
120
|
+
queueMicrotask(() => removeButtons.get(value)?.focus({ preventScroll: true }));
|
|
121
|
+
};
|
|
122
|
+
const commit = async (): Promise<void> => {
|
|
123
|
+
if (local.disabled || local.readOnly || pending()) return;
|
|
124
|
+
const candidate = (local.normalize ?? (value => value.trim()))(draft());
|
|
125
|
+
if (!candidate) return;
|
|
126
|
+
if (values().includes(candidate)) {
|
|
127
|
+
setValidationError(theme.messages().tagDuplicate.replaceAll("{value}", candidate));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
setValidationError(undefined);
|
|
131
|
+
const revision = validationRevision + 1;
|
|
132
|
+
validationRevision = revision;
|
|
133
|
+
validationController?.abort();
|
|
134
|
+
const controller = new AbortController();
|
|
135
|
+
validationController = controller;
|
|
136
|
+
setPending(true);
|
|
137
|
+
try {
|
|
138
|
+
const result = local.validate
|
|
139
|
+
? await local.validate(candidate, { values: [...values()] }, controller.signal)
|
|
140
|
+
: { kind: "accepted" } satisfies TagInputValidationResult;
|
|
141
|
+
if (disposed || controller.signal.aborted || revision !== validationRevision) return;
|
|
142
|
+
if (result.kind === "rejected") {
|
|
143
|
+
setValidationError(result.message);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const accepted = result.value === undefined ? candidate : result.value;
|
|
147
|
+
if (!accepted.trim()) {
|
|
148
|
+
setValidationError(theme.messages().tagValidationFailed);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (values().includes(accepted)) {
|
|
152
|
+
setValidationError(theme.messages().tagDuplicate.replaceAll("{value}", accepted));
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
publish([...values(), accepted]);
|
|
156
|
+
setInputValue("");
|
|
157
|
+
announce(theme.messages().tagAdded, accepted);
|
|
158
|
+
} catch (error: unknown) {
|
|
159
|
+
if (disposed || controller.signal.aborted || revision !== validationRevision) return;
|
|
160
|
+
setValidationError(theme.messages().tagValidationFailed);
|
|
161
|
+
local.onValidationError?.(error);
|
|
162
|
+
} finally {
|
|
163
|
+
if (!disposed && revision === validationRevision) {
|
|
164
|
+
validationController = undefined;
|
|
165
|
+
setPending(false);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const onInput: JSX.InputEventHandler<HTMLInputElement, InputEvent> = event => {
|
|
170
|
+
cancelValidation();
|
|
171
|
+
setValidationError(undefined);
|
|
172
|
+
setDraft(event.currentTarget.value);
|
|
173
|
+
};
|
|
174
|
+
const onKeyDown: JSX.EventHandler<HTMLInputElement, KeyboardEvent> = event => {
|
|
175
|
+
if (event.isComposing || composition()) return;
|
|
176
|
+
const keys = local.commitKeys ?? ["Enter", ","];
|
|
177
|
+
if (keys.includes(event.key)) {
|
|
178
|
+
if (draft().trim()) event.preventDefault();
|
|
179
|
+
void commit();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (event.key === "Backspace" && !draft() && values().length > 0) {
|
|
183
|
+
const last = values().at(-1);
|
|
184
|
+
if (last) remove(last, false);
|
|
185
|
+
} else if (event.key === "ArrowLeft" && !draft()) {
|
|
186
|
+
const last = values().at(-1);
|
|
187
|
+
if (last) {
|
|
188
|
+
event.preventDefault();
|
|
189
|
+
removeButtons.get(last)?.focus({ preventScroll: true });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
const onTagKeyDown = (event: KeyboardEvent & { currentTarget: HTMLButtonElement }, value: string): void => {
|
|
194
|
+
if (event.key === "Delete" || event.key === "Backspace") {
|
|
195
|
+
event.preventDefault();
|
|
196
|
+
remove(value, true);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (!event.altKey) return;
|
|
200
|
+
const index = values().indexOf(value);
|
|
201
|
+
if (index < 0) return;
|
|
202
|
+
const rtl = Boolean(event.currentTarget.closest('[dir="rtl"]'));
|
|
203
|
+
if (event.key === "Home") {
|
|
204
|
+
event.preventDefault();
|
|
205
|
+
move(value, 0);
|
|
206
|
+
} else if (event.key === "End") {
|
|
207
|
+
event.preventDefault();
|
|
208
|
+
move(value, values().length - 1);
|
|
209
|
+
} else if (event.key === "ArrowLeft") {
|
|
210
|
+
event.preventDefault();
|
|
211
|
+
move(value, index + (rtl ? 1 : -1));
|
|
212
|
+
} else if (event.key === "ArrowRight") {
|
|
213
|
+
event.preventDefault();
|
|
214
|
+
move(value, index + (rtl ? -1 : 1));
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
const synchronizeNative = (): void => {
|
|
218
|
+
if (!native) return;
|
|
219
|
+
const selected = new Set(values());
|
|
220
|
+
for (const option of native.options) option.selected = selected.has(option.value);
|
|
221
|
+
};
|
|
222
|
+
createEffect(() => { values(); synchronizeNative(); });
|
|
223
|
+
onMount(() => {
|
|
224
|
+
const element = input;
|
|
225
|
+
const document = element?.ownerDocument;
|
|
226
|
+
const view = document?.defaultView;
|
|
227
|
+
if (!element || !document || !view) return;
|
|
228
|
+
if (element.value !== draft()) setDraft(element.value);
|
|
229
|
+
const timers = new Set<number>();
|
|
230
|
+
const reset = (event: Event): void => {
|
|
231
|
+
if (event.target !== native?.form && event.target !== element.form) return;
|
|
232
|
+
const timer = view.setTimeout(() => {
|
|
233
|
+
timers.delete(timer);
|
|
234
|
+
if (disposed || event.defaultPrevented) return;
|
|
235
|
+
cancelValidation();
|
|
236
|
+
setValidationError(undefined);
|
|
237
|
+
setInputValue("");
|
|
238
|
+
if (local.value === undefined) publish(initial);
|
|
239
|
+
synchronizeNative();
|
|
240
|
+
}, 0);
|
|
241
|
+
timers.add(timer);
|
|
242
|
+
};
|
|
243
|
+
document.addEventListener("reset", reset, true);
|
|
244
|
+
onCleanup(() => {
|
|
245
|
+
document.removeEventListener("reset", reset, true);
|
|
246
|
+
for (const timer of timers) view.clearTimeout(timer);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
onCleanup(() => {
|
|
250
|
+
disposed = true;
|
|
251
|
+
validationRevision += 1;
|
|
252
|
+
validationController?.abort();
|
|
253
|
+
});
|
|
254
|
+
const visibleError = () => local.error ?? validationError();
|
|
255
|
+
return <div {...others} id={local.id ?? generatedId} ref={element => { if (typeof local.ref === "function") local.ref(element); }} class={cn("sheen-field sheen-tag-input", local.class)}
|
|
256
|
+
data-invalid={visibleError() ? "true" : undefined} data-disabled={local.disabled || undefined} data-readonly={local.readOnly || undefined} data-pending={pending() || undefined}>
|
|
257
|
+
<label id={`${generatedId}-label`} for={`${generatedId}-input`} class="sheen-field-label">{local.label}<Show when={local.required}><span aria-hidden="true"> *</span></Show></label>
|
|
258
|
+
<div class="sheen-tag-input-control" onClick={event => { if (event.target === event.currentTarget) input?.focus(); }}>
|
|
259
|
+
<ul class="sheen-tag-input-values" aria-label={theme.messages().tagValues}><For each={values()}>{value => {
|
|
260
|
+
onCleanup(() => removeButtons.delete(value));
|
|
261
|
+
return <li class="sheen-tag-input-value" data-tag-value={value}>
|
|
262
|
+
<span class="sheen-tag-input-value-label">{value}</span>
|
|
263
|
+
<Button ref={element => removeButtons.set(value, element)} class="sheen-tag-input-remove" size="xs" disabled={local.disabled} aria-disabled={local.readOnly || undefined} aria-label={`${theme.messages().remove} ${value}`}
|
|
264
|
+
aria-describedby={`${generatedId}-reorder`} onKeyDown={event => onTagKeyDown(event, value)} onClick={() => remove(value, true)}>{theme.messages().remove}</Button>
|
|
265
|
+
</li>;
|
|
266
|
+
}}</For></ul>
|
|
267
|
+
<input id={`${generatedId}-input`} ref={element => { input = element; if (typeof local.inputRef === "function") local.inputRef(element); }} type="text" class="sheen-tag-input-editor"
|
|
268
|
+
value={draft()} placeholder={values().length === 0 ? local.placeholder : undefined} disabled={local.disabled} readOnly={local.readOnly} autocomplete="off"
|
|
269
|
+
aria-label={local["aria-label"]} aria-labelledby={local["aria-labelledby"] ?? `${generatedId}-label`} aria-describedby={describedBy()} aria-invalid={visibleError() ? true : undefined}
|
|
270
|
+
aria-required={local.required || undefined} aria-busy={pending() || undefined} onInput={onInput} onKeyDown={onKeyDown}
|
|
271
|
+
onCompositionStart={() => setComposition(true)} onCompositionEnd={event => { setComposition(false); setDraft(event.currentTarget.value); }} />
|
|
272
|
+
</div>
|
|
273
|
+
<select ref={native} class="sheen-select-native" aria-hidden="true" tabIndex={-1} multiple name={local.name} form={local.form} required={local.required} disabled={local.disabled} aria-label={local.label}
|
|
274
|
+
onInvalid={event => { event.preventDefault(); input?.focus(); }} onChange={event => { if (!local.readOnly) publish([...event.currentTarget.selectedOptions].map(option => option.value)); synchronizeNative(); }}>
|
|
275
|
+
<For each={values()}>{value => <option value={value} selected>{value}</option>}</For>
|
|
276
|
+
</select>
|
|
277
|
+
<span id={`${generatedId}-reorder`} class="sheen-tag-input-instructions">{theme.messages().tagReorderInstructions}</span>
|
|
278
|
+
<Show when={local.description}><span id={`${generatedId}-description`} class="sheen-field-description">{local.description}</span></Show>
|
|
279
|
+
<Show when={visibleError()}>{message => <span id={`${generatedId}-error`} class="sheen-field-error" role="alert">{message()}</span>}</Show>
|
|
280
|
+
<span class="sheen-tag-input-announcer" role="status" aria-live="polite" aria-atomic="true">{pending() ? theme.messages().tagValidating : announcement()}</span>
|
|
281
|
+
</div>;
|
|
282
|
+
}
|