@glasshome/ui 1.42.0 → 1.43.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 (147) hide show
  1. package/dist/index.js +2 -2
  2. package/dist/lib/anchor-placement.d.ts +4 -0
  3. package/dist/lib/balance-rows.d.ts +10 -4
  4. package/dist/lib/behavior/anchored.d.ts +16 -2
  5. package/dist/lib/behavior/button-root.d.ts +7 -0
  6. package/dist/lib/behavior/collection.d.ts +8 -0
  7. package/dist/lib/behavior/dismiss.d.ts +6 -4
  8. package/dist/lib/behavior/focus-scope.d.ts +7 -1
  9. package/dist/lib/behavior/hide-outside.d.ts +1 -1
  10. package/dist/lib/behavior/layer-stack.d.ts +3 -2
  11. package/dist/lib/behavior/menu.d.ts +59 -0
  12. package/dist/lib/behavior/modal-root.d.ts +2 -0
  13. package/dist/lib/behavior/range.d.ts +44 -0
  14. package/dist/lib/color/color.d.ts +41 -0
  15. package/dist/lib/color/index.d.ts +2 -0
  16. package/dist/lib/color/intl.d.ts +40 -0
  17. package/dist/lib/dock-slot-classes.d.ts +2 -0
  18. package/dist/lib/hold.d.ts +1 -1
  19. package/dist/lib/locale.d.ts +3 -0
  20. package/dist/lib/menu-classes.d.ts +2 -0
  21. package/dist/lib/motion-classes.d.ts +1 -1
  22. package/dist/lib/overlay-classes.d.ts +1 -0
  23. package/dist/lib/scroll-track.d.ts +3 -2
  24. package/dist/lib/section-tokens.d.ts +1 -1
  25. package/dist/lib/segment-classes.d.ts +2 -0
  26. package/dist/lib/shadow-layer.d.ts +0 -45
  27. package/dist/lib/toggle-set.d.ts +44 -0
  28. package/dist/lib/visually-hidden.d.ts +3 -0
  29. package/dist/solid/accordion.d.ts +35 -11
  30. package/dist/solid/avatar.d.ts +8 -4
  31. package/dist/solid/bottom-sheet/bottom-sheet.d.ts +1 -1
  32. package/dist/solid/button.d.ts +5 -4
  33. package/dist/solid/charts.d.ts +1 -1
  34. package/dist/solid/checkbox.d.ts +14 -4
  35. package/dist/solid/collapsible.d.ts +33 -5
  36. package/dist/solid/color-disc.d.ts +1 -1
  37. package/dist/solid/color-slider.d.ts +1 -1
  38. package/dist/solid/color-wheel.d.ts +1 -1
  39. package/dist/solid/context-menu.d.ts +58 -24
  40. package/dist/solid/dialog-parts.d.ts +8 -8
  41. package/dist/solid/dropdown-menu.d.ts +55 -24
  42. package/dist/solid/empty.d.ts +1 -1
  43. package/dist/solid/form.d.ts +5 -6
  44. package/dist/solid/hover-card.d.ts +65 -9
  45. package/dist/solid/index.d.ts +1 -1
  46. package/dist/solid/index.js +7725 -13458
  47. package/dist/solid/input-group.d.ts +6 -6
  48. package/dist/solid/item.d.ts +1 -1
  49. package/dist/solid/menu-parts.d.ts +175 -24
  50. package/dist/solid/option-card.d.ts +1 -4
  51. package/dist/solid/picker-row.d.ts +2 -0
  52. package/dist/solid/popover.d.ts +77 -12
  53. package/dist/solid/progress.d.ts +11 -3
  54. package/dist/solid/radio-group.d.ts +31 -6
  55. package/dist/solid/responsive-dialog.d.ts +1 -1
  56. package/dist/solid/scroll-area.d.ts +1 -1
  57. package/dist/solid/section-card.d.ts +2 -3
  58. package/dist/solid/select.d.ts +107 -10
  59. package/dist/solid/selection.d.ts +10 -1
  60. package/dist/solid/sheet.d.ts +1 -1
  61. package/dist/solid/sliding-indicator.d.ts +1 -1
  62. package/dist/solid/sonner.d.ts +1 -1
  63. package/dist/solid/toggle.d.ts +11 -3
  64. package/dist/solid/tooltip.d.ts +22 -22
  65. package/dist/tokens/index.js +54 -51
  66. package/dist/{utils-CxAii-e9.js → utils-3Codx-NZ.js} +527 -489
  67. package/package.json +3 -6
  68. package/src/lib/anchor-placement.ts +10 -3
  69. package/src/lib/balance-rows.ts +115 -40
  70. package/src/lib/behavior/anchored.ts +26 -8
  71. package/src/lib/behavior/button-root.tsx +103 -0
  72. package/src/lib/behavior/collection.ts +66 -29
  73. package/src/lib/behavior/dismiss.ts +61 -21
  74. package/src/lib/behavior/focus-scope.ts +31 -6
  75. package/src/lib/behavior/hide-outside.ts +2 -2
  76. package/src/lib/behavior/layer-stack.ts +33 -8
  77. package/src/lib/behavior/menu.ts +470 -0
  78. package/src/lib/behavior/modal-root.tsx +24 -18
  79. package/src/lib/behavior/polymorphic.tsx +1 -1
  80. package/src/lib/behavior/presence.ts +1 -1
  81. package/src/lib/behavior/range.ts +212 -0
  82. package/src/lib/clipboard.ts +2 -3
  83. package/src/lib/color/color.ts +746 -0
  84. package/src/lib/color/index.ts +2 -0
  85. package/src/lib/color/intl.ts +60 -0
  86. package/src/lib/dock-slot-classes.ts +3 -0
  87. package/src/lib/hold.ts +1 -1
  88. package/src/lib/locale.ts +62 -0
  89. package/src/lib/menu-classes.ts +3 -0
  90. package/src/lib/motion-classes.ts +7 -7
  91. package/src/lib/overlay-classes.ts +1 -3
  92. package/src/lib/scroll-track.ts +11 -6
  93. package/src/lib/section-tokens.ts +1 -1
  94. package/src/lib/segment-classes.ts +3 -0
  95. package/src/lib/shadow-layer.ts +0 -118
  96. package/src/lib/toggle-set.ts +133 -0
  97. package/src/lib/visually-hidden.ts +15 -0
  98. package/src/solid/accordion.tsx +294 -20
  99. package/src/solid/area-picker.tsx +3 -2
  100. package/src/solid/avatar.tsx +98 -24
  101. package/src/solid/bottom-sheet/bottom-sheet.tsx +1 -1
  102. package/src/solid/button.tsx +12 -6
  103. package/src/solid/charts.tsx +1 -1
  104. package/src/solid/checkbox.tsx +167 -44
  105. package/src/solid/collapsible.tsx +260 -12
  106. package/src/solid/color-disc.tsx +11 -12
  107. package/src/solid/color-slider.tsx +114 -47
  108. package/src/solid/color-wheel.tsx +137 -39
  109. package/src/solid/context-menu.tsx +285 -94
  110. package/src/solid/dialog-parts.tsx +9 -9
  111. package/src/solid/dock.tsx +3 -2
  112. package/src/solid/dropdown-menu.tsx +252 -115
  113. package/src/solid/empty.tsx +1 -1
  114. package/src/solid/entity-selector.tsx +3 -2
  115. package/src/solid/face-toggle.tsx +43 -18
  116. package/src/solid/form.tsx +5 -6
  117. package/src/solid/glyph-tile.tsx +48 -21
  118. package/src/solid/hover-card.tsx +287 -25
  119. package/src/solid/image-picker.tsx +2 -2
  120. package/src/solid/index.ts +1 -3
  121. package/src/solid/input-group.tsx +2 -2
  122. package/src/solid/item.tsx +1 -1
  123. package/src/solid/menu-parts.tsx +619 -145
  124. package/src/solid/option-card.tsx +6 -10
  125. package/src/solid/picker-row.tsx +5 -1
  126. package/src/solid/popover.tsx +424 -79
  127. package/src/solid/preview-tile.tsx +1 -1
  128. package/src/solid/progress.tsx +84 -15
  129. package/src/solid/radio-group.tsx +271 -34
  130. package/src/solid/responsive-dialog.tsx +1 -1
  131. package/src/solid/schema-form.tsx +1 -6
  132. package/src/solid/scroll-area.tsx +1 -1
  133. package/src/solid/section-card.tsx +3 -4
  134. package/src/solid/select.tsx +950 -95
  135. package/src/solid/selection.tsx +142 -66
  136. package/src/solid/sheet.tsx +1 -1
  137. package/src/solid/slider.tsx +115 -65
  138. package/src/solid/sliding-indicator.tsx +1 -1
  139. package/src/solid/sonner.tsx +1 -1
  140. package/src/solid/tabs.tsx +12 -6
  141. package/src/solid/term.tsx +3 -4
  142. package/src/solid/toggle-group.tsx +29 -99
  143. package/src/solid/toggle.tsx +43 -9
  144. package/src/solid/tooltip.tsx +24 -24
  145. package/src/styles/globals.css +61 -7
  146. package/src/styles/theme.css +7 -4
  147. package/src/tokens/material.ts +11 -2
@@ -1,14 +1,292 @@
1
- import { Accordion as AccordionPrimitive } from "@kobalte/core/accordion";
2
- import { type Component, type ComponentProps, type ParentComponent, splitProps } from "solid-js";
1
+ import {
2
+ type Accessor,
3
+ type Component,
4
+ type ComponentProps,
5
+ createContext,
6
+ createSignal,
7
+ createUniqueId,
8
+ type JSX,
9
+ type ParentComponent,
10
+ splitProps,
11
+ useContext,
12
+ type ValidComponent,
13
+ } from "solid-js";
14
+ import { type Collection, createCollection } from "../lib/behavior/collection.js";
15
+ import { createControllableSignal } from "../lib/behavior/controllable.js";
16
+ import { focusWithoutTracking, trackFocus } from "../lib/behavior/focus-scope.js";
17
+ import { Polymorphic } from "../lib/behavior/polymorphic.js";
18
+ import { callEventHandler, effect, merge } from "../lib/behavior/solid.js";
3
19
  import { cn } from "../lib/utils.js";
20
+ import {
21
+ CollapsibleContentRoot,
22
+ CollapsibleRoot,
23
+ CollapsibleTriggerRoot,
24
+ useCollapsible,
25
+ } from "./collapsible.js";
4
26
  import { Icon } from "./icon.js";
5
27
 
6
- const Accordion = AccordionPrimitive;
28
+ type AccordionProps = Omit<ComponentProps<"div">, "onChange"> & {
29
+ as?: ValidComponent;
30
+ value?: string[];
31
+ defaultValue?: string[];
32
+ onChange?: (value: string[]) => void;
33
+ multiple?: boolean;
34
+ collapsible?: boolean;
35
+ shouldFocusWrap?: boolean;
36
+ };
37
+
38
+ type AccordionItemProps = Omit<ComponentProps<"div">, "onChange"> & {
39
+ as?: ValidComponent;
40
+ value: string;
41
+ disabled?: boolean;
42
+ forceMount?: boolean;
43
+ };
44
+
45
+ type AccordionHeaderProps = ComponentProps<"h3"> & { as?: ValidComponent };
46
+ type AccordionTriggerProps = ComponentProps<"button"> & { as?: ValidComponent };
47
+ type AccordionContentProps = ComponentProps<"div"> & { as?: ValidComponent };
48
+
49
+ interface AccordionContextValue {
50
+ rootId: Accessor<string>;
51
+ isOpen: (value: string) => boolean;
52
+ toggle: (value: string) => void;
53
+ collection: Collection;
54
+ }
55
+
56
+ interface AccordionItemContextValue {
57
+ value: Accessor<string>;
58
+ itemId: Accessor<string>;
59
+ triggerId: Accessor<string | undefined>;
60
+ setTriggerId: (id: string | undefined) => void;
61
+ }
62
+
63
+ const AccordionContext = createContext<AccordionContextValue>();
64
+ const AccordionItemContext = createContext<AccordionItemContextValue>();
65
+
66
+ function useAccordion(): AccordionContextValue {
67
+ const ctx = useContext(AccordionContext);
68
+ if (!ctx) throw new Error("An accordion part renders inside an Accordion");
69
+ return ctx;
70
+ }
71
+
72
+ function useAccordionItem(): AccordionItemContextValue {
73
+ const ctx = useContext(AccordionItemContext);
74
+ if (!ctx) throw new Error("An accordion part renders inside an AccordionItem");
75
+ return ctx;
76
+ }
77
+
78
+ const NAVIGATION_KEYS = new Set(["ArrowDown", "ArrowUp", "Home", "End"]);
79
+
80
+ const AccordionRoot: Component<AccordionProps> = (props) => {
81
+ const fallbackId = `accordion-${createUniqueId()}`;
82
+ const [local, others] = splitProps(props, [
83
+ "as",
84
+ "ref",
85
+ "value",
86
+ "defaultValue",
87
+ "onChange",
88
+ "multiple",
89
+ "collapsible",
90
+ "shouldFocusWrap",
91
+ ]);
92
+ const [value, setValue] = createControllableSignal<string[]>({
93
+ value: () => local.value,
94
+ defaultValue: () => local.defaultValue ?? [],
95
+ onChange: (next) => local.onChange?.(next),
96
+ });
97
+ const mayEmpty = () => !!local.multiple || !!local.collapsible;
98
+ const [el, setEl] = createSignal<HTMLElement>();
99
+ const collection = createCollection({
100
+ root: el,
101
+ itemSelector: "[data-key]",
102
+ orientation: () => "vertical",
103
+ focus: "roving",
104
+ loop: () => local.shouldFocusWrap ?? true,
105
+ });
106
+
107
+ const toggle = (item: string) => {
108
+ const current = value();
109
+ if (current.includes(item)) {
110
+ if (local.multiple) setValue(current.filter((v) => v !== item));
111
+ else if (local.collapsible) setValue([]);
112
+ } else setValue(local.multiple ? [...current, item] : [item]);
113
+ };
114
+
115
+ effect(el, (node) => {
116
+ if (!node) return;
117
+ const keydown = (event: KeyboardEvent) => {
118
+ const onTrigger = event.target instanceof HTMLElement && event.target.matches("[data-key]");
119
+ if (onTrigger && NAVIGATION_KEYS.has(event.key)) return collection.onKeyDown(event);
120
+ if (event.key !== "Escape" || event.defaultPrevented || !mayEmpty()) return;
121
+ if (value().length === 0) return;
122
+ event.preventDefault();
123
+ setValue([]);
124
+ };
125
+ node.addEventListener("keydown", keydown);
126
+ return () => node.removeEventListener("keydown", keydown);
127
+ });
128
+
129
+ const ctx: AccordionContextValue = {
130
+ rootId: () => others.id ?? fallbackId,
131
+ isOpen: (item) => value().includes(item),
132
+ toggle,
133
+ collection,
134
+ };
135
+
136
+ return (
137
+ <AccordionContext.Provider value={ctx}>
138
+ <Polymorphic
139
+ {...merge({ id: fallbackId }, others, {
140
+ as: local.as,
141
+ defaultAs: "div" as ValidComponent,
142
+ ref: (node: HTMLElement) => {
143
+ setEl(node);
144
+ if (typeof local.ref === "function") local.ref(node as HTMLDivElement);
145
+ },
146
+ })}
147
+ />
148
+ </AccordionContext.Provider>
149
+ );
150
+ };
151
+
152
+ const AccordionItemRoot: Component<AccordionItemProps> = (props) => {
153
+ const accordion = useAccordion();
154
+ const fallbackId = `${accordion.rootId()}-item-${createUniqueId()}`;
155
+ const [local, others] = splitProps(props, ["value", "disabled"]);
156
+ const [triggerId, setTriggerId] = createSignal<string>();
157
+ const itemId = () => others.id ?? fallbackId;
158
+
159
+ return (
160
+ <AccordionItemContext.Provider
161
+ value={{ value: () => local.value, itemId, triggerId, setTriggerId }}
162
+ >
163
+ <CollapsibleRoot
164
+ {...merge({ id: fallbackId }, others, {
165
+ get open() {
166
+ return accordion.isOpen(local.value);
167
+ },
168
+ onOpenChange: () => accordion.toggle(local.value),
169
+ get disabled() {
170
+ return local.disabled;
171
+ },
172
+ })}
173
+ />
174
+ </AccordionItemContext.Provider>
175
+ );
176
+ };
177
+
178
+ const AccordionHeader: Component<AccordionHeaderProps> = (props) => {
179
+ const collapsible = useCollapsible();
180
+ const [local, others] = splitProps(props, ["as"]);
181
+ return (
182
+ <Polymorphic
183
+ {...merge(collapsible.markers, others, { as: local.as, defaultAs: "h3" as ValidComponent })}
184
+ />
185
+ );
186
+ };
187
+
188
+ const AccordionTriggerRoot: Component<AccordionTriggerProps> = (props) => {
189
+ const accordion = useAccordion();
190
+ const item = useAccordionItem();
191
+ const collapsible = useCollapsible();
192
+ const [local, others] = splitProps(props, ["ref", "onClick"]);
193
+ const [el, setEl] = createSignal<HTMLElement>();
194
+ const id = () => others.id ?? `${item.itemId()}-trigger`;
195
+ effect(id, (value) => {
196
+ item.setTriggerId(value);
197
+ return () => item.setTriggerId(undefined);
198
+ });
199
+
200
+ let focused: ReturnType<typeof trackFocus> | undefined;
201
+ effect(el, (node) => {
202
+ if (!node) return;
203
+ const tracked = trackFocus(node);
204
+ focused = tracked;
205
+ const focus = () => accordion.collection.highlight(item.value(), "pointer");
206
+ node.addEventListener("focus", focus);
207
+ return () => {
208
+ tracked.stop();
209
+ node.removeEventListener("focus", focus);
210
+ };
211
+ });
212
+
213
+ const click: JSX.EventHandler<HTMLButtonElement, MouseEvent> = (event) => {
214
+ callEventHandler(event, local.onClick);
215
+ // WebKit leaves a clicked button unfocused, and the arrows move from the focused trigger.
216
+ const node = el();
217
+ if (node && !collapsible.disabled() && !focused?.has()) focusWithoutTracking(node);
218
+ };
219
+
220
+ return (
221
+ <CollapsibleTriggerRoot
222
+ {...merge(
223
+ {
224
+ get "data-key"() {
225
+ return item.value();
226
+ },
227
+ },
228
+ others,
229
+ {
230
+ get id() {
231
+ return id();
232
+ },
233
+ onClick: click,
234
+ ref: (node: HTMLButtonElement) => {
235
+ setEl(node);
236
+ if (typeof local.ref === "function") local.ref(node);
237
+ },
238
+ },
239
+ )}
240
+ />
241
+ );
242
+ };
243
+
244
+ const CONTENT_VARS = {
245
+ "--accordion-content-height": "var(--collapsible-content-height)",
246
+ "--accordion-content-width": "var(--collapsible-content-width)",
247
+ "--kb-accordion-content-height": "var(--kb-collapsible-content-height)",
248
+ "--kb-accordion-content-width": "var(--kb-collapsible-content-width)",
249
+ };
250
+
251
+ const CONTENT_VARS_CSS = Object.entries(CONTENT_VARS)
252
+ .map(([name, value]) => `${name}:${value};`)
253
+ .join("");
254
+
255
+ const AccordionContentRoot: Component<AccordionContentProps> = (props) => {
256
+ const item = useAccordionItem();
257
+ const [local, others] = splitProps(props, ["style"]);
258
+ return (
259
+ <CollapsibleContentRoot
260
+ {...merge(
261
+ {
262
+ role: "region" as const,
263
+ get "aria-labelledby"() {
264
+ return item.triggerId();
265
+ },
266
+ get style() {
267
+ return typeof local.style === "string"
268
+ ? `${CONTENT_VARS_CSS}${local.style}`
269
+ : { ...CONTENT_VARS, ...local.style };
270
+ },
271
+ },
272
+ others,
273
+ )}
274
+ />
275
+ );
276
+ };
277
+
278
+ const Accordion = Object.assign(AccordionRoot, {
279
+ Root: AccordionRoot,
280
+ Item: AccordionItemRoot,
281
+ Header: AccordionHeader,
282
+ Trigger: AccordionTriggerRoot,
283
+ Content: AccordionContentRoot,
284
+ });
7
285
 
8
- const AccordionItem: Component<ComponentProps<typeof AccordionPrimitive.Item>> = (props) => {
286
+ const AccordionItem: Component<AccordionItemProps> = (props) => {
9
287
  const [local, rest] = splitProps(props, ["class"]);
10
288
  return (
11
- <AccordionPrimitive.Item
289
+ <AccordionItemRoot
12
290
  data-slot="accordion-item"
13
291
  class={cn("border-b last:border-b-0", local.class)}
14
292
  {...rest}
@@ -16,16 +294,14 @@ const AccordionItem: Component<ComponentProps<typeof AccordionPrimitive.Item>> =
16
294
  );
17
295
  };
18
296
 
19
- const AccordionTrigger: ParentComponent<ComponentProps<typeof AccordionPrimitive.Trigger>> = (
20
- props,
21
- ) => {
297
+ const AccordionTrigger: ParentComponent<AccordionTriggerProps> = (props) => {
22
298
  const [local, rest] = splitProps(props, ["class", "children"]);
23
299
  return (
24
- <AccordionPrimitive.Header class="flex">
25
- <AccordionPrimitive.Trigger
300
+ <AccordionHeader class="flex">
301
+ <AccordionTriggerRoot
26
302
  data-slot="accordion-trigger"
27
303
  class={cn(
28
- "focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-expanded]>[data-slot=icon]]:rotate-180",
304
+ "focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all duration-(--duration-state) outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-expanded]>[data-slot=icon]]:rotate-180",
29
305
  local.class,
30
306
  )}
31
307
  {...rest}
@@ -35,25 +311,23 @@ const AccordionTrigger: ParentComponent<ComponentProps<typeof AccordionPrimitive
35
311
  icon="lucide:chevron-down"
36
312
  width={16}
37
313
  height={16}
38
- class="text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200"
314
+ class="text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-(--duration-expand)"
39
315
  />
40
- </AccordionPrimitive.Trigger>
41
- </AccordionPrimitive.Header>
316
+ </AccordionTriggerRoot>
317
+ </AccordionHeader>
42
318
  );
43
319
  };
44
320
 
45
- const AccordionContent: ParentComponent<ComponentProps<typeof AccordionPrimitive.Content>> = (
46
- props,
47
- ) => {
321
+ const AccordionContent: ParentComponent<AccordionContentProps> = (props) => {
48
322
  const [local, rest] = splitProps(props, ["class", "children"]);
49
323
  return (
50
- <AccordionPrimitive.Content
324
+ <AccordionContentRoot
51
325
  data-slot="accordion-content"
52
- class="data-[closed]:animate-accordion-up data-[expanded]:animate-accordion-down overflow-hidden text-sm"
326
+ class="data-[closed]:animate-accordion-up data-[expanded]:animate-accordion-down overflow-hidden text-sm duration-(--duration-expand)"
53
327
  {...rest}
54
328
  >
55
329
  <div class={cn("pt-0 pb-4", local.class)}>{local.children}</div>
56
- </AccordionPrimitive.Content>
330
+ </AccordionContentRoot>
57
331
  );
58
332
  };
59
333
 
@@ -1,6 +1,6 @@
1
1
  import { createMemo, createSignal, For, Show } from "solid-js";
2
2
  import { focusWithoutTracking } from "../lib/behavior/focus-scope.js";
3
- import { MENU_ITEM } from "../lib/menu-classes.js";
3
+ import { MENU_ITEM, MENU_ITEM_RADIUS } from "../lib/menu-classes.js";
4
4
  import { STAGGER } from "../lib/motion-classes.js";
5
5
  import { PICKER_LIST } from "../lib/picker-classes.js";
6
6
  import { cn } from "../lib/utils.js";
@@ -192,6 +192,7 @@ export function AreaPicker(props: AreaPickerProps) {
192
192
  />
193
193
  <SelectionScope
194
194
  marker="highlighted"
195
+ radius={MENU_ITEM_RADIUS}
195
196
  class={cn("flex flex-col gap-0.5 p-1", STAGGER, PICKER_LIST)}
196
197
  onMouseLeave={() => setHovered(null)}
197
198
  >
@@ -215,7 +216,7 @@ export function AreaPicker(props: AreaPickerProps) {
215
216
  as="button"
216
217
  type="button"
217
218
  data-slot="area-picker-row"
218
- data-highlighted={highlightedId() === area.id || undefined}
219
+ highlighted={highlightedId() === area.id}
219
220
  aria-pressed={multi() ? isSelected(area.id) : undefined}
220
221
  icon={area.icon || "mdi:home-floor-1"}
221
222
  title={area.name}
@@ -1,40 +1,114 @@
1
- import { Image as ImagePrimitive } from "@kobalte/core/image";
2
- import { type Component, type ComponentProps, splitProps } from "solid-js";
1
+ import {
2
+ type Accessor,
3
+ type Component,
4
+ type ComponentProps,
5
+ createContext,
6
+ createSignal,
7
+ Show,
8
+ splitProps,
9
+ useContext,
10
+ } from "solid-js";
11
+ import { effect } from "../lib/behavior/solid.js";
3
12
  import { cn } from "../lib/utils.js";
4
13
 
5
- const Avatar: Component<ComponentProps<typeof ImagePrimitive>> = (props) => {
6
- const [local, rest] = splitProps(props, ["class"]);
14
+ type LoadingStatus = "idle" | "loading" | "loaded" | "error";
15
+
16
+ type AvatarProps = ComponentProps<"span"> & {
17
+ fallbackDelay?: number;
18
+ onLoadingStatusChange?: (status: LoadingStatus) => void;
19
+ };
20
+
21
+ interface AvatarContextValue {
22
+ fallbackDelay: Accessor<number | undefined>;
23
+ status: Accessor<LoadingStatus>;
24
+ report: (status: LoadingStatus) => void;
25
+ }
26
+
27
+ const AvatarContext = createContext<AvatarContextValue>();
28
+
29
+ function useAvatar(): AvatarContextValue {
30
+ const ctx = useContext(AvatarContext);
31
+ if (!ctx) throw new Error("An avatar part renders inside an Avatar");
32
+ return ctx;
33
+ }
34
+
35
+ const Avatar: Component<AvatarProps> = (props) => {
36
+ const [local, rest] = splitProps(props, ["class", "fallbackDelay", "onLoadingStatusChange"]);
37
+ const [status, setStatus] = createSignal<LoadingStatus>("idle");
38
+ const ctx: AvatarContextValue = {
39
+ fallbackDelay: () => local.fallbackDelay,
40
+ status,
41
+ report: (next) => {
42
+ setStatus(next);
43
+ local.onLoadingStatusChange?.(next);
44
+ },
45
+ };
7
46
  return (
8
- <ImagePrimitive
9
- data-slot="avatar"
10
- class={cn("relative flex size-10 shrink-0 overflow-hidden rounded-full", local.class)}
11
- {...rest}
12
- />
47
+ <AvatarContext.Provider value={ctx}>
48
+ <span
49
+ data-slot="avatar"
50
+ class={cn("relative flex size-10 shrink-0 overflow-hidden rounded-full", local.class)}
51
+ {...rest}
52
+ />
53
+ </AvatarContext.Provider>
13
54
  );
14
55
  };
15
56
 
16
- const AvatarImage: Component<ComponentProps<typeof ImagePrimitive.Img>> = (props) => {
57
+ const AvatarImage: Component<ComponentProps<"img">> = (props) => {
58
+ const ctx = useAvatar();
17
59
  const [local, rest] = splitProps(props, ["class"]);
60
+ const [status, setStatus] = createSignal<LoadingStatus>("idle");
61
+
62
+ // A detached probe, so the photo replaces the fallback only once it has decoded.
63
+ effect(
64
+ () => props.src,
65
+ (src) => {
66
+ if (!src) return void setStatus("error");
67
+ let live = true;
68
+ const probe = document.createElement("img");
69
+ const settle = (next: LoadingStatus) => () => live && setStatus(next);
70
+ setStatus("loading");
71
+ if (props.crossOrigin !== undefined) probe.crossOrigin = props.crossOrigin;
72
+ if (props.referrerPolicy !== undefined) probe.referrerPolicy = props.referrerPolicy;
73
+ probe.onload = settle("loaded");
74
+ probe.onerror = settle("error");
75
+ probe.src = src;
76
+ return () => {
77
+ live = false;
78
+ };
79
+ },
80
+ );
81
+ effect(status, (next) => {
82
+ if (next !== "idle") ctx.report(next);
83
+ });
84
+
18
85
  return (
19
- <ImagePrimitive.Img
20
- data-slot="avatar-image"
21
- class={cn("aspect-square size-full", local.class)}
22
- {...rest}
23
- />
86
+ <Show when={status() === "loaded"}>
87
+ <img data-slot="avatar-image" class={cn("aspect-square size-full", local.class)} {...rest} />
88
+ </Show>
24
89
  );
25
90
  };
26
91
 
27
- const AvatarFallback: Component<ComponentProps<typeof ImagePrimitive.Fallback>> = (props) => {
92
+ const AvatarFallback: Component<ComponentProps<"span">> = (props) => {
93
+ const ctx = useAvatar();
28
94
  const [local, rest] = splitProps(props, ["class"]);
95
+ const [due, setDue] = createSignal(ctx.fallbackDelay() === undefined);
96
+ effect(ctx.fallbackDelay, (delay) => {
97
+ if (delay === undefined) return;
98
+ const timer = setTimeout(() => setDue(true), delay);
99
+ return () => clearTimeout(timer);
100
+ });
29
101
  return (
30
- <ImagePrimitive.Fallback
31
- data-slot="avatar-fallback"
32
- class={cn(
33
- "glass flex size-full items-center justify-center rounded-full font-semibold [--glass-tone:var(--primary)]",
34
- local.class,
35
- )}
36
- {...rest}
37
- />
102
+ <Show when={due() && ctx.status() !== "loaded"}>
103
+ <span
104
+ data-slot="avatar-fallback"
105
+ class={cn(
106
+ "glass flex size-full items-center justify-center rounded-full font-semibold [--glass-tone:var(--primary)]",
107
+ local.class,
108
+ )}
109
+ {...rest}
110
+ />
111
+ </Show>
38
112
  );
39
113
  };
40
114
 
@@ -409,7 +409,7 @@ const BottomSheetClose: ParentComponent<SheetButtonProps> = (props) => {
409
409
  );
410
410
  };
411
411
 
412
- /** @deprecated the shared modal parts; `BottomSheetHeader` and `BottomSheetFooter` stay as aliases. */
412
+ /** @deprecated The shared modal parts; removed in 2.0.0. */
413
413
  export {
414
414
  BottomSheet,
415
415
  BottomSheetBody,
@@ -1,21 +1,27 @@
1
- import { Button as KobalteButton } from "@kobalte/core/button";
2
1
  import type { VariantProps } from "cva";
3
- import { type ComponentProps, type JSX, splitProps } from "solid-js";
2
+ import { type JSX, splitProps, type ValidComponent } from "solid-js";
3
+ import { ButtonRoot, type ButtonRootProps } from "../lib/behavior/button-root.js";
4
4
  import { busyProps } from "../lib/busy.js";
5
5
  import { buttonVariants } from "../lib/button-variants.js";
6
6
  import { cn } from "../lib/utils.js";
7
7
  import { Icon } from "./icon.js";
8
8
 
9
- type ButtonProps = ComponentProps<typeof KobalteButton> &
9
+ type ButtonProps<T extends ValidComponent = "button"> = ButtonRootProps<T> &
10
10
  VariantProps<typeof buttonVariants> & {
11
11
  /** Presses do nothing; unlike `disabled` it keeps focus, so the popover or dialog around it stays. */
12
12
  busy?: boolean;
13
+ class?: string;
13
14
  };
14
15
 
15
- function Button(props: ButtonProps) {
16
- const [local, others] = splitProps(props, ["class", "variant", "size", "busy"] as const);
16
+ function Button<T extends ValidComponent = "button">(props: ButtonProps<T>) {
17
+ const [local, others] = splitProps(props as ButtonProps<ValidComponent>, [
18
+ "class",
19
+ "variant",
20
+ "size",
21
+ "busy",
22
+ ]);
17
23
  return (
18
- <KobalteButton
24
+ <ButtonRoot
19
25
  data-slot="button"
20
26
  {...others}
21
27
  class={cn(buttonVariants({ variant: local.variant, size: local.size }), local.class)}
@@ -281,7 +281,7 @@ type StackedBarSegment = {
281
281
  value: number;
282
282
  /** CSS color driving the segment's own glass tint. */
283
283
  tone?: string;
284
- /** @deprecated pass `tone` instead */
284
+ /** @deprecated `tone`; removed in 2.0.0. */
285
285
  class?: string;
286
286
  };
287
287