@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
package/dist/Icon.js ADDED
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ import { iconGlyph } from "./icons.js";
4
+ import { sizeClass } from "./size.js";
5
+ import { textToneClass } from "./typography.js";
6
+ const BOX = {
7
+ sm: "size-3.5",
8
+ md: "size-4",
9
+ lg: "size-5",
10
+ feature: "size-8",
11
+ };
12
+ /** `BOX` from the `md` breakpoint up, for a responsive size (`sm`, `md` and `lg` only). */
13
+ const BOX_MD = { sm: "md:size-3.5", md: "md:size-4", lg: "md:size-5" };
14
+ /** The box table and its `md:` twin, for the data test. */
15
+ export const iconSizeTables = { box: BOX, boxMd: BOX_MD };
16
+ /**
17
+ * One inline icon, sized to a fixed box (sm 14px, md 16px, lg 20px, `feature` 32px) and drawn in
18
+ * `currentColor`, so it takes the text colour around it unless a `tone` says otherwise. `name`
19
+ * picks one of the library's own icons, all drawn on one grid with one stroke: feature ideas
20
+ * (`diff`, `baseline`, `review`, `ci`, `self-host`, `privacy`, `capture`, `branch`, `theme`,
21
+ * `speed`, `search`) and UI glyphs (`chevron-right`, `chevron-down`, `close`, `external-link`,
22
+ * `settings`, `bell`, `check`, `plus`, `more`) and the ideas the docs sections stand for (`grid`, `window`,
23
+ * `type`, `card`, `pointer`, `field`, `table`, `compass`, `page`, `briefcase`);
24
+ * without a name, a bare `<svg>` child fills the box. It is decorative (`aria-hidden`) by
25
+ * default; a `label` makes it an image with that name, for an icon that carries meaning no text
26
+ * beside it says.
27
+ */
28
+ export function Icon({ size = "md", tone, label, name, children, ...rest }) {
29
+ return (_jsx("span", { ...rest, ...(label ? { role: "img", "aria-label": label } : { "aria-hidden": true }), className: cx("inline-flex shrink-0 [&>svg]:size-full", sizeClass(BOX, BOX_MD, size), textToneClass(tone)), children: name === undefined ? children : iconGlyph(name) }));
30
+ }
@@ -0,0 +1,72 @@
1
+ import type { ComponentPropsWithoutRef, ReactElement } from "react";
2
+ import type { IconName } from "./icons.js";
3
+ import type { Unstyled } from "./props.js";
4
+ import { type ResponsiveSize, type Size } from "./size.js";
5
+ import type { Tone } from "./tone.js";
6
+ /** An IconButton's look: `outline` with a border, or `ghost` with none until hover. */
7
+ export type IconButtonVariant = "outline" | "ghost";
8
+ /** An IconButton's tones: `neutral` (the default) and `danger`. */
9
+ export type IconButtonTone = Extract<Tone, "neutral" | "danger">;
10
+ /** The size table and its `md:` twin, for the data test. */
11
+ export declare const iconButtonSizeTables: {
12
+ size: Record<Size, string>;
13
+ sizeMd: Record<Size, string>;
14
+ };
15
+ type IconButtonProps = {
16
+ /** The button's accessible name and its tooltip, shown on hover and on keyboard focus. */
17
+ label: string;
18
+ /**
19
+ * `outline` has a border; `ghost` has none, until the hover fill.
20
+ * @default outline
21
+ */
22
+ variant?: IconButtonVariant | undefined;
23
+ /**
24
+ * `danger` is red, for delete and clear.
25
+ * @default neutral
26
+ */
27
+ tone?: IconButtonTone | undefined;
28
+ /**
29
+ * The button's height, matching a `Button` or `Input` of the same size. Left out, it takes the
30
+ * size of the `Card`, `ListRow` or `Table` it sits in, else `md`. `{ base: "md", md: "lg" }`
31
+ * changes size at the `md` breakpoint (48rem), in CSS.
32
+ *
33
+ * Give it the same value as a responsive `Button` beside it.
34
+ * @default md
35
+ */
36
+ size?: Size | ResponsiveSize | undefined;
37
+ /** The one icon it holds, from the `Icon` set, at the button's size. */
38
+ icon: IconName;
39
+ /** A red count on the top corner at the end edge, for unread alerts. Not shown at 0; the name carries it for a screen reader, "Alerts, 3". */
40
+ count?: number | undefined;
41
+ };
42
+ type IconButtonAsButton = IconButtonProps & Unstyled<Omit<ComponentPropsWithoutRef<"button">, "children">> & {
43
+ /**
44
+ * Why the button cannot be pressed: it dims and is blocked (`aria-disabled`; a click, Enter and
45
+ * Space do nothing) while it stays in the tab order, and the reason is its tooltip on hover,
46
+ * keyboard focus and a tap, read out as its description. The name stays `label`.
47
+ */
48
+ disabledReason?: string | undefined;
49
+ href?: undefined;
50
+ external?: undefined;
51
+ };
52
+ type IconButtonAsLink = IconButtonProps & {
53
+ disabledReason?: undefined;
54
+ /** Opens in a new tab: adds `target="_blank"` and `rel="noreferrer"`. */
55
+ external?: boolean | undefined;
56
+ /** Makes the button a link to this URL; an in-app path goes through the app's `LinkProvider`. */
57
+ href: string;
58
+ } & Unstyled<Omit<ComponentPropsWithoutRef<"a">, "href" | "children">>;
59
+ /** The classes for a variant, tone and size, each at its default when left out. Shared with `ColourSchemeToggle`, which draws its own `<button>`; not exported from `index.ts`. */
60
+ export declare function look({ variant, tone, size, }: Pick<IconButtonProps, "variant" | "tone" | "size">): string;
61
+ /**
62
+ * A square button holding one icon from the `Icon` set (`icon`). `label` is its accessible name
63
+ * and tooltip. `variant="ghost"` drops the border for a quiet action in a row or a toolbar; `size`
64
+ * matches the height of a `Button` of the same size (`sm` 26px, `md` 38px, `lg` 46px; a
65
+ * responsive `{ base, md }` changes at 48rem) and with no
66
+ * `size` it takes its container's; `tone="danger"` is red, for delete and clear; `count` pins a
67
+ * red count to the corner; `disabledReason` blocks it and shows why. Defaults to `type="button"`. `href` makes it a link instead (the app's
68
+ * router link through `LinkProvider` for an in-app path, else a plain `<a>`; `external` opens a
69
+ * new tab), with the same look.
70
+ */
71
+ export declare function IconButton(props: IconButtonAsButton | IconButtonAsLink): ReactElement;
72
+ export {};
@@ -0,0 +1,65 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Badge } from "./Badge.js";
3
+ import { cx, focusRing } from "./cx.js";
4
+ import { useResponsiveDensity } from "./density.js";
5
+ import { Icon } from "./Icon.js";
6
+ import { renderLink } from "./link.js";
7
+ import { blockedProps, hasReason } from "./blocked.js";
8
+ import { Tipped } from "./Tooltip.js";
9
+ import { sizeClass } from "./size.js";
10
+ const BASE = `relative inline-flex items-center justify-center rounded-lg border transition disabled:pointer-events-none disabled:opacity-50 aria-disabled:cursor-not-allowed aria-disabled:opacity-50 ${focusRing}`;
11
+ /** The same heights as a `Button` of the size: 26px, 38px and 46px. */
12
+ const SIZE = { sm: "size-6.5", md: "size-9.5", lg: "size-11.5" };
13
+ /** `SIZE` from the `md` breakpoint up, for a responsive size. */
14
+ const SIZE_MD = { sm: "md:size-6.5", md: "md:size-9.5", lg: "md:size-11.5" };
15
+ /** The size table and its `md:` twin, for the data test. */
16
+ export const iconButtonSizeTables = { size: SIZE, sizeMd: SIZE_MD };
17
+ const LOOK = {
18
+ neutral: {
19
+ outline: "border-slate-200 text-slate-500 hover:bg-slate-50",
20
+ ghost: "border-transparent text-slate-500 hover:bg-slate-100",
21
+ },
22
+ danger: {
23
+ outline: "border-red-200 text-red-700 hover:bg-red-50",
24
+ ghost: "border-transparent text-red-700 hover:bg-red-50",
25
+ },
26
+ };
27
+ /** The classes for a variant, tone and size, each at its default when left out. Shared with `ColourSchemeToggle`, which draws its own `<button>`; not exported from `index.ts`. */
28
+ export function look({ variant = "outline", tone = "neutral", size = "md", }) {
29
+ return cx(BASE, sizeClass(SIZE, SIZE_MD, size), LOOK[tone][variant]);
30
+ }
31
+ function isLink(props) {
32
+ return props.href !== undefined;
33
+ }
34
+ /**
35
+ * A square button holding one icon from the `Icon` set (`icon`). `label` is its accessible name
36
+ * and tooltip. `variant="ghost"` drops the border for a quiet action in a row or a toolbar; `size`
37
+ * matches the height of a `Button` of the same size (`sm` 26px, `md` 38px, `lg` 46px; a
38
+ * responsive `{ base, md }` changes at 48rem) and with no
39
+ * `size` it takes its container's; `tone="danger"` is red, for delete and clear; `count` pins a
40
+ * red count to the corner; `disabledReason` blocks it and shows why. Defaults to `type="button"`. `href` makes it a link instead (the app's
41
+ * router link through `LinkProvider` for an in-app path, else a plain `<a>`; `external` opens a
42
+ * new tab), with the same look.
43
+ */
44
+ export function IconButton(props) {
45
+ const drawn = useResponsiveDensity(props.size);
46
+ const inside = (count, icon) => (_jsxs(_Fragment, { children: [_jsx(Icon, { name: icon, size: drawn }), count ? _jsx(Badge, { count: count, corner: true, "aria-hidden": "true" }) : null] }));
47
+ if (isLink(props)) {
48
+ const { label, variant, tone, size: _size, count, icon, disabledReason: _r, ...link } = props;
49
+ return (_jsx(Tipped, { text: named(label, count), describes: false, own: link, children: (tip) => renderLink({
50
+ ...link,
51
+ ...tip,
52
+ external: link.external ?? false,
53
+ "aria-label": named(label, count),
54
+ className: look({ variant, tone, size: drawn }),
55
+ children: inside(count, icon),
56
+ }) }));
57
+ }
58
+ const { label, variant, tone, size: _size, count, icon, disabledReason, ...rest } = props;
59
+ const blocked = hasReason(disabledReason);
60
+ return (_jsx(Tipped, { text: blocked ? disabledReason : named(label, count), describes: blocked, tap: blocked, own: rest, children: (tip) => (_jsx("button", { type: "button", ...rest, ...tip, ...(blocked ? blockedProps() : {}), "aria-label": named(label, count), className: look({ variant, tone, size: drawn }), children: inside(count, icon) })) }));
61
+ }
62
+ /** The accessible name with its count: `Alerts, 3`. */
63
+ function named(label, count) {
64
+ return count ? `${label}, ${count}` : label;
65
+ }
@@ -0,0 +1,58 @@
1
+ import type { ReactElement } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ import { type LoadingProps } from "./skeleton.js";
4
+ import type { Size } from "./size.js";
5
+ /**
6
+ * The shapes an image is cropped or letterboxed to, or `natural`: no shape of its own, so the
7
+ * picture keeps its own proportions.
8
+ */
9
+ export type ImageAspect = "square" | "4:3" | "3:2" | "16:9" | "3:4" | "9:16" | "natural";
10
+ /** How wide an image is: `full` fills its parent; the others are 96, 160 or 256px, capped at the parent's width. */
11
+ export type ImageWidth = Size | "full";
12
+ /**
13
+ * `full` is the parent's width; a size is a real width that a narrower parent still caps. It is
14
+ * a width and not a `max-width`, so it holds inside a shrink-to-fit parent, where a placeholder
15
+ * has no intrinsic size of its own to give it one.
16
+ */
17
+ export declare const IMAGE_WIDTH: Record<ImageWidth, string>;
18
+ export type ImageProps = {
19
+ /**
20
+ * The picture, a local path or a data URL. It is never loaded for you: this is the app's own
21
+ * image. Left out, or if it fails to load, the picture is replaced by a placeholder.
22
+ */
23
+ src?: string | undefined;
24
+ /** What the picture shows. An empty string marks it as decoration, hidden from a screen reader. */
25
+ alt: string;
26
+ /**
27
+ * The shape it is cropped to: `square`, `4:3`, `3:2`, `16:9`, or the portrait `3:4` and `9:16`.
28
+ * `natural` keeps the picture's own proportions instead, so nothing is cropped or letterboxed;
29
+ * the space is not reserved before it loads.
30
+ * @default 4:3
31
+ */
32
+ aspect?: ImageAspect | undefined;
33
+ /**
34
+ * `cover` fills the shape and crops what overflows; `contain` shows the whole picture, with the
35
+ * rest of the shape left empty (a QR code, a logo).
36
+ * @default cover
37
+ */
38
+ fit?: "cover" | "contain" | undefined;
39
+ /**
40
+ * `sm` 96px, `md` 160px and `lg` 256px set the width, capped at the parent's; `full` fills the parent.
41
+ * @default full
42
+ */
43
+ width?: ImageWidth | undefined;
44
+ /**
45
+ * Sets the picture on a white mat with padding, always white, in every theme: a QR code is
46
+ * scanned off a dark page. It shows the whole picture, as `fit="contain"`, whatever `fit` says.
47
+ */
48
+ framed?: boolean | undefined;
49
+ } & LoadingProps & Passthrough;
50
+ /**
51
+ * A picture in a fixed shape: `aspect` reserves the space before it loads, so the page does not
52
+ * jump, and `fit` crops it to the shape or shows all of it. The corners are rounded and the frame
53
+ * has a hairline. If the picture is missing or fails to load, a same-sized placeholder with a
54
+ * picture mark stands in, still named by `alt`. `framed` mats a code or a logo in white. A user's photo is an `Avatar`; a clickable
55
+ * thumbnail with a label is a `MediaTile`. While `loading` with no `src` yet it is a bone of the same
56
+ * shape, not the placeholder, which means there is no picture.
57
+ */
58
+ export declare function Image({ src, alt, aspect, fit, width, framed, loading, loadingLabel, ...rest }: ImageProps): ReactElement;
package/dist/Image.js ADDED
@@ -0,0 +1,69 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ import { Icon } from "./Icon.js";
4
+ import { useLoading, WaitingBone } from "./skeleton.js";
5
+ import { useImageFailed } from "./useImageFailed.js";
6
+ const ASPECT = {
7
+ square: "aspect-square",
8
+ "4:3": "aspect-[4/3]",
9
+ "3:2": "aspect-[3/2]",
10
+ "16:9": "aspect-video",
11
+ "3:4": "aspect-[3/4]",
12
+ "9:16": "aspect-[9/16]",
13
+ natural: "h-auto",
14
+ };
15
+ /** What stands in for a `natural` picture that has none (yet): it has no proportions to keep. */
16
+ const PLACEHOLDER_ASPECT = "aspect-[4/3]";
17
+ /**
18
+ * `full` is the parent's width; a size is a real width that a narrower parent still caps. It is
19
+ * a width and not a `max-width`, so it holds inside a shrink-to-fit parent, where a placeholder
20
+ * has no intrinsic size of its own to give it one.
21
+ */
22
+ export const IMAGE_WIDTH = {
23
+ sm: "w-24 max-w-full",
24
+ md: "w-40 max-w-full",
25
+ lg: "w-64 max-w-full",
26
+ full: "w-full",
27
+ };
28
+ /** Every image sits on the inset surface with a hairline, so a letterbox or a pale picture has an edge. */
29
+ const FRAME = "block rounded-lg border border-slate-200";
30
+ const INSET = "bg-slate-100";
31
+ /**
32
+ * The white mat of `framed`. `bg-white/100` is the palette's media-matte role: a plain `bg-white` is
33
+ * the surface, which a dark theme darkens, and a scanner needs the code on white. Every theme keeps
34
+ * this one white, as it keeps the Lightbox scrim black.
35
+ */
36
+ const MATTE = "bg-white/100 p-3";
37
+ const PICTURE = "M1 5.25A2.25 2.25 0 0 1 3.25 3h13.5A2.25 2.25 0 0 1 19 5.25v9.5A2.25 2.25 0 0 1 16.75 17H3.25A2.25 2.25 0 0 1 1 14.75v-9.5Zm1.5 5.81v3.69c0 .414.336.75.75.75h13.5a.75.75 0 0 0 .75-.75v-2.69l-2.22-2.22a.75.75 0 0 0-1.06 0l-1.91 1.91.47.47a.75.75 0 1 1-1.06 1.06L6.53 8.09a.75.75 0 0 0-1.06 0l-2.97 2.97ZM12 7a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z";
38
+ /** The fill and the fit of a picture: `framed` is a white mat around all of it. */
39
+ function pictureLook(fit, framed) {
40
+ if (framed)
41
+ return cx(MATTE, "object-contain");
42
+ return cx(INSET, fit === "cover" ? "object-cover" : "object-contain");
43
+ }
44
+ /** The shape a picture's stand-in reserves: its aspect, or 4:3 for a `natural` one. */
45
+ const reservedAspect = (aspect) => aspect === "natural" ? PLACEHOLDER_ASPECT : ASPECT[aspect];
46
+ /** A picture not here yet: a bone of the shape and width it will take. */
47
+ function ImageBone({ own, label, aspect, width, alt, attrs, }) {
48
+ return (_jsx(WaitingBone, { own: own, label: label, shape: cx("block w-full rounded-lg", reservedAspect(aspect)), root: cx("block", IMAGE_WIDTH[width]), attrs: alt ? { ...attrs, role: "img", "aria-label": alt } : attrs }));
49
+ }
50
+ /**
51
+ * A picture in a fixed shape: `aspect` reserves the space before it loads, so the page does not
52
+ * jump, and `fit` crops it to the shape or shows all of it. The corners are rounded and the frame
53
+ * has a hairline. If the picture is missing or fails to load, a same-sized placeholder with a
54
+ * picture mark stands in, still named by `alt`. `framed` mats a code or a logo in white. A user's photo is an `Avatar`; a clickable
55
+ * thumbnail with a label is a `MediaTile`. While `loading` with no `src` yet it is a bone of the same
56
+ * shape, not the placeholder, which means there is no picture.
57
+ */
58
+ export function Image({ src, alt, aspect = "4:3", fit = "cover", width = "full", framed = false, loading, loadingLabel, ...rest }) {
59
+ const { ref, failed, markFailed } = useImageFailed(src);
60
+ const waiting = useLoading(loading).loading;
61
+ if (waiting && !src) {
62
+ return (_jsx(ImageBone, { own: loading, label: loadingLabel, aspect: aspect, width: width, alt: alt, attrs: rest }));
63
+ }
64
+ const box = cx(FRAME, IMAGE_WIDTH[width]);
65
+ if (src && !failed) {
66
+ return (_jsx("img", { ...rest, ref: ref, src: src, alt: alt, className: cx(box, ASPECT[aspect], pictureLook(fit, framed)), onError: markFailed }));
67
+ }
68
+ return (_jsx("span", { ...rest, ...(alt ? { role: "img", "aria-label": alt } : { "aria-hidden": true }), className: cx(box, reservedAspect(aspect), INSET, "grid place-items-center text-slate-400"), children: _jsx(Icon, { size: "lg", children: _jsx("svg", { viewBox: "0 0 20 20", fill: "currentColor", children: _jsx("path", { d: PICTURE }) }) }) }));
69
+ }
@@ -0,0 +1,22 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ /**
4
+ * A value that opens an editor in place, as a part inside a `TableCell` that holds more than the
5
+ * value (an edit trigger in a column cell with other content, say). It shows `children` as a button with a dotted underline; a click, Enter
6
+ * or Space swaps it for `renderEditor(close)` and moves the focus into the editor. The part keeps
7
+ * its own open state. The editor calls `close` when it has saved, and Esc closes it: both put the
8
+ * focus back on the value. A press outside it or Tab out of it closes it too and leaves the focus
9
+ * where it went, so the editor saves its value on its own change or submit, never on a close. Put
10
+ * the control in the part itself, not in a popover of its own, which counts as outside. It takes
11
+ * the alignment of the cell around it. It is a block that bleeds half a rem into the padding of
12
+ * the cell it sits in, so it belongs inside a `TableCell`; a cell that holds only the value is a
13
+ * `TableEditCell`. `data-*` and `aria-*` go on the button, and on the editor's group while open.
14
+ */
15
+ export declare function InlineEdit({ label, renderEditor, children, ...rest }: {
16
+ /** What the button does, for a screen reader, heard after the value: "Edit category". It also names the editor. */
17
+ label: string;
18
+ /** The control that edits the value, drawn while open. `close` shuts it and returns the focus to the value. */
19
+ renderEditor: (close: () => void) => ReactNode;
20
+ /** The value, shown while closed. */
21
+ children: ReactNode;
22
+ } & Omit<Passthrough, "aria-label" | "aria-labelledby">): ReactElement;
@@ -0,0 +1,60 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useRef, useState } from "react";
3
+ import { cx, focusRing } from "./cx.js";
4
+ /** What takes the focus when the editor opens, unless the editor already took it (`autoFocus`). */
5
+ const FOCUSABLE = "input, select, textarea, button, a[href]";
6
+ /** Whether `target` is a node outside `box`. */
7
+ function isOutside(box, target) {
8
+ return target instanceof Node && box !== null && !box.contains(target);
9
+ }
10
+ /** Closes the editor when a press lands outside `box`, for as long as `open`. */
11
+ function useDismissOnOutsidePress(box, open, dismiss) {
12
+ useEffect(() => {
13
+ if (!open)
14
+ return undefined;
15
+ const onPress = (event) => {
16
+ if (isOutside(box.current, event.target))
17
+ dismiss();
18
+ };
19
+ document.addEventListener("pointerdown", onPress);
20
+ return () => document.removeEventListener("pointerdown", onPress);
21
+ }, [box, open, dismiss]);
22
+ }
23
+ /**
24
+ * A value that opens an editor in place, as a part inside a `TableCell` that holds more than the
25
+ * value (an edit trigger in a column cell with other content, say). It shows `children` as a button with a dotted underline; a click, Enter
26
+ * or Space swaps it for `renderEditor(close)` and moves the focus into the editor. The part keeps
27
+ * its own open state. The editor calls `close` when it has saved, and Esc closes it: both put the
28
+ * focus back on the value. A press outside it or Tab out of it closes it too and leaves the focus
29
+ * where it went, so the editor saves its value on its own change or submit, never on a close. Put
30
+ * the control in the part itself, not in a popover of its own, which counts as outside. It takes
31
+ * the alignment of the cell around it. It is a block that bleeds half a rem into the padding of
32
+ * the cell it sits in, so it belongs inside a `TableCell`; a cell that holds only the value is a
33
+ * `TableEditCell`. `data-*` and `aria-*` go on the button, and on the editor's group while open.
34
+ */
35
+ export function InlineEdit({ label, renderEditor, children, ...rest }) {
36
+ const [phase, setPhase] = useState("closed");
37
+ const open = phase === "open";
38
+ const box = useRef(null);
39
+ const trigger = useRef(null);
40
+ const dismiss = useCallback(() => setPhase("closed"), []);
41
+ const close = () => setPhase("returning");
42
+ useDismissOnOutsidePress(box, open, dismiss);
43
+ useEffect(() => {
44
+ if (phase === "returning")
45
+ trigger.current?.focus();
46
+ if (phase === "open" && !box.current?.contains(document.activeElement))
47
+ box.current?.querySelector(FOCUSABLE)?.focus();
48
+ }, [phase]);
49
+ const onKeyDown = (event) => {
50
+ if (event.key !== "Escape")
51
+ return;
52
+ event.preventDefault();
53
+ event.stopPropagation();
54
+ close();
55
+ };
56
+ return open ? (_jsx("div", { ...rest, ref: box, role: "group", "aria-label": label, className: "-mx-2 -my-1", onKeyDown: onKeyDown, onBlur: (event) => {
57
+ if (isOutside(event.currentTarget, event.relatedTarget))
58
+ dismiss();
59
+ }, children: renderEditor(close) })) : (_jsxs("button", { ...rest, ref: trigger, type: "button", onClick: () => setPhase("open"), className: cx("-mx-2 -my-1 block w-[calc(100%+1rem)] cursor-pointer rounded-md px-2 py-1 [text-align:inherit] underline decoration-dotted underline-offset-4 transition hover:bg-slate-100", focusRing), children: [children, _jsxs("span", { className: "sr-only", children: [" ", label] })] }));
60
+ }
@@ -0,0 +1,40 @@
1
+ import type { ComponentPropsWithoutRef, ReactElement, Ref } from "react";
2
+ import { type ControlProps } from "./control.js";
3
+ import type { IconName } from "./icons.js";
4
+ import type { Unstyled } from "./props.js";
5
+ /**
6
+ * A text input. `icon` names a leading icon inside the field (`icon="search"`). `prefix` puts
7
+ * short text inside the border before the value, such as a currency symbol; it is for a plain
8
+ * field, not with an `icon` or `type="search"`. `numeric` is a field for a figure: an amount
9
+ * (`<Input prefix="R" numeric />`) or a count (`numeric inputMode="numeric"`). It right-aligns the
10
+ * value in tabular figures and brings up the phone's number keypad (`inputMode="decimal"` unless
11
+ * you pass your own), and stays a text field, so "1 250" is kept as typed; never use
12
+ * `type="number"` for a figure a person types. `type="search"` drops the browser's own search look and shows a clear button at the
13
+ * trailing edge while the field has a value, named by `clearLabel`. The `ref` reaches the `<input>`.
14
+ */
15
+ export declare function Input({ icon, prefix, size, width, numeric, clearLabel, ...own }: ({
16
+ /** A leading icon inside the field, by name (`search`). Not with `prefix`. */
17
+ icon?: IconName | undefined;
18
+ /** Short text inside the border before the value (a currency symbol). For a plain field: not with `icon` or `type="search"`. */
19
+ prefix?: undefined;
20
+ } | {
21
+ /** A leading icon inside the field, by name (`search`). Not with `prefix`. */
22
+ icon?: undefined;
23
+ /** Short text inside the border before the value (a currency symbol). For a plain field: not with `icon` or `type="search"`. */
24
+ prefix: string;
25
+ }) & ControlProps & {
26
+ /**
27
+ * A field for a figure (an amount, a count): the value right-aligned in tabular figures, and
28
+ * `inputMode="decimal"` unless you pass your own (`numeric` for a whole number). It stays a
29
+ * text field, so the value is kept as typed; parsing it is yours. Ignored on `type="search"`.
30
+ * @default false
31
+ */
32
+ numeric?: boolean | undefined;
33
+ /**
34
+ * The name of a `type="search"` field's clear button, for an app in another language.
35
+ * @default Clear search
36
+ */
37
+ clearLabel?: string | undefined;
38
+ /** The `<input>` itself, for focus control. */
39
+ ref?: Ref<HTMLInputElement> | undefined;
40
+ } & Unstyled<Omit<ComponentPropsWithoutRef<"input">, "size" | "width" | "prefix">>): ReactElement;
package/dist/Input.js ADDED
@@ -0,0 +1,42 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { CONTROL_PAD, controlClass, NUMERIC_VALUE } from "./control.js";
3
+ import { cx } from "./cx.js";
4
+ import { useTypeStep } from "./density.js";
5
+ import { Icon } from "./Icon.js";
6
+ import { InputShell, PrefixShell } from "./InputShell.js";
7
+ import { SearchInput } from "./SearchInput.js";
8
+ import { useFieldControl } from "./fieldControl.js";
9
+ /**
10
+ * A text input. `icon` names a leading icon inside the field (`icon="search"`). `prefix` puts
11
+ * short text inside the border before the value, such as a currency symbol; it is for a plain
12
+ * field, not with an `icon` or `type="search"`. `numeric` is a field for a figure: an amount
13
+ * (`<Input prefix="R" numeric />`) or a count (`numeric inputMode="numeric"`). It right-aligns the
14
+ * value in tabular figures and brings up the phone's number keypad (`inputMode="decimal"` unless
15
+ * you pass your own), and stays a text field, so "1 250" is kept as typed; never use
16
+ * `type="number"` for a figure a person types. `type="search"` drops the browser's own search look and shows a clear button at the
17
+ * trailing edge while the field has a value, named by `clearLabel`. The `ref` reaches the `<input>`.
18
+ */
19
+ export function Input({ icon, prefix, size = "md", width = "full", numeric, clearLabel, ...own }) {
20
+ const step = useTypeStep();
21
+ const { rest, value } = asFigure({ ...own, ...useFieldControl(own) }, numeric);
22
+ const glyph = icon === undefined ? undefined : _jsx(Icon, { name: icon });
23
+ if (rest.type === "search") {
24
+ return (_jsx(SearchInput, { ...rest, icon: glyph, size: size, width: width, clearLabel: clearLabel ?? "Clear search" }));
25
+ }
26
+ if (prefix !== undefined) {
27
+ return (_jsx(PrefixShell, { prefix: prefix, size: size, width: width, disabled: rest.disabled, children: _jsx("input", { ...rest, className: cx("min-w-0 flex-1 bg-transparent px-1 text-ellipsis outline-none placeholder:text-slate-400", value) }) }));
28
+ }
29
+ if (glyph === undefined) {
30
+ return (_jsx("input", { ...rest, className: cx(controlClass(size, width, step), CONTROL_PAD[size].x, value) }));
31
+ }
32
+ return (_jsx(InputShell, { icon: glyph, size: size, width: width, children: _jsx("input", { ...rest, className: cx(controlClass(size, width === "auto" ? "auto" : "full", step), CONTROL_PAD[size].icon, value) }) }));
33
+ }
34
+ /**
35
+ * A `numeric` field's props and value class: the decimal keypad unless the caller chose one, and
36
+ * right-aligned tabular figures. A search field is never a figure.
37
+ */
38
+ function asFigure(props, numeric) {
39
+ if (!numeric || props.type === "search")
40
+ return { rest: props, value: undefined };
41
+ return { rest: { ...props, inputMode: props.inputMode ?? "decimal" }, value: NUMERIC_VALUE };
42
+ }
@@ -0,0 +1,24 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+ import { type ControlProps } from "./control.js";
3
+ /**
4
+ * The relative wrapper of an `Input` that holds more than the field: a leading `icon` and, for search, the clear button. Not exported from the package.
5
+ *
6
+ * Inside a Card or row (`liftInteractive`, which is `isolate`) the field is lifted to `z-10`, and
7
+ * its opaque background would paint over a z-auto icon. So the icon ranks `z-20` there. It is
8
+ * scoped to an `isolate` ancestor so a field elsewhere on the page never outranks AppShell's
9
+ * sticky header (`z-10`). The clear button is a lifted `button` and comes after the field, so it
10
+ * already sits above it.
11
+ */
12
+ export declare function InputShell({ icon, size, width, children, }: {
13
+ icon?: ReactNode;
14
+ children: ReactNode;
15
+ } & ControlProps): ReactElement;
16
+ /**
17
+ * The field box of an `Input` with a `prefix`: the control look and the focus ring sit on the
18
+ * wrapper, around the prefix text and the borderless input. Not exported from the package.
19
+ */
20
+ export declare function PrefixShell({ prefix, size, width, disabled, children, }: {
21
+ prefix: string;
22
+ disabled: boolean | undefined;
23
+ children: ReactNode;
24
+ } & ControlProps): ReactElement;
@@ -0,0 +1,40 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CONTROL_WIDTH, controlClass } from "./control.js";
3
+ import { cx } from "./cx.js";
4
+ import { useTypeStep } from "./density.js";
5
+ /**
6
+ * Where a leading icon sits, and its size, by the control's size. The wrapper is a flex box centred
7
+ * on the field, so the icon's own box centres too, and its one child is sized whether it is a bare
8
+ * `<svg>` or an `Icon`.
9
+ */
10
+ const ICON = {
11
+ sm: "left-2 [&>*]:size-3.5",
12
+ md: "left-3 [&>*]:size-4",
13
+ lg: "left-4 [&>*]:size-5",
14
+ };
15
+ /** The prefix text's inset and size, by the control's size. */
16
+ const PREFIX = {
17
+ sm: "pl-2 text-xs",
18
+ md: "pl-3 text-sm",
19
+ lg: "pl-4 text-base",
20
+ };
21
+ /**
22
+ * The relative wrapper of an `Input` that holds more than the field: a leading `icon` and, for search, the clear button. Not exported from the package.
23
+ *
24
+ * Inside a Card or row (`liftInteractive`, which is `isolate`) the field is lifted to `z-10`, and
25
+ * its opaque background would paint over a z-auto icon. So the icon ranks `z-20` there. It is
26
+ * scoped to an `isolate` ancestor so a field elsewhere on the page never outranks AppShell's
27
+ * sticky header (`z-10`). The clear button is a lifted `button` and comes after the field, so it
28
+ * already sits above it.
29
+ */
30
+ export function InputShell({ icon, size = "md", width = "full", children, }) {
31
+ return (_jsxs("div", { className: cx("relative", width === "auto" && "inline-block", width !== "full" && CONTROL_WIDTH[width]), children: [icon !== undefined && (_jsx("span", { "aria-hidden": "true", className: cx("pointer-events-none absolute top-1/2 flex -translate-y-1/2 items-center leading-none text-slate-400 in-[.isolate]:z-20", ICON[size]), children: icon })), children] }));
32
+ }
33
+ /**
34
+ * The field box of an `Input` with a `prefix`: the control look and the focus ring sit on the
35
+ * wrapper, around the prefix text and the borderless input. Not exported from the package.
36
+ */
37
+ export function PrefixShell({ prefix, size = "md", width = "full", disabled, children, }) {
38
+ const step = useTypeStep();
39
+ return (_jsxs("div", { className: cx(controlClass(size, width, step), "flex items-center has-aria-invalid:border-red-200 has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-violet-600", width === "auto" && "inline-flex", disabled && "opacity-50"), children: [_jsx("span", { className: cx("shrink-0 select-none text-slate-500", PREFIX[size]), children: prefix }), children] }));
40
+ }
package/dist/Kbd.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ /** A keyboard key. Its border takes the surrounding text colour, so it reads on a filled button and on plain text. */
4
+ export declare function Kbd({ children, ...rest }: {
5
+ children: ReactNode;
6
+ } & Passthrough): ReactElement;
package/dist/Kbd.js ADDED
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /** A keyboard key. Its border takes the surrounding text colour, so it reads on a filled button and on plain text. */
3
+ export function Kbd({ children, ...rest }) {
4
+ return (_jsx("kbd", { ...rest, className: "rounded border border-current/30 px-1 font-mono text-xs leading-4", children: children }));
5
+ }
@@ -0,0 +1,34 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ import type { Passthrough } from "./props.js";
3
+ import { type LoadingProps } from "./skeleton.js";
4
+ import { type TextTone } from "./typography.js";
5
+ type KeyValueAlign = "end" | "start";
6
+ /**
7
+ * A definition list of label/value rows. By default each label is on the left and its value
8
+ * right-aligned. `align="start"` puts every value left-aligned in one column beside the labels,
9
+ * which are sized to the widest. While `loading` with no rows it draws three rows of bones.
10
+ */
11
+ export declare function KeyValueList({ align, loading: ownLoading, loadingLabel, children, ...rest }: {
12
+ /**
13
+ * `end` right-aligns each value; `start` puts every value left-aligned in one column beside the labels, sized to the widest.
14
+ * @default end
15
+ */
16
+ align?: KeyValueAlign;
17
+ children?: ReactNode;
18
+ } & LoadingProps & Passthrough): ReactElement;
19
+ /**
20
+ * One row of a KeyValueList: a label on the left, a tabular value on the right (or beside it, in an
21
+ * `align="start"` list). `total` makes it the sum row: a rule above, strong text. `tone` colours the
22
+ * value, on any row: a total that does not reconcile is `total tone="warn"`. While `loading`, a
23
+ * label or value not here yet is a bone.
24
+ */
25
+ export declare function KeyValue({ label, total, tone, loading: ownLoading, loadingLabel, children, ...rest }: {
26
+ /** The term, on the left. */
27
+ label: ReactNode;
28
+ /** The sum the rows above add up to: a firm rule above it and the label and value in strong ink. */
29
+ total?: boolean | undefined;
30
+ /** The meaning of the value, in the colours of a `Table` cell's `tone` (`TextTone`; `neutral`, the default, is the list's ink); the label keeps its ink. Colour alone does not say it, so the value or the label says it too: a sign, a word. */
31
+ tone?: TextTone | undefined;
32
+ children?: ReactNode;
33
+ } & LoadingProps & Passthrough): ReactElement;
34
+ export {};
@@ -0,0 +1,35 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useContext } from "react";
3
+ import { cx } from "./cx.js";
4
+ import { Bone, BusyLabel, busy, isEmptySlot, LoadingScope, useLoading, } from "./skeleton.js";
5
+ import { textToneClass } from "./typography.js";
6
+ const AlignContext = createContext("end");
7
+ /**
8
+ * A definition list of label/value rows. By default each label is on the left and its value
9
+ * right-aligned. `align="start"` puts every value left-aligned in one column beside the labels,
10
+ * which are sized to the widest. While `loading` with no rows it draws three rows of bones.
11
+ */
12
+ export function KeyValueList({ align = "end", loading: ownLoading, loadingLabel, children, ...rest }) {
13
+ const { loading, owner } = useLoading(ownLoading);
14
+ const rows = loading && isEmptySlot(children)
15
+ ? [0, 1, 2].map((i) => (_jsx(KeyValue, { label: undefined, children: undefined }, i)))
16
+ : children;
17
+ return (_jsxs("dl", { ...rest, ...busy(owner, loading), className: cx(align === "start"
18
+ ? "grid grid-cols-[max-content_1fr] gap-x-3 gap-y-1.5"
19
+ : "flex flex-col gap-1.5", "text-sm"), children: [_jsx(AlignContext.Provider, { value: align, children: _jsx(LoadingScope, { loading: loading, children: rows }) }), owner && loading && (_jsx("div", { className: "sr-only", children: _jsx("dd", { children: _jsx(BusyLabel, { owner: owner, loading: loading, label: loadingLabel }) }) }))] }));
20
+ }
21
+ /** A label or value not here yet. */
22
+ function bone(wide) {
23
+ return _jsx(Bone, { shape: cx("inline-block h-[0.6lh] rounded align-middle", wide ? "w-24" : "w-14") });
24
+ }
25
+ /**
26
+ * One row of a KeyValueList: a label on the left, a tabular value on the right (or beside it, in an
27
+ * `align="start"` list). `total` makes it the sum row: a rule above, strong text. `tone` colours the
28
+ * value, on any row: a total that does not reconcile is `total tone="warn"`. While `loading`, a
29
+ * label or value not here yet is a bone.
30
+ */
31
+ export function KeyValue({ label, total = false, tone, loading: ownLoading, loadingLabel, children, ...rest }) {
32
+ const start = useContext(AlignContext) === "start";
33
+ const { loading, owner } = useLoading(ownLoading);
34
+ return (_jsxs("div", { ...rest, ...busy(owner, loading), className: cx(start ? "col-span-2 grid grid-cols-subgrid" : "flex justify-between gap-3", total && "border-t border-slate-300 pt-1.5 font-semibold"), children: [_jsx("dt", { className: total ? "text-slate-900" : "text-slate-600", children: loading && isEmptySlot(label) ? bone(true) : label }), _jsxs("dd", { className: cx(!start && "text-right", "tabular-nums", textToneClass(tone)), children: [loading && isEmptySlot(children) ? bone(false) : children, _jsx(BusyLabel, { owner: owner, loading: loading, label: loadingLabel })] })] }));
35
+ }