@slashsuite/ui-react 0.0.0-stage → 0.12.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 (304) hide show
  1. package/LICENSE +21 -0
  2. package/MIGRATING.md +540 -0
  3. package/README.md +549 -2
  4. package/dist/AppShell.d.ts +127 -0
  5. package/dist/AppShell.js +119 -0
  6. package/dist/AppShellMenu.d.ts +26 -0
  7. package/dist/AppShellMenu.js +66 -0
  8. package/dist/Avatar.d.ts +75 -0
  9. package/dist/Avatar.js +95 -0
  10. package/dist/AvatarStack.d.ts +31 -0
  11. package/dist/AvatarStack.js +34 -0
  12. package/dist/Badge.d.ts +15 -0
  13. package/dist/Badge.js +15 -0
  14. package/dist/BottomSheet.d.ts +36 -0
  15. package/dist/BottomSheet.js +142 -0
  16. package/dist/Breadcrumbs.d.ts +27 -0
  17. package/dist/Breadcrumbs.js +29 -0
  18. package/dist/BulletList.d.ts +18 -0
  19. package/dist/BulletList.js +18 -0
  20. package/dist/Button.d.ts +121 -0
  21. package/dist/Button.js +182 -0
  22. package/dist/ButtonGroup.d.ts +15 -0
  23. package/dist/ButtonGroup.js +10 -0
  24. package/dist/Callout.d.ts +43 -0
  25. package/dist/Callout.js +45 -0
  26. package/dist/Card.d.ts +148 -0
  27. package/dist/Card.js +171 -0
  28. package/dist/CardBadge.d.ts +7 -0
  29. package/dist/CardBadge.js +12 -0
  30. package/dist/CardBody.d.ts +28 -0
  31. package/dist/CardBody.js +30 -0
  32. package/dist/CardGrid.d.ts +53 -0
  33. package/dist/CardGrid.js +52 -0
  34. package/dist/CardParts.d.ts +40 -0
  35. package/dist/CardParts.js +41 -0
  36. package/dist/ChatComposer.d.ts +35 -0
  37. package/dist/ChatComposer.js +50 -0
  38. package/dist/ChatMessage.d.ts +26 -0
  39. package/dist/ChatMessage.js +21 -0
  40. package/dist/ChatThread.d.ts +25 -0
  41. package/dist/ChatThread.js +60 -0
  42. package/dist/Checkbox.d.ts +42 -0
  43. package/dist/Checkbox.js +63 -0
  44. package/dist/Chevron.d.ts +5 -0
  45. package/dist/Chevron.js +6 -0
  46. package/dist/Cluster.d.ts +70 -0
  47. package/dist/Cluster.js +47 -0
  48. package/dist/Code.d.ts +6 -0
  49. package/dist/Code.js +5 -0
  50. package/dist/CodeBlock.d.ts +46 -0
  51. package/dist/CodeBlock.js +21 -0
  52. package/dist/CodeBody.d.ts +20 -0
  53. package/dist/CodeBody.js +38 -0
  54. package/dist/CodeExample.d.ts +25 -0
  55. package/dist/CodeExample.js +17 -0
  56. package/dist/CodeText.d.ts +11 -0
  57. package/dist/CodeText.js +64 -0
  58. package/dist/ColourSchemeToggle.d.ts +36 -0
  59. package/dist/ColourSchemeToggle.js +64 -0
  60. package/dist/Container.d.ts +22 -0
  61. package/dist/Container.js +26 -0
  62. package/dist/CopyButton.d.ts +17 -0
  63. package/dist/CopyButton.js +39 -0
  64. package/dist/CopyLine.d.ts +9 -0
  65. package/dist/CopyLine.js +7 -0
  66. package/dist/DateCalendar.d.ts +23 -0
  67. package/dist/DateCalendar.js +89 -0
  68. package/dist/DateField.d.ts +124 -0
  69. package/dist/DateField.js +111 -0
  70. package/dist/DateFieldCalendar.d.ts +24 -0
  71. package/dist/DateFieldCalendar.js +50 -0
  72. package/dist/DateRangePicker.d.ts +47 -0
  73. package/dist/DateRangePicker.js +44 -0
  74. package/dist/Dialog.d.ts +56 -0
  75. package/dist/Dialog.js +94 -0
  76. package/dist/Disclosure.d.ts +29 -0
  77. package/dist/Disclosure.js +23 -0
  78. package/dist/Divider.d.ts +4 -0
  79. package/dist/Divider.js +5 -0
  80. package/dist/DocsLayout.d.ts +69 -0
  81. package/dist/DocsLayout.js +64 -0
  82. package/dist/Drawer.d.ts +30 -0
  83. package/dist/Drawer.js +24 -0
  84. package/dist/EmptyState.d.ts +47 -0
  85. package/dist/EmptyState.js +34 -0
  86. package/dist/Field.d.ts +44 -0
  87. package/dist/Field.js +51 -0
  88. package/dist/FieldDialog.d.ts +26 -0
  89. package/dist/FieldDialog.js +31 -0
  90. package/dist/Fieldset.d.ts +21 -0
  91. package/dist/Fieldset.js +22 -0
  92. package/dist/FileDrop.d.ts +17 -0
  93. package/dist/FileDrop.js +14 -0
  94. package/dist/FormRow.d.ts +46 -0
  95. package/dist/FormRow.js +39 -0
  96. package/dist/Hero.d.ts +23 -0
  97. package/dist/Hero.js +28 -0
  98. package/dist/Icon.d.ts +40 -0
  99. package/dist/Icon.js +30 -0
  100. package/dist/IconButton.d.ts +72 -0
  101. package/dist/IconButton.js +65 -0
  102. package/dist/Image.d.ts +58 -0
  103. package/dist/Image.js +69 -0
  104. package/dist/InlineEdit.d.ts +22 -0
  105. package/dist/InlineEdit.js +60 -0
  106. package/dist/Input.d.ts +40 -0
  107. package/dist/Input.js +42 -0
  108. package/dist/InputShell.d.ts +24 -0
  109. package/dist/InputShell.js +40 -0
  110. package/dist/Kbd.d.ts +6 -0
  111. package/dist/Kbd.js +5 -0
  112. package/dist/KeyValueList.d.ts +34 -0
  113. package/dist/KeyValueList.js +35 -0
  114. package/dist/Lightbox.d.ts +45 -0
  115. package/dist/Lightbox.js +46 -0
  116. package/dist/ListRow.d.ts +26 -0
  117. package/dist/ListRow.js +151 -0
  118. package/dist/Markdown.d.ts +11 -0
  119. package/dist/Markdown.js +49 -0
  120. package/dist/MediaTile.d.ts +66 -0
  121. package/dist/MediaTile.js +50 -0
  122. package/dist/Menu.d.ts +64 -0
  123. package/dist/Menu.js +86 -0
  124. package/dist/MetaList.d.ts +23 -0
  125. package/dist/MetaList.js +20 -0
  126. package/dist/Morph.d.ts +41 -0
  127. package/dist/Morph.js +107 -0
  128. package/dist/NavigationProgress.d.ts +20 -0
  129. package/dist/NavigationProgress.js +26 -0
  130. package/dist/OutlineRegion.d.ts +60 -0
  131. package/dist/OutlineRegion.js +51 -0
  132. package/dist/PageFade.d.ts +30 -0
  133. package/dist/PageFade.js +46 -0
  134. package/dist/PageHeader.d.ts +26 -0
  135. package/dist/PageHeader.js +18 -0
  136. package/dist/PageLayouts.d.ts +100 -0
  137. package/dist/PageLayouts.js +78 -0
  138. package/dist/Pagination.d.ts +38 -0
  139. package/dist/Pagination.js +65 -0
  140. package/dist/Pill.d.ts +79 -0
  141. package/dist/Pill.js +121 -0
  142. package/dist/ProgressBar.d.ts +47 -0
  143. package/dist/ProgressBar.js +47 -0
  144. package/dist/RadioGroup.d.ts +55 -0
  145. package/dist/RadioGroup.js +53 -0
  146. package/dist/ScrollStrip.d.ts +21 -0
  147. package/dist/ScrollStrip.js +12 -0
  148. package/dist/SearchInput.d.ts +9 -0
  149. package/dist/SearchInput.js +55 -0
  150. package/dist/Section.d.ts +93 -0
  151. package/dist/Section.js +55 -0
  152. package/dist/SegmentedControl.d.ts +47 -0
  153. package/dist/SegmentedControl.js +78 -0
  154. package/dist/Select.d.ts +28 -0
  155. package/dist/Select.js +19 -0
  156. package/dist/Show.d.ts +33 -0
  157. package/dist/Show.js +27 -0
  158. package/dist/SideColumn.d.ts +50 -0
  159. package/dist/SideColumn.js +45 -0
  160. package/dist/SidebarLayout.d.ts +32 -0
  161. package/dist/SidebarLayout.js +77 -0
  162. package/dist/SiteFooter.d.ts +31 -0
  163. package/dist/SiteFooter.js +24 -0
  164. package/dist/SiteSearch.d.ts +40 -0
  165. package/dist/SiteSearch.js +150 -0
  166. package/dist/SortableList.d.ts +86 -0
  167. package/dist/SortableList.js +191 -0
  168. package/dist/SplitBar.d.ts +29 -0
  169. package/dist/SplitBar.js +22 -0
  170. package/dist/Stack.d.ts +114 -0
  171. package/dist/Stack.js +76 -0
  172. package/dist/StackedBar.d.ts +64 -0
  173. package/dist/StackedBar.js +58 -0
  174. package/dist/StatTile.d.ts +33 -0
  175. package/dist/StatTile.js +44 -0
  176. package/dist/StatusPages.d.ts +49 -0
  177. package/dist/StatusPages.js +63 -0
  178. package/dist/Steps.d.ts +29 -0
  179. package/dist/Steps.js +43 -0
  180. package/dist/StickyBar.d.ts +12 -0
  181. package/dist/StickyBar.js +10 -0
  182. package/dist/Switch.d.ts +56 -0
  183. package/dist/Switch.js +91 -0
  184. package/dist/Table.d.ts +92 -0
  185. package/dist/Table.js +92 -0
  186. package/dist/TableCells.d.ts +97 -0
  187. package/dist/TableCells.js +104 -0
  188. package/dist/TableEditCell.d.ts +31 -0
  189. package/dist/TableEditCell.js +17 -0
  190. package/dist/TableExpandCell.d.ts +25 -0
  191. package/dist/TableExpandCell.js +15 -0
  192. package/dist/Tabs.d.ts +38 -0
  193. package/dist/Tabs.js +46 -0
  194. package/dist/TextLink.d.ts +51 -0
  195. package/dist/TextLink.js +38 -0
  196. package/dist/Textarea.d.ts +11 -0
  197. package/dist/Textarea.js +11 -0
  198. package/dist/Timeline.d.ts +31 -0
  199. package/dist/Timeline.js +38 -0
  200. package/dist/ToastRegion.d.ts +44 -0
  201. package/dist/ToastRegion.js +37 -0
  202. package/dist/Tooltip.d.ts +46 -0
  203. package/dist/Tooltip.js +181 -0
  204. package/dist/TrendChart.d.ts +36 -0
  205. package/dist/TrendChart.js +58 -0
  206. package/dist/Video.d.ts +13 -0
  207. package/dist/Video.js +9 -0
  208. package/dist/blocked.d.ts +31 -0
  209. package/dist/blocked.js +31 -0
  210. package/dist/cardContext.d.ts +8 -0
  211. package/dist/cardContext.js +14 -0
  212. package/dist/cardWait.d.ts +13 -0
  213. package/dist/cardWait.js +16 -0
  214. package/dist/colourScheme.d.ts +22 -0
  215. package/dist/colourScheme.js +53 -0
  216. package/dist/control.d.ts +29 -0
  217. package/dist/control.js +37 -0
  218. package/dist/copyScript.d.ts +13 -0
  219. package/dist/copyScript.js +13 -0
  220. package/dist/cx.d.ts +19 -0
  221. package/dist/cx.js +21 -0
  222. package/dist/density.d.ts +38 -0
  223. package/dist/density.js +77 -0
  224. package/dist/emptySlot.d.ts +11 -0
  225. package/dist/emptySlot.js +16 -0
  226. package/dist/fieldControl.d.ts +23 -0
  227. package/dist/fieldControl.js +24 -0
  228. package/dist/fieldWait.d.ts +30 -0
  229. package/dist/fieldWait.js +27 -0
  230. package/dist/foldedColumn.d.ts +18 -0
  231. package/dist/foldedColumn.js +51 -0
  232. package/dist/headingLevel.d.ts +10 -0
  233. package/dist/headingLevel.js +18 -0
  234. package/dist/highlight.d.ts +18 -0
  235. package/dist/highlight.js +306 -0
  236. package/dist/highlightConsole.d.ts +9 -0
  237. package/dist/highlightConsole.js +42 -0
  238. package/dist/highlightHtml.d.ts +7 -0
  239. package/dist/highlightHtml.js +132 -0
  240. package/dist/highlightKit.d.ts +16 -0
  241. package/dist/highlightKit.js +23 -0
  242. package/dist/highlightYaml.d.ts +3 -0
  243. package/dist/highlightYaml.js +143 -0
  244. package/dist/icons.d.ts +16 -0
  245. package/dist/icons.js +108 -0
  246. package/dist/index.d.ts +99 -0
  247. package/dist/index.js +92 -0
  248. package/dist/isoDate.d.ts +5 -0
  249. package/dist/isoDate.js +16 -0
  250. package/dist/labelWords.d.ts +20 -0
  251. package/dist/labelWords.js +28 -0
  252. package/dist/layoutWait.d.ts +15 -0
  253. package/dist/layoutWait.js +18 -0
  254. package/dist/link.d.ts +82 -0
  255. package/dist/link.js +68 -0
  256. package/dist/listRowProps.d.ts +108 -0
  257. package/dist/listRowProps.js +1 -0
  258. package/dist/listRowWait.d.ts +6 -0
  259. package/dist/listRowWait.js +14 -0
  260. package/dist/modal.d.ts +25 -0
  261. package/dist/modal.js +61 -0
  262. package/dist/navFold.d.ts +15 -0
  263. package/dist/navFold.js +46 -0
  264. package/dist/pillTip.d.ts +8 -0
  265. package/dist/pillTip.js +25 -0
  266. package/dist/props.d.ts +26 -0
  267. package/dist/props.js +14 -0
  268. package/dist/scrollEdges.d.ts +12 -0
  269. package/dist/scrollEdges.js +40 -0
  270. package/dist/scrollStop.d.ts +32 -0
  271. package/dist/scrollStop.js +79 -0
  272. package/dist/sheetSnap.d.ts +27 -0
  273. package/dist/sheetSnap.js +45 -0
  274. package/dist/shownDate.d.ts +88 -0
  275. package/dist/shownDate.js +186 -0
  276. package/dist/size.d.ts +45 -0
  277. package/dist/size.js +12 -0
  278. package/dist/skeleton.d.ts +83 -0
  279. package/dist/skeleton.js +88 -0
  280. package/dist/stackGap.d.ts +9 -0
  281. package/dist/stackGap.js +16 -0
  282. package/dist/stickyColumn.d.ts +38 -0
  283. package/dist/stickyColumn.js +38 -0
  284. package/dist/switcher.d.ts +93 -0
  285. package/dist/switcher.js +78 -0
  286. package/dist/tableColumns.d.ts +31 -0
  287. package/dist/tableColumns.js +72 -0
  288. package/dist/tableEmpty.d.ts +15 -0
  289. package/dist/tableEmpty.js +26 -0
  290. package/dist/tableRow.d.ts +67 -0
  291. package/dist/tableRow.js +49 -0
  292. package/dist/tableSort.d.ts +22 -0
  293. package/dist/tableSort.js +19 -0
  294. package/dist/textBox.d.ts +10 -0
  295. package/dist/textBox.js +23 -0
  296. package/dist/tone.d.ts +11 -0
  297. package/dist/tone.js +1 -0
  298. package/dist/trend.d.ts +26 -0
  299. package/dist/trend.js +64 -0
  300. package/dist/typography.d.ts +203 -0
  301. package/dist/typography.js +242 -0
  302. package/dist/useImageFailed.d.ts +19 -0
  303. package/dist/useImageFailed.js +21 -0
  304. package/package.json +84 -4
@@ -0,0 +1,111 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CalendarDate as CalendarDateClass, DateFormatter, } from "@internationalized/date";
3
+ import { useContext, useEffect } from "react";
4
+ import { DateField as AriaDateField, DateFieldStateContext, DateInput, DateSegment, FieldError, I18nProvider, Label, Text, } from "react-aria-components";
5
+ import { cx, focusRing } from "./cx.js";
6
+ import { CalendarDateField } from "./DateFieldCalendar.js";
7
+ import { toISODate } from "./isoDate.js";
8
+ import { definedProps } from "./props.js";
9
+ import { WaitingField } from "./fieldWait.js";
10
+ import { useLoading } from "./skeleton.js";
11
+ import { ShownInput, useShownDate } from "./shownDate.js";
12
+ import { controlText, useTypeStep } from "./density.js";
13
+ /** Fixed, whatever the browser's locale: DD/MM/YYYY and Monday-first weeks. */
14
+ export const LOCALE = "en-GB";
15
+ const MONTHS = new DateFormatter(LOCALE, { month: "long", timeZone: "UTC" });
16
+ export const MONTH_OPTIONS = Array.from({ length: 12 }, (_, i) => ({
17
+ month: i + 1,
18
+ name: MONTHS.format(new Date(Date.UTC(2000, i, 1))),
19
+ }));
20
+ /** The react-aria flags for `disabled` and `required`, set only when true. */
21
+ export function fieldFlags(disabled, required) {
22
+ return { ...(disabled ? { isDisabled: true } : {}), ...(required ? { isRequired: true } : {}) };
23
+ }
24
+ function readSegments(segments) {
25
+ const editable = segments.filter((segment) => segment.isEditable);
26
+ const blank = editable.filter((segment) => segment.isPlaceholder).length;
27
+ const none = { typed: "", impossible: null, partial: blank > 0 && blank < editable.length };
28
+ if (editable.length === 0 || blank > 0)
29
+ return none;
30
+ const part = (type) => editable.find((s) => s.type === type)?.value ?? 0;
31
+ const [day, month, year] = [part("day"), part("month"), part("year")];
32
+ if (day < 1 || month < 1 || year < 1)
33
+ return none;
34
+ const first = new CalendarDateClass(year, month, 1);
35
+ const days = first.calendar.getDaysInMonth(first);
36
+ if (day <= days)
37
+ return { ...none, typed: toISODate(first.set({ day })) };
38
+ return {
39
+ ...none,
40
+ impossible: `${MONTH_OPTIONS[month - 1]?.name ?? ""} ${year} has ${days} days.`,
41
+ };
42
+ }
43
+ /** One segment. The day segment also reports what the segments show to the field. */
44
+ export function FieldSegment({ segment, onRead, }) {
45
+ const state = useContext(DateFieldStateContext);
46
+ const { typed, impossible, partial } = readSegments(state?.segments ?? []);
47
+ useEffect(() => onRead?.({ typed, impossible, partial }), [typed, impossible, partial, onRead]);
48
+ return (_jsx(DateSegment, { segment: segment, className: ({ isFocused, isPlaceholder, type }) => {
49
+ if (type === "literal")
50
+ return "text-slate-400";
51
+ let tone = "text-slate-900";
52
+ if (isFocused)
53
+ tone = "bg-violet-50 text-violet-600";
54
+ else if (isPlaceholder)
55
+ tone = "text-slate-400";
56
+ return cx("rounded px-0.5 tabular-nums outline-none", tone);
57
+ }, children: ({ isPlaceholder, placeholder, text }) => (isPlaceholder ? placeholder.toUpperCase() : text) }));
58
+ }
59
+ export function frameClass({ isInvalid, isFocusWithin, isDisabled, }) {
60
+ let tone = "border-slate-300 bg-white text-slate-900 hover:border-violet-400";
61
+ if (isInvalid)
62
+ tone = "border-red-200 bg-white text-slate-900";
63
+ else if (isFocusWithin)
64
+ tone = "border-violet-600 bg-white text-slate-900";
65
+ return cx("flex w-full items-center rounded-lg border transition", tone, isDisabled && "opacity-50");
66
+ }
67
+ /** The props that force a field invalid: an impossible date, or an `error` from outside. Spread onto the React Aria field after the rest. */
68
+ export function forcedInvalid({ impossible, error, }) {
69
+ return impossible || error ? { isInvalid: true } : {};
70
+ }
71
+ /** The hint or the error line: the shared outside of every date field. */
72
+ export function Notes({ hint, error, impossible, isInvalid, }) {
73
+ return (_jsxs(_Fragment, { children: [!isInvalid && hint ? (_jsx(Text, { slot: "description", className: "text-xs text-slate-500", children: hint })) : null, _jsx(FieldError, { className: "text-xs text-red-700", children: ({ validationErrors }) => error ? _jsx("span", { role: "alert", children: error }) : (impossible ?? validationErrors.join(" ")) })] }));
74
+ }
75
+ /** A `DateField`'s padding, by `size`: the heights of an `Input`. Its type is `controlText`'s, as an `Input`'s. */
76
+ const FIELD_SIZE = {
77
+ sm: "py-1 pl-2 pr-2",
78
+ md: "py-2 pl-2.5 pr-2.5",
79
+ lg: "py-2.5 pl-3 pr-3",
80
+ };
81
+ export const labelClass = "text-sm font-medium text-slate-700";
82
+ /** A small icon button inside a date field or calendar, without its box size. */
83
+ export const iconButtonLook = `inline-flex shrink-0 items-center justify-center rounded-md text-slate-500 transition hover:bg-slate-100 disabled:opacity-50 ${focusRing}`;
84
+ export const iconButtonClass = `${iconButtonLook} h-7 w-7`;
85
+ /**
86
+ * A segmented DD / MM / YYYY date input. Values are `CalendarDate`s; `name` posts it as
87
+ * `YYYY-MM-DD`. `calendar` adds a calendar button that opens a month view in a popover, at the
88
+ * same height as the plain field; `defaultOpen` opens it on mount. While `loading` the label is
89
+ * drawn and the field is a bone of its height.
90
+ */
91
+ export function DateField({ calendar, defaultOpen, monthLabel = "Month", yearLabel = "Year", loading, loadingLabel, ...field }) {
92
+ if (useLoading(loading).loading) {
93
+ return (_jsx(WaitingField, { own: loading, loadingLabel: loadingLabel, label: field.label, look: labelClass, size: field.size, attrs: field }));
94
+ }
95
+ if (calendar) {
96
+ return (_jsx(CalendarDateField, { ...field, labels: { monthLabel, yearLabel }, ...(defaultOpen === undefined ? {} : { defaultOpen }) }));
97
+ }
98
+ return _jsx(PlainDateField, { ...field });
99
+ }
100
+ function PlainDateField({ label, hint, error, disabled, required, value, defaultValue, onChange, name, size = "md", ...rest }) {
101
+ const step = useTypeStep();
102
+ const { inner, setInner, shown, impossible, onRead, validate, leaving, onBlurCapture, onLeft } = useShownDate({
103
+ value,
104
+ defaultValue,
105
+ onChange,
106
+ minValue: rest.minValue,
107
+ maxValue: rest.maxValue,
108
+ isRequired: required,
109
+ });
110
+ return (_jsx(I18nProvider, { locale: LOCALE, children: _jsx(AriaDateField, { ...definedProps(rest), ...fieldFlags(disabled, required), value: inner, onChange: setInner, validate: validate, ...forcedInvalid({ impossible, error }), isReadOnly: leaving, onBlur: onLeft, granularity: "day", shouldForceLeadingZeros: true, className: "flex flex-col gap-1.5", children: ({ isInvalid }) => (_jsxs(_Fragment, { children: [label ? _jsx(Label, { className: labelClass, children: label }) : null, _jsx("div", { className: "contents", onBlurCapture: onBlurCapture, children: _jsx(DateInput, { className: (state) => cx(frameClass(state), FIELD_SIZE[size], controlText(size, step, true)), children: (segment) => (_jsx(FieldSegment, { segment: segment, ...(segment.type === "day" ? { onRead } : {}) })) }) }), _jsx(ShownInput, { name: name, shown: shown, isDisabled: disabled }), _jsx(Notes, { hint: hint, error: error, impossible: impossible, isInvalid: isInvalid })] })) }) }));
111
+ }
@@ -0,0 +1,24 @@
1
+ import { type ReactElement } from "react";
2
+ import { type CalendarLabels } from "./DateCalendar.js";
3
+ import { type FieldProps } from "./DateField.js";
4
+ import type { Size } from "./size.js";
5
+ /** The picker's padding and calendar button, by `size` (its type is `controlText`'s). The button sets the height, so the padding is less than a `DateField`'s. */
6
+ export declare const PICKER_SIZE: Record<Size, {
7
+ frame: string;
8
+ button: string;
9
+ }>;
10
+ /** The picker's frame at `size`: its gap and padding, and the type of a control at the type step in force. */
11
+ export declare function usePickerFrame(size: Size): string;
12
+ /**
13
+ * The modal `<dialog>` a picker sits in, if any, for its popover's `container`: pass `findDialog` as the
14
+ * picker's `ref`.
15
+ */
16
+ export declare function useDialogContainer(): {
17
+ container: Element | undefined;
18
+ findDialog: (el: HTMLDivElement | null) => void;
19
+ };
20
+ /** The body of `<DateField calendar>`: the field with a calendar button that opens a month view in a popover. */
21
+ export declare function CalendarDateField({ label, hint, error, disabled, required, labels, value, defaultValue, onChange, name, size, ...rest }: FieldProps & {
22
+ defaultOpen?: boolean;
23
+ labels: CalendarLabels;
24
+ }): ReactElement;
@@ -0,0 +1,50 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useContext, useState } from "react";
3
+ import { Button, DatePicker as AriaDatePicker, DateFieldContext, DateInput, Group, I18nProvider, Label, } from "react-aria-components";
4
+ import { cx } from "./cx.js";
5
+ import { CalendarPopover, calendarIcon } from "./DateCalendar.js";
6
+ import { FieldSegment, LOCALE, fieldFlags, forcedInvalid, Notes, frameClass, iconButtonLook, labelClass, } from "./DateField.js";
7
+ import { definedProps } from "./props.js";
8
+ import { ShownInput, useShownDate } from "./shownDate.js";
9
+ import { controlText, useTypeStep } from "./density.js";
10
+ /** The picker's padding and calendar button, by `size` (its type is `controlText`'s). The button sets the height, so the padding is less than a `DateField`'s. */
11
+ export const PICKER_SIZE = {
12
+ sm: { frame: "py-0.5 pl-2 pr-0.5", button: "h-5 w-5" },
13
+ md: { frame: "py-1 pl-2.5 pr-1", button: "h-7 w-7" },
14
+ lg: { frame: "py-1.5 pl-3 pr-1.5", button: "h-8 w-8" },
15
+ };
16
+ /** The picker's frame at `size`: its gap and padding, and the type of a control at the type step in force. */
17
+ export function usePickerFrame(size) {
18
+ return cx("gap-1", PICKER_SIZE[size].frame, controlText(size, useTypeStep(), true));
19
+ }
20
+ /**
21
+ * The picker's input, read-only while `leaving`. Only the field: a read-only picker would also
22
+ * disable the calendar button that focus may be moving to.
23
+ */
24
+ function PickerInput({ leaving, onLeft, children, }) {
25
+ const field = useContext(DateFieldContext);
26
+ return (_jsx(DateFieldContext.Provider, { value: { ...field, isReadOnly: leaving, onBlur: onLeft }, children: children }));
27
+ }
28
+ /**
29
+ * The modal `<dialog>` a picker sits in, if any, for its popover's `container`: pass `findDialog` as the
30
+ * picker's `ref`.
31
+ */
32
+ export function useDialogContainer() {
33
+ const [container, setContainer] = useState(undefined);
34
+ const findDialog = useCallback((el) => setContainer(el?.closest("dialog") ?? undefined), []);
35
+ return { container, findDialog };
36
+ }
37
+ /** The body of `<DateField calendar>`: the field with a calendar button that opens a month view in a popover. */
38
+ export function CalendarDateField({ label, hint, error, disabled, required, labels, value, defaultValue, onChange, name, size = "md", ...rest }) {
39
+ const frame = usePickerFrame(size);
40
+ const { inner, setInner, shown, impossible, onRead, validate, leaving, onBlurCapture, onLeft } = useShownDate({
41
+ value,
42
+ defaultValue,
43
+ onChange,
44
+ minValue: rest.minValue,
45
+ maxValue: rest.maxValue,
46
+ isRequired: required,
47
+ });
48
+ const { container, findDialog } = useDialogContainer();
49
+ return (_jsx(I18nProvider, { locale: LOCALE, children: _jsx(AriaDatePicker, { ...definedProps(rest), ...fieldFlags(disabled, required), ref: findDialog, value: inner, onChange: setInner, validate: validate, ...forcedInvalid({ impossible, error }), granularity: "day", shouldForceLeadingZeros: true, className: "flex flex-col gap-1.5", children: ({ isInvalid }) => (_jsxs(_Fragment, { children: [label ? _jsx(Label, { className: labelClass, children: label }) : null, _jsxs(Group, { className: (state) => cx(frameClass(state), frame), children: [_jsx("div", { className: "contents", onBlurCapture: onBlurCapture, children: _jsx(PickerInput, { leaving: leaving, onLeft: onLeft, children: _jsx(DateInput, { className: "flex flex-1", children: (segment) => (_jsx(FieldSegment, { segment: segment, ...(segment.type === "day" ? { onRead } : {}) })) }) }) }), _jsx(Button, { className: cx(iconButtonLook, PICKER_SIZE[size].button), children: calendarIcon })] }), _jsx(ShownInput, { name: name, shown: shown, isDisabled: disabled }), _jsx(Notes, { hint: hint, error: error, impossible: impossible, isInvalid: isInvalid }), _jsx(CalendarPopover, { container: container, labels: labels })] })) }) }));
50
+ }
@@ -0,0 +1,47 @@
1
+ import { type ReactElement } from "react";
2
+ import { type FieldProps } from "./DateField.js";
3
+ import { type Passthrough } from "./props.js";
4
+ import { type ShownRange } from "./shownDate.js";
5
+ /** A from and to date: `start` on or before `end`. */
6
+ export type DateRange = ShownRange;
7
+ /** A ready-made range the app builds from its own today, such as "Last 7 days". */
8
+ export type DateRangePreset = {
9
+ label: string;
10
+ value: DateRange;
11
+ };
12
+ export type DateRangePickerProps = Pick<FieldProps, "label" | "hint" | "error" | "size" | "minValue" | "maxValue" | "required" | "disabled"> & Passthrough & {
13
+ /** The range, or `null` for none. Reported only when both days are complete, real and in order. */
14
+ value?: DateRange | null | undefined;
15
+ /** The range shown first when the picker holds its own value. */
16
+ defaultValue?: DateRange | null | undefined;
17
+ /** Called with the range once both sides make one, and with `null` when they stop making one. */
18
+ onChange?: ((range: DateRange | null) => void) | undefined;
19
+ /** Posts the start as `YYYY-MM-DD` in a form, or `""` while there is no range. */
20
+ startName?: string | undefined;
21
+ /** Posts the end as `YYYY-MM-DD` in a form, or `""` while there is no range. */
22
+ endName?: string | undefined;
23
+ /**
24
+ * Ready-made ranges, a row of buttons above the month. The app builds them from its own today;
25
+ * the picker has none of its own and never reads the clock.
26
+ */
27
+ presets?: readonly DateRangePreset[] | undefined;
28
+ /** Open the calendar on mount. */
29
+ defaultOpen?: boolean | undefined;
30
+ /**
31
+ * The month dropdown's name, for an app in another language.
32
+ * @default Month
33
+ */
34
+ monthLabel?: string | undefined;
35
+ /**
36
+ * The year dropdown's name, for an app in another language.
37
+ * @default Year
38
+ */
39
+ yearLabel?: string | undefined;
40
+ };
41
+ /**
42
+ * A from and to date in one field: DD/MM/YYYY "to" DD/MM/YYYY and a calendar button that opens one
43
+ * Monday-first month, where two presses pick the range. `presets` adds the app's ready-made ranges
44
+ * above the month. The range is reported only when both sides are complete, real dates within
45
+ * min/max and the start is on or before the end; otherwise `null`.
46
+ */
47
+ export declare function DateRangePicker({ label, hint, error, disabled, required, monthLabel, yearLabel, value, defaultValue, onChange, startName, endName, presets, defaultOpen, size, ...rest }: DateRangePickerProps): ReactElement;
@@ -0,0 +1,44 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useContext } from "react";
3
+ import { Button, DateFieldContext, DateInput, DateRangePicker as AriaDateRangePicker, Group, I18nProvider, Label, } from "react-aria-components";
4
+ import { cx } from "./cx.js";
5
+ import { RangeCalendarPopover, calendarIcon } from "./DateCalendar.js";
6
+ import { FieldSegment, LOCALE, fieldFlags, forcedInvalid, frameClass, iconButtonLook, labelClass, Notes, } from "./DateField.js";
7
+ import { PICKER_SIZE, useDialogContainer, usePickerFrame } from "./DateFieldCalendar.js";
8
+ import { definedProps } from "./props.js";
9
+ import { ShownInput, useShownRange } from "./shownDate.js";
10
+ /**
11
+ * One side's segments, named for a screen reader and read-only while focus leaves it with an
12
+ * impossible day (see `useShownDate`). React Aria hands each side its field props through the
13
+ * `start` and `end` slots; only this side's slot is changed.
14
+ */
15
+ function SideInput({ slot, name, side, onRead, }) {
16
+ const field = useContext(DateFieldContext);
17
+ const slots = field && "slots" in field ? field.slots : undefined;
18
+ const own = slots?.[slot] ?? {};
19
+ return (_jsx("div", { role: "group", "aria-label": name, className: "flex items-center", onBlurCapture: side.onBlurCapture, children: _jsx(DateFieldContext.Provider, { value: {
20
+ slots: {
21
+ ...slots,
22
+ [slot]: { ...own, isReadOnly: side.leaving, onBlur: side.onLeft },
23
+ },
24
+ }, children: _jsx(DateInput, { slot: slot, className: "flex", children: (segment) => (_jsx(FieldSegment, { segment: segment, ...(segment.type === "day" ? { onRead } : {}) })) }) }) }));
25
+ }
26
+ /**
27
+ * A from and to date in one field: DD/MM/YYYY "to" DD/MM/YYYY and a calendar button that opens one
28
+ * Monday-first month, where two presses pick the range. `presets` adds the app's ready-made ranges
29
+ * above the month. The range is reported only when both sides are complete, real dates within
30
+ * min/max and the start is on or before the end; otherwise `null`.
31
+ */
32
+ export function DateRangePicker({ label, hint, error, disabled, required, monthLabel = "Month", yearLabel = "Year", value, defaultValue, onChange, startName, endName, presets, defaultOpen, size = "md", ...rest }) {
33
+ const frame = usePickerFrame(size);
34
+ const shown = useShownRange({
35
+ value,
36
+ defaultValue,
37
+ onChange,
38
+ minValue: rest.minValue,
39
+ maxValue: rest.maxValue,
40
+ isRequired: required,
41
+ });
42
+ const { container, findDialog } = useDialogContainer();
43
+ return (_jsx(I18nProvider, { locale: LOCALE, children: _jsx(AriaDateRangePicker, { ...definedProps(rest), ...fieldFlags(disabled, required), ...(defaultOpen === undefined ? {} : { defaultOpen }), ref: findDialog, value: shown.inner, onChange: shown.setInner, validate: shown.validate, ...forcedInvalid({ impossible: shown.problem, error }), granularity: "day", shouldForceLeadingZeros: true, className: "flex flex-col gap-1.5", children: ({ isInvalid }) => (_jsxs(_Fragment, { children: [label ? _jsx(Label, { className: labelClass, children: label }) : null, _jsxs(Group, { className: (state) => cx(frameClass(state), frame), children: [_jsx(SideInput, { slot: "start", name: "Start date", side: shown.start, onRead: shown.onReadStart }), _jsx("span", { "aria-hidden": "true", className: "px-1 text-slate-500", children: "to" }), _jsx(SideInput, { slot: "end", name: "End date", side: shown.end, onRead: shown.onReadEnd }), _jsx(Button, { className: cx(iconButtonLook, PICKER_SIZE[size].button, "ml-auto"), children: calendarIcon })] }), _jsx(ShownInput, { name: startName, shown: shown.startShown, isDisabled: disabled }), _jsx(ShownInput, { name: endName, shown: shown.endShown, isDisabled: disabled }), _jsx(Notes, { hint: hint, error: error, impossible: shown.problem, isInvalid: isInvalid }), _jsx(RangeCalendarPopover, { container: container, presets: presets, labels: { monthLabel, yearLabel } })] })) }) }));
44
+ }
@@ -0,0 +1,56 @@
1
+ import { type FormEvent, type ReactElement, type ReactNode } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ import type { Size } from "./size.js";
4
+ export type DialogProps = {
5
+ /** The dialog's accessible name, shown as its heading. */
6
+ title: ReactNode;
7
+ /** A muted line under the title. */
8
+ description?: ReactNode;
9
+ children?: ReactNode;
10
+ /** Actions under the body, right-aligned: Cancel (`variant="ghost"`), then the one main action. */
11
+ footer?: ReactNode;
12
+ /**
13
+ * Makes the dialog a form: one `<form noValidate>` holds the body, the `error` and the footer,
14
+ * so a `Button type="submit"` in the footer or Enter in a field submits it, with no `form`
15
+ * attribute or id. The default is prevented before this runs, and a rejection is yours to
16
+ * catch and show as `error`. Put no `<form method="dialog">` in the footer of a form dialog:
17
+ * it would nest a form.
18
+ */
19
+ onSubmit?: ((event: FormEvent<HTMLFormElement>) => void | Promise<unknown>) | undefined;
20
+ /**
21
+ * What went wrong with the whole submit (the server refused it, no connection): a danger
22
+ * `Callout`, announced as an alert, between the body and the footer, so it stays beside the
23
+ * buttons however tall the body is. An error about one field is that `Field`'s `error`.
24
+ */
25
+ error?: ReactNode;
26
+ /**
27
+ * The panel's width: `sm` (320px) is a list, `md` (440px) holds a form, `lg` (640px) a wider
28
+ * form or a table. `full` fills the whole screen, for media or a player: the body takes the
29
+ * height between the header and the footer and scrolls if it is taller. It has no backdrop to
30
+ * click, so give it a close action in the `footer` (a `<form method="dialog">` button).
31
+ *
32
+ * A single photo or video is a `Lightbox`.
33
+ * @default md
34
+ */
35
+ width?: Size | "full";
36
+ /** Called when the dialog closes: Esc, a click on the backdrop, or a `<form method="dialog">` submit. */
37
+ onClose: () => void;
38
+ } & Passthrough;
39
+ /**
40
+ * What a modal resets, since the browser's `<dialog>` renders where it is written: it is back on the
41
+ * app scale, out of any card, and its controls are `md` whatever row, card or table opened it.
42
+ */
43
+ export declare function ModalScope({ children }: {
44
+ children: ReactNode;
45
+ }): ReactElement;
46
+ /** What a dialog or drawer sets for its body: a `Stack` in it is `xs` apart, and a heading in it is one below the title. */
47
+ export declare function BodyContext({ children }: {
48
+ children: ReactNode;
49
+ }): ReactElement;
50
+ /**
51
+ * A modal on the browser's own `<dialog>`: it is opened with `showModal()` on mount, so render it
52
+ * only while it is open. The page behind goes inert, Esc closes it and focus stays inside; a click
53
+ * on the backdrop (the `<dialog>` element itself, not its contents) closes it too. A windowed dialog is
54
+ * never taller than the screen: a tall body scrolls and the title and footer stay on screen.
55
+ */
56
+ export declare function Dialog({ title, description, children, footer, onSubmit, error, width, onClose, ...rest }: DialogProps): ReactElement;
package/dist/Dialog.js ADDED
@@ -0,0 +1,94 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId, useLayoutEffect, useRef, } from "react";
3
+ import { Callout } from "./Callout.js";
4
+ import { InCard } from "./cardContext.js";
5
+ import { cx } from "./cx.js";
6
+ import { DensityProvider } from "./density.js";
7
+ import { HeadingLevelProvider } from "./headingLevel.js";
8
+ import { useBackdropClose, useModal } from "./modal.js";
9
+ import { scrollStopProps, TABBABLE, useScrollStop } from "./scrollStop.js";
10
+ import { GapProvider } from "./stackGap.js";
11
+ import { AppScale, HeaderText, SectionHeading } from "./typography.js";
12
+ /** Shared by every size: the surface, its colours and the fade (and the scrim's) in and out. */
13
+ const BASE = "bg-white p-0 text-slate-900 whitespace-normal opacity-0 transition-[opacity,translate,overlay,display] transition-discrete duration-200 open:opacity-100 starting:open:opacity-0 backdrop:bg-slate-900/35 backdrop:opacity-0 backdrop:transition-[opacity,overlay,display] backdrop:transition-discrete backdrop:duration-200 open:backdrop:opacity-100 starting:open:backdrop:opacity-0 motion-reduce:transition-none motion-reduce:backdrop:transition-none";
14
+ /** A floating panel under the top edge: it also slides down 8px as it fades in. */
15
+ const WINDOW = "mx-auto mt-28 max-w-[calc(100vw-2rem)] overflow-visible rounded-2xl border border-slate-200 shadow-2xl -translate-y-2 open:translate-y-0 starting:open:-translate-y-2";
16
+ const WIDTH = { sm: "w-80", md: "w-110", lg: "w-160" };
17
+ /**
18
+ * A windowed dialog is as tall as its content up to the room under its top margin (7rem) with 1rem
19
+ * to spare and its 1px borders, and no taller: the body scrolls inside that cap, so the title and
20
+ * the footer stay on screen. The cap sits on the panel inside the `<dialog>`, which stays
21
+ * `overflow-visible` so a `DateField` calendar portalled into it is not clipped.
22
+ */
23
+ const CAP = "max-h-[calc(100dvh-8rem-2px)]";
24
+ /**
25
+ * The scrolling body clips what paints outside it, a field's focus ring included. Its padding keeps
26
+ * the ring whole (4px: a 2px outline at a 2px offset), and the negative margins give that room back,
27
+ * so the body sits where an unpadded one would.
28
+ */
29
+ const SCROLL_BODY = "mt-3 -mb-1 -mx-1 min-h-0 flex-1 scroll-py-1 overflow-y-auto px-1 pt-1 pb-1";
30
+ /** The whole viewport, edge to edge: no margin, radius, border or shadow, and a column so the body can fill it. */
31
+ const FULL = "fixed inset-0 m-0 size-full max-h-none max-w-none flex-col overflow-hidden rounded-none border-0 open:flex";
32
+ /**
33
+ * The body's keyboard side. In a windowed dialog Chromium's `showModal()` focuses a scrolling box
34
+ * ahead of the field inside it, though the other engines pick the field: when the open took the
35
+ * body, the focus goes to the first thing in the dialog the keyboard can reach, where it lands in a
36
+ * dialog that does not scroll. And a body that overflows and holds nothing the keyboard can reach
37
+ * takes a tab stop, so the arrow keys can scroll it. Every other body has none: `showModal()`
38
+ * focuses the first focusable element, and a tab stop on the body would take that from the field
39
+ * inside it. `size="full"` is left as it was.
40
+ */
41
+ function useScrollingBody(dialog, titleId, full) {
42
+ const { element: body, attach, stop } = useScrollStop();
43
+ const tabStop = stop && !full;
44
+ // After `useModal`'s own layout effect (the caller's earlier hook), so the dialog is open.
45
+ useLayoutEffect(() => {
46
+ if (!full && body && document.activeElement === body) {
47
+ dialog.current?.querySelector(TABBABLE)?.focus();
48
+ }
49
+ }, [body, dialog, full]);
50
+ const { props, ring } = scrollStopProps(tabStop, { labelledBy: titleId });
51
+ return {
52
+ attach,
53
+ props,
54
+ className: cx(full ? "mt-4 min-h-0 flex-1 overflow-auto" : SCROLL_BODY, ring),
55
+ };
56
+ }
57
+ /**
58
+ * What a modal resets, since the browser's `<dialog>` renders where it is written: it is back on the
59
+ * app scale, out of any card, and its controls are `md` whatever row, card or table opened it.
60
+ */
61
+ export function ModalScope({ children }) {
62
+ return (_jsx(AppScale, { children: _jsx(DensityProvider, { size: null, children: _jsx(InCard, { value: false, children: children }) }) }));
63
+ }
64
+ /** What a dialog or drawer sets for its body: a `Stack` in it is `xs` apart, and a heading in it is one below the title. */
65
+ export function BodyContext({ children }) {
66
+ return (_jsx(GapProvider, { gap: "xs", children: _jsx(HeadingLevelProvider, { level: 2, children: children }) }));
67
+ }
68
+ /**
69
+ * A modal on the browser's own `<dialog>`: it is opened with `showModal()` on mount, so render it
70
+ * only while it is open. The page behind goes inert, Esc closes it and focus stays inside; a click
71
+ * on the backdrop (the `<dialog>` element itself, not its contents) closes it too. A windowed dialog is
72
+ * never taller than the screen: a tall body scrolls and the title and footer stay on screen.
73
+ */
74
+ export function Dialog({ title, description, children, footer, onSubmit, error, width = "md", onClose, ...rest }) {
75
+ const dialog = useRef(null);
76
+ const titleId = useId();
77
+ const closed = useModal(dialog, onClose);
78
+ const backdrop = useBackdropClose(dialog);
79
+ const full = width === "full";
80
+ const { attach, props: bodyProps, className: bodyClass, } = useScrollingBody(dialog, titleId, full);
81
+ return (_jsx(ModalScope, { children: _jsx("dialog", { ...rest, ref: dialog, "aria-labelledby": titleId, onClose: closed, ...backdrop, className: cx(BASE, width === "full" ? FULL : `${WINDOW} ${WIDTH[width]}`), children: _jsxs("div", { className: cx("flex flex-col p-5.5", full ? "min-h-0 flex-1" : CAP), children: [_jsx(SectionHeading, { id: titleId, children: title }), description && (_jsx("div", { className: "mt-1", children: _jsx(HeaderText, { children: description }) })), _jsxs(FormColumn, { onSubmit: onSubmit, children: [children && (_jsx("div", { ref: attach, ...bodyProps, className: bodyClass, children: _jsx(BodyContext, { children: children }) })), error && (_jsx("div", { className: "mt-5 shrink-0", children: _jsx(Callout, { tone: "danger", children: error }) })), footer && _jsx("div", { className: "mt-5 flex shrink-0 justify-end gap-2", children: footer })] })] }) }) }));
82
+ }
83
+ /**
84
+ * With `onSubmit`, the body, error and footer in one `<form>` that keeps the panel's column, so the
85
+ * body still scrolls under the cap; without it they sit in the panel as they are.
86
+ */
87
+ function FormColumn({ onSubmit, children, }) {
88
+ if (!onSubmit)
89
+ return _jsx(_Fragment, { children: children });
90
+ return (_jsx("form", { noValidate: true, className: "flex min-h-0 flex-1 flex-col", onSubmit: (event) => {
91
+ event.preventDefault();
92
+ void onSubmit(event);
93
+ }, children: children }));
94
+ }
@@ -0,0 +1,29 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ /**
4
+ * A summary line with a chevron over a body that opens and closes under it. The summary is a
5
+ * button with `aria-expanded`, and Enter and Space toggle it; the body is hidden while closed.
6
+ * It starts closed and keeps its own state; `defaultOpen` starts it open. To drive it from the
7
+ * app, pass `open` with `onOpenChange`.
8
+ *
9
+ * `bordered` draws it as a panel: a bordered box with the summary as a roomy row across the top
10
+ * (the hover fill of a `ListRow`) and the body padded under a hairline, for a section that opens in
11
+ * place in a page of cards. Plain, it is a line of text with the body indented under it.
12
+ */
13
+ export declare function Disclosure({ summary, defaultOpen, open, onOpenChange, bordered, children, ...rest }: {
14
+ /** The always-visible line: the button that toggles the body. */
15
+ summary: ReactNode;
16
+ /** Starts with the body showing. */
17
+ defaultOpen?: boolean | undefined;
18
+ /** Whether the body shows, for an app that holds the state; pass `onOpenChange` with it. */
19
+ open?: boolean | undefined;
20
+ /** Called with the new state when the summary is pressed. */
21
+ onOpenChange?: ((open: boolean) => void) | undefined;
22
+ /**
23
+ * Draws it as a bordered panel: the summary a full-width row, the body padded under a hairline.
24
+ * @default false
25
+ */
26
+ bordered?: boolean | undefined;
27
+ /** The body, shown while open. */
28
+ children: ReactNode;
29
+ } & Passthrough): ReactElement;
@@ -0,0 +1,23 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button, Disclosure as AriaDisclosure, DisclosurePanel } from "react-aria-components";
3
+ import { Chevron } from "./Chevron.js";
4
+ import { cx, focusRing } from "./cx.js";
5
+ /** The panel form's box: the Card's border, fill and shadow, clipped to its radius. */
6
+ const FRAME = "overflow-hidden rounded-xl border border-slate-200/70 bg-white shadow-sm";
7
+ /** The body's own box, not the panel's: a collapsed panel still draws its border and padding. */
8
+ const PANEL = "border-t border-slate-200/70 p-4";
9
+ /**
10
+ * A summary line with a chevron over a body that opens and closes under it. The summary is a
11
+ * button with `aria-expanded`, and Enter and Space toggle it; the body is hidden while closed.
12
+ * It starts closed and keeps its own state; `defaultOpen` starts it open. To drive it from the
13
+ * app, pass `open` with `onOpenChange`.
14
+ *
15
+ * `bordered` draws it as a panel: a bordered box with the summary as a roomy row across the top
16
+ * (the hover fill of a `ListRow`) and the body padded under a hairline, for a section that opens in
17
+ * place in a page of cards. Plain, it is a line of text with the body indented under it.
18
+ */
19
+ export function Disclosure({ summary, defaultOpen = false, open, onOpenChange, bordered = false, children, ...rest }) {
20
+ return (_jsx("div", { ...rest, className: bordered ? FRAME : undefined, children: _jsx(AriaDisclosure, { defaultExpanded: defaultOpen, ...(open === undefined ? {} : { isExpanded: open }), ...(onOpenChange ? { onExpandedChange: onOpenChange } : {}), children: ({ isExpanded }) => (_jsxs(_Fragment, { children: [_jsxs(Button, { slot: "trigger", className: cx("flex w-full cursor-pointer items-center gap-2 text-left text-sm font-medium text-slate-900", focusRing, bordered
21
+ ? "px-4 py-3 hover:bg-slate-50 focus-visible:-outline-offset-2"
22
+ : "rounded-md py-1.5 hover:text-violet-700"), children: [_jsx(Chevron, { open: isExpanded }), summary] }), _jsx(DisclosurePanel, { className: cx("text-sm text-slate-700", !bordered && "pt-1 pb-2 pl-6"), children: bordered ? _jsx("div", { className: PANEL, children: children }) : children })] })) }) }));
23
+ }
@@ -0,0 +1,4 @@
1
+ import type { ReactElement } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ /** A hairline rule in the theme's line colour: between a heading and its content, or above a footer. Space around it is the layout's. */
4
+ export declare function Divider(props: Passthrough): ReactElement;
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /** A hairline rule in the theme's line colour: between a heading and its content, or above a footer. Space around it is the layout's. */
3
+ export function Divider(props) {
4
+ return _jsx("hr", { ...props, className: "border-t border-slate-200/70" });
5
+ }
@@ -0,0 +1,69 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ import type { SwitchLink } from "./switcher.js";
4
+ /** One group of the docs nav: a title over its links (`Tab`s with an `href`). A group with no title is the nav's top. */
5
+ export type DocsNavGroup = {
6
+ title?: string | undefined;
7
+ items: SwitchLink[];
8
+ };
9
+ /** One entry of "On this page": a heading's id, its text and its level. */
10
+ export type DocsHeading = {
11
+ id: string;
12
+ label: string;
13
+ level: 2 | 3;
14
+ };
15
+ /** The page before or after this one in reading order. */
16
+ export type DocsNeighbour = {
17
+ label: string;
18
+ href: string;
19
+ };
20
+ type DocsLayoutProps = {
21
+ /** The docs nav, in reading order: each group's title over a vertical pill list of its pages. */
22
+ nav: DocsNavGroup[];
23
+ /** Names the nav's landmark, and the disclosure it folds behind below `md` ("Docs", "All components"). */
24
+ navLabel: string;
25
+ /** The page's title, its `h1`. */
26
+ title: ReactNode;
27
+ /** The line under the title (a `Lead`). */
28
+ description?: ReactNode;
29
+ /** A `Breadcrumbs` above the title. */
30
+ breadcrumbs?: ReactNode;
31
+ /** The page's own headings, in order. With fewer than two there is no "On this page" list. */
32
+ contents?: DocsHeading[] | undefined;
33
+ /** The id of the heading being read: its entry is marked (`aria-current="location"`). A value the page passes, never tracked inside. */
34
+ current?: string | undefined;
35
+ /**
36
+ * The contents list's name and its label.
37
+ * @default On this page
38
+ */
39
+ contentsLabel?: string | undefined;
40
+ /** The page before this one in reading order. */
41
+ previous?: DocsNeighbour | undefined;
42
+ /** The page after this one in reading order. */
43
+ next?: DocsNeighbour | undefined;
44
+ /**
45
+ * The word over the previous page's label.
46
+ * @default Previous
47
+ */
48
+ previousLabel?: string | undefined;
49
+ /**
50
+ * The word over the next page's label.
51
+ * @default Next
52
+ */
53
+ nextLabel?: string | undefined;
54
+ /** The article. Wrap long text in a `Prose`. */
55
+ children: ReactNode;
56
+ } & Passthrough;
57
+ /**
58
+ * A docs page: a `SidebarLayout` whose rail is the docs `nav` (each group's title over its links,
59
+ * folded behind a disclosure named `navLabel` below `md`), and a canvas of the page's title, an
60
+ * "On this page" list of its `contents`, the article and the previous and next links.
61
+ *
62
+ * The contents list is rendered once: from `xl` a 12rem column right of the article that sticks
63
+ * under the header, below `xl` a closed disclosure above the article. `current` marks the heading
64
+ * being read; it is a value the page passes (a site that follows the reader computes it), with no
65
+ * scroll spy inside. The previous and next links are links, not cards, so they add no heading to
66
+ * the page's outline.
67
+ */
68
+ export declare function DocsLayout({ nav, navLabel, title, description, breadcrumbs, contents, current, contentsLabel, previous, next, previousLabel, nextLabel, children, ...rest }: DocsLayoutProps): ReactElement;
69
+ export {};