@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.
- package/SPEC.md +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/lib/anchor-placement.d.ts +34 -0
- package/dist/lib/balance-rows.d.ts +10 -4
- package/dist/lib/behavior/anchored.d.ts +26 -0
- package/dist/lib/behavior/button-root.d.ts +7 -0
- package/dist/lib/behavior/collection.d.ts +32 -0
- package/dist/lib/behavior/controllable.d.ts +8 -0
- package/dist/lib/behavior/dismiss.d.ts +13 -0
- package/dist/lib/behavior/focus-scope.d.ts +24 -0
- package/dist/lib/behavior/hide-outside.d.ts +7 -0
- package/dist/lib/behavior/layer-stack.d.ts +34 -0
- package/dist/lib/behavior/menu.d.ts +59 -0
- package/dist/lib/behavior/modal-root.d.ts +68 -0
- package/dist/lib/behavior/polymorphic.d.ts +6 -0
- package/dist/lib/behavior/presence.d.ts +18 -0
- package/dist/lib/behavior/range.d.ts +44 -0
- package/dist/lib/behavior/solid.d.ts +13 -0
- package/dist/lib/color/color.d.ts +41 -0
- package/dist/lib/color/index.d.ts +2 -0
- package/dist/lib/color/intl.d.ts +40 -0
- package/dist/lib/dock-slot-classes.d.ts +2 -0
- package/dist/lib/hold.d.ts +1 -1
- package/dist/lib/locale.d.ts +3 -0
- package/dist/lib/menu-classes.d.ts +2 -0
- package/dist/lib/motion-classes.d.ts +5 -2
- package/dist/lib/overlay-classes.d.ts +4 -0
- package/dist/lib/page-cover.d.ts +8 -0
- package/dist/lib/scroll-track.d.ts +3 -2
- package/dist/lib/section-tokens.d.ts +1 -1
- package/dist/lib/segment-classes.d.ts +2 -0
- package/dist/lib/shadow-layer.d.ts +0 -43
- package/dist/lib/toggle-set.d.ts +44 -0
- package/dist/lib/visually-hidden.d.ts +3 -0
- package/dist/solid/accordion.d.ts +35 -11
- package/dist/solid/alert-dialog.d.ts +5 -8
- package/dist/solid/avatar.d.ts +8 -4
- package/dist/solid/bottom-sheet/bottom-sheet.d.ts +2 -2
- package/dist/solid/bottom-sheet/constants.d.ts +1 -1
- package/dist/solid/button.d.ts +5 -4
- package/dist/solid/charts.d.ts +1 -1
- package/dist/solid/checkbox.d.ts +14 -4
- package/dist/solid/collapsible.d.ts +33 -5
- package/dist/solid/color-disc.d.ts +1 -1
- package/dist/solid/color-slider.d.ts +1 -1
- package/dist/solid/color-wheel.d.ts +1 -1
- package/dist/solid/context-menu.d.ts +58 -24
- package/dist/solid/dialog-parts.d.ts +53 -16
- package/dist/solid/dialog.d.ts +7 -10
- package/dist/solid/dropdown-menu.d.ts +55 -24
- package/dist/solid/empty.d.ts +1 -1
- package/dist/solid/form.d.ts +5 -6
- package/dist/solid/hover-card.d.ts +65 -9
- package/dist/solid/index.d.ts +5 -2
- package/dist/solid/index.js +8671 -14317
- package/dist/solid/input-group.d.ts +6 -6
- package/dist/solid/item.d.ts +1 -1
- package/dist/solid/menu-parts.d.ts +175 -24
- package/dist/solid/option-card.d.ts +1 -4
- package/dist/solid/picker-row.d.ts +2 -0
- package/dist/solid/popover.d.ts +77 -12
- package/dist/solid/progress.d.ts +11 -3
- package/dist/solid/radio-group.d.ts +31 -6
- package/dist/solid/responsive-dialog.d.ts +3 -1
- package/dist/solid/scroll-area.d.ts +1 -1
- package/dist/solid/section-card.d.ts +2 -3
- package/dist/solid/select.d.ts +107 -10
- package/dist/solid/selection.d.ts +10 -1
- package/dist/solid/sheet.d.ts +6 -9
- package/dist/solid/sliding-indicator.d.ts +1 -1
- package/dist/solid/sonner.d.ts +1 -1
- package/dist/solid/stale-veil.d.ts +7 -0
- package/dist/solid/tabs.d.ts +28 -9
- package/dist/solid/toggle-group.d.ts +30 -5
- package/dist/solid/toggle.d.ts +11 -3
- package/dist/solid/tooltip.d.ts +71 -9
- package/dist/tokens/index.js +54 -51
- package/dist/{utils-CGN4X-2O.js → utils-3Codx-NZ.js} +848 -618
- package/package.json +6 -7
- package/src/index.ts +1 -0
- package/src/lib/anchor-placement.ts +77 -4
- package/src/lib/balance-rows.ts +115 -40
- package/src/lib/behavior/anchored.ts +106 -0
- package/src/lib/behavior/button-root.tsx +103 -0
- package/src/lib/behavior/collection.ts +218 -0
- package/src/lib/behavior/controllable.ts +22 -0
- package/src/lib/behavior/dismiss.ts +185 -0
- package/src/lib/behavior/focus-scope.ts +227 -0
- package/src/lib/behavior/hide-outside.ts +85 -0
- package/src/lib/behavior/layer-stack.ts +150 -0
- package/src/lib/behavior/menu.ts +470 -0
- package/src/lib/behavior/modal-root.tsx +452 -0
- package/src/lib/behavior/polymorphic.tsx +30 -0
- package/src/lib/behavior/presence.ts +89 -0
- package/src/lib/behavior/range.ts +212 -0
- package/src/lib/behavior/solid.ts +30 -0
- package/src/lib/clipboard.ts +4 -4
- package/src/lib/color/color.ts +746 -0
- package/src/lib/color/index.ts +2 -0
- package/src/lib/color/intl.ts +60 -0
- package/src/lib/dock-slot-classes.ts +3 -0
- package/src/lib/hold.ts +1 -1
- package/src/lib/locale.ts +62 -0
- package/src/lib/menu-classes.ts +3 -0
- package/src/lib/motion-classes.ts +33 -8
- package/src/lib/overlay-classes.ts +8 -3
- package/src/lib/page-cover.ts +47 -0
- package/src/lib/scroll-track.ts +11 -6
- package/src/lib/section-tokens.ts +1 -1
- package/src/lib/segment-classes.ts +3 -0
- package/src/lib/shadow-layer.ts +0 -136
- package/src/lib/toggle-set.ts +133 -0
- package/src/lib/visually-hidden.ts +15 -0
- package/src/solid/accordion.tsx +294 -20
- package/src/solid/alert-dialog.tsx +36 -85
- package/src/solid/area-picker.tsx +5 -3
- package/src/solid/avatar.tsx +98 -24
- package/src/solid/badge.tsx +5 -5
- package/src/solid/bottom-sheet/bottom-sheet.tsx +73 -129
- package/src/solid/bottom-sheet/constants.ts +3 -1
- package/src/solid/bottom-sheet/drag-controller.ts +11 -0
- package/src/solid/breadcrumb.tsx +4 -4
- package/src/solid/button-group.tsx +4 -4
- package/src/solid/button.tsx +12 -6
- package/src/solid/card.tsx +5 -4
- package/src/solid/charts.tsx +1 -1
- package/src/solid/checkbox.tsx +167 -44
- package/src/solid/collapsible.tsx +260 -12
- package/src/solid/color-disc.tsx +11 -12
- package/src/solid/color-slider.tsx +114 -47
- package/src/solid/color-wheel.tsx +137 -39
- package/src/solid/context-menu.tsx +287 -86
- package/src/solid/dialog-parts.tsx +135 -46
- package/src/solid/dialog.tsx +44 -76
- package/src/solid/dock-edit.tsx +5 -4
- package/src/solid/dock.tsx +6 -5
- package/src/solid/dropdown-menu.tsx +252 -107
- package/src/solid/empty.tsx +1 -1
- package/src/solid/entity-selector.tsx +5 -3
- package/src/solid/face-toggle.tsx +43 -18
- package/src/solid/form.tsx +9 -9
- package/src/solid/glyph-tile.tsx +48 -21
- package/src/solid/hover-card.tsx +288 -21
- package/src/solid/icon-picker.tsx +2 -1
- package/src/solid/image-picker.tsx +6 -5
- package/src/solid/index.ts +5 -4
- package/src/solid/input-group.tsx +7 -5
- package/src/solid/input-otp.tsx +2 -1
- package/src/solid/item.tsx +5 -5
- package/src/solid/logo.tsx +5 -4
- package/src/solid/menu-parts.tsx +619 -145
- package/src/solid/option-card.tsx +6 -10
- package/src/solid/picker-row.tsx +10 -5
- package/src/solid/picker-search.tsx +2 -1
- package/src/solid/popover.tsx +424 -71
- package/src/solid/preview-tile.tsx +1 -1
- package/src/solid/progress.tsx +84 -15
- package/src/solid/radio-group.tsx +271 -34
- package/src/solid/responsive-dialog.tsx +10 -10
- package/src/solid/schema-form.tsx +1 -6
- package/src/solid/scroll-area.tsx +1 -1
- package/src/solid/section-card.tsx +3 -4
- package/src/solid/select.tsx +950 -95
- package/src/solid/selection.tsx +142 -66
- package/src/solid/sheet.tsx +48 -80
- package/src/solid/slider.tsx +115 -65
- package/src/solid/sliding-indicator.tsx +1 -1
- package/src/solid/sonner.tsx +1 -1
- package/src/solid/spotlight.tsx +23 -11
- package/src/solid/stale-veil.tsx +20 -0
- package/src/solid/switch.tsx +8 -6
- package/src/solid/tabs.tsx +377 -52
- package/src/solid/term.tsx +3 -4
- package/src/solid/toggle-group.tsx +237 -95
- package/src/solid/toggle.tsx +43 -9
- package/src/solid/tooltip.tsx +285 -26
- package/src/styles/globals.css +64 -10
- package/src/styles/theme.css +12 -4
- package/src/tokens/material.ts +11 -2
- package/dist/lib/when-animations-settle.d.ts +0 -4
- package/dist/solid/bottom-sheet/focus-trap.d.ts +0 -6
- package/dist/solid/bottom-sheet/scroll-lock.d.ts +0 -2
- package/dist/solid/bottom-sheet/sheet-motion.d.ts +0 -1
- package/src/lib/when-animations-settle.ts +0 -12
- package/src/solid/bottom-sheet/focus-trap.ts +0 -63
- package/src/solid/bottom-sheet/scroll-lock.ts +0 -66
- package/src/solid/bottom-sheet/sheet-motion.ts +0 -4
package/src/solid/popover.tsx
CHANGED
|
@@ -1,25 +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";
|
|
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";
|
|
24
|
+
import {
|
|
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";
|
|
11
34
|
import { INPUT_SURFACE } from "../lib/input-classes.js";
|
|
12
|
-
import { inShadowRoot, shadowLayer } from "../lib/shadow-layer.js";
|
|
13
35
|
import { nestedLayerAttrs, Z_CLASS } from "../lib/layers.js";
|
|
14
|
-
import { FIELD_MOTION, MORPH_MOTION, STAGGER } from "../lib/motion-classes.js";
|
|
15
|
-
import {
|
|
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";
|
|
16
39
|
import { cn } from "../lib/utils.js";
|
|
40
|
+
import { usePortalMount } from "./portal-mount.js";
|
|
17
41
|
|
|
18
42
|
type PopoverSurface = "overlay" | "field";
|
|
43
|
+
type Placement = Side | `${Side}-${Exclude<Align, "center">}`;
|
|
19
44
|
|
|
20
|
-
const
|
|
21
|
-
() => "overlay" as PopoverSurface,
|
|
22
|
-
);
|
|
45
|
+
const ANCHOR_WIDTH = "--kb-popper-anchor-width";
|
|
23
46
|
|
|
24
47
|
/* The expanding field panel: opaque (the trigger sits underneath it), bound to
|
|
25
48
|
* the anchor width and radius, and padded by whatever part needs padding, never
|
|
@@ -28,114 +51,444 @@ const FIELD_PANEL = `${INPUT_SURFACE} ${FIELD_MOTION} relative ${Z_CLASS.overlay
|
|
|
28
51
|
|
|
29
52
|
const OVERLAY_PANEL = `${FLOATING_PANEL} ${MORPH_MOTION} ${STAGGER} w-72 p-4`;
|
|
30
53
|
|
|
31
|
-
|
|
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;
|
|
32
60
|
/** "field" anchors the panel over the trigger's top edge, so the field reads
|
|
33
61
|
* as expanding into its panel instead of a box dropping in below it. */
|
|
34
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;
|
|
35
125
|
};
|
|
36
126
|
|
|
37
127
|
const PopoverRoot: Component<PopoverProps> = (props) => {
|
|
38
|
-
const [
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
});
|
|
42
192
|
return (
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
+
/>
|
|
53
211
|
);
|
|
54
|
-
}
|
|
212
|
+
}
|
|
55
213
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
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);
|
|
59
216
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
+
}
|
|
65
236
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
};
|
|
237
|
+
/** The control, inside a PopoverAnchor, that opens its popover. */
|
|
238
|
+
const useAnchorTrigger = () => useContext(AnchorTriggerContext) ?? undefined;
|
|
69
239
|
|
|
70
|
-
|
|
240
|
+
interface PopoverContentProps extends Omit<ComponentProps<"div">, "ref"> {
|
|
71
241
|
surface?: PopoverSurface;
|
|
72
|
-
|
|
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
|
+
}
|
|
73
259
|
|
|
74
260
|
const PopoverContent: Component<PopoverContentProps> = (props) => {
|
|
261
|
+
const ctx = usePopover();
|
|
75
262
|
const [local, rest] = splitProps(props, [
|
|
76
263
|
"class",
|
|
77
264
|
"surface",
|
|
78
265
|
"ref",
|
|
266
|
+
"id",
|
|
267
|
+
"forceMount",
|
|
268
|
+
"onEscapeKeyDown",
|
|
269
|
+
"onPointerDownOutside",
|
|
270
|
+
"onFocusOutside",
|
|
79
271
|
"onInteractOutside",
|
|
272
|
+
"onOpenAutoFocus",
|
|
80
273
|
"onCloseAutoFocus",
|
|
81
274
|
]);
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const
|
|
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);
|
|
85
286
|
const [panel, setPanel] = createSignal<HTMLElement>();
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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,
|
|
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
|
+
},
|
|
92
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
|
+
|
|
93
387
|
// The morph starts as the trigger's box (pill radius clamped to h/2). A
|
|
94
388
|
// field picker has an Anchor, not a Trigger, and keeps its clip reveal.
|
|
95
389
|
const writeMorphStart = (el: HTMLElement) => {
|
|
96
|
-
const trigger =
|
|
390
|
+
const trigger = ctx.trigger();
|
|
97
391
|
if (!trigger || surface() === "field") return;
|
|
98
392
|
const height = trigger.getBoundingClientRect().height;
|
|
99
|
-
const radius = Math.min(
|
|
100
|
-
Number.parseFloat(getComputedStyle(trigger).borderTopLeftRadius) || 0,
|
|
101
|
-
height / 2,
|
|
102
|
-
);
|
|
103
393
|
el.style.setProperty("--morph-h", `${height}px`);
|
|
104
|
-
el.style.setProperty("--morph-radius",
|
|
394
|
+
el.style.setProperty("--morph-radius", controlRadius(height));
|
|
105
395
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
396
|
+
|
|
397
|
+
const Panel: Component = () => {
|
|
398
|
+
onCleanup(() => setPanel(undefined));
|
|
399
|
+
return (
|
|
400
|
+
<div
|
|
401
|
+
{...nestedLayerAttrs(modal() || covered())}
|
|
402
|
+
{...rest}
|
|
403
|
+
ref={(el) => {
|
|
110
404
|
setPanel(el);
|
|
111
405
|
writeMorphStart(el);
|
|
112
406
|
if (typeof local.ref === "function") local.ref(el);
|
|
113
407
|
}}
|
|
114
|
-
|
|
115
|
-
|
|
408
|
+
id={id()}
|
|
409
|
+
role="dialog"
|
|
410
|
+
tabIndex={-1}
|
|
411
|
+
aria-labelledby={ctx.titleId()}
|
|
412
|
+
aria-describedby={ctx.descriptionId()}
|
|
116
413
|
data-slot="popover-content"
|
|
117
414
|
data-surface={surface()}
|
|
118
|
-
{
|
|
415
|
+
data-expanded={ctx.isOpen() ? "" : undefined}
|
|
416
|
+
data-closed={ctx.isOpen() ? undefined : ""}
|
|
119
417
|
class={cn(surface() === "field" ? FIELD_PANEL : OVERLAY_PANEL, local.class)}
|
|
120
|
-
{...rest}
|
|
121
418
|
/>
|
|
122
|
-
|
|
419
|
+
);
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
return (
|
|
423
|
+
<Show when={presence.mounted()}>
|
|
424
|
+
<Portal mount={mount}>
|
|
425
|
+
<Panel />
|
|
426
|
+
</Portal>
|
|
427
|
+
</Show>
|
|
123
428
|
);
|
|
124
429
|
};
|
|
125
430
|
|
|
126
|
-
|
|
127
|
-
|
|
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
|
+
}
|
|
128
457
|
|
|
129
|
-
const
|
|
130
|
-
|
|
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"]);
|
|
131
464
|
return (
|
|
132
|
-
<
|
|
133
|
-
|
|
134
|
-
|
|
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
|
+
/>
|
|
135
472
|
);
|
|
136
|
-
}
|
|
473
|
+
}
|
|
137
474
|
|
|
138
|
-
/**
|
|
139
|
-
const
|
|
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
|
+
});
|
|
140
493
|
|
|
141
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]",
|
|
36
|
+
if (props.scroll && group) onCleanup(trackScroll(group, "[data-checked]", () => props.value));
|
|
37
37
|
});
|
|
38
38
|
return (
|
|
39
39
|
<RadioGroup
|