@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.
Files changed (113) hide show
  1. package/SPEC.md +7 -0
  2. package/dist/index.js +1 -1
  3. package/dist/lib/menu-classes.d.ts +2 -2
  4. package/dist/solid/icon.d.ts +18 -12
  5. package/dist/solid/index.d.ts +1 -0
  6. package/dist/solid/index.js +3692 -3490
  7. package/dist/{utils-CIwpbaOd.js → utils-CdUh67Y9.js} +1 -1
  8. package/package.json +7 -3
  9. package/scripts/check-pack.ts +32 -0
  10. package/src/index.ts +111 -0
  11. package/src/lib/menu-classes.ts +1 -1
  12. package/src/solid/accordion.tsx +60 -0
  13. package/src/solid/alert-dialog.tsx +148 -0
  14. package/src/solid/alert.tsx +118 -0
  15. package/src/solid/area-picker.tsx +225 -0
  16. package/src/solid/aspect-ratio.tsx +21 -0
  17. package/src/solid/avatar.tsx +41 -0
  18. package/src/solid/badge.tsx +74 -0
  19. package/src/solid/bottom-sheet/arbitration.ts +40 -0
  20. package/src/solid/bottom-sheet/bottom-sheet.tsx +457 -0
  21. package/src/solid/bottom-sheet/constants.ts +8 -0
  22. package/src/solid/bottom-sheet/drag-controller.ts +221 -0
  23. package/src/solid/bottom-sheet/focus-trap.ts +56 -0
  24. package/src/solid/bottom-sheet/index.ts +14 -0
  25. package/src/solid/bottom-sheet/keyboard.ts +35 -0
  26. package/src/solid/bottom-sheet/scroll-lock.ts +64 -0
  27. package/src/solid/bottom-sheet/state-machine.ts +40 -0
  28. package/src/solid/bottom-sheet/velocity.ts +42 -0
  29. package/src/solid/breadcrumb.tsx +105 -0
  30. package/src/solid/button-group.tsx +66 -0
  31. package/src/solid/button.tsx +20 -0
  32. package/src/solid/card.tsx +101 -0
  33. package/src/solid/carousel.tsx +302 -0
  34. package/src/solid/charts.tsx +338 -0
  35. package/src/solid/checkbox.tsx +70 -0
  36. package/src/solid/collapsible.tsx +38 -0
  37. package/src/solid/color-slider.tsx +98 -0
  38. package/src/solid/color-wheel.tsx +77 -0
  39. package/src/solid/context-menu.tsx +109 -0
  40. package/src/solid/copy-button.tsx +46 -0
  41. package/src/solid/count-pill.tsx +24 -0
  42. package/src/solid/data-table.tsx +248 -0
  43. package/src/solid/dialog-parts.tsx +242 -0
  44. package/src/solid/dialog.tsx +121 -0
  45. package/src/solid/dock.tsx +186 -0
  46. package/src/solid/dropdown-menu.tsx +130 -0
  47. package/src/solid/empty.tsx +99 -0
  48. package/src/solid/entity-data.ts +78 -0
  49. package/src/solid/entity-selector.tsx +697 -0
  50. package/src/solid/field.tsx +253 -0
  51. package/src/solid/form.tsx +231 -0
  52. package/src/solid/hero-action.tsx +117 -0
  53. package/src/solid/hover-card.tsx +26 -0
  54. package/src/solid/icon-picker.tsx +432 -0
  55. package/src/solid/icon.tsx +126 -0
  56. package/src/solid/image-picker.tsx +380 -0
  57. package/src/solid/index.ts +413 -0
  58. package/src/solid/input-group.tsx +170 -0
  59. package/src/solid/input-otp.tsx +175 -0
  60. package/src/solid/input.tsx +12 -0
  61. package/src/solid/item.tsx +179 -0
  62. package/src/solid/kbd.tsx +30 -0
  63. package/src/solid/label.tsx +19 -0
  64. package/src/solid/list-reorder.ts +148 -0
  65. package/src/solid/logo.tsx +79 -0
  66. package/src/solid/media-copy.ts +37 -0
  67. package/src/solid/media-store.ts +110 -0
  68. package/src/solid/media-tile.tsx +100 -0
  69. package/src/solid/menu-parts.tsx +248 -0
  70. package/src/solid/number-field.tsx +72 -0
  71. package/src/solid/option-card.tsx +218 -0
  72. package/src/solid/ornament.tsx +53 -0
  73. package/src/solid/overlay.tsx +16 -0
  74. package/src/solid/page-header.tsx +102 -0
  75. package/src/solid/pagination.tsx +111 -0
  76. package/src/solid/password-input.tsx +69 -0
  77. package/src/solid/picker-row.tsx +102 -0
  78. package/src/solid/picker-search.tsx +78 -0
  79. package/src/solid/popover.tsx +103 -0
  80. package/src/solid/progress.tsx +31 -0
  81. package/src/solid/radio-group.tsx +60 -0
  82. package/src/solid/resizable.tsx +149 -0
  83. package/src/solid/responsive-dialog.tsx +180 -0
  84. package/src/solid/schema-form.tsx +830 -0
  85. package/src/solid/scope-indicator.tsx +13 -0
  86. package/src/solid/scroll-area.tsx +27 -0
  87. package/src/solid/section-card.tsx +358 -0
  88. package/src/solid/select.tsx +139 -0
  89. package/src/solid/separator.tsx +35 -0
  90. package/src/solid/settings-row.tsx +159 -0
  91. package/src/solid/sheet.tsx +157 -0
  92. package/src/solid/skeleton.tsx +15 -0
  93. package/src/solid/slider.tsx +148 -0
  94. package/src/solid/sliding-indicator.tsx +294 -0
  95. package/src/solid/sonner.tsx +217 -0
  96. package/src/solid/spinner.tsx +20 -0
  97. package/src/solid/step-indicator.tsx +30 -0
  98. package/src/solid/switch.tsx +62 -0
  99. package/src/solid/table.tsx +98 -0
  100. package/src/solid/tabs.tsx +86 -0
  101. package/src/solid/textarea.tsx +16 -0
  102. package/src/solid/toggle-group.tsx +102 -0
  103. package/src/solid/toggle.tsx +57 -0
  104. package/src/solid/tooltip.tsx +38 -0
  105. package/src/solid/widget-card.tsx +117 -0
  106. package/src/solid/widget-identity.tsx +135 -0
  107. package/src/solid/widget-trust-badge.tsx +37 -0
  108. package/src/styles/globals.css +7 -0
  109. package/src/styles/theme.css +8 -0
  110. package/src/tokens/hex.ts +50 -0
  111. package/src/tokens/index.ts +8 -0
  112. package/src/tokens/presets.ts +192 -0
  113. package/src/tokens/theme-colors.ts +147 -0
@@ -0,0 +1,242 @@
1
+ import { Button as KobalteButton } from "@kobalte/core/button";
2
+ import { useDialogContext } from "@kobalte/core/dialog";
3
+ import {
4
+ type Accessor,
5
+ type Component,
6
+ type ComponentProps,
7
+ createContext,
8
+ createSignal,
9
+ createUniqueId,
10
+ type JSX,
11
+ onCleanup,
12
+ onMount,
13
+ type ParentComponent,
14
+ Show,
15
+ splitProps,
16
+ useContext,
17
+ type ValidComponent,
18
+ } from "solid-js";
19
+ import { Dynamic } from "solid-js/web";
20
+ import { Z_CLASS } from "../lib/layers.js";
21
+ import { MODAL_MOTION, SCRIM_MOTION } from "../lib/motion-classes.js";
22
+ import { OVERLAY_SURFACE, SCRIM_CLASS } from "../lib/overlay-classes.js";
23
+ import { cn } from "../lib/utils.js";
24
+ import { acquireScrollLock, releaseScrollLock } from "./bottom-sheet/scroll-lock.js";
25
+
26
+ /* kobalte 0.13.13 builds AlertDialog with Object.assign(DialogRoot, ...), the
27
+ * same object Dialog is built from, so whichever of the two modules a bundle
28
+ * evaluates last owns .Content for both. Every family therefore states its own
29
+ * role instead of trusting the primitive's default. */
30
+
31
+ export type ModalSize = "sm" | "md" | "lg" | "xl" | "full";
32
+
33
+ /* The height cap every modal panel shares. Declared and consumed in one string,
34
+ * so the sheet's keyboard rule in theme.css subtracts from the same length. */
35
+ export const MODAL_MAX_H = "[--modal-max-h:85dvh] max-h-[var(--modal-max-h)]";
36
+
37
+ export const MODAL_WIDTH: Record<ModalSize, string> = {
38
+ sm: "max-w-sm",
39
+ md: "max-w-md",
40
+ lg: "max-w-lg",
41
+ xl: "max-w-3xl",
42
+ full: "max-w-5xl",
43
+ };
44
+
45
+ /* Where the panel sits. Up to lg it centres; xl and full (the workbench
46
+ * dialogs: tabs, steps, editors) hang from the line a full-height panel would
47
+ * start on, so a body that changes height grows downward instead of
48
+ * re-centring and jumping. */
49
+ const MODAL_CENTER = "top-1/2 -translate-y-1/2";
50
+ const MODAL_HANG = "top-[calc((100dvh-var(--modal-max-h))/2)] translate-y-0";
51
+ export const MODAL_ANCHOR: Record<ModalSize, string> = {
52
+ sm: MODAL_CENTER,
53
+ md: MODAL_CENTER,
54
+ lg: MODAL_CENTER,
55
+ xl: MODAL_HANG,
56
+ full: MODAL_HANG,
57
+ };
58
+
59
+ /* The panel: it clips, it never scrolls, and it carries no padding. Every inset
60
+ * belongs to Header, Body or Footer, so the Body scrollbar rides inside the
61
+ * panel edge instead of under the header. */
62
+ export const MODAL_PANEL = `${OVERLAY_SURFACE} ${MODAL_MOTION} fixed left-1/2 flex ${MODAL_MAX_H} w-[calc(100%-2rem)] -translate-x-1/2 flex-col overflow-hidden rounded-lg outline-none ${Z_CLASS.overlay}`;
63
+
64
+ export const MODAL_SCRIM = `${SCRIM_MOTION} fixed inset-0 ${Z_CLASS.overlay} ${SCRIM_CLASS}`;
65
+
66
+ const MODAL_HEADER = "flex shrink-0 items-start gap-4 px-6 pt-6 pb-3";
67
+ const MODAL_HEADER_MEDIA = "flex shrink-0 items-center";
68
+ /* `grow`, not `flex-1`: a zero basis would make the text column shrink to a
69
+ * word per line beside a wide action instead of pushing it onto the next line
70
+ * when the Header wraps. */
71
+ const MODAL_HEADER_TEXT = "flex min-w-0 grow flex-col gap-1.5 text-left";
72
+ const MODAL_HEADER_ACTION = "flex shrink-0 items-center gap-2";
73
+
74
+ /* The only scroll container.
75
+ * - The inset is the full one and a Header or Footer sibling shortens it, keyed
76
+ * on data-slot rather than on position: kobalte parks a focus-trap <span> at
77
+ * each end of the panel, and Sheet's `above` and the sheet handle add more
78
+ * element siblings, so `first:`/`first-of-type:` all lie.
79
+ * - `pan-y pinch-zoom` leaves the single-finger vertical gesture to the sheet's
80
+ * drag arbitration without taking two-finger zoom away.
81
+ * - The reserved scrollbar lives inside the right inset, so the content column
82
+ * ends where the Header's and Footer's do. */
83
+ const MODAL_BODY =
84
+ "gh-scroll gh-stagger flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto overscroll-contain [touch-action:pan-y_pinch-zoom] [scrollbar-gutter:stable] pl-6 pr-[calc(var(--spacing)*6-var(--scrollbar-w))] pt-6 pb-6 [[data-slot$='-header']~&]:pt-3 [&:has(~[data-slot$='-footer'])]:pb-3";
85
+
86
+ const MODAL_FOOTER =
87
+ "gh-stagger flex shrink-0 flex-col-reverse gap-2 px-6 pt-3 pb-6 sm:flex-row sm:justify-end";
88
+
89
+ export const MODAL_TITLE = "font-semibold text-foreground text-lg leading-none tracking-tight";
90
+ export const MODAL_DESCRIPTION = "text-muted-foreground text-sm";
91
+
92
+ export type ModalHeaderProps = ComponentProps<"div"> & {
93
+ /** Avatar or icon, rendered ahead of the title column. */
94
+ media?: JSX.Element;
95
+ action?: JSX.Element;
96
+ /** Lets a wide action (a tab row) drop below the title instead of squeezing
97
+ * it; a phone has no room for both on one line. */
98
+ wrap?: boolean;
99
+ };
100
+
101
+ /** `as="form"` makes the scroll container the form, so a footer submit button
102
+ * reaches it through `form="<id>"` with no wrapper in between. */
103
+ export type ModalBodyProps = ComponentProps<"div"> & { as?: ValidComponent };
104
+
105
+ export interface ModalParts {
106
+ Header: Component<ModalHeaderProps>;
107
+ Body: Component<ModalBodyProps>;
108
+ Footer: Component<ComponentProps<"div">>;
109
+ }
110
+
111
+ export function createModalParts(slot: string): ModalParts {
112
+ const Header: Component<ModalHeaderProps> = (props) => {
113
+ const [local, rest] = splitProps(props, ["class", "media", "action", "wrap", "children"]);
114
+ return (
115
+ <div
116
+ data-slot={`${slot}-header`}
117
+ class={cn(MODAL_HEADER, local.wrap && "flex-wrap", local.class)}
118
+ {...rest}
119
+ >
120
+ <Show when={local.media}>
121
+ <div data-slot={`${slot}-header-media`} class={MODAL_HEADER_MEDIA}>
122
+ {local.media}
123
+ </div>
124
+ </Show>
125
+ <div data-slot={`${slot}-header-text`} class={MODAL_HEADER_TEXT}>
126
+ {local.children}
127
+ </div>
128
+ <Show when={local.action}>
129
+ <div data-slot={`${slot}-header-action`} class={MODAL_HEADER_ACTION}>
130
+ {local.action}
131
+ </div>
132
+ </Show>
133
+ </div>
134
+ );
135
+ };
136
+
137
+ /* data-sheet-scroll is the bottom sheet's drag arbitration marker: a Body
138
+ * inside a sheet must yield the gesture to its own scroll, whichever family
139
+ * rendered it. */
140
+ const Body: Component<ModalBodyProps> = (props) => {
141
+ const [local, rest] = splitProps(props, ["class", "as"]);
142
+ return (
143
+ <Dynamic
144
+ component={local.as ?? "div"}
145
+ data-slot={`${slot}-body`}
146
+ data-sheet-scroll=""
147
+ class={cn(MODAL_BODY, local.class)}
148
+ {...rest}
149
+ />
150
+ );
151
+ };
152
+
153
+ const Footer: Component<ComponentProps<"div">> = (props) => {
154
+ const [local, rest] = splitProps(props, ["class"]);
155
+ return <div data-slot={`${slot}-footer`} class={cn(MODAL_FOOTER, local.class)} {...rest} />;
156
+ };
157
+
158
+ return { Header, Body, Footer };
159
+ }
160
+
161
+ /** Solid's handler prop is a union: a plain function, or the bound
162
+ * `[handler, data]` form that calls `handler(data, event)`. A wrapper that
163
+ * only checks for a function silently drops the bound one. */
164
+ export function callEventHandler<T, E extends Event>(
165
+ event: E & { currentTarget: T; target: Element },
166
+ handler: JSX.EventHandlerUnion<T, E> | undefined,
167
+ ): void {
168
+ if (!handler) return;
169
+ if (typeof handler === "function") handler(event);
170
+ else handler[0](handler[1], event);
171
+ }
172
+
173
+ export type ModalDismissProps = ComponentProps<typeof KobalteButton>;
174
+
175
+ /* Not kobalte's own CloseButton: that one hard-defaults aria-label to its
176
+ * "Dismiss" translation, and an aria-label outranks the visible text, so every
177
+ * labelled button in every modal answered to "Dismiss". Here a name is set only
178
+ * when the caller passes one. AlertDialog is built on the Dialog context, so
179
+ * one factory serves both families. */
180
+ export function createModalDismiss(slot: string): ParentComponent<ModalDismissProps> {
181
+ return (props) => {
182
+ const [local, rest] = splitProps(props, ["onClick"]);
183
+ const context = useDialogContext();
184
+ return (
185
+ <KobalteButton
186
+ data-slot={slot}
187
+ onClick={(event: MouseEvent & { currentTarget: HTMLButtonElement; target: Element }) => {
188
+ callEventHandler(event, local.onClick);
189
+ context.close();
190
+ }}
191
+ {...rest}
192
+ />
193
+ );
194
+ };
195
+ }
196
+
197
+ /** Renderless. Mounted inside a portal that exists only while the modal is
198
+ * open, so the refcounted page lock follows the modal's real lifetime. */
199
+ export const ModalScrollLock: Component = () => {
200
+ onMount(acquireScrollLock);
201
+ onCleanup(releaseScrollLock);
202
+ return null;
203
+ };
204
+
205
+ export interface ModalLabels {
206
+ titleId: string;
207
+ descriptionId: string;
208
+ labelledBy: Accessor<string | undefined>;
209
+ describedBy: Accessor<string | undefined>;
210
+ registerTitle: (id: string | undefined) => void;
211
+ registerDescription: (id: string | undefined) => void;
212
+ }
213
+
214
+ const ModalLabelsContext = createContext<ModalLabels>();
215
+
216
+ /** Kobalte wires title/description ids for its own families; the hand-rolled
217
+ * surfaces (BottomSheet) wire them through this. The part registers the id it
218
+ * actually rendered, so a caller's own `id` still labels the panel. */
219
+ export function createModalLabels(): ModalLabels {
220
+ const titleId = createUniqueId();
221
+ const descriptionId = createUniqueId();
222
+ const [labelledBy, setLabelledBy] = createSignal<string>();
223
+ const [describedBy, setDescribedBy] = createSignal<string>();
224
+ const register = (set: (id: string | undefined) => void, id: string | undefined) => {
225
+ set(id);
226
+ onCleanup(() => set(undefined));
227
+ };
228
+ return {
229
+ titleId,
230
+ descriptionId,
231
+ labelledBy,
232
+ describedBy,
233
+ registerTitle: (id) => register(setLabelledBy, id),
234
+ registerDescription: (id) => register(setDescribedBy, id),
235
+ };
236
+ }
237
+
238
+ export const ModalLabelsProvider = ModalLabelsContext.Provider;
239
+
240
+ export function useModalLabels(): ModalLabels | undefined {
241
+ return useContext(ModalLabelsContext);
242
+ }
@@ -0,0 +1,121 @@
1
+ import { Dialog as DialogPrimitive, useDialogContext } from "@kobalte/core/dialog";
2
+ import type { VariantProps } from "cva";
3
+ import { type Component, type ComponentProps, type ParentComponent, splitProps } from "solid-js";
4
+ import { buttonVariants } from "../lib/button-variants.js";
5
+ import { cn } from "../lib/utils.js";
6
+ import {
7
+ createModalDismiss,
8
+ createModalParts,
9
+ MODAL_ANCHOR,
10
+ MODAL_DESCRIPTION,
11
+ MODAL_PANEL,
12
+ MODAL_SCRIM,
13
+ MODAL_TITLE,
14
+ MODAL_WIDTH,
15
+ type ModalDismissProps,
16
+ ModalScrollLock,
17
+ type ModalSize,
18
+ } from "./dialog-parts.js";
19
+
20
+ /* Kobalte's own scroll lock is off everywhere: one refcounted lock
21
+ * (bottom-sheet/scroll-lock.ts) serves every modal family, so a nested modal
22
+ * cannot release the page early. */
23
+ const Dialog: ParentComponent<ComponentProps<typeof DialogPrimitive>> = (props) => (
24
+ <DialogPrimitive {...props} preventScroll={false} />
25
+ );
26
+
27
+ const DialogTrigger: Component<ComponentProps<typeof DialogPrimitive.Trigger>> = (props) => (
28
+ <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
29
+ );
30
+
31
+ type DialogCloseProps = ModalDismissProps &
32
+ Partial<Pick<VariantProps<typeof buttonVariants>, "variant" | "size">>;
33
+
34
+ const DialogDismiss = createModalDismiss("dialog-close");
35
+
36
+ /** Already the outline button, so `as` is for a non-button element (a link),
37
+ * never for `Button`: two buttonVariants() calls leave tone knobs side by side
38
+ * and the later stylesheet rule wins. */
39
+ const DialogClose: ParentComponent<DialogCloseProps> = (props) => {
40
+ const [local, rest] = splitProps(props, ["class", "variant", "size", "children"]);
41
+ return (
42
+ <DialogDismiss
43
+ class={cn(
44
+ buttonVariants({ variant: local.variant ?? "outline", size: local.size }),
45
+ local.class,
46
+ )}
47
+ {...rest}
48
+ >
49
+ {local.children ?? "Close"}
50
+ </DialogDismiss>
51
+ );
52
+ };
53
+
54
+ type DialogContentProps = ComponentProps<typeof DialogPrimitive.Content> & {
55
+ size?: ModalSize;
56
+ /** Names a panel that has no `DialogTitle`. A registered Title wins. */
57
+ ariaLabel?: string;
58
+ };
59
+
60
+ const DialogContent: ParentComponent<DialogContentProps> = (props) => {
61
+ const [local, others] = splitProps(props, ["class", "children", "size", "ariaLabel"]);
62
+ const context = useDialogContext();
63
+ return (
64
+ <DialogPrimitive.Portal>
65
+ <ModalScrollLock />
66
+ <DialogPrimitive.Overlay data-slot="dialog-overlay" class={MODAL_SCRIM} />
67
+ <DialogPrimitive.Content
68
+ data-slot="dialog-content"
69
+ role="dialog"
70
+ aria-label={context.titleId() ? undefined : local.ariaLabel}
71
+ class={cn(
72
+ MODAL_PANEL,
73
+ MODAL_WIDTH[local.size ?? "lg"],
74
+ MODAL_ANCHOR[local.size ?? "lg"],
75
+ local.class,
76
+ )}
77
+ {...others}
78
+ >
79
+ {local.children}
80
+ </DialogPrimitive.Content>
81
+ </DialogPrimitive.Portal>
82
+ );
83
+ };
84
+
85
+ const { Header: DialogHeader, Body: DialogBody, Footer: DialogFooter } = createModalParts("dialog");
86
+
87
+ const DialogTitle: Component<ComponentProps<typeof DialogPrimitive.Title>> = (props) => {
88
+ const [local, others] = splitProps(props, ["class"]);
89
+ return (
90
+ <DialogPrimitive.Title
91
+ data-slot="dialog-title"
92
+ class={cn(MODAL_TITLE, local.class)}
93
+ {...others}
94
+ />
95
+ );
96
+ };
97
+
98
+ const DialogDescription: Component<ComponentProps<typeof DialogPrimitive.Description>> = (
99
+ props,
100
+ ) => {
101
+ const [local, others] = splitProps(props, ["class"]);
102
+ return (
103
+ <DialogPrimitive.Description
104
+ data-slot="dialog-description"
105
+ class={cn(MODAL_DESCRIPTION, local.class)}
106
+ {...others}
107
+ />
108
+ );
109
+ };
110
+
111
+ export {
112
+ Dialog,
113
+ DialogBody,
114
+ DialogClose,
115
+ DialogContent,
116
+ DialogDescription,
117
+ DialogFooter,
118
+ DialogHeader,
119
+ DialogTitle,
120
+ DialogTrigger,
121
+ };
@@ -0,0 +1,186 @@
1
+ import {
2
+ type Component,
3
+ type ComponentProps,
4
+ createEffect,
5
+ createSignal,
6
+ Index,
7
+ type JSX,
8
+ onCleanup,
9
+ onMount,
10
+ Show,
11
+ splitProps,
12
+ } from "solid-js";
13
+ import { Dynamic } from "solid-js/web";
14
+ import { CARD_SURFACE } from "../lib/card-classes.js";
15
+ import { PRESS_DIP } from "../lib/motion-classes.js";
16
+ import { cn } from "../lib/utils.js";
17
+ import { Badge } from "./badge.js";
18
+ import { SlidingIndicator } from "./sliding-indicator.js";
19
+ import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js";
20
+
21
+ interface DockItem {
22
+ id: string;
23
+ icon: Component<{ class?: string }> | JSX.Element;
24
+ label: string;
25
+ onClick?: () => void;
26
+ isActive?: boolean;
27
+ /** Optional count badge on the item (e.g. pending updates). */
28
+ badge?: number;
29
+ }
30
+
31
+ interface DockProps extends ComponentProps<"div"> {
32
+ items: DockItem[];
33
+ dockMode?: "floating" | "docked";
34
+ }
35
+
36
+ interface DockIconButtonProps extends ComponentProps<"button"> {
37
+ icon: Component<{ class?: string }> | JSX.Element;
38
+ label: string;
39
+ isActive?: boolean;
40
+ badge?: number;
41
+ }
42
+
43
+ const DockIconButton: Component<DockIconButtonProps> = (props) => {
44
+ // Kobalte's button root narrows `type`; Solid's ComponentProps<"button"> also
45
+ // admits "menu", so it is split off rather than spread.
46
+ const [local, rest] = splitProps(props, ["icon", "label", "class", "isActive", "badge", "type"]);
47
+ const isElement = () => typeof local.icon !== "function";
48
+
49
+ return (
50
+ <Tooltip openDelay={150} placement="top">
51
+ <TooltipTrigger
52
+ type="button"
53
+ data-slot="dock-item"
54
+ class={cn(
55
+ "group relative flex size-11 touch-manipulation items-center justify-center rounded-lg transition-transform duration-(--duration-micro) sm:size-12",
56
+ PRESS_DIP,
57
+ local.class,
58
+ )}
59
+ aria-label={local.label}
60
+ aria-current={local.isActive ? "page" : undefined}
61
+ {...rest}
62
+ >
63
+ <div
64
+ data-slot="dock-item-icon"
65
+ class={cn(
66
+ "flex items-center justify-center transition-colors duration-300",
67
+ local.isActive ? "text-primary" : "text-foreground group-hover:text-primary/80",
68
+ )}
69
+ >
70
+ {isElement() ? (
71
+ (local.icon as JSX.Element)
72
+ ) : (
73
+ <Dynamic
74
+ component={local.icon as Component<{ class?: string }>}
75
+ class="h-5 w-5 sm:h-6 sm:w-6"
76
+ />
77
+ )}
78
+ </div>
79
+ <Show when={typeof local.badge === "number" && local.badge > 0}>
80
+ {/* Inside the item box: an overhanging badge inflates the bar's
81
+ * scrollWidth and trips the overflow-to-scroll check below. */}
82
+ <Badge
83
+ role="status"
84
+ tone="var(--primary)"
85
+ class="absolute top-0 right-0 h-4 min-w-4 justify-center px-1 pt-0.5 pb-0 font-medium font-mono text-[9px] tabular-nums leading-none"
86
+ aria-label={`${local.badge} pending`}
87
+ >
88
+ {local.badge != null && local.badge > 9 ? "9+" : local.badge}
89
+ </Badge>
90
+ </Show>
91
+ </TooltipTrigger>
92
+ <TooltipContent class="hidden sm:block">{local.label}</TooltipContent>
93
+ </Tooltip>
94
+ );
95
+ };
96
+
97
+ const Dock: Component<DockProps> = (props) => {
98
+ const [local, rest] = splitProps(props, ["items", "class", "dockMode"]);
99
+ const dockMode = () => local.dockMode ?? "floating";
100
+ let containerRef!: HTMLDivElement;
101
+ const [needsScroll, setNeedsScroll] = createSignal(false);
102
+
103
+ // The moving background: the shared SlidingIndicator tracks the active item.
104
+ const activeIndex = () => {
105
+ const i = local.items.findIndex((it) => it.isActive);
106
+ return i < 0 ? null : i;
107
+ };
108
+
109
+ const checkOverflow = () => {
110
+ if (containerRef) {
111
+ const naturalWidth = containerRef.scrollWidth;
112
+ const availableWidth = containerRef.parentElement?.clientWidth || window.innerWidth;
113
+ setNeedsScroll(naturalWidth > availableWidth);
114
+ }
115
+ };
116
+
117
+ onMount(() => {
118
+ const timeoutId = setTimeout(checkOverflow, 100);
119
+ // disconnect() stops further callbacks but not one already scheduled, so the
120
+ // pending id is held to be cleared on cleanup.
121
+ let resizeTimeoutId: ReturnType<typeof setTimeout> | undefined;
122
+ const resizeObserver = new ResizeObserver(() => {
123
+ clearTimeout(resizeTimeoutId);
124
+ resizeTimeoutId = setTimeout(checkOverflow, 50);
125
+ });
126
+ resizeObserver.observe(containerRef);
127
+ onCleanup(() => {
128
+ clearTimeout(timeoutId);
129
+ clearTimeout(resizeTimeoutId);
130
+ resizeObserver.disconnect();
131
+ });
132
+ });
133
+
134
+ createEffect(() => {
135
+ local.items.length;
136
+ const timeoutId = setTimeout(checkOverflow, 150);
137
+ onCleanup(() => clearTimeout(timeoutId));
138
+ });
139
+
140
+ return (
141
+ <div
142
+ data-slot="dock"
143
+ class={cn(
144
+ "flex items-center justify-center",
145
+ dockMode() === "floating" ? "p-1 sm:p-2" : "",
146
+ local.class,
147
+ )}
148
+ {...rest}
149
+ >
150
+ <div class="relative flex items-center justify-center">
151
+ <div
152
+ ref={containerRef}
153
+ data-slot="dock-bar"
154
+ class={cn(
155
+ "flex items-center gap-0.5 p-1.5 sm:gap-1 sm:p-2",
156
+ CARD_SURFACE,
157
+ "[--glass-lift:0.55]",
158
+ dockMode() === "floating" ? "rounded-xl" : "rounded-t-xl",
159
+ needsScroll() ? "scrollbar-hide overflow-x-auto" : "overflow-visible",
160
+ !needsScroll() && "justify-center",
161
+ )}
162
+ style={{
163
+ "min-width": needsScroll() ? "auto" : "fit-content",
164
+ }}
165
+ >
166
+ <SlidingIndicator active={activeIndex()} class="flex items-center gap-0.5 sm:gap-1">
167
+ <Index each={local.items}>
168
+ {(item) => (
169
+ <DockIconButton
170
+ icon={item().icon}
171
+ label={item().label}
172
+ onClick={item().onClick}
173
+ isActive={item().isActive}
174
+ badge={item().badge}
175
+ />
176
+ )}
177
+ </Index>
178
+ </SlidingIndicator>
179
+ </div>
180
+ </div>
181
+ </div>
182
+ );
183
+ };
184
+
185
+ export type { DockIconButtonProps, DockItem, DockProps };
186
+ export { Dock };
@@ -0,0 +1,130 @@
1
+ import { DropdownMenu as DropdownMenuPrimitive } from "@kobalte/core/dropdown-menu";
2
+ import { useMenuContext } from "@kobalte/core/menu";
3
+ import { type Component, type ComponentProps, type ParentComponent, splitProps } from "solid-js";
4
+ import { MORPH_MOTION } from "../lib/motion-classes.js";
5
+ import { anchorToTriggerTop } from "../lib/overlay-classes.js";
6
+ import { cn } from "../lib/utils.js";
7
+ import {
8
+ MENU_CONTENT_CLASS,
9
+ MenuCheckboxItemPart,
10
+ MenuContentIndicator,
11
+ MenuItemPart,
12
+ MenuLabelPart,
13
+ MenuRadioItemPart,
14
+ MenuSeparatorPart,
15
+ MenuSubContentPart,
16
+ MenuSubTriggerPart,
17
+ } from "./menu-parts.js";
18
+
19
+ /* The panel covers the trigger (see MORPH_MOTION); statics carried across so
20
+ * `DropdownMenu.Portal` keeps resolving. */
21
+ const DropdownMenuRoot: Component<ComponentProps<typeof DropdownMenuPrimitive>> = (props) => (
22
+ <DropdownMenuPrimitive gutter={0} getAnchorRect={anchorToTriggerTop} {...props} />
23
+ );
24
+ const DropdownMenu = Object.assign(DropdownMenuRoot, DropdownMenuPrimitive) as Component<
25
+ ComponentProps<typeof DropdownMenuPrimitive>
26
+ > &
27
+ typeof DropdownMenuPrimitive;
28
+ const DropdownMenuGroup = DropdownMenuPrimitive.Group;
29
+ const DropdownMenuSub = DropdownMenuPrimitive.Sub;
30
+ const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
31
+
32
+ const DropdownMenuTrigger: Component<ComponentProps<typeof DropdownMenuPrimitive.Trigger>> = (
33
+ props,
34
+ ) => {
35
+ return <DropdownMenuPrimitive.Trigger data-slot="dropdown-menu-trigger" {...props} />;
36
+ };
37
+
38
+ const DropdownMenuContent: Component<ComponentProps<typeof DropdownMenuPrimitive.Content>> = (
39
+ props,
40
+ ) => {
41
+ const [local, others] = splitProps(props, ["class", "children"]);
42
+ const menu = useMenuContext();
43
+ // The morph starts as the trigger's box: its height and radius are read
44
+ // from the trigger itself, its width is kobalte's anchor width.
45
+ const writeMorphStart = (el: HTMLElement) => {
46
+ const trigger = menu.triggerRef();
47
+ if (!trigger) return;
48
+ const height = trigger.getBoundingClientRect().height;
49
+ // A pill's radius is "infinite"; the rendered one is half its height.
50
+ const radius = Math.min(
51
+ Number.parseFloat(getComputedStyle(trigger).borderTopLeftRadius) || 0,
52
+ height / 2,
53
+ );
54
+ el.style.setProperty("--morph-h", `${height}px`);
55
+ el.style.setProperty("--morph-radius", `${radius}px`);
56
+ };
57
+ return (
58
+ <DropdownMenuPrimitive.Portal>
59
+ <DropdownMenuPrimitive.Content
60
+ ref={writeMorphStart}
61
+ data-slot="dropdown-menu-content"
62
+ class={cn(MENU_CONTENT_CLASS, MORPH_MOTION, local.class)}
63
+ {...others}
64
+ >
65
+ <MenuContentIndicator>{local.children}</MenuContentIndicator>
66
+ </DropdownMenuPrimitive.Content>
67
+ </DropdownMenuPrimitive.Portal>
68
+ );
69
+ };
70
+
71
+ const DropdownMenuItem: Component<
72
+ ComponentProps<typeof DropdownMenuPrimitive.Item> & {
73
+ inset?: boolean;
74
+ tone?: string;
75
+ /** @deprecated pass `tone="var(--destructive)"` instead */
76
+ variant?: "default" | "destructive";
77
+ }
78
+ > = (props) => <MenuItemPart slotName="dropdown-menu-item" {...props} />;
79
+
80
+ const DropdownMenuSubTrigger: ParentComponent<
81
+ ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & { inset?: boolean }
82
+ > = (props) => <MenuSubTriggerPart slotName="dropdown-menu-sub-trigger" {...props} />;
83
+
84
+ const DropdownMenuSubContent: ParentComponent<
85
+ ComponentProps<typeof DropdownMenuPrimitive.SubContent>
86
+ > = (props) => <MenuSubContentPart slotName="dropdown-menu-sub-content" {...props} />;
87
+
88
+ const DropdownMenuCheckboxItem: ParentComponent<
89
+ ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>
90
+ > = (props) => <MenuCheckboxItemPart slotName="dropdown-menu-checkbox-item" {...props} />;
91
+
92
+ const DropdownMenuRadioItem: ParentComponent<
93
+ ComponentProps<typeof DropdownMenuPrimitive.RadioItem>
94
+ > = (props) => <MenuRadioItemPart slotName="dropdown-menu-radio-item" {...props} />;
95
+
96
+ const DropdownMenuSeparator: Component<ComponentProps<typeof DropdownMenuPrimitive.Separator>> = (
97
+ props,
98
+ ) => <MenuSeparatorPart slotName="dropdown-menu-separator" {...props} />;
99
+
100
+ const DropdownMenuLabel: Component<
101
+ ComponentProps<typeof DropdownMenuPrimitive.GroupLabel> & { inset?: boolean }
102
+ > = (props) => <MenuLabelPart slotName="dropdown-menu-label" {...props} />;
103
+
104
+ const DropdownMenuShortcut: Component<ComponentProps<"span">> = (props) => {
105
+ const [local, others] = splitProps(props, ["class"]);
106
+ return (
107
+ <span
108
+ data-slot="dropdown-menu-shortcut"
109
+ class={cn("ml-auto text-muted-foreground text-xs tracking-widest", local.class)}
110
+ {...others}
111
+ />
112
+ );
113
+ };
114
+
115
+ export {
116
+ DropdownMenu,
117
+ DropdownMenuCheckboxItem,
118
+ DropdownMenuContent,
119
+ DropdownMenuGroup,
120
+ DropdownMenuItem,
121
+ DropdownMenuLabel,
122
+ DropdownMenuRadioGroup,
123
+ DropdownMenuRadioItem,
124
+ DropdownMenuSeparator,
125
+ DropdownMenuShortcut,
126
+ DropdownMenuSub,
127
+ DropdownMenuSubContent,
128
+ DropdownMenuSubTrigger,
129
+ DropdownMenuTrigger,
130
+ };