@glasshome/ui 1.21.1 → 1.22.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/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/use-is-mobile.d.ts +3 -1
- package/dist/solid/index.d.ts +9 -9
- package/dist/solid/index.js +5431 -5424
- package/dist/solid/sonner.d.ts +1 -0
- package/dist/{utils-CMk7R3zM.js → utils-D5blHO4O.js} +624 -622
- package/package.json +128 -126
- package/scripts/check-gallery.ts +142 -142
- package/scripts/check-pack.ts +13 -13
- package/scripts/check-structural-classes.ts +20 -20
- package/scripts/check-tokens.ts +27 -27
- package/scripts/check-ui-drift.mjs +103 -103
- package/src/index.ts +75 -80
- package/src/lib/alert-tones.ts +41 -41
- package/src/lib/anchor-placement.ts +21 -21
- package/src/lib/button-variants.ts +28 -28
- package/src/lib/card-classes.ts +9 -9
- package/src/lib/carousel-classes.ts +14 -14
- package/src/lib/glass-tone.ts +11 -11
- package/src/lib/input-classes.ts +6 -6
- package/src/lib/layers.ts +4 -4
- package/src/lib/logo-lockup.ts +8 -8
- package/src/lib/menu-classes.ts +2 -2
- package/src/lib/motion-classes.ts +8 -8
- package/src/lib/motion-window.ts +24 -24
- package/src/lib/overlay-classes.ts +6 -6
- package/src/lib/pill-classes.ts +3 -3
- package/src/lib/position-bar-classes.ts +1 -1
- package/src/lib/spotlight-geometry.ts +67 -67
- package/src/lib/thumb-classes.ts +2 -2
- package/src/lib/tier-badge.ts +16 -16
- package/src/lib/use-is-mobile.ts +17 -14
- package/src/lib/utils.ts +1 -1
- package/src/solid/accordion.tsx +41 -41
- package/src/solid/alert-dialog.tsx +95 -95
- package/src/solid/alert.tsx +88 -88
- package/src/solid/area-picker.tsx +204 -204
- package/src/solid/aspect-ratio.tsx +13 -13
- package/src/solid/avatar.tsx +27 -27
- package/src/solid/badge.tsx +49 -49
- package/src/solid/bottom-sheet/arbitration.ts +22 -22
- package/src/solid/bottom-sheet/bottom-sheet.tsx +394 -394
- package/src/solid/bottom-sheet/drag-controller.ts +201 -201
- package/src/solid/bottom-sheet/focus-trap.ts +51 -47
- package/src/solid/bottom-sheet/index.ts +12 -12
- package/src/solid/bottom-sheet/keyboard.ts +25 -25
- package/src/solid/bottom-sheet/scroll-lock.ts +46 -46
- package/src/solid/bottom-sheet/state-machine.ts +28 -28
- package/src/solid/bottom-sheet/velocity.ts +29 -29
- package/src/solid/breadcrumb.tsx +76 -76
- package/src/solid/button-group.tsx +46 -46
- package/src/solid/button.tsx +19 -19
- package/src/solid/card.tsx +67 -67
- package/src/solid/carousel.tsx +246 -246
- package/src/solid/charts.tsx +253 -253
- package/src/solid/checkbox.tsx +51 -51
- package/src/solid/collapsible.tsx +22 -22
- package/src/solid/color-disc.tsx +213 -213
- package/src/solid/color-slider.tsx +81 -81
- package/src/solid/color-wheel.tsx +61 -61
- package/src/solid/context-menu.tsx +63 -63
- package/src/solid/copy-button.tsx +31 -31
- package/src/solid/count-pill.tsx +11 -11
- package/src/solid/dashboard-preview.tsx +104 -104
- package/src/solid/data-table.tsx +228 -228
- package/src/solid/dialog-parts.tsx +127 -127
- package/src/solid/dialog.tsx +113 -113
- package/src/solid/dock-paging.ts +9 -9
- package/src/solid/dock.tsx +339 -339
- package/src/solid/docked-panel.tsx +35 -35
- package/src/solid/dropdown-menu.tsx +77 -77
- package/src/solid/empty.tsx +70 -70
- package/src/solid/entity-data.ts +38 -38
- package/src/solid/entity-selector.tsx +634 -634
- package/src/solid/field.tsx +205 -205
- package/src/solid/form.tsx +159 -159
- package/src/solid/hero-action.tsx +85 -85
- package/src/solid/hover-card.tsx +11 -11
- package/src/solid/icon-picker.tsx +401 -401
- package/src/solid/icon.tsx +101 -78
- package/src/solid/image-picker.tsx +416 -414
- package/src/solid/index.ts +265 -304
- package/src/solid/input-group.tsx +123 -123
- package/src/solid/input-otp.tsx +143 -143
- package/src/solid/input.tsx +4 -4
- package/src/solid/item.tsx +130 -130
- package/src/solid/kbd.tsx +20 -20
- package/src/solid/label.tsx +12 -12
- package/src/solid/list-reorder.ts +122 -122
- package/src/solid/logo.tsx +60 -60
- package/src/solid/media-copy.ts +21 -21
- package/src/solid/media-store.ts +56 -56
- package/src/solid/media-tile.tsx +85 -85
- package/src/solid/menu-parts.tsx +164 -164
- package/src/solid/number-field.tsx +56 -56
- package/src/solid/option-card.tsx +164 -164
- package/src/solid/ornament.tsx +43 -43
- package/src/solid/overlay.tsx +4 -4
- package/src/solid/page-header.tsx +75 -75
- package/src/solid/pagination.tsx +80 -80
- package/src/solid/password-input.tsx +51 -51
- package/src/solid/picker-row.tsx +83 -83
- package/src/solid/picker-search.tsx +65 -63
- package/src/solid/picker-trigger.tsx +59 -57
- package/src/solid/popover.tsx +54 -54
- package/src/solid/preview-tile.tsx +67 -67
- package/src/solid/progress.tsx +21 -21
- package/src/solid/radio-group.tsx +51 -51
- package/src/solid/resizable.tsx +128 -128
- package/src/solid/responsive-dialog.tsx +134 -134
- package/src/solid/schema-form.tsx +743 -743
- package/src/solid/scope-indicator.tsx +5 -5
- package/src/solid/scroll-area.tsx +16 -16
- package/src/solid/section-card.tsx +281 -281
- package/src/solid/select.tsx +101 -101
- package/src/solid/separator.tsx +25 -25
- package/src/solid/settings-row.tsx +122 -122
- package/src/solid/sheet.tsx +96 -96
- package/src/solid/skeleton.tsx +8 -8
- package/src/solid/slider.tsx +132 -132
- package/src/solid/sliding-indicator.tsx +280 -265
- package/src/solid/sonner.tsx +165 -164
- package/src/solid/spinner.tsx +12 -12
- package/src/solid/spotlight.tsx +140 -140
- package/src/solid/step-indicator.tsx +18 -18
- package/src/solid/swatch-picker.tsx +38 -38
- package/src/solid/switch.tsx +52 -52
- package/src/solid/table.tsx +63 -63
- package/src/solid/tabs.tsx +93 -93
- package/src/solid/textarea.tsx +8 -8
- package/src/solid/toggle-group.tsx +83 -83
- package/src/solid/toggle.tsx +33 -33
- package/src/solid/tooltip.tsx +16 -16
- package/src/solid/widget-card.tsx +90 -90
- package/src/solid/widget-identity.tsx +99 -99
- package/src/solid/widget-trust-badge.tsx +20 -20
- package/src/styles/globals.css +316 -319
- package/src/styles/theme.css +448 -448
- package/src/tokens/hex.ts +29 -29
- package/src/tokens/material.ts +75 -75
- package/src/tokens/presets.ts +303 -303
- package/src/tokens/readability.ts +32 -32
- package/src/tokens/theme-colors.ts +95 -95
- package/src/tokens/theme-css.ts +22 -22
- package/src/tokens/theme-recipe.ts +106 -106
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
type Component,
|
|
3
|
+
type ComponentProps,
|
|
4
|
+
createContext,
|
|
5
|
+
createEffect,
|
|
6
|
+
createMemo,
|
|
7
|
+
createRenderEffect,
|
|
8
|
+
createSignal,
|
|
9
|
+
type JSX,
|
|
10
|
+
onCleanup,
|
|
11
|
+
type ParentComponent,
|
|
12
|
+
Show,
|
|
13
|
+
splitProps,
|
|
14
|
+
useContext,
|
|
15
|
+
type ValidComponent,
|
|
16
16
|
} from "solid-js";
|
|
17
17
|
import { Dynamic, Portal } from "solid-js/web";
|
|
18
18
|
import { Z } from "../../lib/layers.js";
|
|
19
19
|
import { OVERLAY_SURFACE_OPAQUE } from "../../lib/overlay-classes.js";
|
|
20
20
|
import { cn } from "../../lib/utils.js";
|
|
21
21
|
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
callEventHandler,
|
|
23
|
+
createModalLabels,
|
|
24
|
+
createModalParts,
|
|
25
|
+
MODAL_DESCRIPTION,
|
|
26
|
+
MODAL_MAX_H,
|
|
27
|
+
MODAL_TITLE,
|
|
28
|
+
ModalLabelsProvider,
|
|
29
|
+
useModalLabels,
|
|
30
30
|
} from "../dialog-parts.js";
|
|
31
31
|
import { EASE, TRANSITION_MS } from "./constants.js";
|
|
32
32
|
import { attachDrag } from "./drag-controller.js";
|
|
@@ -36,429 +36,429 @@ import { acquireScrollLock, releaseScrollLock } from "./scroll-lock.js";
|
|
|
36
36
|
import { assertTransition, type SheetState } from "./state-machine.js";
|
|
37
37
|
|
|
38
38
|
interface BottomSheetContextValue {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
state: () => SheetState;
|
|
40
|
+
setState: (next: SheetState) => void;
|
|
41
|
+
open: () => boolean;
|
|
42
|
+
setOpen: (next: boolean) => void;
|
|
43
|
+
dismissible: () => boolean;
|
|
44
|
+
contentRef: () => HTMLDivElement | undefined;
|
|
45
|
+
setContentRef: (el: HTMLDivElement | undefined) => void;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
const BottomSheetContext = createContext<BottomSheetContextValue>();
|
|
49
49
|
|
|
50
50
|
function useBottomSheetContext(): BottomSheetContextValue {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
const ctx = useContext(BottomSheetContext);
|
|
52
|
+
if (!ctx) throw new Error("BottomSheet components must be used within <BottomSheet>");
|
|
53
|
+
return ctx;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
interface BottomSheetRootProps {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
open?: boolean;
|
|
58
|
+
defaultOpen?: boolean;
|
|
59
|
+
onOpenChange?: (open: boolean) => void;
|
|
60
|
+
dismissible?: boolean;
|
|
61
|
+
children: JSX.Element;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
const BottomSheet: ParentComponent<BottomSheetRootProps> = (props) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
65
|
+
const [uncontrolled, setUncontrolled] = createSignal(props.defaultOpen ?? false);
|
|
66
|
+
const [state, setStateRaw] = createSignal<SheetState>("closed");
|
|
67
|
+
const [contentRef, setContentRef] = createSignal<HTMLDivElement | undefined>(undefined);
|
|
68
|
+
|
|
69
|
+
const isControlled = () => props.open !== undefined;
|
|
70
|
+
const open = (): boolean => (isControlled() ? props.open === true : uncontrolled());
|
|
71
|
+
|
|
72
|
+
const setOpen = (next: boolean) => {
|
|
73
|
+
if (!isControlled()) setUncontrolled(next);
|
|
74
|
+
props.onOpenChange?.(next);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const setState = (next: SheetState) => {
|
|
78
|
+
const current = state();
|
|
79
|
+
assertTransition(current, next);
|
|
80
|
+
setStateRaw(next);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const dismissible = () => props.dismissible !== false;
|
|
84
|
+
|
|
85
|
+
createEffect(() => {
|
|
86
|
+
const isOpen = open();
|
|
87
|
+
const s = state();
|
|
88
|
+
if (isOpen && s === "closed") {
|
|
89
|
+
setState("opening");
|
|
90
|
+
} else if (
|
|
91
|
+
!isOpen &&
|
|
92
|
+
(s === "open" || s === "opening" || s === "pressing" || s === "dragging" || s === "snapping")
|
|
93
|
+
) {
|
|
94
|
+
setState("closing");
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<BottomSheetContext.Provider
|
|
100
|
+
value={{
|
|
101
|
+
state,
|
|
102
|
+
setState,
|
|
103
|
+
open,
|
|
104
|
+
setOpen,
|
|
105
|
+
dismissible,
|
|
106
|
+
contentRef,
|
|
107
|
+
setContentRef,
|
|
108
|
+
}}
|
|
109
|
+
>
|
|
110
|
+
{props.children}
|
|
111
|
+
</BottomSheetContext.Provider>
|
|
112
|
+
);
|
|
113
113
|
};
|
|
114
114
|
|
|
115
115
|
/* A button by default; rendered as a link it takes the anchor's own props. */
|
|
116
116
|
type SheetButtonProps = ComponentProps<"button"> &
|
|
117
|
-
|
|
117
|
+
Partial<Pick<ComponentProps<"a">, "href" | "target" | "rel">> & { as?: ValidComponent };
|
|
118
118
|
|
|
119
119
|
const BottomSheetTrigger: ParentComponent<SheetButtonProps> = (props) => {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
120
|
+
const [local, rest] = splitProps(props, ["children", "onClick", "as"]);
|
|
121
|
+
const ctx = useBottomSheetContext();
|
|
122
|
+
const component = () => local.as ?? "button";
|
|
123
|
+
return (
|
|
124
|
+
<Dynamic
|
|
125
|
+
component={component()}
|
|
126
|
+
type={component() === "button" ? "button" : undefined}
|
|
127
|
+
data-slot="bottom-sheet-trigger"
|
|
128
|
+
aria-haspopup="dialog"
|
|
129
|
+
aria-expanded={ctx.open()}
|
|
130
|
+
onClick={(event: MouseEvent & { currentTarget: HTMLButtonElement; target: Element }) => {
|
|
131
|
+
callEventHandler(event, local.onClick);
|
|
132
|
+
ctx.setOpen(true);
|
|
133
|
+
}}
|
|
134
|
+
{...rest}
|
|
135
|
+
>
|
|
136
|
+
{local.children}
|
|
137
|
+
</Dynamic>
|
|
138
|
+
);
|
|
139
139
|
};
|
|
140
140
|
|
|
141
141
|
interface BottomSheetPortalProps {
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
children: JSX.Element;
|
|
143
|
+
mount?: Node;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
const BottomSheetPortal: Component<BottomSheetPortalProps> = (props) => {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
147
|
+
const ctx = useBottomSheetContext();
|
|
148
|
+
const mounted = () => ctx.state() !== "closed";
|
|
149
|
+
return (
|
|
150
|
+
<Show when={mounted()}>
|
|
151
|
+
<Portal mount={props.mount}>{props.children}</Portal>
|
|
152
|
+
</Show>
|
|
153
|
+
);
|
|
154
154
|
};
|
|
155
155
|
|
|
156
156
|
const BottomSheetOverlay: Component<ComponentProps<"div">> = (props) => {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
157
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
158
|
+
const ctx = useBottomSheetContext();
|
|
159
|
+
|
|
160
|
+
const dataState = () => {
|
|
161
|
+
const s = ctx.state();
|
|
162
|
+
if (s === "closing") return "closing";
|
|
163
|
+
if (s === "opening" || s === "closed") return s;
|
|
164
|
+
return "open";
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<div
|
|
169
|
+
data-slot="bottom-sheet-overlay"
|
|
170
|
+
data-sheet-overlay=""
|
|
171
|
+
data-state={dataState()}
|
|
172
|
+
aria-hidden="true"
|
|
173
|
+
class={cn(
|
|
174
|
+
"fixed inset-0 bg-black/80 transition-opacity duration-300 ease-out",
|
|
175
|
+
"data-[state=closing]:opacity-0 data-[state=open]:opacity-100",
|
|
176
|
+
local.class,
|
|
177
|
+
)}
|
|
178
|
+
style={{ "z-index": Z.sheet }}
|
|
179
|
+
{...rest}
|
|
180
|
+
/>
|
|
181
|
+
);
|
|
182
182
|
};
|
|
183
183
|
|
|
184
184
|
interface BottomSheetContentProps extends ComponentProps<"div"> {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
185
|
+
initialFocus?: InitialFocus;
|
|
186
|
+
/** Names a sheet that has no `BottomSheetTitle`. A registered Title wins. */
|
|
187
|
+
ariaLabel?: string;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
const BottomSheetContent: ParentComponent<BottomSheetContentProps> = (props) => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
191
|
+
const [local, rest] = splitProps(props, [
|
|
192
|
+
"class",
|
|
193
|
+
"children",
|
|
194
|
+
"initialFocus",
|
|
195
|
+
"ariaLabel",
|
|
196
|
+
"style",
|
|
197
|
+
]);
|
|
198
|
+
const ctx = useBottomSheetContext();
|
|
199
|
+
const labels = createModalLabels();
|
|
200
|
+
let el: HTMLDivElement | undefined;
|
|
201
|
+
|
|
202
|
+
/* Keyed on presence, not on mount: a sheet rendered without
|
|
203
|
+
* BottomSheetPortal stays in the tree while closed and must not hold the
|
|
204
|
+
* page lock. Release also runs on unmount, so no animation can strand it. */
|
|
205
|
+
const present = createMemo(() => ctx.state() !== "closed");
|
|
206
|
+
createEffect(() => {
|
|
207
|
+
if (!present()) return;
|
|
208
|
+
acquireScrollLock();
|
|
209
|
+
onCleanup(releaseScrollLock);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const clearAnimInline = () => {
|
|
213
|
+
if (!el) return;
|
|
214
|
+
el.style.transition = "";
|
|
215
|
+
el.style.animation = "";
|
|
216
|
+
el.style.transform = "";
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const onAnimationEnd = (e: AnimationEvent) => {
|
|
220
|
+
if (e.target !== el) return;
|
|
221
|
+
const s = ctx.state();
|
|
222
|
+
if (s === "opening" && e.animationName === "bs-slide-up") ctx.setState("open");
|
|
223
|
+
else if (s === "closing" && e.animationName === "bs-slide-down") ctx.setState("closed");
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const onTransitionEnd = (e: TransitionEvent) => {
|
|
227
|
+
if (e.target !== el) return;
|
|
228
|
+
if (e.propertyName !== "transform") return;
|
|
229
|
+
const s = ctx.state();
|
|
230
|
+
if (s === "snapping") {
|
|
231
|
+
ctx.setState("open");
|
|
232
|
+
clearAnimInline();
|
|
233
|
+
} else if (s === "closing") {
|
|
234
|
+
ctx.setState("closed");
|
|
235
|
+
clearAnimInline();
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
createEffect(() => {
|
|
240
|
+
const node = ctx.contentRef();
|
|
241
|
+
if (!node) return;
|
|
242
|
+
const handle = attachDrag({
|
|
243
|
+
el: node,
|
|
244
|
+
getState: ctx.state,
|
|
245
|
+
setState: ctx.setState,
|
|
246
|
+
requestClose: () => ctx.setOpen(false),
|
|
247
|
+
});
|
|
248
|
+
onCleanup(() => handle.destroy());
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
createEffect(() => {
|
|
252
|
+
const node = ctx.contentRef();
|
|
253
|
+
if (!node) return;
|
|
254
|
+
if (ctx.state() === "closed") return;
|
|
255
|
+
const handle = watchKeyboard(node);
|
|
256
|
+
onCleanup(() => handle.destroy());
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
createEffect(() => {
|
|
260
|
+
const s = ctx.state();
|
|
261
|
+
if (s !== "open" && s !== "opening") return;
|
|
262
|
+
if (!el) return;
|
|
263
|
+
const handle = trapFocus(el, local.initialFocus ?? "container");
|
|
264
|
+
onCleanup(() => handle.release());
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
createEffect(() => {
|
|
268
|
+
if (ctx.state() === "closed") return;
|
|
269
|
+
const onKey = (e: KeyboardEvent) => {
|
|
270
|
+
if (e.key !== "Escape") return;
|
|
271
|
+
if (!ctx.dismissible()) return;
|
|
272
|
+
e.preventDefault();
|
|
273
|
+
ctx.setOpen(false);
|
|
274
|
+
};
|
|
275
|
+
document.addEventListener("keydown", onKey);
|
|
276
|
+
onCleanup(() => document.removeEventListener("keydown", onKey));
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// setTimeout(0) lets the click that opened the sheet finish bubbling
|
|
280
|
+
// before the dismiss listener is attached. Touch defers to `click` so
|
|
281
|
+
// drag/scroll intent can be detected first.
|
|
282
|
+
createEffect(() => {
|
|
283
|
+
if (ctx.state() === "closed") return;
|
|
284
|
+
if (!ctx.dismissible()) return;
|
|
285
|
+
|
|
286
|
+
let attached = false;
|
|
287
|
+
let pendingClick: ((e: MouseEvent) => void) | null = null;
|
|
288
|
+
|
|
289
|
+
const PORTAL_LAYER_SELECTOR =
|
|
290
|
+
'[data-kb-top-layer], [role="dialog"], [role="menu"], [role="listbox"], [role="combobox"], [role="tooltip"]';
|
|
291
|
+
const isOutside = (target: EventTarget | null): boolean => {
|
|
292
|
+
if (!(target instanceof Element) || !el) return false;
|
|
293
|
+
if (el.contains(target)) return false;
|
|
294
|
+
if (target.closest("[data-sheet-content]")) return false;
|
|
295
|
+
if (target.closest(PORTAL_LAYER_SELECTOR)) return false;
|
|
296
|
+
return true;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
const onPointerDown = (e: PointerEvent) => {
|
|
300
|
+
if (!isOutside(e.target)) return;
|
|
301
|
+
const dismiss = () => {
|
|
302
|
+
if (ctx.state() === "open") ctx.setOpen(false);
|
|
303
|
+
};
|
|
304
|
+
if (e.pointerType === "touch") {
|
|
305
|
+
if (pendingClick) document.removeEventListener("click", pendingClick);
|
|
306
|
+
pendingClick = () => {
|
|
307
|
+
dismiss();
|
|
308
|
+
pendingClick = null;
|
|
309
|
+
};
|
|
310
|
+
document.addEventListener("click", pendingClick, { once: true });
|
|
311
|
+
} else {
|
|
312
|
+
dismiss();
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const timer = window.setTimeout(() => {
|
|
317
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
318
|
+
attached = true;
|
|
319
|
+
}, 0);
|
|
320
|
+
|
|
321
|
+
onCleanup(() => {
|
|
322
|
+
window.clearTimeout(timer);
|
|
323
|
+
if (attached) document.removeEventListener("pointerdown", onPointerDown, true);
|
|
324
|
+
if (pendingClick) document.removeEventListener("click", pendingClick);
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
const setRef = (node: HTMLDivElement) => {
|
|
329
|
+
el = node;
|
|
330
|
+
ctx.setContentRef(node);
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
onCleanup(() => {
|
|
334
|
+
ctx.setContentRef(undefined);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
const prefersReducedMotion = () =>
|
|
338
|
+
typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
339
|
+
|
|
340
|
+
return (
|
|
341
|
+
<ModalLabelsProvider value={labels}>
|
|
342
|
+
<div
|
|
343
|
+
{...rest}
|
|
344
|
+
ref={setRef}
|
|
345
|
+
role="dialog"
|
|
346
|
+
aria-modal="true"
|
|
347
|
+
aria-label={labels.labelledBy() ? undefined : local.ariaLabel}
|
|
348
|
+
aria-labelledby={labels.labelledBy()}
|
|
349
|
+
aria-describedby={labels.describedBy()}
|
|
350
|
+
tabIndex={-1}
|
|
351
|
+
data-slot="bottom-sheet-content"
|
|
352
|
+
data-sheet-content=""
|
|
353
|
+
data-state={ctx.state()}
|
|
354
|
+
data-reduced-motion={prefersReducedMotion() ? "" : undefined}
|
|
355
|
+
onAnimationEnd={onAnimationEnd}
|
|
356
|
+
onTransitionEnd={onTransitionEnd}
|
|
357
|
+
style={{
|
|
358
|
+
...(typeof local.style === "object" ? local.style : {}),
|
|
359
|
+
"z-index": Z.sheet,
|
|
360
|
+
"--bs-duration": `${TRANSITION_MS}ms`,
|
|
361
|
+
"--bs-ease": EASE,
|
|
362
|
+
"will-change": "transform",
|
|
363
|
+
"touch-action": "pan-y",
|
|
364
|
+
"-webkit-tap-highlight-color": "transparent",
|
|
365
|
+
}}
|
|
366
|
+
class={cn(
|
|
367
|
+
"bs-content",
|
|
368
|
+
`fixed inset-x-0 bottom-0 flex ${MODAL_MAX_H} flex-col rounded-t-xl ${OVERLAY_SURFACE_OPAQUE} outline-none`,
|
|
369
|
+
"after:absolute after:inset-x-0 after:top-full after:h-1/2 after:bg-inherit",
|
|
370
|
+
local.class,
|
|
371
|
+
)}
|
|
372
|
+
>
|
|
373
|
+
{local.children}
|
|
374
|
+
</div>
|
|
375
|
+
</ModalLabelsProvider>
|
|
376
|
+
);
|
|
377
377
|
};
|
|
378
378
|
|
|
379
379
|
const BottomSheetHandle: Component<ComponentProps<"div">> = (props) => {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
380
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
381
|
+
return (
|
|
382
|
+
<div
|
|
383
|
+
data-slot="bottom-sheet-handle"
|
|
384
|
+
data-sheet-handle=""
|
|
385
|
+
aria-hidden="true"
|
|
386
|
+
class={cn(
|
|
387
|
+
"flex h-8 w-full shrink-0 touch-none items-center justify-center select-none",
|
|
388
|
+
local.class,
|
|
389
|
+
)}
|
|
390
|
+
{...rest}
|
|
391
|
+
>
|
|
392
|
+
<div class="bg-muted-foreground/30 h-1.5 w-12 rounded-full" />
|
|
393
|
+
</div>
|
|
394
|
+
);
|
|
395
395
|
};
|
|
396
396
|
|
|
397
397
|
/* Only the Body: a titled, footed sheet is a ResponsiveDialog, which renders
|
|
398
398
|
* its own Header and Footer around this same surface. */
|
|
399
399
|
const {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
400
|
+
Header: BottomSheetHeader,
|
|
401
|
+
Body: BottomSheetBody,
|
|
402
|
+
Footer: BottomSheetFooter,
|
|
403
403
|
} = createModalParts("bottom-sheet");
|
|
404
404
|
|
|
405
405
|
const BottomSheetTitle: Component<ComponentProps<"h2">> = (props) => {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
406
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
407
|
+
const labels = useModalLabels();
|
|
408
|
+
const id = () => rest.id ?? labels?.titleId;
|
|
409
|
+
createRenderEffect(() => labels?.registerTitle(id()));
|
|
410
|
+
return (
|
|
411
|
+
<h2 data-slot="bottom-sheet-title" id={id()} class={cn(MODAL_TITLE, local.class)} {...rest} />
|
|
412
|
+
);
|
|
413
413
|
};
|
|
414
414
|
|
|
415
415
|
const BottomSheetDescription: Component<ComponentProps<"p">> = (props) => {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
416
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
417
|
+
const labels = useModalLabels();
|
|
418
|
+
const id = () => rest.id ?? labels?.descriptionId;
|
|
419
|
+
createRenderEffect(() => labels?.registerDescription(id()));
|
|
420
|
+
return (
|
|
421
|
+
<p
|
|
422
|
+
data-slot="bottom-sheet-description"
|
|
423
|
+
id={id()}
|
|
424
|
+
class={cn(MODAL_DESCRIPTION, local.class)}
|
|
425
|
+
{...rest}
|
|
426
|
+
/>
|
|
427
|
+
);
|
|
428
428
|
};
|
|
429
429
|
|
|
430
430
|
const BottomSheetClose: ParentComponent<SheetButtonProps> = (props) => {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
431
|
+
const [local, rest] = splitProps(props, ["children", "onClick", "as"]);
|
|
432
|
+
const ctx = useBottomSheetContext();
|
|
433
|
+
const component = () => local.as ?? "button";
|
|
434
|
+
return (
|
|
435
|
+
<Dynamic
|
|
436
|
+
component={component()}
|
|
437
|
+
type={component() === "button" ? "button" : undefined}
|
|
438
|
+
data-slot="bottom-sheet-close"
|
|
439
|
+
onClick={(event: MouseEvent & { currentTarget: HTMLButtonElement; target: Element }) => {
|
|
440
|
+
callEventHandler(event, local.onClick);
|
|
441
|
+
ctx.setOpen(false);
|
|
442
|
+
}}
|
|
443
|
+
{...rest}
|
|
444
|
+
>
|
|
445
|
+
{local.children}
|
|
446
|
+
</Dynamic>
|
|
447
|
+
);
|
|
448
448
|
};
|
|
449
449
|
|
|
450
450
|
/** @deprecated the shared modal parts; `BottomSheetHeader` and `BottomSheetFooter` stay as aliases. */
|
|
451
451
|
export {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
452
|
+
BottomSheet,
|
|
453
|
+
BottomSheetBody,
|
|
454
|
+
BottomSheetClose,
|
|
455
|
+
BottomSheetContent,
|
|
456
|
+
BottomSheetDescription,
|
|
457
|
+
BottomSheetFooter,
|
|
458
|
+
BottomSheetHandle,
|
|
459
|
+
BottomSheetHeader,
|
|
460
|
+
BottomSheetOverlay,
|
|
461
|
+
BottomSheetPortal,
|
|
462
|
+
BottomSheetTitle,
|
|
463
|
+
BottomSheetTrigger,
|
|
464
464
|
};
|