@glasshome/ui 1.10.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 (103) hide show
  1. package/package.json +5 -2
  2. package/scripts/check-pack.ts +32 -0
  3. package/src/index.ts +111 -0
  4. package/src/solid/accordion.tsx +60 -0
  5. package/src/solid/alert-dialog.tsx +148 -0
  6. package/src/solid/alert.tsx +118 -0
  7. package/src/solid/area-picker.tsx +225 -0
  8. package/src/solid/aspect-ratio.tsx +21 -0
  9. package/src/solid/avatar.tsx +41 -0
  10. package/src/solid/badge.tsx +74 -0
  11. package/src/solid/bottom-sheet/arbitration.ts +40 -0
  12. package/src/solid/bottom-sheet/bottom-sheet.tsx +457 -0
  13. package/src/solid/bottom-sheet/constants.ts +8 -0
  14. package/src/solid/bottom-sheet/drag-controller.ts +221 -0
  15. package/src/solid/bottom-sheet/focus-trap.ts +56 -0
  16. package/src/solid/bottom-sheet/index.ts +14 -0
  17. package/src/solid/bottom-sheet/keyboard.ts +35 -0
  18. package/src/solid/bottom-sheet/scroll-lock.ts +64 -0
  19. package/src/solid/bottom-sheet/state-machine.ts +40 -0
  20. package/src/solid/bottom-sheet/velocity.ts +42 -0
  21. package/src/solid/breadcrumb.tsx +105 -0
  22. package/src/solid/button-group.tsx +66 -0
  23. package/src/solid/button.tsx +20 -0
  24. package/src/solid/card.tsx +101 -0
  25. package/src/solid/carousel.tsx +302 -0
  26. package/src/solid/charts.tsx +338 -0
  27. package/src/solid/checkbox.tsx +70 -0
  28. package/src/solid/collapsible.tsx +38 -0
  29. package/src/solid/color-slider.tsx +98 -0
  30. package/src/solid/color-wheel.tsx +77 -0
  31. package/src/solid/context-menu.tsx +109 -0
  32. package/src/solid/copy-button.tsx +46 -0
  33. package/src/solid/count-pill.tsx +24 -0
  34. package/src/solid/data-table.tsx +248 -0
  35. package/src/solid/dialog-parts.tsx +242 -0
  36. package/src/solid/dialog.tsx +121 -0
  37. package/src/solid/dock.tsx +186 -0
  38. package/src/solid/dropdown-menu.tsx +130 -0
  39. package/src/solid/empty.tsx +99 -0
  40. package/src/solid/entity-data.ts +78 -0
  41. package/src/solid/entity-selector.tsx +697 -0
  42. package/src/solid/field.tsx +253 -0
  43. package/src/solid/form.tsx +231 -0
  44. package/src/solid/hero-action.tsx +117 -0
  45. package/src/solid/hover-card.tsx +26 -0
  46. package/src/solid/icon-picker.tsx +432 -0
  47. package/src/solid/icon.tsx +20 -0
  48. package/src/solid/image-picker.tsx +380 -0
  49. package/src/solid/index.ts +417 -0
  50. package/src/solid/input-group.tsx +170 -0
  51. package/src/solid/input-otp.tsx +175 -0
  52. package/src/solid/input.tsx +12 -0
  53. package/src/solid/item.tsx +179 -0
  54. package/src/solid/kbd.tsx +30 -0
  55. package/src/solid/label.tsx +19 -0
  56. package/src/solid/list-reorder.ts +148 -0
  57. package/src/solid/logo.tsx +79 -0
  58. package/src/solid/media-copy.ts +37 -0
  59. package/src/solid/media-store.ts +110 -0
  60. package/src/solid/media-tile.tsx +100 -0
  61. package/src/solid/menu-parts.tsx +248 -0
  62. package/src/solid/number-field.tsx +72 -0
  63. package/src/solid/option-card.tsx +218 -0
  64. package/src/solid/ornament.tsx +53 -0
  65. package/src/solid/overlay.tsx +16 -0
  66. package/src/solid/page-header.tsx +102 -0
  67. package/src/solid/pagination.tsx +111 -0
  68. package/src/solid/password-input.tsx +69 -0
  69. package/src/solid/picker-row.tsx +102 -0
  70. package/src/solid/picker-search.tsx +78 -0
  71. package/src/solid/popover.tsx +103 -0
  72. package/src/solid/progress.tsx +31 -0
  73. package/src/solid/radio-group.tsx +60 -0
  74. package/src/solid/resizable.tsx +149 -0
  75. package/src/solid/responsive-dialog.tsx +180 -0
  76. package/src/solid/schema-form.tsx +830 -0
  77. package/src/solid/scope-indicator.tsx +13 -0
  78. package/src/solid/scroll-area.tsx +27 -0
  79. package/src/solid/section-card.tsx +358 -0
  80. package/src/solid/select.tsx +139 -0
  81. package/src/solid/separator.tsx +35 -0
  82. package/src/solid/settings-row.tsx +159 -0
  83. package/src/solid/sheet.tsx +157 -0
  84. package/src/solid/skeleton.tsx +15 -0
  85. package/src/solid/slider.tsx +148 -0
  86. package/src/solid/sliding-indicator.tsx +294 -0
  87. package/src/solid/sonner.tsx +219 -0
  88. package/src/solid/spinner.tsx +20 -0
  89. package/src/solid/step-indicator.tsx +30 -0
  90. package/src/solid/switch.tsx +62 -0
  91. package/src/solid/table.tsx +98 -0
  92. package/src/solid/tabs.tsx +86 -0
  93. package/src/solid/textarea.tsx +16 -0
  94. package/src/solid/toggle-group.tsx +102 -0
  95. package/src/solid/toggle.tsx +57 -0
  96. package/src/solid/tooltip.tsx +38 -0
  97. package/src/solid/widget-card.tsx +117 -0
  98. package/src/solid/widget-identity.tsx +135 -0
  99. package/src/solid/widget-trust-badge.tsx +37 -0
  100. package/src/tokens/hex.ts +50 -0
  101. package/src/tokens/index.ts +8 -0
  102. package/src/tokens/presets.ts +192 -0
  103. package/src/tokens/theme-colors.ts +147 -0
@@ -0,0 +1,175 @@
1
+ import {
2
+ type Component,
3
+ type ComponentProps,
4
+ createContext,
5
+ createSignal,
6
+ type ParentComponent,
7
+ Show,
8
+ splitProps,
9
+ useContext,
10
+ } from "solid-js";
11
+ import { CONTROL_H, FOCUS_RING, INPUT_SURFACE } from "../lib/input-classes.js";
12
+ import { cn } from "../lib/utils.js";
13
+ import { Icon } from "./icon.js";
14
+
15
+ interface InputOTPContextValue {
16
+ value: () => string;
17
+ activeIndex: () => number;
18
+ isActive: () => boolean;
19
+ }
20
+
21
+ const InputOTPContext = createContext<InputOTPContextValue>();
22
+
23
+ const InputOTP: ParentComponent<
24
+ ComponentProps<"div"> & {
25
+ maxLength: number;
26
+ value?: string;
27
+ onValueChange?: (value: string) => void;
28
+ onComplete?: (value: string) => void;
29
+ containerClass?: string;
30
+ pattern?: string;
31
+ }
32
+ > = (props) => {
33
+ const [local, rest] = splitProps(props, [
34
+ "class",
35
+ "children",
36
+ "maxLength",
37
+ "value",
38
+ "onValueChange",
39
+ "onComplete",
40
+ "containerClass",
41
+ "pattern",
42
+ ]);
43
+ const [internalValue, setInternalValue] = createSignal(local.value ?? "");
44
+ const [activeIndex, setActiveIndex] = createSignal(-1);
45
+ const [isActive, setIsActive] = createSignal(false);
46
+ let inputRef!: HTMLInputElement;
47
+
48
+ const value = () => (local.value !== undefined ? local.value : internalValue());
49
+
50
+ const handleInput = (e: InputEvent) => {
51
+ const target = e.target as HTMLInputElement;
52
+ let newValue = target.value.slice(0, local.maxLength);
53
+ if (local.pattern) {
54
+ const regex = new RegExp(local.pattern);
55
+ newValue = newValue
56
+ .split("")
57
+ .filter((c) => regex.test(c))
58
+ .join("");
59
+ }
60
+ setInternalValue(newValue);
61
+ local.onValueChange?.(newValue);
62
+ setActiveIndex(newValue.length);
63
+ if (newValue.length === local.maxLength) {
64
+ local.onComplete?.(newValue);
65
+ }
66
+ };
67
+
68
+ const handleKeyDown = (e: KeyboardEvent) => {
69
+ if (e.key === "Backspace") {
70
+ const val = value();
71
+ if (val.length > 0) {
72
+ const newValue = val.slice(0, -1);
73
+ setInternalValue(newValue);
74
+ local.onValueChange?.(newValue);
75
+ setActiveIndex(newValue.length);
76
+ }
77
+ e.preventDefault();
78
+ }
79
+ };
80
+
81
+ const handleFocus = () => {
82
+ setIsActive(true);
83
+ setActiveIndex(value().length);
84
+ };
85
+
86
+ const handleBlur = () => {
87
+ setIsActive(false);
88
+ setActiveIndex(-1);
89
+ };
90
+
91
+ return (
92
+ <InputOTPContext.Provider value={{ value, activeIndex, isActive }}>
93
+ {/* Container click forwards focus to the visually hidden input, which owns all keyboard interaction. */}
94
+ {/* biome-ignore lint/a11y/noStaticElementInteractions: see above */}
95
+ {/* biome-ignore lint/a11y/useKeyWithClickEvents: see above */}
96
+ <div
97
+ data-slot="input-otp"
98
+ class={cn("flex items-center gap-2 has-[:disabled]:opacity-50", local.containerClass)}
99
+ onClick={() => inputRef.focus()}
100
+ {...rest}
101
+ >
102
+ <input
103
+ ref={inputRef}
104
+ type="text"
105
+ inputMode="numeric"
106
+ autocomplete="one-time-code"
107
+ maxLength={local.maxLength}
108
+ value={value()}
109
+ onInput={handleInput}
110
+ onKeyDown={handleKeyDown}
111
+ onFocus={handleFocus}
112
+ onBlur={handleBlur}
113
+ class={cn(
114
+ "pointer-events-none absolute opacity-0",
115
+ "disabled:cursor-not-allowed",
116
+ local.class,
117
+ )}
118
+ />
119
+ {local.children}
120
+ </div>
121
+ </InputOTPContext.Provider>
122
+ );
123
+ };
124
+
125
+ const InputOTPGroup: Component<ComponentProps<"div">> = (props) => {
126
+ const [local, rest] = splitProps(props, ["class"]);
127
+ return (
128
+ <div
129
+ data-slot="input-otp-group"
130
+ class={cn("flex items-center gap-1.5", local.class)}
131
+ {...rest}
132
+ />
133
+ );
134
+ };
135
+
136
+ const InputOTPSlot: Component<ComponentProps<"div"> & { index: number }> = (props) => {
137
+ const [local, rest] = splitProps(props, ["class", "index"]);
138
+ const context = useContext(InputOTPContext);
139
+ const char = () => context?.value()[local.index] ?? "";
140
+ const isSlotActive = () => context?.isActive() && context?.activeIndex() === local.index;
141
+ const hasFakeCaret = () => isSlotActive() && !char();
142
+
143
+ return (
144
+ <div
145
+ data-slot="input-otp-slot"
146
+ data-active={isSlotActive()}
147
+ class={cn(
148
+ // Same constraint as the checkbox box: the theme's smallest radius token
149
+ // fully rounds a cell this size, and a digit cell is not a dot.
150
+ `relative flex ${CONTROL_H.default} w-9 items-center justify-center rounded-xs ${INPUT_SURFACE} text-sm transition-glass ${FOCUS_RING}`,
151
+ "data-[active=true]:z-10 data-[active=true]:ring-[3px] data-[active=true]:ring-ring/50 data-[active=true]:[--glass-edge:var(--ring)]",
152
+ "aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:[--glass-edge:var(--destructive)]",
153
+ local.class,
154
+ )}
155
+ {...rest}
156
+ >
157
+ {char()}
158
+ <Show when={hasFakeCaret()}>
159
+ <div class="pointer-events-none absolute inset-0 flex items-center justify-center">
160
+ <div class="h-4 w-px animate-caret-blink bg-foreground duration-1000" />
161
+ </div>
162
+ </Show>
163
+ </div>
164
+ );
165
+ };
166
+
167
+ const InputOTPSeparator: Component<ComponentProps<"div">> = (props) => {
168
+ return (
169
+ <div data-slot="input-otp-separator" aria-hidden="true" {...props}>
170
+ <Icon icon="lucide:minus" width={16} height={16} />
171
+ </div>
172
+ );
173
+ };
174
+
175
+ export { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot };
@@ -0,0 +1,12 @@
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
+
5
+ const Input: Component<ComponentProps<"input">> = (props) => {
6
+ const [local, others] = splitProps(props, ["class", "type"]);
7
+ return (
8
+ <input type={local.type} data-slot="input" class={cn(INPUT_CLASS, local.class)} {...others} />
9
+ );
10
+ };
11
+
12
+ export { Input };
@@ -0,0 +1,179 @@
1
+ import { cva, type VariantProps } from "cva";
2
+ import { type Component, type ComponentProps, splitProps, type ValidComponent } from "solid-js";
3
+ import { Dynamic } from "solid-js/web";
4
+ import { ICON_PILL } from "../lib/pill-classes.js";
5
+ import { cn } from "../lib/utils.js";
6
+ import { Separator } from "./separator.js";
7
+
8
+ const ItemGroup: Component<ComponentProps<"ul">> = (props) => {
9
+ const [local, rest] = splitProps(props, ["class"]);
10
+ return (
11
+ <ul
12
+ data-slot="item-group"
13
+ class={cn("group/item-group flex flex-col", local.class)}
14
+ {...rest}
15
+ />
16
+ );
17
+ };
18
+
19
+ const ItemSeparator: Component<ComponentProps<typeof Separator>> = (props) => {
20
+ const [local, rest] = splitProps(props, ["class"]);
21
+ return (
22
+ <Separator
23
+ data-slot="item-separator"
24
+ orientation="horizontal"
25
+ class={cn("my-0", local.class)}
26
+ {...rest}
27
+ />
28
+ );
29
+ };
30
+
31
+ const itemVariants = cva({
32
+ base: "group/item flex flex-wrap items-center rounded-md border border-transparent text-sm outline-none transition-colors duration-100 focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 [a]:transition-colors [a]:hover:bg-muted/50",
33
+ variants: {
34
+ variant: {
35
+ // Item is structure, not a surface (that is <Card>). Plain treatments only.
36
+ default: "bg-transparent",
37
+ outline: "border-border",
38
+ muted: "bg-muted/40",
39
+ },
40
+ size: {
41
+ default: "gap-4 p-4",
42
+ sm: "gap-2.5 px-4 py-3",
43
+ },
44
+ },
45
+ defaultVariants: {
46
+ variant: "default",
47
+ size: "default",
48
+ },
49
+ });
50
+
51
+ const Item: Component<
52
+ ComponentProps<"div"> & VariantProps<typeof itemVariants> & { as?: ValidComponent; href?: string }
53
+ > = (props) => {
54
+ const [local, rest] = splitProps(props, ["class", "variant", "size", "as"] as const);
55
+ const variant = () => local.variant ?? "default";
56
+ const size = () => local.size ?? "default";
57
+ const Comp = () => local.as || "div";
58
+ return (
59
+ <Dynamic
60
+ component={Comp()}
61
+ data-slot="item"
62
+ data-variant={variant()}
63
+ data-size={size()}
64
+ class={cn(itemVariants({ variant: variant(), size: size() }), local.class)}
65
+ {...rest}
66
+ />
67
+ );
68
+ };
69
+
70
+ type ItemMediaKind = "icon" | "image";
71
+
72
+ const ITEM_MEDIA: Record<ItemMediaKind, string> = {
73
+ icon: `${ICON_PILL} size-8 rounded-md text-foreground/80 [&_svg:not([class*='size-'])]:size-4`,
74
+ image: "size-10 overflow-hidden rounded-sm [&_img]:size-full [&_img]:object-cover",
75
+ };
76
+
77
+ const ItemMedia: Component<
78
+ ComponentProps<"div"> & {
79
+ /** The well the media sits in. Omit for bare content. */
80
+ media?: ItemMediaKind;
81
+ /** @deprecated `media` */
82
+ variant?: ItemMediaKind | "default";
83
+ }
84
+ > = (props) => {
85
+ const [local, rest] = splitProps(props, ["class", "media", "variant"] as const);
86
+ const media = () => local.media ?? (local.variant === "default" ? undefined : local.variant);
87
+ return (
88
+ <div
89
+ data-slot="item-media"
90
+ data-media={media()}
91
+ data-variant={local.variant ?? media() ?? "default"}
92
+ class={cn(
93
+ "flex shrink-0 items-center justify-center gap-2 group-has-[[data-slot=item-description]]/item:translate-y-0.5 group-has-[[data-slot=item-description]]/item:self-start [&_svg]:pointer-events-none",
94
+ media() && ITEM_MEDIA[media() as ItemMediaKind],
95
+ local.class,
96
+ )}
97
+ {...rest}
98
+ />
99
+ );
100
+ };
101
+
102
+ const ItemContent: Component<ComponentProps<"div">> = (props) => {
103
+ const [local, rest] = splitProps(props, ["class"]);
104
+ return (
105
+ <div
106
+ data-slot="item-content"
107
+ class={cn("flex flex-1 flex-col gap-1 [&+[data-slot=item-content]]:flex-none", local.class)}
108
+ {...rest}
109
+ />
110
+ );
111
+ };
112
+
113
+ const ItemTitle: Component<ComponentProps<"div">> = (props) => {
114
+ const [local, rest] = splitProps(props, ["class"]);
115
+ return (
116
+ <div
117
+ data-slot="item-title"
118
+ class={cn("flex w-fit items-center gap-2 font-medium text-sm leading-snug", local.class)}
119
+ {...rest}
120
+ />
121
+ );
122
+ };
123
+
124
+ const ItemDescription: Component<ComponentProps<"p">> = (props) => {
125
+ const [local, rest] = splitProps(props, ["class"]);
126
+ return (
127
+ <p
128
+ data-slot="item-description"
129
+ class={cn(
130
+ "line-clamp-2 text-balance font-normal text-muted-foreground text-sm leading-normal",
131
+ "[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",
132
+ local.class,
133
+ )}
134
+ {...rest}
135
+ />
136
+ );
137
+ };
138
+
139
+ const ItemActions: Component<ComponentProps<"div">> = (props) => {
140
+ const [local, rest] = splitProps(props, ["class"]);
141
+ return (
142
+ <div data-slot="item-actions" class={cn("flex items-center gap-2", local.class)} {...rest} />
143
+ );
144
+ };
145
+
146
+ const ItemHeader: Component<ComponentProps<"div">> = (props) => {
147
+ const [local, rest] = splitProps(props, ["class"]);
148
+ return (
149
+ <div
150
+ data-slot="item-header"
151
+ class={cn("flex basis-full items-center justify-between gap-2", local.class)}
152
+ {...rest}
153
+ />
154
+ );
155
+ };
156
+
157
+ const ItemFooter: Component<ComponentProps<"div">> = (props) => {
158
+ const [local, rest] = splitProps(props, ["class"]);
159
+ return (
160
+ <div
161
+ data-slot="item-footer"
162
+ class={cn("flex basis-full items-center justify-between gap-2", local.class)}
163
+ {...rest}
164
+ />
165
+ );
166
+ };
167
+
168
+ export {
169
+ Item,
170
+ ItemActions,
171
+ ItemContent,
172
+ ItemDescription,
173
+ ItemFooter,
174
+ ItemGroup,
175
+ ItemHeader,
176
+ ItemMedia,
177
+ ItemSeparator,
178
+ ItemTitle,
179
+ };
@@ -0,0 +1,30 @@
1
+ import { type Component, type ComponentProps, splitProps } from "solid-js";
2
+ import { cn } from "../lib/utils.js";
3
+
4
+ const Kbd: Component<ComponentProps<"kbd">> = (props) => {
5
+ const [local, rest] = splitProps(props, ["class"]);
6
+ return (
7
+ <kbd
8
+ data-slot="kbd"
9
+ class={cn(
10
+ "pointer-events-none inline-flex h-5 w-fit min-w-5 select-none items-center justify-center gap-1 rounded-sm bg-muted px-1 font-medium font-sans text-muted-foreground text-xs",
11
+ "[&_svg:not([class*='size-'])]:size-3",
12
+ local.class,
13
+ )}
14
+ {...rest}
15
+ />
16
+ );
17
+ };
18
+
19
+ const KbdGroup: Component<ComponentProps<"kbd">> = (props) => {
20
+ const [local, rest] = splitProps(props, ["class"]);
21
+ return (
22
+ <kbd
23
+ data-slot="kbd-group"
24
+ class={cn("inline-flex items-center gap-1", local.class)}
25
+ {...rest}
26
+ />
27
+ );
28
+ };
29
+
30
+ export { Kbd, KbdGroup };
@@ -0,0 +1,19 @@
1
+ import { type Component, type ComponentProps, splitProps } from "solid-js";
2
+ import { cn } from "../lib/utils.js";
3
+
4
+ const Label: Component<ComponentProps<"label">> = (props) => {
5
+ const [local, others] = splitProps(props, ["class"]);
6
+ return (
7
+ // biome-ignore lint/a11y/noLabelWithoutControl: generic library label; callers associate it via `for` or by nesting the control.
8
+ <label
9
+ data-slot="label"
10
+ class={cn(
11
+ "flex select-none items-center gap-2 font-medium text-sm leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-50 group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50",
12
+ local.class,
13
+ )}
14
+ {...others}
15
+ />
16
+ );
17
+ };
18
+
19
+ export { Label };
@@ -0,0 +1,148 @@
1
+ import { createSignal } from "solid-js";
2
+
3
+ const DEFAULT_GAP_PX = 8;
4
+ const DRAG_THRESHOLD_PX = 6;
5
+
6
+ /**
7
+ * Where a row dragged by dy lands: cross into a neighbor once the pointer
8
+ * passes half that neighbor's height, using live measured heights so rows of
9
+ * different sizes (e.g. one expanded) count at their real size.
10
+ */
11
+ export function dragTargetIndex(heights: number[], from: number, dy: number): number {
12
+ let to = from;
13
+ let remaining = dy;
14
+ if (dy < 0) {
15
+ while (to > 0 && -remaining > (heights[to - 1] ?? 0) / 2) {
16
+ remaining += heights[to - 1] ?? 0;
17
+ to--;
18
+ }
19
+ } else {
20
+ while (to < heights.length - 1 && remaining > (heights[to + 1] ?? 0) / 2) {
21
+ remaining -= heights[to + 1] ?? 0;
22
+ to++;
23
+ }
24
+ }
25
+ return to;
26
+ }
27
+
28
+ export interface ListReorderOptions {
29
+ /** Live row count; row elements beyond it are ignored. */
30
+ count: () => number;
31
+ /** Commit a completed drag (or keyboard move). Indices are pre-move. */
32
+ onReorder: (from: number, to: number) => void;
33
+ /** Fires when a drag actually activates (e.g. collapse the dragged row). */
34
+ onDragStart?: (index: number) => void;
35
+ /** Vertical gap between rows in px; neighbors shift by height + gap. */
36
+ gapPx?: number;
37
+ }
38
+
39
+ export interface ListReorder {
40
+ /** Attach as each row's ref so heights can be measured live. */
41
+ setRowEl: (index: number, el: HTMLElement) => void;
42
+ /**
43
+ * Wire to pointerdown. immediate: a dedicated handle, drags at once, any
44
+ * pointer type. Non-immediate: a whole clickable row, mouse/pen only
45
+ * (touch must keep scrolling) and only past a movement threshold so plain
46
+ * clicks keep their meaning.
47
+ */
48
+ startDrag: (index: number, e: PointerEvent, immediate: boolean) => void;
49
+ /** Inline style for a row: the dragged row follows the pointer, rows
50
+ * between origin and target shift one slot. Undefined when idle. */
51
+ rowStyle: (index: number) => Record<string, string | number> | undefined;
52
+ /** Index being dragged, undefined when idle. */
53
+ draggingIndex: () => number | undefined;
54
+ /** True from drag activation until the click that follows pointerup has
55
+ * passed; row click/toggle handlers must ignore that click. */
56
+ isToggleSuppressed: () => boolean;
57
+ }
58
+
59
+ /** Pointer-driven vertical list reorder. Rendering-agnostic: the consumer owns
60
+ * the rows and applies rowStyle; this owns pointer tracking and drop math. */
61
+ export function createListReorder(opts: ListReorderOptions): ListReorder {
62
+ const gap = opts.gapPx ?? DEFAULT_GAP_PX;
63
+ const rowEls: Array<HTMLElement | undefined> = [];
64
+ const [drag, setDrag] = createSignal<{ from: number; to: number; dy: number } | null>(null);
65
+ // One-frame phase after a drop: transforms clear with transitions disabled,
66
+ // otherwise every row animates from its dragged offset back to zero before
67
+ // the reordered content appears (visible snap-back).
68
+ const [settling, setSettling] = createSignal(false);
69
+ let suppressToggle = false;
70
+
71
+ const startDrag = (index: number, e: PointerEvent, immediate: boolean) => {
72
+ if (e.pointerType === "mouse" && e.button !== 0) return;
73
+ if (!immediate && e.pointerType === "touch") return;
74
+ const el = e.currentTarget as HTMLElement;
75
+ if (immediate) e.preventDefault();
76
+ const startY = e.clientY;
77
+ let active = false;
78
+ const activate = (dy: number) => {
79
+ active = true;
80
+ suppressToggle = true;
81
+ try {
82
+ el.setPointerCapture(e.pointerId);
83
+ } catch {
84
+ // jsdom and detached elements: capture is best-effort
85
+ }
86
+ opts.onDragStart?.(index);
87
+ setDrag({ from: index, to: index, dy });
88
+ };
89
+ const heights = () => rowEls.slice(0, opts.count()).map((row) => row?.offsetHeight ?? 0);
90
+ const onMove = (ev: PointerEvent) => {
91
+ const dy = ev.clientY - startY;
92
+ if (!active) {
93
+ if (Math.abs(dy) < DRAG_THRESHOLD_PX) return;
94
+ activate(dy);
95
+ }
96
+ setDrag({ from: index, to: dragTargetIndex(heights(), index, dy), dy });
97
+ };
98
+ const onUp = () => {
99
+ el.removeEventListener("pointermove", onMove);
100
+ el.removeEventListener("pointerup", onUp);
101
+ el.removeEventListener("pointercancel", onUp);
102
+ const d = drag();
103
+ if (active && d) {
104
+ setSettling(true);
105
+ if (typeof requestAnimationFrame === "function") {
106
+ requestAnimationFrame(() => requestAnimationFrame(() => setSettling(false)));
107
+ } else {
108
+ setSettling(false);
109
+ }
110
+ }
111
+ setDrag(null);
112
+ if (active && d) opts.onReorder(d.from, d.to);
113
+ setTimeout(() => {
114
+ suppressToggle = false;
115
+ }, 0);
116
+ };
117
+ if (immediate) activate(0);
118
+ el.addEventListener("pointermove", onMove);
119
+ el.addEventListener("pointerup", onUp);
120
+ el.addEventListener("pointercancel", onUp);
121
+ };
122
+
123
+ const rowStyle = (index: number): Record<string, string | number> | undefined => {
124
+ const d = drag();
125
+ if (!d) return settling() ? { transition: "none" } : undefined;
126
+ if (index === d.from) {
127
+ return { transform: `translateY(${d.dy}px)`, transition: "none", "z-index": 10 };
128
+ }
129
+ const slot = (rowEls[d.from]?.offsetHeight ?? 0) + gap;
130
+ if (d.to > d.from && index > d.from && index <= d.to) {
131
+ return { transform: `translateY(-${slot}px)` };
132
+ }
133
+ if (d.to < d.from && index >= d.to && index < d.from) {
134
+ return { transform: `translateY(${slot}px)` };
135
+ }
136
+ return undefined;
137
+ };
138
+
139
+ return {
140
+ setRowEl: (index, el) => {
141
+ rowEls[index] = el;
142
+ },
143
+ startDrag,
144
+ rowStyle,
145
+ draggingIndex: () => drag()?.from,
146
+ isToggleSuppressed: () => suppressToggle,
147
+ };
148
+ }
@@ -0,0 +1,79 @@
1
+ import { type Component, type ComponentProps, type JSX, splitProps } from "solid-js";
2
+ import { Dynamic } from "solid-js/web";
3
+ import {
4
+ LOGO_DEFAULT_SIZE,
5
+ LOGO_DEFAULT_SRC,
6
+ LOGO_DEFAULT_SUB,
7
+ LOGO_MARK_CLASS,
8
+ LOGO_MARK_PX,
9
+ LOGO_NAME_CLASS,
10
+ LOGO_ROOT_CLASS,
11
+ LOGO_SIZES,
12
+ LOGO_STACK_CLASS,
13
+ LOGO_SUB_CLASS,
14
+ type LogoSize,
15
+ } from "../lib/logo-lockup.js";
16
+ import { cn } from "../lib/utils.js";
17
+
18
+ type LogoProps = Omit<ComponentProps<"div">, "children"> & {
19
+ /** Sub-brand line. Defaults to "Dash". */
20
+ sub?: string;
21
+ size?: LogoSize;
22
+ /** Renders the lockup as a link when set. */
23
+ href?: string;
24
+ /** Override the mark asset. Both apps serve the default path. */
25
+ src?: string;
26
+ /** Extra classes for the mark, e.g. a hover transform. */
27
+ markClass?: string;
28
+ /** Replaces the sub-brand line for surfaces that animate over it. */
29
+ subSlot?: JSX.Element;
30
+ };
31
+
32
+ /**
33
+ * The GlassHome lockup: mark + "GlassHome" + the sub-brand line. One ratio
34
+ * everywhere (audit L2) — the sub-line is the dominant element, the wordmark
35
+ * rides above it as a smaller eyebrow, and both scale together via `size`.
36
+ * Never hand-build this stack; the spec lives in lib/logo-lockup.ts.
37
+ */
38
+ const Logo: Component<LogoProps> = (props) => {
39
+ const [local, others] = splitProps(props, [
40
+ "class",
41
+ "sub",
42
+ "size",
43
+ "href",
44
+ "src",
45
+ "markClass",
46
+ "subSlot",
47
+ ]);
48
+ const size = () => local.size ?? LOGO_DEFAULT_SIZE;
49
+ const s = () => LOGO_SIZES[size()];
50
+ return (
51
+ <Dynamic
52
+ component={local.href ? "a" : "div"}
53
+ data-slot="logo"
54
+ class={cn(LOGO_ROOT_CLASS, s().gap, local.class)}
55
+ href={local.href}
56
+ {...others}
57
+ >
58
+ <img
59
+ src={local.src ?? LOGO_DEFAULT_SRC}
60
+ alt=""
61
+ width={LOGO_MARK_PX[size()]}
62
+ height={LOGO_MARK_PX[size()]}
63
+ class={cn(LOGO_MARK_CLASS, s().mark, local.markClass)}
64
+ />
65
+ <span class={LOGO_STACK_CLASS}>
66
+ <span data-slot="logo-name" class={cn(s().name, LOGO_NAME_CLASS)}>
67
+ GlassHome
68
+ </span>
69
+ {local.subSlot ?? (
70
+ <span data-slot="logo-sub" class={cn(s().sub, LOGO_SUB_CLASS)}>
71
+ {local.sub ?? LOGO_DEFAULT_SUB}
72
+ </span>
73
+ )}
74
+ </span>
75
+ </Dynamic>
76
+ );
77
+ };
78
+
79
+ export { Logo };
@@ -0,0 +1,37 @@
1
+ import { formatBytes } from "./charts.js";
2
+ import { type MediaQuotaUsage, MediaStoreError, type MediaStoreErrorKind } from "./media-store.js";
3
+
4
+ /** One table for every surface that shows a media failure: the picker, the settings
5
+ * section, the library. Two tables drifted apart once already. */
6
+ const STORE_ERROR_COPY: Record<MediaStoreErrorKind, (usage?: MediaQuotaUsage) => string> = {
7
+ file_too_large: () => "That file is too large to upload.",
8
+ image_too_large: () => "That image's dimensions are too large.",
9
+ not_an_image: () => "That file isn't an image.",
10
+ quota_bytes_exceeded: (usage) =>
11
+ usage
12
+ ? `You've used ${formatBytes(usage.bytes)} of ${formatBytes(usage.limitBytes)} of photo storage. Delete a photo to free up space.`
13
+ : "You're out of photo storage. Delete a photo to free up space.",
14
+ quota_files_exceeded: (usage) =>
15
+ usage
16
+ ? `You've stored ${usage.files} of ${usage.limitFiles} photos. Delete one to add another.`
17
+ : "You've reached the photo limit. Delete one to add another.",
18
+ upload_rate_exceeded: () => "Too many uploads at once. Wait a moment and try again.",
19
+ server_storage_full: () =>
20
+ "The dashboard's photo storage is full. Whoever runs this dashboard needs to free up space on the server.",
21
+ no_active_household: () => "No household is active, so photos can't be stored right now.",
22
+ upload_failed: () => "That didn't work. Try again, and sign in again if it keeps failing.",
23
+ };
24
+
25
+ export function toMediaStoreError(cause: unknown): MediaStoreError {
26
+ return cause instanceof MediaStoreError ? cause : new MediaStoreError("upload_failed");
27
+ }
28
+
29
+ export function mediaStoreErrorCopy(error: MediaStoreError): string {
30
+ return STORE_ERROR_COPY[error.kind](error.usage);
31
+ }
32
+
33
+ export function mediaIndexErrorCopy(error: MediaStoreError): string {
34
+ return error.kind === "no_active_household"
35
+ ? "No household is active, so your photos can't be listed right now."
36
+ : "Your photos couldn't be listed. The dashboard may have lost the server.";
37
+ }