@glasshome/ui 1.21.1 → 1.21.2
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/{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 +164 -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,20 +1,20 @@
|
|
|
1
1
|
import { Button as KobalteButton } from "@kobalte/core/button";
|
|
2
2
|
import { useDialogContext } from "@kobalte/core/dialog";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
type Accessor,
|
|
5
|
+
type Component,
|
|
6
|
+
type ComponentProps,
|
|
7
|
+
createContext,
|
|
8
|
+
createSignal,
|
|
9
|
+
createUniqueId,
|
|
10
|
+
type JSX,
|
|
11
|
+
onCleanup,
|
|
12
|
+
onMount,
|
|
13
|
+
type ParentComponent,
|
|
14
|
+
Show,
|
|
15
|
+
splitProps,
|
|
16
|
+
useContext,
|
|
17
|
+
type ValidComponent,
|
|
18
18
|
} from "solid-js";
|
|
19
19
|
import { Dynamic } from "solid-js/web";
|
|
20
20
|
import { Z_CLASS } from "../lib/layers.js";
|
|
@@ -35,11 +35,11 @@ export type ModalSize = "sm" | "md" | "lg" | "xl" | "full";
|
|
|
35
35
|
export const MODAL_MAX_H = "[--modal-max-h:85dvh] max-h-[var(--modal-max-h)]";
|
|
36
36
|
|
|
37
37
|
export const MODAL_WIDTH: Record<ModalSize, string> = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
sm: "max-w-sm",
|
|
39
|
+
md: "max-w-md",
|
|
40
|
+
lg: "max-w-lg",
|
|
41
|
+
xl: "max-w-3xl",
|
|
42
|
+
full: "max-w-5xl",
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
/* Where the panel sits. Up to lg it centres; xl and full (the workbench
|
|
@@ -49,11 +49,11 @@ export const MODAL_WIDTH: Record<ModalSize, string> = {
|
|
|
49
49
|
const MODAL_CENTER = "top-1/2 -translate-y-1/2";
|
|
50
50
|
const MODAL_HANG = "top-[calc((100dvh-var(--modal-max-h))/2)] translate-y-0";
|
|
51
51
|
export const MODAL_ANCHOR: Record<ModalSize, string> = {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
sm: MODAL_CENTER,
|
|
53
|
+
md: MODAL_CENTER,
|
|
54
|
+
lg: MODAL_CENTER,
|
|
55
|
+
xl: MODAL_HANG,
|
|
56
|
+
full: MODAL_HANG,
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
/* The panel: it clips, it never scrolls, and it carries no padding. Every inset
|
|
@@ -85,21 +85,21 @@ const MODAL_HEADER_ACTION = "flex shrink-0 items-center gap-2";
|
|
|
85
85
|
* - The reserved scrollbar lives inside the right inset, so the content column
|
|
86
86
|
* ends where the Header's and Footer's do. */
|
|
87
87
|
const MODAL_BODY =
|
|
88
|
-
|
|
88
|
+
"gh-scroll gh-stagger flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto overscroll-contain [touch-action:pan-y_pinch-zoom] [scrollbar-gutter:stable] pl-6 pr-[calc(var(--spacing)*6-var(--scrollbar-w))] pt-6 pb-6 [[data-slot$='-header']~&]:pt-3 [&:has(~[data-slot$='-footer'])]:pb-3";
|
|
89
89
|
|
|
90
90
|
const MODAL_FOOTER =
|
|
91
|
-
|
|
91
|
+
"gh-stagger flex shrink-0 flex-col-reverse gap-2 px-6 pt-3 pb-6 sm:flex-row sm:justify-end";
|
|
92
92
|
|
|
93
93
|
export const MODAL_TITLE = "font-semibold text-foreground text-lg leading-none tracking-tight";
|
|
94
94
|
export const MODAL_DESCRIPTION = "text-muted-foreground text-sm";
|
|
95
95
|
|
|
96
96
|
type ModalHeaderProps = ComponentProps<"div"> & {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
/** Avatar or icon, rendered ahead of the title column. */
|
|
98
|
+
media?: JSX.Element;
|
|
99
|
+
action?: JSX.Element;
|
|
100
|
+
/** Lets a wide action (a tab row) drop below the title instead of squeezing
|
|
101
|
+
* it; a phone has no room for both on one line. */
|
|
102
|
+
wrap?: boolean;
|
|
103
103
|
};
|
|
104
104
|
|
|
105
105
|
/** `as="form"` makes the scroll container the form, so a footer submit button
|
|
@@ -107,71 +107,71 @@ type ModalHeaderProps = ComponentProps<"div"> & {
|
|
|
107
107
|
type ModalBodyProps = ComponentProps<"div"> & { as?: ValidComponent };
|
|
108
108
|
|
|
109
109
|
export interface ModalParts {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
Header: Component<ModalHeaderProps>;
|
|
111
|
+
Body: Component<ModalBodyProps>;
|
|
112
|
+
Footer: Component<ComponentProps<"div">>;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
export function createModalParts(slot: string): ModalParts {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
116
|
+
const Header: Component<ModalHeaderProps> = (props) => {
|
|
117
|
+
const [local, rest] = splitProps(props, ["class", "media", "action", "wrap", "children"]);
|
|
118
|
+
return (
|
|
119
|
+
<div
|
|
120
|
+
data-slot={`${slot}-header`}
|
|
121
|
+
class={cn(MODAL_HEADER, local.wrap && "flex-wrap", local.class)}
|
|
122
|
+
{...rest}
|
|
123
|
+
>
|
|
124
|
+
<Show when={local.media}>
|
|
125
|
+
<div data-slot={`${slot}-header-media`} class={MODAL_HEADER_MEDIA}>
|
|
126
|
+
{local.media}
|
|
127
|
+
</div>
|
|
128
|
+
</Show>
|
|
129
|
+
<div data-slot={`${slot}-header-text`} class={MODAL_HEADER_TEXT}>
|
|
130
|
+
{local.children}
|
|
131
|
+
</div>
|
|
132
|
+
<Show when={local.action}>
|
|
133
|
+
<div data-slot={`${slot}-header-action`} class={MODAL_HEADER_ACTION}>
|
|
134
|
+
{local.action}
|
|
135
|
+
</div>
|
|
136
|
+
</Show>
|
|
137
|
+
</div>
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/* data-sheet-scroll is the bottom sheet's drag arbitration marker: a Body
|
|
142
|
+
* inside a sheet must yield the gesture to its own scroll, whichever family
|
|
143
|
+
* rendered it. */
|
|
144
|
+
const Body: Component<ModalBodyProps> = (props) => {
|
|
145
|
+
const [local, rest] = splitProps(props, ["class", "as"]);
|
|
146
|
+
return (
|
|
147
|
+
<Dynamic
|
|
148
|
+
component={local.as ?? "div"}
|
|
149
|
+
data-slot={`${slot}-body`}
|
|
150
|
+
data-sheet-scroll=""
|
|
151
|
+
class={cn(MODAL_BODY, local.class)}
|
|
152
|
+
{...rest}
|
|
153
|
+
/>
|
|
154
|
+
);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const Footer: Component<ComponentProps<"div">> = (props) => {
|
|
158
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
159
|
+
return <div data-slot={`${slot}-footer`} class={cn(MODAL_FOOTER, local.class)} {...rest} />;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
return { Header, Body, Footer };
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
/** Solid's handler prop is a union: a plain function, or the bound
|
|
166
166
|
* `[handler, data]` form that calls `handler(data, event)`. A wrapper that
|
|
167
167
|
* only checks for a function silently drops the bound one. */
|
|
168
168
|
export function callEventHandler<T, E extends Event>(
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
event: E & { currentTarget: T; target: Element },
|
|
170
|
+
handler: JSX.EventHandlerUnion<T, E> | undefined,
|
|
171
171
|
): void {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
if (!handler) return;
|
|
173
|
+
if (typeof handler === "function") handler(event);
|
|
174
|
+
else handler[0](handler[1], event);
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
export type ModalDismissProps = ComponentProps<typeof KobalteButton>;
|
|
@@ -182,37 +182,37 @@ export type ModalDismissProps = ComponentProps<typeof KobalteButton>;
|
|
|
182
182
|
* when the caller passes one. AlertDialog is built on the Dialog context, so
|
|
183
183
|
* one factory serves both families. */
|
|
184
184
|
export function createModalDismiss(slot: string): ParentComponent<ModalDismissProps> {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
185
|
+
return (props) => {
|
|
186
|
+
const [local, rest] = splitProps(props, ["onClick"]);
|
|
187
|
+
const context = useDialogContext();
|
|
188
|
+
return (
|
|
189
|
+
<KobalteButton
|
|
190
|
+
data-slot={slot}
|
|
191
|
+
onClick={(event: MouseEvent & { currentTarget: HTMLButtonElement; target: Element }) => {
|
|
192
|
+
callEventHandler(event, local.onClick);
|
|
193
|
+
context.close();
|
|
194
|
+
}}
|
|
195
|
+
{...rest}
|
|
196
|
+
/>
|
|
197
|
+
);
|
|
198
|
+
};
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
/** Renderless. Mounted inside a portal that exists only while the modal is
|
|
202
202
|
* open, so the refcounted page lock follows the modal's real lifetime. */
|
|
203
203
|
export const ModalScrollLock: Component = () => {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
onMount(acquireScrollLock);
|
|
205
|
+
onCleanup(releaseScrollLock);
|
|
206
|
+
return null;
|
|
207
207
|
};
|
|
208
208
|
|
|
209
209
|
export interface ModalLabels {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
210
|
+
titleId: string;
|
|
211
|
+
descriptionId: string;
|
|
212
|
+
labelledBy: Accessor<string | undefined>;
|
|
213
|
+
describedBy: Accessor<string | undefined>;
|
|
214
|
+
registerTitle: (id: string | undefined) => void;
|
|
215
|
+
registerDescription: (id: string | undefined) => void;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
const ModalLabelsContext = createContext<ModalLabels>();
|
|
@@ -221,26 +221,26 @@ const ModalLabelsContext = createContext<ModalLabels>();
|
|
|
221
221
|
* surfaces (BottomSheet) wire them through this. The part registers the id it
|
|
222
222
|
* actually rendered, so a caller's own `id` still labels the panel. */
|
|
223
223
|
export function createModalLabels(): ModalLabels {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
224
|
+
const titleId = createUniqueId();
|
|
225
|
+
const descriptionId = createUniqueId();
|
|
226
|
+
const [labelledBy, setLabelledBy] = createSignal<string>();
|
|
227
|
+
const [describedBy, setDescribedBy] = createSignal<string>();
|
|
228
|
+
const register = (set: (id: string | undefined) => void, id: string | undefined) => {
|
|
229
|
+
set(id);
|
|
230
|
+
onCleanup(() => set(undefined));
|
|
231
|
+
};
|
|
232
|
+
return {
|
|
233
|
+
titleId,
|
|
234
|
+
descriptionId,
|
|
235
|
+
labelledBy,
|
|
236
|
+
describedBy,
|
|
237
|
+
registerTitle: (id) => register(setLabelledBy, id),
|
|
238
|
+
registerDescription: (id) => register(setDescribedBy, id),
|
|
239
|
+
};
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
export const ModalLabelsProvider = ModalLabelsContext.Provider;
|
|
243
243
|
|
|
244
244
|
export function useModalLabels(): ModalLabels | undefined {
|
|
245
|
-
|
|
245
|
+
return useContext(ModalLabelsContext);
|
|
246
246
|
}
|
package/src/solid/dialog.tsx
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
import { Dialog as DialogPrimitive, useDialogContext } from "@kobalte/core/dialog";
|
|
2
2
|
import type { VariantProps } from "cva";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
type Component,
|
|
5
|
+
type ComponentProps,
|
|
6
|
+
createEffect,
|
|
7
|
+
createSignal,
|
|
8
|
+
onCleanup,
|
|
9
|
+
type ParentComponent,
|
|
10
|
+
splitProps,
|
|
11
11
|
} from "solid-js";
|
|
12
12
|
import { overAnchor } from "../lib/anchor-placement.js";
|
|
13
13
|
import { buttonVariants } from "../lib/button-variants.js";
|
|
14
14
|
import { cn } from "../lib/utils.js";
|
|
15
15
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
ANCHORED_PANEL,
|
|
17
|
+
createModalDismiss,
|
|
18
|
+
createModalParts,
|
|
19
|
+
MODAL_ANCHOR,
|
|
20
|
+
MODAL_DESCRIPTION,
|
|
21
|
+
MODAL_PANEL,
|
|
22
|
+
MODAL_SCRIM,
|
|
23
|
+
MODAL_TITLE,
|
|
24
|
+
MODAL_WIDTH,
|
|
25
|
+
type ModalDismissProps,
|
|
26
|
+
ModalScrollLock,
|
|
27
|
+
type ModalSize,
|
|
28
28
|
} from "./dialog-parts.js";
|
|
29
29
|
|
|
30
30
|
/* Kobalte's own scroll lock is off everywhere: one refcounted lock
|
|
31
31
|
* (bottom-sheet/scroll-lock.ts) serves every modal family, so a nested modal
|
|
32
32
|
* cannot release the page early. */
|
|
33
33
|
const Dialog: ParentComponent<ComponentProps<typeof DialogPrimitive>> = (props) => (
|
|
34
|
-
|
|
34
|
+
<DialogPrimitive {...props} preventScroll={false} />
|
|
35
35
|
);
|
|
36
36
|
|
|
37
37
|
const DialogTrigger: Component<ComponentProps<typeof DialogPrimitive.Trigger>> = (props) => (
|
|
38
|
-
|
|
38
|
+
<DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
|
|
39
39
|
);
|
|
40
40
|
|
|
41
41
|
type DialogCloseProps = ModalDismissProps &
|
|
42
|
-
|
|
42
|
+
Partial<Pick<VariantProps<typeof buttonVariants>, "variant" | "size">>;
|
|
43
43
|
|
|
44
44
|
const DialogDismiss = createModalDismiss("dialog-close");
|
|
45
45
|
|
|
@@ -47,117 +47,117 @@ const DialogDismiss = createModalDismiss("dialog-close");
|
|
|
47
47
|
* never for `Button`: two buttonVariants() calls leave tone knobs side by side
|
|
48
48
|
* and the later stylesheet rule wins. */
|
|
49
49
|
const DialogClose: ParentComponent<DialogCloseProps> = (props) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
50
|
+
const [local, rest] = splitProps(props, ["class", "variant", "size", "children"]);
|
|
51
|
+
return (
|
|
52
|
+
<DialogDismiss
|
|
53
|
+
class={cn(
|
|
54
|
+
buttonVariants({ variant: local.variant ?? "outline", size: local.size }),
|
|
55
|
+
local.class,
|
|
56
|
+
)}
|
|
57
|
+
{...rest}
|
|
58
|
+
>
|
|
59
|
+
{local.children ?? "Close"}
|
|
60
|
+
</DialogDismiss>
|
|
61
|
+
);
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
type DialogContentProps = ComponentProps<typeof DialogPrimitive.Content> & {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
size?: ModalSize;
|
|
66
|
+
/** Names a panel that has no `DialogTitle`. A registered Title wins. */
|
|
67
|
+
ariaLabel?: string;
|
|
68
|
+
/** Opens the panel out of this element (the tile it came from): it grows from the element's box
|
|
69
|
+
* over it instead of appearing centred, and closes back into it. */
|
|
70
|
+
anchor?: HTMLElement;
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
/* Pixel widths of the sizes an anchored panel keeps (Tailwind's max-w-sm/md/lg/3xl/5xl). */
|
|
74
74
|
const ANCHORED_WIDTH: Record<ModalSize, number> = {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
sm: 384,
|
|
76
|
+
md: 448,
|
|
77
|
+
lg: 512,
|
|
78
|
+
xl: 768,
|
|
79
|
+
full: 1024,
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
const DialogContent: ParentComponent<DialogContentProps> = (props) => {
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
83
|
+
const [local, others] = splitProps(props, [
|
|
84
|
+
"class",
|
|
85
|
+
"children",
|
|
86
|
+
"size",
|
|
87
|
+
"ariaLabel",
|
|
88
|
+
"anchor",
|
|
89
|
+
"style",
|
|
90
|
+
]);
|
|
91
|
+
const context = useDialogContext();
|
|
92
|
+
const [viewport, setViewport] = createSignal(0);
|
|
93
|
+
createEffect(() => {
|
|
94
|
+
if (!local.anchor || !context.isOpen()) return;
|
|
95
|
+
const measure = () => setViewport((n) => n + 1);
|
|
96
|
+
window.addEventListener("resize", measure);
|
|
97
|
+
onCleanup(() => window.removeEventListener("resize", measure));
|
|
98
|
+
});
|
|
99
|
+
const placement = () => {
|
|
100
|
+
viewport();
|
|
101
|
+
const a = local.anchor;
|
|
102
|
+
return a ? overAnchor(a, ANCHORED_WIDTH[local.size ?? "lg"]) : undefined;
|
|
103
|
+
};
|
|
104
|
+
return (
|
|
105
|
+
<DialogPrimitive.Portal>
|
|
106
|
+
<ModalScrollLock />
|
|
107
|
+
<DialogPrimitive.Overlay data-slot="dialog-overlay" class={MODAL_SCRIM} />
|
|
108
|
+
<DialogPrimitive.Content
|
|
109
|
+
data-slot="dialog-content"
|
|
110
|
+
role="dialog"
|
|
111
|
+
aria-label={context.titleId() ? undefined : local.ariaLabel}
|
|
112
|
+
class={cn(
|
|
113
|
+
local.anchor ? ANCHORED_PANEL : MODAL_PANEL,
|
|
114
|
+
!local.anchor && MODAL_WIDTH[local.size ?? "lg"],
|
|
115
|
+
!local.anchor && MODAL_ANCHOR[local.size ?? "lg"],
|
|
116
|
+
local.class,
|
|
117
|
+
)}
|
|
118
|
+
style={{ ...(typeof local.style === "object" ? local.style : {}), ...placement() }}
|
|
119
|
+
{...others}
|
|
120
|
+
>
|
|
121
|
+
{local.children}
|
|
122
|
+
</DialogPrimitive.Content>
|
|
123
|
+
</DialogPrimitive.Portal>
|
|
124
|
+
);
|
|
125
125
|
};
|
|
126
126
|
|
|
127
127
|
const { Header: DialogHeader, Body: DialogBody, Footer: DialogFooter } = createModalParts("dialog");
|
|
128
128
|
|
|
129
129
|
const DialogTitle: Component<ComponentProps<typeof DialogPrimitive.Title>> = (props) => {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
130
|
+
const [local, others] = splitProps(props, ["class"]);
|
|
131
|
+
return (
|
|
132
|
+
<DialogPrimitive.Title
|
|
133
|
+
data-slot="dialog-title"
|
|
134
|
+
class={cn(MODAL_TITLE, local.class)}
|
|
135
|
+
{...others}
|
|
136
|
+
/>
|
|
137
|
+
);
|
|
138
138
|
};
|
|
139
139
|
|
|
140
140
|
const DialogDescription: Component<ComponentProps<typeof DialogPrimitive.Description>> = (
|
|
141
|
-
|
|
141
|
+
props,
|
|
142
142
|
) => {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
143
|
+
const [local, others] = splitProps(props, ["class"]);
|
|
144
|
+
return (
|
|
145
|
+
<DialogPrimitive.Description
|
|
146
|
+
data-slot="dialog-description"
|
|
147
|
+
class={cn(MODAL_DESCRIPTION, local.class)}
|
|
148
|
+
{...others}
|
|
149
|
+
/>
|
|
150
|
+
);
|
|
151
151
|
};
|
|
152
152
|
|
|
153
153
|
export {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
154
|
+
Dialog,
|
|
155
|
+
DialogBody,
|
|
156
|
+
DialogClose,
|
|
157
|
+
DialogContent,
|
|
158
|
+
DialogDescription,
|
|
159
|
+
DialogFooter,
|
|
160
|
+
DialogHeader,
|
|
161
|
+
DialogTitle,
|
|
162
|
+
DialogTrigger,
|
|
163
163
|
};
|
package/src/solid/dock-paging.ts
CHANGED
|
@@ -2,25 +2,25 @@
|
|
|
2
2
|
* The tolerance keeps a strip a sub-pixel over its viewport on one page: both
|
|
3
3
|
* numbers are rounded reads of the same box. */
|
|
4
4
|
export function pageCount(scrollWidth: number, viewport: number): number {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
if (viewport <= 0) return 1;
|
|
6
|
+
return Math.max(1, Math.ceil((scrollWidth - 1) / viewport));
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
/** The page a scroll position sits on, counting a half-page as turned. */
|
|
10
10
|
export function pageOf(scrollLeft: number, viewport: number): number {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
if (viewport <= 0) return 0;
|
|
12
|
+
return Math.round(scrollLeft / viewport);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/** Where to scroll for a page, clamped to the end of the strip. */
|
|
16
16
|
export function pageOffset(page: number, viewport: number, scrollWidth: number): number {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const max = Math.max(0, scrollWidth - viewport);
|
|
18
|
+
return Math.min(max, Math.max(0, page * viewport));
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/** The strip shows whole items: a half-drawn icon at the edge reads as damage, not as a hint. */
|
|
22
22
|
export function stripWidth(available: number, itemWidth: number, gap: number): number {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
if (available <= 0 || itemWidth <= 0) return available;
|
|
24
|
+
const count = Math.max(1, Math.floor((available + gap) / (itemWidth + gap)));
|
|
25
|
+
return Math.min(available, count * itemWidth + (count - 1) * gap);
|
|
26
26
|
}
|