@glasshome/ui 1.41.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 (188) hide show
  1. package/SPEC.md +5 -0
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +3 -3
  4. package/dist/lib/anchor-placement.d.ts +34 -0
  5. package/dist/lib/balance-rows.d.ts +10 -4
  6. package/dist/lib/behavior/anchored.d.ts +26 -0
  7. package/dist/lib/behavior/button-root.d.ts +7 -0
  8. package/dist/lib/behavior/collection.d.ts +32 -0
  9. package/dist/lib/behavior/controllable.d.ts +8 -0
  10. package/dist/lib/behavior/dismiss.d.ts +13 -0
  11. package/dist/lib/behavior/focus-scope.d.ts +24 -0
  12. package/dist/lib/behavior/hide-outside.d.ts +7 -0
  13. package/dist/lib/behavior/layer-stack.d.ts +34 -0
  14. package/dist/lib/behavior/menu.d.ts +59 -0
  15. package/dist/lib/behavior/modal-root.d.ts +68 -0
  16. package/dist/lib/behavior/polymorphic.d.ts +6 -0
  17. package/dist/lib/behavior/presence.d.ts +18 -0
  18. package/dist/lib/behavior/range.d.ts +44 -0
  19. package/dist/lib/behavior/solid.d.ts +13 -0
  20. package/dist/lib/color/color.d.ts +41 -0
  21. package/dist/lib/color/index.d.ts +2 -0
  22. package/dist/lib/color/intl.d.ts +40 -0
  23. package/dist/lib/dock-slot-classes.d.ts +2 -0
  24. package/dist/lib/hold.d.ts +1 -1
  25. package/dist/lib/locale.d.ts +3 -0
  26. package/dist/lib/menu-classes.d.ts +2 -0
  27. package/dist/lib/motion-classes.d.ts +5 -2
  28. package/dist/lib/overlay-classes.d.ts +4 -0
  29. package/dist/lib/page-cover.d.ts +8 -0
  30. package/dist/lib/scroll-track.d.ts +3 -2
  31. package/dist/lib/section-tokens.d.ts +1 -1
  32. package/dist/lib/segment-classes.d.ts +2 -0
  33. package/dist/lib/shadow-layer.d.ts +0 -43
  34. package/dist/lib/toggle-set.d.ts +44 -0
  35. package/dist/lib/visually-hidden.d.ts +3 -0
  36. package/dist/solid/accordion.d.ts +35 -11
  37. package/dist/solid/alert-dialog.d.ts +5 -8
  38. package/dist/solid/avatar.d.ts +8 -4
  39. package/dist/solid/bottom-sheet/bottom-sheet.d.ts +2 -2
  40. package/dist/solid/bottom-sheet/constants.d.ts +1 -1
  41. package/dist/solid/button.d.ts +5 -4
  42. package/dist/solid/charts.d.ts +1 -1
  43. package/dist/solid/checkbox.d.ts +14 -4
  44. package/dist/solid/collapsible.d.ts +33 -5
  45. package/dist/solid/color-disc.d.ts +1 -1
  46. package/dist/solid/color-slider.d.ts +1 -1
  47. package/dist/solid/color-wheel.d.ts +1 -1
  48. package/dist/solid/context-menu.d.ts +58 -24
  49. package/dist/solid/dialog-parts.d.ts +53 -16
  50. package/dist/solid/dialog.d.ts +7 -10
  51. package/dist/solid/dropdown-menu.d.ts +55 -24
  52. package/dist/solid/empty.d.ts +1 -1
  53. package/dist/solid/form.d.ts +5 -6
  54. package/dist/solid/hover-card.d.ts +65 -9
  55. package/dist/solid/index.d.ts +5 -2
  56. package/dist/solid/index.js +8671 -14317
  57. package/dist/solid/input-group.d.ts +6 -6
  58. package/dist/solid/item.d.ts +1 -1
  59. package/dist/solid/menu-parts.d.ts +175 -24
  60. package/dist/solid/option-card.d.ts +1 -4
  61. package/dist/solid/picker-row.d.ts +2 -0
  62. package/dist/solid/popover.d.ts +77 -12
  63. package/dist/solid/progress.d.ts +11 -3
  64. package/dist/solid/radio-group.d.ts +31 -6
  65. package/dist/solid/responsive-dialog.d.ts +3 -1
  66. package/dist/solid/scroll-area.d.ts +1 -1
  67. package/dist/solid/section-card.d.ts +2 -3
  68. package/dist/solid/select.d.ts +107 -10
  69. package/dist/solid/selection.d.ts +10 -1
  70. package/dist/solid/sheet.d.ts +6 -9
  71. package/dist/solid/sliding-indicator.d.ts +1 -1
  72. package/dist/solid/sonner.d.ts +1 -1
  73. package/dist/solid/stale-veil.d.ts +7 -0
  74. package/dist/solid/tabs.d.ts +28 -9
  75. package/dist/solid/toggle-group.d.ts +30 -5
  76. package/dist/solid/toggle.d.ts +11 -3
  77. package/dist/solid/tooltip.d.ts +71 -9
  78. package/dist/tokens/index.js +54 -51
  79. package/dist/{utils-CGN4X-2O.js → utils-3Codx-NZ.js} +848 -618
  80. package/package.json +6 -7
  81. package/src/index.ts +1 -0
  82. package/src/lib/anchor-placement.ts +77 -4
  83. package/src/lib/balance-rows.ts +115 -40
  84. package/src/lib/behavior/anchored.ts +106 -0
  85. package/src/lib/behavior/button-root.tsx +103 -0
  86. package/src/lib/behavior/collection.ts +218 -0
  87. package/src/lib/behavior/controllable.ts +22 -0
  88. package/src/lib/behavior/dismiss.ts +185 -0
  89. package/src/lib/behavior/focus-scope.ts +227 -0
  90. package/src/lib/behavior/hide-outside.ts +85 -0
  91. package/src/lib/behavior/layer-stack.ts +150 -0
  92. package/src/lib/behavior/menu.ts +470 -0
  93. package/src/lib/behavior/modal-root.tsx +452 -0
  94. package/src/lib/behavior/polymorphic.tsx +30 -0
  95. package/src/lib/behavior/presence.ts +89 -0
  96. package/src/lib/behavior/range.ts +212 -0
  97. package/src/lib/behavior/solid.ts +30 -0
  98. package/src/lib/clipboard.ts +4 -4
  99. package/src/lib/color/color.ts +746 -0
  100. package/src/lib/color/index.ts +2 -0
  101. package/src/lib/color/intl.ts +60 -0
  102. package/src/lib/dock-slot-classes.ts +3 -0
  103. package/src/lib/hold.ts +1 -1
  104. package/src/lib/locale.ts +62 -0
  105. package/src/lib/menu-classes.ts +3 -0
  106. package/src/lib/motion-classes.ts +33 -8
  107. package/src/lib/overlay-classes.ts +8 -3
  108. package/src/lib/page-cover.ts +47 -0
  109. package/src/lib/scroll-track.ts +11 -6
  110. package/src/lib/section-tokens.ts +1 -1
  111. package/src/lib/segment-classes.ts +3 -0
  112. package/src/lib/shadow-layer.ts +0 -136
  113. package/src/lib/toggle-set.ts +133 -0
  114. package/src/lib/visually-hidden.ts +15 -0
  115. package/src/solid/accordion.tsx +294 -20
  116. package/src/solid/alert-dialog.tsx +36 -85
  117. package/src/solid/area-picker.tsx +5 -3
  118. package/src/solid/avatar.tsx +98 -24
  119. package/src/solid/badge.tsx +5 -5
  120. package/src/solid/bottom-sheet/bottom-sheet.tsx +73 -129
  121. package/src/solid/bottom-sheet/constants.ts +3 -1
  122. package/src/solid/bottom-sheet/drag-controller.ts +11 -0
  123. package/src/solid/breadcrumb.tsx +4 -4
  124. package/src/solid/button-group.tsx +4 -4
  125. package/src/solid/button.tsx +12 -6
  126. package/src/solid/card.tsx +5 -4
  127. package/src/solid/charts.tsx +1 -1
  128. package/src/solid/checkbox.tsx +167 -44
  129. package/src/solid/collapsible.tsx +260 -12
  130. package/src/solid/color-disc.tsx +11 -12
  131. package/src/solid/color-slider.tsx +114 -47
  132. package/src/solid/color-wheel.tsx +137 -39
  133. package/src/solid/context-menu.tsx +287 -86
  134. package/src/solid/dialog-parts.tsx +135 -46
  135. package/src/solid/dialog.tsx +44 -76
  136. package/src/solid/dock-edit.tsx +5 -4
  137. package/src/solid/dock.tsx +6 -5
  138. package/src/solid/dropdown-menu.tsx +252 -107
  139. package/src/solid/empty.tsx +1 -1
  140. package/src/solid/entity-selector.tsx +5 -3
  141. package/src/solid/face-toggle.tsx +43 -18
  142. package/src/solid/form.tsx +9 -9
  143. package/src/solid/glyph-tile.tsx +48 -21
  144. package/src/solid/hover-card.tsx +288 -21
  145. package/src/solid/icon-picker.tsx +2 -1
  146. package/src/solid/image-picker.tsx +6 -5
  147. package/src/solid/index.ts +5 -4
  148. package/src/solid/input-group.tsx +7 -5
  149. package/src/solid/input-otp.tsx +2 -1
  150. package/src/solid/item.tsx +5 -5
  151. package/src/solid/logo.tsx +5 -4
  152. package/src/solid/menu-parts.tsx +619 -145
  153. package/src/solid/option-card.tsx +6 -10
  154. package/src/solid/picker-row.tsx +10 -5
  155. package/src/solid/picker-search.tsx +2 -1
  156. package/src/solid/popover.tsx +424 -71
  157. package/src/solid/preview-tile.tsx +1 -1
  158. package/src/solid/progress.tsx +84 -15
  159. package/src/solid/radio-group.tsx +271 -34
  160. package/src/solid/responsive-dialog.tsx +10 -10
  161. package/src/solid/schema-form.tsx +1 -6
  162. package/src/solid/scroll-area.tsx +1 -1
  163. package/src/solid/section-card.tsx +3 -4
  164. package/src/solid/select.tsx +950 -95
  165. package/src/solid/selection.tsx +142 -66
  166. package/src/solid/sheet.tsx +48 -80
  167. package/src/solid/slider.tsx +115 -65
  168. package/src/solid/sliding-indicator.tsx +1 -1
  169. package/src/solid/sonner.tsx +1 -1
  170. package/src/solid/spotlight.tsx +23 -11
  171. package/src/solid/stale-veil.tsx +20 -0
  172. package/src/solid/switch.tsx +8 -6
  173. package/src/solid/tabs.tsx +377 -52
  174. package/src/solid/term.tsx +3 -4
  175. package/src/solid/toggle-group.tsx +237 -95
  176. package/src/solid/toggle.tsx +43 -9
  177. package/src/solid/tooltip.tsx +285 -26
  178. package/src/styles/globals.css +64 -10
  179. package/src/styles/theme.css +12 -4
  180. package/src/tokens/material.ts +11 -2
  181. package/dist/lib/when-animations-settle.d.ts +0 -4
  182. package/dist/solid/bottom-sheet/focus-trap.d.ts +0 -6
  183. package/dist/solid/bottom-sheet/scroll-lock.d.ts +0 -2
  184. package/dist/solid/bottom-sheet/sheet-motion.d.ts +0 -1
  185. package/src/lib/when-animations-settle.ts +0 -12
  186. package/src/solid/bottom-sheet/focus-trap.ts +0 -63
  187. package/src/solid/bottom-sheet/scroll-lock.ts +0 -66
  188. package/src/solid/bottom-sheet/sheet-motion.ts +0 -4
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  import { type Component, type ComponentProps, splitProps, type ValidComponent } from "solid-js";
2
- import { Dynamic } from "solid-js/web";
2
+ import { Polymorphic } from "../lib/behavior/polymorphic.js";
3
3
  import { BADGE_DEFAULT_TONE, BADGE_NEUTRAL_KNOBS } from "../lib/badge-tone.js";
4
4
  import { isNeutralTone } from "../lib/glass-tone.js";
5
5
  import { CHIP } from "../lib/pill-classes.js";
@@ -15,18 +15,18 @@ type BadgeProps = ComponentProps<"span"> &
15
15
 
16
16
  const Badge: Component<BadgeProps> = (props) => {
17
17
  const [local, others] = splitProps(props, ["class", "as", "tone", "children", "style"]);
18
- const Comp = () => local.as || "span";
19
18
  const c = () => local.tone ?? BADGE_DEFAULT_TONE;
20
19
  return (
21
- <Dynamic
22
- component={Comp()}
20
+ <Polymorphic
21
+ defaultAs="span"
22
+ as={local.as}
23
23
  data-slot="badge"
24
24
  class={cn(CHIP, isNeutralTone(c()) && BADGE_NEUTRAL_KNOBS, local.class)}
25
25
  style={{ "--glass-tone": c(), ...(local.style as Record<string, string>) }}
26
26
  {...others}
27
27
  >
28
28
  {local.children}
29
- </Dynamic>
29
+ </Polymorphic>
30
30
  );
31
31
  };
32
32
 
@@ -14,15 +14,22 @@ import {
14
14
  useContext,
15
15
  type ValidComponent,
16
16
  } from "solid-js";
17
- import { Dynamic, Portal } from "solid-js/web";
17
+ import { Portal } from "solid-js/web";
18
+ import { Polymorphic } from "../../lib/behavior/polymorphic.js";
18
19
  import { usePortalMount } from "../portal-mount.js";
20
+ import { createControllableSignal } from "../../lib/behavior/controllable.js";
19
21
  import { Z } from "../../lib/layers.js";
20
- import { OVERLAY_SURFACE_OPAQUE } from "../../lib/overlay-classes.js";
22
+ import {
23
+ OVERLAY_SURFACE_OPAQUE,
24
+ SCRIM_CONTAIN,
25
+ SCROLL_CONTAIN,
26
+ } from "../../lib/overlay-classes.js";
27
+ import { coverNow } from "../../lib/page-cover.js";
28
+ import { callEventHandler, effect } from "../../lib/behavior/solid.js";
21
29
  import { cn } from "../../lib/utils.js";
22
- import { whenAnimationsSettle } from "../../lib/when-animations-settle.js";
23
- import { isSheetMotion } from "./sheet-motion.js";
30
+ import { type MotionEvent, watchMotion } from "../../lib/behavior/presence.js";
31
+ import { MOTION_EXIT_MS } from "../../lib/motion-classes.js";
24
32
  import {
25
- callEventHandler,
26
33
  createModalLabels,
27
34
  createModalParts,
28
35
  MODAL_DESCRIPTION,
@@ -33,9 +40,11 @@ import {
33
40
  } from "../dialog-parts.js";
34
41
  import { EASE, TRANSITION_MS } from "./constants.js";
35
42
  import { attachDrag } from "./drag-controller.js";
36
- import { type InitialFocus, trapFocus } from "./focus-trap.js";
43
+ import { createDismiss } from "../../lib/behavior/dismiss.js";
44
+ import { createFocusScope, type InitialFocus } from "../../lib/behavior/focus-scope.js";
45
+ import { createHideOutside } from "../../lib/behavior/hide-outside.js";
46
+ import { registerLayer } from "../../lib/behavior/layer-stack.js";
37
47
  import { watchKeyboard } from "./keyboard.js";
38
- import { acquireScrollLock, releaseScrollLock } from "./scroll-lock.js";
39
48
  import { assertTransition, type SheetState } from "./state-machine.js";
40
49
 
41
50
  interface BottomSheetContextValue {
@@ -48,6 +57,11 @@ interface BottomSheetContextValue {
48
57
  setContentRef: (el: HTMLDivElement | undefined) => void;
49
58
  }
50
59
 
60
+ const isSheetMotion = (e: MotionEvent) =>
61
+ "animationName" in e
62
+ ? e.animationName === "bs-slide-up" || e.animationName === "bs-slide-down"
63
+ : e.propertyName === "transform";
64
+
51
65
  const BottomSheetContext = createContext<BottomSheetContextValue>();
52
66
 
53
67
  function useBottomSheetContext(): BottomSheetContextValue {
@@ -65,18 +79,14 @@ interface BottomSheetRootProps {
65
79
  }
66
80
 
67
81
  const BottomSheet: ParentComponent<BottomSheetRootProps> = (props) => {
68
- const [uncontrolled, setUncontrolled] = createSignal(props.defaultOpen ?? false);
82
+ const [open, setOpen] = createControllableSignal<boolean>({
83
+ value: () => props.open,
84
+ defaultValue: () => props.defaultOpen ?? false,
85
+ onChange: (next) => props.onOpenChange?.(next),
86
+ });
69
87
  const [state, setStateRaw] = createSignal<SheetState>("closed");
70
88
  const [contentRef, setContentRef] = createSignal<HTMLDivElement | undefined>(undefined);
71
89
 
72
- const isControlled = () => props.open !== undefined;
73
- const open = (): boolean => (isControlled() ? props.open === true : uncontrolled());
74
-
75
- const setOpen = (next: boolean) => {
76
- if (!isControlled()) setUncontrolled(next);
77
- props.onOpenChange?.(next);
78
- };
79
-
80
90
  const setState = (next: SheetState) => {
81
91
  const current = state();
82
92
  assertTransition(current, next);
@@ -122,11 +132,10 @@ type SheetButtonProps = ComponentProps<"button"> &
122
132
  const BottomSheetTrigger: ParentComponent<SheetButtonProps> = (props) => {
123
133
  const [local, rest] = splitProps(props, ["children", "onClick", "as"]);
124
134
  const ctx = useBottomSheetContext();
125
- const component = () => local.as ?? "button";
126
135
  return (
127
- <Dynamic
128
- component={component()}
129
- type={component() === "button" ? "button" : undefined}
136
+ <Polymorphic
137
+ defaultAs="button"
138
+ as={local.as}
130
139
  data-slot="bottom-sheet-trigger"
131
140
  aria-haspopup="dialog"
132
141
  aria-expanded={ctx.open()}
@@ -137,7 +146,7 @@ const BottomSheetTrigger: ParentComponent<SheetButtonProps> = (props) => {
137
146
  {...rest}
138
147
  >
139
148
  {local.children}
140
- </Dynamic>
149
+ </Polymorphic>
141
150
  );
142
151
  };
143
152
 
@@ -175,7 +184,7 @@ const BottomSheetOverlay: Component<ComponentProps<"div">> = (props) => {
175
184
  data-state={dataState()}
176
185
  aria-hidden="true"
177
186
  class={cn(
178
- "fixed inset-0 bg-black/80 transition-opacity duration-300 ease-out",
187
+ `fixed inset-0 bg-black/80 transition-opacity duration-300 ease-out ${SCRIM_CONTAIN}`,
179
188
  "data-[state=closing]:opacity-0 data-[state=open]:opacity-100",
180
189
  local.class,
181
190
  )}
@@ -203,15 +212,9 @@ const BottomSheetContent: ParentComponent<BottomSheetContentProps> = (props) =>
203
212
  const labels = createModalLabels();
204
213
  let el: HTMLDivElement | undefined;
205
214
 
206
- /* Keyed on presence, not on mount: a sheet rendered without
207
- * BottomSheetPortal stays in the tree while closed and must not hold the
208
- * page lock. Release also runs on unmount, so no animation can strand it. */
209
215
  const present = createMemo(() => ctx.state() !== "closed");
210
- createEffect(() => {
211
- if (!present()) return;
212
- acquireScrollLock();
213
- onCleanup(releaseScrollLock);
214
- });
216
+
217
+ effect(present, (on) => (on && el ? coverNow(el) : undefined));
215
218
 
216
219
  const clearAnimInline = () => {
217
220
  if (!el) return;
@@ -225,16 +228,20 @@ const BottomSheetContent: ParentComponent<BottomSheetContentProps> = (props) =>
225
228
  if (s !== "opening" && s !== "closing" && s !== "snapping") return;
226
229
  const node = el;
227
230
  if (!node) return;
228
- let stale = false;
229
- onCleanup(() => (stale = true));
230
- void whenAnimationsSettle(node, { filter: isSheetMotion }).then(() => {
231
- if (stale) return;
232
- if (s === "opening") ctx.setState("open");
233
- else {
234
- ctx.setState(s === "snapping" ? "open" : "closed");
235
- clearAnimInline();
236
- }
237
- });
231
+ onCleanup(
232
+ watchMotion(
233
+ node,
234
+ MOTION_EXIT_MS.sheet,
235
+ () => {
236
+ if (s === "opening") ctx.setState("open");
237
+ else {
238
+ ctx.setState(s === "snapping" ? "open" : "closed");
239
+ clearAnimInline();
240
+ }
241
+ },
242
+ isSheetMotion,
243
+ ),
244
+ );
238
245
  });
239
246
 
240
247
  createEffect(() => {
@@ -257,92 +264,30 @@ const BottomSheetContent: ParentComponent<BottomSheetContentProps> = (props) =>
257
264
  onCleanup(() => handle.destroy());
258
265
  });
259
266
 
260
- createEffect(() => {
261
- const s = ctx.state();
262
- if (s !== "open" && s !== "opening") return;
263
- if (!el) return;
264
- const handle = trapFocus(el, local.initialFocus ?? "container");
265
- onCleanup(() => handle.release());
267
+ const handle = registerLayer({
268
+ element: ctx.contentRef,
269
+ open: ctx.open,
270
+ kind: "modal",
271
+ escape: ctx.dismissible,
272
+ dismiss: () => ctx.setOpen(false),
266
273
  });
267
274
 
268
- createEffect(() => {
269
- if (ctx.state() === "closed") return;
270
- const onKey = (e: KeyboardEvent) => {
271
- if (e.key !== "Escape") return;
272
- if (!ctx.dismissible()) return;
273
- e.preventDefault();
274
- ctx.setOpen(false);
275
- };
276
- document.addEventListener("keydown", onKey);
277
- onCleanup(() => document.removeEventListener("keydown", onKey));
275
+ createHideOutside({ layer: handle, active: ctx.open });
276
+
277
+ createFocusScope({
278
+ container: ctx.contentRef,
279
+ active: () => ctx.state() !== "closed" && ctx.state() !== "closing",
280
+ trapped: () => true,
281
+ initialFocus: local.initialFocus ?? "container",
278
282
  });
279
283
 
280
- // setTimeout(0) lets the click that opened the sheet finish bubbling
281
- // before the dismiss listener is attached. Touch defers to `click` so
282
- // drag/scroll intent can be detected first.
283
- createEffect(() => {
284
- if (ctx.state() === "closed") return;
285
- if (!ctx.dismissible()) return;
286
-
287
- let attached = false;
288
- let pendingClick: ((click: Event) => void) | null = null;
289
-
290
- const PORTAL_LAYER_SELECTOR =
291
- '[data-kb-top-layer], [role="dialog"], [role="menu"], [role="listbox"], [role="combobox"], [role="tooltip"]';
292
- // Judged along the composed path: a press inside an icon's own shadow root is still inside the
293
- // sheet. Only the part below the listening root counts: a realm's host inside a page dialog
294
- // must not make every press in the realm look like one inside a layer.
295
- const isOutside = (e: Event): boolean => {
296
- if (!el || !(e.target instanceof Element)) return false;
297
- const full = e.composedPath();
298
- const listener = e.currentTarget;
299
- const end = listener && listener !== document ? full.indexOf(listener) : -1;
300
- const path = end >= 0 ? full.slice(0, end) : full;
301
- if (path.includes(el)) return false;
302
- return !path.some(
303
- (node) =>
304
- node instanceof Element &&
305
- (node.matches("[data-sheet-content]") || node.matches(PORTAL_LAYER_SELECTOR)),
306
- );
307
- };
308
-
309
- // Inside a shadow root the page sees every press there as one on the root's host, so the
310
- // sheet judges those from its own root and only the page's other presses from the document.
311
- const scope = (el?.getRootNode() ?? document) as Document | ShadowRoot;
312
- const scopes: (Document | ShadowRoot)[] = scope === document ? [document] : [scope, document];
313
- const host = scope instanceof ShadowRoot ? scope.host : undefined;
314
- const onPointerDown = (e: Event) => {
315
- if (e.currentTarget === document && host && e.target === host) return;
316
- // Every press starts over: a touch that scrolled never clicked, and its close must not wait for the next tap.
317
- if (pendingClick) document.removeEventListener("click", pendingClick);
318
- pendingClick = null;
319
- if (!isOutside(e)) return;
320
- const dismiss = () => {
321
- if (ctx.state() === "open") ctx.setOpen(false);
322
- };
323
- if ((e as PointerEvent).pointerType === "touch") {
324
- pendingClick = (click: Event) => {
325
- pendingClick = null;
326
- // The click lands where the touch ended; it closes only if that is still outside.
327
- if (el && !click.composedPath().includes(el)) dismiss();
328
- };
329
- document.addEventListener("click", pendingClick, { once: true });
330
- } else {
331
- dismiss();
332
- }
333
- };
334
-
335
- const timer = window.setTimeout(() => {
336
- for (const s of scopes) s.addEventListener("pointerdown", onPointerDown, true);
337
- attached = true;
338
- }, 0);
339
-
340
- onCleanup(() => {
341
- window.clearTimeout(timer);
342
- if (attached)
343
- for (const s of scopes) s.removeEventListener("pointerdown", onPointerDown, true);
344
- if (pendingClick) document.removeEventListener("click", pendingClick);
345
- });
284
+ createDismiss({
285
+ layer: handle,
286
+ outsidePress: ctx.dismissible,
287
+ onDismiss: (reason) => {
288
+ if (reason === "outside-press" && ctx.state() !== "open") return;
289
+ ctx.setOpen(false);
290
+ },
346
291
  });
347
292
 
348
293
  const setRef = (node: HTMLDivElement) => {
@@ -383,7 +328,7 @@ const BottomSheetContent: ParentComponent<BottomSheetContentProps> = (props) =>
383
328
  }}
384
329
  class={cn(
385
330
  "bs-content",
386
- `fixed inset-x-0 bottom-0 flex ${MODAL_MAX_H} flex-col rounded-t-xl ${OVERLAY_SURFACE_OPAQUE} outline-none`,
331
+ `fixed inset-x-0 bottom-0 flex ${MODAL_MAX_H} flex-col ${SCROLL_CONTAIN} rounded-t-xl ${OVERLAY_SURFACE_OPAQUE} outline-none`,
387
332
  "after:absolute after:inset-x-0 after:top-full after:h-1/2 after:bg-inherit",
388
333
  local.class,
389
334
  )}
@@ -448,11 +393,10 @@ const BottomSheetDescription: Component<ComponentProps<"p">> = (props) => {
448
393
  const BottomSheetClose: ParentComponent<SheetButtonProps> = (props) => {
449
394
  const [local, rest] = splitProps(props, ["children", "onClick", "as"]);
450
395
  const ctx = useBottomSheetContext();
451
- const component = () => local.as ?? "button";
452
396
  return (
453
- <Dynamic
454
- component={component()}
455
- type={component() === "button" ? "button" : undefined}
397
+ <Polymorphic
398
+ defaultAs="button"
399
+ as={local.as}
456
400
  data-slot="bottom-sheet-close"
457
401
  onClick={(event: MouseEvent & { currentTarget: HTMLButtonElement; target: Element }) => {
458
402
  callEventHandler(event, local.onClick);
@@ -461,11 +405,11 @@ const BottomSheetClose: ParentComponent<SheetButtonProps> = (props) => {
461
405
  {...rest}
462
406
  >
463
407
  {local.children}
464
- </Dynamic>
408
+ </Polymorphic>
465
409
  );
466
410
  };
467
411
 
468
- /** @deprecated the shared modal parts; `BottomSheetHeader` and `BottomSheetFooter` stay as aliases. */
412
+ /** @deprecated The shared modal parts; removed in 2.0.0. */
469
413
  export {
470
414
  BottomSheet,
471
415
  BottomSheetBody,
@@ -1,5 +1,7 @@
1
+ import { MOTION_EXIT_MS } from "../../lib/motion-classes.js";
2
+
1
3
  export const EASE = "cubic-bezier(0.32, 0.72, 0, 1)";
2
- export const TRANSITION_MS = 500;
4
+ export const TRANSITION_MS = MOTION_EXIT_MS.sheet;
3
5
 
4
6
  export const DEAD_ZONE_PX = 6;
5
7
  export const CLOSE_DISTANCE_RATIO = 0.4;
@@ -43,6 +43,7 @@ export function attachDrag(opts: DragOptions): DragHandle {
43
43
  let dragAborted = false;
44
44
  let height = 0;
45
45
  let lastTotalDy = 0;
46
+ let shownDy = 0;
46
47
 
47
48
  const isDraggableState = (): boolean => {
48
49
  const s = getState();
@@ -55,6 +56,7 @@ export function attachDrag(opts: DragOptions): DragHandle {
55
56
  const value = pendingDy;
56
57
  pendingDy = null;
57
58
  const applied = value < 0 ? dampen(-value) * -1 : value;
59
+ shownDy = applied;
58
60
  el.style.transform = `translate3d(0, ${applied}px, 0)`;
59
61
  };
60
62
 
@@ -77,6 +79,7 @@ export function attachDrag(opts: DragOptions): DragHandle {
77
79
  startX = e.clientX;
78
80
  pointerTarget = target;
79
81
  dy = 0;
82
+ shownDy = 0;
80
83
  lastTotalDy = 0;
81
84
  movedPastDeadZone = false;
82
85
  dragAborted = false;
@@ -141,6 +144,14 @@ export function attachDrag(opts: DragOptions): DragHandle {
141
144
 
142
145
  const settleSnap = () => {
143
146
  setState("snapping");
147
+ if (shownDy === 0) {
148
+ el.style.transition = "";
149
+ el.style.animation = "";
150
+ el.style.transform = "";
151
+ setState("open");
152
+ return;
153
+ }
154
+ shownDy = 0;
144
155
  el.style.transition = TRANSITION_CSS;
145
156
  el.style.animation = "";
146
157
  el.style.transform = "translate3d(0, 0, 0)";
@@ -5,7 +5,7 @@ import {
5
5
  splitProps,
6
6
  type ValidComponent,
7
7
  } from "solid-js";
8
- import { Dynamic } from "solid-js/web";
8
+ import { Polymorphic } from "../lib/behavior/polymorphic.js";
9
9
  import { cn } from "../lib/utils.js";
10
10
  import { Icon } from "./icon.js";
11
11
 
@@ -40,10 +40,10 @@ const BreadcrumbItem: Component<ComponentProps<"li">> = (props) => {
40
40
 
41
41
  const BreadcrumbLink: Component<ComponentProps<"a"> & { as?: ValidComponent }> = (props) => {
42
42
  const [local, rest] = splitProps(props, ["class", "as"]);
43
- const Comp = () => local.as || "a";
44
43
  return (
45
- <Dynamic
46
- component={Comp()}
44
+ <Polymorphic
45
+ defaultAs="a"
46
+ as={local.as}
47
47
  data-slot="breadcrumb-link"
48
48
  class={cn("hover:text-foreground transition-colors", local.class)}
49
49
  {...rest}
@@ -1,6 +1,6 @@
1
1
  import { cva, type VariantProps } from "cva";
2
2
  import { type Component, type ComponentProps, splitProps, type ValidComponent } from "solid-js";
3
- import { Dynamic } from "solid-js/web";
3
+ import { Polymorphic } from "../lib/behavior/polymorphic.js";
4
4
  import { cn } from "../lib/utils.js";
5
5
  import { Separator } from "./separator.js";
6
6
 
@@ -35,10 +35,10 @@ const ButtonGroup: Component<ComponentProps<"div"> & VariantProps<typeof buttonG
35
35
 
36
36
  const ButtonGroupText: Component<ComponentProps<"div"> & { as?: ValidComponent }> = (props) => {
37
37
  const [local, rest] = splitProps(props, ["class", "as"] as const);
38
- const Comp = () => local.as || "div";
39
38
  return (
40
- <Dynamic
41
- component={Comp()}
39
+ <Polymorphic
40
+ defaultAs="div"
41
+ as={local.as}
42
42
  class={cn(
43
43
  "glass text-muted-foreground flex items-center gap-2 rounded-md px-4 text-sm font-medium [--glass-edge:var(--border)] [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
44
44
  local.class,
@@ -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)}
@@ -5,7 +5,7 @@ import {
5
5
  splitProps,
6
6
  type ValidComponent,
7
7
  } from "solid-js";
8
- import { Dynamic } from "solid-js/web";
8
+ import { Polymorphic } from "../lib/behavior/polymorphic.js";
9
9
  import {
10
10
  CARD_ACTION_CLASS,
11
11
  CARD_CONTENT_CLASS,
@@ -48,8 +48,9 @@ const Card: Component<CardProps> = (props) => {
48
48
  "children",
49
49
  ]);
50
50
  return (
51
- <Dynamic
52
- component={local.as ?? "div"}
51
+ <Polymorphic
52
+ defaultAs="div"
53
+ as={local.as}
53
54
  data-slot="card"
54
55
  class={cn(
55
56
  local.opaque ? CARD_SURFACE_OPAQUE : CARD_SURFACE,
@@ -63,7 +64,7 @@ const Card: Component<CardProps> = (props) => {
63
64
  >
64
65
  <Show when={local.ornament}>{(kind) => <Ornament kind={kind()} />}</Show>
65
66
  {local.children}
66
- </Dynamic>
67
+ </Polymorphic>
67
68
  );
68
69
  };
69
70
 
@@ -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