@nswds/ui 9.4.0 → 9.6.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/components/alert-dialog.js +2 -2
- package/dist/components/alert-dialog.js.map +1 -1
- package/dist/components/button-group.d.ts +2 -2
- package/dist/components/button-group.js.map +1 -1
- package/dist/components/combobox.js +2 -2
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/component-preview.d.ts +153 -0
- package/dist/components/component-preview.js +690 -0
- package/dist/components/component-preview.js.map +1 -0
- package/dist/components/dialog.js +2 -2
- package/dist/components/dialog.js.map +1 -1
- package/dist/components/drawer.js +2 -2
- package/dist/components/drawer.js.map +1 -1
- package/dist/components/dropdown-menu.js +2 -2
- package/dist/components/dropdown-menu.js.map +1 -1
- package/dist/components/hover-card.js +2 -2
- package/dist/components/hover-card.js.map +1 -1
- package/dist/components/navigation-menu.js +2 -1
- package/dist/components/navigation-menu.js.map +1 -1
- package/dist/components/popover.js +2 -2
- package/dist/components/popover.js.map +1 -1
- package/dist/components/select.js +2 -2
- package/dist/components/select.js.map +1 -1
- package/dist/components/sheet.js +2 -2
- package/dist/components/sheet.js.map +1 -1
- package/dist/components/site-search.js +2 -2
- package/dist/components/site-search.js.map +1 -1
- package/dist/components/tooltip.js +2 -2
- package/dist/components/tooltip.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/lib/portal-boundary.d.ts +47 -0
- package/dist/lib/portal-boundary.js +24 -0
- package/dist/lib/portal-boundary.js.map +1 -0
- package/dist/lib/preview-theme.d.ts +167 -0
- package/dist/lib/preview-theme.js +176 -0
- package/dist/lib/preview-theme.js.map +1 -0
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/styles/theme.css +12 -2
|
@@ -0,0 +1,690 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { Popover as Popover$1 } from '@base-ui/react/popover';
|
|
4
|
+
import { Radio } from '@base-ui/react/radio';
|
|
5
|
+
import { RadioGroup } from '@base-ui/react/radio-group';
|
|
6
|
+
import { Slider } from '@base-ui/react/slider';
|
|
7
|
+
import { Toggle } from '@base-ui/react/toggle';
|
|
8
|
+
import { ToggleGroup } from '@base-ui/react/toggle-group';
|
|
9
|
+
import * as React from 'react';
|
|
10
|
+
import { ButtonGroup } from '../components/button-group.js';
|
|
11
|
+
import { Button } from '../components/button.js';
|
|
12
|
+
import { CodeBlockCopyButton, CodeBlock, CodeBlockContent, CodeBlockFooter } from '../components/code-block.js';
|
|
13
|
+
import { Popover, PopoverTrigger, PopoverContent } from '../components/popover.js';
|
|
14
|
+
import { Tabs, TabsList, TabsTrigger, TabsContent } from '../components/tabs.js';
|
|
15
|
+
import { IconCheck } from '../icons/check.js';
|
|
16
|
+
import { IconContrast } from '../icons/contrast.js';
|
|
17
|
+
import { IconDarkMode } from '../icons/dark-mode.js';
|
|
18
|
+
import { IconDesktopWindows } from '../icons/desktop-windows.js';
|
|
19
|
+
import { IconDragIndicator } from '../icons/drag-indicator.js';
|
|
20
|
+
import { IconExpandMore } from '../icons/expand-more.js';
|
|
21
|
+
import { IconLightMode } from '../icons/light-mode.js';
|
|
22
|
+
import { IconPalette } from '../icons/palette.js';
|
|
23
|
+
import { IconSmartphone } from '../icons/smartphone.js';
|
|
24
|
+
import { IconTabletMac } from '../icons/tablet-mac.js';
|
|
25
|
+
import { PortalScopeContext } from '../lib/portal-boundary.js';
|
|
26
|
+
import { ABORIGINAL_PALETTES, BRAND_PALETTES, previewThemeStyle, PALETTE_STEPS } from '../lib/preview-theme.js';
|
|
27
|
+
import { cn } from '../lib/utils.js';
|
|
28
|
+
|
|
29
|
+
const MIN_WIDTH = 280;
|
|
30
|
+
const PHONE_WIDTH = 375;
|
|
31
|
+
const TABLET_WIDTH = 768;
|
|
32
|
+
const PALETTES = {
|
|
33
|
+
brand: BRAND_PALETTES,
|
|
34
|
+
aboriginal: ABORIGINAL_PALETTES
|
|
35
|
+
};
|
|
36
|
+
const setOf = (palette) => palette.startsWith("aboriginal-") ? "aboriginal" : "brand";
|
|
37
|
+
function colorPair(primary, accent) {
|
|
38
|
+
const anchor = primary ?? accent;
|
|
39
|
+
if (!anchor) return { primary: void 0, accent: void 0 };
|
|
40
|
+
const palettes = PALETTES[setOf(anchor)];
|
|
41
|
+
const first = (not) => palettes.find((palette) => palette !== not);
|
|
42
|
+
const resolvedPrimary = primary ?? first(accent);
|
|
43
|
+
const fits = accent && palettes.includes(accent) && accent !== resolvedPrimary;
|
|
44
|
+
return { primary: resolvedPrimary, accent: fits ? accent : first(resolvedPrimary) };
|
|
45
|
+
}
|
|
46
|
+
const paletteName = (palette) => {
|
|
47
|
+
const name = palette.replace("aboriginal-", "");
|
|
48
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
49
|
+
};
|
|
50
|
+
const ComponentPreviewContext = React.createContext(null);
|
|
51
|
+
function useComponentPreview(part) {
|
|
52
|
+
const context = React.useContext(ComponentPreviewContext);
|
|
53
|
+
if (!context) throw new Error(`[nswds/ui] ${part} must be used inside a ComponentPreview.`);
|
|
54
|
+
return context;
|
|
55
|
+
}
|
|
56
|
+
function ComponentPreview({
|
|
57
|
+
className,
|
|
58
|
+
defaultTheme = "both",
|
|
59
|
+
defaultWidth,
|
|
60
|
+
defaultDirection = "ltr",
|
|
61
|
+
defaultPrimary,
|
|
62
|
+
defaultAccent,
|
|
63
|
+
...props
|
|
64
|
+
}) {
|
|
65
|
+
const [theme, setTheme] = React.useState(defaultTheme);
|
|
66
|
+
const [width, setWidth] = React.useState(
|
|
67
|
+
() => typeof defaultWidth === "number" && Number.isFinite(defaultWidth) ? Math.max(MIN_WIDTH, defaultWidth) : null
|
|
68
|
+
);
|
|
69
|
+
const [measuredWidth, setMeasuredWidth] = React.useState(null);
|
|
70
|
+
const [direction, setDirection] = React.useState(defaultDirection);
|
|
71
|
+
const [colors, setColorState] = React.useState(() => colorPair(defaultPrimary, defaultAccent));
|
|
72
|
+
const setColors = React.useCallback(
|
|
73
|
+
(primary, accent) => setColorState({ primary, accent }),
|
|
74
|
+
[]
|
|
75
|
+
);
|
|
76
|
+
const context = React.useMemo(
|
|
77
|
+
() => ({
|
|
78
|
+
theme,
|
|
79
|
+
setTheme,
|
|
80
|
+
width,
|
|
81
|
+
setWidth,
|
|
82
|
+
measuredWidth,
|
|
83
|
+
setMeasuredWidth,
|
|
84
|
+
direction,
|
|
85
|
+
setDirection,
|
|
86
|
+
primary: colors.primary,
|
|
87
|
+
accent: colors.accent,
|
|
88
|
+
setColors
|
|
89
|
+
}),
|
|
90
|
+
[theme, width, measuredWidth, direction, colors, setColors]
|
|
91
|
+
);
|
|
92
|
+
return /* @__PURE__ */ jsx(ComponentPreviewContext.Provider, { value: context, children: /* @__PURE__ */ jsx(
|
|
93
|
+
"div",
|
|
94
|
+
{
|
|
95
|
+
"data-slot": "component-preview",
|
|
96
|
+
className: cn(
|
|
97
|
+
"@container/component-preview flex w-full min-w-0 flex-col overflow-hidden rounded-md border border-border bg-background text-base text-foreground",
|
|
98
|
+
className
|
|
99
|
+
),
|
|
100
|
+
...props,
|
|
101
|
+
"data-theme-mode": theme
|
|
102
|
+
}
|
|
103
|
+
) });
|
|
104
|
+
}
|
|
105
|
+
function ComponentPreviewHeader({ className, ...props }) {
|
|
106
|
+
return /* @__PURE__ */ jsx(
|
|
107
|
+
"div",
|
|
108
|
+
{
|
|
109
|
+
"data-slot": "component-preview-header",
|
|
110
|
+
className: cn(
|
|
111
|
+
"flex min-w-0 flex-wrap items-center gap-x-4 gap-y-2 bg-primary-800 py-3 pe-4 text-white @max-3xl/component-preview:ps-4 @3xl/component-preview:ps-6 dark:bg-primary-950",
|
|
112
|
+
className
|
|
113
|
+
),
|
|
114
|
+
...props
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
function ComponentPreviewTitle({ className, ...props }) {
|
|
119
|
+
return /* @__PURE__ */ jsx(
|
|
120
|
+
"div",
|
|
121
|
+
{
|
|
122
|
+
"data-slot": "component-preview-title",
|
|
123
|
+
className: cn("min-w-0 truncate text-xl font-semibold", className),
|
|
124
|
+
...props
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
function ComponentPreviewControls({ className, ...props }) {
|
|
129
|
+
return /* @__PURE__ */ jsx(
|
|
130
|
+
"div",
|
|
131
|
+
{
|
|
132
|
+
"data-slot": "component-preview-controls",
|
|
133
|
+
className: cn("ms-auto flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2", className),
|
|
134
|
+
...props
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
const asButtonProps = (props) => props;
|
|
139
|
+
function Segment({
|
|
140
|
+
value,
|
|
141
|
+
label,
|
|
142
|
+
children
|
|
143
|
+
}) {
|
|
144
|
+
return /* @__PURE__ */ jsx(
|
|
145
|
+
Toggle,
|
|
146
|
+
{
|
|
147
|
+
value,
|
|
148
|
+
"aria-label": label,
|
|
149
|
+
title: label,
|
|
150
|
+
render: (props, state) => /* @__PURE__ */ jsx(Button, { ...asButtonProps(props), iconOnly: true, variant: state.pressed ? "solid" : "ghost" }),
|
|
151
|
+
children
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
function ComponentPreviewThemeToggle({
|
|
156
|
+
lightLabel = "Light",
|
|
157
|
+
darkLabel = "Dark",
|
|
158
|
+
bothLabel = "Light and dark",
|
|
159
|
+
"aria-label": ariaLabel = "Colour scheme",
|
|
160
|
+
...props
|
|
161
|
+
}) {
|
|
162
|
+
const { theme, setTheme } = useComponentPreview("ComponentPreviewThemeToggle");
|
|
163
|
+
return /* @__PURE__ */ jsxs(
|
|
164
|
+
ToggleGroup,
|
|
165
|
+
{
|
|
166
|
+
value: [theme],
|
|
167
|
+
onValueChange: (value) => {
|
|
168
|
+
const next = value[0];
|
|
169
|
+
if (next) setTheme(next);
|
|
170
|
+
},
|
|
171
|
+
render: /* @__PURE__ */ jsx(
|
|
172
|
+
ButtonGroup,
|
|
173
|
+
{
|
|
174
|
+
"data-slot": "component-preview-theme-toggle",
|
|
175
|
+
color: "white",
|
|
176
|
+
size: "sm",
|
|
177
|
+
"aria-label": ariaLabel,
|
|
178
|
+
...props
|
|
179
|
+
}
|
|
180
|
+
),
|
|
181
|
+
children: [
|
|
182
|
+
/* @__PURE__ */ jsx(Segment, { value: "light", label: lightLabel, children: /* @__PURE__ */ jsx(IconLightMode, { "aria-hidden": "true" }) }),
|
|
183
|
+
/* @__PURE__ */ jsx(Segment, { value: "dark", label: darkLabel, children: /* @__PURE__ */ jsx(IconDarkMode, { "aria-hidden": "true" }) }),
|
|
184
|
+
/* @__PURE__ */ jsx(Segment, { value: "both", label: bothLabel, children: /* @__PURE__ */ jsx(IconContrast, { "aria-hidden": "true" }) })
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
function ComponentPreviewWidthToggle({
|
|
190
|
+
phoneLabel = `Phone, ${PHONE_WIDTH}px`,
|
|
191
|
+
tabletLabel = `Tablet, ${TABLET_WIDTH}px`,
|
|
192
|
+
fullLabel = "Full width",
|
|
193
|
+
"aria-label": ariaLabel = "Width",
|
|
194
|
+
...props
|
|
195
|
+
}) {
|
|
196
|
+
const { width, setWidth, measuredWidth } = useComponentPreview("ComponentPreviewWidthToggle");
|
|
197
|
+
return /* @__PURE__ */ jsxs("div", { "data-slot": "component-preview-width", className: "flex items-center gap-3", children: [
|
|
198
|
+
/* @__PURE__ */ jsxs(
|
|
199
|
+
ToggleGroup,
|
|
200
|
+
{
|
|
201
|
+
value: [width === null ? "full" : String(width)],
|
|
202
|
+
onValueChange: (value) => {
|
|
203
|
+
const next = value[0];
|
|
204
|
+
if (next) setWidth(next === "full" ? null : Number(next));
|
|
205
|
+
},
|
|
206
|
+
render: /* @__PURE__ */ jsx(
|
|
207
|
+
ButtonGroup,
|
|
208
|
+
{
|
|
209
|
+
"data-slot": "component-preview-width-toggle",
|
|
210
|
+
color: "white",
|
|
211
|
+
size: "sm",
|
|
212
|
+
"aria-label": ariaLabel,
|
|
213
|
+
...props
|
|
214
|
+
}
|
|
215
|
+
),
|
|
216
|
+
children: [
|
|
217
|
+
/* @__PURE__ */ jsx(Segment, { value: String(PHONE_WIDTH), label: phoneLabel, children: /* @__PURE__ */ jsx(IconSmartphone, { "aria-hidden": "true" }) }),
|
|
218
|
+
/* @__PURE__ */ jsx(Segment, { value: String(TABLET_WIDTH), label: tabletLabel, children: /* @__PURE__ */ jsx(IconTabletMac, { "aria-hidden": "true" }) }),
|
|
219
|
+
/* @__PURE__ */ jsx(Segment, { value: "full", label: fullLabel, children: /* @__PURE__ */ jsx(IconDesktopWindows, { "aria-hidden": "true" }) })
|
|
220
|
+
]
|
|
221
|
+
}
|
|
222
|
+
),
|
|
223
|
+
/* @__PURE__ */ jsx(
|
|
224
|
+
"span",
|
|
225
|
+
{
|
|
226
|
+
"data-slot": "component-preview-width-readout",
|
|
227
|
+
className: "min-w-[6ch] text-end font-mono text-base tabular-nums",
|
|
228
|
+
children: measuredWidth === null ? "" : `${measuredWidth}px`
|
|
229
|
+
}
|
|
230
|
+
)
|
|
231
|
+
] });
|
|
232
|
+
}
|
|
233
|
+
function ComponentPreviewDirectionToggle({
|
|
234
|
+
children = "RTL",
|
|
235
|
+
title = "Right to left",
|
|
236
|
+
...props
|
|
237
|
+
}) {
|
|
238
|
+
const { direction, setDirection } = useComponentPreview("ComponentPreviewDirectionToggle");
|
|
239
|
+
return /* @__PURE__ */ jsx(
|
|
240
|
+
Toggle,
|
|
241
|
+
{
|
|
242
|
+
pressed: direction === "rtl",
|
|
243
|
+
onPressedChange: (pressed) => setDirection(pressed ? "rtl" : "ltr"),
|
|
244
|
+
title,
|
|
245
|
+
render: (toggleProps, state) => /* @__PURE__ */ jsx(
|
|
246
|
+
Button,
|
|
247
|
+
{
|
|
248
|
+
"data-slot": "component-preview-direction-toggle",
|
|
249
|
+
color: "white",
|
|
250
|
+
size: "sm",
|
|
251
|
+
...props,
|
|
252
|
+
...asButtonProps(toggleProps),
|
|
253
|
+
variant: state.pressed ? "solid" : "outline"
|
|
254
|
+
}
|
|
255
|
+
),
|
|
256
|
+
children
|
|
257
|
+
}
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
const optionClassName = "relative flex min-h-11 cursor-pointer items-center gap-2.5 rounded-sm border border-border bg-background px-3 py-2 text-start text-base font-medium text-foreground hover:bg-muted focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring data-checked:border-foreground data-checked:ring-1 data-checked:ring-foreground";
|
|
261
|
+
function PaletteGroup({
|
|
262
|
+
label,
|
|
263
|
+
step,
|
|
264
|
+
value,
|
|
265
|
+
options,
|
|
266
|
+
onValueChange,
|
|
267
|
+
format
|
|
268
|
+
}) {
|
|
269
|
+
const id = React.useId();
|
|
270
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
271
|
+
/* @__PURE__ */ jsx("div", { id, className: "text-base font-semibold", children: label }),
|
|
272
|
+
/* @__PURE__ */ jsx(
|
|
273
|
+
RadioGroup,
|
|
274
|
+
{
|
|
275
|
+
"aria-labelledby": id,
|
|
276
|
+
value,
|
|
277
|
+
onValueChange: (next) => onValueChange(next),
|
|
278
|
+
className: "grid grid-cols-2 gap-2",
|
|
279
|
+
children: options.map((palette) => /* @__PURE__ */ jsxs(Radio.Root, { value: palette, className: optionClassName, children: [
|
|
280
|
+
/* @__PURE__ */ jsx(
|
|
281
|
+
"span",
|
|
282
|
+
{
|
|
283
|
+
"aria-hidden": "true",
|
|
284
|
+
className: "size-5 flex-none rounded-full",
|
|
285
|
+
style: { backgroundColor: `var(--nsw-${palette}-${step})` }
|
|
286
|
+
}
|
|
287
|
+
),
|
|
288
|
+
format(palette),
|
|
289
|
+
/* @__PURE__ */ jsx(Radio.Indicator, { className: "ms-auto", children: /* @__PURE__ */ jsx(IconCheck, { "aria-hidden": "true", className: "size-5" }) })
|
|
290
|
+
] }, palette))
|
|
291
|
+
}
|
|
292
|
+
)
|
|
293
|
+
] });
|
|
294
|
+
}
|
|
295
|
+
function ComponentPreviewColorPicker({
|
|
296
|
+
label = "Theme",
|
|
297
|
+
setLabel = "Colour set",
|
|
298
|
+
brandLabel = "Brand",
|
|
299
|
+
aboriginalLabel = "Aboriginal",
|
|
300
|
+
primaryLabel = "Primary",
|
|
301
|
+
accentLabel = "Accent",
|
|
302
|
+
resetLabel = "Reset",
|
|
303
|
+
pageLabel = "Using this page\u2019s colours",
|
|
304
|
+
formatPalette = paletteName,
|
|
305
|
+
...props
|
|
306
|
+
}) {
|
|
307
|
+
const context = useComponentPreview("ComponentPreviewColorPicker");
|
|
308
|
+
const setId = React.useId();
|
|
309
|
+
const { primary, accent } = context;
|
|
310
|
+
const set = primary ? setOf(primary) : null;
|
|
311
|
+
const palettes = PALETTES[set ?? "brand"];
|
|
312
|
+
const primaryDot = primary ? `var(--nsw-${primary}-800)` : "var(--color-primary-800)";
|
|
313
|
+
const accentDot = accent ? `var(--nsw-${accent}-600)` : "var(--color-accent-600)";
|
|
314
|
+
const choose = (nextPrimary, nextAccent) => {
|
|
315
|
+
const pair = colorPair(nextPrimary, nextAccent);
|
|
316
|
+
context.setColors(pair.primary, pair.accent);
|
|
317
|
+
};
|
|
318
|
+
return /* @__PURE__ */ jsxs(Popover, { children: [
|
|
319
|
+
/* @__PURE__ */ jsxs(
|
|
320
|
+
PopoverTrigger,
|
|
321
|
+
{
|
|
322
|
+
render: /* @__PURE__ */ jsx(
|
|
323
|
+
Button,
|
|
324
|
+
{
|
|
325
|
+
"data-slot": "component-preview-color-picker",
|
|
326
|
+
variant: "outline",
|
|
327
|
+
color: "white",
|
|
328
|
+
size: "sm",
|
|
329
|
+
...props
|
|
330
|
+
}
|
|
331
|
+
),
|
|
332
|
+
children: [
|
|
333
|
+
/* @__PURE__ */ jsx(IconPalette, { "aria-hidden": "true" }),
|
|
334
|
+
label,
|
|
335
|
+
/* @__PURE__ */ jsxs("span", { "aria-hidden": "true", className: "flex gap-1", children: [
|
|
336
|
+
/* @__PURE__ */ jsx(
|
|
337
|
+
"span",
|
|
338
|
+
{
|
|
339
|
+
className: "size-4 rounded-full ring-1 ring-white",
|
|
340
|
+
"data-slot": "component-preview-color-dot",
|
|
341
|
+
style: { backgroundColor: primaryDot }
|
|
342
|
+
}
|
|
343
|
+
),
|
|
344
|
+
/* @__PURE__ */ jsx(
|
|
345
|
+
"span",
|
|
346
|
+
{
|
|
347
|
+
className: "size-4 rounded-full ring-1 ring-white",
|
|
348
|
+
"data-slot": "component-preview-color-dot",
|
|
349
|
+
style: { backgroundColor: accentDot }
|
|
350
|
+
}
|
|
351
|
+
)
|
|
352
|
+
] })
|
|
353
|
+
]
|
|
354
|
+
}
|
|
355
|
+
),
|
|
356
|
+
/* @__PURE__ */ jsxs(
|
|
357
|
+
PopoverContent,
|
|
358
|
+
{
|
|
359
|
+
align: "end",
|
|
360
|
+
sideOffset: 8,
|
|
361
|
+
className: "w-100 max-w-[calc(100vw-1rem)] gap-5 p-5 text-base",
|
|
362
|
+
children: [
|
|
363
|
+
/* @__PURE__ */ jsx(Popover$1.Title, { className: "sr-only", children: label }),
|
|
364
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
365
|
+
/* @__PURE__ */ jsx("div", { id: setId, className: "text-base font-semibold", children: setLabel }),
|
|
366
|
+
/* @__PURE__ */ jsxs(
|
|
367
|
+
RadioGroup,
|
|
368
|
+
{
|
|
369
|
+
"aria-labelledby": setId,
|
|
370
|
+
value: set,
|
|
371
|
+
onValueChange: (next) => {
|
|
372
|
+
const list = PALETTES[next];
|
|
373
|
+
context.setColors(list[0], list[1]);
|
|
374
|
+
},
|
|
375
|
+
className: "grid grid-cols-2 gap-2",
|
|
376
|
+
children: [
|
|
377
|
+
/* @__PURE__ */ jsx(Radio.Root, { value: "brand", className: cn(optionClassName, "justify-center"), children: brandLabel }),
|
|
378
|
+
/* @__PURE__ */ jsx(
|
|
379
|
+
Radio.Root,
|
|
380
|
+
{
|
|
381
|
+
value: "aboriginal",
|
|
382
|
+
className: cn(optionClassName, "justify-center"),
|
|
383
|
+
children: aboriginalLabel
|
|
384
|
+
}
|
|
385
|
+
)
|
|
386
|
+
]
|
|
387
|
+
}
|
|
388
|
+
)
|
|
389
|
+
] }),
|
|
390
|
+
/* @__PURE__ */ jsx(
|
|
391
|
+
PaletteGroup,
|
|
392
|
+
{
|
|
393
|
+
label: primaryLabel,
|
|
394
|
+
step: 800,
|
|
395
|
+
value: primary ?? null,
|
|
396
|
+
options: palettes,
|
|
397
|
+
onValueChange: (next) => choose(next, accent),
|
|
398
|
+
format: formatPalette
|
|
399
|
+
}
|
|
400
|
+
),
|
|
401
|
+
/* @__PURE__ */ jsx(
|
|
402
|
+
PaletteGroup,
|
|
403
|
+
{
|
|
404
|
+
label: accentLabel,
|
|
405
|
+
step: 600,
|
|
406
|
+
value: accent ?? null,
|
|
407
|
+
options: palettes.filter((palette) => palette !== primary),
|
|
408
|
+
onValueChange: (next) => choose(primary, next),
|
|
409
|
+
format: formatPalette
|
|
410
|
+
}
|
|
411
|
+
),
|
|
412
|
+
/* @__PURE__ */ jsxs("div", { className: "-mx-2 -mb-2 flex items-center gap-3 border-t border-border pt-2", children: [
|
|
413
|
+
/* @__PURE__ */ jsx(Button, { variant: "ghost", size: "sm", onClick: () => context.setColors(void 0, void 0), children: resetLabel }),
|
|
414
|
+
primary ? null : /* @__PURE__ */ jsx(
|
|
415
|
+
"p",
|
|
416
|
+
{
|
|
417
|
+
"data-slot": "component-preview-color-status",
|
|
418
|
+
className: "ms-auto pe-2 text-base text-muted-foreground",
|
|
419
|
+
children: pageLabel
|
|
420
|
+
}
|
|
421
|
+
)
|
|
422
|
+
] })
|
|
423
|
+
]
|
|
424
|
+
}
|
|
425
|
+
)
|
|
426
|
+
] });
|
|
427
|
+
}
|
|
428
|
+
const NO_VALUES = {};
|
|
429
|
+
const sameValues = (a, b) => {
|
|
430
|
+
const keys = Object.keys(a);
|
|
431
|
+
return keys.length === Object.keys(b).length && keys.every((key) => a[key] === b[key]);
|
|
432
|
+
};
|
|
433
|
+
function StagePane({
|
|
434
|
+
scheme,
|
|
435
|
+
label,
|
|
436
|
+
resizeLabel,
|
|
437
|
+
reportsWidth,
|
|
438
|
+
children
|
|
439
|
+
}) {
|
|
440
|
+
const { width, setWidth, setMeasuredWidth, direction, primary, accent } = useComponentPreview("ComponentPreviewStage");
|
|
441
|
+
const wellRef = React.useRef(null);
|
|
442
|
+
const frameRef = React.useRef(null);
|
|
443
|
+
const [available, setAvailable] = React.useState(0);
|
|
444
|
+
const measure = React.useCallback(() => {
|
|
445
|
+
const well = wellRef.current;
|
|
446
|
+
const frame = frameRef.current;
|
|
447
|
+
if (!well || !frame) return;
|
|
448
|
+
setAvailable(Math.round(well.getBoundingClientRect().width));
|
|
449
|
+
if (reportsWidth) setMeasuredWidth(Math.round(frame.getBoundingClientRect().width));
|
|
450
|
+
}, [reportsWidth, setMeasuredWidth]);
|
|
451
|
+
React.useLayoutEffect(measure, [measure, width]);
|
|
452
|
+
React.useEffect(() => {
|
|
453
|
+
const well = wellRef.current;
|
|
454
|
+
const frame = frameRef.current;
|
|
455
|
+
if (!well || !frame || typeof ResizeObserver === "undefined") return;
|
|
456
|
+
const observer = new ResizeObserver(measure);
|
|
457
|
+
observer.observe(well);
|
|
458
|
+
observer.observe(frame);
|
|
459
|
+
return () => observer.disconnect();
|
|
460
|
+
}, [measure]);
|
|
461
|
+
const style = React.useMemo(
|
|
462
|
+
() => previewThemeStyle({ scheme, primary, accent }),
|
|
463
|
+
[scheme, primary, accent]
|
|
464
|
+
);
|
|
465
|
+
const scope = React.useMemo(
|
|
466
|
+
() => ({
|
|
467
|
+
className: scheme === "dark" ? "dark scheme-dark" : "scheme-light",
|
|
468
|
+
style,
|
|
469
|
+
dir: direction,
|
|
470
|
+
attributes: {
|
|
471
|
+
"data-theme": scheme,
|
|
472
|
+
"data-theme-island": scheme === "light" ? "light" : void 0
|
|
473
|
+
}
|
|
474
|
+
}),
|
|
475
|
+
[scheme, style, direction]
|
|
476
|
+
);
|
|
477
|
+
const paneRef = React.useRef(null);
|
|
478
|
+
const [inherited, setInherited] = React.useState(NO_VALUES);
|
|
479
|
+
const readInherited = React.useCallback(() => {
|
|
480
|
+
const pane = paneRef.current;
|
|
481
|
+
if (!pane) return;
|
|
482
|
+
const computed = getComputedStyle(pane);
|
|
483
|
+
const next = {};
|
|
484
|
+
for (const [ramp, chosen] of [
|
|
485
|
+
["primary", primary],
|
|
486
|
+
["accent", accent]
|
|
487
|
+
]) {
|
|
488
|
+
if (chosen) continue;
|
|
489
|
+
for (const step of PALETTE_STEPS) {
|
|
490
|
+
for (const name of [`--${ramp}-${step}`, `--color-${ramp}-${step}`]) {
|
|
491
|
+
const value = computed.getPropertyValue(name).trim();
|
|
492
|
+
if (value) next[name] = value;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
setInherited((current) => sameValues(current, next) ? current : next);
|
|
497
|
+
}, [primary, accent]);
|
|
498
|
+
React.useLayoutEffect(readInherited, [readInherited]);
|
|
499
|
+
const portalScope = React.useMemo(
|
|
500
|
+
() => ({ ...scope, style: { ...scope.style, ...inherited } }),
|
|
501
|
+
[scope, inherited]
|
|
502
|
+
);
|
|
503
|
+
const resizable = available > MIN_WIDTH;
|
|
504
|
+
return /* @__PURE__ */ jsxs(
|
|
505
|
+
"div",
|
|
506
|
+
{
|
|
507
|
+
ref: paneRef,
|
|
508
|
+
"data-slot": "component-preview-pane",
|
|
509
|
+
onPointerEnter: readInherited,
|
|
510
|
+
onFocusCapture: readInherited,
|
|
511
|
+
className: cn(
|
|
512
|
+
"min-w-0 flex-1 bg-muted text-foreground @max-3xl/component-preview:py-4 @max-3xl/component-preview:ps-4 @max-3xl/component-preview:pe-9 @3xl/component-preview:py-6 @3xl/component-preview:ps-6 @3xl/component-preview:pe-10",
|
|
513
|
+
scope.className
|
|
514
|
+
),
|
|
515
|
+
...scope.attributes,
|
|
516
|
+
style: scope.style,
|
|
517
|
+
children: [
|
|
518
|
+
label ? /* @__PURE__ */ jsx(
|
|
519
|
+
"div",
|
|
520
|
+
{
|
|
521
|
+
"data-slot": "component-preview-pane-label",
|
|
522
|
+
className: "mb-2 font-medium text-muted-foreground",
|
|
523
|
+
children: label
|
|
524
|
+
}
|
|
525
|
+
) : null,
|
|
526
|
+
/* @__PURE__ */ jsxs("div", { ref: wellRef, className: "relative", children: [
|
|
527
|
+
/* @__PURE__ */ jsx(
|
|
528
|
+
"div",
|
|
529
|
+
{
|
|
530
|
+
ref: frameRef,
|
|
531
|
+
"data-slot": "component-preview-frame",
|
|
532
|
+
dir: scope.dir,
|
|
533
|
+
style: { maxWidth: width ?? void 0 },
|
|
534
|
+
className: "@container/component-preview-frame min-w-0 border border-border bg-background text-foreground @max-3xl/component-preview:p-4 @3xl/component-preview:p-8",
|
|
535
|
+
children: /* @__PURE__ */ jsx(PortalScopeContext.Provider, { value: portalScope, children })
|
|
536
|
+
}
|
|
537
|
+
),
|
|
538
|
+
resizable ? /* @__PURE__ */ jsx(
|
|
539
|
+
Slider.Root,
|
|
540
|
+
{
|
|
541
|
+
min: MIN_WIDTH,
|
|
542
|
+
max: available,
|
|
543
|
+
step: 8,
|
|
544
|
+
largeStep: 64,
|
|
545
|
+
value: Math.min(width ?? available, available),
|
|
546
|
+
onValueChange: (value) => setWidth(value >= available ? null : value),
|
|
547
|
+
children: /* @__PURE__ */ jsx(Slider.Control, { className: "pointer-events-none absolute inset-y-0 start-70 end-0", children: /* @__PURE__ */ jsx(
|
|
548
|
+
Slider.Thumb,
|
|
549
|
+
{
|
|
550
|
+
"data-slot": "component-preview-resize-handle",
|
|
551
|
+
"aria-label": resizeLabel,
|
|
552
|
+
getAriaValueText: (_, value) => `${value}px`,
|
|
553
|
+
className: "pointer-events-auto ms-4 flex h-full w-6 cursor-ew-resize touch-none items-center justify-center rounded-sm text-muted-foreground hover:bg-foreground/10 hover:text-foreground has-focus:outline-2 has-focus:outline-offset-2 has-focus:outline-ring data-dragging:bg-foreground/10 data-dragging:text-foreground",
|
|
554
|
+
children: /* @__PURE__ */ jsx(IconDragIndicator, { "aria-hidden": "true", className: "size-5 flex-none" })
|
|
555
|
+
}
|
|
556
|
+
) })
|
|
557
|
+
}
|
|
558
|
+
) : null
|
|
559
|
+
] })
|
|
560
|
+
]
|
|
561
|
+
}
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
function ComponentPreviewStage({
|
|
565
|
+
className,
|
|
566
|
+
children,
|
|
567
|
+
lightLabel = "Light",
|
|
568
|
+
darkLabel = "Dark",
|
|
569
|
+
resizeLabel = "Preview width",
|
|
570
|
+
...props
|
|
571
|
+
}) {
|
|
572
|
+
const { theme } = useComponentPreview("ComponentPreviewStage");
|
|
573
|
+
const schemes = theme === "both" ? ["light", "dark"] : [theme];
|
|
574
|
+
const labels = { light: lightLabel, dark: darkLabel };
|
|
575
|
+
return /* @__PURE__ */ jsx(
|
|
576
|
+
"div",
|
|
577
|
+
{
|
|
578
|
+
"data-slot": "component-preview-stage",
|
|
579
|
+
className: cn(
|
|
580
|
+
"flex min-w-0 @max-3xl/component-preview:flex-col @3xl/component-preview:flex-row",
|
|
581
|
+
className
|
|
582
|
+
),
|
|
583
|
+
...props,
|
|
584
|
+
children: schemes.map((scheme, index) => /* @__PURE__ */ jsx(
|
|
585
|
+
StagePane,
|
|
586
|
+
{
|
|
587
|
+
scheme,
|
|
588
|
+
label: theme === "both" ? labels[scheme] : void 0,
|
|
589
|
+
resizeLabel,
|
|
590
|
+
reportsWidth: index === 0,
|
|
591
|
+
children
|
|
592
|
+
},
|
|
593
|
+
scheme
|
|
594
|
+
))
|
|
595
|
+
}
|
|
596
|
+
);
|
|
597
|
+
}
|
|
598
|
+
function ComponentPreviewCode({
|
|
599
|
+
className,
|
|
600
|
+
files,
|
|
601
|
+
collapsedLines = 8,
|
|
602
|
+
showMoreLabel = "Show more",
|
|
603
|
+
showLessLabel = "Show less",
|
|
604
|
+
copyLabel,
|
|
605
|
+
copiedLabel,
|
|
606
|
+
...props
|
|
607
|
+
}) {
|
|
608
|
+
const [active, setActive] = React.useState(0);
|
|
609
|
+
const [expanded, setExpanded] = React.useState([]);
|
|
610
|
+
const contentId = React.useId();
|
|
611
|
+
const shown = active < files.length ? active : 0;
|
|
612
|
+
const current = files[shown];
|
|
613
|
+
if (!current) return null;
|
|
614
|
+
return /* @__PURE__ */ jsxs(
|
|
615
|
+
Tabs,
|
|
616
|
+
{
|
|
617
|
+
"data-slot": "component-preview-code",
|
|
618
|
+
value: shown,
|
|
619
|
+
onValueChange: (value) => setActive(value),
|
|
620
|
+
className: cn("min-w-0 gap-0 border-t border-border", className),
|
|
621
|
+
...props,
|
|
622
|
+
children: [
|
|
623
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center gap-2 border-b border-border ps-4 pe-2", children: [
|
|
624
|
+
/* @__PURE__ */ jsx(TabsList, { variant: "line", className: "min-w-0 gap-5 overflow-x-auto border-b-0", children: files.map((file, index) => /* @__PURE__ */ jsx(
|
|
625
|
+
TabsTrigger,
|
|
626
|
+
{
|
|
627
|
+
value: index,
|
|
628
|
+
className: "text-base focus-visible:-outline-offset-2",
|
|
629
|
+
children: file.label
|
|
630
|
+
},
|
|
631
|
+
file.label
|
|
632
|
+
)) }),
|
|
633
|
+
/* @__PURE__ */ jsx(
|
|
634
|
+
CodeBlockCopyButton,
|
|
635
|
+
{
|
|
636
|
+
className: "ms-auto",
|
|
637
|
+
value: current.code,
|
|
638
|
+
"aria-label": copyLabel,
|
|
639
|
+
copiedLabel
|
|
640
|
+
}
|
|
641
|
+
)
|
|
642
|
+
] }),
|
|
643
|
+
files.map((file, index) => {
|
|
644
|
+
const long = file.code.split("\n").length > collapsedLines;
|
|
645
|
+
const open = expanded.includes(file.label);
|
|
646
|
+
const collapsed = long && !open;
|
|
647
|
+
return /* @__PURE__ */ jsx(TabsContent, { value: index, className: "min-w-0 text-base", children: /* @__PURE__ */ jsxs(CodeBlock, { className: "rounded-none border-0", children: [
|
|
648
|
+
/* @__PURE__ */ jsx(
|
|
649
|
+
CodeBlockContent,
|
|
650
|
+
{
|
|
651
|
+
id: `${contentId}-${index}`,
|
|
652
|
+
style: collapsed ? { maxHeight: `calc(${collapsedLines}lh + var(--code-block-p))` } : void 0,
|
|
653
|
+
className: cn(
|
|
654
|
+
collapsed && "overflow-hidden [mask-image:linear-gradient(black_55%,transparent)]"
|
|
655
|
+
),
|
|
656
|
+
children: file.code
|
|
657
|
+
}
|
|
658
|
+
),
|
|
659
|
+
long ? /* @__PURE__ */ jsx(CodeBlockFooter, { className: "px-2 pb-2", children: /* @__PURE__ */ jsxs(
|
|
660
|
+
Button,
|
|
661
|
+
{
|
|
662
|
+
variant: "ghost",
|
|
663
|
+
size: "sm",
|
|
664
|
+
"aria-expanded": open,
|
|
665
|
+
"aria-controls": `${contentId}-${index}`,
|
|
666
|
+
onClick: () => setExpanded(
|
|
667
|
+
(state) => open ? state.filter((label) => label !== file.label) : [...state, file.label]
|
|
668
|
+
),
|
|
669
|
+
children: [
|
|
670
|
+
open ? showLessLabel : showMoreLabel,
|
|
671
|
+
/* @__PURE__ */ jsx(
|
|
672
|
+
IconExpandMore,
|
|
673
|
+
{
|
|
674
|
+
"aria-hidden": "true",
|
|
675
|
+
className: cn("motion-safe:transition-transform", open && "rotate-180")
|
|
676
|
+
}
|
|
677
|
+
)
|
|
678
|
+
]
|
|
679
|
+
}
|
|
680
|
+
) }) : null
|
|
681
|
+
] }) }, file.label);
|
|
682
|
+
})
|
|
683
|
+
]
|
|
684
|
+
}
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
export { ComponentPreview, ComponentPreviewCode, ComponentPreviewColorPicker, ComponentPreviewControls, ComponentPreviewDirectionToggle, ComponentPreviewHeader, ComponentPreviewStage, ComponentPreviewThemeToggle, ComponentPreviewTitle, ComponentPreviewWidthToggle };
|
|
689
|
+
//# sourceMappingURL=component-preview.js.map
|
|
690
|
+
//# sourceMappingURL=component-preview.js.map
|