@ignite-ember/ui-react 0.0.0-stage → 0.2.1

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 (134) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +260 -2
  4. package/dist/CopySource.d.ts +4 -0
  5. package/dist/CopySource.d.ts.map +1 -0
  6. package/dist/CopySource.js +50 -0
  7. package/dist/CopySource.js.map +1 -0
  8. package/dist/DataTable.d.ts +77 -0
  9. package/dist/DataTable.d.ts.map +1 -0
  10. package/dist/DataTable.js +45 -0
  11. package/dist/DataTable.js.map +1 -0
  12. package/dist/Dialog.d.ts +41 -0
  13. package/dist/Dialog.d.ts.map +1 -0
  14. package/dist/Dialog.js +94 -0
  15. package/dist/Dialog.js.map +1 -0
  16. package/dist/ErrorBoundary.d.ts +97 -0
  17. package/dist/ErrorBoundary.d.ts.map +1 -0
  18. package/dist/ErrorBoundary.js +97 -0
  19. package/dist/ErrorBoundary.js.map +1 -0
  20. package/dist/LiveRegion.d.ts +41 -0
  21. package/dist/LiveRegion.d.ts.map +1 -0
  22. package/dist/LiveRegion.js +76 -0
  23. package/dist/LiveRegion.js.map +1 -0
  24. package/dist/Markdown.d.ts +22 -0
  25. package/dist/Markdown.d.ts.map +1 -0
  26. package/dist/Markdown.js +56 -0
  27. package/dist/Markdown.js.map +1 -0
  28. package/dist/MarkdownInline.d.ts +53 -0
  29. package/dist/MarkdownInline.d.ts.map +1 -0
  30. package/dist/MarkdownInline.js +159 -0
  31. package/dist/MarkdownInline.js.map +1 -0
  32. package/dist/MenuIcon.d.ts +60 -0
  33. package/dist/MenuIcon.d.ts.map +1 -0
  34. package/dist/MenuIcon.js +102 -0
  35. package/dist/MenuIcon.js.map +1 -0
  36. package/dist/Mermaid.d.ts +40 -0
  37. package/dist/Mermaid.d.ts.map +1 -0
  38. package/dist/Mermaid.js +121 -0
  39. package/dist/Mermaid.js.map +1 -0
  40. package/dist/Monogram.d.ts +46 -0
  41. package/dist/Monogram.d.ts.map +1 -0
  42. package/dist/Monogram.js +96 -0
  43. package/dist/Monogram.js.map +1 -0
  44. package/dist/OverflowMenu.d.ts +60 -0
  45. package/dist/OverflowMenu.d.ts.map +1 -0
  46. package/dist/OverflowMenu.js +149 -0
  47. package/dist/OverflowMenu.js.map +1 -0
  48. package/dist/Shell.d.ts +67 -0
  49. package/dist/Shell.d.ts.map +1 -0
  50. package/dist/Shell.js +44 -0
  51. package/dist/Shell.js.map +1 -0
  52. package/dist/Skeleton.d.ts +62 -0
  53. package/dist/Skeleton.d.ts.map +1 -0
  54. package/dist/Skeleton.js +56 -0
  55. package/dist/Skeleton.js.map +1 -0
  56. package/dist/Split.d.ts +85 -0
  57. package/dist/Split.d.ts.map +1 -0
  58. package/dist/Split.js +156 -0
  59. package/dist/Split.js.map +1 -0
  60. package/dist/Tabs.d.ts +77 -0
  61. package/dist/Tabs.d.ts.map +1 -0
  62. package/dist/Tabs.js +91 -0
  63. package/dist/Tabs.js.map +1 -0
  64. package/dist/Toast.d.ts +98 -0
  65. package/dist/Toast.d.ts.map +1 -0
  66. package/dist/Toast.js +129 -0
  67. package/dist/Toast.js.map +1 -0
  68. package/dist/Tooltip.d.ts +24 -0
  69. package/dist/Tooltip.d.ts.map +1 -0
  70. package/dist/Tooltip.js +166 -0
  71. package/dist/Tooltip.js.map +1 -0
  72. package/dist/controls.d.ts +117 -0
  73. package/dist/controls.d.ts.map +1 -0
  74. package/dist/controls.js +59 -0
  75. package/dist/controls.js.map +1 -0
  76. package/dist/cx.d.ts +3 -0
  77. package/dist/cx.d.ts.map +1 -0
  78. package/dist/cx.js +5 -0
  79. package/dist/cx.js.map +1 -0
  80. package/dist/fenceInfo.d.ts +26 -0
  81. package/dist/fenceInfo.d.ts.map +1 -0
  82. package/dist/fenceInfo.js +22 -0
  83. package/dist/fenceInfo.js.map +1 -0
  84. package/dist/formControls.d.ts +143 -0
  85. package/dist/formControls.d.ts.map +1 -0
  86. package/dist/formControls.js +108 -0
  87. package/dist/formControls.js.map +1 -0
  88. package/dist/index.d.ts +78 -0
  89. package/dist/index.d.ts.map +1 -0
  90. package/dist/index.js +78 -0
  91. package/dist/index.js.map +1 -0
  92. package/dist/layout.d.ts +95 -0
  93. package/dist/layout.d.ts.map +1 -0
  94. package/dist/layout.js +93 -0
  95. package/dist/layout.js.map +1 -0
  96. package/dist/primitives.d.ts +33 -0
  97. package/dist/primitives.d.ts.map +1 -0
  98. package/dist/primitives.js +33 -0
  99. package/dist/primitives.js.map +1 -0
  100. package/dist/progress.d.ts +64 -0
  101. package/dist/progress.d.ts.map +1 -0
  102. package/dist/progress.js +51 -0
  103. package/dist/progress.js.map +1 -0
  104. package/dist/text.d.ts +63 -0
  105. package/dist/text.d.ts.map +1 -0
  106. package/dist/text.js +61 -0
  107. package/dist/text.js.map +1 -0
  108. package/package.json +56 -4
  109. package/src/CopySource.tsx +67 -0
  110. package/src/DataTable.tsx +120 -0
  111. package/src/Dialog.tsx +158 -0
  112. package/src/ErrorBoundary.tsx +137 -0
  113. package/src/LiveRegion.tsx +127 -0
  114. package/src/Markdown.tsx +75 -0
  115. package/src/MarkdownInline.tsx +177 -0
  116. package/src/MenuIcon.tsx +209 -0
  117. package/src/Mermaid.tsx +144 -0
  118. package/src/Monogram.tsx +112 -0
  119. package/src/OverflowMenu.tsx +359 -0
  120. package/src/Shell.tsx +99 -0
  121. package/src/Skeleton.tsx +98 -0
  122. package/src/Split.tsx +267 -0
  123. package/src/Tabs.tsx +194 -0
  124. package/src/Toast.tsx +269 -0
  125. package/src/Tooltip.tsx +213 -0
  126. package/src/controls.tsx +159 -0
  127. package/src/cx.ts +4 -0
  128. package/src/fenceInfo.ts +36 -0
  129. package/src/formControls.tsx +249 -0
  130. package/src/index.ts +149 -0
  131. package/src/layout.tsx +141 -0
  132. package/src/primitives.tsx +33 -0
  133. package/src/progress.tsx +129 -0
  134. package/src/text.tsx +99 -0
@@ -0,0 +1,249 @@
1
+ /**
2
+ * The form controls: a drop-down, a multi-line field, a checkbox, a
3
+ * radio, a switch, and the field that labels any of them.
4
+ *
5
+ * Part of the primitives; see `primitives.tsx`. **Under the
6
+ * compatibility floor.**
7
+ */
8
+
9
+ import type {
10
+ ButtonHTMLAttributes,
11
+ HTMLAttributes,
12
+ InputHTMLAttributes,
13
+ ReactElement,
14
+ ReactNode,
15
+ SelectHTMLAttributes,
16
+ TextareaHTMLAttributes,
17
+ } from "react";
18
+ import { cloneElement, isValidElement, useId } from "react";
19
+
20
+ import { cx } from "./cx.js";
21
+
22
+ /** What a {@link Select} takes. */
23
+ export interface SelectProps extends SelectHTMLAttributes<HTMLSelectElement> {}
24
+
25
+ /**
26
+ * A drop-down.
27
+ *
28
+ * @param className — added to the element's classes, beside the one the
29
+ * theme gives it.
30
+ * @param rest — the remaining props, spread onto the select.
31
+ */
32
+ export function Select({ className, ...rest }: SelectProps) {
33
+ return <select {...rest} className={cx("ui-select", className)} />;
34
+ }
35
+
36
+ /** What a {@link Textarea} takes. */
37
+ export interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {}
38
+
39
+ /**
40
+ * A multi-line text field.
41
+ *
42
+ * @param className — added to the element's classes, beside the one the
43
+ * theme gives it.
44
+ * @param rest — the remaining props, spread onto the textarea.
45
+ */
46
+ export function Textarea({ className, ...rest }: TextareaProps) {
47
+ return <textarea {...rest} className={cx("ui-textarea", className)} />;
48
+ }
49
+
50
+ /** What a {@link Checkbox} takes. */
51
+ export interface CheckboxProps extends InputHTMLAttributes<HTMLInputElement> {
52
+ /** The text beside the box. It is the accessible name too. */
53
+ label: ReactNode;
54
+ }
55
+
56
+ /**
57
+ * A native checkbox, wrapped in its own label.
58
+ *
59
+ * Wrapped rather than associated by `id`, because an `id` an
60
+ * extension forgets to make unique is a label that checks somebody
61
+ * else's box — and nothing about the page looks wrong when it does.
62
+ *
63
+ * @param label — the text beside the box, and the accessible name too.
64
+ * @param className — added to the label's classes, beside the one the
65
+ * theme gives it.
66
+ * @param rest — the remaining props, spread onto the input inside the
67
+ * label.
68
+ */
69
+ export function Checkbox({ label, className, ...rest }: CheckboxProps) {
70
+ return (
71
+ <label className={cx("ui-check", className)}>
72
+ <input {...rest} type="checkbox" />
73
+ <span>{label}</span>
74
+ </label>
75
+ );
76
+ }
77
+
78
+ /** What a {@link Radio} takes. */
79
+ export interface RadioProps extends InputHTMLAttributes<HTMLInputElement> {
80
+ /** The text beside the box. It is the accessible name too. */
81
+ label: ReactNode;
82
+ }
83
+
84
+ /**
85
+ * A native radio, wrapped in its own label.
86
+ *
87
+ * Wrapped for the same reason a {@link Checkbox} is: an `id` an
88
+ * extension forgets to make unique is a label that picks somebody
89
+ * else's radio.
90
+ *
91
+ * @param label — the text beside the box, and the accessible name too.
92
+ * @param className — added to the label's classes, beside the one the
93
+ * theme gives it.
94
+ * @param rest — the remaining props, spread onto the input inside the
95
+ * label.
96
+ */
97
+ export function Radio({ label, className, ...rest }: RadioProps) {
98
+ return (
99
+ <label className={cx("ui-check", className)}>
100
+ <input {...rest} type="radio" />
101
+ <span>{label}</span>
102
+ </label>
103
+ );
104
+ }
105
+
106
+ /** What a {@link Switch} takes. */
107
+ export interface SwitchProps extends Omit<
108
+ ButtonHTMLAttributes<HTMLButtonElement>,
109
+ "onChange"
110
+ > {
111
+ /** Whether it is on. */
112
+ checked: boolean;
113
+ /** Called with the next value. It takes effect at once. */
114
+ onChange: (next: boolean) => void;
115
+ /**
116
+ * Shown beside the switch, and used as its accessible name.
117
+ *
118
+ * Visible, like `Checkbox.label` and `Radio.label`, so the one prop
119
+ * name means the same thing on all three and a sighted user reads
120
+ * what the toggle is for.
121
+ */
122
+ label: ReactNode;
123
+ }
124
+
125
+ /**
126
+ * A switch, which is a button rather than a checkbox.
127
+ *
128
+ * The difference is not cosmetic. A checkbox is a value you submit; a
129
+ * switch takes effect the moment it moves. `role="switch"` is what
130
+ * tells a screen reader which of those it is looking at.
131
+ *
132
+ * @param checked — whether it is on.
133
+ * @param onChange — called with the next value; it takes effect at
134
+ * once.
135
+ * @param label — shown beside the switch, and used as its accessible
136
+ * name.
137
+ * @param className — added to the element's classes, beside the one the
138
+ * theme gives it.
139
+ * @param rest — the remaining props, spread onto the button.
140
+ */
141
+ export function Switch({
142
+ checked,
143
+ onChange,
144
+ label,
145
+ className,
146
+ ...rest
147
+ }: SwitchProps) {
148
+ const id = useId();
149
+ return (
150
+ <span className="ui-check">
151
+ <button
152
+ // `rest` goes first so a caller cannot clobber the parts that
153
+ // make this a switch: a caller's own onClick would otherwise
154
+ // replace the toggle, and the control would look fine and do
155
+ // nothing.
156
+ {...rest}
157
+ type="button"
158
+ role="switch"
159
+ aria-checked={checked}
160
+ aria-labelledby={id}
161
+ onClick={() => onChange(!checked)}
162
+ className={cx("ui-switch", className)}
163
+ />
164
+ <span id={id}>{label}</span>
165
+ </span>
166
+ );
167
+ }
168
+
169
+ /**
170
+ * A label, a control, and room for the reason it is wrong.
171
+ *
172
+ * The error slot is the part that gets left out, and a form that
173
+ * rejects input without saying why is the one people abandon. When
174
+ * `htmlFor` is set and the control is a single element, `error` (or
175
+ * `hint`) is wired to it through `aria-describedby`, and an `error`
176
+ * also sets `aria-invalid`, so it is announced rather than merely
177
+ * shown. Without `htmlFor` the note is shown and nothing points at it.
178
+ */
179
+ export interface FieldProps extends HTMLAttributes<HTMLDivElement> {
180
+ /** The label. It is visible, not a placeholder. */
181
+ label: ReactNode;
182
+ /** A sentence under the control, for when nothing is wrong. */
183
+ hint?: ReactNode;
184
+ /** Why the control is wrong. It replaces the hint while it is set. */
185
+ error?: ReactNode;
186
+ /**
187
+ * The id of the control, so the label points at it. Also what wires
188
+ * `error` and `hint` to the control: without it, nothing does.
189
+ */
190
+ htmlFor?: string;
191
+ }
192
+
193
+ /**
194
+ * A label, a control, and room for the reason it is wrong.
195
+ *
196
+ * See {@link FieldProps}. The error slot is the part that gets left
197
+ * out, and a form that rejects input without saying why is the one
198
+ * people abandon.
199
+ *
200
+ * @param label — the label, which is visible rather than a placeholder.
201
+ * @param hint — a sentence under the control, for when nothing is
202
+ * wrong.
203
+ * @param error — why the control is wrong; it replaces the hint while
204
+ * it is set.
205
+ * @param htmlFor — the id of the control, so the label points at it.
206
+ * @param children — the control the label is for.
207
+ * @param className — added to the element's classes, beside the one the
208
+ * theme gives it.
209
+ * @param rest — the remaining props, spread onto the element.
210
+ */
211
+ export function Field({
212
+ label,
213
+ hint,
214
+ error,
215
+ htmlFor,
216
+ children,
217
+ className,
218
+ ...rest
219
+ }: FieldProps) {
220
+ const describedBy = htmlFor ? `${htmlFor}-note` : undefined;
221
+ // Cloned, not merely rendered beside: the control has to point at
222
+ // the note through `aria-describedby` for the note to be announced,
223
+ // and a Field cannot set an attribute on an opaque child any other
224
+ // way.
225
+ const control =
226
+ isValidElement(children) && describedBy && (error || hint)
227
+ ? cloneElement(children as ReactElement<Record<string, unknown>>, {
228
+ "aria-describedby": describedBy,
229
+ ...(error ? { "aria-invalid": true } : {}),
230
+ })
231
+ : children;
232
+ return (
233
+ <div {...rest} className={cx("ui-field", className)}>
234
+ <label className="ui-label" htmlFor={htmlFor}>
235
+ {label}
236
+ </label>
237
+ {control}
238
+ {error ? (
239
+ <span className="ui-error" id={describedBy} role="alert">
240
+ {error}
241
+ </span>
242
+ ) : hint ? (
243
+ <span className="ui-hint" id={describedBy}>
244
+ {hint}
245
+ </span>
246
+ ) : null}
247
+ </div>
248
+ );
249
+ }
package/src/index.ts ADDED
@@ -0,0 +1,149 @@
1
+ /**
2
+ * @ignite-ember/ui-react — the components an extension is allowed to build on.
3
+ *
4
+ * This list is not a guess at what an extension might want. It is
5
+ * what the extensions actually import, measured rather than estimated.
6
+ *
7
+ * Those components were never the whole floor, though. An extension also writes
8
+ * `className="btn btn-primary"` by hand, and so would every
9
+ * other — the primitives existed as CSS and not as an API, which
10
+ * is no autocomplete, no way to learn a variant name short of
11
+ * reading `theme.css`, and nothing to stop `btn-primery` shipping as
12
+ * an invisible bug. `./primitives` closes that: thin typed wrappers
13
+ * over classes the app already uses.
14
+ *
15
+ * They are React, not web components, because most of them are
16
+ * worse as web components: `MarkdownInline` and `RichFences` are a
17
+ * react-markdown pipeline with remark and rehype plugins, and
18
+ * `Tooltip` and `OverflowMenu` are positioning behaviour that wants
19
+ * the light DOM. Rewriting those inside a shadow root would mean
20
+ * maintaining a second implementation of something the app already
21
+ * has — the drift this repository has been bitten by.
22
+ *
23
+ * An extension runs in its own frame and bundles its own React, so
24
+ * consuming a React package costs it nothing it was not already
25
+ * paying.
26
+ *
27
+ * **Everything exported here is under the compatibility floor.**
28
+ * Removing one, renaming it, or changing a prop's meaning is a
29
+ * breaking change under EXTENSIBILITY.md §8. Anything in the app
30
+ * that is not exported here stays ours to change — which is why this
31
+ * file is short and should be argued over before it grows.
32
+ *
33
+ * ## The two rules an export has to pass
34
+ *
35
+ * **It must render outside this repository.** A component whose CSS
36
+ * lives only in ``theme.css`` is unstyled in the one place it is
37
+ * promised for, because an extension runs on its own origin under
38
+ * ``default-src 'self'`` and cannot link ours. ``styled.test.ts``
39
+ * checks every class named here against ``clients/ui/igni-ui.css``
40
+ * and fails on the first one that is missing. This was not a
41
+ * hypothetical: seven components shipped under the floor naming
42
+ * thirty-two classes that no published stylesheet defined, and the
43
+ * reference extension did not catch it because it happens to import
44
+ * only from ``primitives``, which is the half that was covered.
45
+ *
46
+ * **It must not drag the app behind it.** ``boundary.test.ts``
47
+ * fails on an import — static or dynamic — that leaves this
48
+ * directory for anywhere but ``react`` and the published
49
+ * dependencies. ``SpecBlock`` left the floor for this reason: it
50
+ * loaded ``../components/JsonRenderView``, a path that does not
51
+ * exist in a published package, through a dynamic import that no
52
+ * compiler would flag. ``visualizationStream`` left for the same
53
+ * reason — it types its return as the app's ``ChatItem``, which
54
+ * would have put the chat model under the floor by transitivity.
55
+ *
56
+ * Helpers that only their own tests imported — ``closeOpenMarks``,
57
+ * ``dropEchoedTitle``, ``hexOf``, ``hueOf``, ``initialsOf`` — are
58
+ * gone from here too. They were exported to be tested, and tests in
59
+ * this repository can import them from their own module. Putting
60
+ * them here promised them to extensions for two releases.
61
+ */
62
+
63
+ export {
64
+ Actions,
65
+ Badge,
66
+ Button,
67
+ type ButtonProps,
68
+ type ButtonSize,
69
+ type ButtonVariant,
70
+ type BadgeProps,
71
+ Card,
72
+ Chip,
73
+ type ChipProps,
74
+ Dialog,
75
+ type DialogProps,
76
+ Empty,
77
+ type EmptyProps,
78
+ Input,
79
+ type InputProps,
80
+ Item,
81
+ List,
82
+ Row,
83
+ Checkbox,
84
+ type CheckboxProps,
85
+ Code,
86
+ Divider,
87
+ Field,
88
+ type FieldProps,
89
+ Heading,
90
+ type HeadingProps,
91
+ Progress,
92
+ type ProgressProps,
93
+ Radio,
94
+ type RadioProps,
95
+ Select,
96
+ type SelectProps,
97
+ Spinner,
98
+ type SpinnerProps,
99
+ Switch,
100
+ type SwitchProps,
101
+ Table,
102
+ TabPanel,
103
+ type TabPanelProps,
104
+ Tabs,
105
+ type TabsProps,
106
+ Text,
107
+ type TextProps,
108
+ type TextTone,
109
+ Textarea,
110
+ type TextareaProps,
111
+ type Tone,
112
+ Toolbar,
113
+ } from "./primitives.js";
114
+
115
+ export { AppShell, type AppShellProps, Scroll, type ScrollProps } from "./Shell.js";
116
+ export {
117
+ SortableTh,
118
+ type SortableThProps,
119
+ type SortDirection,
120
+ Status,
121
+ type StatusProps,
122
+ } from "./DataTable.js";
123
+ export { ErrorBoundary, type ErrorBoundaryProps } from "./ErrorBoundary.js";
124
+ export {
125
+ Banner,
126
+ type BannerProps,
127
+ type Toast,
128
+ type ToastApi,
129
+ ToastHost,
130
+ type ToastOptions,
131
+ useToast,
132
+ } from "./Toast.js";
133
+ export {
134
+ type Announcer,
135
+ LiveRegion,
136
+ type LiveRegionProps,
137
+ useAnnounce,
138
+ type Urgency,
139
+ } from "./LiveRegion.js";
140
+ export { Markdown, type MarkdownProps } from "./Markdown.js";
141
+ export { MarkdownInline } from "./MarkdownInline.js";
142
+ export { Split, type SplitProps } from "./Split.js";
143
+ export { MenuIcon, type MenuIconName, type MenuIconProps } from "./MenuIcon.js";
144
+ export { Monogram } from "./Monogram.js";
145
+ export { OverflowMenu, type OverflowAction } from "./OverflowMenu.js";
146
+ export { fenceInfo } from "./fenceInfo.js";
147
+ export { MermaidBlock, loadMermaid } from "./Mermaid.js";
148
+ export { Skeleton } from "./Skeleton.js";
149
+ export { Tooltip, type TooltipProps } from "./Tooltip.js";
package/src/layout.tsx ADDED
@@ -0,0 +1,141 @@
1
+ /**
2
+ * The boxes a panel is laid out in: rows, stacks, a toolbar, a card,
3
+ * a selectable item, a table and an empty state.
4
+ *
5
+ * Part of the primitives; see `primitives.tsx`. **Under the
6
+ * compatibility floor.**
7
+ */
8
+
9
+ import type { ButtonHTMLAttributes, HTMLAttributes, ReactNode } from "react";
10
+
11
+ import { cx } from "./cx.js";
12
+
13
+ /**
14
+ * A horizontal run of things, vertically centred.
15
+ *
16
+ * @param className — added to the element's classes, beside the one the
17
+ * theme gives it.
18
+ * @param rest — the remaining props, spread onto the row.
19
+ */
20
+ export function Row({ className, ...rest }: HTMLAttributes<HTMLDivElement>) {
21
+ return <div {...rest} className={cx("ui-row", className)} />;
22
+ }
23
+
24
+ /** A horizontal run of buttons. Separate from `Row` because it is
25
+ * what a reader looks for at the foot of a panel.
26
+ *
27
+ * @param className — added to the element's classes, beside the one the
28
+ * theme gives it.
29
+ * @param rest — the remaining props, spread onto the row of actions.
30
+ */
31
+ export function Actions({
32
+ className,
33
+ ...rest
34
+ }: HTMLAttributes<HTMLDivElement>) {
35
+ return <div {...rest} className={cx("ui-actions", className)} />;
36
+ }
37
+
38
+ /**
39
+ * A vertical stack.
40
+ *
41
+ * @param className — added to the element's classes, beside the one the
42
+ * theme gives it.
43
+ * @param rest — the remaining props, spread onto the list.
44
+ */
45
+ export function List({ className, ...rest }: HTMLAttributes<HTMLDivElement>) {
46
+ return <div {...rest} className={cx("ui-list", className)} />;
47
+ }
48
+
49
+ /**
50
+ * A row of controls at the top of a panel: what the panel is, and what
51
+ * you can do to it.
52
+ *
53
+ * @param className — added to the element's classes, beside the one the
54
+ * theme gives it.
55
+ * @param rest — the remaining props, spread onto the toolbar.
56
+ */
57
+ export function Toolbar({
58
+ className,
59
+ ...rest
60
+ }: HTMLAttributes<HTMLDivElement>) {
61
+ return <div {...rest} className={cx("ui-toolbar", className)} />;
62
+ }
63
+
64
+ /**
65
+ * A surface: background, border, radius, padding.
66
+ *
67
+ * @param className — added to the element's classes, beside the one the
68
+ * theme gives it.
69
+ * @param rest — the remaining props, spread onto the card.
70
+ */
71
+ export function Card({ className, ...rest }: HTMLAttributes<HTMLDivElement>) {
72
+ return <div {...rest} className={cx("ui-card", className)} />;
73
+ }
74
+
75
+ /** One selectable row inside a list. Renders a button, because
76
+ * something clickable that is not a button is a keyboard trap.
77
+ *
78
+ * @param className — added to the element's classes, beside the one the
79
+ * theme gives it.
80
+ * @param rest — the remaining props, spread onto the button.
81
+ */
82
+ export function Item({
83
+ className,
84
+ ...rest
85
+ }: ButtonHTMLAttributes<HTMLButtonElement>) {
86
+ return (
87
+ <button type="button" {...rest} className={cx("ui-item", className)} />
88
+ );
89
+ }
90
+
91
+ /**
92
+ * A table.
93
+ *
94
+ * The class only; the head, the rows and the cells are yours, because
95
+ * a table that decides its own columns is a table you cannot use for
96
+ * anything the app has not already seen.
97
+ *
98
+ * @param className — added to the element's classes, beside the one the
99
+ * theme gives it.
100
+ * @param rest — the remaining props, spread onto the table.
101
+ */
102
+ export function Table({
103
+ className,
104
+ ...rest
105
+ }: HTMLAttributes<HTMLTableElement>) {
106
+ return <table {...rest} className={cx("ui-table", className)} />;
107
+ }
108
+
109
+ /**
110
+ * What to show where there is nothing.
111
+ *
112
+ * Its own component rather than a paragraph with a class, because an
113
+ * empty state that says only "nothing here" is the commonest way a
114
+ * panel wastes the one moment it had the reader's attention. The
115
+ * `action` slot is a nudge to say what to do next.
116
+ */
117
+ export interface EmptyProps extends HTMLAttributes<HTMLDivElement> {
118
+ /** A button, usually: the one thing to do about being empty. */
119
+ action?: ReactNode;
120
+ }
121
+
122
+ /**
123
+ * What to show where there is nothing.
124
+ *
125
+ * See {@link EmptyProps} for why the `action` slot exists.
126
+ *
127
+ * @param children — what to show where there is nothing.
128
+ * @param action — a button, usually: the one thing to do about being
129
+ * empty.
130
+ * @param className — added to the element's classes, beside the one the
131
+ * theme gives it.
132
+ * @param rest — the remaining props, spread onto the element.
133
+ */
134
+ export function Empty({ children, action, className, ...rest }: EmptyProps) {
135
+ return (
136
+ <div {...rest} className={cx("ui-empty", className)}>
137
+ {children}
138
+ {action}
139
+ </div>
140
+ );
141
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Typed wrappers over the CSS primitives.
3
+ *
4
+ * The classes already existed — `btn`, `ui-card`, `ui-row`,
5
+ * `ui-badge` — and an extension could write them by hand. These
6
+ * exist because writing them by hand is not an API: there is no
7
+ * autocomplete, no way to learn the variant names short of reading
8
+ * `theme.css`, and nothing stops `class="btn btn-primery"` from
9
+ * shipping as an invisible bug.
10
+ *
11
+ * Every one of these is a thin mapping from props to class names.
12
+ * They hold no state and make no decisions. That is deliberate: the
13
+ * appearance lives in CSS where the app and the extension share it,
14
+ * and a wrapper that started making layout choices would be a second
15
+ * place for the design to live.
16
+ *
17
+ * `Dialog` is the exception and says so at its own definition — a
18
+ * dialog is behaviour, not just a box.
19
+ *
20
+ * This module is the one name the primitives are imported by. Each
21
+ * group lives in its own file, re-exported here in reading order.
22
+ *
23
+ * **Under the compatibility floor.** A prop here is a promise; see
24
+ * EXTENSIBILITY.md §8.
25
+ */
26
+
27
+ export * from "./controls.js";
28
+ export * from "./layout.js";
29
+ export * from "./Dialog.js";
30
+ export * from "./formControls.js";
31
+ export * from "./progress.js";
32
+ export * from "./Tabs.js";
33
+ export * from "./text.js";
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Work in progress: a spinner for work of unknown length, and a bar
3
+ * for work that can say how far along it is.
4
+ *
5
+ * Part of the primitives; see `primitives.tsx`. **Under the
6
+ * compatibility floor.**
7
+ */
8
+
9
+ import type { HTMLAttributes } from "react";
10
+
11
+ import { cx } from "./cx.js";
12
+
13
+ /**
14
+ * Work whose duration is unknown. `Skeleton` is for known shapes.
15
+ *
16
+ * `label` is required for the same reason `Progress.label` is: a
17
+ * `role="status"` with nothing in it gives a screen reader silence
18
+ * while a sighted user watches something spin.
19
+ */
20
+ export interface SpinnerProps extends HTMLAttributes<HTMLSpanElement> {
21
+ /** Required: a spinner with no name is a live region with nothing in it. */
22
+ label: string;
23
+ }
24
+
25
+ /**
26
+ * Work whose duration is unknown.
27
+ *
28
+ * See {@link SpinnerProps} for why `label` is required.
29
+ *
30
+ * @param label — required: a spinner with no name is a live region with
31
+ * nothing in it.
32
+ * @param className — added to the element's classes, beside the one the
33
+ * theme gives it.
34
+ * @param rest — the remaining props, spread onto the span.
35
+ */
36
+ export function Spinner({ label, className, ...rest }: SpinnerProps) {
37
+ return (
38
+ <span
39
+ {...rest}
40
+ role="status"
41
+ aria-live="polite"
42
+ className={cx("ui-spinner", className)}
43
+ >
44
+ <span className="ui-visually-hidden">{label}</span>
45
+ </span>
46
+ );
47
+ }
48
+
49
+ /** What a {@link Progress} takes. */
50
+ export interface ProgressProps extends HTMLAttributes<HTMLDivElement> {
51
+ /**
52
+ * How far along, against `max`. Omit for indeterminate, which
53
+ * slides rather than sits.
54
+ *
55
+ * A value against a max, as `<progress>` and the ARIA attributes
56
+ * take it, so `value={50}` means half way.
57
+ */
58
+ value?: number;
59
+ /** Defaults to 100. */
60
+ max?: number;
61
+ /** Its name, for a screen reader. */
62
+ label: string;
63
+ }
64
+
65
+ /** Where a determinate bar stands: its clamped value and how full it is. */
66
+ interface Reading {
67
+ /** `value`, clamped to `0..max`. */
68
+ now: number;
69
+ /** How full the bar is, as a percentage. */
70
+ pct: number;
71
+ }
72
+
73
+ /**
74
+ * `value` measured against `max`, or `null` when there is nothing to
75
+ * measure and the bar is indeterminate.
76
+ */
77
+ function measure(value: number | undefined, max: number): Reading | null {
78
+ // NaN is not a measurement: it reads as unknown, like no value.
79
+ if (typeof value !== "number" || Number.isNaN(value)) return null;
80
+ const now = Math.max(0, Math.min(max, value));
81
+ // A `max` of zero or less has nothing to measure against; an empty
82
+ // bar is honest where `0 / 0` would write "NaN%".
83
+ const pct = max > 0 ? (now / max) * 100 : 0;
84
+ return { now, pct };
85
+ }
86
+
87
+ /**
88
+ * A bar that fills.
89
+ *
90
+ * See {@link ProgressProps}. Without a `value` it slides, because a
91
+ * bar that sits still while unknown work is happening is a bar that
92
+ * looks broken.
93
+ *
94
+ * @param value — how far along, against `max`; omit it for
95
+ * indeterminate, which slides rather than sits.
96
+ * @param max — the value that counts as complete, against which `value`
97
+ * is measured; it defaults to 100.
98
+ * @param label — its name, for a screen reader.
99
+ * @param className — added to the element's classes, beside the one the
100
+ * theme gives it.
101
+ * @param rest — the remaining props, spread onto the element.
102
+ */
103
+ export function Progress({
104
+ value,
105
+ max = 100,
106
+ label,
107
+ className,
108
+ ...rest
109
+ }: ProgressProps) {
110
+ const reading = measure(value, max);
111
+ return (
112
+ <div
113
+ {...rest}
114
+ className={cx("ui-progress", className)}
115
+ role="progressbar"
116
+ aria-label={label}
117
+ aria-valuenow={reading?.now}
118
+ aria-valuemin={0}
119
+ aria-valuemax={max}
120
+ aria-valuetext={reading ? `${Math.round(reading.pct)}%` : undefined}
121
+ data-indeterminate={reading === null}
122
+ >
123
+ <div
124
+ className="ui-progress-fill"
125
+ style={reading ? { width: `${reading.pct}%` } : undefined}
126
+ />
127
+ </div>
128
+ );
129
+ }