@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
package/src/metadata.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Build-time documentation data. Never imported by the component runtime entry point. */
|
|
2
|
+
export interface PropMetadata {
|
|
3
|
+
readonly description: string;
|
|
4
|
+
readonly default?: string | number | boolean | null;
|
|
5
|
+
readonly control?: { readonly kind: "boolean" | "text" } | { readonly kind: "select"; readonly values: readonly (string | number | boolean | null)[] };
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type ComposerMetadataParentRegion = "root" | "topbar" | "sidebar" | "page-header" | "toolbar" | "main-grid" | "details-panel" | "status-bar" | "overlays";
|
|
9
|
+
|
|
10
|
+
export interface ComposerMetadata {
|
|
11
|
+
readonly allowedParentRegions: readonly ComposerMetadataParentRegion[];
|
|
12
|
+
readonly acceptedChildRegions: readonly string[];
|
|
13
|
+
readonly editableSafeProps: readonly string[];
|
|
14
|
+
readonly fixtureFactory: string;
|
|
15
|
+
readonly codeGenerationAdapter: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const composerMetadataParentRegions: readonly ComposerMetadataParentRegion[] = ["root", "topbar", "sidebar", "page-header", "toolbar", "main-grid", "details-panel", "status-bar", "overlays"];
|
|
19
|
+
|
|
20
|
+
function composerParentRegions(value: unknown): value is ComposerMetadataParentRegion[] {
|
|
21
|
+
return strings(value) && value.every(candidate => composerMetadataParentRegions.some(region => region === candidate));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ComponentMetadata {
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly package: string;
|
|
27
|
+
readonly category: string;
|
|
28
|
+
readonly summary: string;
|
|
29
|
+
readonly props: Readonly<Record<string, PropMetadata>>;
|
|
30
|
+
readonly tokens: readonly string[];
|
|
31
|
+
readonly a11y: { readonly role: string; readonly keyboard: readonly string[] };
|
|
32
|
+
readonly examples: readonly { readonly title: string; readonly code: string; readonly imports?: string; readonly setup?: string }[];
|
|
33
|
+
readonly guidance: { readonly do: readonly string[]; readonly dont: readonly string[] };
|
|
34
|
+
readonly composer?: ComposerMetadata;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function defineMeta<Props>(metadata: Omit<ComponentMetadata, "props"> & { readonly props: Partial<Record<keyof Props, PropMetadata>> }): ComponentMetadata {
|
|
38
|
+
if (!isComponentMetadata(metadata)) throw new Error("Invalid component metadata");
|
|
39
|
+
return Object.freeze(metadata);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function record(value: unknown): value is Record<string, unknown> { return typeof value === "object" && value !== null && !Array.isArray(value); }
|
|
43
|
+
function text(value: unknown): value is string { return typeof value === "string" && value.trim().length > 0; }
|
|
44
|
+
function strings(value: unknown): value is string[] { return Array.isArray(value) && value.every(text); }
|
|
45
|
+
function scalar(value: unknown): boolean { return value === null || typeof value === "string" || typeof value === "boolean" || (typeof value === "number" && Number.isFinite(value)); }
|
|
46
|
+
|
|
47
|
+
export function isComponentMetadata(value: unknown): value is ComponentMetadata {
|
|
48
|
+
if (!record(value) || !text(value.name) || !text(value.package) || !text(value.category) || !text(value.summary) || !record(value.props)) return false;
|
|
49
|
+
for (const prop of Object.values(value.props)) {
|
|
50
|
+
if (!record(prop) || !text(prop.description) || ("default" in prop && !scalar(prop.default))) return false;
|
|
51
|
+
if (prop.control !== undefined) {
|
|
52
|
+
if (!record(prop.control)) return false;
|
|
53
|
+
if (prop.control.kind === "select") {
|
|
54
|
+
if (!Array.isArray(prop.control.values) || !prop.control.values.length || !prop.control.values.every(scalar)) return false;
|
|
55
|
+
} else if (prop.control.kind !== "text" && prop.control.kind !== "boolean") return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const composer = value.composer;
|
|
59
|
+
const validComposer = composer === undefined || (record(composer)
|
|
60
|
+
&& composerParentRegions(composer.allowedParentRegions) && composer.allowedParentRegions.length > 0
|
|
61
|
+
&& strings(composer.acceptedChildRegions) && strings(composer.editableSafeProps)
|
|
62
|
+
&& text(composer.fixtureFactory) && text(composer.codeGenerationAdapter));
|
|
63
|
+
return validComposer && strings(value.tokens) && record(value.a11y) && text(value.a11y.role) && strings(value.a11y.keyboard)
|
|
64
|
+
&& Array.isArray(value.examples) && value.examples.length > 0 && value.examples.every(example => record(example) && text(example.title) && text(example.code) && (example.imports === undefined || typeof example.imports === "string") && (example.setup === undefined || typeof example.setup === "string"))
|
|
65
|
+
&& record(value.guidance) && strings(value.guidance.do) && strings(value.guidance.dont);
|
|
66
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export { createShortcutRegistry } from "./utils/shortcut-registry.ts";
|
|
2
|
+
export type { PendingShortcut, ShortcutAction, ShortcutBinding, ShortcutDefinition, ShortcutInput, ShortcutRegistryOptions } from "./utils/shortcut-registry.ts";
|
|
3
|
+
export { ShortcutProvider, useShortcut, usePendingShortcut, useShortcutBindings, useShortcutCommands } from "./primitives/ShortcutProvider.tsx";
|
|
4
|
+
export type { ShortcutProviderProps } from "./primitives/ShortcutProvider.tsx";
|
|
5
|
+
export { ShortcutSheet } from "./primitives/ShortcutSheet.tsx";
|
|
6
|
+
export type { ShortcutSheetProps } from "./primitives/ShortcutSheet.tsx";
|
|
7
|
+
export { ShortcutPending } from "./primitives/ShortcutPending.tsx";
|
|
8
|
+
export type { ShortcutPendingProps } from "./primitives/ShortcutPending.tsx";
|
|
9
|
+
export { ShortcutScope } from "./primitives/ShortcutScope.tsx";
|
|
10
|
+
export type { ShortcutScopeProps } from "./primitives/ShortcutScope.tsx";
|
|
11
|
+
export { Breadcrumb } from "./primitives/Breadcrumb.tsx";
|
|
12
|
+
export type { BreadcrumbProps, BreadcrumbEntry } from "./primitives/Breadcrumb.tsx";
|
|
13
|
+
export { Collapsible } from "./primitives/Collapsible.tsx";
|
|
14
|
+
export type { CollapsibleProps } from "./primitives/Collapsible.tsx";
|
|
15
|
+
export { Accordion, AccordionItem } from "./primitives/Accordion.tsx";
|
|
16
|
+
export type { AccordionProps, AccordionItemProps } from "./primitives/Accordion.tsx";
|
|
17
|
+
export { Tabs } from "./primitives/Tabs.tsx";
|
|
18
|
+
export type { TabsProps, TabOption } from "./primitives/Tabs.tsx";
|
|
19
|
+
export { NavList, NavItem } from "./primitives/NavList.tsx";
|
|
20
|
+
export type { NavListProps, NavItemProps } from "./primitives/NavList.tsx";
|
|
21
|
+
export { ScrollArea } from "./primitives/ScrollArea.tsx";
|
|
22
|
+
export type { ScrollAreaProps } from "./primitives/ScrollArea.tsx";
|
|
23
|
+
export { Pagination } from "./primitives/Pagination.tsx";
|
|
24
|
+
export type { PaginationProps } from "./primitives/Pagination.tsx";
|
|
25
|
+
export { Tree, TreeItem } from "./primitives/Tree.tsx";
|
|
26
|
+
export type { TreeProps, TreeItemProps, TreeSelectionMode } from "./primitives/Tree.tsx";
|
|
27
|
+
export { Resizable, ResizablePanel, ResizableHandle } from "./primitives/Resizable.tsx";
|
|
28
|
+
export type { ResizableProps, ResizablePanelProps, ResizableHandleProps, ResizablePersistence } from "./primitives/Resizable.tsx";
|
|
29
|
+
export { Stepper } from "./primitives/Stepper.tsx";
|
|
30
|
+
export type { StepperProps, StepperStep, StepperStatusStep, StepperLinkStep, StepperActionStep } from "./primitives/Stepper.tsx";
|
package/src/overlays.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { Dialog } from "./primitives/Dialog.tsx";
|
|
2
|
+
export type { DialogProps } from "./primitives/Dialog.tsx";
|
|
3
|
+
export { Drawer, Sheet } from "./primitives/Drawer.tsx";
|
|
4
|
+
export type { DrawerProps, DrawerSide, SheetProps } from "./primitives/Drawer.tsx";
|
|
5
|
+
export { AlertDialog } from "./primitives/AlertDialog.tsx";
|
|
6
|
+
export type { AlertDialogProps } from "./primitives/AlertDialog.tsx";
|
|
7
|
+
export { ConfirmDialog } from "./primitives/ConfirmDialog.tsx";
|
|
8
|
+
export type { ConfirmDialogProps } from "./primitives/ConfirmDialog.tsx";
|
|
9
|
+
export { createConfirm } from "./primitives/create-confirm.tsx";
|
|
10
|
+
export type { ConfirmController, ConfirmOptions } from "./primitives/create-confirm.tsx";
|
|
11
|
+
export { Tooltip } from "./primitives/Tooltip.tsx";
|
|
12
|
+
export type { TooltipProps } from "./primitives/Tooltip.tsx";
|
|
13
|
+
export { LinkTooltip } from "./primitives/LinkTooltip.tsx";
|
|
14
|
+
export type { LinkTooltipProps } from "./primitives/LinkTooltip.tsx";
|
|
15
|
+
export { Popover } from "./primitives/Popover.tsx";
|
|
16
|
+
export type { PopoverProps } from "./primitives/Popover.tsx";
|
|
17
|
+
export { DropdownMenu } from "./primitives/DropdownMenu.tsx";
|
|
18
|
+
export type { DropdownMenuProps, MenuItem, MenuAction, MenuCheckbox, MenuRadioGroup, MenuRadioOption, MenuSubmenu, MenuSeparator } from "./primitives/DropdownMenu.tsx";
|
|
19
|
+
export { ContextMenu } from "./primitives/ContextMenu.tsx";
|
|
20
|
+
export type { ContextMenuProps } from "./primitives/ContextMenu.tsx";
|
|
21
|
+
export { CommandPalette, commandPaletteFilter } from "./primitives/CommandPalette.tsx";
|
|
22
|
+
export type { CommandPaletteProps, CommandPaletteCommand, CommandPaletteSource, CommandPaletteStaticSource, CommandPaletteRemoteSource, CommandPaletteRecents } from "./primitives/CommandPalette.tsx";
|
|
23
|
+
export { createToaster } from "./primitives/create-toaster.ts";
|
|
24
|
+
export { Toast } from "./primitives/Toast.tsx";
|
|
25
|
+
export type { ToastProps } from "./primitives/Toast.tsx";
|
|
26
|
+
export { Toaster } from "./primitives/Toaster.tsx";
|
|
27
|
+
export type { ToasterProps } from "./primitives/Toaster.tsx";
|
|
28
|
+
export type { ToastId, ToastAction, ToastOptions, ToastNotification, ToastActionResult, ToastController } from "./primitives/create-toaster.ts";
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import * as Primitive from "@kobalte/core/accordion";
|
|
2
|
+
import { createContext, createEffect, createMemo, createSignal, createUniqueId, onCleanup, onMount, splitProps, useContext } from "solid-js";
|
|
3
|
+
import type { Accessor, JSX } from "solid-js";
|
|
4
|
+
import { Button } from "./Button.tsx";
|
|
5
|
+
import { cn } from "../utils/cn.ts";
|
|
6
|
+
|
|
7
|
+
export interface AccordionProps extends Omit<JSX.HTMLAttributes<HTMLDivElement>, "onChange"> {
|
|
8
|
+
value?: string[];
|
|
9
|
+
defaultValue?: string[];
|
|
10
|
+
onValueChange?: (value: string[]) => void;
|
|
11
|
+
multiple?: boolean;
|
|
12
|
+
collapsible?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface AccordionItemProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
15
|
+
value: string;
|
|
16
|
+
label: string;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
headingLevel?: 2 | 3 | 4 | 5 | 6;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const AccordionOptions = createContext<{
|
|
22
|
+
multiple: Accessor<boolean>;
|
|
23
|
+
collapsible: Accessor<boolean>;
|
|
24
|
+
values: Set<string>;
|
|
25
|
+
onKeyDown: Accessor<JSX.HTMLAttributes<HTMLDivElement>["onKeyDown"]>;
|
|
26
|
+
}>();
|
|
27
|
+
|
|
28
|
+
function AccordionContainer(props: JSX.HTMLAttributes<HTMLDivElement>): JSX.Element {
|
|
29
|
+
const options = useContext(AccordionOptions);
|
|
30
|
+
const [local, others] = splitProps(props, ["onKeyDown", "ref"]);
|
|
31
|
+
let root: HTMLDivElement | undefined;
|
|
32
|
+
const headers = (element: HTMLDivElement) => [...element.querySelectorAll<HTMLButtonElement>("[data-sheen-accordion-trigger]")]
|
|
33
|
+
.filter(header => header.closest("[data-sheen-accordion]") === element);
|
|
34
|
+
onMount(() => {
|
|
35
|
+
const element = root;
|
|
36
|
+
if (!element) return;
|
|
37
|
+
let previous = headers(element);
|
|
38
|
+
let focused: HTMLElement | undefined;
|
|
39
|
+
const recordFocus = () => {
|
|
40
|
+
const active = element.ownerDocument.activeElement;
|
|
41
|
+
focused = active instanceof HTMLElement && element.contains(active) ? active : undefined;
|
|
42
|
+
};
|
|
43
|
+
recordFocus();
|
|
44
|
+
element.ownerDocument.addEventListener("focusin", recordFocus);
|
|
45
|
+
const observer = new MutationObserver(() => {
|
|
46
|
+
const next = headers(element);
|
|
47
|
+
const active = element.ownerDocument.activeElement;
|
|
48
|
+
const previousFocus = focused;
|
|
49
|
+
if (element.isConnected && previousFocus && active === element.ownerDocument.body) {
|
|
50
|
+
const eligible = (target: HTMLElement) => target.isConnected && !target.matches(":disabled") && !target.closest("[inert], [hidden]") && target.getClientRects().length > 0;
|
|
51
|
+
const retained = element.contains(previousFocus) && eligible(previousFocus) ? previousFocus : undefined;
|
|
52
|
+
const previousIndex = previous.findIndex(header => header.closest(".sheen-accordion-item")?.contains(previousFocus));
|
|
53
|
+
if (previousIndex >= 0) {
|
|
54
|
+
const index = Math.min(previousIndex, next.length);
|
|
55
|
+
const nearest = next.slice(index).find(eligible) ?? next.slice(0, index).reverse().find(eligible);
|
|
56
|
+
(retained ?? nearest ?? element).focus({ preventScroll: true });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
previous = next;
|
|
60
|
+
});
|
|
61
|
+
observer.observe(element, { childList: true, subtree: true, attributes: true, attributeFilter: ["disabled", "hidden", "inert"] });
|
|
62
|
+
onCleanup(() => {
|
|
63
|
+
observer.disconnect();
|
|
64
|
+
element.ownerDocument.removeEventListener("focusin", recordFocus);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
const onKeyDown: JSX.EventHandler<HTMLDivElement, KeyboardEvent> = event => {
|
|
68
|
+
const handler = options?.onKeyDown();
|
|
69
|
+
if (typeof handler === "function") handler(event);
|
|
70
|
+
else if (handler) handler[0](handler[1], event);
|
|
71
|
+
if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
|
|
72
|
+
const target = event.target;
|
|
73
|
+
if (!(target instanceof HTMLButtonElement) || !target.hasAttribute("data-sheen-accordion-trigger") || target.closest("[data-sheen-accordion]") !== event.currentTarget) return;
|
|
74
|
+
const triggers = headers(event.currentTarget).filter(element => !element.disabled);
|
|
75
|
+
const index = triggers.indexOf(target);
|
|
76
|
+
if (index < 0) return;
|
|
77
|
+
let next: HTMLButtonElement | undefined;
|
|
78
|
+
switch (event.key) {
|
|
79
|
+
case "ArrowDown": next = triggers[(index + 1) % triggers.length]; break;
|
|
80
|
+
case "ArrowUp": next = triggers[(index + triggers.length - 1) % triggers.length]; break;
|
|
81
|
+
case "Home": next = triggers[0]; break;
|
|
82
|
+
case "End": next = triggers.at(-1); break;
|
|
83
|
+
default: return;
|
|
84
|
+
}
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
next?.focus();
|
|
87
|
+
};
|
|
88
|
+
return <div {...others} ref={element => { root = element; if (typeof local.ref === "function") local.ref(element); }} tabIndex={others.tabIndex ?? -1} data-sheen-accordion="" onKeyDown={onKeyDown} />;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function Accordion(props: AccordionProps): JSX.Element {
|
|
92
|
+
const [local, others] = splitProps(props, ["value", "defaultValue", "onValueChange", "multiple", "collapsible", "class", "id", "ref", "onKeyDown", "onMouseDown", "onFocusIn", "onFocusOut"]);
|
|
93
|
+
const id = createUniqueId();
|
|
94
|
+
const [draft, setDraft] = createSignal(local.defaultValue ?? []);
|
|
95
|
+
const value = createMemo(() => {
|
|
96
|
+
const next = local.value ?? draft();
|
|
97
|
+
if (!local.multiple && next.length > 1) throw new Error("Accordion single mode accepts at most one expanded value");
|
|
98
|
+
if (new Set(next).size !== next.length) throw new Error("Accordion expanded values must be unique");
|
|
99
|
+
return next;
|
|
100
|
+
});
|
|
101
|
+
const options = { multiple: () => local.multiple ?? false, collapsible: () => local.collapsible ?? true, values: new Set<string>(), onKeyDown: () => local.onKeyDown };
|
|
102
|
+
const common = () => ({
|
|
103
|
+
...(local.ref === undefined ? {} : { ref: local.ref }),
|
|
104
|
+
...(local.onMouseDown === undefined ? {} : { onMouseDown: local.onMouseDown }),
|
|
105
|
+
...(local.onFocusIn === undefined ? {} : { onFocusIn: local.onFocusIn }),
|
|
106
|
+
...(local.onFocusOut === undefined ? {} : { onFocusOut: local.onFocusOut }),
|
|
107
|
+
});
|
|
108
|
+
return <AccordionOptions.Provider value={options}><Primitive.Root as={AccordionContainer} {...others} {...common()} id={local.id ?? `sheen-accordion-${id}`} class={cn("sheen-accordion", local.class)} value={value()}
|
|
109
|
+
onChange={next => { if (local.value === undefined) setDraft(next); local.onValueChange?.(next); }} multiple={options.multiple()} collapsible={options.collapsible()} /></AccordionOptions.Provider>;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function AccordionItem(props: AccordionItemProps): JSX.Element {
|
|
113
|
+
const context = Primitive.useAccordionContext();
|
|
114
|
+
const options = useContext(AccordionOptions);
|
|
115
|
+
if (!options) throw new Error("AccordionItem requires a sheen Accordion owner");
|
|
116
|
+
const [local, others] = splitProps(props, ["value", "label", "disabled", "headingLevel", "class", "id", "children"]);
|
|
117
|
+
const generatedId = createUniqueId();
|
|
118
|
+
const id = () => local.id ?? `sheen-accordion-item-${generatedId}`;
|
|
119
|
+
const open = () => context.listState().selectionManager().isSelected(local.value);
|
|
120
|
+
createMemo(() => {
|
|
121
|
+
const value = local.value;
|
|
122
|
+
if (!value.trim() || !local.label.trim()) throw new Error("AccordionItem requires nonempty values and labels");
|
|
123
|
+
if (options.values.has(value)) throw new Error(`Accordion duplicate item value: ${value}`);
|
|
124
|
+
options.values.add(value);
|
|
125
|
+
onCleanup(() => options.values.delete(value));
|
|
126
|
+
});
|
|
127
|
+
let trigger: HTMLButtonElement | undefined;
|
|
128
|
+
let content: HTMLDivElement | undefined;
|
|
129
|
+
const heading = (): "h2" | "h3" | "h4" | "h5" | "h6" => {
|
|
130
|
+
switch (local.headingLevel) { case 2: return "h2"; case 4: return "h4"; case 5: return "h5"; case 6: return "h6"; default: return "h3"; }
|
|
131
|
+
};
|
|
132
|
+
createEffect(() => {
|
|
133
|
+
if (!open() && content?.contains(content.ownerDocument.activeElement)) trigger?.focus({ preventScroll: true });
|
|
134
|
+
});
|
|
135
|
+
return <Primitive.Item {...others} id={id()} value={local.value} disabled={local.disabled ?? false} class={cn("sheen-accordion-item", local.class)}>
|
|
136
|
+
<Primitive.Header as={heading()} class="sheen-accordion-heading">
|
|
137
|
+
<Primitive.Trigger as={Button} ref={trigger} data-sheen-accordion-trigger="" id={`${id()}-trigger`} aria-controls={`${id()}-content`} aria-disabled={open() && !options.multiple() && !options.collapsible() || undefined} class="sheen-collapsible-trigger">
|
|
138
|
+
<span class="sheen-collapsible-indicator" aria-hidden="true" />{local.label}
|
|
139
|
+
</Primitive.Trigger>
|
|
140
|
+
</Primitive.Header>
|
|
141
|
+
<div ref={content} id={`${id()}-content`} class="sheen-collapsible-content" data-open={open()} aria-hidden={!open() || undefined} inert={!open()}>
|
|
142
|
+
<div class="sheen-collapsible-clip"><div class="sheen-collapsible-body">{local.children}</div></div>
|
|
143
|
+
</div>
|
|
144
|
+
</Primitive.Item>;
|
|
145
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { For, Show, createMemo, splitProps } from "solid-js";
|
|
2
|
+
import type { JSX } from "solid-js";
|
|
3
|
+
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
4
|
+
import type { Messages } from "../theme/messages.ts";
|
|
5
|
+
import { cn } from "../utils/cn.ts";
|
|
6
|
+
|
|
7
|
+
export type WorkflowState = "completed" | "current" | "upcoming" | "error";
|
|
8
|
+
|
|
9
|
+
export interface ActivityTimelineItem {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly title: string;
|
|
12
|
+
readonly description?: string;
|
|
13
|
+
readonly actor?: string;
|
|
14
|
+
readonly timestamp?: string;
|
|
15
|
+
readonly timeLabel?: string;
|
|
16
|
+
readonly state: WorkflowState;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ActivityTimelineProps extends Omit<JSX.OlHTMLAttributes<HTMLOListElement>, "children" | "ref"> {
|
|
20
|
+
ref?: HTMLOListElement | ((element: HTMLOListElement) => void);
|
|
21
|
+
label: string;
|
|
22
|
+
items: readonly ActivityTimelineItem[];
|
|
23
|
+
density?: "compact" | "default";
|
|
24
|
+
refreshing?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function stateLabel(state: WorkflowState, messages: Messages): string {
|
|
28
|
+
if (state === "completed") return messages.workflowCompleted;
|
|
29
|
+
if (state === "current") return messages.workflowCurrent;
|
|
30
|
+
if (state === "error") return messages.workflowError;
|
|
31
|
+
return messages.workflowUpcoming;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function marker(state: WorkflowState): string {
|
|
35
|
+
if (state === "completed") return "✓";
|
|
36
|
+
if (state === "current") return "●";
|
|
37
|
+
if (state === "error") return "!";
|
|
38
|
+
return "○";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A stable-ID chronological activity list with explicit non-color state labels. */
|
|
42
|
+
export function ActivityTimeline(props: ActivityTimelineProps): JSX.Element {
|
|
43
|
+
const theme = useTheme();
|
|
44
|
+
const [local, others] = splitProps(props, ["ref", "class", "label", "items", "density", "refreshing", "aria-label"]);
|
|
45
|
+
const byId = createMemo(() => {
|
|
46
|
+
const result = new Map<string, ActivityTimelineItem>();
|
|
47
|
+
for (const item of local.items) {
|
|
48
|
+
if (!item.id.trim()) throw new Error("ActivityTimeline: item IDs must be nonempty");
|
|
49
|
+
if (result.has(item.id)) throw new Error(`ActivityTimeline: duplicate item ID ${JSON.stringify(item.id)}`);
|
|
50
|
+
if (!item.title.trim()) throw new Error(`ActivityTimeline: title must be nonempty for ${JSON.stringify(item.id)}`);
|
|
51
|
+
if ((item.timestamp === undefined) !== (item.timeLabel === undefined) || (item.timestamp !== undefined && (!item.timestamp.trim() || !item.timeLabel?.trim()))) throw new Error(`ActivityTimeline: timestamp and timeLabel must be supplied together for ${JSON.stringify(item.id)}`);
|
|
52
|
+
result.set(item.id, item);
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
});
|
|
56
|
+
const ids = createMemo(() => [...byId().keys()]);
|
|
57
|
+
return <ol {...others} ref={element => { if (typeof local.ref === "function") local.ref(element); }} class={cn("sheen-activity-timeline", local.class)} aria-label={local["aria-label"] ?? local.label}
|
|
58
|
+
aria-busy={local.refreshing || undefined} data-density={local.density ?? "default"} data-refreshing={local.refreshing || undefined}>
|
|
59
|
+
<For each={ids()}>{id => {
|
|
60
|
+
const item = () => byId().get(id);
|
|
61
|
+
return <Show when={item()}>{current => <li class="sheen-activity-timeline-item" data-activity-id={id} data-state={current().state} aria-current={current().state === "current" ? "true" : undefined}>
|
|
62
|
+
<span class="sheen-workflow-marker" data-state={current().state} aria-hidden="true">{marker(current().state)}</span>
|
|
63
|
+
<article class="sheen-activity-timeline-content">
|
|
64
|
+
<header><strong>{current().title}</strong><span class="sheen-workflow-state">{stateLabel(current().state, theme.messages())}</span></header>
|
|
65
|
+
<Show when={current().description}>{description => <p>{description()}</p>}</Show>
|
|
66
|
+
<Show when={current().actor}>{actor => <span class="sheen-activity-timeline-actor">{actor()}</span>}</Show>
|
|
67
|
+
<Show when={current().timestamp && current().timeLabel}><time dateTime={current().timestamp}>{current().timeLabel}</time></Show>
|
|
68
|
+
</article>
|
|
69
|
+
</li>}</Show>;
|
|
70
|
+
}}</For>
|
|
71
|
+
</ol>;
|
|
72
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { JSX } from "solid-js";
|
|
2
|
+
import { ModalFrame } from "./Dialog.tsx";
|
|
3
|
+
import type { DialogProps } from "./Dialog.tsx";
|
|
4
|
+
|
|
5
|
+
export interface AlertDialogProps extends DialogProps { description: string }
|
|
6
|
+
|
|
7
|
+
/** Requires an explicit dismissal and initially focuses the safe close action. */
|
|
8
|
+
export function AlertDialog(props: AlertDialogProps): JSX.Element { return <ModalFrame {...props} alert />; }
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { For, Show, createEffect, createMemo, createSignal, on, onMount, splitProps } from "solid-js";
|
|
2
|
+
import type { JSX } from "solid-js";
|
|
3
|
+
import { useNumberFormatter } from "../theme/intl.ts";
|
|
4
|
+
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
5
|
+
import { cn } from "../utils/cn.ts";
|
|
6
|
+
|
|
7
|
+
export type AvatarSize = "sm" | "md" | "lg";
|
|
8
|
+
|
|
9
|
+
export interface AvatarProps extends Omit<JSX.HTMLAttributes<HTMLSpanElement>, "children"> {
|
|
10
|
+
label: string;
|
|
11
|
+
src?: string;
|
|
12
|
+
fallback?: string;
|
|
13
|
+
size?: AvatarSize;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function avatarFallback(label: string, explicit: string | undefined): string {
|
|
17
|
+
if (explicit !== undefined) {
|
|
18
|
+
if (!explicit.trim()) throw new Error("Avatar fallback must be nonempty when supplied");
|
|
19
|
+
return explicit;
|
|
20
|
+
}
|
|
21
|
+
return label.trim().split(/\s+/u).slice(0, 2).map(part => Array.from(part)[0] ?? "").join("").toUpperCase();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function Avatar(props: AvatarProps): JSX.Element {
|
|
25
|
+
const [local, forwarded] = splitProps(props, ["label", "src", "fallback", "size", "class"]);
|
|
26
|
+
if (!local.label?.trim()) throw new Error("Avatar requires a nonempty label");
|
|
27
|
+
const size = (): AvatarSize => {
|
|
28
|
+
const value = local.size ?? "md";
|
|
29
|
+
if (value !== "sm" && value !== "md" && value !== "lg") throw new Error("Avatar size is invalid");
|
|
30
|
+
return value;
|
|
31
|
+
};
|
|
32
|
+
const [failed, setFailed] = createSignal(false);
|
|
33
|
+
let image: HTMLImageElement | undefined;
|
|
34
|
+
createEffect(on(() => local.src, () => setFailed(false), { defer: true }));
|
|
35
|
+
onMount(() => {
|
|
36
|
+
if (image?.complete && image.naturalWidth === 0) setFailed(true);
|
|
37
|
+
});
|
|
38
|
+
const fallback = createMemo(() => avatarFallback(local.label, local.fallback));
|
|
39
|
+
return <span {...forwarded} class={cn("sheen-avatar", local.class)} role="img" aria-label={local.label} data-size={size()}>
|
|
40
|
+
<span class="sheen-avatar-fallback" aria-hidden="true">{fallback()}</span>
|
|
41
|
+
<Show when={local.src && !failed()}>
|
|
42
|
+
<img ref={image} class="sheen-avatar-image" src={local.src} alt="" draggable={false} onError={() => setFailed(true)} />
|
|
43
|
+
</Show>
|
|
44
|
+
</span>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface AvatarItem {
|
|
48
|
+
readonly id: string;
|
|
49
|
+
readonly label: string;
|
|
50
|
+
readonly src?: string;
|
|
51
|
+
readonly fallback?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface AvatarGroupProps extends Omit<JSX.HTMLAttributes<HTMLDivElement>, "children"> {
|
|
55
|
+
label: string;
|
|
56
|
+
avatars: readonly AvatarItem[];
|
|
57
|
+
max?: number;
|
|
58
|
+
size?: AvatarSize;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function AvatarGroup(props: AvatarGroupProps): JSX.Element {
|
|
62
|
+
const [local, forwarded] = splitProps(props, ["label", "avatars", "max", "size", "class"]);
|
|
63
|
+
if (!local.label?.trim()) throw new Error("AvatarGroup requires a nonempty label");
|
|
64
|
+
const theme = useTheme();
|
|
65
|
+
const formatter = useNumberFormatter();
|
|
66
|
+
const items = createMemo(() => {
|
|
67
|
+
const ids = new Set<string>();
|
|
68
|
+
for (const item of local.avatars) {
|
|
69
|
+
if (!item.id?.trim() || ids.has(item.id)) throw new Error("AvatarGroup IDs must be unique nonempty strings");
|
|
70
|
+
ids.add(item.id);
|
|
71
|
+
}
|
|
72
|
+
return local.avatars;
|
|
73
|
+
});
|
|
74
|
+
const maximum = (): number => {
|
|
75
|
+
const value = local.max ?? 5;
|
|
76
|
+
if (!Number.isSafeInteger(value) || value <= 0) throw new Error("AvatarGroup max must be a positive safe integer");
|
|
77
|
+
return value;
|
|
78
|
+
};
|
|
79
|
+
const visible = createMemo(() => items().slice(0, maximum()));
|
|
80
|
+
const hidden = createMemo(() => Math.max(0, items().length - visible().length));
|
|
81
|
+
return <div {...forwarded} class={cn("sheen-avatar-group", local.class)} role="group" aria-label={local.label}>
|
|
82
|
+
<For each={visible()}>{item => <Avatar label={item.label} {...(item.src === undefined ? {} : { src: item.src })} {...(item.fallback === undefined ? {} : { fallback: item.fallback })} {...(local.size === undefined ? {} : { size: local.size })} />}</For>
|
|
83
|
+
<Show when={hidden()}>{count => <span class="sheen-avatar sheen-avatar-overflow" data-size={local.size ?? "md"} aria-label={theme.messages().avatarOverflow.replaceAll("{count}", formatter().format(count()))}>+{formatter().format(count())}</span>}</Show>
|
|
84
|
+
</div>;
|
|
85
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { For, Show, createMemo, 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 { createLinkFocusRecovery } from "./link-focus.ts";
|
|
6
|
+
|
|
7
|
+
export interface BreadcrumbEntry {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly label: string;
|
|
10
|
+
readonly href?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface BreadcrumbProps extends Omit<JSX.HTMLAttributes<HTMLElement>, "children"> {
|
|
13
|
+
items: readonly BreadcrumbEntry[];
|
|
14
|
+
label?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function Breadcrumb(props: BreadcrumbProps): JSX.Element {
|
|
18
|
+
const theme = useTheme();
|
|
19
|
+
const [local, others] = splitProps(props, ["items", "label", "class", "ref"]);
|
|
20
|
+
let root: HTMLElement | undefined;
|
|
21
|
+
createLinkFocusRecovery(() => root);
|
|
22
|
+
const entries = createMemo(() => {
|
|
23
|
+
const result = new Map<string, BreadcrumbEntry>();
|
|
24
|
+
for (const [index, item] of local.items.entries()) {
|
|
25
|
+
if (!item.id.trim() || !item.label.trim()) throw new Error("Breadcrumb requires nonempty item IDs and labels");
|
|
26
|
+
if (result.has(item.id)) throw new Error(`Breadcrumb duplicate item ID: ${item.id}`);
|
|
27
|
+
if (index < local.items.length - 1 && !item.href?.trim()) throw new Error(`Breadcrumb ancestor requires href: ${item.id}`);
|
|
28
|
+
result.set(item.id, item);
|
|
29
|
+
}
|
|
30
|
+
if (!result.size) throw new Error("Breadcrumb requires at least the current page");
|
|
31
|
+
return result;
|
|
32
|
+
});
|
|
33
|
+
const current = () => local.items.at(-1)?.id;
|
|
34
|
+
return <nav aria-label={local.label ?? theme.messages().breadcrumb} {...others} ref={element => { root = element; if (typeof local.ref === "function") local.ref(element); }} tabIndex={others.tabIndex ?? -1} class={cn("sheen-breadcrumb", local.class)}>
|
|
35
|
+
<ol><For each={[...entries().keys()]}>{id => <li>
|
|
36
|
+
<Show when={id !== current()} fallback={<span aria-current="page">{entries().get(id)?.label}</span>}>
|
|
37
|
+
<a href={entries().get(id)?.href}>{entries().get(id)?.label}</a>
|
|
38
|
+
</Show>
|
|
39
|
+
</li>}</For></ol>
|
|
40
|
+
</nav>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { splitProps } from "solid-js";
|
|
2
|
+
import type { JSX } from "solid-js";
|
|
3
|
+
import { cn } from "../utils/cn.ts";
|
|
4
|
+
import { buttonVariants } from "./button-variants.ts";
|
|
5
|
+
import type { ButtonVariantProps } from "./button-variants.ts";
|
|
6
|
+
import { useShortcutAction } from "./ShortcutProvider.tsx";
|
|
7
|
+
import type { ShortcutAction } from "../utils/shortcut-registry.ts";
|
|
8
|
+
|
|
9
|
+
export interface ButtonProps extends JSX.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
10
|
+
variant?: NonNullable<ButtonVariantProps["variant"]>;
|
|
11
|
+
tone?: NonNullable<ButtonVariantProps["tone"]>;
|
|
12
|
+
size?: NonNullable<ButtonVariantProps["size"]>;
|
|
13
|
+
loading?: boolean;
|
|
14
|
+
shortcut?: ShortcutAction | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function Button(props: ButtonProps): JSX.Element {
|
|
18
|
+
const [local, others] = splitProps(props, ["class", "variant", "tone", "size", "loading", "disabled", "shortcut", "ref", "children"]);
|
|
19
|
+
let element: HTMLButtonElement | undefined;
|
|
20
|
+
const binding = useShortcutAction(() => local.shortcut, () => {
|
|
21
|
+
if (!local.disabled && !local.loading) element?.click();
|
|
22
|
+
});
|
|
23
|
+
return <button {...others} ref={node => { element = node; if (typeof local.ref === "function") local.ref(node); }} type={others.type ?? "button"}
|
|
24
|
+
class={cn(buttonVariants({ variant: local.variant, tone: local.tone, size: local.size }), local.class)}
|
|
25
|
+
data-variant={local.variant ?? "ghost"} data-tone={local.tone ?? "neutral"} data-size={local.size ?? "md"}
|
|
26
|
+
data-sheen-shortcut={binding()?.displayKeys} disabled={local.disabled || local.loading} aria-busy={local.loading || undefined}>{local.children}</button>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createMemo, splitProps } from "solid-js";
|
|
2
|
+
import type { JSX } from "solid-js";
|
|
3
|
+
import { cn } from "../utils/cn.ts";
|
|
4
|
+
|
|
5
|
+
export interface ButtonGroupProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
6
|
+
label: string;
|
|
7
|
+
orientation?: "horizontal" | "vertical";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Related actions, not a toolbar or a selection widget. */
|
|
11
|
+
export function ButtonGroup(props: ButtonGroupProps): JSX.Element {
|
|
12
|
+
const [local, others] = splitProps(props, ["label", "orientation", "class", "children"]);
|
|
13
|
+
const label = createMemo(() => {
|
|
14
|
+
if (!local.label.trim()) throw new Error("ButtonGroup requires a nonempty accessible label");
|
|
15
|
+
return local.label;
|
|
16
|
+
});
|
|
17
|
+
return <div {...others} role="group" aria-label={label()} class={cn("sheen-button-group", local.class)} data-orientation={local.orientation ?? "horizontal"}>{local.children}</div>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Show, createUniqueId, splitProps } from "solid-js";
|
|
2
|
+
import type { JSX } from "solid-js";
|
|
3
|
+
import { cn } from "../utils/cn.ts";
|
|
4
|
+
import { createBooleanInputState } from "./boolean-input-state.ts";
|
|
5
|
+
|
|
6
|
+
export interface CheckboxProps extends Omit<JSX.HTMLAttributes<HTMLDivElement>, "children" | "onChange" | "id" | "ref" | "onPointerDown"> {
|
|
7
|
+
id?: string;
|
|
8
|
+
ref?: HTMLDivElement | ((element: HTMLDivElement) => void);
|
|
9
|
+
onPointerDown?: NonNullable<JSX.HTMLAttributes<HTMLDivElement>["onPointerDown"]>;
|
|
10
|
+
label: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
error?: string;
|
|
13
|
+
checked?: boolean;
|
|
14
|
+
defaultChecked?: boolean;
|
|
15
|
+
indeterminate?: boolean;
|
|
16
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
readOnly?: boolean;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
name?: string;
|
|
21
|
+
form?: string | undefined;
|
|
22
|
+
value?: string;
|
|
23
|
+
inputRef?: (element: HTMLInputElement) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function createNativeBooleanControl(props: CheckboxProps, kind: "checkbox" | "switch"): JSX.Element {
|
|
27
|
+
const [local, state, others] = splitProps(props,
|
|
28
|
+
["label", "description", "error", "class", "onCheckedChange", "inputRef", "form"],
|
|
29
|
+
["checked", "defaultChecked", "indeterminate", "disabled", "readOnly", "required", "name", "value"]);
|
|
30
|
+
const prefix = `sheen-${kind}`;
|
|
31
|
+
const generatedId = createUniqueId();
|
|
32
|
+
const inputId = `${generatedId}-input`;
|
|
33
|
+
let input: HTMLInputElement | undefined;
|
|
34
|
+
const describedBy = () => [local.description ? `${generatedId}-description` : "", local.error ? `${generatedId}-error` : ""].filter(Boolean).join(" ") || undefined;
|
|
35
|
+
const { checked, requestChange, setInput } = createBooleanInputState(state, next => local.onCheckedChange?.(next));
|
|
36
|
+
return <div {...others} class={cn(prefix, local.class)} data-checked={checked() || undefined} data-indeterminate={state.indeterminate || undefined} data-disabled={state.disabled || undefined} data-readonly={state.readOnly || undefined} data-invalid={local.error ? "" : undefined}>
|
|
37
|
+
<div class={`${prefix}-row`}>
|
|
38
|
+
<input id={inputId} type="checkbox" role={kind === "switch" ? "switch" : undefined} name={state.name ?? ""} value={state.value} form={local.form} disabled={state.disabled} required={state.required} readOnly={state.readOnly} checked={checked()} aria-readonly={state.readOnly || undefined} aria-invalid={local.error ? "true" : undefined} aria-describedby={describedBy()} class={`${prefix}-input`} ref={element => { input = element; setInput(element); local.inputRef?.(element); }} onChange={event => requestChange(event.currentTarget)} />
|
|
39
|
+
<span class={`${prefix}-control`} data-indeterminate={state.indeterminate || undefined} aria-hidden="true" onClick={() => input?.click()}>
|
|
40
|
+
{kind === "checkbox" ? <span class="sheen-checkbox-indicator"><span class="sheen-checkbox-mark" /></span> : <span class="sheen-switch-thumb" />}
|
|
41
|
+
</span>
|
|
42
|
+
<label for={inputId} class={`${prefix}-label`}>{local.label}<Show when={state.required}><span aria-hidden="true"> *</span></Show></label>
|
|
43
|
+
</div>
|
|
44
|
+
<Show when={local.description}><p id={`${generatedId}-description`} class={`${prefix}-description`}>{local.description}</p></Show>
|
|
45
|
+
<Show when={local.error}><p id={`${generatedId}-error`} class={`${prefix}-error`}>{local.error}</p></Show>
|
|
46
|
+
</div>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function Checkbox(props: CheckboxProps): JSX.Element {
|
|
50
|
+
return createNativeBooleanControl(props, "checkbox");
|
|
51
|
+
}
|