@jonmilner/ui 0.21.2 → 0.23.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 (204) hide show
  1. package/README.md +17 -0
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/dist/Alert/Alert.css +2 -0
  4. package/dist/Alert/Alert.css.mjs +9 -0
  5. package/dist/Alert/index.d.mts +13 -0
  6. package/dist/Alert/index.mjs +45 -0
  7. package/dist/AlertDialog/client.mjs +4 -4
  8. package/dist/AlertDialog/index.d.mts +3 -2
  9. package/dist/AlertDialog/index.mjs +10 -9
  10. package/dist/Avatar/Avatar.css +1 -1
  11. package/dist/Avatar/index.d.mts +1 -1
  12. package/dist/Avatar/index.mjs +5 -5
  13. package/dist/Badge/Badge.css +1 -1
  14. package/dist/Badge/index.d.mts +1 -1
  15. package/dist/Badge/index.mjs +12 -12
  16. package/dist/Body/index.d.mts +9 -0
  17. package/dist/Body/index.mjs +12 -0
  18. package/dist/Box/Box.css +1 -1
  19. package/dist/Box/index.mjs +1 -1
  20. package/dist/Button/Button.css +1 -1
  21. package/dist/Button/index.d.mts +1 -1
  22. package/dist/Button/index.mjs +22 -22
  23. package/dist/Caption/index.d.mts +6 -0
  24. package/dist/Caption/index.mjs +14 -0
  25. package/dist/Checkbox/Checkbox.css +1 -1
  26. package/dist/Checkbox/index.mjs +7 -7
  27. package/dist/Chip/Chip.css +1 -1
  28. package/dist/Chip/index.mjs +35 -35
  29. package/dist/Clickable/Clickable.css +1 -1
  30. package/dist/Clickable/index.d.mts +1 -1
  31. package/dist/Clickable/index.mjs +4 -4
  32. package/dist/Code/Code.css +2 -0
  33. package/dist/Code/Code.css.mjs +7 -0
  34. package/dist/Code/index.d.mts +10 -0
  35. package/dist/Code/index.mjs +40 -0
  36. package/dist/ColorField/ColorField.css +2 -2
  37. package/dist/ColorField/client.mjs +6 -6
  38. package/dist/ColorField/index.mjs +14 -14
  39. package/dist/Combobox/Combobox.css +2 -2
  40. package/dist/Combobox/client.mjs +26 -26
  41. package/dist/Combobox/index.mjs +20 -20
  42. package/dist/Dialog/Dialog.css +2 -2
  43. package/dist/Dialog/client.d.mts +1 -1
  44. package/dist/Dialog/client.mjs +30 -28
  45. package/dist/Dialog/index.d.mts +2 -2
  46. package/dist/Dialog/index.mjs +19 -19
  47. package/dist/Field/Field.css +1 -1
  48. package/dist/Field/client.mjs +6 -6
  49. package/dist/Field/index.mjs +29 -29
  50. package/dist/Flex/index.d.mts +5 -0
  51. package/dist/Flex/index.mjs +14 -0
  52. package/dist/Heading/Heading.css +1 -1
  53. package/dist/Icon/Icon.css +1 -1
  54. package/dist/IconButton/IconButton.css +2 -2
  55. package/dist/IconButton/IconButton.css.mjs +2 -2
  56. package/dist/IconButton/index.d.mts +5 -2
  57. package/dist/IconButton/index.mjs +60 -21
  58. package/dist/Inline/Inline.css +1 -1
  59. package/dist/Inline/index.d.mts +2 -2
  60. package/dist/Inline/index.mjs +4 -4
  61. package/dist/Label/index.d.mts +9 -0
  62. package/dist/Label/index.mjs +19 -0
  63. package/dist/Menu/Menu.css +2 -2
  64. package/dist/Menu/Menu.css.mjs +1 -1
  65. package/dist/Menu/client.d.mts +1 -0
  66. package/dist/Menu/client.mjs +83 -62
  67. package/dist/Menu/index.d.mts +8 -0
  68. package/dist/Menu/index.mjs +123 -87
  69. package/dist/Menu/item-row.mjs +2 -2
  70. package/dist/MultiSelect/MultiSelect.css +2 -2
  71. package/dist/MultiSelect/client.mjs +4 -4
  72. package/dist/MultiSelect/index.mjs +8 -8
  73. package/dist/NavList/NavList.css +2 -2
  74. package/dist/NavList/client.mjs +3 -3
  75. package/dist/NavList/index.d.mts +3 -3
  76. package/dist/NavList/index.mjs +67 -65
  77. package/dist/NumberField/NumberField.css +2 -2
  78. package/dist/NumberField/index.mjs +17 -17
  79. package/dist/Popover/Popover.css +2 -0
  80. package/dist/Popover/Popover.css.mjs +7 -0
  81. package/dist/Popover/client.d.mts +11 -0
  82. package/dist/Popover/client.mjs +54 -0
  83. package/dist/Popover/index.d.mts +20 -0
  84. package/dist/Popover/index.mjs +39 -0
  85. package/dist/RadioGroup/RadioGroup.css +1 -1
  86. package/dist/RadioGroup/index.mjs +23 -23
  87. package/dist/SearchField/SearchField.css +2 -2
  88. package/dist/SearchField/client.mjs +13 -13
  89. package/dist/SearchField/index.mjs +16 -16
  90. package/dist/Select/Select.css +2 -2
  91. package/dist/Select/client.mjs +11 -11
  92. package/dist/Select/index.mjs +8 -8
  93. package/dist/Sidebar/Sidebar.css +1 -1
  94. package/dist/Sidebar/index.d.mts +1 -1
  95. package/dist/Sidebar/index.mjs +21 -21
  96. package/dist/SidebarLayout/SidebarLayout.css +1 -1
  97. package/dist/SidebarLayout/index.d.mts +1 -1
  98. package/dist/SidebarLayout/index.mjs +8 -8
  99. package/dist/Stack/Stack.css +1 -1
  100. package/dist/Stack/index.d.mts +2 -2
  101. package/dist/Stack/index.mjs +4 -4
  102. package/dist/Switch/Switch.css +1 -1
  103. package/dist/Switch/index.mjs +13 -13
  104. package/dist/Table/Table.css +2 -2
  105. package/dist/Table/Table.css.mjs +4 -2
  106. package/dist/Table/index.d.mts +4 -10
  107. package/dist/Table/index.mjs +80 -94
  108. package/dist/Tabs/Tabs.css +1 -1
  109. package/dist/Tabs/index.mjs +26 -26
  110. package/dist/Tag/Tag.css +1 -1
  111. package/dist/Tag/index.d.mts +1 -1
  112. package/dist/Tag/index.mjs +16 -16
  113. package/dist/Text/Text.css +1 -1
  114. package/dist/Text/index.d.mts +2 -2
  115. package/dist/Text/index.mjs +4 -4
  116. package/dist/TextField/TextField.css +2 -2
  117. package/dist/TextField/index.mjs +16 -16
  118. package/dist/Textarea/Textarea.css +2 -2
  119. package/dist/Textarea/index.mjs +9 -9
  120. package/dist/Toast/Toast.css +2 -2
  121. package/dist/Toast/Toast.css.mjs +10 -7
  122. package/dist/Toast/client.d.mts +5 -19
  123. package/dist/Toast/client.mjs +117 -152
  124. package/dist/Tooltip/Tooltip.css +1 -1
  125. package/dist/Tooltip/base.mjs +13 -13
  126. package/dist/VisuallyHidden/VisuallyHidden.css +1 -1
  127. package/dist/base.css +2 -2
  128. package/dist/brands/default.mjs +2 -1
  129. package/dist/brands/forced-colors.mjs +2 -1
  130. package/dist/brands/neutral.mjs +8 -7
  131. package/dist/contrast/contrast.d.mts +1 -1
  132. package/dist/contrast/contrast.mjs +42 -34
  133. package/dist/contrast/mixes.mjs +37 -30
  134. package/dist/docs/Alert.md +106 -0
  135. package/dist/docs/AlertDialog.md +25 -11
  136. package/dist/docs/Body.md +74 -0
  137. package/dist/docs/Box.md +4 -3
  138. package/dist/docs/Caption.md +77 -0
  139. package/dist/docs/Code.md +84 -0
  140. package/dist/docs/ColorField.md +1 -1
  141. package/dist/docs/Combobox.md +3 -1
  142. package/dist/docs/Dialog.md +28 -4
  143. package/dist/docs/Flex.md +76 -0
  144. package/dist/docs/Icon.md +1 -0
  145. package/dist/docs/IconButton.md +9 -1
  146. package/dist/docs/Inline.md +3 -2
  147. package/dist/docs/Label.md +77 -0
  148. package/dist/docs/Menu.md +54 -6
  149. package/dist/docs/MultiSelect.md +2 -0
  150. package/dist/docs/NavList.md +2 -2
  151. package/dist/docs/NumberField.md +1 -1
  152. package/dist/docs/Popover.md +135 -0
  153. package/dist/docs/SearchField.md +1 -1
  154. package/dist/docs/Select.md +2 -0
  155. package/dist/docs/Stack.md +12 -10
  156. package/dist/docs/Table.md +5 -5
  157. package/dist/docs/Text.md +30 -23
  158. package/dist/docs/TextField.md +1 -1
  159. package/dist/docs/Textarea.md +1 -1
  160. package/dist/docs/Toast.md +14 -7
  161. package/dist/docs/Tooltip.md +2 -2
  162. package/dist/docs/lint.md +18 -0
  163. package/dist/docs/llms.txt +20 -11
  164. package/dist/docs/manifest.json +732 -65
  165. package/dist/docs/migrations/0.22.0.md +35 -0
  166. package/dist/docs/migrations/0.23.0.md +84 -0
  167. package/dist/docs/theming.md +3 -3
  168. package/dist/icons/TriangleAlertIcon.d.mts +2 -0
  169. package/dist/icons/TriangleAlertIcon.mjs +10 -0
  170. package/dist/icons/index.d.mts +6 -5
  171. package/dist/icons/index.mjs +35 -34
  172. package/dist/index.d.mts +24 -16
  173. package/dist/index.mjs +47 -40
  174. package/dist/lint/index.d.mts +20 -1
  175. package/dist/lint/index.mjs +19 -3
  176. package/dist/popup/client.d.mts +1 -1
  177. package/dist/popup/client.mjs +59 -41
  178. package/dist/popup/direction.d.mts +2 -0
  179. package/dist/popup/direction.mjs +23 -0
  180. package/dist/popup/listbox-base.mjs +24 -24
  181. package/dist/popup/listbox-options.mjs +4 -4
  182. package/dist/popup/listbox-row.mjs +1 -0
  183. package/dist/popup/positioner.mjs +27 -0
  184. package/dist/popup/tooltip.d.mts +1 -0
  185. package/dist/popup/tooltip.mjs +48 -42
  186. package/dist/scroll-region/scroll-region.d.mts +12 -0
  187. package/dist/scroll-region/scroll-region.mjs +29 -0
  188. package/dist/status-message/status-message.d.mts +5 -0
  189. package/dist/status-message/status-message.mjs +74 -0
  190. package/dist/status-message/tones.d.mts +7 -0
  191. package/dist/status-message/tones.mjs +8 -0
  192. package/dist/styles/atom-values.mjs +131 -0
  193. package/dist/styles/atoms.css +1 -1
  194. package/dist/styles/layers.css +1 -1
  195. package/dist/styles/responsive.css +1 -1
  196. package/dist/styles/scroll-region.css +2 -0
  197. package/dist/styles/scroll-region.css.mjs +7 -0
  198. package/dist/styles/status-message.css +2 -0
  199. package/dist/styles/status-message.css.mjs +7 -0
  200. package/dist/theme/define-theme.mjs +42 -42
  201. package/dist/tokens/contract.d.mts +1 -1
  202. package/dist/tokens/roles.d.mts +1 -1
  203. package/dist/tokens/roles.mjs +1 -1
  204. package/package.json +30 -2
@@ -36,6 +36,7 @@ var e = {
36
36
  doneSubtle: "Canvas",
37
37
  doneSubtleFg: "CanvasText",
38
38
  focus: "Highlight",
39
- shadow: "CanvasText"
39
+ shadow: "CanvasText",
40
+ backdrop: "transparent"
40
41
  };
41
42
  export { e as forcedColors };
@@ -19,12 +19,12 @@ var t = {
19
19
  selected: .07
20
20
  };
21
21
  function c(t) {
22
- let n = r(t);
22
+ let c = r(t);
23
23
  return {
24
- bg: e(a, n[950]),
25
- bgMuted: e(n[100], n[800]),
26
- bgRaised: e(a, n[900]),
27
- bgPanel: e(n[50], n[925]),
24
+ bg: e(a, c[950]),
25
+ bgMuted: e(c[100], c[800]),
26
+ bgRaised: e(a, c[900]),
27
+ bgPanel: e(c[50], c[925]),
28
28
  fg: i(t, 950),
29
29
  fgMuted: i(t, 600),
30
30
  border: i(t, 200),
@@ -32,9 +32,10 @@ function c(t) {
32
32
  hover: i(t, 950, s.hover),
33
33
  controlFill: i(t, 950, s.controlFill),
34
34
  selected: i(t, 950, s.selected),
35
- neutralSubtle: e(n[100], n[800]),
35
+ neutralSubtle: e(c[100], c[800]),
36
36
  neutralSubtleFg: i(t, 700),
37
- shadow: e(n[950], o)
37
+ shadow: e(c[950], o),
38
+ backdrop: e(n(t, 950, .4), "oklch(0 0 0 / 0.7)")
38
39
  };
39
40
  }
40
41
  export { r as neutralRamp, c as neutralRoles };
@@ -1,5 +1,5 @@
1
- import { ColorRole } from "../tokens/roles.mjs";
2
1
  import { Brand } from "../brands/brand.mjs";
2
+ import { ColorRole } from "../tokens/roles.mjs";
3
3
  import { Mode } from "./color.mjs";
4
4
  export interface ContrastPair {
5
5
  fg: ColorRole;
@@ -1,18 +1,20 @@
1
- import { subtleFills as e } from "../styles/subtle-fills.mjs";
2
- import { decode as t, resolveColor as n } from "./color.mjs";
1
+ import { statusTones as e } from "../status-message/tones.mjs";
2
+ import { fills as t } from "../styles/button-fills.mjs";
3
+ import { subtleFills as n } from "../styles/subtle-fills.mjs";
3
4
  import { overlayRoles as r } from "../tokens/roles.mjs";
5
+ import { decode as i, resolveColor as a } from "./color.mjs";
4
6
  // src/contrast/contrast.ts
5
- var i = [
7
+ var o = [
6
8
  "bg",
7
9
  "bgMuted",
8
10
  "bgRaised",
9
11
  "bgPanel"
10
- ], a = (e, t, n) => e.flatMap((e) => t.map((t) => ({
12
+ ], s = (e, t, n) => e.flatMap((e) => t.map((t) => ({
11
13
  fg: e,
12
14
  bg: t,
13
15
  min: n
14
- }))), o = Object.values(e).map(({ color: e, backgroundColor: t }) => [e, t]), s = [
15
- ...a([
16
+ }))), c = Object.values(n).map(({ color: e, backgroundColor: t }) => [e, t]), l = Object.values(e).map((e) => n[e].backgroundColor), u = [
17
+ ...s([
16
18
  "fg",
17
19
  "fgMuted",
18
20
  "accent",
@@ -20,30 +22,36 @@ var i = [
20
22
  "success",
21
23
  "warning",
22
24
  "done"
23
- ], i, 4.5),
24
- ...a(["accentFg"], ["accent"], 4.5),
25
- ...a(["accentFillFg"], ["accentFill"], 4.5),
26
- ...a(["dangerFg"], ["danger"], 4.5),
27
- ...a(["successFg"], ["success"], 4.5),
28
- ...a(["warningFg"], ["warning"], 4.5),
29
- ...a(["doneFg"], ["done"], 4.5),
30
- ...o.flatMap(([e, t]) => a([e], [t], 4.5)),
31
- ...a(["borderStrong", "focus"], i, 3),
32
- ...a(["focus"], o.map(([, e]) => e), 3),
33
- ...a(o.map(([e]) => e), ["bg"], 3),
34
- ...a(["fg", "fgMuted"], r, 4.5).flatMap((e) => i.map((t) => ({
25
+ ], o, 4.5),
26
+ ...s(["accentFg"], ["accent"], 4.5),
27
+ ...s(["accentFillFg"], ["accentFill"], 4.5),
28
+ ...s(["dangerFg"], ["danger"], 4.5),
29
+ ...s(["successFg"], ["success"], 4.5),
30
+ ...s(["warningFg"], ["warning"], 4.5),
31
+ ...s(["doneFg"], ["done"], 4.5),
32
+ ...c.flatMap(([e, t]) => s([e], [t], 4.5)),
33
+ ...s(["borderStrong", "focus"], o, 3),
34
+ ...s(["focus"], c.map(([, e]) => e), 3),
35
+ ...s(c.map(([e]) => e), ["bg"], 3),
36
+ ...s(["fg", "fgMuted"], r, 4.5).flatMap((e) => o.map((t) => ({
35
37
  ...e,
36
38
  over: t
37
- })))
38
- ], c = ["light", "dark"];
39
- function l({ r: e, g: n, b: r }) {
40
- return .2126 * t(e) + .7152 * t(n) + .0722 * t(r);
39
+ }))),
40
+ ...l.map((e) => ({
41
+ fg: t.secondary.color,
42
+ bg: t.secondary.backgroundColor,
43
+ min: 4.5,
44
+ over: e
45
+ }))
46
+ ], d = ["light", "dark"];
47
+ function f({ r: e, g: t, b: n }) {
48
+ return .2126 * i(e) + .7152 * i(t) + .0722 * i(n);
41
49
  }
42
- function u(e, t, r = "light", i) {
43
- let a = n(t, r);
44
- return f(n(e, r), i ? d(a, n(i, r)) : a, t);
50
+ function p(e, t, n = "light", r) {
51
+ let i = a(t, n);
52
+ return h(a(e, n), r ? m(i, a(r, n)) : i, t);
45
53
  }
46
- function d(e, t) {
54
+ function m(e, t) {
47
55
  let n = (t, n) => t * e.alpha + n * (1 - e.alpha);
48
56
  return {
49
57
  r: n(e.r, t.r),
@@ -52,16 +60,16 @@ function d(e, t) {
52
60
  alpha: 1
53
61
  };
54
62
  }
55
- function f(e, t, n) {
63
+ function h(e, t, n) {
56
64
  if (t.alpha < 1) throw Error(`Contrast background must be opaque: ${n}`);
57
- let [r, i] = [l(d(e, t)), l(t)].toSorted((e, t) => t - e);
65
+ let [r, i] = [f(m(e, t)), f(t)].toSorted((e, t) => t - e);
58
66
  return (r + .05) / (i + .05);
59
67
  }
60
- function p(e) {
61
- return c.flatMap((t) => {
62
- let r = /* @__PURE__ */ new Map(), i = (i) => r.get(i) ?? r.set(i, n(e.color[i], t)).get(i);
63
- return s.flatMap((n) => {
64
- let r = n.over ? d(i(n.bg), i(n.over)) : i(n.bg), a = f(i(n.fg), r, e.color[n.bg]);
68
+ function g(e) {
69
+ return d.flatMap((t) => {
70
+ let n = /* @__PURE__ */ new Map(), r = (r) => n.get(r) ?? n.set(r, a(e.color[r], t)).get(r);
71
+ return u.flatMap((n) => {
72
+ let i = n.over ? m(r(n.bg), r(n.over)) : r(n.bg), a = h(r(n.fg), i, e.color[n.bg]);
65
73
  return a < n.min ? [{
66
74
  ...n,
67
75
  mode: t,
@@ -70,4 +78,4 @@ function p(e) {
70
78
  });
71
79
  });
72
80
  }
73
- export { p as checkContrast, d as composite, s as contrastPairs, u as contrastRatio, i as surfaces };
81
+ export { g as checkContrast, m as composite, u as contrastPairs, p as contrastRatio, l as statusFills, o as surfaces };
@@ -1,41 +1,48 @@
1
1
  import { fills as e } from "../styles/button-fills.mjs";
2
- import { subtleFills as t } from "../styles/subtle-fills.mjs";
3
- import { overlayRoles as n } from "../tokens/roles.mjs";
4
- import { contrastRatio as r, surfaces as i } from "./contrast.mjs";
5
- import { highlightFill as a, highlightText as o } from "../styles/highlight.mjs";
6
- import { hoverFill as s } from "../styles/hover-tint.mjs";
2
+ import { highlightFill as t, highlightText as n } from "../styles/highlight.mjs";
3
+ import { hoverFill as r } from "../styles/hover-tint.mjs";
4
+ import { subtleFills as i } from "../styles/subtle-fills.mjs";
5
+ import { overlayRoles as a } from "../tokens/roles.mjs";
6
+ import { contrastRatio as o, statusFills as s, surfaces as c } from "./contrast.mjs";
7
7
  // src/contrast/mixes.ts
8
- var c = (e) => n.includes(e), l = [
8
+ var l = (e) => a.includes(e), u = [
9
9
  {
10
10
  name: "Menu highlight",
11
- fill: a,
12
- text: o,
11
+ fill: t,
12
+ text: n,
13
13
  min: 4.5
14
14
  },
15
15
  ...Object.entries(e).flatMap(([e, { backgroundColor: t, color: n }]) => {
16
- let r = [n];
17
- return t && !c(t) ? [{
16
+ let i = [n];
17
+ return t && !l(t) ? [{
18
18
  name: `${e} Button hover`,
19
- fill: (e) => s(e.fg, e[t]),
20
- text: r,
19
+ fill: (e) => r(e.fg, e[t]),
20
+ text: i,
21
21
  min: 4.5
22
- }] : i.map((n) => ({
22
+ }] : c.map((n) => ({
23
23
  name: `${e} Button hover on ${n}`,
24
- fill: (e) => s(e.fg, e[t ?? n]),
24
+ fill: (e) => r(e.fg, e[t ?? n]),
25
25
  ...t && { over: n },
26
- text: r,
26
+ text: i,
27
27
  min: 4.5
28
28
  }));
29
29
  }),
30
+ ...s.map((t) => ({
31
+ name: `secondary Button hover on ${t}`,
32
+ fill: (t) => r(t.fg, t[e.secondary.backgroundColor]),
33
+ over: t,
34
+ text: [e.secondary.color],
35
+ min: 4.5
36
+ })),
30
37
  {
31
38
  name: "pressed Chip hover",
32
- fill: (e) => s(e.fg, e.accent),
39
+ fill: (e) => r(e.fg, e.accent),
33
40
  text: ["accentFg"],
34
41
  min: 4.5
35
42
  },
36
- ...i.map((e) => ({
43
+ ...c.map((e) => ({
37
44
  name: `Table row hover on ${e}`,
38
- fill: (t) => s(t.fg, t[e], "5%"),
45
+ fill: (t) => r(t.fg, t[e], "5%"),
39
46
  text: e === "bgMuted" || e === "bgPanel" ? ["fg", "fgMuted"] : [
40
47
  "fg",
41
48
  "fgMuted",
@@ -47,26 +54,26 @@ var c = (e) => n.includes(e), l = [
47
54
  ],
48
55
  min: 4.5
49
56
  })),
50
- ...Object.entries(t).map(([e, { backgroundColor: t, color: n }]) => ({
57
+ ...Object.entries(i).map(([e, { backgroundColor: t, color: n }]) => ({
51
58
  name: `${e} Table row hover`,
52
- fill: (e) => s(e.fg, e[t], "5%"),
59
+ fill: (e) => r(e.fg, e[t], "5%"),
53
60
  text: [n],
54
61
  min: 4.5
55
62
  }))
56
63
  ];
57
- function u(e) {
58
- return ["light", "dark"].flatMap((t) => l.flatMap(({ name: n, fill: i, text: a, min: o, over: s }) => {
59
- let c = i(e.color), l = s && e.color[s];
60
- return a.flatMap((i) => {
61
- let a = r(e.color[i], c, t, l);
62
- return a < o ? [{
63
- fg: i,
64
+ function d(e) {
65
+ return ["light", "dark"].flatMap((t) => u.flatMap(({ name: n, fill: r, text: i, min: a, over: s }) => {
66
+ let c = r(e.color), l = s && e.color[s];
67
+ return i.flatMap((r) => {
68
+ let i = o(e.color[r], c, t, l);
69
+ return i < a ? [{
70
+ fg: r,
64
71
  mix: n,
65
- min: o,
72
+ min: a,
66
73
  mode: t,
67
- ratio: a
74
+ ratio: i
68
75
  }] : [];
69
76
  });
70
77
  }));
71
78
  }
72
- export { u as checkMixes, l as contrastMixes };
79
+ export { d as checkMixes, u as contrastMixes };
@@ -0,0 +1,106 @@
1
+ # Alert
2
+
3
+ ## Purpose
4
+
5
+ Tells the user about a condition on the page that lasts until its cause changes: offline, a trial ending, a sync that failed. A tinted card in the page's flow with the variant's icon, a title, an optional description, optional actions and an optional close button. It is a static surface: only what you put in it is interactive.
6
+
7
+ ## When to use
8
+
9
+ - A state of the page or account that stays true until something changes: "You're offline", "Your trial ends in 3 days", "Sync failed".
10
+ - A form-level error, in a slot that reserves its height, once the fields' own errors don't cover it.
11
+
12
+ ## When not to use
13
+
14
+ - The brief result of something the user just did ("Saved"): use `Toast`, which floats and leaves on its own.
15
+ - The error of one input: use the field's own error (`TextField`'s `error`, or `Field`).
16
+ - A decision that must be made before going on: use `AlertDialog`, which interrupts.
17
+ - A status label beside a name: use `Badge`.
18
+ - A bar fixed to the top of the viewport: Alert sits in the page's flow; the library has no such bar.
19
+
20
+ ## Rules
21
+
22
+ - `variant`: `info` (default), `success`, `warning` or `danger`. Each brings its icon and tinted fill, so the icon, not only the color, tells them apart (WCAG 1.4.1).
23
+ - `title` states the condition in a few words; `description` says what it means or what to do. Keep the description to a sentence or two.
24
+ - `actions` holds the buttons or links that fix the condition, usually a `Button` with `variant="secondary"` and the default size, or `size="sm"`. They sit at the end when the space inside the alert's padding is 32rem wide or more, centered against the text, and below the text when it is narrower. The width is the alert's own, not the viewport's, so it holds in a sidebar. Only actions go here: a link inside a sentence belongs in `description`.
25
+ - `onDismiss` shows the close button and runs when it is pressed. The caller removes the alert; without `onDismiss` it stays until its cause changes. `dismissLabel` is the button's accessible name, "Dismiss" by default; pass a translated string.
26
+ - Dismissing moves nothing for free: the page below an alert closes up. Give an alert that comes and goes a slot that reserves its height, or put it where nothing below can be mid-use.
27
+ - The icon stays centered on the title's first line however far the text wraps. Below 16rem the content takes its own line under the icon.
28
+ - It fills its container's inline size and sits in normal flow. It measures itself, so it adds no width to a parent that shrinks to its content, such as `inline-flex` or a popup: give that parent a width. It sets no margin: the parent's `gap` spaces it. Fill, text color, radius, padding and `inlineSize` are default style props on the root; a consumer's win. `className`, `style`, `ref` and other attributes go to the root, `className` last.
29
+ - The module has no hooks, so a server component can render it, as long as it passes no `onDismiss` from there.
30
+
31
+ ## Do
32
+
33
+ ```tsx
34
+ <Alert
35
+ variant="warning"
36
+ title="Your trial ends in 3 days"
37
+ description="Add a card to keep your projects."
38
+ actions={<Button variant="secondary">Add a card</Button>}
39
+ />
40
+ ```
41
+
42
+ ```tsx
43
+ // Dismissible: the caller decides when it leaves, and remembers it.
44
+ {
45
+ showNotice && (
46
+ <Alert title="New export format" onDismiss={hideNotice} dismissLabel="Dismiss the notice" />
47
+ );
48
+ }
49
+ ```
50
+
51
+ ```tsx
52
+ // It appears because of what the user just did, so it announces itself. The region is on the page
53
+ // first, and the alert renders inside it.
54
+ <Box aria-atomic="true" aria-live="assertive">
55
+ {syncFailed && (
56
+ <Alert
57
+ variant="danger"
58
+ title="Sync failed"
59
+ actions={<Button variant="secondary">Retry</Button>}
60
+ />
61
+ )}
62
+ </Box>
63
+ ```
64
+
65
+ ## Don't
66
+
67
+ ```tsx
68
+ // The brief result of an action: it would stay on the page with nothing left to say. Use Toast.
69
+ <Alert variant="success" title="Saved" />
70
+ ```
71
+
72
+ ```tsx
73
+ // One input's error, away from the input. Use the field's `error`.
74
+ <Alert variant="danger" title="Email is required" />
75
+ ```
76
+
77
+ ```tsx
78
+ // A decision: Alert does not stop the user. Use AlertDialog.
79
+ <Alert variant="danger" title="Delete this project?" actions={<Button>Delete</Button>} />
80
+ ```
81
+
82
+ ## Accessibility
83
+
84
+ - An alert announces nothing by default, since one present when the page loads should be read in order like the rest of it (ADR 0097). When one appears because of something the user just did, render it inside an element with `role="status"`, or `aria-live="assertive" aria-atomic="true"` for an urgent error, that is already on the page: a live region added with its text may go unread. An urgent region takes no `role="alert"`, since it sits empty until the error appears (ADR 0097), and an empty region still takes its parent's `gap`. Pass `role` to the alert itself only when it stays mounted and its text changes.
85
+ - Showing an alert never moves focus. When the close button removes the alert, move focus somewhere deliberate, such as the next control or the section's heading: the button is gone, so focus would otherwise fall to the page.
86
+ - The icon is decorative; the title states the condition.
87
+ - The close button is a native button with the shared focus ring and a 24px target.
88
+ - Resize text (WCAG 1.4.4): the 32rem width and the narrower 16rem one, where the content takes its own line below the icon and close button, are measured inside the padding and in rem, so at 200% text the layout wraps sooner and nothing overflows.
89
+ - Under forced colors the fill drops and the border keeps the card's edge.
90
+
91
+ ## Props
92
+
93
+ Generated from the TypeScript types.
94
+
95
+ ### Alert
96
+
97
+ | Prop | Type | Required | Description |
98
+ | --- | --- | --- | --- |
99
+ | `actions` | `ReactNode` | no | |
100
+ | `description` | `ReactNode` | no | |
101
+ | `dismissLabel` | `string` | no | |
102
+ | `onDismiss` | `(() => void)` | no | |
103
+ | `title` | `ReactNode` | yes | |
104
+ | `variant` | `"danger" \| "info" \| "success" \| "warning"` | no | |
105
+
106
+ Also accepts the style props (see `manifest.json` `styleProps`).
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Purpose
4
4
 
5
- Asks the user to confirm a consequential action before it runs: delete a project, discard unsaved changes, sign out every device. Built on Base UI's AlertDialog, which owns the behavior: `role="alertdialog"`, focus moves into the dialog and stays there, the page behind is inert, Esc closes it, and a click outside does not. It wears Dialog's panel at the `sm` width with a title, a description, Cancel and one confirm button, and Cancel takes focus on open.
5
+ Asks the user to confirm a consequential action before it runs: delete a project, discard unsaved changes, sign out every device. Built on Base UI's AlertDialog, which owns the behavior: `role="alertdialog"`, focus moves into the dialog and stays there, the page behind is hidden from assistive tech, Esc closes it, and a click outside does not. It wears Dialog's panel at the `sm` width with a title, a description, Cancel and one confirm button, and Cancel takes focus on open.
6
6
 
7
7
  ## When to use
8
8
 
@@ -24,6 +24,7 @@ Asks the user to confirm a consequential action before it runs: delete a project
24
24
  - `onConfirm` runs once on the confirm button, then the dialog closes; a second click while it fades out does nothing. If it throws, the dialog stays open; a returned promise is not awaited. For an action that can fail, control it with `open` and `onOpenChange` and report the failure where the action started.
25
25
  - Cancel comes first and takes focus, so Enter on open cancels. On a touch screen Base UI focuses the panel instead, so no button is pressed by accident.
26
26
  - Without `AlertDialog.Trigger`, control it with `open` and `onOpenChange`; it then portals to `<body>`, as Dialog does.
27
+ - `finalFocus` says where focus goes when it closes, as on `Dialog.Popup`. Opened from a menu item, the item is gone once the menu closes and there is no trigger, so pass a ref to the control to return to, usually the menu's trigger. The ref points at the focusable control itself. It gets focus at once on Esc, Cancel or confirm, with a visible focus ring after a key (ADR 0192); an empty ref falls back to the trigger, or the element focused before it opened.
27
28
  - It is always modal and takes no `className`, `style` or style props: the panel is fixed so every confirm looks the same.
28
29
  - The module has no hooks and no `"use client"`, but `onConfirm` is a function, so the component that renders it is a client component.
29
30
 
@@ -42,16 +43,28 @@ Asks the user to confirm a consequential action before it runs: delete a project
42
43
  ```
43
44
 
44
45
  ```tsx
45
- // Opened from a menu item: no trigger, so control it.
46
+ // Opened from a menu item: no trigger, so control it, and return focus to the menu's trigger.
46
47
  const [open, setOpen] = useState(false);
47
- <AlertDialog
48
- open={open}
49
- onOpenChange={setOpen}
50
- title="Sign out of every device?"
51
- description="You stay signed in here."
52
- confirmLabel="Sign out"
53
- onConfirm={signOutEverywhere}
54
- />;
48
+ const account = useRef<HTMLButtonElement>(null);
49
+ <>
50
+ <Menu>
51
+ <Menu.Trigger ref={account} variant="secondary">
52
+ Account
53
+ </Menu.Trigger>
54
+ <Menu.Popup>
55
+ <Menu.Item onClick={() => setOpen(true)}>Sign out everywhere…</Menu.Item>
56
+ </Menu.Popup>
57
+ </Menu>
58
+ <AlertDialog
59
+ open={open}
60
+ onOpenChange={setOpen}
61
+ finalFocus={account}
62
+ title="Sign out of every device?"
63
+ description="You stay signed in here."
64
+ confirmLabel="Sign out"
65
+ onConfirm={signOutEverywhere}
66
+ />
67
+ </>;
55
68
  ```
56
69
 
57
70
  ## Don't
@@ -74,7 +87,7 @@ const [open, setOpen] = useState(false);
74
87
  ## Accessibility
75
88
 
76
89
  - The trigger has `aria-haspopup="dialog"` and `aria-expanded`. The popup is `role="alertdialog"` with `aria-modal`, labelled by the title and described by the description.
77
- - Opening moves focus to Cancel; Tab and Shift+Tab cycle between the two buttons, and the page behind is inert. Esc or Cancel closes it, and focus returns to the trigger. A click outside does nothing.
90
+ - Opening moves focus to Cancel; Tab and Shift+Tab cycle between the two buttons, and the page behind is `aria-hidden`. Esc or Cancel closes it, and focus returns to the trigger, or to `finalFocus`. A click outside does nothing.
78
91
  - A closed alert dialog stays on the page while it fades out, but is `inert` and `aria-hidden` from the moment it closes, and focus is back on the trigger at once, so a dialog opened during the fade is the only one a screen reader or a role query finds, and nothing in the fading one takes focus or a click (ADR 0113).
79
92
  - The danger confirm button is told apart by its label as well as its color.
80
93
  - Under reduced motion the panel only fades.
@@ -92,6 +105,7 @@ Generated from the TypeScript types.
92
105
  | `confirmLabel` | `string` | yes | |
93
106
  | `defaultOpen` | `boolean` | no | Whether the dialog is initially open. To render a controlled dialog, use the `open` prop instead. |
94
107
  | `description` | `string \| number \| bigint \| Iterable<ReactNode> \| Promise<AwaitedReactNode> \| ReactElement<unknown, string \| JSXElementConstructor<any>> \| ReactPortal` | yes | |
108
+ | `finalFocus` | `boolean \| RefObject<HTMLElement \| null> \| ((closeType: InteractionType) => void \| boolean \| HTMLElement \| null)` | no | |
95
109
  | `onConfirm` | `() => void` | yes | |
96
110
  | `onOpenChange` | `((open: boolean, eventDetails: AlertDialogRootChangeEventDetails) => void)` | no | Event handler called when the alert dialog is opened or closed. |
97
111
  | `onOpenChangeComplete` | `((open: boolean) => void)` | no | Event handler called after any animations complete when the dialog is opened or closed. |
@@ -0,0 +1,74 @@
1
+ # Body
2
+
3
+ ## Purpose
4
+
5
+ Running text: paragraphs, descriptions, empty-state copy, the sentences in a card or dialog. A `Text` with body defaults: the `body` font role at `med`, rendered as a `p`. At `sm` it takes the paired `body` leading, 14/20, for dense UI.
6
+
7
+ ## When to use
8
+
9
+ - A paragraph or sentence a user reads.
10
+ - Dense UI copy (a table's empty state, a sidebar's help text): `size="sm"`.
11
+
12
+ ## When not to use
13
+
14
+ - A heading: use `Heading`.
15
+ - Short UI text that names something (a value's name, a status, a column's label outside a table): use `Label`.
16
+ - A note under or beside other text (a timestamp, a count, a file size): use `Caption`.
17
+ - A form control's label: use `Field.Label`.
18
+
19
+ ## Rules
20
+
21
+ - `size` is `sm`, `med` (default) or `lg`. Larger type is a `Heading`, or `Text` with `font="display"`.
22
+ - `as` defaults to `p`. Set another block element (`div`) when the text is not a paragraph.
23
+ - Body always sets its size, so it is not a run: a bold or emphasised word inside a Body is `<Text as="strong">`, which inherits the outer size. A `p` inside a `p` is invalid HTML.
24
+ - Body takes every other Text prop (`color`, `weight`, `leading`, `font`, `truncate`, `wrap`, style props) and overrides its defaults with them.
25
+ - Space paragraphs with the gap of a `Stack` around them, not margins: the box is trimmed to the text.
26
+
27
+ ## Do
28
+
29
+ ```tsx
30
+ <Stack gap="12">
31
+ <Body>Invites go to everyone on the list.</Body>
32
+ <Body color="fgMuted" size="sm">
33
+ Each link works once and expires after seven days.
34
+ </Body>
35
+ </Stack>
36
+ ```
37
+
38
+ ## Don't
39
+
40
+ ```tsx
41
+ // Body stops at lg; a heading is a Heading.
42
+ <Body size="2xl">Settings</Body>
43
+ ```
44
+
45
+ ```tsx
46
+ // A Body inside a Body is a p inside a p, and resets the size; a run is a Text.
47
+ <Body size="sm">
48
+ Saved <Body>today</Body>
49
+ </Body>
50
+ ```
51
+
52
+ ## Accessibility
53
+
54
+ - A `p` is a paragraph to screen readers; set `as` to another element only when the text is not one.
55
+ - Keep muted body text on the color roles meant for it (`fgMuted`), which meet contrast on every surface.
56
+
57
+ ## Props
58
+
59
+ Generated from the TypeScript types.
60
+
61
+ ### Body
62
+
63
+ | Prop | Type | Required | Description |
64
+ | --- | --- | --- | --- |
65
+ | `as` | `ElementType` | no | |
66
+ | `font` | `"body" \| "display" \| "heading" \| "label" \| "mono"` | no | |
67
+ | `leading` | `"body" \| "lg" \| "med" \| "meta" \| "sm"` | no | |
68
+ | `size` | `"lg" \| "med" \| "sm"` | no | |
69
+ | `tabularNums` | `boolean` | no | |
70
+ | `truncate` | `"box" \| boolean` | no | |
71
+ | `weight` | `"bold" \| "medium" \| "regular" \| "semibold"` | no | |
72
+ | `wrap` | `"nowrap" \| "pre" \| "pre-wrap"` | no | |
73
+
74
+ Also accepts every `<p>` attribute (change the element with `as`) and the style props (see `manifest.json` `styleProps`).
package/dist/docs/Box.md CHANGED
@@ -7,13 +7,13 @@ The base element every component builds on: one element, chosen with `as`, style
7
7
  ## When to use
8
8
 
9
9
  - Surfaces that need tokens but no behavior: a padded panel, a sticky bar, a grid.
10
- - A semantic element (`as="section"`, `as="nav"`, `as="ul"`) that needs style props.
10
+ - A semantic element (`as="section"`, `as="nav"`, `as="ul"`) that needs style props. A raw element with a `className` (`<ul className={css.list}>`) is a code smell: a `Box` with `as` and style props is the minimum.
11
11
  - Building a new component: render a `Box` and pass its tunable values as default style props.
12
12
 
13
13
  ## When not to use
14
14
 
15
- - Text: use `Text` or `Heading`; all visible text goes through them.
16
- - Stacks and rows of children with a gap: use `Stack` or `Inline`. A Box with `display="flex"`, `flexDirection="column"` and `gap` is a `Stack` rebuilt by hand.
15
+ - Text: use `Heading`, `Body`, `Label`, `Caption` or `Code`; all visible text goes through them, or through `Text` for what none covers (see its docs).
16
+ - Stacks and rows of children with a gap: use `Stack` or `Inline`, not `Box` or `Flex`. A Box with `display="flex"`, `flexDirection="column"` and `gap` is a `Stack` rebuilt by hand.
17
17
  - Records in rows that share named columns: use `Table`, not a grid of boxes, so the columns have headers.
18
18
  - Anything interactive: use `Button` or a link component, which bring focus and states.
19
19
 
@@ -26,6 +26,7 @@ The base element every component builds on: one element, chosen with `as`, style
26
26
  - The style-prop CSS ships in two files (decision 0111). Every component brings the base rules. The `sm`, `med`, `lg` and `xl` rules are `@jonmilner/ui/responsive.css`, which only Box, Stack and Inline import, so a Button alone ships none of them, whether imported from `@jonmilner/ui/Button` or from `@jonmilner/ui`.
27
27
  - A responsive value on any other component (`<Button marginBlock={{ base: "8", med: "16" }}>`) keeps only its `base` value unless `responsive.css` is on the page. A Box, Stack or Inline on the page brings it, but one on another route only does if that route loaded first. So an app that sets one imports it once, as a JS import, in its root module beside `base.css`.
28
28
  - In development a console warning names the missing import, but only where the rules are really absent: in development the root `@jonmilner/ui` import loads every component, Box included, so there the value works and the warning stays silent, and only the production build drops it.
29
+ - A `*.css.ts` file is the exception: never write a property/value pair there that a style prop covers (`display: "flex"`, `gap: vars.space["16"]`), unless the style prop cannot work in that case. `styleProps` from `@jonmilner/ui/lint` lists each prop's values (see `lint.md`).
29
30
  - There are no hover, focus or active props; states belong in component CSS.
30
31
  - `null` and `false` leave a prop unset, so `paddingInline={dense && "8"}` works.
31
32
  - The consumer's `className` comes last and `style` is passed through, so consumer values win.
@@ -0,0 +1,77 @@
1
+ # Caption
2
+
3
+ ## Purpose
4
+
5
+ A note that sits under or beside other text: a timestamp, a count, a file size, a hint under a value. A `Text` with caption defaults: `xs`, `medium` weight, the paired `meta` leading (12/16), `fgMuted`, rendered as a `span`. One size, so it has no `size` or `leading` prop.
6
+
7
+ ## When to use
8
+
9
+ - Secondary detail about the thing next to it: "Updated 3 minutes ago", "12 files", "2.4 MB".
10
+ - A count or timestamp in a dense row.
11
+ - A figure's caption: `as="figcaption"` inside the `figure`.
12
+
13
+ ## When not to use
14
+
15
+ - A form field's help text: use the field's `description` (or `Field.Description`), which the control is described by.
16
+ - A form field's error: use the field's `error` (or `Field.Error`).
17
+ - A sentence a user must read to act: use `Body`, at `sm` if it must be small.
18
+ - A name or tag: use `Label`.
19
+
20
+ ## Rules
21
+
22
+ - No `size` or `leading`: a caption is 12/16. Larger secondary text is `Body size="sm" color="fgMuted"`.
23
+ - `color` defaults to `fgMuted`; set another role (`fg`, `danger`, …) to override it.
24
+ - `as` defaults to `span`. On its own it is still a trimmed block (Text's default `display`); directly inside another Text it is an inline run, still at `xs`.
25
+ - Caption takes every other Text prop (`weight`, `font`, `tabularNums`, `truncate`, style props) and overrides its defaults with them.
26
+ - Use `tabularNums` on a count or duration that ticks or sits in a column.
27
+
28
+ ## Do
29
+
30
+ ```tsx
31
+ <Stack gap="8">
32
+ <Body size="sm">Quarterly report.pdf</Body>
33
+ <Caption>Updated 3 minutes ago</Caption>
34
+ </Stack>
35
+ ```
36
+
37
+ ```tsx
38
+ <Caption as="time" dateTime="2026-11-10">
39
+ Nov 10
40
+ </Caption>
41
+ ```
42
+
43
+ ## Don't
44
+
45
+ ```tsx
46
+ // A caption has one size; small body text is Body.
47
+ <Caption size="sm">Each link works once.</Caption>
48
+ ```
49
+
50
+ ```tsx
51
+ // Help text under a field is its description, which the control is described by.
52
+ <TextField label="Email" />
53
+ <Caption>We never share it.</Caption>
54
+ ```
55
+
56
+ ## Accessibility
57
+
58
+ - `fgMuted` meets text contrast on every surface; do not lighten a caption further with opacity.
59
+ - A caption is not tied to anything for assistive technology. When it describes a control, use `Field.Description` or `aria-describedby`.
60
+ - Never put information only in a caption that a user needs to complete a task.
61
+
62
+ ## Props
63
+
64
+ Generated from the TypeScript types.
65
+
66
+ ### Caption
67
+
68
+ | Prop | Type | Required | Description |
69
+ | --- | --- | --- | --- |
70
+ | `as` | `ElementType` | no | |
71
+ | `font` | `"body" \| "display" \| "heading" \| "label" \| "mono"` | no | |
72
+ | `tabularNums` | `boolean` | no | |
73
+ | `truncate` | `"box" \| boolean` | no | |
74
+ | `weight` | `"bold" \| "medium" \| "regular" \| "semibold"` | no | |
75
+ | `wrap` | `"nowrap" \| "pre" \| "pre-wrap"` | no | |
76
+
77
+ Also accepts every `<span>` attribute (change the element with `as`) and the style props (see `manifest.json` `styleProps`).