@glasshome/ui 1.10.0 → 1.11.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/SPEC.md +7 -0
- package/dist/index.js +1 -1
- package/dist/lib/menu-classes.d.ts +2 -2
- package/dist/solid/icon.d.ts +18 -12
- package/dist/solid/index.d.ts +1 -0
- package/dist/solid/index.js +3692 -3490
- package/dist/{utils-CIwpbaOd.js → utils-CdUh67Y9.js} +1 -1
- package/package.json +7 -3
- package/scripts/check-pack.ts +32 -0
- package/src/index.ts +111 -0
- package/src/lib/menu-classes.ts +1 -1
- package/src/solid/accordion.tsx +60 -0
- package/src/solid/alert-dialog.tsx +148 -0
- package/src/solid/alert.tsx +118 -0
- package/src/solid/area-picker.tsx +225 -0
- package/src/solid/aspect-ratio.tsx +21 -0
- package/src/solid/avatar.tsx +41 -0
- package/src/solid/badge.tsx +74 -0
- package/src/solid/bottom-sheet/arbitration.ts +40 -0
- package/src/solid/bottom-sheet/bottom-sheet.tsx +457 -0
- package/src/solid/bottom-sheet/constants.ts +8 -0
- package/src/solid/bottom-sheet/drag-controller.ts +221 -0
- package/src/solid/bottom-sheet/focus-trap.ts +56 -0
- package/src/solid/bottom-sheet/index.ts +14 -0
- package/src/solid/bottom-sheet/keyboard.ts +35 -0
- package/src/solid/bottom-sheet/scroll-lock.ts +64 -0
- package/src/solid/bottom-sheet/state-machine.ts +40 -0
- package/src/solid/bottom-sheet/velocity.ts +42 -0
- package/src/solid/breadcrumb.tsx +105 -0
- package/src/solid/button-group.tsx +66 -0
- package/src/solid/button.tsx +20 -0
- package/src/solid/card.tsx +101 -0
- package/src/solid/carousel.tsx +302 -0
- package/src/solid/charts.tsx +338 -0
- package/src/solid/checkbox.tsx +70 -0
- package/src/solid/collapsible.tsx +38 -0
- package/src/solid/color-slider.tsx +98 -0
- package/src/solid/color-wheel.tsx +77 -0
- package/src/solid/context-menu.tsx +109 -0
- package/src/solid/copy-button.tsx +46 -0
- package/src/solid/count-pill.tsx +24 -0
- package/src/solid/data-table.tsx +248 -0
- package/src/solid/dialog-parts.tsx +242 -0
- package/src/solid/dialog.tsx +121 -0
- package/src/solid/dock.tsx +186 -0
- package/src/solid/dropdown-menu.tsx +130 -0
- package/src/solid/empty.tsx +99 -0
- package/src/solid/entity-data.ts +78 -0
- package/src/solid/entity-selector.tsx +697 -0
- package/src/solid/field.tsx +253 -0
- package/src/solid/form.tsx +231 -0
- package/src/solid/hero-action.tsx +117 -0
- package/src/solid/hover-card.tsx +26 -0
- package/src/solid/icon-picker.tsx +432 -0
- package/src/solid/icon.tsx +126 -0
- package/src/solid/image-picker.tsx +380 -0
- package/src/solid/index.ts +413 -0
- package/src/solid/input-group.tsx +170 -0
- package/src/solid/input-otp.tsx +175 -0
- package/src/solid/input.tsx +12 -0
- package/src/solid/item.tsx +179 -0
- package/src/solid/kbd.tsx +30 -0
- package/src/solid/label.tsx +19 -0
- package/src/solid/list-reorder.ts +148 -0
- package/src/solid/logo.tsx +79 -0
- package/src/solid/media-copy.ts +37 -0
- package/src/solid/media-store.ts +110 -0
- package/src/solid/media-tile.tsx +100 -0
- package/src/solid/menu-parts.tsx +248 -0
- package/src/solid/number-field.tsx +72 -0
- package/src/solid/option-card.tsx +218 -0
- package/src/solid/ornament.tsx +53 -0
- package/src/solid/overlay.tsx +16 -0
- package/src/solid/page-header.tsx +102 -0
- package/src/solid/pagination.tsx +111 -0
- package/src/solid/password-input.tsx +69 -0
- package/src/solid/picker-row.tsx +102 -0
- package/src/solid/picker-search.tsx +78 -0
- package/src/solid/popover.tsx +103 -0
- package/src/solid/progress.tsx +31 -0
- package/src/solid/radio-group.tsx +60 -0
- package/src/solid/resizable.tsx +149 -0
- package/src/solid/responsive-dialog.tsx +180 -0
- package/src/solid/schema-form.tsx +830 -0
- package/src/solid/scope-indicator.tsx +13 -0
- package/src/solid/scroll-area.tsx +27 -0
- package/src/solid/section-card.tsx +358 -0
- package/src/solid/select.tsx +139 -0
- package/src/solid/separator.tsx +35 -0
- package/src/solid/settings-row.tsx +159 -0
- package/src/solid/sheet.tsx +157 -0
- package/src/solid/skeleton.tsx +15 -0
- package/src/solid/slider.tsx +148 -0
- package/src/solid/sliding-indicator.tsx +294 -0
- package/src/solid/sonner.tsx +217 -0
- package/src/solid/spinner.tsx +20 -0
- package/src/solid/step-indicator.tsx +30 -0
- package/src/solid/switch.tsx +62 -0
- package/src/solid/table.tsx +98 -0
- package/src/solid/tabs.tsx +86 -0
- package/src/solid/textarea.tsx +16 -0
- package/src/solid/toggle-group.tsx +102 -0
- package/src/solid/toggle.tsx +57 -0
- package/src/solid/tooltip.tsx +38 -0
- package/src/solid/widget-card.tsx +117 -0
- package/src/solid/widget-identity.tsx +135 -0
- package/src/solid/widget-trust-badge.tsx +37 -0
- package/src/styles/globals.css +7 -0
- package/src/styles/theme.css +8 -0
- package/src/tokens/hex.ts +50 -0
- package/src/tokens/index.ts +8 -0
- package/src/tokens/presets.ts +192 -0
- package/src/tokens/theme-colors.ts +147 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createContext, createSignal, useContext } from "solid-js";
|
|
2
|
+
|
|
3
|
+
export type StoredMedia = {
|
|
4
|
+
id: string;
|
|
5
|
+
mimeType: string;
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
size: number;
|
|
9
|
+
/** Server-computed count of live widget configs referencing this id. */
|
|
10
|
+
usedBy: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type MediaQuotaUsage = {
|
|
14
|
+
bytes: number;
|
|
15
|
+
limitBytes: number;
|
|
16
|
+
files: number;
|
|
17
|
+
limitFiles: number;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type MediaStoreErrorKind =
|
|
21
|
+
| "file_too_large"
|
|
22
|
+
| "image_too_large"
|
|
23
|
+
| "not_an_image"
|
|
24
|
+
| "quota_bytes_exceeded"
|
|
25
|
+
| "quota_files_exceeded"
|
|
26
|
+
| "upload_rate_exceeded"
|
|
27
|
+
| "server_storage_full"
|
|
28
|
+
| "no_active_household"
|
|
29
|
+
| "upload_failed";
|
|
30
|
+
|
|
31
|
+
export class MediaStoreError extends Error {
|
|
32
|
+
readonly kind: MediaStoreErrorKind;
|
|
33
|
+
readonly usage?: MediaQuotaUsage;
|
|
34
|
+
|
|
35
|
+
constructor(kind: MediaStoreErrorKind, usage?: MediaQuotaUsage) {
|
|
36
|
+
super(kind);
|
|
37
|
+
this.name = "MediaStoreError";
|
|
38
|
+
this.kind = kind;
|
|
39
|
+
this.usage = usage;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** One gallery open, one query: the server counts usage in the same scan. */
|
|
44
|
+
export type MediaIndex = {
|
|
45
|
+
media: StoredMedia[];
|
|
46
|
+
usage: MediaQuotaUsage;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** "thumb" is a server-side derivative, longest edge ~400px, for grids. */
|
|
50
|
+
export type MediaVariant = "original" | "thumb";
|
|
51
|
+
|
|
52
|
+
export interface MediaStore {
|
|
53
|
+
index(): Promise<MediaIndex>;
|
|
54
|
+
upload(file: File): Promise<StoredMedia>;
|
|
55
|
+
remove(id: string): Promise<void>;
|
|
56
|
+
url(id: string, variant?: MediaVariant): string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const MediaStoreContext = createContext<MediaStore>();
|
|
60
|
+
|
|
61
|
+
let defaultStore: MediaStore | undefined;
|
|
62
|
+
|
|
63
|
+
/** Host apps call this once at startup; MediaStoreContext overrides it per-tree. */
|
|
64
|
+
export function provideMediaStore(store: MediaStore): void {
|
|
65
|
+
defaultStore = store;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function useMediaStore(): MediaStore | undefined {
|
|
69
|
+
return useContext(MediaStoreContext) ?? defaultStore;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** One grid page. The picker and the library both slice by this, so neither can
|
|
73
|
+
* mount a whole 500-file library at once. */
|
|
74
|
+
export const MEDIA_PAGE_SIZE = 24;
|
|
75
|
+
|
|
76
|
+
/** A row whose mime is missing or not a string is not an image; a throw here would
|
|
77
|
+
* take the surrounding gallery down with it. */
|
|
78
|
+
export function isMediaImage(item: StoredMedia): boolean {
|
|
79
|
+
return typeof item.mimeType === "string" && item.mimeType.startsWith("image/");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Unused first: someone browsing stored media is looking for what is safe to delete. */
|
|
83
|
+
export function sortMediaForClearing(media: StoredMedia[]): StoredMedia[] {
|
|
84
|
+
return media.filter(isMediaImage).sort((a, b) => {
|
|
85
|
+
if ((a.usedBy === 0) !== (b.usedBy === 0)) return a.usedBy === 0 ? -1 : 1;
|
|
86
|
+
return a.id.localeCompare(b.id);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface BrokenMedia {
|
|
91
|
+
isBroken: (item: StoredMedia) => boolean;
|
|
92
|
+
markBroken: (item: StoredMedia) => void;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Keyed by the url that failed, so a re-uploaded id (new url) starts unbroken again. */
|
|
96
|
+
export function createBrokenMedia(thumbUrl: (id: string) => string): BrokenMedia {
|
|
97
|
+
const [broken, setBroken] = createSignal<Readonly<Record<string, string>>>({});
|
|
98
|
+
return {
|
|
99
|
+
isBroken: (item) => broken()[item.id] === thumbUrl(item.id),
|
|
100
|
+
markBroken: (item) => setBroken((previous) => ({ ...previous, [item.id]: thumbUrl(item.id) })),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function mediaUrl(id: string | null | undefined): string | undefined {
|
|
105
|
+
if (!id) return undefined;
|
|
106
|
+
return useMediaStore()?.url(id);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Reads better than mediaUrl in an image widget's source. */
|
|
110
|
+
export const imageUrl = mediaUrl;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Show } from "solid-js";
|
|
2
|
+
import { FIELD_CHROME } from "../lib/input-classes.js";
|
|
3
|
+
import { SCRIM_CLASS } from "../lib/overlay-classes.js";
|
|
4
|
+
import { SECTION_INNER_RADIUS } from "../lib/section-tokens.js";
|
|
5
|
+
import { cn } from "../lib/utils.js";
|
|
6
|
+
import { Badge } from "./badge.js";
|
|
7
|
+
import { Button } from "./button.js";
|
|
8
|
+
import { Icon } from "./icon.js";
|
|
9
|
+
import type { StoredMedia } from "./media-store.js";
|
|
10
|
+
|
|
11
|
+
export interface MediaTileProps {
|
|
12
|
+
item: StoredMedia;
|
|
13
|
+
thumbUrl: string;
|
|
14
|
+
/** Describes what the click does here: the picker chooses, a library opens a preview. */
|
|
15
|
+
label: string;
|
|
16
|
+
broken: boolean;
|
|
17
|
+
onSelect: () => void;
|
|
18
|
+
onBroken: () => void;
|
|
19
|
+
onDelete?: () => void;
|
|
20
|
+
markUnused?: boolean;
|
|
21
|
+
selected?: boolean;
|
|
22
|
+
class?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function MediaTile(props: MediaTileProps) {
|
|
26
|
+
return (
|
|
27
|
+
<div data-slot="media-tile" class={cn("relative min-w-0", props.class)}>
|
|
28
|
+
<button
|
|
29
|
+
type="button"
|
|
30
|
+
data-slot="media-tile-select"
|
|
31
|
+
data-testid="media-tile"
|
|
32
|
+
aria-label={props.label}
|
|
33
|
+
aria-pressed={props.selected}
|
|
34
|
+
onClick={() => props.onSelect()}
|
|
35
|
+
class={cn(
|
|
36
|
+
FIELD_CHROME,
|
|
37
|
+
SECTION_INNER_RADIUS,
|
|
38
|
+
"relative block aspect-square w-full overflow-hidden",
|
|
39
|
+
props.selected && "ring-2 ring-primary",
|
|
40
|
+
)}
|
|
41
|
+
>
|
|
42
|
+
<Show
|
|
43
|
+
when={!props.broken}
|
|
44
|
+
fallback={
|
|
45
|
+
<span
|
|
46
|
+
data-slot="media-tile-broken"
|
|
47
|
+
data-testid="media-tile-broken"
|
|
48
|
+
class="absolute inset-0 flex items-center justify-center text-muted-foreground"
|
|
49
|
+
>
|
|
50
|
+
<Icon icon="lucide:image-off" width={20} height={20} />
|
|
51
|
+
</span>
|
|
52
|
+
}
|
|
53
|
+
>
|
|
54
|
+
<img
|
|
55
|
+
data-slot="media-tile-image"
|
|
56
|
+
src={props.thumbUrl}
|
|
57
|
+
alt={`Stored ${props.item.id}`}
|
|
58
|
+
width={props.item.width}
|
|
59
|
+
height={props.item.height}
|
|
60
|
+
loading="lazy"
|
|
61
|
+
decoding="async"
|
|
62
|
+
class="absolute inset-0 h-full w-full object-cover"
|
|
63
|
+
onError={() => props.onBroken()}
|
|
64
|
+
/>
|
|
65
|
+
</Show>
|
|
66
|
+
</button>
|
|
67
|
+
{/* Bottom-left, diagonally clear of the delete control, on the same scrim
|
|
68
|
+
* so it stays legible over a bright photo. */}
|
|
69
|
+
<Show when={props.markUnused === true && props.item.usedBy === 0}>
|
|
70
|
+
<Badge
|
|
71
|
+
data-slot="media-tile-unused"
|
|
72
|
+
data-testid="media-tile-unused"
|
|
73
|
+
tone="var(--warning)"
|
|
74
|
+
class="pointer-events-none absolute bottom-1 left-1 backdrop-blur-md"
|
|
75
|
+
>
|
|
76
|
+
Unused
|
|
77
|
+
</Badge>
|
|
78
|
+
</Show>
|
|
79
|
+
{/* Sibling, not nested: a button inside the tile button is invalid and eats the click. */}
|
|
80
|
+
<Show when={props.onDelete !== undefined}>
|
|
81
|
+
<Button
|
|
82
|
+
type="button"
|
|
83
|
+
variant="ghost"
|
|
84
|
+
size="none"
|
|
85
|
+
data-slot="media-tile-delete"
|
|
86
|
+
// after:-inset-1.5 lifts the touch target to ~44px without growing the glyph or its scrim.
|
|
87
|
+
class={cn(
|
|
88
|
+
"absolute top-1 right-1 size-8 rounded-full text-destructive hover:text-destructive",
|
|
89
|
+
"after:absolute after:-inset-1.5 after:content-['']",
|
|
90
|
+
SCRIM_CLASS,
|
|
91
|
+
)}
|
|
92
|
+
aria-label={`Delete ${props.item.id}`}
|
|
93
|
+
onClick={() => props.onDelete?.()}
|
|
94
|
+
>
|
|
95
|
+
<Icon icon="lucide:trash-2" width={16} height={16} />
|
|
96
|
+
</Button>
|
|
97
|
+
</Show>
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { DropdownMenu as MenuPrimitive } from "@kobalte/core/dropdown-menu";
|
|
2
|
+
import {
|
|
3
|
+
type Component,
|
|
4
|
+
type ComponentProps,
|
|
5
|
+
createSignal,
|
|
6
|
+
onCleanup,
|
|
7
|
+
onMount,
|
|
8
|
+
type ParentComponent,
|
|
9
|
+
splitProps,
|
|
10
|
+
} from "solid-js";
|
|
11
|
+
import { glassToneText } from "../lib/glass-tone.js";
|
|
12
|
+
import { MENU_ITEM, MENU_ITEM_BASE, MENU_LABEL, MENU_SEPARATOR } from "../lib/menu-classes.js";
|
|
13
|
+
import { STAGGER } from "../lib/motion-classes.js";
|
|
14
|
+
import { FLOATING_PANEL } from "../lib/overlay-classes.js";
|
|
15
|
+
import { cn } from "../lib/utils.js";
|
|
16
|
+
import { Icon } from "./icon.js";
|
|
17
|
+
import { SlidingIndicator } from "./sliding-indicator.js";
|
|
18
|
+
|
|
19
|
+
/*
|
|
20
|
+
* DropdownMenu and ContextMenu are two Root flavors over one Kobalte Menu
|
|
21
|
+
* engine: Item, CheckboxItem, RadioItem, SubTrigger, SubContent, GroupLabel,
|
|
22
|
+
* Separator and ItemIndicator are the identical components either family
|
|
23
|
+
* re-exports (see @kobalte/core's dropdown-menu and context-menu index,
|
|
24
|
+
* which both alias the same ../menu implementation), so they are styled once
|
|
25
|
+
* here under whichever Root happens to be an ancestor.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/* The panel without its motion: DropdownMenu morphs out of its trigger,
|
|
29
|
+
* ContextMenu unfolds from the pointer. */
|
|
30
|
+
export const MENU_CONTENT_CLASS = cn(FLOATING_PANEL, "min-w-[8rem] overflow-hidden p-1");
|
|
31
|
+
|
|
32
|
+
/** Every menu content and sub content wraps its rows in one sliding highlight,
|
|
33
|
+
* keyed off Kobalte's roving-focus attribute. The highlighted row's own
|
|
34
|
+
* --glass-tone (set inline by MenuItemPart) is mirrored onto the indicator,
|
|
35
|
+
* since --glass-tone does not inherit and the indicator is a sibling, not
|
|
36
|
+
* an ancestor, of the rows it highlights. */
|
|
37
|
+
export const MenuContentIndicator: ParentComponent = (props) => {
|
|
38
|
+
let containerRef: HTMLDivElement | undefined;
|
|
39
|
+
const [tone, setTone] = createSignal<string | undefined>(undefined);
|
|
40
|
+
|
|
41
|
+
const syncTone = () => {
|
|
42
|
+
const highlighted = containerRef?.querySelector<HTMLElement>("[data-highlighted]");
|
|
43
|
+
setTone(highlighted?.style.getPropertyValue("--glass-tone") || undefined);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
onMount(() => {
|
|
47
|
+
if (!containerRef) return;
|
|
48
|
+
const mo = new MutationObserver(syncTone);
|
|
49
|
+
mo.observe(containerRef, {
|
|
50
|
+
subtree: true,
|
|
51
|
+
attributes: true,
|
|
52
|
+
attributeFilter: ["data-highlighted"],
|
|
53
|
+
});
|
|
54
|
+
containerRef.addEventListener("focusin", syncTone);
|
|
55
|
+
syncTone();
|
|
56
|
+
onCleanup(() => {
|
|
57
|
+
mo.disconnect();
|
|
58
|
+
containerRef?.removeEventListener("focusin", syncTone);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<SlidingIndicator
|
|
64
|
+
ref={containerRef}
|
|
65
|
+
// The one element between role="menu" and its role="menuitem" rows:
|
|
66
|
+
// an unnamed div there breaks the menu's ownership in the a11y tree.
|
|
67
|
+
role="none"
|
|
68
|
+
class={STAGGER}
|
|
69
|
+
activeSelector="[data-highlighted]"
|
|
70
|
+
orientation="vertical"
|
|
71
|
+
indicatorClass="rounded-sm"
|
|
72
|
+
indicatorTone={tone()}
|
|
73
|
+
>
|
|
74
|
+
{props.children}
|
|
75
|
+
</SlidingIndicator>
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
type ToneProps = {
|
|
80
|
+
tone?: string;
|
|
81
|
+
/** @deprecated pass `tone="var(--destructive)"` instead */
|
|
82
|
+
variant?: "default" | "destructive";
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
function resolveTone(local: ToneProps): string | undefined {
|
|
86
|
+
return local.tone ?? (local.variant === "destructive" ? "var(--destructive)" : undefined);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function toneStyle(tone: string | undefined) {
|
|
90
|
+
return tone ? { "--glass-tone": tone, color: glassToneText(tone) } : undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
type MenuItemProps = ComponentProps<typeof MenuPrimitive.Item> &
|
|
94
|
+
ToneProps & { inset?: boolean; slotName: string; style?: Record<string, string> };
|
|
95
|
+
|
|
96
|
+
/* True order among the menu's rows, labels and separators, for the stagger:
|
|
97
|
+
* nth-child restarts inside a group, the DOM order does not. Refs fire before
|
|
98
|
+
* insertion, hence the microtask. */
|
|
99
|
+
function writeRowIndex(el: HTMLElement) {
|
|
100
|
+
queueMicrotask(() => {
|
|
101
|
+
const menu = el.closest('[role="menu"], [role="listbox"]');
|
|
102
|
+
if (!menu) return;
|
|
103
|
+
const i = Array.from(menu.querySelectorAll("[data-stagger-row]")).indexOf(el);
|
|
104
|
+
if (i >= 0) el.style.setProperty("--i", String(i));
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export const MenuItemPart: Component<MenuItemProps> = (props) => {
|
|
109
|
+
const [local, rest] = splitProps(props, [
|
|
110
|
+
"class",
|
|
111
|
+
"inset",
|
|
112
|
+
"tone",
|
|
113
|
+
"variant",
|
|
114
|
+
"slotName",
|
|
115
|
+
"style",
|
|
116
|
+
]);
|
|
117
|
+
const tone = () => resolveTone(local);
|
|
118
|
+
return (
|
|
119
|
+
<MenuPrimitive.Item
|
|
120
|
+
ref={writeRowIndex}
|
|
121
|
+
data-stagger-row=""
|
|
122
|
+
data-slot={local.slotName}
|
|
123
|
+
data-inset={local.inset}
|
|
124
|
+
data-tone={tone() ? "" : undefined}
|
|
125
|
+
class={cn(MENU_ITEM, local.inset && "pl-8", local.class)}
|
|
126
|
+
style={{ ...toneStyle(tone()), ...local.style }}
|
|
127
|
+
{...rest}
|
|
128
|
+
/>
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
type MenuLabelProps = ComponentProps<typeof MenuPrimitive.GroupLabel> & {
|
|
133
|
+
inset?: boolean;
|
|
134
|
+
slotName: string;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export const MenuLabelPart: Component<MenuLabelProps> = (props) => {
|
|
138
|
+
const [local, rest] = splitProps(props, ["class", "inset", "slotName"]);
|
|
139
|
+
return (
|
|
140
|
+
<MenuPrimitive.GroupLabel
|
|
141
|
+
ref={writeRowIndex}
|
|
142
|
+
data-stagger-row=""
|
|
143
|
+
data-slot={local.slotName}
|
|
144
|
+
data-inset={local.inset}
|
|
145
|
+
class={cn(MENU_LABEL, local.inset && "pl-8", local.class)}
|
|
146
|
+
{...rest}
|
|
147
|
+
/>
|
|
148
|
+
);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
type MenuSeparatorProps = ComponentProps<typeof MenuPrimitive.Separator> & { slotName: string };
|
|
152
|
+
|
|
153
|
+
export const MenuSeparatorPart: Component<MenuSeparatorProps> = (props) => {
|
|
154
|
+
const [local, rest] = splitProps(props, ["class", "slotName"]);
|
|
155
|
+
return (
|
|
156
|
+
<MenuPrimitive.Separator
|
|
157
|
+
ref={writeRowIndex}
|
|
158
|
+
data-stagger-row=""
|
|
159
|
+
data-slot={local.slotName}
|
|
160
|
+
class={cn(MENU_SEPARATOR, local.class)}
|
|
161
|
+
{...rest}
|
|
162
|
+
/>
|
|
163
|
+
);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
type MenuSubTriggerProps = ComponentProps<typeof MenuPrimitive.SubTrigger> & {
|
|
167
|
+
inset?: boolean;
|
|
168
|
+
slotName: string;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export const MenuSubTriggerPart: ParentComponent<MenuSubTriggerProps> = (props) => {
|
|
172
|
+
const [local, rest] = splitProps(props, ["class", "children", "inset", "slotName"]);
|
|
173
|
+
return (
|
|
174
|
+
<MenuPrimitive.SubTrigger
|
|
175
|
+
ref={writeRowIndex}
|
|
176
|
+
data-stagger-row=""
|
|
177
|
+
data-slot={local.slotName}
|
|
178
|
+
data-inset={local.inset}
|
|
179
|
+
class={cn(MENU_ITEM, local.inset && "pl-8", local.class)}
|
|
180
|
+
{...rest}
|
|
181
|
+
>
|
|
182
|
+
{local.children}
|
|
183
|
+
<Icon icon="lucide:chevron-right" width={16} height={16} class="ml-auto" />
|
|
184
|
+
</MenuPrimitive.SubTrigger>
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
type MenuSubContentProps = ComponentProps<typeof MenuPrimitive.SubContent> & { slotName: string };
|
|
189
|
+
|
|
190
|
+
export const MenuSubContentPart: ParentComponent<MenuSubContentProps> = (props) => {
|
|
191
|
+
const [local, rest] = splitProps(props, ["class", "children", "slotName"]);
|
|
192
|
+
return (
|
|
193
|
+
<MenuPrimitive.SubContent
|
|
194
|
+
data-slot={local.slotName}
|
|
195
|
+
class={cn(MENU_CONTENT_CLASS, local.class)}
|
|
196
|
+
{...rest}
|
|
197
|
+
>
|
|
198
|
+
<MenuContentIndicator>{local.children}</MenuContentIndicator>
|
|
199
|
+
</MenuPrimitive.SubContent>
|
|
200
|
+
);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
type MenuCheckboxItemProps = ComponentProps<typeof MenuPrimitive.CheckboxItem> & {
|
|
204
|
+
slotName: string;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
export const MenuCheckboxItemPart: ParentComponent<MenuCheckboxItemProps> = (props) => {
|
|
208
|
+
const [local, rest] = splitProps(props, ["class", "children", "slotName"]);
|
|
209
|
+
return (
|
|
210
|
+
<MenuPrimitive.CheckboxItem
|
|
211
|
+
ref={writeRowIndex}
|
|
212
|
+
data-stagger-row=""
|
|
213
|
+
data-slot={local.slotName}
|
|
214
|
+
class={cn(MENU_ITEM_BASE, "py-1.5 pr-2 pl-8", local.class)}
|
|
215
|
+
{...rest}
|
|
216
|
+
>
|
|
217
|
+
<span class="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
|
218
|
+
<MenuPrimitive.ItemIndicator>
|
|
219
|
+
<Icon icon="lucide:check" width={16} height={16} class="size-4" />
|
|
220
|
+
</MenuPrimitive.ItemIndicator>
|
|
221
|
+
</span>
|
|
222
|
+
{local.children}
|
|
223
|
+
</MenuPrimitive.CheckboxItem>
|
|
224
|
+
);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
type MenuRadioItemProps = ComponentProps<typeof MenuPrimitive.RadioItem> & { slotName: string };
|
|
228
|
+
|
|
229
|
+
export const MenuRadioItemPart: ParentComponent<MenuRadioItemProps> = (props) => {
|
|
230
|
+
const [local, rest] = splitProps(props, ["class", "children", "slotName"]);
|
|
231
|
+
return (
|
|
232
|
+
<MenuPrimitive.RadioItem
|
|
233
|
+
ref={writeRowIndex}
|
|
234
|
+
data-stagger-row=""
|
|
235
|
+
data-slot={local.slotName}
|
|
236
|
+
class={cn(MENU_ITEM_BASE, "py-1.5 pr-2 pl-8", local.class)}
|
|
237
|
+
{...rest}
|
|
238
|
+
>
|
|
239
|
+
<span class="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
|
240
|
+
<MenuPrimitive.ItemIndicator>
|
|
241
|
+
{/* mdi:circle is filled; lucide:circle is stroke-only and invisible at 8px. */}
|
|
242
|
+
<Icon icon="mdi:circle" width={8} height={8} class="size-2" />
|
|
243
|
+
</MenuPrimitive.ItemIndicator>
|
|
244
|
+
</span>
|
|
245
|
+
{local.children}
|
|
246
|
+
</MenuPrimitive.RadioItem>
|
|
247
|
+
);
|
|
248
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type Component, type ComponentProps, splitProps } from "solid-js";
|
|
2
|
+
import { INPUT_CLASS } from "../lib/input-classes.js";
|
|
3
|
+
import { cn } from "../lib/utils.js";
|
|
4
|
+
import { Icon } from "./icon.js";
|
|
5
|
+
|
|
6
|
+
/* The spinner column and the padding that reserves it: one pair, so the value
|
|
7
|
+
* can never run under the chevrons. */
|
|
8
|
+
const SPINNER_COLUMN = "w-10";
|
|
9
|
+
const SPINNER_RESERVE = "pr-10";
|
|
10
|
+
|
|
11
|
+
const NumberField: Component<Omit<ComponentProps<"input">, "type">> = (props) => {
|
|
12
|
+
const [local, others] = splitProps(props, ["class", "step", "min", "max"]);
|
|
13
|
+
let ref: HTMLInputElement | undefined;
|
|
14
|
+
const step = () => Number(local.step ?? 1) || 1;
|
|
15
|
+
|
|
16
|
+
const nudge = (dir: 1 | -1) => {
|
|
17
|
+
if (!ref) return;
|
|
18
|
+
let next = (Number(ref.value) || 0) + dir * step();
|
|
19
|
+
if (local.min != null) next = Math.max(Number(local.min), next);
|
|
20
|
+
if (local.max != null) next = Math.min(Number(local.max), next);
|
|
21
|
+
ref.value = String(next);
|
|
22
|
+
ref.dispatchEvent(new Event("input", { bubbles: true }));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div data-slot="number-field-root" class="relative">
|
|
27
|
+
<input
|
|
28
|
+
ref={ref}
|
|
29
|
+
type="number"
|
|
30
|
+
data-slot="number-field"
|
|
31
|
+
step={local.step}
|
|
32
|
+
min={local.min}
|
|
33
|
+
max={local.max}
|
|
34
|
+
class={cn(
|
|
35
|
+
INPUT_CLASS,
|
|
36
|
+
SPINNER_RESERVE,
|
|
37
|
+
"[appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none",
|
|
38
|
+
local.class,
|
|
39
|
+
)}
|
|
40
|
+
{...others}
|
|
41
|
+
/>
|
|
42
|
+
<div
|
|
43
|
+
data-slot="number-field-spinner"
|
|
44
|
+
class={cn(
|
|
45
|
+
"absolute inset-y-0 right-0 flex flex-col divide-y divide-border overflow-hidden rounded-r-md border-border border-l",
|
|
46
|
+
SPINNER_COLUMN,
|
|
47
|
+
)}
|
|
48
|
+
>
|
|
49
|
+
<button
|
|
50
|
+
type="button"
|
|
51
|
+
tabindex={-1}
|
|
52
|
+
aria-label="Increment"
|
|
53
|
+
onClick={() => nudge(1)}
|
|
54
|
+
class="flex flex-1 items-center justify-center text-muted-foreground transition-colors hover:bg-muted hover:text-foreground active:bg-muted"
|
|
55
|
+
>
|
|
56
|
+
<Icon icon="lucide:chevron-up" width={16} height={16} class="size-4" />
|
|
57
|
+
</button>
|
|
58
|
+
<button
|
|
59
|
+
type="button"
|
|
60
|
+
tabindex={-1}
|
|
61
|
+
aria-label="Decrement"
|
|
62
|
+
onClick={() => nudge(-1)}
|
|
63
|
+
class="flex flex-1 items-center justify-center text-muted-foreground transition-colors hover:bg-muted hover:text-foreground active:bg-muted"
|
|
64
|
+
>
|
|
65
|
+
<Icon icon="lucide:chevron-down" width={16} height={16} class="size-4" />
|
|
66
|
+
</button>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { NumberField };
|