@zonsh/ui 0.2.0 → 0.4.1

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 (180) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -13
  3. package/dist/components/alert-dialog.js +1 -1
  4. package/dist/components/ascii-field.d.ts +1 -1
  5. package/dist/components/bottom-nav.d.ts +86 -0
  6. package/dist/components/bottom-nav.js +175 -0
  7. package/dist/components/breadcrumb.d.ts +9 -0
  8. package/dist/components/breadcrumb.js +6 -1
  9. package/dist/components/button-group.d.ts +1 -1
  10. package/dist/components/button-group.js +2 -2
  11. package/dist/components/calendar.d.ts +1 -1
  12. package/dist/components/calendar.js +18 -3
  13. package/dist/components/carousel.d.ts +22 -3
  14. package/dist/components/carousel.js +25 -7
  15. package/dist/components/chart.d.ts +9 -0
  16. package/dist/components/chart.js +40 -3
  17. package/dist/components/code-block.d.ts +20 -10
  18. package/dist/components/code-block.js +54 -12
  19. package/dist/components/collapsible.js +2 -2
  20. package/dist/components/color-picker.d.ts +30 -8
  21. package/dist/components/color-picker.js +48 -27
  22. package/dist/components/combobox.d.ts +21 -3
  23. package/dist/components/combobox.js +79 -7
  24. package/dist/components/command.d.ts +23 -3
  25. package/dist/components/command.js +61 -16
  26. package/dist/components/conversation.d.ts +10 -1
  27. package/dist/components/conversation.js +14 -4
  28. package/dist/components/copy-button.d.ts +15 -6
  29. package/dist/components/copy-button.js +20 -5
  30. package/dist/components/data-table.d.ts +66 -6
  31. package/dist/components/data-table.js +376 -23
  32. package/dist/components/date-picker.d.ts +73 -4
  33. package/dist/components/date-picker.js +138 -7
  34. package/dist/components/dialog.d.ts +10 -1
  35. package/dist/components/dialog.js +6 -3
  36. package/dist/components/drawer.d.ts +10 -1
  37. package/dist/components/drawer.js +6 -3
  38. package/dist/components/feature-list.js +2 -2
  39. package/dist/components/field.d.ts +27 -8
  40. package/dist/components/field.js +49 -4
  41. package/dist/components/file-drop.d.ts +26 -4
  42. package/dist/components/file-drop.js +125 -64
  43. package/dist/components/filter-bar.d.ts +50 -3
  44. package/dist/components/filter-bar.js +71 -33
  45. package/dist/components/form.d.ts +4 -2
  46. package/dist/components/form.js +24 -2
  47. package/dist/components/graph.d.ts +41 -0
  48. package/dist/components/graph.js +84 -45
  49. package/dist/components/illustration.js +1 -1
  50. package/dist/components/input-group.d.ts +16 -5
  51. package/dist/components/input-group.js +35 -15
  52. package/dist/components/input.d.ts +2 -2
  53. package/dist/components/input.js +3 -3
  54. package/dist/components/kbd.d.ts +17 -0
  55. package/dist/components/kbd.js +8 -1
  56. package/dist/components/lightbox.d.ts +100 -0
  57. package/dist/components/lightbox.js +439 -0
  58. package/dist/components/locale.d.ts +44 -0
  59. package/dist/components/locale.js +37 -0
  60. package/dist/components/logo.js +1 -1
  61. package/dist/components/menu.js +3 -1
  62. package/dist/components/message.d.ts +3 -3
  63. package/dist/components/message.js +10 -7
  64. package/dist/components/meter.js +3 -1
  65. package/dist/components/money-input.d.ts +80 -0
  66. package/dist/components/money-input.js +253 -0
  67. package/dist/components/number-field.d.ts +21 -2
  68. package/dist/components/number-field.js +27 -16
  69. package/dist/components/otp-field.d.ts +14 -1
  70. package/dist/components/otp-field.js +10 -2
  71. package/dist/components/pagination.d.ts +13 -7
  72. package/dist/components/pagination.js +18 -7
  73. package/dist/components/pdf-viewer.d.ts +67 -2
  74. package/dist/components/pdf-viewer.js +88 -21
  75. package/dist/components/phone-input.d.ts +79 -0
  76. package/dist/components/phone-input.js +282 -0
  77. package/dist/components/popover.js +1 -1
  78. package/dist/components/progress.js +3 -1
  79. package/dist/components/prompt-input.d.ts +34 -9
  80. package/dist/components/prompt-input.js +28 -16
  81. package/dist/components/rating.d.ts +73 -0
  82. package/dist/components/rating.js +124 -0
  83. package/dist/components/reasoning.d.ts +16 -1
  84. package/dist/components/reasoning.js +10 -7
  85. package/dist/components/resizable.d.ts +10 -1
  86. package/dist/components/resizable.js +4 -1
  87. package/dist/components/response.d.ts +14 -3
  88. package/dist/components/response.js +36 -8
  89. package/dist/components/scroll-area.d.ts +1 -1
  90. package/dist/components/select.js +14 -3
  91. package/dist/components/separator.js +1 -1
  92. package/dist/components/sidebar.d.ts +20 -4
  93. package/dist/components/sidebar.js +34 -18
  94. package/dist/components/site-header.d.ts +46 -12
  95. package/dist/components/site-header.js +73 -19
  96. package/dist/components/slider.js +3 -1
  97. package/dist/components/sortable.d.ts +178 -0
  98. package/dist/components/sortable.js +1258 -0
  99. package/dist/components/sources.d.ts +17 -2
  100. package/dist/components/sources.js +11 -4
  101. package/dist/components/spinner.d.ts +13 -1
  102. package/dist/components/spinner.js +5 -2
  103. package/dist/components/stat.d.ts +91 -0
  104. package/dist/components/stat.js +141 -0
  105. package/dist/components/stepper.d.ts +71 -0
  106. package/dist/components/stepper.js +101 -0
  107. package/dist/components/switch.d.ts +2 -2
  108. package/dist/components/switch.js +2 -2
  109. package/dist/components/table.d.ts +12 -2
  110. package/dist/components/table.js +176 -39
  111. package/dist/components/tags-input.d.ts +18 -2
  112. package/dist/components/tags-input.js +65 -33
  113. package/dist/components/theme.d.ts +16 -2
  114. package/dist/components/theme.js +15 -7
  115. package/dist/components/time-field.d.ts +22 -3
  116. package/dist/components/time-field.js +19 -6
  117. package/dist/components/timeline.d.ts +18 -2
  118. package/dist/components/timeline.js +13 -4
  119. package/dist/components/tippy.d.ts +48 -0
  120. package/dist/components/tippy.js +648 -0
  121. package/dist/components/toast.d.ts +18 -2
  122. package/dist/components/toast.js +12 -3
  123. package/dist/components/tool-call.d.ts +19 -8
  124. package/dist/components/tool-call.js +18 -7
  125. package/dist/components/toolbar.js +6 -1
  126. package/dist/components/tour.d.ts +127 -0
  127. package/dist/components/tour.js +648 -0
  128. package/dist/components/tree.js +17 -4
  129. package/dist/components/video-player.d.ts +10 -2
  130. package/dist/components/video-player.js +73 -33
  131. package/dist/illustration.d.ts +2 -0
  132. package/dist/illustration.js +7 -0
  133. package/dist/index.d.ts +11 -3
  134. package/dist/index.js +11 -3
  135. package/dist/lib/code-highlight.d.ts +3 -16
  136. package/dist/lib/code-highlight.js +160 -10
  137. package/dist/lib/code-theme.js +3 -3
  138. package/dist/lib/digit-roll.js +8 -8
  139. package/dist/lib/field-errors.d.ts +28 -0
  140. package/dist/lib/field-errors.js +24 -0
  141. package/dist/lib/field-value.d.ts +13 -0
  142. package/dist/lib/field-value.js +44 -0
  143. package/dist/lib/graph-layout.js +11 -2
  144. package/dist/lib/money.d.ts +73 -0
  145. package/dist/lib/money.js +343 -0
  146. package/dist/lib/phone-countries.d.ts +1 -0
  147. package/dist/lib/phone-countries.js +281 -0
  148. package/dist/lib/phone.d.ts +90 -0
  149. package/dist/lib/phone.js +286 -0
  150. package/dist/lib/platform.d.ts +8 -3
  151. package/dist/lib/platform.js +13 -6
  152. package/dist/lib/row-index.d.ts +15 -0
  153. package/dist/lib/row-index.js +136 -0
  154. package/dist/lib/table-fit.js +23 -4
  155. package/dist/lib/theme-script.d.ts +15 -2
  156. package/dist/lib/theme-script.js +23 -3
  157. package/dist/lib/tippy/pixels.d.ts +47 -0
  158. package/dist/lib/tippy/pixels.js +187 -0
  159. package/dist/lib/tippy/sprite.d.ts +86 -0
  160. package/dist/lib/tippy/sprite.js +753 -0
  161. package/dist/messages/de.d.ts +12 -0
  162. package/dist/messages/de.js +326 -0
  163. package/dist/styles/expressive.css +20 -5
  164. package/dist/styles/index.css +3 -2
  165. package/dist/styles/material.css +7 -3
  166. package/dist/styles/parts/ai.css +2 -1
  167. package/dist/styles/parts/controls.css +62 -13
  168. package/dist/styles/parts/feedback.css +68 -1
  169. package/dist/styles/parts/foundations.css +1 -1
  170. package/dist/styles/parts/navigation.css +194 -2
  171. package/dist/styles/parts/overlays.css +7 -7
  172. package/dist/styles/tokens.css +12 -3
  173. package/dist/vite.d.ts +0 -50
  174. package/dist/vite.js +0 -100
  175. package/package.json +28 -33
  176. package/dist/components/code-highlight.d.ts +0 -13
  177. package/dist/components/code-highlight.js +0 -107
  178. package/dist/components/whiteboard.d.ts +0 -80
  179. package/dist/components/whiteboard.js +0 -389
  180. package/dist/styles/parts/whiteboard.css +0 -855
@@ -177,4 +177,13 @@ export interface ChartLegendContentProps {
177
177
  * or more series; a single series is named by the chart's title instead.
178
178
  */
179
179
  export declare function ChartLegendContent({ payload, verticalAlign, hideIcon, nameKey, className, }: ChartLegendContentProps): React.JSX.Element | null;
180
+ /**
181
+ * downsample — the points of a long series that a chart can show: for each of `buckets` runs of
182
+ * points, its first point and each series' lowest and highest, in order. A line keeps its shape,
183
+ * its peaks and its dips; a chart a few hundred pixels wide draws no more than that anyway, and
184
+ * Recharts takes seconds over tens of thousands of points.
185
+ *
186
+ * <LineChart data={downsample(readings, ["cpu", "memory"])}>
187
+ */
188
+ export declare function downsample<T extends Record<string, unknown>>(data: readonly T[], keys: readonly (keyof T & string)[], buckets?: number): T[];
180
189
  export {};
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import * as React from "react";
4
4
  import * as RechartsPrimitive from "recharts";
5
5
  import { cn } from "../lib/cn.js";
6
+ import { useLocale } from "./locale.js";
6
7
  const ChartContext = React.createContext(null);
7
8
  /** The config of the nearest `ChartContainer`. For custom tooltip or legend content. */
8
9
  export function useChart() {
@@ -81,7 +82,7 @@ export function ChartContainer({ id, config, palette = "mono", grid = "horizonta
81
82
  const value = React.useMemo(() => ({ config }), [config]);
82
83
  // Pies lift the slice under the pointer (ChartActiveSector): know where it is from the start.
83
84
  React.useEffect(track, []);
84
- return (_jsx(ChartContext.Provider, { value: value, children: _jsxs("div", { "data-slot": "chart", role: props["aria-label"] || props["aria-labelledby"] ? "figure" : undefined, "data-chart": chartId, "data-grid": grid, className: cn("relative flex aspect-video w-full min-w-0 justify-center font-body text-xs text-foreground-soft", className), style: { ...vars, ...style }, ...props, children: [rules ? _jsx("style", { children: `[data-chart="${chartId}"]{${rules}}` }) : null, _jsx(RechartsPrimitive.ResponsiveContainer, { initialDimension: { width: 320, height: 180 }, children: children })] }) }));
85
+ return (_jsx(ChartContext.Provider, { value: value, children: _jsxs("div", { "data-slot": "chart", id: id, role: props["aria-label"] || props["aria-labelledby"] ? "figure" : undefined, "data-chart": chartId, "data-grid": grid, className: cn("relative flex aspect-video w-full min-w-0 justify-center font-body text-xs text-foreground-soft", className), style: { ...vars, ...style }, ...props, children: [rules ? _jsx("style", { children: `[data-chart="${chartId}"]{${rules}}` }) : null, _jsx(RechartsPrimitive.ResponsiveContainer, { initialDimension: { width: 320, height: 180 }, children: children })] }) }));
85
86
  }
86
87
  /**
87
88
  * ChartGradient — the soft vertical fill under an area: the series colour fading to nothing.
@@ -227,6 +228,7 @@ export function ChartTooltip(props) {
227
228
  */
228
229
  export function ChartTooltipContent({ active, payload, label, indicator = "dot", hideLabel = false, hideIndicator = false, labelFormatter, valueFormatter, nameKey, labelKey, className, }) {
229
230
  const { config } = useChart();
231
+ const locale = useLocale();
230
232
  if (!active || !payload?.length)
231
233
  return null;
232
234
  const items = payload.filter((item) => item.type !== "none" && !item.hide);
@@ -250,10 +252,10 @@ export function ChartTooltipContent({ active, payload, label, indicator = "dot",
250
252
  const name = series?.label ?? item.name ?? key;
251
253
  const dash = indicator === "dashed" ? "3 2" : (series?.dash ?? item.strokeDasharray?.toString());
252
254
  const Icon = series?.icon;
253
- return (_jsxs("div", { "data-slot": "chart-tooltip-item", className: "flex min-h-4 items-center gap-2", children: [hideIndicator ? null : Icon ? (_jsx(Icon, { className: "size-3 shrink-0 text-muted-foreground" })) : (_jsx(ChartSwatch, { shape: indicator === "dot" ? "dot" : "line", color: color, dash: dash, pattern: series?.pattern })), _jsx("span", { className: "text-foreground-soft", children: name }), item.value != null ? (_jsx("span", { className: "ml-auto pl-4 font-mono text-xs text-foreground tabular-nums", children: valueFormatter
255
+ return (_jsxs("div", { "data-slot": "chart-tooltip-item", className: "flex min-h-4 items-center gap-2", children: [hideIndicator ? null : Icon ? (_jsx(Icon, { className: "size-3 shrink-0 text-muted-foreground" })) : (_jsx(ChartSwatch, { shape: indicator === "dot" ? "dot" : "line", color: color, dash: dash, pattern: series?.pattern })), _jsx("span", { className: "text-foreground-soft", children: name }), item.value != null ? (_jsx("span", { className: "ms-auto ps-4 font-mono text-xs text-foreground tabular-nums", children: valueFormatter
254
256
  ? valueFormatter(item.value, name, item)
255
257
  : typeof item.value === "number"
256
- ? item.value.toLocaleString()
258
+ ? item.value.toLocaleString(locale)
257
259
  : String(item.value) })) : null] }, `${key}-${index}`));
258
260
  }) })] }));
259
261
  }
@@ -284,3 +286,38 @@ export function ChartLegendContent({ payload, verticalAlign = "bottom", hideIcon
284
286
  return (_jsxs("li", { "data-slot": "chart-legend-item", "data-inactive": item.inactive ? "" : undefined, className: "flex items-center gap-1.5 font-mono text-[11px] leading-none text-muted-foreground data-inactive:opacity-50", children: [hideIcon ? null : Icon ? (_jsx(Icon, { className: "size-3 shrink-0" })) : (_jsx(ChartSwatch, { shape: item.type === "line" || series?.dash ? "line" : "dot", color: color, dash: dash, pattern: series?.pattern })), series?.label ?? item.value] }, `${key}-${index}`));
285
287
  }) }));
286
288
  }
289
+ /**
290
+ * downsample — the points of a long series that a chart can show: for each of `buckets` runs of
291
+ * points, its first point and each series' lowest and highest, in order. A line keeps its shape,
292
+ * its peaks and its dips; a chart a few hundred pixels wide draws no more than that anyway, and
293
+ * Recharts takes seconds over tens of thousands of points.
294
+ *
295
+ * <LineChart data={downsample(readings, ["cpu", "memory"])}>
296
+ */
297
+ export function downsample(data, keys, buckets = 600) {
298
+ if (data.length <= buckets * (keys.length * 2 + 1))
299
+ return [...data];
300
+ const size = data.length / buckets;
301
+ const picked = [];
302
+ for (let b = 0; b < buckets; b++) {
303
+ const from = Math.floor(b * size);
304
+ const to = Math.min(data.length, Math.floor((b + 1) * size));
305
+ const at = new Set([from]);
306
+ for (const key of keys) {
307
+ let low = from;
308
+ let high = from;
309
+ for (let i = from; i < to; i++) {
310
+ const value = Number(data[i][key]);
311
+ if (value < Number(data[low][key]))
312
+ low = i;
313
+ if (value > Number(data[high][key]))
314
+ high = i;
315
+ }
316
+ at.add(low).add(high);
317
+ }
318
+ picked.push(...[...at].sort((a, b) => a - b));
319
+ }
320
+ if (picked.at(-1) !== data.length - 1)
321
+ picked.push(data.length - 1);
322
+ return picked.map((i) => data[i]);
323
+ }
@@ -1,4 +1,14 @@
1
1
  import * as React from "react";
2
+ import { type CopyButtonMessages } from "./copy-button.js";
3
+ export interface CodeBlockMessages {
4
+ /** The copy button's name. Its confirmation comes from `copyButton`. */
5
+ copy: string;
6
+ }
7
+ declare module "./locale" {
8
+ interface Messages {
9
+ codeBlock: CodeBlockMessages;
10
+ }
11
+ }
2
12
  export interface CodeBlockProps extends Omit<React.ComponentProps<"figure">, "children"> {
3
13
  /** The source to show. Alternatively pass it as the child string. */
4
14
  code?: string;
@@ -13,8 +23,8 @@ export interface CodeBlockProps extends Omit<React.ComponentProps<"figure">, "ch
13
23
  */
14
24
  language?: string;
15
25
  /**
16
- * Colour the code by its `language`, in the zon theme. Needs a `CodeHighlightProvider` (from
17
- * `@zonsh/ui/code-highlight`) above it; without one, or for an unknown language, it stays mono.
26
+ * Colour the code by its `language`, in the zon theme. Default `true`; without a `language`, or
27
+ * for one Shiki does not know, the code stays mono either way.
18
28
  */
19
29
  highlight?: boolean;
20
30
  /** Show muted, mono line numbers. */
@@ -23,18 +33,18 @@ export interface CodeBlockProps extends Omit<React.ComponentProps<"figure">, "ch
23
33
  wrap?: boolean;
24
34
  /** Show the copy button. Defaults to `true`. */
25
35
  copyable?: boolean;
26
- /** Accessible names for the copy button and its confirmation (see `CopyButton`). */
27
- labels?: {
28
- copy?: string;
29
- copied?: string;
30
- failed?: string;
31
- };
36
+ /**
37
+ * Accessible names for the copy button and its confirmation (see `CopyButton`). A
38
+ * LocaleProvider sets `copy` for every CodeBlock (`messages.codeBlock`) and the confirmation
39
+ * for every CopyButton (`messages.copyButton`).
40
+ */
41
+ labels?: Partial<CopyButtonMessages>;
32
42
  }
33
43
  /**
34
44
  * CodeBlock — source code in Licht Mono 13px, 1.75 line height, `white-space: pre`, tab size 2,
35
45
  * scrolling horizontally rather than wrapping. Give it a height or a max height and the code
36
- * scrolls under the header. Monochrome by default; `highlight` colours it by its `language` in
37
- * the zon theme, inside a `CodeHighlightProvider`.
46
+ * scrolls under the header. With a `language`, it is coloured in the zon theme (Shiki, loaded the
47
+ * first time a block needs it); without one, or with `highlight={false}`, it stays mono.
38
48
  *
39
49
  * A **region** by default (square `surface-container`, part of the page); `variant="card"`
40
50
  * makes it a 20px object for a snippet that stands on its own. An optional header carries a
@@ -4,11 +4,13 @@ import * as React from "react";
4
4
  import { useCodeTokens } from "../lib/code-highlight.js";
5
5
  import { cn } from "../lib/cn.js";
6
6
  import { CopyButton } from "./copy-button.js";
7
+ import { useMessages } from "./locale.js";
8
+ const defaultMessages = { copy: "Copy code" };
7
9
  /**
8
10
  * CodeBlock — source code in Licht Mono 13px, 1.75 line height, `white-space: pre`, tab size 2,
9
11
  * scrolling horizontally rather than wrapping. Give it a height or a max height and the code
10
- * scrolls under the header. Monochrome by default; `highlight` colours it by its `language` in
11
- * the zon theme, inside a `CodeHighlightProvider`.
12
+ * scrolls under the header. With a `language`, it is coloured in the zon theme (Shiki, loaded the
13
+ * first time a block needs it); without one, or with `highlight={false}`, it stays mono.
12
14
  *
13
15
  * A **region** by default (square `surface-container`, part of the page); `variant="card"`
14
16
  * makes it a 20px object for a snippet that stands on its own. An optional header carries a
@@ -16,26 +18,66 @@ import { CopyButton } from "./copy-button.js";
16
18
  * people break: a theme of their own. Syntax colours are kinds of token, so they come from the
17
19
  * category tones (`--code-*`), never a palette brought in from an editor.
18
20
  */
19
- export function CodeBlock({ code, children, variant = "region", filename, language, lineNumbers = false, wrap = false, highlight = false, copyable = true, labels, className, ...props }) {
21
+ export function CodeBlock({ code, children, variant = "region", filename, language, lineNumbers = false, wrap = false, highlight = true, copyable = true, labels, className, ...props }) {
20
22
  const source = (code ?? children ?? "").replace(/\n$/, "");
21
23
  const { tokens, pending } = useCodeTokens(source, language, highlight);
22
- const lines = React.useMemo(() => (tokens ? tokens.map(renderTokens) : source.split("\n")), [tokens, source]);
24
+ const lines = React.useMemo(() => {
25
+ if (!tokens)
26
+ return source.split("\n");
27
+ const drawn = tokens.map(renderTokens);
28
+ // Long code takes its colours from the top down: the lines not coloured yet stay plain.
29
+ if (drawn.length > 0 && source.length > 0) {
30
+ const plain = source.split("\n");
31
+ for (let i = drawn.length; i < plain.length; i++)
32
+ drawn.push(plain[i]);
33
+ }
34
+ return drawn;
35
+ }, [tokens, source]);
36
+ const chunked = lines.length > CHUNKED_FROM;
37
+ const widest = React.useMemo(() => chunked && !wrap
38
+ ? source.split("\n").reduce((max, line) => Math.max(max, line.replace(/\t/g, " ").length), 0)
39
+ : 0, [chunked, wrap, source]);
23
40
  const hasHeader = filename != null || language != null;
24
- const copyButton = copyable && (_jsx(CopyButton, { value: source, labels: { ...labels, copy: labels?.copy ?? "Copy code" }, "data-slot": "code-block-copy", className: cn(!hasHeader && "absolute top-3 right-3 z-10") }));
25
- return (_jsxs("figure", { "data-slot": "code-block", "data-variant": variant, "data-highlighted": tokens ? "" : undefined, "data-highlight-pending": pending ? "" : undefined, className: cn("relative m-0 flex min-w-0 flex-col overflow-hidden text-foreground", variant === "card" ? "surface-card [--card-padding:0]" : "rounded-none surface-container", className), ...props, children: [hasHeader && (_jsxs("figcaption", { "data-slot": "code-block-header", className: cn("flex min-h-(--control-h) shrink-0 items-center justify-between gap-3 border-b border-border/60 pl-4",
41
+ const text = useMessages("codeBlock", defaultMessages);
42
+ const copyButton = copyable && (_jsx(CopyButton, { value: source, labels: { ...labels, copy: labels?.copy ?? text.copy }, "data-slot": "code-block-copy", className: cn(!hasHeader && "absolute top-3 right-3 z-10") }));
43
+ return (_jsxs("figure", { "data-slot": "code-block", "data-variant": variant, "data-highlighted": tokens ? "" : undefined, "data-highlight-pending": pending ? "" : undefined, className: cn("relative m-0 flex min-w-0 flex-col overflow-hidden text-foreground", variant === "card" ? "surface-card [--card-padding:0]" : "rounded-none surface-container", className), ...props, children: [hasHeader && (_jsxs("figcaption", { "data-slot": "code-block-header", className: cn("flex min-h-(--control-h) shrink-0 items-center justify-between gap-3 border-b border-border/60 ps-4",
26
44
  // With the copy button, the header is the button plus the same 8px above, below and
27
45
  // to the right, so the button sits as far from the top edge as from the right edge.
28
- copyable ? "py-2 pr-2" : "pr-4"), children: [_jsx("span", { className: "min-w-0 truncate eyebrow text-[11px] tracking-[0.12em] normal-case", children: filename }), _jsxs("span", { className: "flex shrink-0 items-center gap-3", children: [language && _jsx("span", { className: "eyebrow text-[11px]", children: language }), copyButton] })] })), !hasHeader && copyButton, _jsx("pre", { "data-slot": "code-block-pre",
46
+ copyable ? "py-2 pe-2" : "pe-4"), children: [_jsx("span", { className: "min-w-0 truncate eyebrow text-[11px] tracking-[0.12em] normal-case", children: filename }), _jsxs("span", { className: "flex shrink-0 items-center gap-3", children: [language && _jsx("span", { className: "eyebrow text-[11px]", children: language }), copyButton] })] })), !hasHeader && copyButton, _jsx("pre", { "data-slot": "code-block-pre",
29
47
  // Code reads left to right on a right-to-left page too: its brackets and commas stay put.
30
48
  dir: "ltr", tabIndex: 0, className: cn(
31
49
  // A height or max height on the block scrolls the code under the header, both ways.
32
- "m-0 min-h-0 grow overflow-auto bg-transparent px-4 py-4 font-mono text-[13px] leading-[1.75] [tab-size:2] focus-ring", wrap ? "[overflow-wrap:anywhere] whitespace-pre-wrap" : "whitespace-pre", !hasHeader && copyable && "pr-14"), children: _jsx("code", { className: cn("font-[inherit]", lineNumbers && "table min-w-full"), children: lineNumbers
33
- ? lines.map((line, i) => (_jsxs("span", { className: "table-row", children: [_jsx("span", { "aria-hidden": true, className: "table-cell w-[1%] pr-5 text-right text-control-muted tabular-nums select-none", children: i + 1 }), _jsx("span", { className: "table-cell", children: isEmpty(line) ? "\n" : line })] }, i)))
34
- : tokens
35
- ? lines.map((line, i) => (_jsxs(React.Fragment, { children: [i > 0 && "\n", line] }, i)))
36
- : source }) })] }));
50
+ "m-0 min-h-0 grow overflow-auto bg-transparent px-4 py-4 font-mono text-[13px] leading-[1.75] [tab-size:2] focus-ring", wrap ? "[overflow-wrap:anywhere] whitespace-pre-wrap" : "whitespace-pre", !hasHeader && copyable && "pr-14"), children: _jsx("code", { className: cn("font-[inherit]", chunked ? "block" : lineNumbers && "table min-w-full"),
51
+ // Chunks out of view are not laid out: the widest line keeps the width to scroll across.
52
+ style: widest
53
+ ? {
54
+ minWidth: `calc(${widest}ch + ${lineNumbers ? `${String(lines.length).length}ch + 1.25rem` : "0px"})`,
55
+ }
56
+ : undefined, children: chunked
57
+ ? Array.from({ length: Math.ceil(lines.length / CHUNK) }, (_, c) => (_jsx(CodeChunk, { from: c * CHUNK, lines: lines.slice(c * CHUNK, (c + 1) * CHUNK), numbers: lineNumbers ? String(lines.length).length : 0 }, c)))
58
+ : lineNumbers
59
+ ? lines.map((line, i) => (_jsxs("span", { className: "table-row", children: [_jsx("span", { "aria-hidden": true, className: "table-cell w-[1%] pr-5 text-right text-control-muted tabular-nums select-none", children: i + 1 }), _jsx("span", { className: "table-cell", children: isEmpty(line) ? "\n" : line })] }, i)))
60
+ : tokens
61
+ ? lines.map((line, i) => (_jsxs(React.Fragment, { children: [i > 0 && "\n", line] }, i)))
62
+ : source }) })] }));
37
63
  }
38
64
  const isEmpty = (line) => line === "" || (Array.isArray(line) && line.length === 0);
65
+ /** Code longer than this many lines is drawn in chunks of CHUNK lines, each laid out only near the view. */
66
+ const CHUNKED_FROM = 400;
67
+ const CHUNK = 100;
68
+ /**
69
+ * CHUNK lines of a long block, skipped by layout and paint while out of view (they stay in the
70
+ * page: found by the browser's search, selected and copied). Drawn again only when one of its
71
+ * lines changes, as colours arrive.
72
+ */
73
+ const CodeChunk = React.memo(function CodeChunk({ from, lines, numbers }) {
74
+ return (_jsx("span", { "data-slot": "code-block-chunk", className: "block [content-visibility:auto]", style: { containIntrinsicBlockSize: `auto ${lines.length * 1.75}em` }, children: numbers
75
+ ? lines.map((line, i) => (_jsxs("span", { className: "flex", children: [_jsx("span", { "aria-hidden": true, className: "shrink-0 pr-5 text-right text-control-muted tabular-nums select-none", style: { width: `calc(${numbers}ch + 1.25rem)` }, children: from + i + 1 }), _jsx("span", { children: isEmpty(line) ? "\n" : line })] }, i)))
76
+ : lines.map((line, i) => (_jsxs(React.Fragment, { children: [i > 0 && "\n", line] }, i))) }));
77
+ }, (a, b) => a.from === b.from &&
78
+ a.numbers === b.numbers &&
79
+ a.lines.length === b.lines.length &&
80
+ a.lines.every((line, i) => line === b.lines[i]));
39
81
  /**
40
82
  * Lines already drawn, by their tokens. The highlighter hands back the same tokens for lines that
41
83
  * did not change (code streaming in), and the same elements let React skip them.
@@ -2,7 +2,7 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { Collapsible as BaseCollapsible } from "@base-ui/react/collapsible";
4
4
  import { ChevronRightIcon } from "lucide-react";
5
- import { sx } from "../lib/cn.js";
5
+ import { sx, triggerSlot } from "../lib/cn.js";
6
6
  /**
7
7
  * Collapsible — one region that can be shown and hidden by a trigger.
8
8
  *
@@ -18,7 +18,7 @@ export function Collapsible({ className, ...props }) {
18
18
  }
19
19
  /** A mono text trigger with a rotating chevron. Use `render` to swap in a `Button`. */
20
20
  export function CollapsibleTrigger({ showIcon = true, className, children, ...props }) {
21
- return (_jsxs(BaseCollapsible.Trigger, { "data-slot": "collapsible-trigger", className: sx([
21
+ return (_jsxs(BaseCollapsible.Trigger, { ...triggerSlot("collapsible-trigger", props.render), className: sx([
22
22
  "group/collapsible-trigger inline-flex w-fit cursor-pointer items-center gap-2 py-1 font-mono text-[13px] text-foreground-soft focus-ring select-none",
23
23
  "transition-colors duration-(--duration) ease-(--ease) hover:text-foreground data-panel-open:text-foreground",
24
24
  "data-disabled:pointer-events-none data-disabled:opacity-50",
@@ -1,5 +1,28 @@
1
1
  import * as React from "react";
2
2
  import { type PopoverContentProps } from "./popover.js";
3
+ export interface ColorPickerMessages {
4
+ /** The saturation × brightness area's name. */
5
+ area: string;
6
+ /** What screen readers call the area instead of "slider". */
7
+ areaRole: string;
8
+ /** The area's value, read out as it moves. */
9
+ areaValue: (saturation: number, brightness: number) => string;
10
+ /** The hue slider. */
11
+ hue: string;
12
+ /** The opacity slider. */
13
+ alpha: string;
14
+ /** The text field's name, by the format it writes. */
15
+ value: (format: ColorFormat) => string;
16
+ /** The group of preset swatches. */
17
+ presets: string;
18
+ /** ColorPicker's trigger while there is no colour. */
19
+ placeholder: string;
20
+ }
21
+ declare module "./locale" {
22
+ interface Messages {
23
+ colorPicker: ColorPickerMessages;
24
+ }
25
+ }
3
26
  export type ColorFormat = "hex" | "rgb" | "hsl" | "oklch";
4
27
  export type ColorPickerPreset = string | {
5
28
  value: string;
@@ -18,13 +41,12 @@ export interface ColorPickerPanelProps extends Omit<React.ComponentProps<"div">,
18
41
  /** Colours to pick in one click, under the value: values, or `{ value, label }` with a name. */
19
42
  presets?: ColorPickerPreset[];
20
43
  disabled?: boolean;
21
- /** Accessible names for the parts. */
22
- labels?: {
23
- area?: string;
24
- hue?: string;
25
- alpha?: string;
44
+ /**
45
+ * Accessible names for the parts — `input` names the text field whatever its format. A
46
+ * LocaleProvider sets them for every picker (`messages.colorPicker`).
47
+ */
48
+ labels?: Partial<ColorPickerMessages> & {
26
49
  input?: string;
27
- presets?: string;
28
50
  };
29
51
  }
30
52
  /**
@@ -45,7 +67,7 @@ export interface ColorSwatchProps extends React.ComponentProps<"span"> {
45
67
  export declare function ColorSwatch({ color, className, style, ...props }: ColorSwatchProps): React.JSX.Element;
46
68
  declare const triggerSizes: {
47
69
  readonly sm: "min-h-(--control-h-sm) gap-2 px-2.5 text-xs";
48
- readonly default: "min-h-(--control-h) gap-2.5 pr-2.5 pl-2.5 text-[13px]";
70
+ readonly default: "min-h-(--control-h) gap-2.5 px-2.5 text-[13px]";
49
71
  };
50
72
  export interface ColorPickerProps extends Pick<ColorPickerPanelProps, "value" | "defaultValue" | "onValueChange" | "format" | "alpha" | "presets" | "disabled" | "labels"> {
51
73
  /** `sm` (30px) for dense surfaces; `default` (38px) everywhere else. */
@@ -58,7 +80,7 @@ export interface ColorPickerProps extends Pick<ColorPickerPanelProps, "value" |
58
80
  */
59
81
  required?: boolean;
60
82
  id?: string;
61
- /** Shown in the trigger while there is no value. */
83
+ /** Shown in the trigger while there is no value. Default `labels.placeholder`. */
62
84
  placeholder?: string;
63
85
  open?: boolean;
64
86
  defaultOpen?: boolean;
@@ -1,12 +1,25 @@
1
1
  "use client";
2
2
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { DirectionProvider } from "@base-ui/react/direction-provider";
3
4
  import { Field as BaseField } from "@base-ui/react/field";
4
5
  import { CheckIcon, ChevronsUpDownIcon } from "lucide-react";
5
6
  import * as React from "react";
6
7
  import { cn, sx } from "../lib/cn.js";
7
8
  import { Input } from "./input.js";
9
+ import { useMessages } from "./locale.js";
8
10
  import { Popover, PopoverContent, PopoverTrigger } from "./popover.js";
9
11
  import { Slider } from "./slider.js";
12
+ const formatNames = { hex: "Hex", rgb: "RGB", hsl: "HSL", oklch: "OKLCH" };
13
+ const defaultMessages = {
14
+ area: "Saturation and brightness",
15
+ areaRole: "2D slider",
16
+ areaValue: (saturation, brightness) => `Saturation ${saturation}%, brightness ${brightness}%`,
17
+ hue: "Hue",
18
+ alpha: "Opacity",
19
+ value: (format) => `${formatNames[format]} value`,
20
+ presets: "Presets",
21
+ placeholder: "Pick a colour",
22
+ };
10
23
  const clamp = (v, min = 0, max = 1) => Math.min(max, Math.max(min, v));
11
24
  const round = (v, digits) => Number(v.toFixed(digits));
12
25
  function hsvToRgb({ h, s, v }) {
@@ -187,7 +200,7 @@ function useColorValue({ value, defaultValue, onValueChange, format, }) {
187
200
  * (Shift, Page Up/Down, Home and End for bigger steps). One focusable thumb with `role="slider"`
188
201
  * carries both values in its text.
189
202
  */
190
- function ColorArea({ color, onChange, disabled, label }) {
203
+ function ColorArea({ color, onChange, disabled, label, text }) {
191
204
  const thumb = React.useRef(null);
192
205
  const move = (event) => {
193
206
  const box = event.currentTarget.getBoundingClientRect();
@@ -231,7 +244,7 @@ function ColorArea({ color, onChange, disabled, label }) {
231
244
  }, onPointerMove: (event) => {
232
245
  if (event.currentTarget.hasPointerCapture(event.pointerId))
233
246
  move(event);
234
- }, children: [_jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-0 rounded-item border border-control-edge shadow-field" }), _jsx("div", { ref: thumb, role: "slider", tabIndex: disabled ? -1 : 0, "aria-label": label, "aria-roledescription": "2D slider", "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": saturation, "aria-valuetext": `Saturation ${saturation}%, brightness ${brightness}%`, "aria-disabled": disabled || undefined, "data-slot": "color-picker-area-thumb", onKeyDown: disabled ? undefined : onKeyDown, className: cn("absolute size-[18px] -translate-x-1/2 -translate-y-1/2 cursor-grab rounded-full border-2 border-white shadow-thumb forced-color-adjust-auto active:cursor-grabbing", "focus-visible:outline-2 focus-visible:outline-offset-0 focus-visible:outline-control-focus", disabled && "cursor-not-allowed"), style: {
247
+ }, children: [_jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-0 rounded-item border border-control-edge shadow-field" }), _jsx("div", { ref: thumb, role: "slider", tabIndex: disabled ? -1 : 0, "aria-label": label, "aria-roledescription": text.areaRole, "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": saturation, "aria-valuetext": text.areaValue(saturation, brightness), "aria-disabled": disabled || undefined, "data-slot": "color-picker-area-thumb", onKeyDown: disabled ? undefined : onKeyDown, className: cn("absolute size-[18px] -translate-x-1/2 -translate-y-1/2 cursor-grab rounded-full border-2 border-white shadow-thumb forced-color-adjust-auto active:cursor-grabbing", "focus-visible:outline-2 focus-visible:outline-offset-0 focus-visible:outline-control-focus", disabled && "cursor-not-allowed"), style: {
235
248
  // Rounded: read from oklch(), the server's maths and the browser's can differ in the
236
249
  // last digits, and the page would not hydrate.
237
250
  left: `${round(color.s * 100, 2)}%`,
@@ -252,12 +265,6 @@ const checker = "repeating-conic-gradient(var(--field-edge) 0 25%, var(--field-s
252
265
  const paintedSlider = cn("[&_[data-slot=slider-control]]:py-0.5", "[&_[data-slot=slider-indicator]]:hidden", "[&_[data-slot=slider-track]]:h-3 [&_[data-slot=slider-track]]:border-control-edge [&_[data-slot=slider-track]]:[background:var(--color-picker-track)]!",
253
266
  // The colours are the content, also in a contrast theme; the thumb keeps the forced colours.
254
267
  "[&_[data-slot=slider-thumb]]:forced-color-adjust-auto [&_[data-slot=slider-track]]:forced-color-adjust-none", "[&_[data-slot=slider-thumb]]:border-2 [&_[data-slot=slider-thumb]]:border-white [&_[data-slot=slider-thumb]]:[background:var(--color-picker-thumb)]!");
255
- const inputLabels = {
256
- hex: "Hex value",
257
- rgb: "RGB value",
258
- hsl: "HSL value",
259
- oklch: "OKLCH value",
260
- };
261
268
  /**
262
269
  * A Field of its own around each of the panel's controls. Base UI's slider and text field join the
263
270
  * Field around them: inside a picker's Field they would take the picker's place as its control (its
@@ -267,6 +274,7 @@ function OwnField({ children }) {
267
274
  return _jsx(BaseField.Root, { className: "contents", children: children });
268
275
  }
269
276
  function PanelBody({ color, text, onColorChange, format = "hex", alpha = false, presets, disabled, labels, className, ...props }) {
277
+ const messages = useMessages("colorPicker", defaultMessages, labels);
270
278
  const [draft, setDraft] = React.useState(text);
271
279
  const [invalid, setInvalid] = React.useState(false);
272
280
  React.useEffect(() => {
@@ -287,13 +295,27 @@ function PanelBody({ color, text, onColorChange, format = "hex", alpha = false,
287
295
  };
288
296
  const opaque = cssColor({ ...color, a: 1 });
289
297
  const hue = Math.round(color.h) % 360;
290
- return (_jsxs("div", { "data-slot": "color-picker-panel", className: cn("flex w-full min-w-0 flex-col gap-3", className), ...props, children: [_jsx(ColorArea, { color: color, onChange: onColorChange, disabled: disabled, label: labels?.area ?? "Saturation and brightness" }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(OwnField, { children: _jsx(Slider, { "data-slot": "color-picker-hue", min: 0, max: 360, step: 1, thumbAlignment: "edge", value: Math.round(color.h), onValueChange: (h) => onColorChange({ ...color, h }), thumbLabels: [labels?.hue ?? "Hue"], disabled: disabled, className: paintedSlider, style: {
291
- "--color-picker-track": hueTrack,
292
- "--color-picker-thumb": `hsl(${hue} 100% 50%)`,
293
- } }) }), alpha && (_jsx(OwnField, { children: _jsx(Slider, { "data-slot": "color-picker-alpha", min: 0, max: 1, step: 0.01, thumbAlignment: "edge", value: color.a, onValueChange: (a) => onColorChange({ ...color, a }), format: { style: "percent" }, thumbLabels: [labels?.alpha ?? "Opacity"], disabled: disabled, className: paintedSlider, style: {
294
- "--color-picker-track": `linear-gradient(to right, transparent, ${opaque}), ${checker}`,
295
- "--color-picker-thumb": `linear-gradient(${cssColor(color)}, ${cssColor(color)}), ${checker}`,
296
- } }) }))] }), _jsx(OwnField, { children: _jsx(Input, { size: "sm", "data-slot": "color-picker-input", "aria-label": labels?.input ?? inputLabels[format], "aria-invalid": invalid || undefined, spellCheck: false, autoComplete: "off", disabled: disabled, value: draft, onChange: (event) => {
298
+ // One swatch per colour: a preset that picks the same colour as an earlier one (`#fff` after
299
+ // `rgb(255 255 255)`, or a translucent one in a picker without `alpha`) is left out, keeping the
300
+ // first one's label. The colour a preset picks, as hex, is its key.
301
+ const swatches = [];
302
+ for (const preset of presets ?? []) {
303
+ const { value, label } = typeof preset === "string" ? { value: preset, label: preset } : preset;
304
+ const parsed = parseColor(value, color);
305
+ if (!parsed)
306
+ continue;
307
+ const picks = alpha ? parsed : { ...parsed, a: 1 };
308
+ const hex = formatColor(picks, "hex");
309
+ if (!swatches.some((s) => s.hex === hex))
310
+ swatches.push({ hex, label, picks });
311
+ }
312
+ return (_jsxs("div", { "data-slot": "color-picker-panel", className: cn("flex w-full min-w-0 flex-col gap-3", className), ...props, children: [_jsx(ColorArea, { color: color, onChange: onColorChange, disabled: disabled, label: messages.area, text: messages }), _jsx(DirectionProvider, { direction: "ltr", children: _jsxs("div", { dir: "ltr", className: "flex flex-col gap-2", children: [_jsx(OwnField, { children: _jsx(Slider, { "data-slot": "color-picker-hue", min: 0, max: 360, step: 1, thumbAlignment: "edge", value: Math.round(color.h), onValueChange: (h) => onColorChange({ ...color, h }), thumbLabels: [messages.hue], disabled: disabled, className: paintedSlider, style: {
313
+ "--color-picker-track": hueTrack,
314
+ "--color-picker-thumb": `hsl(${hue} 100% 50%)`,
315
+ } }) }), alpha && (_jsx(OwnField, { children: _jsx(Slider, { "data-slot": "color-picker-alpha", min: 0, max: 1, step: 0.01, thumbAlignment: "edge", value: color.a, onValueChange: (a) => onColorChange({ ...color, a }), format: { style: "percent" }, thumbLabels: [messages.alpha], disabled: disabled, className: paintedSlider, style: {
316
+ "--color-picker-track": `linear-gradient(to right, transparent, ${opaque}), ${checker}`,
317
+ "--color-picker-thumb": `linear-gradient(${cssColor(color)}, ${cssColor(color)}), ${checker}`,
318
+ } }) }))] }) }), _jsx(OwnField, { children: _jsx(Input, { size: "sm", "data-slot": "color-picker-input", "aria-label": labels?.input ?? messages.value(format), "aria-invalid": invalid || undefined, spellCheck: false, autoComplete: "off", disabled: disabled, value: draft, onChange: (event) => {
297
319
  setDraft(event.target.value);
298
320
  setInvalid(false);
299
321
  }, onBlur: commit, onKeyDown: (event) => {
@@ -312,15 +334,13 @@ function PanelBody({ color, text, onColorChange, format = "hex", alpha = false,
312
334
  setDraft(text);
313
335
  setInvalid(false);
314
336
  }
315
- }, className: "font-mono text-xs tabular-nums" }) }), presets && presets.length > 0 && (_jsx("div", { role: "group", "aria-label": labels?.presets ?? "Presets", "data-slot": "color-picker-presets", className: "flex flex-wrap gap-1", children: presets.map((preset) => {
316
- const { value, label } = typeof preset === "string" ? { value: preset, label: preset } : preset;
317
- const parsed = parseColor(value, color);
318
- if (!parsed)
319
- return null;
320
- const current = formatColor(parsed, "hex") === formatColor(color, "hex");
321
- return (_jsx("button", { type: "button", "aria-label": label, "aria-pressed": current, disabled: disabled, "data-slot": "color-picker-preset", "data-current": current ? "" : undefined, onClick: () => onColorChange(alpha ? parsed : { ...parsed, a: 1 }), className: "grid size-(--control-inset-sm) cursor-pointer place-items-center rounded-checkbox border border-control-edge focus-ring forced-color-adjust-none disabled:cursor-not-allowed disabled:opacity-55 forced-colors:focus-visible:outline-[CanvasText]", style: { background: cssColor(parsed) }, children: current && (_jsx(CheckIcon, { "aria-hidden": true, className: "size-3.5",
337
+ },
338
+ // 16px on a phone, so focusing it doesn't zoom the page (iOS); 12px from `sm` up.
339
+ className: "font-mono text-base tabular-nums sm:text-xs" }) }), swatches.length > 0 && (_jsx("div", { role: "group", "aria-label": messages.presets, "data-slot": "color-picker-presets", className: "flex flex-wrap gap-1", children: swatches.map(({ hex, label, picks }) => {
340
+ const current = hex === formatColor(color, "hex");
341
+ return (_jsx("button", { type: "button", "aria-label": label, "aria-pressed": current, disabled: disabled, "data-slot": "color-picker-preset", "data-current": current ? "" : undefined, onClick: () => onColorChange(picks), className: "grid size-(--control-inset-sm) cursor-pointer place-items-center rounded-item border border-control-edge focus-ring forced-color-adjust-none disabled:cursor-not-allowed disabled:opacity-55 forced-colors:focus-visible:outline-[CanvasText]", style: { background: cssColor(picks) }, children: current && (_jsx(CheckIcon, { "aria-hidden": true, className: "size-3.5",
322
342
  // Colour is the content here: the tick takes whichever ink reads on it.
323
- style: { color: isLight(parsed) ? "oklch(0.2 0 0)" : "oklch(0.98 0 0)" } })) }, value));
343
+ style: { color: isLight(picks) ? "oklch(0.2 0 0)" : "oklch(0.98 0 0)" } })) }, hex));
324
344
  }) }))] }));
325
345
  }
326
346
  /**
@@ -338,12 +358,12 @@ export function ColorPickerPanel({ value, defaultValue, onValueChange, format =
338
358
  * checkerboard so transparency shows. Decorative (`aria-hidden`): say the colour in text beside it.
339
359
  */
340
360
  export function ColorSwatch({ color, className, style, ...props }) {
341
- return (_jsx("span", { "aria-hidden": true, "data-slot": "color-swatch", className: cn("relative inline-block size-4 shrink-0 overflow-hidden rounded-checkbox border border-field-edge forced-color-adjust-none", className), style: { background: checker, ...style }, ...props, children: _jsx("span", { className: "absolute inset-0", style: { background: color } }) }));
361
+ return (_jsx("span", { "aria-hidden": true, "data-slot": "color-swatch", className: cn("relative inline-block size-4 shrink-0 overflow-hidden rounded-checkbox border border-field-edge forced-color-adjust-none", className), style: { background: checker, ...style }, ...props, children: _jsx("span", { "data-slot": "color-swatch-fill", className: "absolute inset-0", style: { background: color } }) }));
342
362
  }
343
363
  /* ── ColorPicker ────────────────────────────────────────────────────────────── */
344
364
  const triggerSizes = {
345
365
  sm: "min-h-(--control-h-sm) gap-2 px-2.5 text-xs",
346
- default: "min-h-(--control-h) gap-2.5 pr-2.5 pl-2.5 text-[13px]",
366
+ default: "min-h-(--control-h) gap-2.5 px-2.5 text-[13px]",
347
367
  };
348
368
  /**
349
369
  * ColorPicker — a recessed trigger like a `Select` trigger, with a swatch and the value in Licht
@@ -355,8 +375,9 @@ const triggerSizes = {
355
375
  * break: a picker for a choice among a few named colours. Those are a `RadioGroup` or a
356
376
  * `ToggleGroup` of tones, with names.
357
377
  */
358
- export function ColorPicker({ value, defaultValue, onValueChange, format = "hex", size = "default", name, required, placeholder = "Pick a colour", open, defaultOpen, onOpenChange, className, popover, disabled, id, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, ...panel }) {
378
+ export function ColorPicker({ value, defaultValue, onValueChange, format = "hex", size = "default", name, required, placeholder, open, defaultOpen, onOpenChange, className, popover, disabled, id, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, ...panel }) {
359
379
  const state = useColorValue({ value, defaultValue, onValueChange, format });
380
+ const text = useMessages("colorPicker", defaultMessages, panel.labels);
360
381
  const empty = state.text === "";
361
382
  const trigger = React.useRef(null);
362
383
  const valueId = React.useId();
@@ -397,7 +418,7 @@ export function ColorPicker({ value, defaultValue, onValueChange, format = "hex"
397
418
  "aria-label": ariaLabel,
398
419
  "aria-labelledby": ariaLabelledBy,
399
420
  "aria-describedby": ariaDescribedBy,
400
- }).filter(([, v]) => v !== undefined)), className: cn("group/trigger inline-flex w-full min-w-40 material-field cursor-pointer items-center rounded-control text-start font-mono leading-none whitespace-nowrap tabular-nums outline-none select-none", "disabled:cursor-not-allowed disabled:opacity-55", triggerSizes[size], className), children: [_jsx(ColorSwatch, { color: empty ? "transparent" : cssColor(state.color), className: size === "sm" ? "size-4" : "size-5" }), _jsx("span", { id: valueId, "data-slot": "color-picker-value", className: cn("flex-1 truncate", empty && "text-control-muted"), children: empty ? placeholder : state.text }), _jsx(ChevronsUpDownIcon, { "aria-hidden": true, className: "size-4 shrink-0 text-muted-foreground transition-colors duration-(--duration) ease-brand group-hover/trigger:not-group-data-disabled/trigger:text-foreground" })] }), _jsx(PopoverContent, { align: "start", ...popover, "data-slot": "color-picker-content", className: sx("p-3", popover?.className), onBlur: (event) => {
421
+ }).filter(([, v]) => v !== undefined)), className: cn("group/trigger inline-flex w-full min-w-40 material-field cursor-pointer items-center rounded-control text-start font-mono leading-none whitespace-nowrap tabular-nums outline-none select-none", "disabled:cursor-not-allowed disabled:opacity-55", triggerSizes[size], className), children: [_jsx(ColorSwatch, { color: empty ? "transparent" : cssColor(state.color), className: size === "sm" ? "size-4" : "size-5" }), _jsx("span", { id: valueId, "data-slot": "color-picker-value", className: cn("flex-1 truncate", empty && "text-control-muted"), children: empty ? (placeholder ?? text.placeholder) : state.text }), _jsx(ChevronsUpDownIcon, { "aria-hidden": true, className: "size-4 shrink-0 text-muted-foreground transition-colors duration-(--duration) ease-brand group-hover/trigger:not-group-data-disabled/trigger:text-foreground" })] }), _jsx(PopoverContent, { align: "start", ...popover, "data-slot": "color-picker-content", className: sx("p-3", popover?.className), onBlur: (event) => {
401
422
  popover?.onBlur?.(event);
402
423
  // Out of the panel, and not back to the trigger: the field is left.
403
424
  const to = event.relatedTarget;
@@ -1,5 +1,18 @@
1
1
  import { Combobox as BaseCombobox } from "@base-ui/react/combobox";
2
2
  import * as React from "react";
3
+ export interface ComboboxMessages {
4
+ /** ComboboxInput's clear button. */
5
+ clear: string;
6
+ /** ComboboxInput's chevron. */
7
+ showOptions: string;
8
+ /** A chip's remove button, by the chip's text when it is a string. */
9
+ remove: (label?: string) => string;
10
+ }
11
+ declare module "./locale" {
12
+ interface Messages {
13
+ combobox: ComboboxMessages;
14
+ }
15
+ }
3
16
  /**
4
17
  * Combobox — a `Select` you can type into: the input filters a fixed list of options.
5
18
  *
@@ -8,7 +21,7 @@ import * as React from "react";
8
21
  * is long enough that scrolling hurts (roughly 15+ options). The rule people break: using it for
9
22
  * free-text search — a combobox only accepts listed values.
10
23
  */
11
- export declare function Combobox<Value, Multiple extends boolean | undefined = false, Item = Value>({ inputRef, ...props }: BaseCombobox.Root.Props<Value, Multiple, Item>): React.JSX.Element;
24
+ export declare function Combobox<Value, Multiple extends boolean | undefined = false, Item = Value>({ inputRef, onItemHighlighted, ...props }: BaseCombobox.Root.Props<Value, Multiple, Item>): React.JSX.Element;
12
25
  declare const groupSizes: {
13
26
  readonly sm: "min-h-(--control-h-sm) gap-0.5 py-0.5 ps-2.5 pe-0.5 text-[13px]";
14
27
  readonly default: "min-h-(--control-h) gap-0.5 py-[3px] ps-3.5 pe-[3px] text-base sm:text-[15px]";
@@ -22,12 +35,14 @@ export interface ComboboxInputProps extends Omit<BaseCombobox.Input.Props, "size
22
35
  showClear?: boolean;
23
36
  /** Classes for the visible field (the input group), not the bare `<input>`. */
24
37
  className?: string;
38
+ /** The buttons' names (`clear`, `showOptions`); a LocaleProvider sets them for every Combobox. */
39
+ labels?: Partial<ComboboxMessages>;
25
40
  }
26
41
  /**
27
42
  * ComboboxInput — the recessed field the user types into, with an optional clear button and
28
43
  * a chevron trigger. Inside `<ComboboxChips>` it renders as the bare text input after the chips.
29
44
  */
30
- export declare function ComboboxInput({ size, showTrigger, showClear, className, ...props }: ComboboxInputProps): React.JSX.Element;
45
+ export declare function ComboboxInput({ size, showTrigger, showClear, className, labels, ...props }: ComboboxInputProps): React.JSX.Element;
31
46
  export interface ComboboxChipsProps<Value = any> extends Omit<BaseCombobox.Chips.Props, "children"> {
32
47
  /**
33
48
  * The chips and a trailing `<ComboboxInput />`. Pass a function to receive the selected
@@ -41,7 +56,10 @@ export interface ComboboxChipsProps<Value = any> extends Omit<BaseCombobox.Chips
41
56
  */
42
57
  export declare function ComboboxChips<Value = any>({ className, children, ...props }: ComboboxChipsProps<Value>): React.JSX.Element;
43
58
  export interface ComboboxChipProps extends BaseCombobox.Chip.Props {
44
- /** Accessible name for the remove button. Defaults to "Remove {label}" for string children. */
59
+ /**
60
+ * Accessible name for the remove button. Defaults to "Remove {label}" for string children
61
+ * (`messages.combobox.remove`).
62
+ */
45
63
  removeLabel?: string;
46
64
  }
47
65
  /** ComboboxChip — one selected value, with a remove button. */