@seekalfred/primitives 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/README.md +664 -9
  2. package/dist/accordion/accordion.d.ts +5 -5
  3. package/dist/accordion/accordion.js +22 -11
  4. package/dist/accordion/accordion.js.map +1 -1
  5. package/dist/action-button/action-button.d.ts +50 -0
  6. package/dist/action-button/action-button.js +159 -0
  7. package/dist/action-button/action-button.js.map +1 -0
  8. package/dist/action-button/index.d.ts +2 -0
  9. package/dist/action-button/index.js +2 -0
  10. package/dist/alert/alert.d.ts +16 -2
  11. package/dist/alert/alert.js +118 -20
  12. package/dist/alert/alert.js.map +1 -1
  13. package/dist/alert-dialog/alert-dialog.d.ts +1 -1
  14. package/dist/alert-dialog/alert-dialog.js +4 -2
  15. package/dist/alert-dialog/alert-dialog.js.map +1 -1
  16. package/dist/avatar/avatar.d.ts +7 -1
  17. package/dist/avatar/avatar.js +51 -18
  18. package/dist/avatar/avatar.js.map +1 -1
  19. package/dist/badge/badge.d.ts +10 -3
  20. package/dist/badge/badge.js +37 -5
  21. package/dist/badge/badge.js.map +1 -1
  22. package/dist/breadcrumb/breadcrumb.d.ts +3 -30
  23. package/dist/breadcrumb/breadcrumb.js +25 -8
  24. package/dist/breadcrumb/breadcrumb.js.map +1 -1
  25. package/dist/button/button.d.ts +36 -23
  26. package/dist/button/button.js +178 -33
  27. package/dist/button/button.js.map +1 -1
  28. package/dist/button-group/button-group.d.ts +76 -0
  29. package/dist/button-group/button-group.js +403 -0
  30. package/dist/button-group/button-group.js.map +1 -0
  31. package/dist/button-group/index.d.ts +2 -0
  32. package/dist/button-group/index.js +2 -0
  33. package/dist/calendar/calendar.d.ts +3 -3
  34. package/dist/calendar/calendar.js +263 -34
  35. package/dist/calendar/calendar.js.map +1 -1
  36. package/dist/card/card.d.ts +14 -7
  37. package/dist/card/card.js +32 -14
  38. package/dist/card/card.js.map +1 -1
  39. package/dist/checkbox/checkbox.d.ts +2 -9
  40. package/dist/checkbox/checkbox.js +28 -29
  41. package/dist/checkbox/checkbox.js.map +1 -1
  42. package/dist/confirm-morph/confirm-morph.d.ts +85 -0
  43. package/dist/confirm-morph/confirm-morph.js +652 -0
  44. package/dist/confirm-morph/confirm-morph.js.map +1 -0
  45. package/dist/confirm-morph/index.d.ts +2 -0
  46. package/dist/confirm-morph/index.js +2 -0
  47. package/dist/copy-button/copy-button.d.ts +32 -0
  48. package/dist/copy-button/copy-button.js +134 -0
  49. package/dist/copy-button/copy-button.js.map +1 -0
  50. package/dist/copy-button/index.d.ts +2 -0
  51. package/dist/copy-button/index.js +2 -0
  52. package/dist/date-picker/date-picker.d.ts +51 -0
  53. package/dist/date-picker/date-picker.js +241 -0
  54. package/dist/date-picker/date-picker.js.map +1 -0
  55. package/dist/date-picker/date-range-picker.d.ts +78 -0
  56. package/dist/date-picker/date-range-picker.js +1015 -0
  57. package/dist/date-picker/date-range-picker.js.map +1 -0
  58. package/dist/date-picker/index.d.ts +4 -0
  59. package/dist/date-picker/index.js +4 -0
  60. package/dist/date-picker/picker-parts.d.ts +46 -0
  61. package/dist/date-picker/picker-parts.js +135 -0
  62. package/dist/date-picker/picker-parts.js.map +1 -0
  63. package/dist/dialog/dialog.d.ts +12 -16
  64. package/dist/dialog/dialog.js +45 -14
  65. package/dist/dialog/dialog.js.map +1 -1
  66. package/dist/empty-state/empty-state.d.ts +44 -0
  67. package/dist/empty-state/empty-state.js +83 -0
  68. package/dist/empty-state/empty-state.js.map +1 -0
  69. package/dist/empty-state/index.d.ts +2 -0
  70. package/dist/empty-state/index.js +2 -0
  71. package/dist/expanding-button-group/expanding-button-group.d.ts +54 -0
  72. package/dist/expanding-button-group/expanding-button-group.js +350 -0
  73. package/dist/expanding-button-group/expanding-button-group.js.map +1 -0
  74. package/dist/expanding-button-group/index.d.ts +2 -0
  75. package/dist/expanding-button-group/index.js +2 -0
  76. package/dist/file-drop-zone/file-drop-zone.d.ts +71 -0
  77. package/dist/file-drop-zone/file-drop-zone.js +116 -0
  78. package/dist/file-drop-zone/file-drop-zone.js.map +1 -0
  79. package/dist/file-drop-zone/index.d.ts +2 -0
  80. package/dist/file-drop-zone/index.js +2 -0
  81. package/dist/filter-bar/filter-bar.d.ts +121 -0
  82. package/dist/filter-bar/filter-bar.js +300 -0
  83. package/dist/filter-bar/filter-bar.js.map +1 -0
  84. package/dist/filter-bar/index.d.ts +2 -0
  85. package/dist/filter-bar/index.js +2 -0
  86. package/dist/floating-button-group/floating-button-group.d.ts +61 -0
  87. package/dist/floating-button-group/floating-button-group.js +340 -0
  88. package/dist/floating-button-group/floating-button-group.js.map +1 -0
  89. package/dist/floating-button-group/index.d.ts +2 -0
  90. package/dist/floating-button-group/index.js +2 -0
  91. package/dist/icon-morph/icon-morph.d.ts +55 -0
  92. package/dist/icon-morph/icon-morph.js +331 -0
  93. package/dist/icon-morph/icon-morph.js.map +1 -0
  94. package/dist/icon-morph/index.d.ts +2 -0
  95. package/dist/icon-morph/index.js +2 -0
  96. package/dist/index.d.ts +24 -2
  97. package/dist/index.js +29 -7
  98. package/dist/input/input.d.ts +23 -1
  99. package/dist/input/input.js +37 -13
  100. package/dist/input/input.js.map +1 -1
  101. package/dist/label/label.d.ts +1 -1
  102. package/dist/label/label.js +4 -2
  103. package/dist/label/label.js.map +1 -1
  104. package/dist/lib/count-to.js +113 -0
  105. package/dist/lib/count-to.js.map +1 -0
  106. package/dist/lib/eye-morph.js +62 -0
  107. package/dist/lib/eye-morph.js.map +1 -0
  108. package/dist/lib/field-message.js +336 -0
  109. package/dist/lib/field-message.js.map +1 -0
  110. package/dist/lib/field-shell.js +81 -0
  111. package/dist/lib/field-shell.js.map +1 -0
  112. package/dist/lib/field-surface.js +4 -2
  113. package/dist/lib/field-surface.js.map +1 -1
  114. package/dist/lib/flip.js +80 -0
  115. package/dist/lib/flip.js.map +1 -0
  116. package/dist/lib/height-follow.js +59 -0
  117. package/dist/lib/height-follow.js.map +1 -0
  118. package/dist/lib/icon-swap.js +47 -0
  119. package/dist/lib/icon-swap.js.map +1 -0
  120. package/dist/lib/leaving-list.js +57 -0
  121. package/dist/lib/leaving-list.js.map +1 -0
  122. package/dist/lib/merge-refs.js +22 -0
  123. package/dist/lib/merge-refs.js.map +1 -0
  124. package/dist/lib/morph-text.js +128 -0
  125. package/dist/lib/morph-text.js.map +1 -0
  126. package/dist/lib/motion.js +162 -0
  127. package/dist/lib/motion.js.map +1 -0
  128. package/dist/lib/pausable-timeout.js +67 -0
  129. package/dist/lib/pausable-timeout.js.map +1 -0
  130. package/dist/lib/rolling-value.js +31 -0
  131. package/dist/lib/rolling-value.js.map +1 -0
  132. package/dist/lib/spring-progress.js +114 -0
  133. package/dist/lib/spring-progress.js.map +1 -0
  134. package/dist/lib/svg-id.js +10 -0
  135. package/dist/lib/svg-id.js.map +1 -0
  136. package/dist/lib/swap-text.js +77 -0
  137. package/dist/lib/swap-text.js.map +1 -0
  138. package/dist/lib/use-copy-feedback.js +36 -0
  139. package/dist/lib/use-copy-feedback.js.map +1 -0
  140. package/dist/menu/menu.d.ts +5 -5
  141. package/dist/menu/menu.js +10 -6
  142. package/dist/menu/menu.js.map +1 -1
  143. package/dist/page-header/index.d.ts +2 -0
  144. package/dist/page-header/index.js +2 -0
  145. package/dist/page-header/page-header.d.ts +75 -0
  146. package/dist/page-header/page-header.js +83 -0
  147. package/dist/page-header/page-header.js.map +1 -0
  148. package/dist/password-field/index.d.ts +2 -0
  149. package/dist/password-field/index.js +2 -0
  150. package/dist/password-field/password-field.d.ts +37 -0
  151. package/dist/password-field/password-field.js +101 -0
  152. package/dist/password-field/password-field.js.map +1 -0
  153. package/dist/password-strength/index.d.ts +2 -0
  154. package/dist/password-strength/index.js +2 -0
  155. package/dist/password-strength/password-strength.d.ts +127 -0
  156. package/dist/password-strength/password-strength.js +455 -0
  157. package/dist/password-strength/password-strength.js.map +1 -0
  158. package/dist/popover/popover.d.ts +10 -2
  159. package/dist/popover/popover.js +6 -4
  160. package/dist/popover/popover.js.map +1 -1
  161. package/dist/progress/progress.d.ts +2 -2
  162. package/dist/progress/progress.js +50 -7
  163. package/dist/progress/progress.js.map +1 -1
  164. package/dist/radio-group/radio-group.d.ts +3 -3
  165. package/dist/radio-group/radio-group.js +14 -10
  166. package/dist/radio-group/radio-group.js.map +1 -1
  167. package/dist/scroll-area/scroll-area.d.ts +17 -6
  168. package/dist/scroll-area/scroll-area.js +30 -6
  169. package/dist/scroll-area/scroll-area.js.map +1 -1
  170. package/dist/search-field/index.d.ts +2 -0
  171. package/dist/search-field/index.js +2 -0
  172. package/dist/search-field/search-field.d.ts +26 -0
  173. package/dist/search-field/search-field.js +155 -0
  174. package/dist/search-field/search-field.js.map +1 -0
  175. package/dist/select/select.d.ts +3 -3
  176. package/dist/select/select.js +85 -24
  177. package/dist/select/select.js.map +1 -1
  178. package/dist/separator/separator.d.ts +1 -1
  179. package/dist/separator/separator.js +4 -2
  180. package/dist/separator/separator.js.map +1 -1
  181. package/dist/sheet/sheet.d.ts +1 -1
  182. package/dist/sheet/sheet.js +6 -3
  183. package/dist/sheet/sheet.js.map +1 -1
  184. package/dist/side-nav/index.d.ts +2 -0
  185. package/dist/side-nav/index.js +2 -0
  186. package/dist/side-nav/side-nav.d.ts +72 -0
  187. package/dist/side-nav/side-nav.js +142 -0
  188. package/dist/side-nav/side-nav.js.map +1 -0
  189. package/dist/skeleton/skeleton.d.ts +8 -2
  190. package/dist/skeleton/skeleton.js +9 -3
  191. package/dist/skeleton/skeleton.js.map +1 -1
  192. package/dist/slider/slider.d.ts +2 -2
  193. package/dist/slider/slider.js +64 -8
  194. package/dist/slider/slider.js.map +1 -1
  195. package/dist/spinner/spinner.d.ts +1 -1
  196. package/dist/spinner/spinner.js +4 -2
  197. package/dist/spinner/spinner.js.map +1 -1
  198. package/dist/split-button/index.d.ts +2 -0
  199. package/dist/split-button/index.js +2 -0
  200. package/dist/split-button/split-button.d.ts +46 -0
  201. package/dist/split-button/split-button.js +122 -0
  202. package/dist/split-button/split-button.js.map +1 -0
  203. package/dist/stat-card/index.d.ts +2 -0
  204. package/dist/stat-card/index.js +2 -0
  205. package/dist/stat-card/stat-card.d.ts +81 -0
  206. package/dist/stat-card/stat-card.js +152 -0
  207. package/dist/stat-card/stat-card.js.map +1 -0
  208. package/dist/styles.css +1 -1
  209. package/dist/switch/switch.d.ts +2 -2
  210. package/dist/switch/switch.js +11 -8
  211. package/dist/switch/switch.js.map +1 -1
  212. package/dist/table/index.d.ts +2 -2
  213. package/dist/table/index.js +2 -2
  214. package/dist/table/table.d.ts +38 -7
  215. package/dist/table/table.js +114 -12
  216. package/dist/table/table.js.map +1 -1
  217. package/dist/tabs/tabs.d.ts +4 -4
  218. package/dist/tabs/tabs.js +153 -12
  219. package/dist/tabs/tabs.js.map +1 -1
  220. package/dist/textarea/textarea.d.ts +24 -1
  221. package/dist/textarea/textarea.js +27 -3
  222. package/dist/textarea/textarea.js.map +1 -1
  223. package/dist/theme-switch/index.d.ts +2 -0
  224. package/dist/theme-switch/index.js +2 -0
  225. package/dist/theme-switch/theme-switch.d.ts +37 -0
  226. package/dist/theme-switch/theme-switch.js +123 -0
  227. package/dist/theme-switch/theme-switch.js.map +1 -0
  228. package/dist/time-picker/index.d.ts +2 -0
  229. package/dist/time-picker/index.js +2 -0
  230. package/dist/time-picker/time-picker.d.ts +54 -0
  231. package/dist/time-picker/time-picker.js +201 -0
  232. package/dist/time-picker/time-picker.js.map +1 -0
  233. package/dist/toast/toast.d.ts +2 -2
  234. package/dist/toast/toast.js +61 -39
  235. package/dist/toast/toast.js.map +1 -1
  236. package/dist/tooltip/tooltip.d.ts +3 -3
  237. package/dist/tooltip/tooltip.js +66 -15
  238. package/dist/tooltip/tooltip.js.map +1 -1
  239. package/package.json +83 -3
@@ -1,8 +1,11 @@
1
1
  "use client";
2
2
  import { cn, cnAll } from "../lib/cn.js";
3
+ import { SwapText } from "../lib/swap-text.js";
4
+ import { useAfter, useCountTo } from "../lib/count-to.js";
3
5
  import { cva } from "class-variance-authority";
6
+ import { forwardRef } from "react";
4
7
  import { Label, ProgressBar } from "react-aria-components";
5
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
6
9
  //#region src/progress/progress.tsx
7
10
  /**
8
11
  * Progress, ported from the legacy shadcn/Radix component.
@@ -36,7 +39,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
36
39
  */
37
40
  const progressVariants = cva(["flex w-full flex-col gap-1.5 box-border font-sans"]);
38
41
  const progressTrackVariants = cva(["relative h-2 w-full overflow-hidden rounded-pill box-border", "bg-muted border-(length:--border-width) border-border"]);
39
- const progressFillVariants = cva(["h-full rounded-pill", "motion-safe:transition-[width] motion-safe:duration-(--duration-base) motion-safe:ease-standard"], {
42
+ const progressFillVariants = cva(["h-full rounded-pill", "progress-fill"], {
40
43
  variants: { tone: {
41
44
  neutral: "bg-primary-strong",
42
45
  success: "bg-success-strong",
@@ -46,23 +49,62 @@ const progressFillVariants = cva(["h-full rounded-pill", "motion-safe:transition
46
49
  } },
47
50
  defaultVariants: { tone: "neutral" }
48
51
  });
49
- function Progress({ label, labelHidden, showValue, tone, trackClassName, fillClassName, className, ...props }) {
52
+ /**
53
+ * The printed value. A percentage counts to its new number on the same spring the
54
+ * fill follows, and a check lands beside the final count once the bar is full.
55
+ * Any other text (a price, a step count) is shown as it is.
56
+ */
57
+ function ProgressValue({ percentage, valueText }) {
58
+ const percent = Math.round(percentage);
59
+ const counted = useCountTo(percent);
60
+ const done = useAfter(percent >= 100, 240);
61
+ const isPercent = valueText === `${percent}%`;
62
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [isPercent ? `${counted}%` : valueText, isPercent ? /* @__PURE__ */ jsx("span", {
63
+ "data-slot": "progress-done",
64
+ className: "ms-1 inline-flex align-middle text-success-strong",
65
+ children: /* @__PURE__ */ jsx(SwapText, {
66
+ swapKey: done ? "done" : "",
67
+ motion: "glyph",
68
+ className: "inline-flex",
69
+ children: /* @__PURE__ */ jsx("svg", {
70
+ viewBox: "0 0 16 16",
71
+ fill: "none",
72
+ stroke: "currentColor",
73
+ strokeWidth: "2",
74
+ strokeLinecap: "round",
75
+ strokeLinejoin: "round",
76
+ className: "size-3.5",
77
+ "aria-hidden": "true",
78
+ children: /* @__PURE__ */ jsx("path", { d: "m3.5 8.5 3 3 6-6" })
79
+ })
80
+ })
81
+ }) : null] });
82
+ }
83
+ const Progress = forwardRef(function Progress({ label, labelHidden, showValue, tone, trackClassName, fillClassName, className, ...props }, ref) {
50
84
  return /* @__PURE__ */ jsx(ProgressBar, {
85
+ ref,
51
86
  ...props,
52
87
  "data-slot": "progress",
53
88
  className: cn(progressVariants(), className),
54
- children: ({ percentage, isIndeterminate, valueText }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
89
+ children: ({ percentage, isIndeterminate, valueText }) => /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("div", {
55
90
  "data-slot": "progress-header",
56
91
  className: cnAll(showValue && "flex items-baseline justify-between gap-2"),
57
92
  children: [/* @__PURE__ */ jsx(Label, {
58
93
  "data-slot": "progress-label",
59
94
  className: cnAll("text-sm leading-(--leading-normal) text-foreground", labelHidden && "sr-only"),
60
- children: label
95
+ children: typeof label === "string" ? /* @__PURE__ */ jsx(SwapText, {
96
+ swapKey: label,
97
+ className: "block",
98
+ children: label
99
+ }) : label
61
100
  }), showValue ? /* @__PURE__ */ jsx("span", {
62
101
  "data-slot": "progress-value",
63
102
  "aria-hidden": "true",
64
103
  className: "text-sm leading-(--leading-normal) text-muted-foreground tabular-nums",
65
- children: valueText
104
+ children: /* @__PURE__ */ jsx(ProgressValue, {
105
+ percentage: percentage ?? 0,
106
+ valueText
107
+ })
66
108
  }) : null]
67
109
  }), /* @__PURE__ */ jsx("div", {
68
110
  "data-slot": "progress-track",
@@ -70,12 +112,13 @@ function Progress({ label, labelHidden, showValue, tone, trackClassName, fillCla
70
112
  children: /* @__PURE__ */ jsx("div", {
71
113
  "data-slot": "progress-fill",
72
114
  "data-indeterminate": isIndeterminate || void 0,
115
+ "data-complete": (!tone || tone === "neutral") && !isIndeterminate && (percentage ?? 0) >= 100 ? "" : void 0,
73
116
  className: cn(progressFillVariants({ tone }), fillClassName),
74
117
  style: { width: isIndeterminate ? "0%" : `${percentage ?? 0}%` }
75
118
  })
76
119
  })] })
77
120
  });
78
- }
121
+ });
79
122
  //#endregion
80
123
  export { Progress, progressFillVariants, progressTrackVariants, progressVariants };
81
124
 
@@ -1 +1 @@
1
- {"version":3,"file":"progress.js","names":["AriaProgressBar","AriaLabel"],"sources":["../../src/progress/progress.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport type { ReactNode } from \"react\";\nimport {\n Label as AriaLabel,\n ProgressBar as AriaProgressBar,\n type ProgressBarProps as AriaProgressBarProps,\n} from \"react-aria-components\";\n\nimport { cn, cnAll } from \"../lib/cn.js\";\n\n/**\n * Progress, ported from the legacy shadcn/Radix component.\n *\n * Census: seven files import it and only TWO render anything --\n * `ResponseOption.tsx` and `LiveQA.tsx`. Both pass `value` and\n * `className` and nothing else.\n *\n * `label` IS REQUIRED, and that is the point. Neither live call site\n * passes `aria-label`, `aria-labelledby` or an `id` a label targets, and\n * `role=\"progressbar\"` does not take its name from content -- so both\n * rendered progress bars are announced as an unnamed progressbar. React\n * Aria supplies the plumbing for three naming routes but no name of its\n * own: `<ProgressBar value={60}/>` is just as nameless there. Making the\n * prop required is what turns it into something you cannot forget.\n *\n * The migration plan said this component \"adds the missing\n * aria-valuenow\". That is wrong -- Radix already supplies `aria-valuenow`,\n * `aria-valuemin`, `aria-valuemax` and `aria-valuetext`. The missing thing\n * was always the NAME.\n *\n * THE COLOURS ARE NOT THE LEGACY'S. Its track is `bg-primary/20`, an alpha\n * fill that composites against unknown page content and therefore has no\n * fixed contrast pair at all -- over white it is roughly 1.05:1, an\n * invisible boundary. Its indicator is `bg-primary`, 2.44:1 on the page.\n * Here the track is `muted` with a `border` boundary and the fill is\n * `primary-strong`, which puts the fill against the track at 4.61:1 and\n * the track against the page at 5.25:1.\n *\n * Both are in the build-failing contrast contract.\n */\nexport const progressVariants = cva([\"flex w-full flex-col gap-1.5 box-border font-sans\"]);\n\nexport const progressTrackVariants = cva([\n \"relative h-2 w-full overflow-hidden rounded-pill box-border\",\n // muted, NOT `border` as the Switch uses. A switch has no fill; a\n // progress bar does, and primary-strong on a `border` track is 1.01:1 --\n // the two halves are the same grey and the value disappears.\n \"bg-muted border-(length:--border-width) border-border\",\n]);\n\nexport const progressFillVariants = cva(\n [\n \"h-full rounded-pill\",\n \"motion-safe:transition-[width] motion-safe:duration-(--duration-base) motion-safe:ease-standard\",\n ],\n {\n variants: {\n /*\n * What the value MEANS, which for a progress bar is usually a score\n * rather than a completion. The product's bar carried exactly this axis\n * (`default`/`success`/`warning`/`error`/`info`) and reached for it to\n * colour performance metrics.\n *\n * `-strong` throughout: the fill sits on the `muted` track and has to\n * clear the 3:1 non-text floor of WCAG 1.4.11 against it, which is the\n * same reason the track is muted rather than `border` -- primary-strong\n * on a `border` track measures 1.01:1 and the value disappears.\n */\n tone: {\n neutral: \"bg-primary-strong\",\n success: \"bg-success-strong\",\n warning: \"bg-warning-strong\",\n danger: \"bg-destructive-strong\",\n info: \"bg-info-strong\",\n },\n },\n defaultVariants: { tone: \"neutral\" },\n },\n);\n\n/**\n * A determinate or indeterminate progress bar.\n *\n * @example\n * <Progress label=\"Upload\" value={62} />\n * <Progress label=\"Loading results\" />\n */\nexport interface ProgressProps\n extends Omit<AriaProgressBarProps, \"className\" | \"style\" | \"children\">,\n VariantProps<typeof progressFillVariants> {\n /**\n * What is progressing, and the bar's accessible name.\n *\n * **Required.** Both legacy call sites render an unnamed progressbar.\n * Pass `labelHidden` when the surrounding UI already says it.\n */\n label: ReactNode;\n /**\n * Render the label for screen readers only.\n *\n * Both legacy call sites sit beside visible text that was never\n * associated with the bar -- this is how that text becomes the name\n * without printing it twice.\n */\n labelHidden?: boolean;\n /**\n * Print the value beside the label.\n *\n * The text itself comes from React Aria, which already formats it from\n * `value`/`minValue`/`maxValue` and honours `formatOptions` and\n * `valueLabel` -- so a percentage, a currency or \"3 of 7\" are all reachable\n * without a second prop here. It was never RENDERED before: the bar\n * announced its value to assistive tech and showed a sighted reader nothing.\n */\n showValue?: boolean;\n /** Extra classes for the track. */\n trackClassName?: string;\n /** Extra classes for the fill -- a per-call-site colour the tone axis cannot express. */\n fillClassName?: string;\n /** Extra classes. Merged last, so they win conflicts with ours. */\n className?: string;\n}\n\nexport function Progress({\n label,\n labelHidden,\n showValue,\n tone,\n trackClassName,\n fillClassName,\n className,\n ...props\n}: ProgressProps) {\n return (\n <AriaProgressBar\n {...props}\n data-slot=\"progress\"\n className={cn(progressVariants(), className)}\n >\n {({ percentage, isIndeterminate, valueText }) => (\n <>\n {/*\n The row exists only when the value is printed. Wrapping the label\n in a flex row unconditionally would change the label's box for\n every existing consumer to no purpose.\n */}\n <div\n data-slot=\"progress-header\"\n className={cnAll(showValue && \"flex items-baseline justify-between gap-2\")}\n >\n <AriaLabel\n data-slot=\"progress-label\"\n className={cnAll(\n \"text-sm leading-(--leading-normal) text-foreground\",\n labelHidden && \"sr-only\",\n )}\n >\n {label}\n </AriaLabel>\n {showValue ? (\n <span\n data-slot=\"progress-value\"\n // aria-hidden: React Aria already announces the value on the\n // progressbar itself. Without this a screen reader reads it\n // twice, once as the widget's value and once as loose text.\n aria-hidden=\"true\"\n className=\"text-sm leading-(--leading-normal) text-muted-foreground tabular-nums\"\n >\n {valueText}\n </span>\n ) : null}\n </div>\n <div\n data-slot=\"progress-track\"\n className={cn(progressTrackVariants(), trackClassName)}\n >\n {/*\n width, not the legacy translateX(-(100 - value)%). That\n overflowed for value > 100 -- a positive translate slid the\n indicator off to the right, while the announced value stayed\n whatever was passed. React Aria clamps the value, so the two\n can no longer disagree.\n\n An indeterminate bar renders no fill rather than the\n legacy's silent 0%: `value={undefined}` became `(value || 0)`\n there, so a sighted user saw \"0% done\" while a screen reader\n said \"indeterminate\".\n */}\n <div\n data-slot=\"progress-fill\"\n data-indeterminate={isIndeterminate || undefined}\n className={cn(progressFillVariants({ tone }), fillClassName)}\n style={{ width: isIndeterminate ? \"0%\" : `${percentage ?? 0}%` }}\n />\n </div>\n </>\n )}\n </AriaProgressBar>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,mBAAmB,IAAI,CAAC,mDAAmD,CAAC;AAEzF,MAAa,wBAAwB,IAAI,CACvC,+DAIA,uDACF,CAAC;AAED,MAAa,uBAAuB,IAClC,CACE,uBACA,iGACF,GACA;CACE,UAAU,EAYR,MAAM;EACJ,SAAS;EACT,SAAS;EACT,SAAS;EACT,QAAQ;EACR,MAAM;CACR,EACF;CACA,iBAAiB,EAAE,MAAM,UAAU;AACrC,CACF;AA6CA,SAAgB,SAAS,EACvB,OACA,aACA,WACA,MACA,gBACA,eACA,WACA,GAAG,SACa;CAChB,OACE,oBAACA,aAAD;EACE,GAAI;EACJ,aAAU;EACV,WAAW,GAAG,iBAAiB,GAAG,SAAS;EAEzC,WAAA,EAAE,YAAY,iBAAiB,gBAC/B,qBAAA,UAAA,EAAA,UAAA,CAME,qBAAC,OAAD;GACE,aAAU;GACV,WAAW,MAAM,aAAa,2CAA2C;GAF3E,UAAA,CAIE,oBAACC,OAAD;IACE,aAAU;IACV,WAAW,MACT,sDACA,eAAe,SACjB;IAEC,UAAA;GACQ,CAAA,GACV,YACC,oBAAC,QAAD;IACE,aAAU;IAIV,eAAY;IACZ,WAAU;IAET,UAAA;GACG,CAAA,IACJ,IACD;EACL,CAAA,GAAA,oBAAC,OAAD;GACE,aAAU;GACV,WAAW,GAAG,sBAAsB,GAAG,cAAc;GAcrD,UAAA,oBAAC,OAAD;IACE,aAAU;IACV,sBAAoB,mBAAmB,KAAA;IACvC,WAAW,GAAG,qBAAqB,EAAE,KAAK,CAAC,GAAG,aAAa;IAC3D,OAAO,EAAE,OAAO,kBAAkB,OAAO,GAAG,cAAc,EAAE,GAAG;GAChE,CAAA;EACE,CAAA,CACL,EAAA,CAAA;CAEW,CAAA;AAErB"}
1
+ {"version":3,"file":"progress.js","names":["AriaProgressBar","AriaLabel"],"sources":["../../src/progress/progress.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport { forwardRef, type ReactNode } from \"react\";\nimport {\n Label as AriaLabel,\n ProgressBar as AriaProgressBar,\n type ProgressBarProps as AriaProgressBarProps,\n} from \"react-aria-components\";\n\nimport { cn, cnAll } from \"../lib/cn.js\";\nimport { useAfter, useCountTo } from \"../lib/count-to.js\";\nimport { SwapText } from \"../lib/swap-text.js\";\n\n/**\n * Progress, ported from the legacy shadcn/Radix component.\n *\n * Census: seven files import it and only TWO render anything --\n * `ResponseOption.tsx` and `LiveQA.tsx`. Both pass `value` and\n * `className` and nothing else.\n *\n * `label` IS REQUIRED, and that is the point. Neither live call site\n * passes `aria-label`, `aria-labelledby` or an `id` a label targets, and\n * `role=\"progressbar\"` does not take its name from content -- so both\n * rendered progress bars are announced as an unnamed progressbar. React\n * Aria supplies the plumbing for three naming routes but no name of its\n * own: `<ProgressBar value={60}/>` is just as nameless there. Making the\n * prop required is what turns it into something you cannot forget.\n *\n * The migration plan said this component \"adds the missing\n * aria-valuenow\". That is wrong -- Radix already supplies `aria-valuenow`,\n * `aria-valuemin`, `aria-valuemax` and `aria-valuetext`. The missing thing\n * was always the NAME.\n *\n * THE COLOURS ARE NOT THE LEGACY'S. Its track is `bg-primary/20`, an alpha\n * fill that composites against unknown page content and therefore has no\n * fixed contrast pair at all -- over white it is roughly 1.05:1, an\n * invisible boundary. Its indicator is `bg-primary`, 2.44:1 on the page.\n * Here the track is `muted` with a `border` boundary and the fill is\n * `primary-strong`, which puts the fill against the track at 4.61:1 and\n * the track against the page at 5.25:1.\n *\n * Both are in the build-failing contrast contract.\n */\nexport const progressVariants = cva([\"flex w-full flex-col gap-1.5 box-border font-sans\"]);\n\nexport const progressTrackVariants = cva([\n \"relative h-2 w-full overflow-hidden rounded-pill box-border\",\n // muted, NOT `border` as the Switch uses. A switch has no fill; a\n // progress bar does, and primary-strong on a `border` track is 1.01:1 --\n // the two halves are the same grey and the value disappears.\n \"bg-muted border-(length:--border-width) border-border\",\n]);\n\nexport const progressFillVariants = cva(\n [\n \"h-full rounded-pill\",\n // The fill follows the value on the smooth spring and turns success-coloured when it completes (see progress-fill).\n \"progress-fill\",\n ],\n {\n variants: {\n /*\n * What the value MEANS, which for a progress bar is usually a score\n * rather than a completion. The product's bar carried exactly this axis\n * (`default`/`success`/`warning`/`error`/`info`) and reached for it to\n * colour performance metrics.\n *\n * `-strong` throughout: the fill sits on the `muted` track and has to\n * clear the 3:1 non-text floor of WCAG 1.4.11 against it, which is the\n * same reason the track is muted rather than `border` -- primary-strong\n * on a `border` track measures 1.01:1 and the value disappears.\n */\n tone: {\n neutral: \"bg-primary-strong\",\n success: \"bg-success-strong\",\n warning: \"bg-warning-strong\",\n danger: \"bg-destructive-strong\",\n info: \"bg-info-strong\",\n },\n },\n defaultVariants: { tone: \"neutral\" },\n },\n);\n\n/**\n * A determinate or indeterminate progress bar.\n *\n * @example\n * <Progress label=\"Upload\" value={62} />\n * <Progress label=\"Loading results\" />\n */\nexport interface ProgressProps\n extends Omit<AriaProgressBarProps, \"className\" | \"style\" | \"children\">,\n VariantProps<typeof progressFillVariants> {\n /**\n * What is progressing, and the bar's accessible name.\n *\n * **Required.** Both legacy call sites render an unnamed progressbar.\n * Pass `labelHidden` when the surrounding UI already says it.\n */\n label: ReactNode;\n /**\n * Render the label for screen readers only.\n *\n * Both legacy call sites sit beside visible text that was never\n * associated with the bar -- this is how that text becomes the name\n * without printing it twice.\n */\n labelHidden?: boolean;\n /**\n * Print the value beside the label.\n *\n * The text itself comes from React Aria, which already formats it from\n * `value`/`minValue`/`maxValue` and honours `formatOptions` and\n * `valueLabel` -- so a percentage, a currency or \"3 of 7\" are all reachable\n * without a second prop here. It was never RENDERED before: the bar\n * announced its value to assistive tech and showed a sighted reader nothing.\n */\n showValue?: boolean;\n /** Extra classes for the track. */\n trackClassName?: string;\n /** Extra classes for the fill -- a per-call-site colour the tone axis cannot express. */\n fillClassName?: string;\n /** Extra classes. Merged last, so they win conflicts with ours. */\n className?: string;\n}\n\n/**\n * The printed value. A percentage counts to its new number on the same spring the\n * fill follows, and a check lands beside the final count once the bar is full.\n * Any other text (a price, a step count) is shown as it is.\n */\nfunction ProgressValue({ percentage, valueText }: { percentage: number; valueText: string | undefined }) {\n const percent = Math.round(percentage);\n const counted = useCountTo(percent);\n const done = useAfter(percent >= 100, 240);\n const isPercent = valueText === `${percent}%`;\n return (\n <>\n {isPercent ? `${counted}%` : valueText}\n {isPercent ? (\n <span data-slot=\"progress-done\" className=\"ms-1 inline-flex align-middle text-success-strong\">\n <SwapText swapKey={done ? \"done\" : \"\"} motion=\"glyph\" className=\"inline-flex\">\n <svg\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"size-3.5\"\n aria-hidden=\"true\"\n >\n <path d=\"m3.5 8.5 3 3 6-6\" />\n </svg>\n </SwapText>\n </span>\n ) : null}\n </>\n );\n}\n\nexport const Progress = forwardRef<HTMLDivElement, ProgressProps>(function Progress(\n { label, labelHidden, showValue, tone, trackClassName, fillClassName, className, ...props },\n ref,\n) {\n return (\n <AriaProgressBar\n ref={ref}\n {...props}\n data-slot=\"progress\"\n className={cn(progressVariants(), className)}\n >\n {({ percentage, isIndeterminate, valueText }) => (\n <>\n {/*\n The row exists only when the value is printed. Wrapping the label\n in a flex row unconditionally would change the label's box for\n every existing consumer to no purpose.\n */}\n <div\n data-slot=\"progress-header\"\n className={cnAll(showValue && \"flex items-baseline justify-between gap-2\")}\n >\n <AriaLabel\n data-slot=\"progress-label\"\n className={cnAll(\n \"text-sm leading-(--leading-normal) text-foreground\",\n labelHidden && \"sr-only\",\n )}\n >\n {typeof label === \"string\" ? (\n <SwapText swapKey={label} className=\"block\">\n {label}\n </SwapText>\n ) : (\n label\n )}\n </AriaLabel>\n {showValue ? (\n <span\n data-slot=\"progress-value\"\n // aria-hidden: React Aria already announces the value on the\n // progressbar itself. Without this a screen reader reads it\n // twice, once as the widget's value and once as loose text.\n aria-hidden=\"true\"\n className=\"text-sm leading-(--leading-normal) text-muted-foreground tabular-nums\"\n >\n <ProgressValue percentage={percentage ?? 0} valueText={valueText} />\n </span>\n ) : null}\n </div>\n <div\n data-slot=\"progress-track\"\n className={cn(progressTrackVariants(), trackClassName)}\n >\n {/*\n width, not the legacy translateX(-(100 - value)%). That\n overflowed for value > 100 -- a positive translate slid the\n indicator off to the right, while the announced value stayed\n whatever was passed. React Aria clamps the value, so the two\n can no longer disagree.\n\n An indeterminate bar renders no fill rather than the\n legacy's silent 0%: `value={undefined}` became `(value || 0)`\n there, so a sighted user saw \"0% done\" while a screen reader\n said \"indeterminate\".\n */}\n <div\n data-slot=\"progress-fill\"\n data-indeterminate={isIndeterminate || undefined}\n // A default-toned bar turns success-coloured when it completes; an explicit tone is never overridden.\n data-complete={(!tone || tone === \"neutral\") && !isIndeterminate && (percentage ?? 0) >= 100 ? \"\" : undefined}\n className={cn(progressFillVariants({ tone }), fillClassName)}\n style={{ width: isIndeterminate ? \"0%\" : `${percentage ?? 0}%` }}\n />\n </div>\n </>\n )}\n </AriaProgressBar>\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAa,mBAAmB,IAAI,CAAC,mDAAmD,CAAC;AAEzF,MAAa,wBAAwB,IAAI,CACvC,+DAIA,uDACF,CAAC;AAED,MAAa,uBAAuB,IAClC,CACE,uBAEA,eACF,GACA;CACE,UAAU,EAYR,MAAM;EACJ,SAAS;EACT,SAAS;EACT,SAAS;EACT,QAAQ;EACR,MAAM;CACR,EACF;CACA,iBAAiB,EAAE,MAAM,UAAU;AACrC,CACF;;;;;;AAkDA,SAAS,cAAc,EAAE,YAAY,aAAoE;CACvG,MAAM,UAAU,KAAK,MAAM,UAAU;CACrC,MAAM,UAAU,WAAW,OAAO;CAClC,MAAM,OAAO,SAAS,WAAW,KAAK,GAAG;CACzC,MAAM,YAAY,cAAc,GAAG,QAAQ;CAC3C,OACE,qBAAA,YAAA,EAAA,UAAA,CACG,YAAY,GAAG,QAAQ,KAAK,WAC5B,YACC,oBAAC,QAAD;EAAM,aAAU;EAAgB,WAAU;EACxC,UAAA,oBAAC,UAAD;GAAU,SAAS,OAAO,SAAS;GAAI,QAAO;GAAQ,WAAU;GAC9D,UAAA,oBAAC,OAAD;IACE,SAAQ;IACR,MAAK;IACL,QAAO;IACP,aAAY;IACZ,eAAc;IACd,gBAAe;IACf,WAAU;IACV,eAAY;IAEZ,UAAA,oBAAC,QAAD,EAAM,GAAE,mBAAoB,CAAA;GACzB,CAAA;EACG,CAAA;CACN,CAAA,IACJ,IACJ,EAAA,CAAA;AAEN;AAEA,MAAa,WAAW,WAA0C,SAAS,SACzE,EAAE,OAAO,aAAa,WAAW,MAAM,gBAAgB,eAAe,WAAW,GAAG,SACpF,KACA;CACA,OACE,oBAACA,aAAD;EACO;EACL,GAAI;EACJ,aAAU;EACV,WAAW,GAAG,iBAAiB,GAAG,SAAS;EAEzC,WAAA,EAAE,YAAY,iBAAiB,gBAC/B,qBAAA,YAAA,EAAA,UAAA,CAME,qBAAC,OAAD;GACE,aAAU;GACV,WAAW,MAAM,aAAa,2CAA2C;GAF3E,UAAA,CAIE,oBAACC,OAAD;IACE,aAAU;IACV,WAAW,MACT,sDACA,eAAe,SACjB;IAEC,UAAA,OAAO,UAAU,WAChB,oBAAC,UAAD;KAAU,SAAS;KAAO,WAAU;KACjC,UAAA;IACO,CAAA,IAEV;GAEO,CAAA,GACV,YACC,oBAAC,QAAD;IACE,aAAU;IAIV,eAAY;IACZ,WAAU;IAEV,UAAA,oBAAC,eAAD;KAAe,YAAY,cAAc;KAAc;IAAY,CAAA;GAC/D,CAAA,IACJ,IACD;EACL,CAAA,GAAA,oBAAC,OAAD;GACE,aAAU;GACV,WAAW,GAAG,sBAAsB,GAAG,cAAc;GAcrD,UAAA,oBAAC,OAAD;IACE,aAAU;IACV,sBAAoB,mBAAmB,KAAA;IAEvC,kBAAgB,CAAC,QAAQ,SAAS,cAAc,CAAC,oBAAoB,cAAc,MAAM,MAAM,KAAK,KAAA;IACpG,WAAW,GAAG,qBAAqB,EAAE,KAAK,CAAC,GAAG,aAAa;IAC3D,OAAO,EAAE,OAAO,kBAAkB,OAAO,GAAG,cAAc,EAAE,GAAG;GAChE,CAAA;EACE,CAAA,CACL,EAAA,CAAA;CAEW,CAAA;AAErB,CAAC"}
@@ -1,5 +1,5 @@
1
- import { RadioGroupProps, RadioProps } from "react-aria-components";
2
1
  import { ReactNode } from "react";
2
+ import { RadioGroupProps, RadioProps } from "react-aria-components";
3
3
  //#region src/radio-group/radio-group.d.ts
4
4
  /**
5
5
  * RadioGroup, ported from the legacy shadcn/Radix component onto React Aria.
@@ -34,7 +34,7 @@ interface RadioGroupProps$1 extends Omit<RadioGroupProps, "className" | "style">
34
34
  /** Extra classes. Merged last, so they win conflicts with ours. */
35
35
  className?: string;
36
36
  }
37
- declare function RadioGroup$1({ className, ...props }: RadioGroupProps$1): import("react").JSX.Element;
37
+ declare const RadioGroup$1: import("react").ForwardRefExoticComponent<RadioGroupProps$1 & import("react").RefAttributes<HTMLDivElement>>;
38
38
  /**
39
39
  * One choice.
40
40
  *
@@ -47,7 +47,7 @@ interface RadioProps$1 extends Omit<RadioProps, "className" | "style" | "childre
47
47
  /** Extra classes for the label. Merged last, so they win conflicts. */
48
48
  className?: string;
49
49
  }
50
- declare function Radio$1({ className, children, ...props }: RadioProps$1): import("react").JSX.Element;
50
+ declare const Radio$1: import("react").ForwardRefExoticComponent<RadioProps$1 & import("react").RefAttributes<HTMLInputElement>>;
51
51
  //#endregion
52
52
  export { Radio$1 as Radio, RadioGroup$1 as RadioGroup, RadioGroupProps$1 as RadioGroupProps, RadioProps$1 as RadioProps };
53
53
  //# sourceMappingURL=radio-group.d.ts.map
@@ -2,8 +2,9 @@
2
2
  import { cn, cnAll } from "../lib/cn.js";
3
3
  import { selectionLabelVariants, selectionRingVariants } from "../lib/selection-control.js";
4
4
  import { cva } from "class-variance-authority";
5
+ import { forwardRef } from "react";
5
6
  import { Radio, RadioGroup } from "react-aria-components";
6
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
7
8
  //#region src/radio-group/radio-group.tsx
8
9
  /**
9
10
  * RadioGroup, ported from the legacy shadcn/Radix component onto React Aria.
@@ -28,37 +29,40 @@ const radioVariants = cva([
28
29
  "inline-flex size-4 shrink-0 items-center justify-center",
29
30
  "rounded-full border-(length:--border-width) box-border",
30
31
  "bg-background border-border",
31
- "motion-safe:transition-colors motion-safe:duration-(--duration-fast) motion-safe:ease-standard",
32
+ "radio-mark",
32
33
  "group-data-[selected]:bg-primary group-data-[selected]:border-primary-strong",
33
34
  "group-data-[selected]:text-primary-foreground",
34
35
  selectionRingVariants()
35
36
  ]);
36
- function RadioGroup$1({ className, ...props }) {
37
+ const RadioGroup$1 = forwardRef(function RadioGroup$2({ className, ...props }, ref) {
37
38
  return /* @__PURE__ */ jsx(RadioGroup, {
39
+ ref,
38
40
  ...props,
39
41
  "data-slot": "radio-group",
40
42
  className: cn(radioGroupVariants(), className)
41
43
  });
42
- }
43
- function Radio$1({ className, children, ...props }) {
44
+ });
45
+ const Radio$1 = forwardRef(function Radio$2({ className, children, ...props }, ref) {
44
46
  return /* @__PURE__ */ jsx(Radio, {
45
47
  ...props,
48
+ inputRef: ref,
46
49
  "data-slot": "radio",
47
50
  className: cn(cnAll(selectionLabelVariants(), "justify-start"), className),
48
- children: ({ isSelected }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
51
+ children: ({ isSelected }) => /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
49
52
  "aria-hidden": "true",
50
53
  "data-slot": "radio-dot",
51
54
  className: radioVariants(),
52
- children: isSelected ? /* @__PURE__ */ jsx("span", {
55
+ children: /* @__PURE__ */ jsx("span", {
53
56
  "data-slot": "radio-indicator",
54
- className: "size-1.5 rounded-full bg-current"
55
- }) : null
57
+ "data-selected": isSelected || void 0,
58
+ className: "radio-dot size-1.5 rounded-full bg-current"
59
+ })
56
60
  }), children == null ? null : /* @__PURE__ */ jsx("span", {
57
61
  "data-slot": "radio-label",
58
62
  children
59
63
  })] })
60
64
  });
61
- }
65
+ });
62
66
  //#endregion
63
67
  export { Radio$1 as Radio, RadioGroup$1 as RadioGroup, radioGroupVariants, radioVariants };
64
68
 
@@ -1 +1 @@
1
- {"version":3,"file":"radio-group.js","names":["RadioGroup","AriaRadioGroup","Radio","AriaRadio"],"sources":["../../src/radio-group/radio-group.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport type { ReactNode } from \"react\";\nimport {\n Radio as AriaRadio,\n RadioGroup as AriaRadioGroup,\n type RadioGroupProps as AriaRadioGroupProps,\n type RadioProps as AriaRadioProps,\n} from \"react-aria-components\";\n\nimport { cn, cnAll } from \"../lib/cn.js\";\nimport { selectionLabelVariants, selectionRingVariants } from \"../lib/selection-control.js\";\n\n/**\n * RadioGroup, ported from the legacy shadcn/Radix component onto React Aria.\n *\n * Census: 1 file, 3 uses -- `RadioGroup` 1, `RadioGroupItem` 2. The\n * smallest real surface in the migration, so the port is deliberately plain.\n *\n * THE LABEL MOVES INSIDE THE ITEM. Radix's `RadioGroupItem` is a bare\n * button and the caller pairs it with a separate `<Label htmlFor>`; React\n * Aria's `Radio` takes its label as `children` and wires the association\n * itself. That is the one rename a call site has to make, and it removes\n * the id bookkeeping.\n *\n * `border-primary` becomes `border-border` for the same reason it did on\n * Checkbox: brand orange is 2.44:1 on white and cannot legally be the only\n * thing describing a control's edge (WCAG 1.4.11). Selected reuses\n * Checkbox's exact pair -- `bg-primary` with a `primary-strong` boundary --\n * so a radio and a checkbox in the same form agree.\n */\nexport const radioGroupVariants = cva([\n \"flex flex-col gap-2\",\n \"box-border font-sans\",\n]);\n\nexport const radioVariants = cva([\n \"inline-flex size-4 shrink-0 items-center justify-center\",\n \"rounded-full border-(length:--border-width) box-border\",\n \"bg-background border-border\",\n \"motion-safe:transition-colors motion-safe:duration-(--duration-fast) motion-safe:ease-standard\",\n \"group-data-[selected]:bg-primary group-data-[selected]:border-primary-strong\",\n \"group-data-[selected]:text-primary-foreground\",\n selectionRingVariants(),\n]);\n\n/**\n * A set of mutually exclusive choices.\n *\n * @example\n * <RadioGroup value={plan} onChange={setPlan} aria-label=\"Plan\">\n * <Radio value=\"free\">Free</Radio>\n * <Radio value=\"pro\">Pro</Radio>\n * </RadioGroup>\n */\nexport interface RadioGroupProps extends Omit<AriaRadioGroupProps, \"className\" | \"style\"> {\n /** Extra classes. Merged last, so they win conflicts with ours. */\n className?: string;\n}\n\nexport function RadioGroup({ className, ...props }: RadioGroupProps) {\n return (\n <AriaRadioGroup\n {...props}\n data-slot=\"radio-group\"\n className={cn(radioGroupVariants(), className)}\n />\n );\n}\n\n/**\n * One choice.\n *\n * @example\n * <Radio value=\"pro\">Pro</Radio>\n */\nexport interface RadioProps extends Omit<AriaRadioProps, \"className\" | \"style\" | \"children\"> {\n /** The label, and this option's accessible name. */\n children?: ReactNode;\n /** Extra classes for the label. Merged last, so they win conflicts. */\n className?: string;\n}\n\nexport function Radio({ className, children, ...props }: RadioProps) {\n return (\n <AriaRadio\n {...props}\n data-slot=\"radio\"\n // justify-start, overriding the shared label's centring: a radio sits\n // in a vertical list where every label must start on the same line,\n // not centre itself in a 24px box.\n className={cn(cnAll(selectionLabelVariants(), \"justify-start\"), className)}\n >\n {({ isSelected }) => (\n <>\n <span aria-hidden=\"true\" data-slot=\"radio-dot\" className={radioVariants()}>\n {isSelected ? (\n // Rendered in JS rather than toggled with CSS, so the\n // precedence is explicit and a test can read it from the DOM.\n <span data-slot=\"radio-indicator\" className=\"size-1.5 rounded-full bg-current\" />\n ) : null}\n </span>\n {children == null ? null : <span data-slot=\"radio-label\">{children}</span>}\n </>\n )}\n </AriaRadio>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,qBAAqB,IAAI,CACpC,uBACA,sBACF,CAAC;AAED,MAAa,gBAAgB,IAAI;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA,sBAAsB;AACxB,CAAC;AAgBD,SAAgBA,aAAW,EAAE,WAAW,GAAG,SAA0B;CACnE,OACE,oBAACC,YAAD;EACE,GAAI;EACJ,aAAU;EACV,WAAW,GAAG,mBAAmB,GAAG,SAAS;CAC9C,CAAA;AAEL;AAeA,SAAgBC,QAAM,EAAE,WAAW,UAAU,GAAG,SAAqB;CACnE,OACE,oBAACC,OAAD;EACE,GAAI;EACJ,aAAU;EAIV,WAAW,GAAG,MAAM,uBAAuB,GAAG,eAAe,GAAG,SAAS;EAEvE,WAAA,EAAE,iBACF,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,QAAD;GAAM,eAAY;GAAO,aAAU;GAAY,WAAW,cAAc;GACrE,UAAA,aAGC,oBAAC,QAAD;IAAM,aAAU;IAAkB,WAAU;GAAoC,CAAA,IAC9E;EACA,CAAA,GACL,YAAY,OAAO,OAAO,oBAAC,QAAD;GAAM,aAAU;GAAe;EAAe,CAAA,CACzE,EAAA,CAAA;CAEK,CAAA;AAEf"}
1
+ {"version":3,"file":"radio-group.js","names":["RadioGroup","AriaRadioGroup","Radio","AriaRadio"],"sources":["../../src/radio-group/radio-group.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport { forwardRef, type ReactNode } from \"react\";\nimport {\n Radio as AriaRadio,\n RadioGroup as AriaRadioGroup,\n type RadioGroupProps as AriaRadioGroupProps,\n type RadioProps as AriaRadioProps,\n} from \"react-aria-components\";\n\nimport { cn, cnAll } from \"../lib/cn.js\";\nimport { selectionLabelVariants, selectionRingVariants } from \"../lib/selection-control.js\";\n\n/**\n * RadioGroup, ported from the legacy shadcn/Radix component onto React Aria.\n *\n * Census: 1 file, 3 uses -- `RadioGroup` 1, `RadioGroupItem` 2. The\n * smallest real surface in the migration, so the port is deliberately plain.\n *\n * THE LABEL MOVES INSIDE THE ITEM. Radix's `RadioGroupItem` is a bare\n * button and the caller pairs it with a separate `<Label htmlFor>`; React\n * Aria's `Radio` takes its label as `children` and wires the association\n * itself. That is the one rename a call site has to make, and it removes\n * the id bookkeeping.\n *\n * `border-primary` becomes `border-border` for the same reason it did on\n * Checkbox: brand orange is 2.44:1 on white and cannot legally be the only\n * thing describing a control's edge (WCAG 1.4.11). Selected reuses\n * Checkbox's exact pair -- `bg-primary` with a `primary-strong` boundary --\n * so a radio and a checkbox in the same form agree.\n */\nexport const radioGroupVariants = cva([\n \"flex flex-col gap-2\",\n \"box-border font-sans\",\n]);\n\nexport const radioVariants = cva([\n \"inline-flex size-4 shrink-0 items-center justify-center\",\n \"rounded-full border-(length:--border-width) box-border\",\n \"bg-background border-border\",\n // Colours ease, the mark dips under a press and springs back (see radio-mark).\n \"radio-mark\",\n \"group-data-[selected]:bg-primary group-data-[selected]:border-primary-strong\",\n \"group-data-[selected]:text-primary-foreground\",\n selectionRingVariants(),\n]);\n\n/**\n * A set of mutually exclusive choices.\n *\n * @example\n * <RadioGroup value={plan} onChange={setPlan} aria-label=\"Plan\">\n * <Radio value=\"free\">Free</Radio>\n * <Radio value=\"pro\">Pro</Radio>\n * </RadioGroup>\n */\nexport interface RadioGroupProps extends Omit<AriaRadioGroupProps, \"className\" | \"style\"> {\n /** Extra classes. Merged last, so they win conflicts with ours. */\n className?: string;\n}\n\nexport const RadioGroup = forwardRef<HTMLDivElement, RadioGroupProps>(function RadioGroup(\n { className, ...props },\n ref,\n) {\n return (\n <AriaRadioGroup\n ref={ref}\n {...props}\n data-slot=\"radio-group\"\n className={cn(radioGroupVariants(), className)}\n />\n );\n});\n\n/**\n * One choice.\n *\n * @example\n * <Radio value=\"pro\">Pro</Radio>\n */\nexport interface RadioProps extends Omit<AriaRadioProps, \"className\" | \"style\" | \"children\"> {\n /** The label, and this option's accessible name. */\n children?: ReactNode;\n /** Extra classes for the label. Merged last, so they win conflicts. */\n className?: string;\n}\n\nexport const Radio = forwardRef<HTMLInputElement, RadioProps>(function Radio(\n { className, children, ...props },\n ref,\n) {\n return (\n <AriaRadio\n {...props}\n // inputRef, not ref: AriaRadio's own ref targets the label it renders\n // around a visually-hidden native input, and a label cannot be\n // focused -- ref.current.focus() would silently no-op. inputRef is\n // React Aria's own escape hatch to the real control.\n inputRef={ref}\n data-slot=\"radio\"\n // justify-start, overriding the shared label's centring: a radio sits\n // in a vertical list where every label must start on the same line,\n // not centre itself in a 24px box.\n className={cn(cnAll(selectionLabelVariants(), \"justify-start\"), className)}\n >\n {({ isSelected }) => (\n <>\n <span aria-hidden=\"true\" data-slot=\"radio-dot\" className={radioVariants()}>\n {/*\n Always there: the state decides whether it shows, so the dot can\n spring in and shrink away. data-selected carries the state to a\n test, which can no longer read it from the dot's presence.\n */}\n <span\n data-slot=\"radio-indicator\"\n data-selected={isSelected || undefined}\n className=\"radio-dot size-1.5 rounded-full bg-current\"\n />\n </span>\n {children == null ? null : <span data-slot=\"radio-label\">{children}</span>}\n </>\n )}\n </AriaRadio>\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,qBAAqB,IAAI,CACpC,uBACA,sBACF,CAAC;AAED,MAAa,gBAAgB,IAAI;CAC/B;CACA;CACA;CAEA;CACA;CACA;CACA,sBAAsB;AACxB,CAAC;AAgBD,MAAaA,eAAa,WAA4C,SAASA,aAC7E,EAAE,WAAW,GAAG,SAChB,KACA;CACA,OACE,oBAACC,YAAD;EACO;EACL,GAAI;EACJ,aAAU;EACV,WAAW,GAAG,mBAAmB,GAAG,SAAS;CAC9C,CAAA;AAEL,CAAC;AAeD,MAAaC,UAAQ,WAAyC,SAASA,QACrE,EAAE,WAAW,UAAU,GAAG,SAC1B,KACA;CACA,OACE,oBAACC,OAAD;EACE,GAAI;EAKJ,UAAU;EACV,aAAU;EAIV,WAAW,GAAG,MAAM,uBAAuB,GAAG,eAAe,GAAG,SAAS;EAEvE,WAAA,EAAE,iBACF,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,QAAD;GAAM,eAAY;GAAO,aAAU;GAAY,WAAW,cAAc;GAMtE,UAAA,oBAAC,QAAD;IACE,aAAU;IACV,iBAAe,cAAc,KAAA;IAC7B,WAAU;GACX,CAAA;EACG,CAAA,GACL,YAAY,OAAO,OAAO,oBAAC,QAAD;GAAM,aAAU;GAAe;EAAe,CAAA,CACzE,EAAA,CAAA;CAEK,CAAA;AAEf,CAAC"}
@@ -53,15 +53,26 @@ export interface ScrollAreaProps extends ComponentPropsWithoutRef<"div"> {
53
53
  * jump to it is the point.
54
54
  */
55
55
  label: string;
56
+ /**
57
+ * Fade the content out at an edge by exactly as much as there is content hidden
58
+ * past it, up to this many pixels: the fade grows in with the first pixels of
59
+ * scroll and is gone at the ends. `0` turns it off, and the default leaves the
60
+ * area as it was. Written on each scroll frame straight to the element, so
61
+ * scrolling never re-renders.
62
+ *
63
+ * @default 0
64
+ */
65
+ fade?: number;
56
66
  /**
57
67
  * Change this when the contents change, and the region scrolls back to the
58
68
  * top.
59
69
  *
60
- * It lives here rather than on the caller because the caller cannot reach
61
- * this node: no component in this package exposes a `ref`, and it must not
62
- * -- React 18 is a supported peer, where a `ref` passed as a plain prop to a
63
- * function component is silently dropped. The scroller owns its own
64
- * scrollTop, so the reset belongs with it.
70
+ * This stays a declarative prop even though a `ref` now exists: reaching
71
+ * for it would mean the caller writes `ref.current.scrollTop = 0` in their
72
+ * own effect on every content change, which is worse ergonomics than a
73
+ * prop that says "reset when this value changes." That is a design choice
74
+ * independent of whether a ref is available, not a consequence of one
75
+ * being withheld.
65
76
  *
66
77
  * Sheet forwards its own `scrollResetKey` straight through: going a level
67
78
  * deeper in a panel and landing halfway down the new view is disorienting,
@@ -69,6 +80,6 @@ export interface ScrollAreaProps extends ComponentPropsWithoutRef<"div"> {
69
80
  */
70
81
  scrollResetKey?: string | number;
71
82
  }
72
- export declare function ScrollArea({ className, children, label, scrollResetKey, ...props }: ScrollAreaProps): import("react").JSX.Element;
83
+ export declare const ScrollArea: import("react").ForwardRefExoticComponent<ScrollAreaProps & import("react").RefAttributes<HTMLDivElement>>;
73
84
  //#endregion
74
85
  //# sourceMappingURL=scroll-area.d.ts.map
@@ -1,8 +1,9 @@
1
1
  "use client";
2
- import { cn } from "../lib/cn.js";
2
+ import { cnAll } from "../lib/cn.js";
3
+ import { mergeRefs } from "../lib/merge-refs.js";
3
4
  import { cva } from "class-variance-authority";
5
+ import { forwardRef, useEffect, useMemo, useRef } from "react";
4
6
  import { jsx } from "react/jsx-runtime";
5
- import { useEffect, useRef } from "react";
6
7
  //#region src/scroll-area/scroll-area.tsx
7
8
  /**
8
9
  * ScrollArea. React Aria has no equivalent, so this is a plain scrolling
@@ -41,22 +42,45 @@ const scrollAreaVariants = cva([
41
42
  "focus-visible:outline-offset-(--focus-ring-offset)",
42
43
  "focus-visible:outline-(--color-ring)"
43
44
  ]);
44
- function ScrollArea({ className, children, label, scrollResetKey, ...props }) {
45
+ const ScrollArea = forwardRef(function ScrollArea({ className, children, label, scrollResetKey, fade = 0, onScroll, ...props }, ref) {
45
46
  const region = useRef(null);
46
47
  useEffect(() => {
47
48
  if (region.current) region.current.scrollTop = 0;
48
49
  }, [scrollResetKey]);
50
+ const rootRef = useMemo(() => mergeRefs(ref, region), [ref, region]);
51
+ const syncFade = () => {
52
+ const node = region.current;
53
+ if (!node || fade <= 0) return;
54
+ const max = Math.max(0, node.scrollHeight - node.clientHeight);
55
+ node.style.setProperty("--fade-top", `${Math.min(fade, node.scrollTop)}px`);
56
+ node.style.setProperty("--fade-bottom", `${Math.min(fade, max - node.scrollTop)}px`);
57
+ };
58
+ useEffect(() => {
59
+ const node = region.current;
60
+ if (!node || fade <= 0) return;
61
+ syncFade();
62
+ if (typeof ResizeObserver === "undefined") return;
63
+ const observer = new ResizeObserver(syncFade);
64
+ observer.observe(node);
65
+ for (const child of Array.from(node.children)) observer.observe(child);
66
+ return () => observer.disconnect();
67
+ }, [fade, children]);
49
68
  return /* @__PURE__ */ jsx("div", {
50
69
  ...props,
51
- ref: region,
70
+ ref: rootRef,
52
71
  tabIndex: 0,
53
72
  role: "region",
54
73
  "aria-label": label,
55
74
  "data-slot": "scroll-area",
56
- className: cn(scrollAreaVariants(), className),
75
+ "data-fade": fade > 0 ? "" : void 0,
76
+ onScroll: (event) => {
77
+ syncFade();
78
+ onScroll?.(event);
79
+ },
80
+ className: cnAll(scrollAreaVariants(), fade > 0 && "scroll-fade-y", className),
57
81
  children
58
82
  });
59
- }
83
+ });
60
84
  //#endregion
61
85
  export { ScrollArea, scrollAreaVariants };
62
86
 
@@ -1 +1 @@
1
- {"version":3,"file":"scroll-area.js","names":[],"sources":["../../src/scroll-area/scroll-area.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport { useEffect, useRef, type ComponentPropsWithoutRef, type ReactNode } from \"react\";\n\nimport { cn } from \"../lib/cn.js\";\n\n/**\n * ScrollArea. React Aria has no equivalent, so this is a plain scrolling\n * div -- and that is the honest answer rather than a shortcut.\n *\n * Census: fourteen paths match, thirteen are counted, ELEVEN render\n * anything, and across them 17 uses. Every single one passes `className`\n * and nothing else, and 13 of the 17 are a height or flex constraint plus\n * padding. `ScrollBar` is exported by the legacy and imported by nobody.\n * `orientation=\"horizontal\"` has zero call sites.\n *\n * So there is no styled-scrollbar requirement to port. The legacy pays for\n * one anyway: Radix injects a `<style>` tag that hides the native\n * scrollbar, then re-draws it in JavaScript with a ResizeObserver, a\n * portal-free overlay and a `display: table` content wrapper. That is a\n * lot of machinery to reproduce a scrollbar, and it is why the legacy\n * `ScrollArea` cannot be scrolled by keyboard at all.\n *\n * Tailwind 4.3.3 ships `scrollbar-width` and `scrollbar-color` utilities\n * (verified in the installed dist, not assumed), which gets the same look\n * in three classes and no JavaScript.\n *\n * WHAT CANNOT BE STYLED, stated rather than glossed: `scrollbar-color`\n * takes a thumb and a track colour and nothing else -- no width in pixels,\n * no radius, no hover state, no margins. `::-webkit-scrollbar` can do\n * those but is non-standard and Firefox has never supported it. This\n * component uses the standard properties only.\n */\nexport const scrollAreaVariants = cva([\n \"overflow-y-auto overscroll-contain\",\n \"box-border\",\n // Standard scrollbar properties. thumb = --color-border (5.25:1 on the\n // page), track transparent so it does not draw a channel.\n \"scrollbar-thin scrollbar-thumb-border scrollbar-track-transparent\",\n // A scrollable region must be reachable by keyboard, or its content is\n // unreachable without a pointer -- WCAG 2.1.1, and axe's\n // scrollable-region-focusable rule. The legacy has no tabIndex at all,\n // so all 17 of its scroll areas are keyboard traps in the other\n // direction: you can see the content but never scroll to it.\n \"outline-none\",\n \"focus-visible:outline-solid\",\n \"focus-visible:outline-(length:--focus-ring-width)\",\n \"focus-visible:outline-offset-(--focus-ring-offset)\",\n \"focus-visible:outline-(--color-ring)\",\n]);\n\n/**\n * A scrolling region.\n *\n * @example\n * <ScrollArea label=\"Chat messages\" className=\"h-64\">...</ScrollArea>\n */\nexport interface ScrollAreaProps extends ComponentPropsWithoutRef<\"div\"> {\n children?: ReactNode;\n /**\n * Names the scrolling region.\n *\n * **Required**, and it took a failing test to get here. A focusable\n * element with no role fails axe `focus-order-semantics`, so the\n * keyboard fix below cannot ship without a role -- and a role with no\n * accessible name is a violation of its own. Naming it is the only\n * combination that is actually correct.\n *\n * `role=\"region\"` specifically. `group` was the first attempt -- it is\n * lighter, since region is a landmark and seventeen landmarks in one app\n * is noise -- but axe does not accept `group` as an appropriate role for\n * a focusable element, and it is right: a named region is the role the\n * ARIA practices name for a scrollable content area, and being able to\n * jump to it is the point.\n */\n label: string;\n /**\n * Change this when the contents change, and the region scrolls back to the\n * top.\n *\n * It lives here rather than on the caller because the caller cannot reach\n * this node: no component in this package exposes a `ref`, and it must not\n * -- React 18 is a supported peer, where a `ref` passed as a plain prop to a\n * function component is silently dropped. The scroller owns its own\n * scrollTop, so the reset belongs with it.\n *\n * Sheet forwards its own `scrollResetKey` straight through: going a level\n * deeper in a panel and landing halfway down the new view is disorienting,\n * and it is exactly the thing every call site forgets.\n */\n scrollResetKey?: string | number;\n}\n\nexport function ScrollArea({\n className,\n children,\n label,\n scrollResetKey,\n ...props\n}: ScrollAreaProps) {\n const region = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n // Unconditional rather than guarded on scrollResetKey being set: with no\n // key this runs once on mount, where scrollTop is already 0.\n if (region.current) region.current.scrollTop = 0;\n }, [scrollResetKey]);\n\n return (\n <div\n {...props}\n ref={region}\n // tabIndex 0 unconditionally: whether the content overflows is a\n // runtime fact that changes as the content does, and a region that\n // becomes scrollable after a fetch would otherwise never gain focus.\n tabIndex={0}\n role=\"region\"\n aria-label={label}\n data-slot=\"scroll-area\"\n className={cn(scrollAreaVariants(), className)}\n >\n {children}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,qBAAqB,IAAI;CACpC;CACA;CAGA;CAMA;CACA;CACA;CACA;CACA;AACF,CAAC;AA4CD,SAAgB,WAAW,EACzB,WACA,UACA,OACA,gBACA,GAAG,SACe;CAClB,MAAM,SAAS,OAAuB,IAAI;CAE1C,gBAAgB;EAGd,IAAI,OAAO,SAAS,OAAO,QAAQ,YAAY;CACjD,GAAG,CAAC,cAAc,CAAC;CAEnB,OACE,oBAAC,OAAD;EACE,GAAI;EACJ,KAAK;EAIL,UAAU;EACV,MAAK;EACL,cAAY;EACZ,aAAU;EACV,WAAW,GAAG,mBAAmB,GAAG,SAAS;EAE5C;CACE,CAAA;AAET"}
1
+ {"version":3,"file":"scroll-area.js","names":[],"sources":["../../src/scroll-area/scroll-area.tsx"],"sourcesContent":["\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport {\n forwardRef,\n useEffect,\n useMemo,\n useRef,\n type ComponentPropsWithoutRef,\n type ReactNode,\n} from \"react\";\n\nimport { cnAll } from \"../lib/cn.js\";\nimport { mergeRefs } from \"../lib/merge-refs.js\";\n\n/**\n * ScrollArea. React Aria has no equivalent, so this is a plain scrolling\n * div -- and that is the honest answer rather than a shortcut.\n *\n * Census: fourteen paths match, thirteen are counted, ELEVEN render\n * anything, and across them 17 uses. Every single one passes `className`\n * and nothing else, and 13 of the 17 are a height or flex constraint plus\n * padding. `ScrollBar` is exported by the legacy and imported by nobody.\n * `orientation=\"horizontal\"` has zero call sites.\n *\n * So there is no styled-scrollbar requirement to port. The legacy pays for\n * one anyway: Radix injects a `<style>` tag that hides the native\n * scrollbar, then re-draws it in JavaScript with a ResizeObserver, a\n * portal-free overlay and a `display: table` content wrapper. That is a\n * lot of machinery to reproduce a scrollbar, and it is why the legacy\n * `ScrollArea` cannot be scrolled by keyboard at all.\n *\n * Tailwind 4.3.3 ships `scrollbar-width` and `scrollbar-color` utilities\n * (verified in the installed dist, not assumed), which gets the same look\n * in three classes and no JavaScript.\n *\n * WHAT CANNOT BE STYLED, stated rather than glossed: `scrollbar-color`\n * takes a thumb and a track colour and nothing else -- no width in pixels,\n * no radius, no hover state, no margins. `::-webkit-scrollbar` can do\n * those but is non-standard and Firefox has never supported it. This\n * component uses the standard properties only.\n */\nexport const scrollAreaVariants = cva([\n \"overflow-y-auto overscroll-contain\",\n \"box-border\",\n // Standard scrollbar properties. thumb = --color-border (5.25:1 on the\n // page), track transparent so it does not draw a channel.\n \"scrollbar-thin scrollbar-thumb-border scrollbar-track-transparent\",\n // A scrollable region must be reachable by keyboard, or its content is\n // unreachable without a pointer -- WCAG 2.1.1, and axe's\n // scrollable-region-focusable rule. The legacy has no tabIndex at all,\n // so all 17 of its scroll areas are keyboard traps in the other\n // direction: you can see the content but never scroll to it.\n \"outline-none\",\n \"focus-visible:outline-solid\",\n \"focus-visible:outline-(length:--focus-ring-width)\",\n \"focus-visible:outline-offset-(--focus-ring-offset)\",\n \"focus-visible:outline-(--color-ring)\",\n]);\n\n/**\n * A scrolling region.\n *\n * @example\n * <ScrollArea label=\"Chat messages\" className=\"h-64\">...</ScrollArea>\n */\nexport interface ScrollAreaProps extends ComponentPropsWithoutRef<\"div\"> {\n children?: ReactNode;\n /**\n * Names the scrolling region.\n *\n * **Required**, and it took a failing test to get here. A focusable\n * element with no role fails axe `focus-order-semantics`, so the\n * keyboard fix below cannot ship without a role -- and a role with no\n * accessible name is a violation of its own. Naming it is the only\n * combination that is actually correct.\n *\n * `role=\"region\"` specifically. `group` was the first attempt -- it is\n * lighter, since region is a landmark and seventeen landmarks in one app\n * is noise -- but axe does not accept `group` as an appropriate role for\n * a focusable element, and it is right: a named region is the role the\n * ARIA practices name for a scrollable content area, and being able to\n * jump to it is the point.\n */\n label: string;\n /**\n * Fade the content out at an edge by exactly as much as there is content hidden\n * past it, up to this many pixels: the fade grows in with the first pixels of\n * scroll and is gone at the ends. `0` turns it off, and the default leaves the\n * area as it was. Written on each scroll frame straight to the element, so\n * scrolling never re-renders.\n *\n * @default 0\n */\n fade?: number;\n /**\n * Change this when the contents change, and the region scrolls back to the\n * top.\n *\n * This stays a declarative prop even though a `ref` now exists: reaching\n * for it would mean the caller writes `ref.current.scrollTop = 0` in their\n * own effect on every content change, which is worse ergonomics than a\n * prop that says \"reset when this value changes.\" That is a design choice\n * independent of whether a ref is available, not a consequence of one\n * being withheld.\n *\n * Sheet forwards its own `scrollResetKey` straight through: going a level\n * deeper in a panel and landing halfway down the new view is disorienting,\n * and it is exactly the thing every call site forgets.\n */\n scrollResetKey?: string | number;\n}\n\nexport const ScrollArea = forwardRef<HTMLDivElement, ScrollAreaProps>(function ScrollArea(\n { className, children, label, scrollResetKey, fade = 0, onScroll, ...props },\n ref,\n) {\n const region = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n // Unconditional rather than guarded on scrollResetKey being set: with no\n // key this runs once on mount, where scrollTop is already 0.\n if (region.current) region.current.scrollTop = 0;\n }, [scrollResetKey]);\n\n // Memoized, not called inline on the div below: mergeRefs returns a new\n // callback every call, and an inline call is a new callback every render --\n // React would detach and reattach the DOM ref on every re-render instead of\n // only on mount, which matters here more than most, since ScrollArea's own\n // purpose is wrapping content that re-renders often.\n const rootRef = useMemo(() => mergeRefs(ref, region), [ref, region]);\n\n // The fade at each edge is how much content is hidden past it, up to `fade`.\n const syncFade = () => {\n const node = region.current;\n if (!node || fade <= 0) return;\n const max = Math.max(0, node.scrollHeight - node.clientHeight);\n node.style.setProperty(\"--fade-top\", `${Math.min(fade, node.scrollTop)}px`);\n node.style.setProperty(\"--fade-bottom\", `${Math.min(fade, max - node.scrollTop)}px`);\n };\n useEffect(() => {\n const node = region.current;\n if (!node || fade <= 0) return;\n syncFade();\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(syncFade);\n observer.observe(node);\n for (const child of Array.from(node.children)) observer.observe(child);\n return () => observer.disconnect();\n // syncFade only reads `fade` and the node, both covered here.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [fade, children]);\n\n return (\n <div\n {...props}\n ref={rootRef}\n // tabIndex 0 unconditionally: whether the content overflows is a\n // runtime fact that changes as the content does, and a region that\n // becomes scrollable after a fetch would otherwise never gain focus.\n tabIndex={0}\n role=\"region\"\n aria-label={label}\n data-slot=\"scroll-area\"\n data-fade={fade > 0 ? \"\" : undefined}\n onScroll={(event) => {\n syncFade();\n onScroll?.(event);\n }}\n className={cnAll(scrollAreaVariants(), fade > 0 && \"scroll-fade-y\", className)}\n >\n {children}\n </div>\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,qBAAqB,IAAI;CACpC;CACA;CAGA;CAMA;CACA;CACA;CACA;CACA;AACF,CAAC;AAuDD,MAAa,aAAa,WAA4C,SAAS,WAC7E,EAAE,WAAW,UAAU,OAAO,gBAAgB,OAAO,GAAG,UAAU,GAAG,SACrE,KACA;CACA,MAAM,SAAS,OAAuB,IAAI;CAE1C,gBAAgB;EAGd,IAAI,OAAO,SAAS,OAAO,QAAQ,YAAY;CACjD,GAAG,CAAC,cAAc,CAAC;CAOnB,MAAM,UAAU,cAAc,UAAU,KAAK,MAAM,GAAG,CAAC,KAAK,MAAM,CAAC;CAGnE,MAAM,iBAAiB;EACrB,MAAM,OAAO,OAAO;EACpB,IAAI,CAAC,QAAQ,QAAQ,GAAG;EACxB,MAAM,MAAM,KAAK,IAAI,GAAG,KAAK,eAAe,KAAK,YAAY;EAC7D,KAAK,MAAM,YAAY,cAAc,GAAG,KAAK,IAAI,MAAM,KAAK,SAAS,EAAE,GAAG;EAC1E,KAAK,MAAM,YAAY,iBAAiB,GAAG,KAAK,IAAI,MAAM,MAAM,KAAK,SAAS,EAAE,GAAG;CACrF;CACA,gBAAgB;EACd,MAAM,OAAO,OAAO;EACpB,IAAI,CAAC,QAAQ,QAAQ,GAAG;EACxB,SAAS;EACT,IAAI,OAAO,mBAAmB,aAAa;EAC3C,MAAM,WAAW,IAAI,eAAe,QAAQ;EAC5C,SAAS,QAAQ,IAAI;EACrB,KAAK,MAAM,SAAS,MAAM,KAAK,KAAK,QAAQ,GAAG,SAAS,QAAQ,KAAK;EACrE,aAAa,SAAS,WAAW;CAGnC,GAAG,CAAC,MAAM,QAAQ,CAAC;CAEnB,OACE,oBAAC,OAAD;EACE,GAAI;EACJ,KAAK;EAIL,UAAU;EACV,MAAK;EACL,cAAY;EACZ,aAAU;EACV,aAAW,OAAO,IAAI,KAAK,KAAA;EAC3B,WAAW,UAAU;GACnB,SAAS;GACT,WAAW,KAAK;EAClB;EACA,WAAW,MAAM,mBAAmB,GAAG,OAAO,KAAK,iBAAiB,SAAS;EAE5E;CACE,CAAA;AAET,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { SearchField, SearchFieldProps } from "./search-field.js";
2
+ export { SearchField, type SearchFieldProps };
@@ -0,0 +1,2 @@
1
+ import { SearchField } from "./search-field.js";
2
+ export { SearchField };
@@ -0,0 +1,26 @@
1
+ import { InputProps } from "react-aria-components";
2
+ //#region src/search-field/search-field.d.ts
3
+ export interface SearchFieldProps extends Omit<InputProps, "className" | "style" | "size" | "type" | "value" | "defaultValue" | "onChange"> {
4
+ /** Extra classes for the input. Merged last, so they win conflicts with ours. */
5
+ className?: string;
6
+ /** The visible label, tied to the input with `htmlFor`. */
7
+ label: string;
8
+ /** The current text. Controlled: the field has no state of its own. */
9
+ value: string;
10
+ /** Called with the new text on every edit, and with `""` when the clear button is pressed. */
11
+ onValueChange: (value: string) => void;
12
+ /** The clear button's accessible name. @default "Clear search" */
13
+ clearLabel?: string;
14
+ }
15
+ /**
16
+ * A search input with a clear button. The button has a reserved box, so the
17
+ * field never changes width as it comes and goes; pressing it clears the text
18
+ * and returns focus to the input. `onChange` is not accepted: use `onValueChange`.
19
+ * Native input props apply to the input, and `disabled` also disables the button.
20
+ *
21
+ * @example
22
+ * <SearchField label="Search contacts" value={query} onValueChange={setQuery} />
23
+ */
24
+ export declare const SearchField: import("react").ForwardRefExoticComponent<SearchFieldProps & import("react").RefAttributes<HTMLInputElement>>;
25
+ //#endregion
26
+ //# sourceMappingURL=search-field.d.ts.map
@@ -0,0 +1,155 @@
1
+ "use client";
2
+ import { cn } from "../lib/cn.js";
3
+ import { mergeRefs } from "../lib/merge-refs.js";
4
+ import { prefersReducedMotion, useExitBackstop, useIsomorphicLayoutEffect } from "../lib/motion.js";
5
+ import { fieldSurfaceVariants } from "../lib/field-surface.js";
6
+ import { FieldShell, useFieldWiring } from "../lib/field-shell.js";
7
+ import { forwardRef, useCallback, useMemo, useRef, useState } from "react";
8
+ import { Button, Group, Input } from "react-aria-components";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
10
+ //#region src/search-field/search-field.tsx
11
+ /**
12
+ * The field's box: a React Aria `Group` carrying the shared field surface (see
13
+ * PasswordField for why a Group, and why `data-focus-within` darkens the border
14
+ * as well). `group/shell` lets the glass read the box's focus and filled state.
15
+ */
16
+ const shellClass = cn(fieldSurfaceVariants(), "group/shell flex items-center gap-(--density-control-gap) h-(--density-control-h-md) px-(--density-control-pad-md) [&:where([data-focus-within])]:border-foreground");
17
+ /** Borderless, fill-less input; the browser's own clear button and search decoration are hidden because the field has its own. */
18
+ const inputClass = "min-w-0 flex-1 appearance-none border-0 bg-transparent p-0 font-sans text-base text-foreground outline-none placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground data-[disabled]:cursor-not-allowed [&::-webkit-search-cancel-button]:hidden [&::-webkit-search-decoration]:hidden";
19
+ const clearClass = "motion-safe:button-motion grid size-6 cursor-pointer place-items-center rounded-md border-0 bg-transparent p-0 text-muted-foreground outline-none data-[hovered]:bg-muted data-[hovered]:text-foreground motion-safe:data-[pressed]:scale-96 data-[focus-visible]:outline-solid data-[focus-visible]:outline-(length:--focus-ring-width) data-[focus-visible]:outline-offset-(--focus-ring-offset) data-[focus-visible]:outline-(--color-ring) data-[disabled]:cursor-not-allowed";
20
+ /** The glass wakes up with the field: muted at rest, full contrast while the field has focus or a value. */
21
+ function SearchGlyph() {
22
+ return /* @__PURE__ */ jsxs("svg", {
23
+ viewBox: "0 0 24 24",
24
+ fill: "none",
25
+ stroke: "currentColor",
26
+ strokeWidth: 2,
27
+ strokeLinecap: "round",
28
+ strokeLinejoin: "round",
29
+ "aria-hidden": "true",
30
+ className: "size-4.5 flex-none text-muted-foreground motion-safe:transition-colors motion-safe:duration-(--duration-quick) motion-safe:ease-settle group-data-[filled]/shell:text-foreground group-data-[focus-within]/shell:text-foreground",
31
+ children: [/* @__PURE__ */ jsx("circle", {
32
+ cx: "11",
33
+ cy: "11",
34
+ r: "8"
35
+ }), /* @__PURE__ */ jsx("path", { d: "m21 21-4.34-4.34" })]
36
+ });
37
+ }
38
+ /**
39
+ * The clear button, in a box that is always there so the field never changes
40
+ * width. It scales in on the snappy spring while it fades and unblurs, and
41
+ * leaves a little smaller. Nothing animates if it is there on first mount, and
42
+ * while it leaves it is inert so it cannot be pressed or focused.
43
+ */
44
+ function ClearButton({ show, label, disabled, onClear }) {
45
+ const [initial] = useState(show);
46
+ const [rendered, setRendered] = useState(show);
47
+ const [animated, setAnimated] = useState(false);
48
+ const leaving = rendered && !show;
49
+ if (show && !rendered) setRendered(true);
50
+ if (!animated && show !== initial) setAnimated(true);
51
+ const unmount = useCallback(() => setRendered(false), []);
52
+ useExitBackstop(leaving, unmount);
53
+ useIsomorphicLayoutEffect(() => {
54
+ if (leaving && prefersReducedMotion()) unmount();
55
+ }, [leaving, unmount]);
56
+ if (!rendered) return null;
57
+ return /* @__PURE__ */ jsx("span", {
58
+ ref: (node) => {
59
+ if (!node) return;
60
+ if (leaving) node.setAttribute("inert", "");
61
+ else node.removeAttribute("inert");
62
+ },
63
+ "aria-hidden": leaving || void 0,
64
+ onAnimationEnd: (event) => {
65
+ if (leaving && event.target === event.currentTarget && event.animationName === "field-clear-out") unmount();
66
+ },
67
+ className: cn("grid size-6 place-items-center", leaving ? "pointer-events-none motion-safe:animate-field-clear-out" : animated && "motion-safe:animate-field-clear-in motion-reduce:animate-fade-in"),
68
+ children: /* @__PURE__ */ jsx(Button, {
69
+ type: "button",
70
+ isDisabled: disabled,
71
+ "aria-label": label,
72
+ onPress: onClear,
73
+ className: clearClass,
74
+ children: /* @__PURE__ */ jsxs("svg", {
75
+ viewBox: "0 0 24 24",
76
+ fill: "none",
77
+ stroke: "currentColor",
78
+ strokeWidth: 2,
79
+ strokeLinecap: "round",
80
+ strokeLinejoin: "round",
81
+ "aria-hidden": "true",
82
+ className: "size-4",
83
+ children: [/* @__PURE__ */ jsx("path", { d: "M18 6 6 18" }), /* @__PURE__ */ jsx("path", { d: "m6 6 12 12" })]
84
+ })
85
+ })
86
+ });
87
+ }
88
+ /**
89
+ * A search input with a clear button. The button has a reserved box, so the
90
+ * field never changes width as it comes and goes; pressing it clears the text
91
+ * and returns focus to the input. `onChange` is not accepted: use `onValueChange`.
92
+ * Native input props apply to the input, and `disabled` also disables the button.
93
+ *
94
+ * @example
95
+ * <SearchField label="Search contacts" value={query} onValueChange={setQuery} />
96
+ */
97
+ const SearchField = forwardRef(function SearchField({ label, value, onValueChange, clearLabel = "Clear search", className, ...props }, ref) {
98
+ const inputRef = useRef(null);
99
+ const refs = useMemo(() => mergeRefs(ref, inputRef), [ref]);
100
+ const field = useFieldWiring({
101
+ enabled: true,
102
+ id: props.id,
103
+ describedBy: props["aria-describedby"],
104
+ invalid: props["aria-invalid"],
105
+ description: void 0,
106
+ error: void 0
107
+ });
108
+ const disabled = Boolean(props.disabled);
109
+ const control = /* @__PURE__ */ jsxs(Group, {
110
+ role: "presentation",
111
+ isDisabled: disabled,
112
+ "data-filled": value ? "true" : void 0,
113
+ "data-slot": "search-field-shell",
114
+ className: shellClass,
115
+ children: [
116
+ /* @__PURE__ */ jsx(SearchGlyph, {}),
117
+ /* @__PURE__ */ jsx(Input, {
118
+ ref: refs,
119
+ ...props,
120
+ ...field.controlProps,
121
+ type: "search",
122
+ value,
123
+ onChange: (event) => onValueChange(event.target.value),
124
+ "data-slot": "search-field",
125
+ className: cn(inputClass, className)
126
+ }),
127
+ /* @__PURE__ */ jsx("span", {
128
+ className: "grid size-6 flex-none place-items-center",
129
+ children: /* @__PURE__ */ jsx(ClearButton, {
130
+ show: value !== "",
131
+ label: clearLabel,
132
+ disabled,
133
+ onClear: () => {
134
+ onValueChange("");
135
+ inputRef.current?.focus();
136
+ }
137
+ })
138
+ })
139
+ ]
140
+ });
141
+ if (!field.active) return control;
142
+ return /* @__PURE__ */ jsx(FieldShell, {
143
+ label,
144
+ controlId: field.controlId,
145
+ description: void 0,
146
+ hintId: void 0,
147
+ error: void 0,
148
+ errorId: void 0,
149
+ children: control
150
+ });
151
+ });
152
+ //#endregion
153
+ export { SearchField };
154
+
155
+ //# sourceMappingURL=search-field.js.map