@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.
Files changed (146) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/lib/use-is-mobile.d.ts +3 -1
  4. package/dist/solid/index.d.ts +9 -9
  5. package/dist/solid/index.js +5431 -5424
  6. package/dist/solid/sonner.d.ts +1 -0
  7. package/dist/{utils-CMk7R3zM.js → utils-D5blHO4O.js} +624 -622
  8. package/package.json +128 -126
  9. package/scripts/check-gallery.ts +142 -142
  10. package/scripts/check-pack.ts +13 -13
  11. package/scripts/check-structural-classes.ts +20 -20
  12. package/scripts/check-tokens.ts +27 -27
  13. package/scripts/check-ui-drift.mjs +103 -103
  14. package/src/index.ts +75 -80
  15. package/src/lib/alert-tones.ts +41 -41
  16. package/src/lib/anchor-placement.ts +21 -21
  17. package/src/lib/button-variants.ts +28 -28
  18. package/src/lib/card-classes.ts +9 -9
  19. package/src/lib/carousel-classes.ts +14 -14
  20. package/src/lib/glass-tone.ts +11 -11
  21. package/src/lib/input-classes.ts +6 -6
  22. package/src/lib/layers.ts +4 -4
  23. package/src/lib/logo-lockup.ts +8 -8
  24. package/src/lib/menu-classes.ts +2 -2
  25. package/src/lib/motion-classes.ts +8 -8
  26. package/src/lib/motion-window.ts +24 -24
  27. package/src/lib/overlay-classes.ts +6 -6
  28. package/src/lib/pill-classes.ts +3 -3
  29. package/src/lib/position-bar-classes.ts +1 -1
  30. package/src/lib/spotlight-geometry.ts +67 -67
  31. package/src/lib/thumb-classes.ts +2 -2
  32. package/src/lib/tier-badge.ts +16 -16
  33. package/src/lib/use-is-mobile.ts +17 -14
  34. package/src/lib/utils.ts +1 -1
  35. package/src/solid/accordion.tsx +41 -41
  36. package/src/solid/alert-dialog.tsx +95 -95
  37. package/src/solid/alert.tsx +88 -88
  38. package/src/solid/area-picker.tsx +204 -204
  39. package/src/solid/aspect-ratio.tsx +13 -13
  40. package/src/solid/avatar.tsx +27 -27
  41. package/src/solid/badge.tsx +49 -49
  42. package/src/solid/bottom-sheet/arbitration.ts +22 -22
  43. package/src/solid/bottom-sheet/bottom-sheet.tsx +394 -394
  44. package/src/solid/bottom-sheet/drag-controller.ts +201 -201
  45. package/src/solid/bottom-sheet/focus-trap.ts +51 -47
  46. package/src/solid/bottom-sheet/index.ts +12 -12
  47. package/src/solid/bottom-sheet/keyboard.ts +25 -25
  48. package/src/solid/bottom-sheet/scroll-lock.ts +46 -46
  49. package/src/solid/bottom-sheet/state-machine.ts +28 -28
  50. package/src/solid/bottom-sheet/velocity.ts +29 -29
  51. package/src/solid/breadcrumb.tsx +76 -76
  52. package/src/solid/button-group.tsx +46 -46
  53. package/src/solid/button.tsx +19 -19
  54. package/src/solid/card.tsx +67 -67
  55. package/src/solid/carousel.tsx +246 -246
  56. package/src/solid/charts.tsx +253 -253
  57. package/src/solid/checkbox.tsx +51 -51
  58. package/src/solid/collapsible.tsx +22 -22
  59. package/src/solid/color-disc.tsx +213 -213
  60. package/src/solid/color-slider.tsx +81 -81
  61. package/src/solid/color-wheel.tsx +61 -61
  62. package/src/solid/context-menu.tsx +63 -63
  63. package/src/solid/copy-button.tsx +31 -31
  64. package/src/solid/count-pill.tsx +11 -11
  65. package/src/solid/dashboard-preview.tsx +104 -104
  66. package/src/solid/data-table.tsx +228 -228
  67. package/src/solid/dialog-parts.tsx +127 -127
  68. package/src/solid/dialog.tsx +113 -113
  69. package/src/solid/dock-paging.ts +9 -9
  70. package/src/solid/dock.tsx +339 -339
  71. package/src/solid/docked-panel.tsx +35 -35
  72. package/src/solid/dropdown-menu.tsx +77 -77
  73. package/src/solid/empty.tsx +70 -70
  74. package/src/solid/entity-data.ts +38 -38
  75. package/src/solid/entity-selector.tsx +634 -634
  76. package/src/solid/field.tsx +205 -205
  77. package/src/solid/form.tsx +159 -159
  78. package/src/solid/hero-action.tsx +85 -85
  79. package/src/solid/hover-card.tsx +11 -11
  80. package/src/solid/icon-picker.tsx +401 -401
  81. package/src/solid/icon.tsx +101 -78
  82. package/src/solid/image-picker.tsx +416 -414
  83. package/src/solid/index.ts +265 -304
  84. package/src/solid/input-group.tsx +123 -123
  85. package/src/solid/input-otp.tsx +143 -143
  86. package/src/solid/input.tsx +4 -4
  87. package/src/solid/item.tsx +130 -130
  88. package/src/solid/kbd.tsx +20 -20
  89. package/src/solid/label.tsx +12 -12
  90. package/src/solid/list-reorder.ts +122 -122
  91. package/src/solid/logo.tsx +60 -60
  92. package/src/solid/media-copy.ts +21 -21
  93. package/src/solid/media-store.ts +56 -56
  94. package/src/solid/media-tile.tsx +85 -85
  95. package/src/solid/menu-parts.tsx +164 -164
  96. package/src/solid/number-field.tsx +56 -56
  97. package/src/solid/option-card.tsx +164 -164
  98. package/src/solid/ornament.tsx +43 -43
  99. package/src/solid/overlay.tsx +4 -4
  100. package/src/solid/page-header.tsx +75 -75
  101. package/src/solid/pagination.tsx +80 -80
  102. package/src/solid/password-input.tsx +51 -51
  103. package/src/solid/picker-row.tsx +83 -83
  104. package/src/solid/picker-search.tsx +65 -63
  105. package/src/solid/picker-trigger.tsx +59 -57
  106. package/src/solid/popover.tsx +54 -54
  107. package/src/solid/preview-tile.tsx +67 -67
  108. package/src/solid/progress.tsx +21 -21
  109. package/src/solid/radio-group.tsx +51 -51
  110. package/src/solid/resizable.tsx +128 -128
  111. package/src/solid/responsive-dialog.tsx +134 -134
  112. package/src/solid/schema-form.tsx +743 -743
  113. package/src/solid/scope-indicator.tsx +5 -5
  114. package/src/solid/scroll-area.tsx +16 -16
  115. package/src/solid/section-card.tsx +281 -281
  116. package/src/solid/select.tsx +101 -101
  117. package/src/solid/separator.tsx +25 -25
  118. package/src/solid/settings-row.tsx +122 -122
  119. package/src/solid/sheet.tsx +96 -96
  120. package/src/solid/skeleton.tsx +8 -8
  121. package/src/solid/slider.tsx +132 -132
  122. package/src/solid/sliding-indicator.tsx +280 -265
  123. package/src/solid/sonner.tsx +165 -164
  124. package/src/solid/spinner.tsx +12 -12
  125. package/src/solid/spotlight.tsx +140 -140
  126. package/src/solid/step-indicator.tsx +18 -18
  127. package/src/solid/swatch-picker.tsx +38 -38
  128. package/src/solid/switch.tsx +52 -52
  129. package/src/solid/table.tsx +63 -63
  130. package/src/solid/tabs.tsx +93 -93
  131. package/src/solid/textarea.tsx +8 -8
  132. package/src/solid/toggle-group.tsx +83 -83
  133. package/src/solid/toggle.tsx +33 -33
  134. package/src/solid/tooltip.tsx +16 -16
  135. package/src/solid/widget-card.tsx +90 -90
  136. package/src/solid/widget-identity.tsx +99 -99
  137. package/src/solid/widget-trust-badge.tsx +20 -20
  138. package/src/styles/globals.css +316 -319
  139. package/src/styles/theme.css +448 -448
  140. package/src/tokens/hex.ts +29 -29
  141. package/src/tokens/material.ts +75 -75
  142. package/src/tokens/presets.ts +303 -303
  143. package/src/tokens/readability.ts +32 -32
  144. package/src/tokens/theme-colors.ts +95 -95
  145. package/src/tokens/theme-css.ts +22 -22
  146. 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
- 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,
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
- sm: "max-w-sm",
39
- md: "max-w-md",
40
- lg: "max-w-lg",
41
- xl: "max-w-3xl",
42
- full: "max-w-5xl",
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
- sm: MODAL_CENTER,
53
- md: MODAL_CENTER,
54
- lg: MODAL_CENTER,
55
- xl: MODAL_HANG,
56
- full: MODAL_HANG,
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
- "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";
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
- "gh-stagger flex shrink-0 flex-col-reverse gap-2 px-6 pt-3 pb-6 sm:flex-row sm:justify-end";
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
- /** 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;
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
- Header: Component<ModalHeaderProps>;
111
- Body: Component<ModalBodyProps>;
112
- Footer: Component<ComponentProps<"div">>;
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
- 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 };
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
- event: E & { currentTarget: T; target: Element },
170
- handler: JSX.EventHandlerUnion<T, E> | undefined,
169
+ event: E & { currentTarget: T; target: Element },
170
+ handler: JSX.EventHandlerUnion<T, E> | undefined,
171
171
  ): void {
172
- if (!handler) return;
173
- if (typeof handler === "function") handler(event);
174
- else handler[0](handler[1], event);
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
- 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
- };
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
- onMount(acquireScrollLock);
205
- onCleanup(releaseScrollLock);
206
- return null;
204
+ onMount(acquireScrollLock);
205
+ onCleanup(releaseScrollLock);
206
+ return null;
207
207
  };
208
208
 
209
209
  export interface ModalLabels {
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;
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
- 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
- };
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
- return useContext(ModalLabelsContext);
245
+ return useContext(ModalLabelsContext);
246
246
  }
@@ -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
- type Component,
5
- type ComponentProps,
6
- createEffect,
7
- createSignal,
8
- onCleanup,
9
- type ParentComponent,
10
- splitProps,
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
- 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,
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
- <DialogPrimitive {...props} preventScroll={false} />
34
+ <DialogPrimitive {...props} preventScroll={false} />
35
35
  );
36
36
 
37
37
  const DialogTrigger: Component<ComponentProps<typeof DialogPrimitive.Trigger>> = (props) => (
38
- <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
38
+ <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
39
39
  );
40
40
 
41
41
  type DialogCloseProps = ModalDismissProps &
42
- Partial<Pick<VariantProps<typeof buttonVariants>, "variant" | "size">>;
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
- 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
- );
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
- 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;
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
- sm: 384,
76
- md: 448,
77
- lg: 512,
78
- xl: 768,
79
- full: 1024,
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
- 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
- );
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
- 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
- );
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
- props,
141
+ props,
142
142
  ) => {
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
- );
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
- Dialog,
155
- DialogBody,
156
- DialogClose,
157
- DialogContent,
158
- DialogDescription,
159
- DialogFooter,
160
- DialogHeader,
161
- DialogTitle,
162
- DialogTrigger,
154
+ Dialog,
155
+ DialogBody,
156
+ DialogClose,
157
+ DialogContent,
158
+ DialogDescription,
159
+ DialogFooter,
160
+ DialogHeader,
161
+ DialogTitle,
162
+ DialogTrigger,
163
163
  };
@@ -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
- if (viewport <= 0) return 1;
6
- return Math.max(1, Math.ceil((scrollWidth - 1) / viewport));
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
- if (viewport <= 0) return 0;
12
- return Math.round(scrollLeft / viewport);
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
- const max = Math.max(0, scrollWidth - viewport);
18
- return Math.min(max, Math.max(0, page * viewport));
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
- 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);
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
  }