@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,4 +1,3 @@
1
- import { useRadioGroupContext } from "@kobalte/core/radio-group";
2
1
  import {
3
2
  children,
4
3
  createContext,
@@ -15,10 +14,10 @@ import { cn } from "../lib/utils.js";
15
14
  import { Icon } from "./icon.js";
16
15
  import { Ornament } from "./ornament.js";
17
16
  import { PickerRow } from "./picker-row.js";
18
- import { isItemActivation, RadioGroup, RadioGroupItem } from "./radio-group.js";
17
+ import { isItemActivation, RadioGroup, RadioGroupItem, useRadioGroup } from "./radio-group.js";
19
18
 
20
19
  /* Tone without .glass-tint: the card holds body copy, which must stay foreground-coloured. */
21
- const OPTION_CARD_CHROME = `${CARD_SURFACE} group/option-card relative cursor-pointer overflow-hidden rounded-xl transition-glass duration-200 [&:not([style*=--glass-tone])]:[--glass-tone:var(--primary)] [--glass-wash:9%] hover:[--glass-wash:16%] has-[:focus-visible]:[--glass-edge:var(--ring)] has-[:focus-visible]:ring-[3px] has-[:focus-visible]:ring-ring/50 data-[checked]:[--glass-wash:30%] data-[checked]:[--glass-edge:oklch(from_var(--glass-tone)_l_c_h/0.75)] data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50`;
20
+ const OPTION_CARD_CHROME = `${CARD_SURFACE} group/option-card relative cursor-pointer overflow-hidden rounded-xl transition-glass duration-(--duration-expand) [&:not([style*=--glass-tone])]:[--glass-tone:var(--primary)] [--glass-wash:9%] hover:[--glass-wash:16%] has-[:focus-visible]:[--glass-edge:var(--ring)] has-[:focus-visible]:ring-[3px] has-[:focus-visible]:ring-ring/50 data-[checked]:[--glass-wash:30%] data-[checked]:[--glass-edge:oklch(from_var(--glass-tone)_l_c_h/0.75)] data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50`;
22
21
 
23
22
  /* Sub-options live inside the card: the card grows (a grid row morphing
24
23
  * 0fr -> 1fr on the morph token) while it is picked, and the content settles
@@ -28,7 +27,7 @@ const OPTION_CARD_DRAWER =
28
27
  /* Flat: hover is a tint, the current row is the check plus full text colour.
29
28
  * The rows start under the title text (card pad + icon + gap, less the row's own pad). */
30
29
  const OPTION_CHOICE_ROW =
31
- "rounded-sm text-foreground/75 transition-colors hover:bg-foreground/5 aria-checked:text-foreground";
30
+ "rounded-sm text-foreground/75 transition-colors duration-(--duration-state) hover:bg-foreground/5 aria-checked:text-foreground";
32
31
 
33
32
  const OPTION_CARD_DRAWER_CONTENT =
34
33
  "-translate-y-2 flex flex-col gap-0.5 pr-1 pb-2 pl-[calc(var(--spacing)*3.5+54px)] opacity-0 transition-[opacity,translate] duration-(--duration-expand) ease-(--ease-morph) group-data-[checked]/option-card:translate-y-0 group-data-[checked]/option-card:opacity-100 group-data-[checked]/option-card:delay-[var(--stagger-base,80ms)]";
@@ -86,7 +85,7 @@ export function OptionCardGroup(props: {
86
85
  return (
87
86
  <RadioGroup
88
87
  class={cn("gap-2", props.class)}
89
- value={props.value ?? undefined}
88
+ value={props.value ?? ""}
90
89
  onChange={props.onChange}
91
90
  aria-label={props["aria-label"]}
92
91
  aria-labelledby={props["aria-labelledby"]}
@@ -120,7 +119,7 @@ export function OptionCard(props: {
120
119
  * reveal them while it is picked. */
121
120
  children?: JSX.Element;
122
121
  }) {
123
- const group = useRadioGroupContext();
122
+ const group = useRadioGroup();
124
123
  const checked = () => group.isSelectedValue(props.value);
125
124
  const [choices, setChoices] = createSignal<string[]>([]);
126
125
  const choice: ChoiceContext = {
@@ -215,8 +214,5 @@ function OptionIconWell(props: { icon?: string; image?: string }) {
215
214
  );
216
215
  }
217
216
 
218
- /**
219
- * @deprecated OptionCard carries the same props; HeroOption is an alias.
220
- * @alias
221
- */
217
+ /** @deprecated `OptionCard`; removed in 2.0.0. */
222
218
  export const HeroOption = OptionCard;
@@ -27,6 +27,8 @@ type PickerRowProps = Omit<ComponentProps<"button">, "title"> & {
27
27
  subtitle?: JSX.Element;
28
28
  meta?: JSX.Element;
29
29
  selected: boolean;
30
+ /** The row the keys point at; it carries `data-highlighted` and the selection glass. */
31
+ highlighted?: boolean;
30
32
  multi: boolean;
31
33
  dimmed?: boolean;
32
34
  };
@@ -39,6 +41,7 @@ export function PickerRow(props: PickerRowProps) {
39
41
  "subtitle",
40
42
  "meta",
41
43
  "selected",
44
+ "highlighted",
42
45
  "multi",
43
46
  "dimmed",
44
47
  "class",
@@ -56,9 +59,10 @@ export function PickerRow(props: PickerRowProps) {
56
59
  local.class,
57
60
  )}
58
61
  style={{ "min-height": `${PICKER_ROW_HEIGHT}px` }}
62
+ data-highlighted={local.highlighted ? "" : undefined}
59
63
  {...rest}
60
64
  >
61
- <SelectionHighlight />
65
+ <SelectionHighlight active={local.highlighted} />
62
66
  <Show when={local.icon}>
63
67
  {(icon) => (
64
68
  <div
@@ -1,30 +1,48 @@
1
- import { Popover as PopoverPrimitive, usePopoverContext } from "@kobalte/core/popover";
2
- import { usePortalMount } from "./portal-mount.js";
3
1
  import {
2
+ type Accessor,
4
3
  type Component,
5
4
  type ComponentProps,
6
5
  createContext,
7
6
  createSignal,
7
+ createUniqueId,
8
+ type JSX,
9
+ onCleanup,
10
+ Show,
8
11
  splitProps,
12
+ untrack,
9
13
  useContext,
14
+ type ValidComponent,
10
15
  } from "solid-js";
11
- import { INPUT_SURFACE } from "../lib/input-classes.js";
16
+ import { Portal } from "solid-js/web";
17
+ import { type Align, controlRadius, type Side } from "../lib/anchor-placement.js";
18
+ import { createAnchored } from "../lib/behavior/anchored.js";
19
+ import { createControllableSignal } from "../lib/behavior/controllable.js";
20
+ import { createDismiss } from "../lib/behavior/dismiss.js";
21
+ import { activeOf, createFocusScope, focusWithoutTracking } from "../lib/behavior/focus-scope.js";
22
+ import { createHideOutside } from "../lib/behavior/hide-outside.js";
23
+ import { registerLayer } from "../lib/behavior/layer-stack.js";
12
24
  import {
13
- createCoveredRoot,
14
- inShadowRoot,
15
- ReportCovered,
16
- shadowLayer,
17
- } from "../lib/shadow-layer.js";
25
+ type FocusOutsideEvent,
26
+ type InteractOutsideEvent,
27
+ interactOutside,
28
+ type PointerDownOutsideEvent,
29
+ vetoed,
30
+ } from "../lib/behavior/modal-root.js";
31
+ import { Polymorphic } from "../lib/behavior/polymorphic.js";
32
+ import { createPresence } from "../lib/behavior/presence.js";
33
+ import { effect, merge } from "../lib/behavior/solid.js";
34
+ import { INPUT_SURFACE } from "../lib/input-classes.js";
18
35
  import { nestedLayerAttrs, Z_CLASS } from "../lib/layers.js";
19
- import { FIELD_MOTION, MORPH_MOTION, STAGGER } from "../lib/motion-classes.js";
20
- import { anchorToTriggerTop, FLOATING_PANEL } from "../lib/overlay-classes.js";
36
+ import { FIELD_MOTION, MORPH_MOTION, MOTION_EXIT_MS, STAGGER } from "../lib/motion-classes.js";
37
+ import { FLOATING_PANEL } from "../lib/overlay-classes.js";
38
+ import { inShadowRoot } from "../lib/shadow-layer.js";
21
39
  import { cn } from "../lib/utils.js";
40
+ import { usePortalMount } from "./portal-mount.js";
22
41
 
23
42
  type PopoverSurface = "overlay" | "field";
43
+ type Placement = Side | `${Side}-${Exclude<Align, "center">}`;
24
44
 
25
- const PopoverSurfaceContext = createContext<() => PopoverSurface>(
26
- () => "overlay" as PopoverSurface,
27
- );
45
+ const ANCHOR_WIDTH = "--kb-popper-anchor-width";
28
46
 
29
47
  /* The expanding field panel: opaque (the trigger sits underneath it), bound to
30
48
  * the anchor width and radius, and padded by whatever part needs padding, never
@@ -33,117 +51,444 @@ const FIELD_PANEL = `${INPUT_SURFACE} ${FIELD_MOTION} relative ${Z_CLASS.overlay
33
51
 
34
52
  const OVERLAY_PANEL = `${FLOATING_PANEL} ${MORPH_MOTION} ${STAGGER} w-72 p-4`;
35
53
 
36
- type PopoverProps = ComponentProps<typeof PopoverPrimitive> & {
54
+ interface PopoverProps {
55
+ open?: boolean;
56
+ defaultOpen?: boolean;
57
+ onOpenChange?: (open: boolean) => void;
58
+ /** Hides the page from assistive technology and keeps Tab inside the panel. */
59
+ modal?: boolean;
37
60
  /** "field" anchors the panel over the trigger's top edge, so the field reads
38
61
  * as expanding into its panel instead of a box dropping in below it. */
39
62
  surface?: PopoverSurface;
63
+ placement?: Placement;
64
+ gutter?: number;
65
+ anchorRef?: Accessor<HTMLElement | undefined>;
66
+ children?: JSX.Element;
67
+ /** @deprecated Ignored; removed in 2.0.0. */
68
+ id?: string;
69
+ /** @deprecated Ignored; removed in 2.0.0. */
70
+ preventScroll?: boolean;
71
+ /** @deprecated Ignored; removed in 2.0.0. */
72
+ forceMount?: boolean;
73
+ /** @deprecated Ignored; removed in 2.0.0. */
74
+ translations?: unknown;
75
+ /** @deprecated Ignored; removed in 2.0.0. */
76
+ getAnchorRect?: (anchor?: HTMLElement) => unknown;
77
+ /** @deprecated Ignored; removed in 2.0.0. */
78
+ shift?: number;
79
+ /** @deprecated Ignored; removed in 2.0.0. */
80
+ flip?: boolean | string;
81
+ /** @deprecated Ignored; removed in 2.0.0. */
82
+ slide?: boolean;
83
+ /** @deprecated Ignored; removed in 2.0.0. */
84
+ overlap?: boolean;
85
+ /** @deprecated Ignored; removed in 2.0.0. */
86
+ sameWidth?: boolean;
87
+ /** @deprecated Ignored; removed in 2.0.0. */
88
+ fitViewport?: boolean;
89
+ /** @deprecated Ignored; removed in 2.0.0. */
90
+ hideWhenDetached?: boolean;
91
+ /** @deprecated Ignored; removed in 2.0.0. */
92
+ detachedPadding?: number;
93
+ /** @deprecated Ignored; removed in 2.0.0. */
94
+ arrowPadding?: number;
95
+ /** @deprecated Ignored; removed in 2.0.0. */
96
+ overflowPadding?: number;
97
+ }
98
+
99
+ interface PopoverContextValue {
100
+ isOpen: Accessor<boolean>;
101
+ setOpen: (open: boolean) => void;
102
+ modal: Accessor<boolean>;
103
+ surface: Accessor<PopoverSurface>;
104
+ side: Accessor<Side>;
105
+ align: Accessor<Align>;
106
+ gutter: Accessor<number>;
107
+ anchor: Accessor<HTMLElement | undefined>;
108
+ setAnchor: (el: HTMLElement | undefined) => void;
109
+ trigger: Accessor<HTMLElement | undefined>;
110
+ setTrigger: (el: HTMLElement | undefined) => void;
111
+ contentId: Accessor<string | undefined>;
112
+ setContentId: (id: string | undefined) => void;
113
+ titleId: Accessor<string | undefined>;
114
+ setTitleId: (id: string | undefined) => void;
115
+ descriptionId: Accessor<string | undefined>;
116
+ setDescriptionId: (id: string | undefined) => void;
117
+ }
118
+
119
+ const PopoverContext = createContext<PopoverContextValue | null>(null);
120
+
121
+ const usePopover = (): PopoverContextValue => {
122
+ const ctx = useContext(PopoverContext);
123
+ if (!ctx) throw new Error("Popover parts render inside a Popover");
124
+ return ctx;
40
125
  };
41
126
 
42
127
  const PopoverRoot: Component<PopoverProps> = (props) => {
43
- const [local, rest] = splitProps(props, ["surface", "gutter", "getAnchorRect"]);
44
- const surface = () => local.surface ?? "overlay";
45
- // Modal in a shadow root, Kobalte would aria-hide the realm's host, popover included.
46
- const inShadow = inShadowRoot(usePortalMount());
47
- const cover = createCoveredRoot();
128
+ const [isOpen, setOpen] = createControllableSignal<boolean>({
129
+ value: () => props.open,
130
+ defaultValue: () => props.defaultOpen ?? false,
131
+ onChange: (next) => props.onOpenChange?.(next),
132
+ });
133
+ const [anchor, setAnchor] = createSignal<HTMLElement>();
134
+ const [trigger, setTrigger] = createSignal<HTMLElement>();
135
+ const [contentId, setContentId] = createSignal<string>();
136
+ const [titleId, setTitleId] = createSignal<string>();
137
+ const [descriptionId, setDescriptionId] = createSignal<string>();
138
+ const placement = () => (props.placement ?? "bottom").split("-") as [Side, Align?];
139
+ const value: PopoverContextValue = {
140
+ isOpen,
141
+ setOpen,
142
+ modal: () => props.modal ?? false,
143
+ surface: () => props.surface ?? "overlay",
144
+ side: () => placement()[0],
145
+ align: () => placement()[1] ?? "center",
146
+ gutter: () => props.gutter ?? 0,
147
+ anchor: () => props.anchorRef?.() ?? anchor(),
148
+ setAnchor: (el) => setAnchor(el),
149
+ trigger,
150
+ setTrigger: (el) => setTrigger(el),
151
+ contentId,
152
+ setContentId,
153
+ titleId,
154
+ setTitleId,
155
+ descriptionId,
156
+ setDescriptionId,
157
+ };
158
+ return <PopoverContext.Provider value={value}>{props.children}</PopoverContext.Provider>;
159
+ };
160
+
161
+ type PartProps<T extends ValidComponent> = { as?: T } & Omit<ComponentProps<T>, "as">;
162
+
163
+ const expandedAttrs = (open: Accessor<boolean>) => ({
164
+ get "data-expanded"() {
165
+ return open() ? "" : undefined;
166
+ },
167
+ get "data-closed"() {
168
+ return open() ? undefined : "";
169
+ },
170
+ });
171
+
172
+ function PopoverTrigger<T extends ValidComponent = "button">(props: PartProps<T>): JSX.Element {
173
+ const ctx = usePopover();
174
+ const [local, rest] = splitProps(props as PartProps<ValidComponent>, ["as", "ref"]);
175
+ const [own, setOwn] = createSignal<HTMLElement>();
176
+ onCleanup(() => {
177
+ const el = untrack(own);
178
+ if (el && untrack(ctx.trigger) === el) ctx.setTrigger(undefined);
179
+ });
180
+ effect(own, (el) => {
181
+ if (!el) return;
182
+ // A press never focuses the trigger, so focus stays where the panel left it.
183
+ const down = (event: PointerEvent) => event.preventDefault();
184
+ const click = () => ctx.setOpen(!untrack(ctx.isOpen));
185
+ el.addEventListener("pointerdown", down);
186
+ el.addEventListener("click", click);
187
+ return () => {
188
+ el.removeEventListener("pointerdown", down);
189
+ el.removeEventListener("click", click);
190
+ };
191
+ });
48
192
  return (
49
- <PopoverSurfaceContext.Provider value={surface}>
50
- <ReportCovered.Provider value={cover.report}>
51
- <PopoverPrimitive
52
- gutter={local.gutter ?? 0}
53
- getAnchorRect={local.getAnchorRect ?? anchorToTriggerTop}
54
- flip={false}
55
- overlap
56
- {...rest}
57
- modal={inShadow || cover.covered() ? false : rest.modal}
58
- />
59
- </ReportCovered.Provider>
60
- </PopoverSurfaceContext.Provider>
193
+ <Polymorphic
194
+ {...merge({ "data-slot": "popover-trigger" }, rest, expandedAttrs(ctx.isOpen), {
195
+ as: local.as,
196
+ defaultAs: "button" as ValidComponent,
197
+ ref: (el: HTMLElement) => {
198
+ setOwn(el);
199
+ ctx.setTrigger(el);
200
+ if (typeof local.ref === "function") local.ref(el);
201
+ },
202
+ "aria-haspopup": "dialog",
203
+ get "aria-expanded"() {
204
+ return ctx.isOpen();
205
+ },
206
+ get "aria-controls"() {
207
+ return ctx.isOpen() ? ctx.contentId() : undefined;
208
+ },
209
+ })}
210
+ />
61
211
  );
62
- };
212
+ }
63
213
 
64
- /* Omit<T, never> keeps the statics and drops the call signature, so the
65
- * intersection has one call signature: ours, with `surface`. */
66
- type PopoverStatics = Omit<typeof PopoverPrimitive, never>;
214
+ /** Inside a PopoverAnchor: names the control that opens the popover, so focus goes back to it on close. */
215
+ const AnchorTriggerContext = createContext<((el: HTMLElement) => void) | null>(null);
67
216
 
68
- /* Kobalte hangs Anchor/Content/Portal/Title/Trigger/CloseButton/Arrow off the
69
- * root; carry them across so `Popover.Portal` keeps resolving for hosts that
70
- * reach past the wrapped parts. */
71
- const Popover = Object.assign(PopoverRoot, PopoverPrimitive) as Component<PopoverProps> &
72
- PopoverStatics;
217
+ function PopoverAnchor<T extends ValidComponent = "div">(props: PartProps<T>): JSX.Element {
218
+ const ctx = usePopover();
219
+ const [local, rest] = splitProps(props as PartProps<ValidComponent>, ["as", "ref"]);
220
+ onCleanup(() => ctx.setAnchor(undefined));
221
+ return (
222
+ <AnchorTriggerContext.Provider value={ctx.setTrigger}>
223
+ <Polymorphic
224
+ {...merge({ "data-slot": "popover-anchor" }, rest, expandedAttrs(ctx.isOpen), {
225
+ as: local.as,
226
+ defaultAs: "div" as ValidComponent,
227
+ ref: (el: HTMLElement) => {
228
+ ctx.setAnchor(el);
229
+ if (typeof local.ref === "function") local.ref(el);
230
+ },
231
+ })}
232
+ />
233
+ </AnchorTriggerContext.Provider>
234
+ );
235
+ }
73
236
 
74
- const PopoverTrigger: Component<ComponentProps<typeof PopoverPrimitive.Trigger>> = (props) => {
75
- return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />;
76
- };
237
+ /** The control, inside a PopoverAnchor, that opens its popover. */
238
+ const useAnchorTrigger = () => useContext(AnchorTriggerContext) ?? undefined;
77
239
 
78
- type PopoverContentProps = ComponentProps<typeof PopoverPrimitive.Content> & {
240
+ interface PopoverContentProps extends Omit<ComponentProps<"div">, "ref"> {
79
241
  surface?: PopoverSurface;
80
- };
242
+ ref?: HTMLElement | ((el: HTMLElement) => void);
243
+ onEscapeKeyDown?: (event: KeyboardEvent) => void;
244
+ onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;
245
+ onFocusOutside?: (event: FocusOutsideEvent) => void;
246
+ onInteractOutside?: (event: InteractOutsideEvent) => void;
247
+ onOpenAutoFocus?: (event: Event) => void;
248
+ onCloseAutoFocus?: (event: Event) => void;
249
+ /** @deprecated Ignored; removed in 2.0.0. */
250
+ forceMount?: boolean;
251
+ }
252
+
253
+ function focusLostFrom(panel: HTMLElement): boolean {
254
+ const page = document.activeElement;
255
+ if (!page || page === document.body) return true;
256
+ const active = activeOf(panel);
257
+ return active !== null && panel.contains(active);
258
+ }
81
259
 
82
260
  const PopoverContent: Component<PopoverContentProps> = (props) => {
261
+ const ctx = usePopover();
83
262
  const [local, rest] = splitProps(props, [
84
263
  "class",
85
264
  "surface",
86
265
  "ref",
266
+ "id",
267
+ "forceMount",
268
+ "onEscapeKeyDown",
269
+ "onPointerDownOutside",
270
+ "onFocusOutside",
87
271
  "onInteractOutside",
272
+ "onOpenAutoFocus",
88
273
  "onCloseAutoFocus",
89
274
  ]);
90
- const fromRoot = useContext(PopoverSurfaceContext);
91
- const surface = () => local.surface ?? fromRoot();
92
- const popover = usePopoverContext();
275
+ const surface = () => local.surface ?? ctx.surface();
276
+ const fallbackId = createUniqueId();
277
+ const id = () => local.id ?? fallbackId;
278
+ effect(id, (next) => {
279
+ ctx.setContentId(next);
280
+ return () => ctx.setContentId(undefined);
281
+ });
282
+
283
+ const mount = usePortalMount();
284
+ // In a shadow root, hiding the page outside the panel would hide the realm's host, panel included.
285
+ const modal = () => ctx.modal() && !inShadowRoot(mount);
93
286
  const [panel, setPanel] = createSignal<HTMLElement>();
94
- const layer = shadowLayer({
95
- content: panel,
96
- open: () => popover.isOpen(),
97
- dismiss: () => popover.close(),
98
- trigger: () => popover.triggerRef(),
99
- consumer: local,
287
+ const presence = createPresence({
288
+ present: ctx.isOpen,
289
+ element: panel,
290
+ get exitMs() {
291
+ return surface() === "field" ? MOTION_EXIT_MS.field : MOTION_EXIT_MS.anchored;
292
+ },
293
+ });
294
+
295
+ const handle = registerLayer({
296
+ element: panel,
297
+ open: ctx.isOpen,
298
+ kind: "popover",
299
+ escape: () => true,
300
+ dismiss: () => ctx.setOpen(false),
301
+ trigger: ctx.trigger,
302
+ blockPointer: modal,
100
303
  });
304
+ const covered = () => ctx.isOpen() && handle.above().some((layer) => layer.kind === "modal");
305
+
306
+ let closedOutside = false;
307
+ createDismiss({
308
+ layer: handle,
309
+ escapeFrom: "document",
310
+ focusOutside: () => !modal(),
311
+ onDismiss: (reason, original) => {
312
+ if (reason === "escape") {
313
+ if (vetoed(local.onEscapeKeyDown, original as KeyboardEvent)) return;
314
+ } else {
315
+ closedOutside = true;
316
+ const event = interactOutside(original as PointerEvent | FocusEvent, (e) => {
317
+ if (reason === "outside-press")
318
+ local.onPointerDownOutside?.(e as PointerDownOutsideEvent);
319
+ else local.onFocusOutside?.(e as FocusOutsideEvent);
320
+ local.onInteractOutside?.(e);
321
+ });
322
+ if (event.defaultPrevented) {
323
+ closedOutside = false;
324
+ return;
325
+ }
326
+ }
327
+ ctx.setOpen(false);
328
+ // A controlled `open` refused the close.
329
+ if (untrack(ctx.isOpen)) closedOutside = false;
330
+ },
331
+ });
332
+
333
+ createHideOutside({ layer: handle, active: () => ctx.isOpen() && modal() });
334
+
335
+ createAnchored({
336
+ anchor: () => ctx.anchor() ?? ctx.trigger(),
337
+ floating: panel,
338
+ open: ctx.isOpen,
339
+ side: ctx.side,
340
+ align: ctx.align,
341
+ offset: untrack(ctx.gutter),
342
+ coverAnchor: true,
343
+ widthVar: ANCHOR_WIDTH,
344
+ });
345
+
346
+ const [scoping, setScoping] = createSignal(false);
347
+ const scope = createFocusScope({
348
+ container: panel,
349
+ active: scoping,
350
+ trapped: modal,
351
+ initialFocus: (container) => {
352
+ if (!vetoed(local.onOpenAutoFocus, new Event("openautofocus", { cancelable: true })))
353
+ return null;
354
+ const active = activeOf(container);
355
+ return active instanceof HTMLElement && container.contains(active) ? active : container;
356
+ },
357
+ });
358
+
359
+ effect(
360
+ () => ctx.isOpen() && panel() !== undefined,
361
+ (open) => {
362
+ if (open) {
363
+ closedOutside = false;
364
+ setScoping(true);
365
+ return;
366
+ }
367
+ if (!untrack(scoping)) return;
368
+ const outside = closedOutside;
369
+ closedOutside = false;
370
+ scope.skipRestore();
371
+ setScoping(false);
372
+ if (vetoed(local.onCloseAutoFocus, new Event("closeautofocus", { cancelable: true }))) return;
373
+ const trigger = ctx.trigger();
374
+ const from = panel();
375
+ if (!trigger || !from) return;
376
+ if (!outside) {
377
+ queueMicrotask(() => focusWithoutTracking(trigger));
378
+ return;
379
+ }
380
+ // After the press's own focus change: the trigger takes focus only if nothing else did.
381
+ setTimeout(() => {
382
+ if (trigger.isConnected && focusLostFrom(from)) focusWithoutTracking(trigger);
383
+ }, 0);
384
+ },
385
+ );
386
+
101
387
  // The morph starts as the trigger's box (pill radius clamped to h/2). A
102
388
  // field picker has an Anchor, not a Trigger, and keeps its clip reveal.
103
389
  const writeMorphStart = (el: HTMLElement) => {
104
- const trigger = popover.triggerRef();
390
+ const trigger = ctx.trigger();
105
391
  if (!trigger || surface() === "field") return;
106
392
  const height = trigger.getBoundingClientRect().height;
107
- const radius = Math.min(
108
- Number.parseFloat(getComputedStyle(trigger).borderTopLeftRadius) || 0,
109
- height / 2,
110
- );
111
393
  el.style.setProperty("--morph-h", `${height}px`);
112
- el.style.setProperty("--morph-radius", `${radius}px`);
394
+ el.style.setProperty("--morph-radius", controlRadius(height));
113
395
  };
114
- return (
115
- <PopoverPrimitive.Portal mount={usePortalMount()}>
116
- <PopoverPrimitive.Content
117
- ref={(el: HTMLElement) => {
396
+
397
+ const Panel: Component = () => {
398
+ onCleanup(() => setPanel(undefined));
399
+ return (
400
+ <div
401
+ {...nestedLayerAttrs(modal() || covered())}
402
+ {...rest}
403
+ ref={(el) => {
118
404
  setPanel(el);
119
405
  writeMorphStart(el);
120
406
  if (typeof local.ref === "function") local.ref(el);
121
407
  }}
122
- onInteractOutside={layer.onInteractOutside}
123
- onCloseAutoFocus={layer.onCloseAutoFocus}
408
+ id={id()}
409
+ role="dialog"
410
+ tabIndex={-1}
411
+ aria-labelledby={ctx.titleId()}
412
+ aria-describedby={ctx.descriptionId()}
124
413
  data-slot="popover-content"
125
414
  data-surface={surface()}
126
- {...nestedLayerAttrs(popover.isModal() || layer.covered())}
415
+ data-expanded={ctx.isOpen() ? "" : undefined}
416
+ data-closed={ctx.isOpen() ? undefined : ""}
127
417
  class={cn(surface() === "field" ? FIELD_PANEL : OVERLAY_PANEL, local.class)}
128
- {...rest}
129
418
  />
130
- </PopoverPrimitive.Portal>
419
+ );
420
+ };
421
+
422
+ return (
423
+ <Show when={presence.mounted()}>
424
+ <Portal mount={mount}>
425
+ <Panel />
426
+ </Portal>
427
+ </Show>
131
428
  );
132
429
  };
133
430
 
134
- /** Inside a PopoverAnchor: names the control that opens the popover, so focus goes back to it on close. */
135
- const AnchorTriggerContext = createContext<(el: HTMLElement) => void>();
431
+ function labelPart(
432
+ defaultAs: ValidComponent,
433
+ register: (ctx: PopoverContextValue) => (id: string | undefined) => void,
434
+ ) {
435
+ return <T extends ValidComponent>(props: PartProps<T>): JSX.Element => {
436
+ const set = register(usePopover());
437
+ const [local, rest] = splitProps(props as PartProps<ValidComponent>, ["as", "id"]);
438
+ const fallback = createUniqueId();
439
+ const id = (): string => local.id ?? fallback;
440
+ effect(id, (next) => {
441
+ set(next);
442
+ return () => set(undefined);
443
+ });
444
+ return (
445
+ <Polymorphic
446
+ {...merge(rest, {
447
+ as: local.as,
448
+ defaultAs,
449
+ get id() {
450
+ return id();
451
+ },
452
+ })}
453
+ />
454
+ );
455
+ };
456
+ }
136
457
 
137
- const PopoverAnchor: Component<ComponentProps<typeof PopoverPrimitive.Anchor>> = (props) => {
138
- const popover = usePopoverContext();
458
+ const PopoverTitle = labelPart("h2", (ctx) => ctx.setTitleId);
459
+ const PopoverDescription = labelPart("p", (ctx) => ctx.setDescriptionId);
460
+
461
+ function PopoverCloseButton<T extends ValidComponent = "button">(props: PartProps<T>): JSX.Element {
462
+ const ctx = usePopover();
463
+ const [local, rest] = splitProps(props as PartProps<ValidComponent>, ["as"]);
139
464
  return (
140
- <AnchorTriggerContext.Provider value={popover.setTriggerRef}>
141
- <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} />
142
- </AnchorTriggerContext.Provider>
465
+ <Polymorphic
466
+ {...merge({ "aria-label": "Dismiss" }, rest, {
467
+ as: local.as,
468
+ defaultAs: "button" as ValidComponent,
469
+ "on:click": () => ctx.setOpen(false),
470
+ })}
471
+ />
143
472
  );
144
- };
473
+ }
145
474
 
146
- /** The control, inside a PopoverAnchor, that opens its popover. */
147
- const useAnchorTrigger = () => useContext(AnchorTriggerContext);
475
+ /** @deprecated Drop the wrapper; the content portals itself; removed in 2.0.0. */
476
+ const PopoverPortal: Component<{ children?: JSX.Element; mount?: Node }> = (props) => (
477
+ <>{props.children}</>
478
+ );
479
+
480
+ /** @deprecated Ignored; removed in 2.0.0. */
481
+ const PopoverArrow: Component = () => null;
482
+
483
+ const Popover = Object.assign(PopoverRoot, {
484
+ Anchor: PopoverAnchor,
485
+ Arrow: PopoverArrow,
486
+ CloseButton: PopoverCloseButton,
487
+ Content: PopoverContent,
488
+ Description: PopoverDescription,
489
+ Portal: PopoverPortal,
490
+ Title: PopoverTitle,
491
+ Trigger: PopoverTrigger,
492
+ });
148
493
 
149
494
  export { Popover, PopoverAnchor, PopoverContent, PopoverTrigger, useAnchorTrigger };
@@ -33,7 +33,7 @@ export function PreviewTileGroup(props: {
33
33
  }) {
34
34
  let group: HTMLElement | undefined;
35
35
  onMount(() => {
36
- if (props.scroll && group) onCleanup(trackScroll(group, "[data-checked]", "data-checked"));
36
+ if (props.scroll && group) onCleanup(trackScroll(group, "[data-checked]", () => props.value));
37
37
  });
38
38
  return (
39
39
  <RadioGroup