@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,234 @@
|
|
|
1
|
+
import { Command } from "cmdk-solid";
|
|
2
|
+
import * as KobalteDialog from "@kobalte/core/dialog";
|
|
3
|
+
import { For, Show, createEffect, createMemo, createSignal, createUniqueId, onCleanup, splitProps, type JSX } from "solid-js";
|
|
4
|
+
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
5
|
+
import { cn } from "../utils/cn.ts";
|
|
6
|
+
import { useModalShortcutScope, useShortcut, useShortcutCommands } from "./ShortcutProvider.tsx";
|
|
7
|
+
import { Kbd, Text } from "./Typography.tsx";
|
|
8
|
+
|
|
9
|
+
export interface CommandPaletteCommand {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly label: string;
|
|
12
|
+
readonly group: string;
|
|
13
|
+
readonly keywords?: readonly string[];
|
|
14
|
+
readonly disabled?: boolean;
|
|
15
|
+
readonly run: () => void | Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface CommandPaletteStaticSource {
|
|
19
|
+
readonly kind: "static";
|
|
20
|
+
readonly id: string;
|
|
21
|
+
readonly commands: readonly CommandPaletteCommand[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface CommandPaletteRemoteSource {
|
|
25
|
+
readonly kind: "remote";
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly initialCommands?: readonly CommandPaletteCommand[];
|
|
28
|
+
readonly minimumQueryLength?: number;
|
|
29
|
+
readonly search: (query: string, signal: AbortSignal) => Promise<readonly CommandPaletteCommand[]>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type CommandPaletteSource = CommandPaletteStaticSource | CommandPaletteRemoteSource;
|
|
33
|
+
|
|
34
|
+
export interface CommandPaletteRecents {
|
|
35
|
+
readonly initialIds: readonly string[];
|
|
36
|
+
readonly limit?: number;
|
|
37
|
+
readonly save: (ids: readonly string[]) => void | Promise<void>;
|
|
38
|
+
readonly onError: (error: unknown) => void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface CommandPaletteProps {
|
|
42
|
+
readonly sources: readonly CommandPaletteSource[];
|
|
43
|
+
readonly open?: boolean;
|
|
44
|
+
readonly defaultOpen?: boolean;
|
|
45
|
+
readonly onOpenChange?: (open: boolean) => void;
|
|
46
|
+
readonly recents?: CommandPaletteRecents;
|
|
47
|
+
readonly shortcutScope?: string;
|
|
48
|
+
readonly onSourceError?: (sourceId: string, error: unknown) => void;
|
|
49
|
+
readonly onCommandError?: (commandId: string, error: unknown) => void;
|
|
50
|
+
readonly class?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function requiredText(value: string, name: string): string {
|
|
54
|
+
const result = value.trim();
|
|
55
|
+
if (!result) throw new Error(`CommandPalette ${name} must be nonempty`);
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function validateCommands(commands: readonly CommandPaletteCommand[], name: string): readonly CommandPaletteCommand[] {
|
|
60
|
+
const ids = new Set<string>();
|
|
61
|
+
return Object.freeze(commands.map(command => {
|
|
62
|
+
const id = requiredText(command.id, `${name} command id`);
|
|
63
|
+
if (ids.has(id)) throw new Error(`CommandPalette ${name} has duplicate command id: ${id}`);
|
|
64
|
+
ids.add(id);
|
|
65
|
+
requiredText(command.label, `${id} label`);
|
|
66
|
+
requiredText(command.group, `${id} group`);
|
|
67
|
+
for (const keyword of command.keywords ?? []) requiredText(keyword, `${id} keyword`);
|
|
68
|
+
return command;
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function subsequenceScore(value: string, search: string): number {
|
|
73
|
+
const candidate = Array.from(value.toLocaleLowerCase("en-US"));
|
|
74
|
+
const query = Array.from(search.toLocaleLowerCase("en-US"));
|
|
75
|
+
let cursor = 0;
|
|
76
|
+
let gap = 0;
|
|
77
|
+
for (const character of query) {
|
|
78
|
+
const next = candidate.indexOf(character, cursor);
|
|
79
|
+
if (next < 0) return 0;
|
|
80
|
+
gap += next - cursor;
|
|
81
|
+
cursor = next + 1;
|
|
82
|
+
}
|
|
83
|
+
return Math.max(0.1, 0.55 - gap / Math.max(candidate.length, 1) * 0.2);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Deterministic fuzzy rank used by cmdk: exact, prefix, substring, then subsequence. */
|
|
87
|
+
export function commandPaletteFilter(value: string, search: string, keywords: readonly string[] = []): number {
|
|
88
|
+
const query = search.trim().toLocaleLowerCase("en-US");
|
|
89
|
+
if (!query) return 1;
|
|
90
|
+
const candidates = [value, ...keywords].map(candidate => candidate.toLocaleLowerCase("en-US"));
|
|
91
|
+
let best = 0;
|
|
92
|
+
for (const candidate of candidates) {
|
|
93
|
+
if (candidate === query) best = Math.max(best, 1);
|
|
94
|
+
else if (candidate.startsWith(query)) best = Math.max(best, 0.9);
|
|
95
|
+
else if (candidate.includes(query)) best = Math.max(best, 0.7);
|
|
96
|
+
else best = Math.max(best, subsequenceScore(candidate, query));
|
|
97
|
+
}
|
|
98
|
+
return best;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function validateRecentIds(ids: readonly string[]): readonly string[] {
|
|
102
|
+
const unique = new Set<string>();
|
|
103
|
+
for (const id of ids) {
|
|
104
|
+
const value = requiredText(id, "recent id");
|
|
105
|
+
if (unique.has(value)) throw new Error(`CommandPalette has duplicate recent id: ${value}`);
|
|
106
|
+
unique.add(value);
|
|
107
|
+
}
|
|
108
|
+
return Object.freeze([...unique]);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function CommandPalette(props: CommandPaletteProps): JSX.Element {
|
|
112
|
+
const theme = useTheme();
|
|
113
|
+
const shortcuts = useShortcutCommands();
|
|
114
|
+
const [local] = splitProps(props, ["sources", "open", "defaultOpen", "onOpenChange", "recents", "shortcutScope", "onSourceError", "onCommandError", "class"]);
|
|
115
|
+
const [uncontrolled, setUncontrolled] = createSignal(local.defaultOpen ?? false);
|
|
116
|
+
const [search, setSearch] = createSignal("");
|
|
117
|
+
const [pending, setPending] = createSignal(false);
|
|
118
|
+
const [sourceError, setSourceError] = createSignal<string>();
|
|
119
|
+
const [recentIds, setRecentIds] = createSignal<readonly string[]>(validateRecentIds(local.recents?.initialIds ?? []));
|
|
120
|
+
const initialRemote = local.sources.flatMap(source => source.kind === "remote" ? source.initialCommands ?? [] : []);
|
|
121
|
+
const [remoteCommands, setRemoteCommands] = createSignal<readonly CommandPaletteCommand[]>(validateCommands(initialRemote, "initial remote results"));
|
|
122
|
+
let request = 0;
|
|
123
|
+
const open = () => local.open === undefined ? uncontrolled() : local.open;
|
|
124
|
+
const change = (next: boolean) => {
|
|
125
|
+
if (next === open()) return;
|
|
126
|
+
if (local.open === undefined) setUncontrolled(next);
|
|
127
|
+
if (!next) setSearch("");
|
|
128
|
+
local.onOpenChange?.(next);
|
|
129
|
+
};
|
|
130
|
+
const paletteId = createUniqueId();
|
|
131
|
+
useShortcut({ keys: "mod+k", scope: local.shortcutScope ?? "global", label: theme.messages().openCommandPalette, group: "Navigation", run: () => change(!open()) });
|
|
132
|
+
useModalShortcutScope(() => `command-palette:${paletteId}`, open);
|
|
133
|
+
createEffect(() => { if (open()) onCleanup(theme.layers.register(paletteId)); });
|
|
134
|
+
const layer = createMemo<number>(previous => open() ? theme.layers.zIndex(paletteId) : previous ?? 100);
|
|
135
|
+
|
|
136
|
+
const staticCommands = createMemo(() => validateCommands(local.sources.flatMap(source => source.kind === "static" ? source.commands : []), "static sources"));
|
|
137
|
+
createEffect(() => {
|
|
138
|
+
const query = search().trim();
|
|
139
|
+
const sources = local.sources.flatMap(source => source.kind === "remote" && query.length >= (source.minimumQueryLength ?? 1) ? [source] : []);
|
|
140
|
+
const token = ++request;
|
|
141
|
+
if (!sources.length) { setPending(false); setSourceError(undefined); return; }
|
|
142
|
+
const controller = new AbortController();
|
|
143
|
+
setPending(true);
|
|
144
|
+
setSourceError(undefined);
|
|
145
|
+
void Promise.all(sources.map(async source => ({ source, commands: await source.search(query, controller.signal) }))).then(results => {
|
|
146
|
+
if (token !== request || controller.signal.aborted) return;
|
|
147
|
+
const ids = new Set<string>();
|
|
148
|
+
const accepted = results.flatMap(result => validateCommands(result.commands, `source ${result.source.id}`)).map(command => {
|
|
149
|
+
if (ids.has(command.id)) throw new Error(`CommandPalette remote sources have duplicate command id: ${command.id}`);
|
|
150
|
+
ids.add(command.id);
|
|
151
|
+
return command;
|
|
152
|
+
});
|
|
153
|
+
setRemoteCommands(Object.freeze(accepted));
|
|
154
|
+
setPending(false);
|
|
155
|
+
}).catch(error => {
|
|
156
|
+
if (token !== request || controller.signal.aborted) return;
|
|
157
|
+
setPending(false);
|
|
158
|
+
setSourceError(theme.messages().commandSourceFailed);
|
|
159
|
+
for (const source of sources) local.onSourceError?.(source.id, error);
|
|
160
|
+
});
|
|
161
|
+
onCleanup(() => controller.abort());
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const registeredCommands = createMemo<readonly CommandPaletteCommand[]>(() => shortcuts.bindings().filter(binding => !binding.shadowed).map(binding => Object.freeze({
|
|
165
|
+
id: `shortcut:${binding.id}`,
|
|
166
|
+
label: binding.label,
|
|
167
|
+
group: binding.group,
|
|
168
|
+
keywords: [binding.keys, binding.displayKeys, binding.scope],
|
|
169
|
+
disabled: binding.keys === "mod+k" && binding.label === theme.messages().openCommandPalette,
|
|
170
|
+
run: () => { shortcuts.run(binding.id); },
|
|
171
|
+
})));
|
|
172
|
+
const commands = createMemo(() => {
|
|
173
|
+
const values = [...staticCommands(), ...remoteCommands(), ...registeredCommands()];
|
|
174
|
+
const ids = new Set<string>();
|
|
175
|
+
for (const command of values) {
|
|
176
|
+
if (ids.has(command.id)) throw new Error(`CommandPalette has duplicate command id: ${command.id}`);
|
|
177
|
+
ids.add(command.id);
|
|
178
|
+
}
|
|
179
|
+
return values;
|
|
180
|
+
});
|
|
181
|
+
const commandById = createMemo(() => new Map(commands().map(command => [command.id, command])));
|
|
182
|
+
const recents = createMemo(() => search().trim() ? [] : recentIds().flatMap(id => {
|
|
183
|
+
const command = commandById().get(id);
|
|
184
|
+
return command && !command.disabled ? [command] : [];
|
|
185
|
+
}));
|
|
186
|
+
const recentSet = createMemo(() => new Set(recents().map(command => command.id)));
|
|
187
|
+
const groups = createMemo(() => [...new Set(commands().filter(command => !recentSet().has(command.id)).map(command => command.group))]);
|
|
188
|
+
const remember = (id: string) => {
|
|
189
|
+
const persistence = local.recents;
|
|
190
|
+
if (!persistence || id.startsWith("shortcut:")) return;
|
|
191
|
+
const limit = persistence.limit ?? 5;
|
|
192
|
+
if (!Number.isSafeInteger(limit) || limit < 1) throw new Error("CommandPalette recent limit must be a positive integer");
|
|
193
|
+
const next = Object.freeze([id, ...recentIds().filter(current => current !== id)].slice(0, limit));
|
|
194
|
+
setRecentIds(next);
|
|
195
|
+
try {
|
|
196
|
+
const result = persistence.save(next);
|
|
197
|
+
if (result instanceof Promise) void result.catch(persistence.onError);
|
|
198
|
+
} catch (error) { persistence.onError(error); }
|
|
199
|
+
};
|
|
200
|
+
const select = (command: CommandPaletteCommand) => {
|
|
201
|
+
if (command.disabled) return;
|
|
202
|
+
change(false);
|
|
203
|
+
remember(command.id);
|
|
204
|
+
try {
|
|
205
|
+
const result = command.run();
|
|
206
|
+
if (result instanceof Promise) void result.catch(error => local.onCommandError?.(command.id, error));
|
|
207
|
+
} catch (error) { local.onCommandError?.(command.id, error); }
|
|
208
|
+
};
|
|
209
|
+
const item = (command: CommandPaletteCommand) => {
|
|
210
|
+
const binding = () => shortcuts.bindings().find(value => `shortcut:${value.id}` === command.id);
|
|
211
|
+
return <Command.Item value={`${command.id} ${command.label}`} keywords={[...(command.keywords ?? [])]}
|
|
212
|
+
{...(command.disabled === undefined ? {} : { disabled: command.disabled })} onSelect={() => select(command)}>
|
|
213
|
+
<span>{command.label}</span><Show when={binding()}>{value => <Kbd>{value().displayKeys}</Kbd>}</Show>
|
|
214
|
+
</Command.Item>;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
return <KobalteDialog.Root open={open()} onOpenChange={change}><Show when={theme.portal()}>{target => <KobalteDialog.Portal mount={target()}>
|
|
218
|
+
<KobalteDialog.Overlay class="sheen-command-overlay" style={{ "z-index": layer() }} />
|
|
219
|
+
<KobalteDialog.Content class="sheen-command-dialog" style={{ "z-index": layer() + 1 }} aria-label={theme.messages().commandPalette}
|
|
220
|
+
onEscapeKeyDown={event => { if (!theme.layers.isTop(paletteId)) event.preventDefault(); }}>
|
|
221
|
+
<Command class={cn("sheen-command-palette", local.class)} label={theme.messages().commandPalette}
|
|
222
|
+
filter={(value, query, keywords) => commandPaletteFilter(value, query, keywords)} loop data-refreshing={pending() || undefined}>
|
|
223
|
+
<Command.Input value={search()} onValueChange={setSearch} placeholder={theme.messages().searchCommands} aria-label={theme.messages().searchCommands} />
|
|
224
|
+
<Command.List label={theme.messages().commandResults}>
|
|
225
|
+
<Show when={pending()}><Command.Loading label={theme.messages().loading}>{theme.messages().refreshingCommands}</Command.Loading></Show>
|
|
226
|
+
<Show when={sourceError()}>{message => <div role="alert"><Text tone="muted">{message()}</Text></div>}</Show>
|
|
227
|
+
<Command.Empty>{theme.messages().noResults}</Command.Empty>
|
|
228
|
+
<Show when={recents().length}><Command.Group heading={theme.messages().recentCommands}><For each={recents()}>{item}</For></Command.Group></Show>
|
|
229
|
+
<For each={groups()}>{group => <Command.Group heading={group}><For each={commands().filter(command => command.group === group && !recentSet().has(command.id))}>{item}</For></Command.Group>}</For>
|
|
230
|
+
</Command.List>
|
|
231
|
+
</Command>
|
|
232
|
+
</KobalteDialog.Content>
|
|
233
|
+
</KobalteDialog.Portal>}</Show></KobalteDialog.Root>;
|
|
234
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { JSX } from "solid-js";
|
|
2
|
+
import { AlertDialog } from "./AlertDialog.tsx";
|
|
3
|
+
import type { AlertDialogProps } from "./AlertDialog.tsx";
|
|
4
|
+
import { Button } from "./Button.tsx";
|
|
5
|
+
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
6
|
+
|
|
7
|
+
export interface ConfirmDialogProps extends Omit<AlertDialogProps, "children" | "footer" | "trigger" | "initialFocus" | "closeLabel" | "dismissible" | "defaultOpen" | "onOpenChange"> {
|
|
8
|
+
open: boolean;
|
|
9
|
+
onConfirm: () => void;
|
|
10
|
+
onCancel: () => void;
|
|
11
|
+
confirmLabel?: string;
|
|
12
|
+
cancelLabel?: string;
|
|
13
|
+
tone?: "accent" | "danger";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function ConfirmDialog(props: ConfirmDialogProps): JSX.Element {
|
|
17
|
+
const theme = useTheme();
|
|
18
|
+
return <AlertDialog title={props.title} description={props.description} open={props.open}
|
|
19
|
+
{...(props.contentId === undefined ? {} : { contentId: props.contentId })}
|
|
20
|
+
{...(props.class === undefined ? {} : { class: props.class })}
|
|
21
|
+
{...(props.returnFocus === undefined ? {} : { returnFocus: props.returnFocus })}
|
|
22
|
+
{...(props.shortcutScope === undefined ? {} : { shortcutScope: props.shortcutScope })}
|
|
23
|
+
closeLabel={props.cancelLabel ?? theme.messages().cancel} onOpenChange={next => { if (!next) props.onCancel(); }}
|
|
24
|
+
footer={<Button variant="solid" tone={props.tone ?? "accent"} onClick={props.onConfirm}>{props.confirmLabel ?? theme.messages().confirm}</Button>} />;
|
|
25
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { MenuContent, MenuPortal, MenuRoot } from "@kobalte/core/menu";
|
|
2
|
+
import { Polymorphic } from "@kobalte/core/polymorphic";
|
|
3
|
+
import { Show, createEffect, createMemo, createSignal, createUniqueId, onCleanup, splitProps } from "solid-js";
|
|
4
|
+
import type { JSX } from "solid-js";
|
|
5
|
+
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
6
|
+
import { cn } from "../utils/cn.ts";
|
|
7
|
+
import { MenuItems, validateMenuTree } from "./DropdownMenu.tsx";
|
|
8
|
+
import type { MenuItem } from "./DropdownMenu.tsx";
|
|
9
|
+
import { createMenuFocusRecovery } from "./menu-focus.ts";
|
|
10
|
+
import { useShortcutKeyboardOwner } from "./ShortcutProvider.tsx";
|
|
11
|
+
|
|
12
|
+
interface ContextMenuOptions {
|
|
13
|
+
/** Shared menu model. An empty collection leaves the native browser menu available. */
|
|
14
|
+
readonly items: readonly MenuItem[];
|
|
15
|
+
readonly disabled?: boolean;
|
|
16
|
+
readonly onOpenChange?: (open: boolean) => void;
|
|
17
|
+
readonly menuClass?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ContextMenuProps extends ContextMenuOptions, JSX.HTMLAttributes<HTMLElement> {
|
|
21
|
+
/** Supported native trigger semantics. */
|
|
22
|
+
readonly as?: "div" | "tr" | "li";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function callHandler(handler: unknown, event: MouseEvent): void {
|
|
26
|
+
if (typeof handler === "function") handler(event);
|
|
27
|
+
else if (Array.isArray(handler) && typeof handler[0] === "function") handler[0](handler[1], event);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A pointer/keyboard context menu whose trigger stays the requested native element. */
|
|
31
|
+
export function ContextMenu(props: ContextMenuProps): JSX.Element {
|
|
32
|
+
const theme = useTheme();
|
|
33
|
+
const id = createUniqueId();
|
|
34
|
+
const [local, triggerProps] = splitProps(props, ["as", "items", "disabled", "onOpenChange", "menuClass", "children"]);
|
|
35
|
+
const items = createMemo(() => {
|
|
36
|
+
validateMenuTree(local.items);
|
|
37
|
+
return local.items;
|
|
38
|
+
});
|
|
39
|
+
const unavailable = () => local.disabled === true || items().length === 0;
|
|
40
|
+
const [open, setOpen] = createSignal(false);
|
|
41
|
+
const [anchor, setAnchor] = createSignal({ x: 0, y: 0 });
|
|
42
|
+
const change = (next: boolean): void => {
|
|
43
|
+
if (next === open() || (next && unavailable())) return;
|
|
44
|
+
setOpen(next);
|
|
45
|
+
local.onOpenChange?.(next);
|
|
46
|
+
};
|
|
47
|
+
const [content, setContent] = createSignal<HTMLElement>();
|
|
48
|
+
useShortcutKeyboardOwner(content, open);
|
|
49
|
+
createMenuFocusRecovery(content, open);
|
|
50
|
+
createEffect(() => { if (open()) onCleanup(theme.layers.register(id)); });
|
|
51
|
+
const layer = createMemo<number>(previous => open() ? theme.layers.zIndex(id) : previous ?? 100);
|
|
52
|
+
const triggerId = () => triggerProps.id ?? `${id}-trigger`;
|
|
53
|
+
function restoreTriggerFocus(): void {
|
|
54
|
+
queueMicrotask(() => {
|
|
55
|
+
const trigger = document.getElementById(triggerId());
|
|
56
|
+
if (trigger instanceof HTMLElement && trigger.isConnected) trigger.focus({ preventScroll: true });
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
createEffect(() => {
|
|
60
|
+
if (!open()) return;
|
|
61
|
+
const listener = (event: KeyboardEvent): void => {
|
|
62
|
+
if (event.key === "Escape" && theme.layers.isTop(id)) restoreTriggerFocus();
|
|
63
|
+
};
|
|
64
|
+
document.addEventListener("keydown", listener, true);
|
|
65
|
+
onCleanup(() => document.removeEventListener("keydown", listener, true));
|
|
66
|
+
});
|
|
67
|
+
return <MenuRoot id={id} open={open()} onOpenChange={change} getAnchorRect={anchor} modal={false} gutter={2} shift={2} placement={theme.state().direction === "rtl" ? "left-start" : "right-start"}>
|
|
68
|
+
<Polymorphic as={local.as ?? "div"} {...triggerProps} id={triggerId()} aria-haspopup={unavailable() ? undefined : "menu"} aria-expanded={local.as === "tr" || unavailable() ? undefined : open()}
|
|
69
|
+
onContextMenu={(event: MouseEvent) => {
|
|
70
|
+
callHandler(triggerProps.onContextMenu, event);
|
|
71
|
+
if (event.defaultPrevented || unavailable()) return;
|
|
72
|
+
event.preventDefault();
|
|
73
|
+
event.stopPropagation();
|
|
74
|
+
const current = event.currentTarget;
|
|
75
|
+
const bounds = current instanceof Element ? current.getBoundingClientRect() : undefined;
|
|
76
|
+
setAnchor(event.clientX || event.clientY || !bounds ? { x: event.clientX, y: event.clientY } : { x: bounds.x, y: bounds.bottom });
|
|
77
|
+
change(true);
|
|
78
|
+
}}>{local.children}</Polymorphic>
|
|
79
|
+
<Show when={unavailable() ? undefined : theme.portal()}>{target => <MenuPortal mount={target()}>
|
|
80
|
+
<MenuContent ref={setContent} class={cn("sheen-menu", local.menuClass)} data-kb-top-layer="true" aria-hidden={!open() || undefined} inert={!open()} style={{ "z-index": layer() }}
|
|
81
|
+
onCloseAutoFocus={() => queueMicrotask(() => {
|
|
82
|
+
const trigger = document.getElementById(triggerId());
|
|
83
|
+
const active = document.activeElement;
|
|
84
|
+
if (trigger instanceof HTMLElement && trigger.isConnected && (active === document.body || active === null || (content()?.contains(active) ?? false))) trigger.focus({ preventScroll: true });
|
|
85
|
+
})}
|
|
86
|
+
onKeyDown={event => {
|
|
87
|
+
if (!event.defaultPrevented && event.key === "Escape" && open() && theme.layers.isTop(id)) {
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
change(false);
|
|
90
|
+
}
|
|
91
|
+
}}
|
|
92
|
+
onEscapeKeyDown={event => {
|
|
93
|
+
if (!theme.layers.isTop(id)) event.preventDefault();
|
|
94
|
+
else restoreTriggerFocus();
|
|
95
|
+
}}>
|
|
96
|
+
<MenuItems items={items()} />
|
|
97
|
+
</MenuContent>
|
|
98
|
+
</MenuPortal>}</Show>
|
|
99
|
+
</MenuRoot>;
|
|
100
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { splitProps } from "solid-js";
|
|
2
|
+
import type { JSX } from "solid-js";
|
|
3
|
+
import { cn } from "../utils/cn.ts";
|
|
4
|
+
|
|
5
|
+
export interface DescriptionListProps extends JSX.HTMLAttributes<HTMLDListElement> {
|
|
6
|
+
layout?: "stacked" | "columns";
|
|
7
|
+
}
|
|
8
|
+
export type DescriptionTermProps = JSX.HTMLAttributes<HTMLElement>;
|
|
9
|
+
export interface DescriptionDetailsProps extends JSX.HTMLAttributes<HTMLElement> {
|
|
10
|
+
numeric?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function DescriptionList(props: DescriptionListProps): JSX.Element {
|
|
14
|
+
const [local, others] = splitProps(props, ["class", "layout"]);
|
|
15
|
+
return <dl {...others} class={cn("sheen-description-list", local.class)} data-layout={local.layout ?? "stacked"} />;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function DescriptionTerm(props: DescriptionTermProps): JSX.Element {
|
|
19
|
+
const [local, others] = splitProps(props, ["class"]);
|
|
20
|
+
return <dt {...others} class={cn("sheen-description-term", local.class)} />;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function DescriptionDetails(props: DescriptionDetailsProps): JSX.Element {
|
|
24
|
+
const [local, others] = splitProps(props, ["class", "numeric"]);
|
|
25
|
+
return <dd {...others} class={cn("sheen-description-details", local.class)} data-numeric={local.numeric || undefined} />;
|
|
26
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as KobalteDialog from "@kobalte/core/dialog";
|
|
2
|
+
import type { JSX, ParentProps } from "solid-js";
|
|
3
|
+
import { Show, createEffect, createMemo, createSignal, createUniqueId, onCleanup } from "solid-js";
|
|
4
|
+
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
5
|
+
import { Button } from "./Button.tsx";
|
|
6
|
+
import { buttonVariants } from "./button-variants.ts";
|
|
7
|
+
import { cn } from "../utils/cn.ts";
|
|
8
|
+
import { useModalShortcutScope } from "./ShortcutProvider.tsx";
|
|
9
|
+
|
|
10
|
+
export interface DialogProps extends ParentProps {
|
|
11
|
+
title: string;
|
|
12
|
+
contentId?: string;
|
|
13
|
+
trigger?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
open?: boolean;
|
|
16
|
+
defaultOpen?: boolean;
|
|
17
|
+
onOpenChange?: (open: boolean) => void;
|
|
18
|
+
dismissible?: boolean;
|
|
19
|
+
closeLabel?: string;
|
|
20
|
+
initialFocus?: () => HTMLElement | undefined;
|
|
21
|
+
returnFocus?: () => HTMLElement | undefined;
|
|
22
|
+
shortcutScope?: string;
|
|
23
|
+
class?: string;
|
|
24
|
+
footer?: JSX.Element;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function ModalFrame(props: DialogProps & { alert?: boolean }): JSX.Element {
|
|
28
|
+
const theme = useTheme();
|
|
29
|
+
const [uncontrolled, setUncontrolled] = createSignal(props.defaultOpen ?? false);
|
|
30
|
+
const open = () => props.open === undefined ? uncontrolled() : props.open;
|
|
31
|
+
const dismissible = () => props.dismissible ?? true;
|
|
32
|
+
const change = (next: boolean) => {
|
|
33
|
+
if (!next && !dismissible()) return;
|
|
34
|
+
if (next === open()) return;
|
|
35
|
+
if (props.open === undefined) setUncontrolled(next);
|
|
36
|
+
props.onOpenChange?.(next);
|
|
37
|
+
};
|
|
38
|
+
const id = createUniqueId();
|
|
39
|
+
useModalShortcutScope(() => props.shortcutScope ?? `dialog:${id}`, open);
|
|
40
|
+
let content: HTMLDivElement | undefined;
|
|
41
|
+
let closeButton: HTMLButtonElement | undefined;
|
|
42
|
+
createEffect(() => {
|
|
43
|
+
if (open()) onCleanup(theme.layers.register(id));
|
|
44
|
+
});
|
|
45
|
+
const layer = createMemo<number>(previous => open() ? theme.layers.zIndex(id) : previous ?? 100);
|
|
46
|
+
return <KobalteDialog.Root open={open()} onOpenChange={change}>
|
|
47
|
+
<Show when={props.trigger}><KobalteDialog.Trigger class={buttonVariants({ variant: "outline" })} data-variant="outline">{props.trigger}</KobalteDialog.Trigger></Show>
|
|
48
|
+
<Show when={theme.portal()}>{target => <KobalteDialog.Portal mount={target()}>
|
|
49
|
+
<KobalteDialog.Overlay class="sheen-dialog-overlay" style={{ "z-index": layer() }} />
|
|
50
|
+
<KobalteDialog.Content {...(props.contentId === undefined ? {} : { id: props.contentId })} ref={element => { content = element; }} role={props.alert ? "alertdialog" : "dialog"} aria-hidden={!open() || undefined} inert={!open()} class={cn("sheen-dialog", props.class)} style={{ "z-index": layer() + 1 }}
|
|
51
|
+
onEscapeKeyDown={event => { if (!theme.layers.isTop(id) || !dismissible()) event.preventDefault(); }}
|
|
52
|
+
onPointerDownOutside={event => { if (props.alert || !dismissible() || !theme.layers.isTop(id)) event.preventDefault(); }}
|
|
53
|
+
onOpenAutoFocus={event => {
|
|
54
|
+
const target = props.initialFocus?.() ?? (props.alert ? closeButton : undefined);
|
|
55
|
+
if (target?.isConnected && content?.contains(target) && !target.matches(":disabled,[inert]")) {
|
|
56
|
+
target.focus({ preventScroll: true });
|
|
57
|
+
if (target.ownerDocument.activeElement === target) event.preventDefault();
|
|
58
|
+
}
|
|
59
|
+
}}
|
|
60
|
+
onCloseAutoFocus={event => {
|
|
61
|
+
const target = props.returnFocus?.();
|
|
62
|
+
if (target?.isConnected && !target.matches(":disabled,[inert]")) {
|
|
63
|
+
target.focus({ preventScroll: true });
|
|
64
|
+
if (target.ownerDocument.activeElement === target) event.preventDefault();
|
|
65
|
+
}
|
|
66
|
+
}}>
|
|
67
|
+
<div class="sheen-dialog-header">
|
|
68
|
+
<KobalteDialog.Title>{props.title}</KobalteDialog.Title>
|
|
69
|
+
<Show when={props.description}><KobalteDialog.Description>{props.description}</KobalteDialog.Description></Show>
|
|
70
|
+
</div>
|
|
71
|
+
<div class="sheen-dialog-body">{props.children}</div>
|
|
72
|
+
<div class="sheen-dialog-footer">
|
|
73
|
+
<KobalteDialog.CloseButton as={Button} ref={element => { closeButton = element; }} disabled={!dismissible()} aria-label={props.closeLabel ?? theme.messages().close}>{props.closeLabel ?? theme.messages().close}</KobalteDialog.CloseButton>
|
|
74
|
+
{props.footer}
|
|
75
|
+
</div>
|
|
76
|
+
</KobalteDialog.Content>
|
|
77
|
+
</KobalteDialog.Portal>}</Show>
|
|
78
|
+
</KobalteDialog.Root>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function Dialog(props: DialogProps): JSX.Element { return <ModalFrame {...props} />; }
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { JSX } from "solid-js";
|
|
2
|
+
import { ModalFrame } from "./Dialog.tsx";
|
|
3
|
+
import type { DialogProps } from "./Dialog.tsx";
|
|
4
|
+
import { cn } from "../utils/cn.ts";
|
|
5
|
+
|
|
6
|
+
export type DrawerSide = "start" | "end";
|
|
7
|
+
|
|
8
|
+
export interface DrawerProps extends DialogProps {
|
|
9
|
+
side?: DrawerSide;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function panelClass(kind: "drawer" | "sheet", props: DrawerProps): string {
|
|
13
|
+
const side = props.side ?? "end";
|
|
14
|
+
if (side !== "start" && side !== "end") throw new Error(`${kind} side must be start or end`);
|
|
15
|
+
return cn("sheen-drawer", `sheen-drawer-${side}`, `sheen-${kind}`, props.class);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function Drawer(props: DrawerProps): JSX.Element {
|
|
19
|
+
return <ModalFrame {...props} class={panelClass("drawer", props)} />;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type SheetProps = DrawerProps;
|
|
23
|
+
|
|
24
|
+
export function Sheet(props: SheetProps): JSX.Element {
|
|
25
|
+
return <ModalFrame {...props} class={panelClass("sheet", props)} />;
|
|
26
|
+
}
|