@glasshome/ui 1.9.0 → 1.10.1

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 (122) hide show
  1. package/README.md +2 -13
  2. package/SPEC.md +4 -4
  3. package/dist/lib/badge-tone.d.ts +0 -2
  4. package/dist/solid/badge.d.ts +1 -1
  5. package/dist/solid/card.d.ts +4 -2
  6. package/dist/solid/icon.d.ts +14 -0
  7. package/dist/solid/index.js +1645 -1632
  8. package/dist/solid/spinner.d.ts +1 -1
  9. package/package.json +9 -12
  10. package/scripts/check-pack.ts +32 -0
  11. package/src/index.ts +111 -0
  12. package/src/lib/badge-tone.ts +0 -4
  13. package/src/lib/carousel-classes.ts +2 -3
  14. package/src/solid/accordion.tsx +60 -0
  15. package/src/solid/alert-dialog.tsx +148 -0
  16. package/src/solid/alert.tsx +118 -0
  17. package/src/solid/area-picker.tsx +225 -0
  18. package/src/solid/aspect-ratio.tsx +21 -0
  19. package/src/solid/avatar.tsx +41 -0
  20. package/src/solid/badge.tsx +74 -0
  21. package/src/solid/bottom-sheet/arbitration.ts +40 -0
  22. package/src/solid/bottom-sheet/bottom-sheet.tsx +457 -0
  23. package/src/solid/bottom-sheet/constants.ts +8 -0
  24. package/src/solid/bottom-sheet/drag-controller.ts +221 -0
  25. package/src/solid/bottom-sheet/focus-trap.ts +56 -0
  26. package/src/solid/bottom-sheet/index.ts +14 -0
  27. package/src/solid/bottom-sheet/keyboard.ts +35 -0
  28. package/src/solid/bottom-sheet/scroll-lock.ts +64 -0
  29. package/src/solid/bottom-sheet/state-machine.ts +40 -0
  30. package/src/solid/bottom-sheet/velocity.ts +42 -0
  31. package/src/solid/breadcrumb.tsx +105 -0
  32. package/src/solid/button-group.tsx +66 -0
  33. package/src/solid/button.tsx +20 -0
  34. package/src/solid/card.tsx +101 -0
  35. package/src/solid/carousel.tsx +302 -0
  36. package/src/solid/charts.tsx +338 -0
  37. package/src/solid/checkbox.tsx +70 -0
  38. package/src/solid/collapsible.tsx +38 -0
  39. package/src/solid/color-slider.tsx +98 -0
  40. package/src/solid/color-wheel.tsx +77 -0
  41. package/src/solid/context-menu.tsx +109 -0
  42. package/src/solid/copy-button.tsx +46 -0
  43. package/src/solid/count-pill.tsx +24 -0
  44. package/src/solid/data-table.tsx +248 -0
  45. package/src/solid/dialog-parts.tsx +242 -0
  46. package/src/solid/dialog.tsx +121 -0
  47. package/src/solid/dock.tsx +186 -0
  48. package/src/solid/dropdown-menu.tsx +130 -0
  49. package/src/solid/empty.tsx +99 -0
  50. package/src/solid/entity-data.ts +78 -0
  51. package/src/solid/entity-selector.tsx +697 -0
  52. package/src/solid/field.tsx +253 -0
  53. package/src/solid/form.tsx +231 -0
  54. package/src/solid/hero-action.tsx +117 -0
  55. package/src/solid/hover-card.tsx +26 -0
  56. package/src/solid/icon-picker.tsx +432 -0
  57. package/src/solid/icon.tsx +20 -0
  58. package/src/solid/image-picker.tsx +380 -0
  59. package/src/solid/index.ts +417 -0
  60. package/src/solid/input-group.tsx +170 -0
  61. package/src/solid/input-otp.tsx +175 -0
  62. package/src/solid/input.tsx +12 -0
  63. package/src/solid/item.tsx +179 -0
  64. package/src/solid/kbd.tsx +30 -0
  65. package/src/solid/label.tsx +19 -0
  66. package/src/solid/list-reorder.ts +148 -0
  67. package/src/solid/logo.tsx +79 -0
  68. package/src/solid/media-copy.ts +37 -0
  69. package/src/solid/media-store.ts +110 -0
  70. package/src/solid/media-tile.tsx +100 -0
  71. package/src/solid/menu-parts.tsx +248 -0
  72. package/src/solid/number-field.tsx +72 -0
  73. package/src/solid/option-card.tsx +218 -0
  74. package/src/solid/ornament.tsx +53 -0
  75. package/src/solid/overlay.tsx +16 -0
  76. package/src/solid/page-header.tsx +102 -0
  77. package/src/solid/pagination.tsx +111 -0
  78. package/src/solid/password-input.tsx +69 -0
  79. package/src/solid/picker-row.tsx +102 -0
  80. package/src/solid/picker-search.tsx +78 -0
  81. package/src/solid/popover.tsx +103 -0
  82. package/src/solid/progress.tsx +31 -0
  83. package/src/solid/radio-group.tsx +60 -0
  84. package/src/solid/resizable.tsx +149 -0
  85. package/src/solid/responsive-dialog.tsx +180 -0
  86. package/src/solid/schema-form.tsx +830 -0
  87. package/src/solid/scope-indicator.tsx +13 -0
  88. package/src/solid/scroll-area.tsx +27 -0
  89. package/src/solid/section-card.tsx +358 -0
  90. package/src/solid/select.tsx +139 -0
  91. package/src/solid/separator.tsx +35 -0
  92. package/src/solid/settings-row.tsx +159 -0
  93. package/src/solid/sheet.tsx +157 -0
  94. package/src/solid/skeleton.tsx +15 -0
  95. package/src/solid/slider.tsx +148 -0
  96. package/src/solid/sliding-indicator.tsx +294 -0
  97. package/src/solid/sonner.tsx +219 -0
  98. package/src/solid/spinner.tsx +20 -0
  99. package/src/solid/step-indicator.tsx +30 -0
  100. package/src/solid/switch.tsx +62 -0
  101. package/src/solid/table.tsx +98 -0
  102. package/src/solid/tabs.tsx +86 -0
  103. package/src/solid/textarea.tsx +16 -0
  104. package/src/solid/toggle-group.tsx +102 -0
  105. package/src/solid/toggle.tsx +57 -0
  106. package/src/solid/tooltip.tsx +38 -0
  107. package/src/solid/widget-card.tsx +117 -0
  108. package/src/solid/widget-identity.tsx +135 -0
  109. package/src/solid/widget-trust-badge.tsx +37 -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
  114. package/dist/lib/carousel-init.d.ts +0 -9
  115. package/src/astro/Alert.astro +0 -63
  116. package/src/astro/Badge.astro +0 -18
  117. package/src/astro/Button.astro +0 -47
  118. package/src/astro/Card.astro +0 -48
  119. package/src/astro/Carousel.astro +0 -82
  120. package/src/astro/Logo.astro +0 -73
  121. package/src/astro/TierBadge.astro +0 -33
  122. package/src/lib/carousel-init.ts +0 -87
@@ -0,0 +1,78 @@
1
+ import { type JSX, Show, splitProps } from "solid-js";
2
+ import { CONTROL_H, FIELD_TEXT } from "../lib/input-classes.js";
3
+ import { CONTROL_H_TOUCH } from "../lib/picker-classes.js";
4
+ import { cn } from "../lib/utils.js";
5
+ import { Icon } from "./icon.js";
6
+
7
+ export interface PickerSearchProps
8
+ extends Omit<JSX.InputHTMLAttributes<HTMLInputElement>, "value" | "onInput" | "class"> {
9
+ value?: string;
10
+ onValueChange?: (value: string) => void;
11
+ /** Rendered leading; the row is a divider, not a nested field. */
12
+ icon?: string;
13
+ /** Trailing button that empties the query; hidden while it is empty. */
14
+ clearLabel?: string;
15
+ class?: string;
16
+ inputRef?: (el: HTMLInputElement) => void;
17
+ /** "touch" is the sheet row: a picker that opens as a bottom sheet makes this
18
+ * its primary control, so it takes the full touch target. */
19
+ size?: "default" | "touch";
20
+ }
21
+
22
+ const SEARCH_H = { default: CONTROL_H.default, touch: CONTROL_H_TOUCH } as const;
23
+
24
+ /* The search row inside a picker panel. A bare input, not a nested Input: the
25
+ * panel already wears the field surface, so a second one reads as a field in a
26
+ * field. */
27
+ export function PickerSearch(props: PickerSearchProps) {
28
+ const [local, rest] = splitProps(props, [
29
+ "value",
30
+ "onValueChange",
31
+ "icon",
32
+ "clearLabel",
33
+ "class",
34
+ "inputRef",
35
+ "size",
36
+ ]);
37
+ return (
38
+ <div
39
+ data-slot="picker-search"
40
+ class={cn(
41
+ "flex shrink-0 items-center gap-2 border-border/50 border-b px-3",
42
+ SEARCH_H[local.size ?? "default"],
43
+ local.class,
44
+ )}
45
+ >
46
+ <Icon
47
+ icon={local.icon ?? "mdi:magnify"}
48
+ width={16}
49
+ height={16}
50
+ class="shrink-0 text-muted-foreground"
51
+ aria-hidden="true"
52
+ />
53
+ <input
54
+ ref={local.inputRef}
55
+ data-slot="picker-search-input"
56
+ type="text"
57
+ value={local.value ?? ""}
58
+ onInput={(e) => local.onValueChange?.(e.currentTarget.value)}
59
+ class={cn(
60
+ "h-full w-full min-w-0 appearance-none bg-transparent outline-none placeholder:text-muted-foreground",
61
+ FIELD_TEXT,
62
+ )}
63
+ {...rest}
64
+ />
65
+ <Show when={local.clearLabel && local.value}>
66
+ <button
67
+ type="button"
68
+ data-slot="picker-search-clear"
69
+ aria-label={local.clearLabel}
70
+ class="shrink-0 rounded-sm p-1 text-muted-foreground transition-colors hover:text-foreground"
71
+ onClick={() => local.onValueChange?.("")}
72
+ >
73
+ <Icon icon="mdi:close-circle" width={16} height={16} />
74
+ </button>
75
+ </Show>
76
+ </div>
77
+ );
78
+ }
@@ -0,0 +1,103 @@
1
+ import { Popover as PopoverPrimitive, usePopoverContext } from "@kobalte/core/popover";
2
+ import {
3
+ type Component,
4
+ type ComponentProps,
5
+ createContext,
6
+ splitProps,
7
+ useContext,
8
+ } from "solid-js";
9
+ import { INPUT_SURFACE } from "../lib/input-classes.js";
10
+ import { Z_CLASS } from "../lib/layers.js";
11
+ import { FIELD_MOTION, MORPH_MOTION, STAGGER } from "../lib/motion-classes.js";
12
+ import { anchorToTriggerTop, FLOATING_PANEL } from "../lib/overlay-classes.js";
13
+ import { cn } from "../lib/utils.js";
14
+
15
+ type PopoverSurface = "overlay" | "field";
16
+
17
+ const PopoverSurfaceContext = createContext<() => PopoverSurface>(
18
+ () => "overlay" as PopoverSurface,
19
+ );
20
+
21
+ /* The expanding field panel: opaque (the trigger sits underneath it), bound to
22
+ * the anchor width and radius, and padded by whatever part needs padding, never
23
+ * by the panel, so the panel edge and the trigger edge are one rectangle. */
24
+ const FIELD_PANEL = `${INPUT_SURFACE} ${FIELD_MOTION} relative ${Z_CLASS.overlay} w-[var(--kb-popper-anchor-width)] overflow-hidden rounded-md text-popover-foreground outline-hidden`;
25
+
26
+ const OVERLAY_PANEL = `${FLOATING_PANEL} ${MORPH_MOTION} ${STAGGER} w-72 p-4`;
27
+
28
+ type PopoverProps = ComponentProps<typeof PopoverPrimitive> & {
29
+ /** "field" anchors the panel over the trigger's top edge, so the field reads
30
+ * as expanding into its panel instead of a box dropping in below it. */
31
+ surface?: PopoverSurface;
32
+ };
33
+
34
+ const PopoverRoot: Component<PopoverProps> = (props) => {
35
+ const [local, rest] = splitProps(props, ["surface", "gutter", "getAnchorRect"]);
36
+ const surface = () => local.surface ?? "overlay";
37
+ return (
38
+ <PopoverSurfaceContext.Provider value={surface}>
39
+ <PopoverPrimitive
40
+ gutter={local.gutter ?? 0}
41
+ getAnchorRect={local.getAnchorRect ?? anchorToTriggerTop}
42
+ flip={false}
43
+ overlap
44
+ {...rest}
45
+ />
46
+ </PopoverSurfaceContext.Provider>
47
+ );
48
+ };
49
+
50
+ /* Omit<T, never> keeps the statics and drops the call signature, so the
51
+ * intersection has one call signature: ours, with `surface`. */
52
+ type PopoverStatics = Omit<typeof PopoverPrimitive, never>;
53
+
54
+ /* Kobalte hangs Anchor/Content/Portal/Title/Trigger/CloseButton/Arrow off the
55
+ * root; carry them across so `Popover.Portal` keeps resolving for hosts that
56
+ * reach past the wrapped parts. */
57
+ const Popover = Object.assign(PopoverRoot, PopoverPrimitive) as Component<PopoverProps> &
58
+ PopoverStatics;
59
+
60
+ const PopoverTrigger: Component<ComponentProps<typeof PopoverPrimitive.Trigger>> = (props) => {
61
+ return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />;
62
+ };
63
+
64
+ type PopoverContentProps = ComponentProps<typeof PopoverPrimitive.Content> & {
65
+ surface?: PopoverSurface;
66
+ };
67
+
68
+ const PopoverContent: Component<PopoverContentProps> = (props) => {
69
+ const [local, rest] = splitProps(props, ["class", "surface"]);
70
+ const fromRoot = useContext(PopoverSurfaceContext);
71
+ const surface = () => local.surface ?? fromRoot();
72
+ const popover = usePopoverContext();
73
+ // The morph starts as the trigger's box (pill radius clamped to h/2). A
74
+ // field picker has an Anchor, not a Trigger, and keeps its clip reveal.
75
+ const writeMorphStart = (el: HTMLElement) => {
76
+ const trigger = popover.triggerRef();
77
+ if (!trigger || surface() === "field") return;
78
+ const height = trigger.getBoundingClientRect().height;
79
+ const radius = Math.min(
80
+ Number.parseFloat(getComputedStyle(trigger).borderTopLeftRadius) || 0,
81
+ height / 2,
82
+ );
83
+ el.style.setProperty("--morph-h", `${height}px`);
84
+ el.style.setProperty("--morph-radius", `${radius}px`);
85
+ };
86
+ return (
87
+ <PopoverPrimitive.Portal>
88
+ <PopoverPrimitive.Content
89
+ ref={writeMorphStart}
90
+ data-slot="popover-content"
91
+ data-surface={surface()}
92
+ class={cn(surface() === "field" ? FIELD_PANEL : OVERLAY_PANEL, local.class)}
93
+ {...rest}
94
+ />
95
+ </PopoverPrimitive.Portal>
96
+ );
97
+ };
98
+
99
+ const PopoverAnchor: Component<ComponentProps<typeof PopoverPrimitive.Anchor>> = (props) => {
100
+ return <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} />;
101
+ };
102
+
103
+ export { Popover, PopoverAnchor, PopoverContent, PopoverTrigger };
@@ -0,0 +1,31 @@
1
+ import { Progress as ProgressPrimitive } from "@kobalte/core/progress";
2
+ import { type Component, type ComponentProps, splitProps } from "solid-js";
3
+ import { FIELD_CHROME } from "../lib/input-classes.js";
4
+ import { cn } from "../lib/utils.js";
5
+
6
+ const Progress: Component<
7
+ ComponentProps<typeof ProgressPrimitive> & { value?: number; tone?: string }
8
+ > = (props) => {
9
+ const [local, rest] = splitProps(props, ["class", "value", "tone"]);
10
+ return (
11
+ <ProgressPrimitive
12
+ data-slot="progress"
13
+ value={local.value}
14
+ class={cn(FIELD_CHROME, "relative h-2 w-full overflow-hidden rounded-full", local.class)}
15
+ {...rest}
16
+ >
17
+ <ProgressPrimitive.Track class="h-full w-full">
18
+ <ProgressPrimitive.Fill
19
+ data-slot="progress-indicator"
20
+ class="glass glass-tint h-full w-full flex-1 transition-glass"
21
+ style={{
22
+ "--glass-tone": local.tone ?? "var(--primary)",
23
+ transform: `translateX(-${100 - (local.value || 0)}%)`,
24
+ }}
25
+ />
26
+ </ProgressPrimitive.Track>
27
+ </ProgressPrimitive>
28
+ );
29
+ };
30
+
31
+ export { Progress };
@@ -0,0 +1,60 @@
1
+ import { RadioGroup as RadioGroupPrimitive } from "@kobalte/core/radio-group";
2
+ import { type Component, type ComponentProps, Show, splitProps } from "solid-js";
3
+ import { FIELD_CHROME } from "../lib/input-classes.js";
4
+ import { cn } from "../lib/utils.js";
5
+
6
+ const RadioGroup: Component<ComponentProps<typeof RadioGroupPrimitive>> = (props) => {
7
+ const [local, rest] = splitProps(props, ["class"]);
8
+ return (
9
+ <RadioGroupPrimitive
10
+ data-slot="radio-group"
11
+ class={cn("flex flex-col gap-3", local.class)}
12
+ {...rest}
13
+ />
14
+ );
15
+ };
16
+
17
+ const RadioGroupItem: Component<
18
+ ComponentProps<typeof RadioGroupPrimitive.Item> & { showControl?: boolean }
19
+ > = (props) => {
20
+ const [local, rest] = splitProps(props, ["class", "children", "showControl"]);
21
+ return (
22
+ <RadioGroupPrimitive.Item
23
+ data-slot="radio-group-item"
24
+ class={cn("flex", local.class)}
25
+ {...rest}
26
+ >
27
+ <RadioGroupPrimitive.ItemInput class="peer" />
28
+ <RadioGroupPrimitive.ItemLabel
29
+ data-slot="radio-group-item-label"
30
+ class="flex flex-1 cursor-pointer select-none items-center gap-2.5 data-[disabled]:cursor-not-allowed"
31
+ >
32
+ <Show when={local.showControl ?? true}>
33
+ <RadioGroupPrimitive.ItemControl
34
+ data-slot="radio-group-item-control"
35
+ class={cn(
36
+ "relative flex aspect-square size-7 shrink-0 items-center justify-center overflow-hidden rounded-full transition-glass duration-200 ease-out active:scale-90",
37
+ FIELD_CHROME,
38
+ "peer-focus-visible:ring-[3px] peer-focus-visible:ring-ring/50 peer-focus-visible:[--glass-edge:var(--ring)]",
39
+ "data-[disabled]:opacity-40 data-[invalid]:ring-destructive/20 data-[invalid]:[--glass-edge:var(--destructive)]",
40
+ )}
41
+ >
42
+ {/* Gradient backgrounds can't transition; the glass rides an inner element
43
+ that animates in. */}
44
+ <RadioGroupPrimitive.ItemIndicator
45
+ data-slot="radio-group-item-indicator"
46
+ class="glass glass-tint zoom-in-50 fade-in absolute inset-0 animate-in rounded-full duration-200 [--glass-tone:var(--primary)]"
47
+ />
48
+ </RadioGroupPrimitive.ItemControl>
49
+ </Show>
50
+ {local.children && (
51
+ <div data-slot="radio-group-item-content" class="min-w-0 flex-1 text-sm">
52
+ {local.children}
53
+ </div>
54
+ )}
55
+ </RadioGroupPrimitive.ItemLabel>
56
+ </RadioGroupPrimitive.Item>
57
+ );
58
+ };
59
+
60
+ export { RadioGroup, RadioGroupItem };
@@ -0,0 +1,149 @@
1
+ import {
2
+ type Component,
3
+ type ComponentProps,
4
+ createContext,
5
+ type ParentComponent,
6
+ Show,
7
+ splitProps,
8
+ useContext,
9
+ } from "solid-js";
10
+ import { cn } from "../lib/utils.js";
11
+ import { Icon } from "./icon.js";
12
+
13
+ type Direction = "horizontal" | "vertical";
14
+
15
+ const ResizableContext = createContext<{ direction: () => Direction }>();
16
+
17
+ const ResizablePanelGroup: ParentComponent<ComponentProps<"div"> & { direction?: Direction }> = (
18
+ props,
19
+ ) => {
20
+ const [local, rest] = splitProps(props, ["class", "children", "direction"]);
21
+ const direction = () => local.direction ?? "horizontal";
22
+
23
+ return (
24
+ <ResizableContext.Provider value={{ direction }}>
25
+ <div
26
+ data-slot="resizable-panel-group"
27
+ data-panel-group-direction={direction()}
28
+ class={cn("flex h-full w-full data-[panel-group-direction=vertical]:flex-col", local.class)}
29
+ {...rest}
30
+ >
31
+ {local.children}
32
+ </div>
33
+ </ResizableContext.Provider>
34
+ );
35
+ };
36
+
37
+ const ResizablePanel: ParentComponent<
38
+ ComponentProps<"div"> & {
39
+ defaultSize?: number;
40
+ minSize?: number;
41
+ maxSize?: number;
42
+ }
43
+ > = (props) => {
44
+ const [local, rest] = splitProps(props, [
45
+ "class",
46
+ "children",
47
+ "defaultSize",
48
+ "minSize",
49
+ "maxSize",
50
+ "style",
51
+ ]);
52
+
53
+ return (
54
+ <div
55
+ data-slot="resizable-panel"
56
+ class={cn("flex-1 overflow-auto", local.class)}
57
+ style={{
58
+ ...(typeof local.style === "object" ? local.style : {}),
59
+ "flex-grow": local.defaultSize ? String(local.defaultSize) : undefined,
60
+ "min-width": local.minSize ? `${local.minSize}%` : undefined,
61
+ "max-width": local.maxSize ? `${local.maxSize}%` : undefined,
62
+ }}
63
+ {...rest}
64
+ >
65
+ {local.children}
66
+ </div>
67
+ );
68
+ };
69
+
70
+ const ResizableHandle: Component<ComponentProps<"div"> & { withHandle?: boolean }> = (props) => {
71
+ const [local, rest] = splitProps(props, ["class", "withHandle"]);
72
+ const ctx = useContext(ResizableContext);
73
+
74
+ const handlePointerDown = (e: PointerEvent) => {
75
+ e.preventDefault();
76
+ const target = e.currentTarget as HTMLElement;
77
+ target.setPointerCapture(e.pointerId);
78
+
79
+ const group = target.parentElement;
80
+ if (!group) return;
81
+
82
+ const dir = ctx?.direction() ?? "horizontal";
83
+ const panels = Array.from(group.querySelectorAll<HTMLElement>("[data-slot='resizable-panel']"));
84
+ const children = Array.from(group.children);
85
+ const handleIndex = children.indexOf(target);
86
+
87
+ // Find panels adjacent to this handle
88
+ let leftPanelIdx = -1;
89
+ let rightPanelIdx = -1;
90
+ let panelCount = 0;
91
+ for (let i = 0; i < children.length; i++) {
92
+ if ((children[i] as HTMLElement).dataset.slot === "resizable-panel") {
93
+ if (i < handleIndex) leftPanelIdx = panelCount;
94
+ if (i > handleIndex && rightPanelIdx === -1) rightPanelIdx = panelCount;
95
+ panelCount++;
96
+ }
97
+ }
98
+
99
+ const leftPanel = panels[leftPanelIdx];
100
+ const rightPanel = panels[rightPanelIdx];
101
+ if (!leftPanel || !rightPanel) return;
102
+
103
+ const startPos = dir === "horizontal" ? e.clientX : e.clientY;
104
+ const totalSize =
105
+ dir === "horizontal"
106
+ ? group.getBoundingClientRect().width
107
+ : group.getBoundingClientRect().height;
108
+ const leftStart = dir === "horizontal" ? leftPanel.offsetWidth : leftPanel.offsetHeight;
109
+ const rightStart = dir === "horizontal" ? rightPanel.offsetWidth : rightPanel.offsetHeight;
110
+
111
+ const handleMove = (ev: PointerEvent) => {
112
+ const currentPos = dir === "horizontal" ? ev.clientX : ev.clientY;
113
+ const delta = currentPos - startPos;
114
+ const newLeft = Math.max(0, leftStart + delta);
115
+ const newRight = Math.max(0, rightStart - delta);
116
+ leftPanel.style.flexGrow = String((newLeft / totalSize) * 100);
117
+ rightPanel.style.flexGrow = String((newRight / totalSize) * 100);
118
+ };
119
+
120
+ const handleUp = () => {
121
+ target.removeEventListener("pointermove", handleMove);
122
+ target.removeEventListener("pointerup", handleUp);
123
+ };
124
+
125
+ target.addEventListener("pointermove", handleMove);
126
+ target.addEventListener("pointerup", handleUp);
127
+ };
128
+
129
+ return (
130
+ <div
131
+ data-slot="resizable-handle"
132
+ data-panel-group-direction={ctx?.direction()}
133
+ class={cn(
134
+ "relative flex w-px items-center justify-center bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:translate-x-0 data-[panel-group-direction=vertical]:after:-translate-y-1/2 [&[data-panel-group-direction=vertical]>div]:rotate-90",
135
+ local.class,
136
+ )}
137
+ onPointerDown={handlePointerDown}
138
+ {...rest}
139
+ >
140
+ <Show when={local.withHandle}>
141
+ <div class="z-10 flex h-4 w-3 items-center justify-center rounded-xs border bg-border">
142
+ <Icon icon="lucide:grip-vertical" width={10} height={10} class="size-2.5" />
143
+ </div>
144
+ </Show>
145
+ </div>
146
+ );
147
+ };
148
+
149
+ export { ResizableHandle, ResizablePanel, ResizablePanelGroup };
@@ -0,0 +1,180 @@
1
+ import type { VariantProps } from "cva";
2
+ import {
3
+ type Component,
4
+ type ComponentProps,
5
+ createContext,
6
+ createSignal,
7
+ type JSX,
8
+ type ParentComponent,
9
+ Show,
10
+ splitProps,
11
+ useContext,
12
+ type ValidComponent,
13
+ } from "solid-js";
14
+ import type { buttonVariants } from "../lib/button-variants.js";
15
+ import { createIsMobile } from "../lib/use-is-mobile.js";
16
+ import {
17
+ BottomSheet,
18
+ BottomSheetContent,
19
+ BottomSheetDescription,
20
+ BottomSheetHandle,
21
+ BottomSheetOverlay,
22
+ BottomSheetPortal,
23
+ BottomSheetTitle,
24
+ BottomSheetTrigger,
25
+ } from "./bottom-sheet/index.js";
26
+ import { Button } from "./button.js";
27
+ import { Dialog, DialogContent, DialogDescription, DialogTitle, DialogTrigger } from "./dialog.js";
28
+ import { createModalParts, type ModalSize } from "./dialog-parts.js";
29
+
30
+ interface ResponsiveDialogContextValue {
31
+ open: () => boolean;
32
+ setOpen: (open: boolean) => void;
33
+ isMobile: () => boolean;
34
+ }
35
+
36
+ const ResponsiveDialogContext = createContext<ResponsiveDialogContextValue>();
37
+
38
+ function useResponsiveDialogContext(): ResponsiveDialogContextValue {
39
+ const ctx = useContext(ResponsiveDialogContext);
40
+ if (!ctx) throw new Error("ResponsiveDialog parts must be used within <ResponsiveDialog>");
41
+ return ctx;
42
+ }
43
+
44
+ interface ResponsiveDialogProps {
45
+ children: JSX.Element;
46
+ open?: boolean;
47
+ onOpenChange?: (open: boolean) => void;
48
+ defaultOpen?: boolean;
49
+ }
50
+
51
+ /** Centred kobalte dialog from `sm` up, drag-to-dismiss bottom sheet below it.
52
+ * Both branches render the same parts, so a call site never branches. */
53
+ const ResponsiveDialog: ParentComponent<ResponsiveDialogProps> = (props) => {
54
+ const [uncontrolledOpen, setUncontrolledOpen] = createSignal(props.defaultOpen ?? false);
55
+ const mobile = createIsMobile();
56
+ const isMobile = () => mobile() === true;
57
+
58
+ const open = () => (props.open !== undefined ? props.open === true : uncontrolledOpen());
59
+ const setOpen = (next: boolean) => {
60
+ if (props.open === undefined) setUncontrolledOpen(next);
61
+ props.onOpenChange?.(next);
62
+ };
63
+
64
+ return (
65
+ <ResponsiveDialogContext.Provider value={{ open, setOpen, isMobile }}>
66
+ <Show
67
+ when={isMobile()}
68
+ fallback={
69
+ <Dialog open={open()} onOpenChange={setOpen}>
70
+ {props.children}
71
+ </Dialog>
72
+ }
73
+ >
74
+ <BottomSheet open={open()} onOpenChange={setOpen}>
75
+ {props.children}
76
+ </BottomSheet>
77
+ </Show>
78
+ </ResponsiveDialogContext.Provider>
79
+ );
80
+ };
81
+
82
+ const ResponsiveDialogTrigger: ParentComponent<
83
+ ComponentProps<"button"> & { as?: ValidComponent }
84
+ > = (props) => {
85
+ const ctx = useResponsiveDialogContext();
86
+ return (
87
+ <Show when={ctx.isMobile()} fallback={<DialogTrigger {...props} />}>
88
+ <BottomSheetTrigger {...props} />
89
+ </Show>
90
+ );
91
+ };
92
+
93
+ type ResponsiveDialogContentProps = ComponentProps<"div"> & {
94
+ /** Desktop panel width. The mobile sheet is always full width. */
95
+ size?: ModalSize;
96
+ /** Names a panel that has no `ResponsiveDialogTitle`. */
97
+ ariaLabel?: string;
98
+ };
99
+
100
+ const ResponsiveDialogContent: ParentComponent<ResponsiveDialogContentProps> = (props) => {
101
+ const ctx = useResponsiveDialogContext();
102
+ const [local, rest] = splitProps(props, ["class", "children", "size", "ariaLabel"]);
103
+
104
+ return (
105
+ <Show
106
+ when={ctx.isMobile()}
107
+ fallback={
108
+ <DialogContent class={local.class} size={local.size} ariaLabel={local.ariaLabel} {...rest}>
109
+ {local.children}
110
+ </DialogContent>
111
+ }
112
+ >
113
+ <BottomSheetPortal>
114
+ <BottomSheetOverlay />
115
+ <BottomSheetContent class={local.class} ariaLabel={local.ariaLabel} {...rest}>
116
+ <BottomSheetHandle />
117
+ {local.children}
118
+ </BottomSheetContent>
119
+ </BottomSheetPortal>
120
+ </Show>
121
+ );
122
+ };
123
+
124
+ const {
125
+ Header: ResponsiveDialogHeader,
126
+ Body: ResponsiveDialogBody,
127
+ Footer: ResponsiveDialogFooter,
128
+ } = createModalParts("responsive-dialog");
129
+
130
+ const ResponsiveDialogTitle: Component<ComponentProps<"h2">> = (props) => {
131
+ const ctx = useResponsiveDialogContext();
132
+ return (
133
+ <Show when={ctx.isMobile()} fallback={<DialogTitle {...props} />}>
134
+ <BottomSheetTitle {...props} />
135
+ </Show>
136
+ );
137
+ };
138
+
139
+ const ResponsiveDialogDescription: Component<ComponentProps<"p">> = (props) => {
140
+ const ctx = useResponsiveDialogContext();
141
+ return (
142
+ <Show when={ctx.isMobile()} fallback={<DialogDescription {...props} />}>
143
+ <BottomSheetDescription {...props} />
144
+ </Show>
145
+ );
146
+ };
147
+
148
+ /** Defaults to the footer's outline button; an icon-only close passes `ghost`
149
+ * so the glyph is not boxed. */
150
+ const ResponsiveDialogClose: ParentComponent<
151
+ ComponentProps<"button"> & VariantProps<typeof buttonVariants>
152
+ > = (props) => {
153
+ const [local, rest] = splitProps(props, ["children", "class", "variant", "size"]);
154
+ const ctx = useResponsiveDialogContext();
155
+
156
+ return (
157
+ <Button
158
+ data-slot="responsive-dialog-close"
159
+ variant={local.variant ?? "outline"}
160
+ size={local.size}
161
+ onClick={() => ctx.setOpen(false)}
162
+ class={local.class}
163
+ {...rest}
164
+ >
165
+ {local.children ?? "Close"}
166
+ </Button>
167
+ );
168
+ };
169
+
170
+ export {
171
+ ResponsiveDialog,
172
+ ResponsiveDialogBody,
173
+ ResponsiveDialogClose,
174
+ ResponsiveDialogContent,
175
+ ResponsiveDialogDescription,
176
+ ResponsiveDialogFooter,
177
+ ResponsiveDialogHeader,
178
+ ResponsiveDialogTitle,
179
+ ResponsiveDialogTrigger,
180
+ };