@underpin/ui 0.0.0 → 2.0.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 (259) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -1
  3. package/components/autocomplete.d.ts +25 -0
  4. package/components/autocomplete.js +71 -0
  5. package/components/autocomplete.js.map +1 -0
  6. package/components/avatar.d.ts +5 -0
  7. package/components/avatar.js +26 -0
  8. package/components/avatar.js.map +1 -0
  9. package/components/badge.d.ts +36 -0
  10. package/components/badge.js +140 -0
  11. package/components/badge.js.map +1 -0
  12. package/components/bar-list.d.ts +133 -0
  13. package/components/bar-list.js +204 -0
  14. package/components/bar-list.js.map +1 -0
  15. package/components/breakdown-card.d.ts +30 -0
  16. package/components/breakdown-card.js +43 -0
  17. package/components/breakdown-card.js.map +1 -0
  18. package/components/button-group.d.ts +17 -0
  19. package/components/button-group.js +27 -0
  20. package/components/button-group.js.map +1 -0
  21. package/components/button.d.ts +39 -0
  22. package/components/button.js +128 -0
  23. package/components/button.js.map +1 -0
  24. package/components/calendar.d.ts +27 -0
  25. package/components/calendar.js +95 -0
  26. package/components/calendar.js.map +1 -0
  27. package/components/callout.d.ts +26 -0
  28. package/components/callout.js +71 -0
  29. package/components/callout.js.map +1 -0
  30. package/components/card.d.ts +55 -0
  31. package/components/card.js +96 -0
  32. package/components/card.js.map +1 -0
  33. package/components/chart.d.ts +32 -0
  34. package/components/chart.js +43 -0
  35. package/components/chart.js.map +1 -0
  36. package/components/checkbox.d.ts +15 -0
  37. package/components/checkbox.js +42 -0
  38. package/components/checkbox.js.map +1 -0
  39. package/components/code-block.d.ts +21 -0
  40. package/components/code-block.js +35 -0
  41. package/components/code-block.js.map +1 -0
  42. package/components/collapse.d.ts +14 -0
  43. package/components/collapse.js +25 -0
  44. package/components/collapse.js.map +1 -0
  45. package/components/combobox.d.ts +71 -0
  46. package/components/combobox.js +155 -0
  47. package/components/combobox.js.map +1 -0
  48. package/components/copy-button.d.ts +29 -0
  49. package/components/copy-button.js +100 -0
  50. package/components/copy-button.js.map +1 -0
  51. package/components/copy-input.d.ts +15 -0
  52. package/components/copy-input.js +51 -0
  53. package/components/copy-input.js.map +1 -0
  54. package/components/date-picker-trigger.d.ts +12 -0
  55. package/components/date-picker-trigger.js +30 -0
  56. package/components/date-picker-trigger.js.map +1 -0
  57. package/components/date-picker.d.ts +36 -0
  58. package/components/date-picker.js +70 -0
  59. package/components/date-picker.js.map +1 -0
  60. package/components/detail-row.d.ts +51 -0
  61. package/components/detail-row.js +77 -0
  62. package/components/detail-row.js.map +1 -0
  63. package/components/dialog.d.ts +121 -0
  64. package/components/dialog.js +327 -0
  65. package/components/dialog.js.map +1 -0
  66. package/components/disabled-reason.d.ts +31 -0
  67. package/components/disabled-reason.js +67 -0
  68. package/components/disabled-reason.js.map +1 -0
  69. package/components/empty-state.d.ts +41 -0
  70. package/components/empty-state.js +84 -0
  71. package/components/empty-state.js.map +1 -0
  72. package/components/entity-avatar.d.ts +54 -0
  73. package/components/entity-avatar.js +68 -0
  74. package/components/entity-avatar.js.map +1 -0
  75. package/components/form-section.d.ts +22 -0
  76. package/components/form-section.js +38 -0
  77. package/components/form-section.js.map +1 -0
  78. package/components/form.d.ts +199 -0
  79. package/components/form.js +456 -0
  80. package/components/form.js.map +1 -0
  81. package/components/formatted-number.d.ts +21 -0
  82. package/components/formatted-number.js +13 -0
  83. package/components/formatted-number.js.map +1 -0
  84. package/components/heading.d.ts +23 -0
  85. package/components/heading.js +44 -0
  86. package/components/heading.js.map +1 -0
  87. package/components/icon-swap.d.ts +15 -0
  88. package/components/icon-swap.js +29 -0
  89. package/components/icon-swap.js.map +1 -0
  90. package/components/inline-action.d.ts +21 -0
  91. package/components/inline-action.js +36 -0
  92. package/components/inline-action.js.map +1 -0
  93. package/components/input.d.ts +51 -0
  94. package/components/input.js +52 -0
  95. package/components/input.js.map +1 -0
  96. package/components/kbd.d.ts +17 -0
  97. package/components/kbd.js +34 -0
  98. package/components/kbd.js.map +1 -0
  99. package/components/label.d.ts +10 -0
  100. package/components/label.js +20 -0
  101. package/components/label.js.map +1 -0
  102. package/components/menu.d.ts +77 -0
  103. package/components/menu.js +189 -0
  104. package/components/menu.js.map +1 -0
  105. package/components/nav-button.d.ts +34 -0
  106. package/components/nav-button.js +71 -0
  107. package/components/nav-button.js.map +1 -0
  108. package/components/nav.d.ts +39 -0
  109. package/components/nav.js +68 -0
  110. package/components/nav.js.map +1 -0
  111. package/components/number-input.d.ts +16 -0
  112. package/components/number-input.js +25 -0
  113. package/components/number-input.js.map +1 -0
  114. package/components/page.d.ts +14 -0
  115. package/components/page.js +23 -0
  116. package/components/page.js.map +1 -0
  117. package/components/pagination.d.ts +15 -0
  118. package/components/pagination.js +63 -0
  119. package/components/pagination.js.map +1 -0
  120. package/components/ping.d.ts +38 -0
  121. package/components/ping.js +50 -0
  122. package/components/ping.js.map +1 -0
  123. package/components/popover.d.ts +5 -0
  124. package/components/popover.js +25 -0
  125. package/components/popover.js.map +1 -0
  126. package/components/radio-group.d.ts +35 -0
  127. package/components/radio-group.js +81 -0
  128. package/components/radio-group.js.map +1 -0
  129. package/components/relative-time.d.ts +25 -0
  130. package/components/relative-time.js +51 -0
  131. package/components/relative-time.js.map +1 -0
  132. package/components/saved-mark.d.ts +15 -0
  133. package/components/saved-mark.js +45 -0
  134. package/components/saved-mark.js.map +1 -0
  135. package/components/search-input.d.ts +13 -0
  136. package/components/search-input.js +44 -0
  137. package/components/search-input.js.map +1 -0
  138. package/components/section-header.d.ts +83 -0
  139. package/components/section-header.js +170 -0
  140. package/components/section-header.js.map +1 -0
  141. package/components/segmented-control.d.ts +24 -0
  142. package/components/segmented-control.js +70 -0
  143. package/components/segmented-control.js.map +1 -0
  144. package/components/select.d.ts +28 -0
  145. package/components/select.js +129 -0
  146. package/components/select.js.map +1 -0
  147. package/components/shortcut-keys.d.ts +14 -0
  148. package/components/shortcut-keys.js +32 -0
  149. package/components/shortcut-keys.js.map +1 -0
  150. package/components/shortcuts-dialog.d.ts +10 -0
  151. package/components/shortcuts-dialog.js +92 -0
  152. package/components/shortcuts-dialog.js.map +1 -0
  153. package/components/skeleton.d.ts +8 -0
  154. package/components/skeleton.js +23 -0
  155. package/components/skeleton.js.map +1 -0
  156. package/components/sparkline.d.ts +25 -0
  157. package/components/sparkline.js +70 -0
  158. package/components/sparkline.js.map +1 -0
  159. package/components/stack.d.ts +21 -0
  160. package/components/stack.js +45 -0
  161. package/components/stack.js.map +1 -0
  162. package/components/stat-strip.d.ts +43 -0
  163. package/components/stat-strip.js +151 -0
  164. package/components/stat-strip.js.map +1 -0
  165. package/components/steps.d.ts +19 -0
  166. package/components/steps.js +25 -0
  167. package/components/steps.js.map +1 -0
  168. package/components/switch.d.ts +16 -0
  169. package/components/switch.js +29 -0
  170. package/components/switch.js.map +1 -0
  171. package/components/tabs.d.ts +18 -0
  172. package/components/tabs.js +65 -0
  173. package/components/tabs.js.map +1 -0
  174. package/components/text-link.d.ts +16 -0
  175. package/components/text-link.js +32 -0
  176. package/components/text-link.js.map +1 -0
  177. package/components/textarea.d.ts +10 -0
  178. package/components/textarea.js +23 -0
  179. package/components/textarea.js.map +1 -0
  180. package/components/theme.d.ts +28 -0
  181. package/components/theme.js +158 -0
  182. package/components/theme.js.map +1 -0
  183. package/components/time-series-chart.d.ts +122 -0
  184. package/components/time-series-chart.js +722 -0
  185. package/components/time-series-chart.js.map +1 -0
  186. package/components/toaster.d.ts +3 -0
  187. package/components/toaster.js +44 -0
  188. package/components/toaster.js.map +1 -0
  189. package/components/tooltip.d.ts +64 -0
  190. package/components/tooltip.js +126 -0
  191. package/components/tooltip.js.map +1 -0
  192. package/components/view-picker.d.ts +20 -0
  193. package/components/view-picker.js +24 -0
  194. package/components/view-picker.js.map +1 -0
  195. package/fonts/inter-OFL.txt +93 -0
  196. package/fonts/inter-cyrillic-ext.woff2 +0 -0
  197. package/fonts/inter-cyrillic.woff2 +0 -0
  198. package/fonts/inter-greek-ext.woff2 +0 -0
  199. package/fonts/inter-greek.woff2 +0 -0
  200. package/fonts/inter-latin-ext.woff2 +0 -0
  201. package/fonts/inter-latin.woff2 +0 -0
  202. package/fonts/inter-vietnamese.woff2 +0 -0
  203. package/fonts.css +83 -0
  204. package/lib/animation.d.ts +14 -0
  205. package/lib/animation.js +20 -0
  206. package/lib/animation.js.map +1 -0
  207. package/lib/aria.d.ts +5 -0
  208. package/lib/aria.js +12 -0
  209. package/lib/aria.js.map +1 -0
  210. package/lib/chart-curve.d.ts +13 -0
  211. package/lib/chart-curve.js +79 -0
  212. package/lib/chart-curve.js.map +1 -0
  213. package/lib/classes.d.ts +134 -0
  214. package/lib/classes.js +152 -0
  215. package/lib/classes.js.map +1 -0
  216. package/lib/color.d.ts +25 -0
  217. package/lib/color.js +149 -0
  218. package/lib/color.js.map +1 -0
  219. package/lib/day.d.ts +9 -0
  220. package/lib/day.js +20 -0
  221. package/lib/day.js.map +1 -0
  222. package/lib/design-tokens.d.ts +56 -0
  223. package/lib/design-tokens.js +196 -0
  224. package/lib/design-tokens.js.map +1 -0
  225. package/lib/icon.d.ts +17 -0
  226. package/lib/icon.js +34 -0
  227. package/lib/icon.js.map +1 -0
  228. package/lib/icons.d.ts +23 -0
  229. package/lib/icons.js +28 -0
  230. package/lib/icons.js.map +1 -0
  231. package/lib/interactive.d.ts +21 -0
  232. package/lib/interactive.js +31 -0
  233. package/lib/interactive.js.map +1 -0
  234. package/lib/media.d.ts +58 -0
  235. package/lib/media.js +116 -0
  236. package/lib/media.js.map +1 -0
  237. package/lib/segmented.d.ts +57 -0
  238. package/lib/segmented.js +83 -0
  239. package/lib/segmented.js.map +1 -0
  240. package/lib/shortcuts.d.ts +94 -0
  241. package/lib/shortcuts.js +271 -0
  242. package/lib/shortcuts.js.map +1 -0
  243. package/lib/slot.d.ts +9 -0
  244. package/lib/slot.js +18 -0
  245. package/lib/slot.js.map +1 -0
  246. package/lib/time-series.d.ts +100 -0
  247. package/lib/time-series.js +144 -0
  248. package/lib/time-series.js.map +1 -0
  249. package/lib/tone.d.ts +6 -0
  250. package/lib/tone.js +0 -0
  251. package/lib/variants.d.ts +12 -0
  252. package/lib/variants.js +14 -0
  253. package/lib/variants.js.map +1 -0
  254. package/package.json +110 -3
  255. package/styles.css +619 -0
  256. package/tokens.d.ts +104 -0
  257. package/tokens.js +108 -0
  258. package/tokens.js.map +1 -0
  259. package/publish.log +0 -1
@@ -0,0 +1,25 @@
1
+ import { cn } from "../lib/variants.js";
2
+ import { jsx } from "react/jsx-runtime";
3
+ // src/components/collapse.tsx
4
+ /**
5
+ * Content grown to its own height or folded to nothing, animated both ways. It stays mounted
6
+ * so closing animates too, and the `0fr`/`1fr` grid row is what makes an unknown height
7
+ * animatable at all. It is `inert` while folded, since zero height hides it from the eye and
8
+ * nothing else. Reduced motion keeps the fade and snaps the height. The clipping box reaches
9
+ * one pixel past the content on every side, since a focus outline is drawn past a control's box
10
+ * and a flush clip would cut it off.
11
+ */
12
+ function Collapse({ open, className, children, ...props }) {
13
+ return /* @__PURE__ */ jsx("div", {
14
+ inert: !open,
15
+ className: cn("grid transition-[grid-template-rows,opacity] duration-250 ease-out-expo", "motion-reduce:transition-[opacity] motion-reduce:duration-150", open ? "grid-rows-[1fr] opacity-100" : "grid-rows-[0fr] opacity-0", className),
16
+ ...props,
17
+ children: /* @__PURE__ */ jsx("div", {
18
+ className: "-m-px min-h-0 overflow-hidden p-px",
19
+ children
20
+ })
21
+ });
22
+ }
23
+ export { Collapse };
24
+
25
+ //# sourceMappingURL=collapse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collapse.js","names":[],"sources":["../../src/components/collapse.tsx"],"sourcesContent":["import type { ComponentProps } from \"react\"\nimport { cn } from \"../lib/variants\"\n\ninterface CollapseProps extends ComponentProps<\"div\"> {\n open: boolean\n}\n\n/**\n * Content grown to its own height or folded to nothing, animated both ways. It stays mounted\n * so closing animates too, and the `0fr`/`1fr` grid row is what makes an unknown height\n * animatable at all. It is `inert` while folded, since zero height hides it from the eye and\n * nothing else. Reduced motion keeps the fade and snaps the height. The clipping box reaches\n * one pixel past the content on every side, since a focus outline is drawn past a control's box\n * and a flush clip would cut it off.\n */\nexport function Collapse({ open, className, children, ...props }: CollapseProps) {\n return (\n <div\n inert={!open}\n className={cn(\n \"grid transition-[grid-template-rows,opacity] duration-250 ease-out-expo\",\n \"motion-reduce:transition-[opacity] motion-reduce:duration-150\",\n open ? \"grid-rows-[1fr] opacity-100\" : \"grid-rows-[0fr] opacity-0\",\n className,\n )}\n {...props}\n >\n <div className=\"-m-px min-h-0 overflow-hidden p-px\">{children}</div>\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;AAeA,SAAgB,SAAS,EAAE,MAAM,WAAW,UAAU,GAAG,SAAwB;CAC/E,OACE,oBAAC,OAAD;EACE,OAAO,CAAC;EACR,WAAW,GACT,2EACA,iEACA,OAAO,gCAAgC,6BACvC,SACF;EACA,GAAI;EAEJ,UAAA,oBAAC,OAAD;GAAK,WAAU;GAAsC;EAAc,CAAA;CAChE,CAAA;AAET"}
@@ -0,0 +1,71 @@
1
+ import { VariantProps } from "../lib/variants.js";
2
+ import { PasswordManagerProps, inputVariants } from "./input.js";
3
+ import { ReactNode } from "react";
4
+ import { Combobox as Combobox$1 } from "@base-ui/react/combobox";
5
+ /**
6
+ * A text field that filters a list of options. Use a Combobox when the committed value has to
7
+ * be one of the items and typing only narrows them down; use an Autocomplete when the value is
8
+ * whatever the user typed and the list merely suggests completions.
9
+ *
10
+ * The parts cover two layouts. In the popup layout `ComboboxContent` portals the list and
11
+ * anchors it under the input. In the inline layout the list is already inside someone else's
12
+ * surface (a Popover, a Dialog), so `ComboboxContent` is left out and `ComboboxList` follows
13
+ * `ComboboxInput` directly.
14
+ */
15
+ declare const Combobox: typeof Combobox$1.Root;
16
+ declare const ComboboxGroup: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").ComboboxGroupProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
17
+ declare const ComboboxCollection: typeof Combobox$1.Collection;
18
+ interface ComboboxTriggerProps extends Combobox$1.Trigger.Props, Pick<VariantProps<typeof inputVariants>, "size"> {}
19
+ /**
20
+ * The button that opens the list, for a searchable select: the field lives inside the popup and
21
+ * the trigger shows the committed value. Styled as the package's Select trigger, so the two read
22
+ * as one control with and without search.
23
+ */
24
+ declare function ComboboxTrigger({ children, className, size, ...props }: ComboboxTriggerProps): import("react").JSX.Element;
25
+ /**
26
+ * The text field. Styled as the package's Input, so a combobox sitting next to a plain field in
27
+ * a form row is the same control with a list behind it. The native `size` attribute is dropped
28
+ * in favour of the Input's size variant: a character count is meaningless on a control this
29
+ * package always stretches to its container.
30
+ */
31
+ declare function ComboboxInput({ className, interactive, size, allowPasswordManager, ...props }: Omit<Combobox$1.Input.Props, "size"> & VariantProps<typeof inputVariants> & PasswordManagerProps): import("react").JSX.Element;
32
+ /**
33
+ * The popup the options appear in, for the popup layout only. Holds a `ComboboxList` and,
34
+ * optionally, a `ComboboxEmpty` or `ComboboxStatus` beside it. Both have to be the list's sibling
35
+ * to know whether it is empty. Sized to at least its anchor, so the popup lines up with
36
+ * the control that opened it but a long label still gets the width it needs.
37
+ */
38
+ declare function ComboboxContent({ className, children, align, side, sideOffset, ...props }: Combobox$1.Popup.Props & Pick<Combobox$1.Positioner.Props, "align" | "side" | "sideOffset">): import("react").JSX.Element;
39
+ /**
40
+ * The scroller around the items. Takes them as children, or as a function called with each of
41
+ * the root's (filtered) `items`. The second form is what keeps a long list virtual.
42
+ *
43
+ * Renders standalone as well as inside a `ComboboxContent`: with no positioner above it the list
44
+ * registers itself as the anchor, which is how the inline layout works without a `Popup` or a
45
+ * `Positioner`. Nothing sets `--available-height` in that layout, so the height falls back to a
46
+ * fixed cap that keeps the list scrolling inside whatever surface holds it. A Popover's own
47
+ * positioner does set the variable, and it reaches a list inside the popover: give that list a
48
+ * `max-h` of its own, or it grows to the whole room and the popover overflows it by the height
49
+ * of everything else it holds.
50
+ */
51
+ declare function ComboboxList({ className, ...props }: Combobox$1.List.Props): import("react").JSX.Element;
52
+ /**
53
+ * One option. `prefix` leads the label with a glyph that tells the row apart at a glance;
54
+ * `suffix` fills the trailing edge, for the count or shortcut that belongs to the row rather
55
+ * than to its label. The selected option ends in a check, as in a `Select`.
56
+ */
57
+ declare function ComboboxItem({ className, children, prefix, suffix, ...props }: Omit<Combobox$1.Item.Props, "prefix"> & {
58
+ prefix?: ReactNode;
59
+ suffix?: ReactNode;
60
+ }): import("react").JSX.Element;
61
+ declare function ComboboxGroupLabel({ className, ...props }: Combobox$1.GroupLabel.Props): import("react").JSX.Element;
62
+ declare function ComboboxSeparator({ className, ...props }: Combobox$1.Separator.Props): import("react").JSX.Element;
63
+ /** Stands in for the list while nothing matches the query; renders nothing when something does. */
64
+ declare function ComboboxEmpty({ className, ...props }: Combobox$1.Empty.Props): import("react").JSX.Element;
65
+ /**
66
+ * A line for the state of an asynchronously loaded list, announced politely as it changes. Its
67
+ * element has to stay mounted for screen readers to catch that change, so render it
68
+ * unconditionally and vary its children instead; it collapses to nothing while it has none.
69
+ */
70
+ declare function ComboboxStatus({ className, ...props }: Combobox$1.Status.Props): import("react").JSX.Element;
71
+ export { Combobox, ComboboxCollection, ComboboxContent, ComboboxEmpty, ComboboxGroup, ComboboxGroupLabel, ComboboxInput, ComboboxItem, ComboboxList, ComboboxSeparator, ComboboxStatus, ComboboxTrigger };
@@ -0,0 +1,155 @@
1
+ "use client";
2
+ import { popoverAnimationClasses, popupEmptyClasses, popupGroupLabelClasses, popupItemClasses, popupSeparatorClasses, popupSurfaceClasses } from "../lib/classes.js";
3
+ import { CheckIcon, ChevronsUpDownIcon } from "../lib/icons.js";
4
+ import { cn } from "../lib/variants.js";
5
+ import { inputVariants, passwordManagerAttributes } from "./input.js";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ import { Combobox as Combobox$1 } from "@base-ui/react/combobox";
8
+ // src/components/combobox.tsx
9
+ /**
10
+ * A text field that filters a list of options. Use a Combobox when the committed value has to
11
+ * be one of the items and typing only narrows them down; use an Autocomplete when the value is
12
+ * whatever the user typed and the list merely suggests completions.
13
+ *
14
+ * The parts cover two layouts. In the popup layout `ComboboxContent` portals the list and
15
+ * anchors it under the input. In the inline layout the list is already inside someone else's
16
+ * surface (a Popover, a Dialog), so `ComboboxContent` is left out and `ComboboxList` follows
17
+ * `ComboboxInput` directly.
18
+ */
19
+ const Combobox = Combobox$1.Root;
20
+ const ComboboxGroup = Combobox$1.Group;
21
+ const ComboboxCollection = Combobox$1.Collection;
22
+ /**
23
+ * The button that opens the list, for a searchable select: the field lives inside the popup and
24
+ * the trigger shows the committed value. Styled as the package's Select trigger, so the two read
25
+ * as one control with and without search.
26
+ */
27
+ function ComboboxTrigger({ children, className, size, ...props }) {
28
+ return /* @__PURE__ */ jsxs(Combobox$1.Trigger, {
29
+ className: cn(inputVariants({
30
+ interactive: true,
31
+ size
32
+ }), "flex items-center justify-between", className),
33
+ ...props,
34
+ children: [/* @__PURE__ */ jsx("span", {
35
+ className: "flex min-w-0 items-center gap-2 truncate",
36
+ children
37
+ }), /* @__PURE__ */ jsx(Combobox$1.Icon, { render: /* @__PURE__ */ jsx(ChevronsUpDownIcon, { className: "ml-1 size-3.5 shrink-0 text-ink-muted" }) })]
38
+ });
39
+ }
40
+ /**
41
+ * The text field. Styled as the package's Input, so a combobox sitting next to a plain field in
42
+ * a form row is the same control with a list behind it. The native `size` attribute is dropped
43
+ * in favour of the Input's size variant: a character count is meaningless on a control this
44
+ * package always stretches to its container.
45
+ */
46
+ function ComboboxInput({ className, interactive, size, allowPasswordManager, ...props }) {
47
+ return /* @__PURE__ */ jsx(Combobox$1.Input, {
48
+ className: cn(inputVariants({
49
+ interactive,
50
+ size
51
+ }), className),
52
+ ...passwordManagerAttributes(allowPasswordManager),
53
+ ...props
54
+ });
55
+ }
56
+ /**
57
+ * The popup the options appear in, for the popup layout only. Holds a `ComboboxList` and,
58
+ * optionally, a `ComboboxEmpty` or `ComboboxStatus` beside it. Both have to be the list's sibling
59
+ * to know whether it is empty. Sized to at least its anchor, so the popup lines up with
60
+ * the control that opened it but a long label still gets the width it needs.
61
+ */
62
+ function ComboboxContent({ className, children, align, side, sideOffset = 6, ...props }) {
63
+ return /* @__PURE__ */ jsx(Combobox$1.Portal, { children: /* @__PURE__ */ jsx(Combobox$1.Positioner, {
64
+ sideOffset,
65
+ align,
66
+ side,
67
+ className: "isolate z-50",
68
+ children: /* @__PURE__ */ jsx(Combobox$1.Popup, {
69
+ className: cn(popupSurfaceClasses, "relative z-50 isolate max-h-(--available-height) min-w-(--anchor-width) overflow-hidden outline-none", popoverAnimationClasses, className),
70
+ ...props,
71
+ children
72
+ })
73
+ }) });
74
+ }
75
+ /**
76
+ * The scroller around the items. Takes them as children, or as a function called with each of
77
+ * the root's (filtered) `items`. The second form is what keeps a long list virtual.
78
+ *
79
+ * Renders standalone as well as inside a `ComboboxContent`: with no positioner above it the list
80
+ * registers itself as the anchor, which is how the inline layout works without a `Popup` or a
81
+ * `Positioner`. Nothing sets `--available-height` in that layout, so the height falls back to a
82
+ * fixed cap that keeps the list scrolling inside whatever surface holds it. A Popover's own
83
+ * positioner does set the variable, and it reaches a list inside the popover: give that list a
84
+ * `max-h` of its own, or it grows to the whole room and the popover overflows it by the height
85
+ * of everything else it holds.
86
+ */
87
+ function ComboboxList({ className, ...props }) {
88
+ return /* @__PURE__ */ jsx(Combobox$1.List, {
89
+ className: cn("max-h-[var(--available-height,18rem)] overflow-y-auto overscroll-contain p-1", className),
90
+ ...props
91
+ });
92
+ }
93
+ /**
94
+ * One option. `prefix` leads the label with a glyph that tells the row apart at a glance;
95
+ * `suffix` fills the trailing edge, for the count or shortcut that belongs to the row rather
96
+ * than to its label. The selected option ends in a check, as in a `Select`.
97
+ */
98
+ function ComboboxItem({ className, children, prefix, suffix, ...props }) {
99
+ return /* @__PURE__ */ jsxs(Combobox$1.Item, {
100
+ className: cn(popupItemClasses, "group/choice w-full gap-2 px-2", className),
101
+ ...props,
102
+ children: [
103
+ prefix != null && /* @__PURE__ */ jsx("span", {
104
+ className: "flex shrink-0 text-ink-muted [&>svg]:size-4",
105
+ children: prefix
106
+ }),
107
+ /* @__PURE__ */ jsx("span", {
108
+ className: "truncate",
109
+ children
110
+ }),
111
+ suffix != null && /* @__PURE__ */ jsx("span", {
112
+ className: "ml-auto text-ink-muted tabular-nums",
113
+ children: suffix
114
+ }),
115
+ /* @__PURE__ */ jsx("span", {
116
+ "aria-hidden": true,
117
+ className: "ml-auto hidden shrink-0 pl-4 text-ink-muted group-data-selected/choice:flex",
118
+ children: /* @__PURE__ */ jsx(Combobox$1.ItemIndicator, { children: /* @__PURE__ */ jsx(CheckIcon, { className: "size-4" }) })
119
+ })
120
+ ]
121
+ });
122
+ }
123
+ function ComboboxGroupLabel({ className, ...props }) {
124
+ return /* @__PURE__ */ jsx(Combobox$1.GroupLabel, {
125
+ className: cn(popupGroupLabelClasses, className),
126
+ ...props
127
+ });
128
+ }
129
+ function ComboboxSeparator({ className, ...props }) {
130
+ return /* @__PURE__ */ jsx(Combobox$1.Separator, {
131
+ className: cn(popupSeparatorClasses, className),
132
+ ...props
133
+ });
134
+ }
135
+ /** Stands in for the list while nothing matches the query; renders nothing when something does. */
136
+ function ComboboxEmpty({ className, ...props }) {
137
+ return /* @__PURE__ */ jsx(Combobox$1.Empty, {
138
+ className: cn(popupEmptyClasses, className),
139
+ ...props
140
+ });
141
+ }
142
+ /**
143
+ * A line for the state of an asynchronously loaded list, announced politely as it changes. Its
144
+ * element has to stay mounted for screen readers to catch that change, so render it
145
+ * unconditionally and vary its children instead; it collapses to nothing while it has none.
146
+ */
147
+ function ComboboxStatus({ className, ...props }) {
148
+ return /* @__PURE__ */ jsx(Combobox$1.Status, {
149
+ className: cn(popupEmptyClasses, className),
150
+ ...props
151
+ });
152
+ }
153
+ export { Combobox, ComboboxCollection, ComboboxContent, ComboboxEmpty, ComboboxGroup, ComboboxGroupLabel, ComboboxInput, ComboboxItem, ComboboxList, ComboboxSeparator, ComboboxStatus, ComboboxTrigger };
154
+
155
+ //# sourceMappingURL=combobox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combobox.js","names":["ComboboxPrimitive"],"sources":["../../src/components/combobox.tsx"],"sourcesContent":["\"use client\"\n\nimport { Combobox as ComboboxPrimitive } from \"@base-ui/react/combobox\"\nimport type { ReactNode } from \"react\"\nimport {\n POPUP_SIDE_OFFSET,\n popoverAnimationClasses,\n popupEmptyClasses,\n popupGroupLabelClasses,\n popupItemClasses,\n popupSeparatorClasses,\n popupSurfaceClasses,\n} from \"../lib/classes\"\nimport { CheckIcon, ChevronsUpDownIcon } from \"../lib/icons\"\nimport { cn, type VariantProps } from \"../lib/variants\"\nimport { inputVariants, passwordManagerAttributes, type PasswordManagerProps } from \"./input\"\n\n/**\n * A text field that filters a list of options. Use a Combobox when the committed value has to\n * be one of the items and typing only narrows them down; use an Autocomplete when the value is\n * whatever the user typed and the list merely suggests completions.\n *\n * The parts cover two layouts. In the popup layout `ComboboxContent` portals the list and\n * anchors it under the input. In the inline layout the list is already inside someone else's\n * surface (a Popover, a Dialog), so `ComboboxContent` is left out and `ComboboxList` follows\n * `ComboboxInput` directly.\n */\nconst Combobox = ComboboxPrimitive.Root\nconst ComboboxGroup = ComboboxPrimitive.Group\nconst ComboboxCollection = ComboboxPrimitive.Collection\n\ninterface ComboboxTriggerProps\n extends ComboboxPrimitive.Trigger.Props, Pick<VariantProps<typeof inputVariants>, \"size\"> {}\n\n/**\n * The button that opens the list, for a searchable select: the field lives inside the popup and\n * the trigger shows the committed value. Styled as the package's Select trigger, so the two read\n * as one control with and without search.\n */\nfunction ComboboxTrigger({ children, className, size, ...props }: ComboboxTriggerProps) {\n return (\n <ComboboxPrimitive.Trigger\n className={cn(\n inputVariants({ interactive: true, size }),\n \"flex items-center justify-between\",\n className,\n )}\n {...props}\n >\n <span className=\"flex min-w-0 items-center gap-2 truncate\">{children}</span>\n <ComboboxPrimitive.Icon\n render={<ChevronsUpDownIcon className=\"ml-1 size-3.5 shrink-0 text-ink-muted\" />}\n />\n </ComboboxPrimitive.Trigger>\n )\n}\n\n/**\n * The text field. Styled as the package's Input, so a combobox sitting next to a plain field in\n * a form row is the same control with a list behind it. The native `size` attribute is dropped\n * in favour of the Input's size variant: a character count is meaningless on a control this\n * package always stretches to its container.\n */\nfunction ComboboxInput({\n className,\n interactive,\n size,\n allowPasswordManager,\n ...props\n}: Omit<ComboboxPrimitive.Input.Props, \"size\"> &\n VariantProps<typeof inputVariants> &\n PasswordManagerProps) {\n return (\n <ComboboxPrimitive.Input\n // Merged outside `variants`, which cannot take Base UI's state-function `className`.\n className={cn(inputVariants({ interactive, size }), className)}\n {...passwordManagerAttributes(allowPasswordManager)}\n {...props}\n />\n )\n}\n\n/**\n * The popup the options appear in, for the popup layout only. Holds a `ComboboxList` and,\n * optionally, a `ComboboxEmpty` or `ComboboxStatus` beside it. Both have to be the list's sibling\n * to know whether it is empty. Sized to at least its anchor, so the popup lines up with\n * the control that opened it but a long label still gets the width it needs.\n */\nfunction ComboboxContent({\n className,\n children,\n align,\n side,\n sideOffset = POPUP_SIDE_OFFSET,\n ...props\n}: ComboboxPrimitive.Popup.Props &\n Pick<ComboboxPrimitive.Positioner.Props, \"align\" | \"side\" | \"sideOffset\">) {\n return (\n <ComboboxPrimitive.Portal>\n <ComboboxPrimitive.Positioner\n sideOffset={sideOffset}\n align={align}\n side={side}\n className=\"isolate z-50\"\n >\n <ComboboxPrimitive.Popup\n className={cn(\n popupSurfaceClasses,\n \"relative z-50 isolate max-h-(--available-height) min-w-(--anchor-width) overflow-hidden outline-none\",\n popoverAnimationClasses,\n className,\n )}\n {...props}\n >\n {children}\n </ComboboxPrimitive.Popup>\n </ComboboxPrimitive.Positioner>\n </ComboboxPrimitive.Portal>\n )\n}\n\n/**\n * The scroller around the items. Takes them as children, or as a function called with each of\n * the root's (filtered) `items`. The second form is what keeps a long list virtual.\n *\n * Renders standalone as well as inside a `ComboboxContent`: with no positioner above it the list\n * registers itself as the anchor, which is how the inline layout works without a `Popup` or a\n * `Positioner`. Nothing sets `--available-height` in that layout, so the height falls back to a\n * fixed cap that keeps the list scrolling inside whatever surface holds it. A Popover's own\n * positioner does set the variable, and it reaches a list inside the popover: give that list a\n * `max-h` of its own, or it grows to the whole room and the popover overflows it by the height\n * of everything else it holds.\n */\nfunction ComboboxList({ className, ...props }: ComboboxPrimitive.List.Props) {\n return (\n <ComboboxPrimitive.List\n className={cn(\n \"max-h-[var(--available-height,18rem)] overflow-y-auto overscroll-contain p-1\",\n className,\n )}\n {...props}\n />\n )\n}\n\n/**\n * One option. `prefix` leads the label with a glyph that tells the row apart at a glance;\n * `suffix` fills the trailing edge, for the count or shortcut that belongs to the row rather\n * than to its label. The selected option ends in a check, as in a `Select`.\n */\nfunction ComboboxItem({\n className,\n children,\n prefix,\n suffix,\n ...props\n}: Omit<ComboboxPrimitive.Item.Props, \"prefix\"> & {\n prefix?: ReactNode\n suffix?: ReactNode\n}) {\n return (\n <ComboboxPrimitive.Item\n className={cn(popupItemClasses, \"group/choice w-full gap-2 px-2\", className)}\n {...props}\n >\n {prefix != null && (\n <span className=\"flex shrink-0 text-ink-muted [&>svg]:size-4\">{prefix}</span>\n )}\n {/* Truncation belongs on a child: `text-overflow` has no effect on a flex container,\n so the same classes on the item itself clip a long label without an ellipsis. */}\n <span className=\"truncate\">{children}</span>\n {suffix != null && <span className=\"ml-auto text-ink-muted tabular-nums\">{suffix}</span>}\n <span\n aria-hidden\n className=\"ml-auto hidden shrink-0 pl-4 text-ink-muted group-data-selected/choice:flex\"\n >\n <ComboboxPrimitive.ItemIndicator>\n <CheckIcon className=\"size-4\" />\n </ComboboxPrimitive.ItemIndicator>\n </span>\n </ComboboxPrimitive.Item>\n )\n}\n\nfunction ComboboxGroupLabel({ className, ...props }: ComboboxPrimitive.GroupLabel.Props) {\n return (\n <ComboboxPrimitive.GroupLabel className={cn(popupGroupLabelClasses, className)} {...props} />\n )\n}\n\nfunction ComboboxSeparator({ className, ...props }: ComboboxPrimitive.Separator.Props) {\n return <ComboboxPrimitive.Separator className={cn(popupSeparatorClasses, className)} {...props} />\n}\n\n/** Stands in for the list while nothing matches the query; renders nothing when something does. */\nfunction ComboboxEmpty({ className, ...props }: ComboboxPrimitive.Empty.Props) {\n return <ComboboxPrimitive.Empty className={cn(popupEmptyClasses, className)} {...props} />\n}\n\n/**\n * A line for the state of an asynchronously loaded list, announced politely as it changes. Its\n * element has to stay mounted for screen readers to catch that change, so render it\n * unconditionally and vary its children instead; it collapses to nothing while it has none.\n */\nfunction ComboboxStatus({ className, ...props }: ComboboxPrimitive.Status.Props) {\n return <ComboboxPrimitive.Status className={cn(popupEmptyClasses, className)} {...props} />\n}\n\nexport {\n Combobox,\n ComboboxCollection,\n ComboboxContent,\n ComboboxEmpty,\n ComboboxGroup,\n ComboboxGroupLabel,\n ComboboxInput,\n ComboboxItem,\n ComboboxList,\n ComboboxSeparator,\n ComboboxStatus,\n ComboboxTrigger,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA2BA,MAAM,WAAWA,WAAkB;AACnC,MAAM,gBAAgBA,WAAkB;AACxC,MAAM,qBAAqBA,WAAkB;;;;;;AAU7C,SAAS,gBAAgB,EAAE,UAAU,WAAW,MAAM,GAAG,SAA+B;CACtF,OACE,qBAACA,WAAkB,SAAnB;EACE,WAAW,GACT,cAAc;GAAE,aAAa;GAAM;EAAK,CAAC,GACzC,qCACA,SACF;EACA,GAAI;EANN,UAAA,CAQE,oBAAC,QAAD;GAAM,WAAU;GAA4C;EAAe,CAAA,GAC3E,oBAACA,WAAkB,MAAnB,EACE,QAAQ,oBAAC,oBAAD,EAAoB,WAAU,wCAAyC,CAAA,EAChF,CAAA,CACwB;;AAE/B;;;;;;;AAQA,SAAS,cAAc,EACrB,WACA,aACA,MACA,sBACA,GAAG,SAGmB;CACtB,OACE,oBAACA,WAAkB,OAAnB;EAEE,WAAW,GAAG,cAAc;GAAE;GAAa;EAAK,CAAC,GAAG,SAAS;EAC7D,GAAI,0BAA0B,oBAAoB;EAClD,GAAI;CACL,CAAA;AAEL;;;;;;;AAQA,SAAS,gBAAgB,EACvB,WACA,UACA,OACA,MACA,aAAA,GACA,GAAG,SAEwE;CAC3E,OACE,oBAACA,WAAkB,QAAnB,EAAA,UACE,oBAACA,WAAkB,YAAnB;EACc;EACL;EACD;EACN,WAAU;EAEV,UAAA,oBAACA,WAAkB,OAAnB;GACE,WAAW,GACT,qBACA,wGACA,yBACA,SACF;GACA,GAAI;GAEH;EACsB,CAAA;CACG,CAAA,EACN,CAAA;AAE9B;;;;;;;;;;;;;AAcA,SAAS,aAAa,EAAE,WAAW,GAAG,SAAuC;CAC3E,OACE,oBAACA,WAAkB,MAAnB;EACE,WAAW,GACT,gFACA,SACF;EACA,GAAI;CACL,CAAA;AAEL;;;;;;AAOA,SAAS,aAAa,EACpB,WACA,UACA,QACA,QACA,GAAG,SAIF;CACD,OACE,qBAACA,WAAkB,MAAnB;EACE,WAAW,GAAG,kBAAkB,kCAAkC,SAAS;EAC3E,GAAI;EAFN,UAAA;GAIG,UAAU,QACT,oBAAC,QAAD;IAAM,WAAU;IAA+C,UAAA;GAAa,CAAA;GAI9E,oBAAC,QAAD;IAAM,WAAU;IAAY;GAAe,CAAA;GAC1C,UAAU,QAAQ,oBAAC,QAAD;IAAM,WAAU;IAAuC,UAAA;GAAa,CAAA;GACvF,oBAAC,QAAD;IACE,eAAA;IACA,WAAU;IAEV,UAAA,oBAACA,WAAkB,eAAnB,EAAA,UACE,oBAAC,WAAD,EAAW,WAAU,SAAU,CAAA,EACA,CAAA;GAC7B,CAAA;EACgB;;AAE5B;AAEA,SAAS,mBAAmB,EAAE,WAAW,GAAG,SAA6C;CACvF,OACE,oBAACA,WAAkB,YAAnB;EAA8B,WAAW,GAAG,wBAAwB,SAAS;EAAG,GAAI;CAAQ,CAAA;AAEhG;AAEA,SAAS,kBAAkB,EAAE,WAAW,GAAG,SAA4C;CACrF,OAAO,oBAACA,WAAkB,WAAnB;EAA6B,WAAW,GAAG,uBAAuB,SAAS;EAAG,GAAI;CAAQ,CAAA;AACnG;;AAGA,SAAS,cAAc,EAAE,WAAW,GAAG,SAAwC;CAC7E,OAAO,oBAACA,WAAkB,OAAnB;EAAyB,WAAW,GAAG,mBAAmB,SAAS;EAAG,GAAI;CAAQ,CAAA;AAC3F;;;;;;AAOA,SAAS,eAAe,EAAE,WAAW,GAAG,SAAyC;CAC/E,OAAO,oBAACA,WAAkB,QAAnB;EAA0B,WAAW,GAAG,mBAAmB,SAAS;EAAG,GAAI;CAAQ,CAAA;AAC5F"}
@@ -0,0 +1,29 @@
1
+ import { Button } from "./button.js";
2
+ import { ComponentProps, ReactNode } from "react";
3
+ interface CopyButtonProps extends Omit<ComponentProps<typeof Button>, "prefix" | "onClick" | "children"> {
4
+ value: string;
5
+ /**
6
+ * Visible label. Left out, the button is icon-only with a tooltip.
7
+ */
8
+ label?: ReactNode;
9
+ /**
10
+ * What the label reads while the copied state is showing.
11
+ */
12
+ copiedLabel?: ReactNode;
13
+ /**
14
+ * What the label reads when the browser refused the copy.
15
+ */
16
+ failedLabel?: ReactNode;
17
+ tooltip?: ReactNode;
18
+ /** Runs once the value is on the clipboard, e.g. to say where to paste it. */
19
+ onCopy?: () => void;
20
+ /** Runs when the browser refuses the copy, e.g. to select the text for a copy by hand. */
21
+ onCopyError?: () => void;
22
+ }
23
+ /**
24
+ * Copies `value` to the clipboard and swaps its icon to a check for a couple of seconds, or to a
25
+ * cross with "Copy failed" when the browser refuses. Owns the tooltip so the outcome survives the
26
+ * tooltip closing on click.
27
+ */
28
+ export declare function CopyButton({ value, label, copiedLabel, failedLabel, tooltip, onCopy, onCopyError, className, ...props }: CopyButtonProps): import("react").JSX.Element;
29
+ export {};
@@ -0,0 +1,100 @@
1
+ "use client";
2
+ import { CancelIcon, CheckIcon, CopyIcon } from "../lib/icons.js";
3
+ import { cn } from "../lib/variants.js";
4
+ import { Button } from "./button.js";
5
+ import { IconSwap } from "./icon-swap.js";
6
+ import { Tooltip } from "./tooltip.js";
7
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
+ import { useCallback, useEffect, useRef, useState } from "react";
9
+ // src/components/copy-button.tsx
10
+ /**
11
+ * Copies text to the clipboard and shows how it went for `timeout` ms, then goes back to idle.
12
+ * Resolves to whether the copy took. A tiny local stand-in for `@mantine/hooks`'
13
+ * `useClipboard`, so the package carries no extra hook dependency.
14
+ */
15
+ function useClipboard({ timeout = 2e3 } = {}) {
16
+ const [status, setStatus] = useState("idle");
17
+ const timer = useRef(void 0);
18
+ const copy = useCallback((value) => {
19
+ clearTimeout(timer.current);
20
+ function settle(next) {
21
+ setStatus(next);
22
+ timer.current = setTimeout(() => setStatus("idle"), timeout);
23
+ return next === "copied";
24
+ }
25
+ return (navigator.clipboard?.writeText(value) ?? Promise.reject(/* @__PURE__ */ new Error("No clipboard"))).then(() => settle("copied"), () => settle("failed"));
26
+ }, [timeout]);
27
+ useEffect(() => () => clearTimeout(timer.current), []);
28
+ return {
29
+ status,
30
+ copy
31
+ };
32
+ }
33
+ /** One label laid over the others, all in the same grid cell. */
34
+ const copyLabel = "col-start-1 row-start-1 transition-opacity duration-150 ease-out";
35
+ /**
36
+ * The labels stacked, so the button is as wide as the longest of them in every state and never
37
+ * resizes under the pointer that just clicked it. The ones not on show keep their space rather
38
+ * than unmounting, which is also what lets the swap cross-fade.
39
+ */
40
+ function CopyLabel({ status, labels }) {
41
+ return /* @__PURE__ */ jsx("span", {
42
+ className: "grid",
43
+ children: Object.entries(labels).map(([key, text]) => /* @__PURE__ */ jsx("span", {
44
+ "aria-hidden": key !== status,
45
+ className: cn(copyLabel, key === status ? "opacity-100" : "opacity-0"),
46
+ children: text
47
+ }, key))
48
+ });
49
+ }
50
+ /**
51
+ * Copies `value` to the clipboard and swaps its icon to a check for a couple of seconds, or to a
52
+ * cross with "Copy failed" when the browser refuses. Owns the tooltip so the outcome survives the
53
+ * tooltip closing on click.
54
+ */
55
+ function CopyButton({ value, label, copiedLabel = "Copied", failedLabel = "Copy failed", tooltip = label ? void 0 : "Copy to clipboard", onCopy, onCopyError, className, ...props }) {
56
+ const clipboard = useClipboard({ timeout: 2e3 });
57
+ const outcomes = {
58
+ copied: copiedLabel,
59
+ failed: failedLabel
60
+ };
61
+ const outcome = clipboard.status === "idle" ? void 0 : outcomes[clipboard.status];
62
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Tooltip, {
63
+ tooltip: tooltip && (outcome ?? tooltip),
64
+ children: /* @__PURE__ */ jsx(Button, {
65
+ type: "button",
66
+ variant: "secondary",
67
+ size: "sm",
68
+ "aria-label": label ? void 0 : "Copy to clipboard",
69
+ prefix: /* @__PURE__ */ jsx(IconSwap, {
70
+ value: clipboard.status,
71
+ marks: {
72
+ idle: /* @__PURE__ */ jsx(CopyIcon, { className: "size-3.5" }),
73
+ copied: /* @__PURE__ */ jsx(CheckIcon, { className: "size-3.5 text-success-ink" }),
74
+ failed: /* @__PURE__ */ jsx(CancelIcon, { className: "size-3.5 text-danger-ink" })
75
+ }
76
+ }),
77
+ onClick: () => {
78
+ clipboard.copy(value).then((copied) => {
79
+ if (copied) onCopy?.();
80
+ else onCopyError?.();
81
+ });
82
+ },
83
+ className: cn(!label && "pointer-coarse:size-10", className),
84
+ ...props,
85
+ children: label && /* @__PURE__ */ jsx(CopyLabel, {
86
+ status: clipboard.status,
87
+ labels: {
88
+ idle: label,
89
+ ...outcomes
90
+ }
91
+ })
92
+ })
93
+ }), /* @__PURE__ */ jsx("output", {
94
+ className: "sr-only",
95
+ children: outcome
96
+ })] });
97
+ }
98
+ export { CopyButton };
99
+
100
+ //# sourceMappingURL=copy-button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-button.js","names":[],"sources":["../../src/components/copy-button.tsx"],"sourcesContent":["\"use client\"\n\nimport {\n type ComponentProps,\n type ReactNode,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\"\nimport { CancelIcon, CheckIcon, CopyIcon } from \"../lib/icons\"\nimport { cn } from \"../lib/variants\"\nimport { Button } from \"./button\"\nimport { IconSwap } from \"./icon-swap\"\nimport { Tooltip } from \"./tooltip\"\n\n/** Where a copy stands: nothing to show, or the outcome of the last one for a moment. */\ntype CopyStatus = \"idle\" | \"copied\" | \"failed\"\n\n/**\n * Copies text to the clipboard and shows how it went for `timeout` ms, then goes back to idle.\n * Resolves to whether the copy took. A tiny local stand-in for `@mantine/hooks`'\n * `useClipboard`, so the package carries no extra hook dependency.\n */\nfunction useClipboard({ timeout = 2000 }: { timeout?: number } = {}) {\n const [status, setStatus] = useState<CopyStatus>(\"idle\")\n const timer = useRef<ReturnType<typeof setTimeout>>(undefined)\n\n const copy = useCallback(\n (value: string) => {\n clearTimeout(timer.current)\n\n function settle(next: CopyStatus) {\n setStatus(next)\n timer.current = setTimeout(() => setStatus(\"idle\"), timeout)\n return next === \"copied\"\n }\n\n // Optional chaining, not a bare call: `navigator.clipboard` is undefined outside a\n // secure context (LAN dev over plain http, an old WebView, a sandboxed iframe), and\n // dereferencing it throws synchronously out of the click handler and into the nearest\n // error boundary. A missing clipboard is a failed copy like any other.\n const write =\n navigator.clipboard?.writeText(value) ?? Promise.reject(new Error(\"No clipboard\"))\n\n return write.then(\n () => settle(\"copied\"),\n () => settle(\"failed\"),\n )\n },\n [timeout],\n )\n\n useEffect(() => () => clearTimeout(timer.current), [])\n\n return { status, copy }\n}\n\n/** One label laid over the others, all in the same grid cell. */\nconst copyLabel = \"col-start-1 row-start-1 transition-opacity duration-150 ease-out\"\n\ninterface CopyLabelProps {\n status: CopyStatus\n labels: Record<CopyStatus, ReactNode>\n}\n\n/**\n * The labels stacked, so the button is as wide as the longest of them in every state and never\n * resizes under the pointer that just clicked it. The ones not on show keep their space rather\n * than unmounting, which is also what lets the swap cross-fade.\n */\nfunction CopyLabel({ status, labels }: CopyLabelProps) {\n return (\n <span className=\"grid\">\n {Object.entries<ReactNode>(labels).map(([key, text]) => (\n <span\n key={key}\n aria-hidden={key !== status}\n className={cn(copyLabel, key === status ? \"opacity-100\" : \"opacity-0\")}\n >\n {text}\n </span>\n ))}\n </span>\n )\n}\n\ninterface CopyButtonProps extends Omit<\n ComponentProps<typeof Button>,\n \"prefix\" | \"onClick\" | \"children\"\n> {\n value: string\n /**\n * Visible label. Left out, the button is icon-only with a tooltip.\n */\n label?: ReactNode\n /**\n * What the label reads while the copied state is showing.\n */\n copiedLabel?: ReactNode\n /**\n * What the label reads when the browser refused the copy.\n */\n failedLabel?: ReactNode\n tooltip?: ReactNode\n /** Runs once the value is on the clipboard, e.g. to say where to paste it. */\n onCopy?: () => void\n /** Runs when the browser refuses the copy, e.g. to select the text for a copy by hand. */\n onCopyError?: () => void\n}\n\n/**\n * Copies `value` to the clipboard and swaps its icon to a check for a couple of seconds, or to a\n * cross with \"Copy failed\" when the browser refuses. Owns the tooltip so the outcome survives the\n * tooltip closing on click.\n */\nexport function CopyButton({\n value,\n label,\n copiedLabel = \"Copied\",\n failedLabel = \"Copy failed\",\n tooltip = label ? undefined : \"Copy to clipboard\",\n onCopy,\n onCopyError,\n className,\n ...props\n}: CopyButtonProps) {\n const clipboard = useClipboard({ timeout: 2000 })\n const outcomes = { copied: copiedLabel, failed: failedLabel }\n const outcome = clipboard.status === \"idle\" ? undefined : outcomes[clipboard.status]\n\n return (\n <>\n <Tooltip tooltip={tooltip && (outcome ?? tooltip)}>\n <Button\n type=\"button\"\n variant=\"secondary\"\n size=\"sm\"\n aria-label={label ? undefined : \"Copy to clipboard\"}\n prefix={\n <IconSwap\n value={clipboard.status}\n marks={{\n idle: <CopyIcon className=\"size-3.5\" />,\n copied: <CheckIcon className=\"size-3.5 text-success-ink\" />,\n failed: <CancelIcon className=\"size-3.5 text-danger-ink\" />,\n }}\n />\n }\n onClick={() => {\n void clipboard.copy(value).then(copied => {\n if (copied) onCopy?.()\n else onCopyError?.()\n })\n }}\n className={cn(!label && \"pointer-coarse:size-10\", className)}\n {...props}\n >\n {label && <CopyLabel status={clipboard.status} labels={{ idle: label, ...outcomes }} />}\n </Button>\n </Tooltip>\n\n {/* The icon and label swap only visually; this announces the outcome. */}\n <output className=\"sr-only\">{outcome}</output>\n </>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;AAwBA,SAAS,aAAa,EAAE,UAAU,QAA+B,CAAC,GAAG;CACnE,MAAM,CAAC,QAAQ,aAAa,SAAqB,MAAM;CACvD,MAAM,QAAQ,OAAsC,KAAA,CAAS;CAE7D,MAAM,OAAO,aACV,UAAkB;EACjB,aAAa,MAAM,OAAO;EAE1B,SAAS,OAAO,MAAkB;GAChC,UAAU,IAAI;GACd,MAAM,UAAU,iBAAiB,UAAU,MAAM,GAAG,OAAO;GAC3D,OAAO,SAAS;EAClB;EASA,QAFE,UAAU,WAAW,UAAU,KAAK,KAAK,QAAQ,uBAAO,IAAI,MAAM,cAAc,CAAC,EAAA,CAEtE,WACL,OAAO,QAAQ,SACf,OAAO,QAAQ,CACvB;CACF,GACA,CAAC,OAAO,CACV;CAEA,sBAAsB,aAAa,MAAM,OAAO,GAAG,CAAC,CAAC;CAErD,OAAO;EAAE;EAAQ;CAAK;AACxB;;AAGA,MAAM,YAAY;;;;;;AAYlB,SAAS,UAAU,EAAE,QAAQ,UAA0B;CACrD,OACE,oBAAC,QAAD;EAAM,WAAU;EACb,UAAA,OAAO,QAAmB,MAAM,CAAC,CAAC,KAAK,CAAC,KAAK,UAC5C,oBAAC,QAAD;GAEE,eAAa,QAAQ;GACrB,WAAW,GAAG,WAAW,QAAQ,SAAS,gBAAgB,WAAW;GAEpE,UAAA;EACG,GALC,GAKD,CACP;CACG,CAAA;AAEV;;;;;;AA+BA,SAAgB,WAAW,EACzB,OACA,OACA,cAAc,UACd,cAAc,eACd,UAAU,QAAQ,KAAA,IAAY,qBAC9B,QACA,aACA,WACA,GAAG,SACe;CAClB,MAAM,YAAY,aAAa,EAAE,SAAS,IAAK,CAAC;CAChD,MAAM,WAAW;EAAE,QAAQ;EAAa,QAAQ;CAAY;CAC5D,MAAM,UAAU,UAAU,WAAW,SAAS,KAAA,IAAY,SAAS,UAAU;CAE7E,OACE,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,SAAD;EAAS,SAAS,YAAY,WAAW;EACvC,UAAA,oBAAC,QAAD;GACE,MAAK;GACL,SAAQ;GACR,MAAK;GACL,cAAY,QAAQ,KAAA,IAAY;GAChC,QACE,oBAAC,UAAD;IACE,OAAO,UAAU;IACjB,OAAO;KACL,MAAM,oBAAC,UAAD,EAAU,WAAU,WAAY,CAAA;KACtC,QAAQ,oBAAC,WAAD,EAAW,WAAU,4BAA6B,CAAA;KAC1D,QAAQ,oBAAC,YAAD,EAAY,WAAU,2BAA4B,CAAA;IAC5D;GACD,CAAA;GAEH,eAAe;IACR,UAAU,KAAK,KAAK,CAAC,CAAC,MAAK,WAAU;KACxC,IAAI,QAAQ,SAAS;UAChB,cAAc;IACrB,CAAC;GACH;GACA,WAAW,GAAG,CAAC,SAAS,0BAA0B,SAAS;GAC3D,GAAI;GAEH,UAAA,SAAS,oBAAC,WAAD;IAAW,QAAQ,UAAU;IAAQ,QAAQ;KAAE,MAAM;KAAO,GAAG;IAAS;GAAI,CAAA;EAChF,CAAA;CACD,CAAA,GAGT,oBAAC,UAAD;EAAQ,WAAU;EAAW,UAAA;CAAgB,CAAA,CAC7C,EAAA,CAAA;AAEN"}
@@ -0,0 +1,15 @@
1
+ import { Input } from "./input.js";
2
+ import { ComponentProps } from "react";
3
+ interface CopyInputProps extends Omit<ComponentProps<typeof Input>, "value" | "readOnly"> {
4
+ value: string;
5
+ /** A shorter form to show in the field, such as a URL without its protocol. */
6
+ display?: string;
7
+ }
8
+ /**
9
+ * Read-only input with a copy-to-clipboard button pinned to its right edge, 2px in on every
10
+ * side: the 28px button in the 32px field, its `sm` corners concentric with the field's `md`.
11
+ * Props go to the input itself so `ref`, `aria-label` and font classes land on the field. When
12
+ * the browser refuses the copy, the field's text is selected for a copy by hand.
13
+ */
14
+ export declare function CopyInput({ ref, value, display, className, onFocus, onCopy, ...props }: CopyInputProps): import("react").JSX.Element;
15
+ export {};
@@ -0,0 +1,51 @@
1
+ "use client";
2
+ import { cn } from "../lib/variants.js";
3
+ import { CopyButton } from "./copy-button.js";
4
+ import { Input } from "./input.js";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ import { useImperativeHandle, useRef } from "react";
7
+ // src/components/copy-input.tsx
8
+ /**
9
+ * Read-only input with a copy-to-clipboard button pinned to its right edge, 2px in on every
10
+ * side: the 28px button in the 32px field, its `sm` corners concentric with the field's `md`.
11
+ * Props go to the input itself so `ref`, `aria-label` and font classes land on the field. When
12
+ * the browser refuses the copy, the field's text is selected for a copy by hand.
13
+ */
14
+ function CopyInput({ ref, value, display, className, onFocus, onCopy, ...props }) {
15
+ const shown = display ?? value;
16
+ const inputRef = useRef(null);
17
+ useImperativeHandle(ref, () => inputRef.current);
18
+ return /* @__PURE__ */ jsxs("div", {
19
+ className: "relative w-full",
20
+ children: [/* @__PURE__ */ jsx(Input, {
21
+ ref: inputRef,
22
+ readOnly: true,
23
+ value: shown,
24
+ className: cn("pr-10", className),
25
+ onFocus: (event) => {
26
+ event.currentTarget.select();
27
+ onFocus?.(event);
28
+ },
29
+ onCopy: (event) => {
30
+ const { selectionStart, selectionEnd } = event.currentTarget;
31
+ if (shown !== value && selectionStart === 0 && selectionEnd === shown.length) {
32
+ event.preventDefault();
33
+ event.clipboardData.setData("text/plain", value);
34
+ }
35
+ onCopy?.(event);
36
+ },
37
+ ...props
38
+ }), /* @__PURE__ */ jsx(CopyButton, {
39
+ value,
40
+ variant: "ghost",
41
+ className: "absolute top-1/2 right-0.5 -translate-y-1/2 rounded",
42
+ onCopyError: () => {
43
+ inputRef.current?.focus();
44
+ inputRef.current?.select();
45
+ }
46
+ })]
47
+ });
48
+ }
49
+ export { CopyInput };
50
+
51
+ //# sourceMappingURL=copy-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-input.js","names":[],"sources":["../../src/components/copy-input.tsx"],"sourcesContent":["\"use client\"\n\nimport { type ComponentProps, useImperativeHandle, useRef } from \"react\"\nimport { cn } from \"../lib/variants\"\nimport { CopyButton } from \"./copy-button\"\nimport { Input } from \"./input\"\n\ninterface CopyInputProps extends Omit<ComponentProps<typeof Input>, \"value\" | \"readOnly\"> {\n value: string\n /** A shorter form to show in the field, such as a URL without its protocol. */\n display?: string\n}\n\n/**\n * Read-only input with a copy-to-clipboard button pinned to its right edge, 2px in on every\n * side: the 28px button in the 32px field, its `sm` corners concentric with the field's `md`.\n * Props go to the input itself so `ref`, `aria-label` and font classes land on the field. When\n * the browser refuses the copy, the field's text is selected for a copy by hand.\n */\nexport function CopyInput({\n ref,\n value,\n display,\n className,\n onFocus,\n onCopy,\n ...props\n}: CopyInputProps) {\n const shown = display ?? value\n const inputRef = useRef<HTMLInputElement>(null)\n useImperativeHandle(ref, () => inputRef.current as HTMLInputElement)\n\n return (\n <div className=\"relative w-full\">\n <Input\n ref={inputRef}\n readOnly\n value={shown}\n className={cn(\"pr-10\", className)}\n onFocus={event => {\n event.currentTarget.select()\n onFocus?.(event)\n }}\n // A copy of the whole shortened field takes the full value, as the button does.\n onCopy={event => {\n const { selectionStart, selectionEnd } = event.currentTarget\n\n if (shown !== value && selectionStart === 0 && selectionEnd === shown.length) {\n event.preventDefault()\n event.clipboardData.setData(\"text/plain\", value)\n }\n\n onCopy?.(event)\n }}\n {...props}\n />\n\n <CopyButton\n value={value}\n variant=\"ghost\"\n className=\"absolute top-1/2 right-0.5 -translate-y-1/2 rounded\"\n onCopyError={() => {\n inputRef.current?.focus()\n inputRef.current?.select()\n }}\n />\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,SAAgB,UAAU,EACxB,KACA,OACA,SACA,WACA,SACA,QACA,GAAG,SACc;CACjB,MAAM,QAAQ,WAAW;CACzB,MAAM,WAAW,OAAyB,IAAI;CAC9C,oBAAoB,WAAW,SAAS,OAA2B;CAEnE,OACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACE,oBAAC,OAAD;GACE,KAAK;GACL,UAAA;GACA,OAAO;GACP,WAAW,GAAG,SAAS,SAAS;GAChC,UAAS,UAAS;IAChB,MAAM,cAAc,OAAO;IAC3B,UAAU,KAAK;GACjB;GAEA,SAAQ,UAAS;IACf,MAAM,EAAE,gBAAgB,iBAAiB,MAAM;IAE/C,IAAI,UAAU,SAAS,mBAAmB,KAAK,iBAAiB,MAAM,QAAQ;KAC5E,MAAM,eAAe;KACrB,MAAM,cAAc,QAAQ,cAAc,KAAK;IACjD;IAEA,SAAS,KAAK;GAChB;GACA,GAAI;EACL,CAAA,GAED,oBAAC,YAAD;GACS;GACP,SAAQ;GACR,WAAU;GACV,mBAAmB;IACjB,SAAS,SAAS,MAAM;IACxB,SAAS,SAAS,OAAO;GAC3B;EACD,CAAA,CACE;;AAET"}
@@ -0,0 +1,12 @@
1
+ import { VariantProps } from "../lib/variants.js";
2
+ import { DatePickerProps } from "./date-picker.js";
3
+ import { inputVariants } from "./input.js";
4
+ import { ComponentProps } from "react";
5
+ export type DatePickerTriggerProps = Omit<ComponentProps<"button">, "value" | "children"> & Pick<VariantProps<typeof inputVariants>, "size"> & Pick<DatePickerProps, "value" | "placeholder" | "formatDay">;
6
+ /**
7
+ * The date picker's trigger, kept apart from the calendar so a form can show it while the
8
+ * picker itself still loads. It holds a value, so it is a field like a select's trigger, with
9
+ * the field's ground and edge, rather than a button: in a form it sits flush with the inputs
10
+ * around it. A toolbar's period picker runs a command instead and stays a `Button`.
11
+ */
12
+ export declare function DatePickerTrigger({ value, placeholder, formatDay, size, className, ...props }: DatePickerTriggerProps): import("react").JSX.Element;
@@ -0,0 +1,30 @@
1
+ "use client";
2
+ import { CalendarIcon } from "../lib/icons.js";
3
+ import { cn } from "../lib/variants.js";
4
+ import { inputVariants } from "./input.js";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ // src/components/date-picker-trigger.tsx
7
+ /**
8
+ * The date picker's trigger, kept apart from the calendar so a form can show it while the
9
+ * picker itself still loads. It holds a value, so it is a field like a select's trigger, with
10
+ * the field's ground and edge, rather than a button: in a form it sits flush with the inputs
11
+ * around it. A toolbar's period picker runs a command instead and stays a `Button`.
12
+ */
13
+ function DatePickerTrigger({ value, placeholder = "Pick a date", formatDay, size, className, ...props }) {
14
+ return /* @__PURE__ */ jsxs("button", {
15
+ type: "button",
16
+ className: inputVariants({
17
+ interactive: true,
18
+ size,
19
+ className: cn("flex items-center gap-2 text-start tabular-nums", "data-popup-open:border-edge-solid data-popup-open:bg-fill-subtle active:not-disabled:bg-fill-subtle", className)
20
+ }),
21
+ ...props,
22
+ children: [/* @__PURE__ */ jsx(CalendarIcon, { className: "size-3.5 shrink-0 text-ink-muted" }), /* @__PURE__ */ jsx("span", {
23
+ className: cn("truncate", !value && "text-ink-muted"),
24
+ children: value ? formatDay(value) : placeholder
25
+ })]
26
+ });
27
+ }
28
+ export { DatePickerTrigger };
29
+
30
+ //# sourceMappingURL=date-picker-trigger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date-picker-trigger.js","names":[],"sources":["../../src/components/date-picker-trigger.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ComponentProps } from \"react\"\nimport { CalendarIcon } from \"../lib/icons\"\nimport { cn, type VariantProps } from \"../lib/variants\"\nimport type { DatePickerProps } from \"./date-picker\"\nimport { inputVariants } from \"./input\"\n\nexport type DatePickerTriggerProps = Omit<ComponentProps<\"button\">, \"value\" | \"children\"> &\n Pick<VariantProps<typeof inputVariants>, \"size\"> &\n Pick<DatePickerProps, \"value\" | \"placeholder\" | \"formatDay\">\n\n/**\n * The date picker's trigger, kept apart from the calendar so a form can show it while the\n * picker itself still loads. It holds a value, so it is a field like a select's trigger, with\n * the field's ground and edge, rather than a button: in a form it sits flush with the inputs\n * around it. A toolbar's period picker runs a command instead and stays a `Button`.\n */\nexport function DatePickerTrigger({\n value,\n placeholder = \"Pick a date\",\n formatDay,\n size,\n className,\n ...props\n}: DatePickerTriggerProps) {\n return (\n <button\n type=\"button\"\n className={inputVariants({\n interactive: true,\n size,\n className: cn(\n \"flex items-center gap-2 text-start tabular-nums\",\n \"data-popup-open:border-edge-solid data-popup-open:bg-fill-subtle active:not-disabled:bg-fill-subtle\",\n className,\n ),\n })}\n {...props}\n >\n <CalendarIcon className=\"size-3.5 shrink-0 text-ink-muted\" />\n <span className={cn(\"truncate\", !value && \"text-ink-muted\")}>\n {value ? formatDay(value) : placeholder}\n </span>\n </button>\n )\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,SAAgB,kBAAkB,EAChC,OACA,cAAc,eACd,WACA,MACA,WACA,GAAG,SACsB;CACzB,OACE,qBAAC,UAAD;EACE,MAAK;EACL,WAAW,cAAc;GACvB,aAAa;GACb;GACA,WAAW,GACT,mDACA,uGACA,SACF;EACF,CAAC;EACD,GAAI;EAXN,UAAA,CAaE,oBAAC,cAAD,EAAc,WAAU,mCAAoC,CAAA,GAC5D,oBAAC,QAAD;GAAM,WAAW,GAAG,YAAY,CAAC,SAAS,gBAAgB;GACvD,UAAA,QAAQ,UAAU,KAAK,IAAI;EACxB,CAAA,CACA;;AAEZ"}
@@ -0,0 +1,36 @@
1
+ export interface DatePickerProps {
2
+ /** The selected day as "YYYY-MM-DD", or empty for none. */
3
+ value?: string;
4
+ onChange: (value: string) => void;
5
+ /** Earliest and latest selectable day, both "YYYY-MM-DD" and both inclusive. */
6
+ min?: string;
7
+ max?: string;
8
+ /** Shown on the trigger while nothing is selected. */
9
+ placeholder?: string;
10
+ /**
11
+ * Names the selected "YYYY-MM-DD" day on the trigger. The app supplies it, so the day reads
12
+ * in the app's own locale and time zone like every other date beside it.
13
+ */
14
+ formatDay: (day: string) => string;
15
+ /**
16
+ * Lets the reader remove the date: a second click on the selected day, or the Clear button
17
+ * under the calendar. Set it on an optional date; a required one only ever changes.
18
+ */
19
+ clearable?: boolean;
20
+ id?: string;
21
+ disabled?: boolean;
22
+ /** Why the date cannot be changed: the trigger stays focusable, reads it, and never opens. */
23
+ disabledReason?: string;
24
+ className?: string;
25
+ /** Labels the trigger for screen readers, for a field with no visible `<label>`. */
26
+ "aria-label"?: string;
27
+ "aria-describedby"?: string;
28
+ "aria-invalid"?: boolean;
29
+ "aria-required"?: boolean;
30
+ onBlur?: () => void;
31
+ }
32
+ /**
33
+ * A single date, picked from a calendar in a popover. Replaces `<input type="date">`, whose
34
+ * widget every browser draws its own way and none of them on brand.
35
+ */
36
+ export declare function DatePicker({ value, onChange, min, max, placeholder, formatDay, clearable, id, disabled, disabledReason, className, ...props }: DatePickerProps): import("react").JSX.Element;