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