@ignite-ember/ui-react 0.2.0 → 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 (127) hide show
  1. package/NOTICE +1 -1
  2. package/README.md +56 -13
  3. package/dist/CopySource.d.ts.map +1 -1
  4. package/dist/CopySource.js +16 -2
  5. package/dist/CopySource.js.map +1 -1
  6. package/dist/DataTable.d.ts +17 -1
  7. package/dist/DataTable.d.ts.map +1 -1
  8. package/dist/DataTable.js +17 -1
  9. package/dist/DataTable.js.map +1 -1
  10. package/dist/Dialog.d.ts +41 -0
  11. package/dist/Dialog.d.ts.map +1 -0
  12. package/dist/Dialog.js +94 -0
  13. package/dist/Dialog.js.map +1 -0
  14. package/dist/ErrorBoundary.d.ts +31 -2
  15. package/dist/ErrorBoundary.d.ts.map +1 -1
  16. package/dist/ErrorBoundary.js +38 -4
  17. package/dist/ErrorBoundary.js.map +1 -1
  18. package/dist/LiveRegion.d.ts +7 -1
  19. package/dist/LiveRegion.d.ts.map +1 -1
  20. package/dist/LiveRegion.js +7 -1
  21. package/dist/LiveRegion.js.map +1 -1
  22. package/dist/Markdown.d.ts +4 -0
  23. package/dist/Markdown.d.ts.map +1 -1
  24. package/dist/Markdown.js +4 -0
  25. package/dist/Markdown.js.map +1 -1
  26. package/dist/MarkdownInline.d.ts +13 -4
  27. package/dist/MarkdownInline.d.ts.map +1 -1
  28. package/dist/MarkdownInline.js +20 -5
  29. package/dist/MarkdownInline.js.map +1 -1
  30. package/dist/MenuIcon.d.ts +10 -4
  31. package/dist/MenuIcon.d.ts.map +1 -1
  32. package/dist/MenuIcon.js +8 -2
  33. package/dist/MenuIcon.js.map +1 -1
  34. package/dist/Mermaid.d.ts +2 -0
  35. package/dist/Mermaid.d.ts.map +1 -1
  36. package/dist/Mermaid.js +2 -0
  37. package/dist/Mermaid.js.map +1 -1
  38. package/dist/Monogram.d.ts +7 -3
  39. package/dist/Monogram.d.ts.map +1 -1
  40. package/dist/Monogram.js +14 -6
  41. package/dist/Monogram.js.map +1 -1
  42. package/dist/OverflowMenu.d.ts +6 -1
  43. package/dist/OverflowMenu.d.ts.map +1 -1
  44. package/dist/OverflowMenu.js +10 -2
  45. package/dist/OverflowMenu.js.map +1 -1
  46. package/dist/Shell.d.ts +13 -0
  47. package/dist/Shell.d.ts.map +1 -1
  48. package/dist/Shell.js +13 -0
  49. package/dist/Shell.js.map +1 -1
  50. package/dist/Skeleton.d.ts +30 -0
  51. package/dist/Skeleton.d.ts.map +1 -1
  52. package/dist/Skeleton.js +30 -0
  53. package/dist/Skeleton.js.map +1 -1
  54. package/dist/Split.d.ts +24 -5
  55. package/dist/Split.d.ts.map +1 -1
  56. package/dist/Split.js +27 -4
  57. package/dist/Split.js.map +1 -1
  58. package/dist/Tabs.d.ts +77 -0
  59. package/dist/Tabs.d.ts.map +1 -0
  60. package/dist/Tabs.js +91 -0
  61. package/dist/Tabs.js.map +1 -0
  62. package/dist/Toast.d.ts +12 -1
  63. package/dist/Toast.d.ts.map +1 -1
  64. package/dist/Toast.js +11 -0
  65. package/dist/Toast.js.map +1 -1
  66. package/dist/Tooltip.d.ts +12 -3
  67. package/dist/Tooltip.d.ts.map +1 -1
  68. package/dist/Tooltip.js +29 -7
  69. package/dist/Tooltip.js.map +1 -1
  70. package/dist/controls.d.ts +117 -0
  71. package/dist/controls.d.ts.map +1 -0
  72. package/dist/controls.js +59 -0
  73. package/dist/controls.js.map +1 -0
  74. package/dist/fenceInfo.d.ts +4 -1
  75. package/dist/fenceInfo.d.ts.map +1 -1
  76. package/dist/fenceInfo.js +4 -1
  77. package/dist/fenceInfo.js.map +1 -1
  78. package/dist/formControls.d.ts +143 -0
  79. package/dist/formControls.d.ts.map +1 -0
  80. package/dist/formControls.js +108 -0
  81. package/dist/formControls.js.map +1 -0
  82. package/dist/index.d.ts +5 -9
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +5 -9
  85. package/dist/index.js.map +1 -1
  86. package/dist/layout.d.ts +95 -0
  87. package/dist/layout.d.ts.map +1 -0
  88. package/dist/layout.js +93 -0
  89. package/dist/layout.js.map +1 -0
  90. package/dist/primitives.d.ts +10 -360
  91. package/dist/primitives.d.ts.map +1 -1
  92. package/dist/primitives.js +31 -338
  93. package/dist/primitives.js.map +1 -1
  94. package/dist/progress.d.ts +64 -0
  95. package/dist/progress.d.ts.map +1 -0
  96. package/dist/progress.js +51 -0
  97. package/dist/progress.js.map +1 -0
  98. package/dist/text.d.ts +63 -0
  99. package/dist/text.d.ts.map +1 -0
  100. package/dist/text.js +61 -0
  101. package/dist/text.js.map +1 -0
  102. package/package.json +4 -4
  103. package/src/CopySource.tsx +17 -2
  104. package/src/DataTable.tsx +17 -1
  105. package/src/Dialog.tsx +158 -0
  106. package/src/ErrorBoundary.tsx +39 -4
  107. package/src/LiveRegion.tsx +7 -1
  108. package/src/Markdown.tsx +4 -0
  109. package/src/MarkdownInline.tsx +20 -7
  110. package/src/MenuIcon.tsx +10 -4
  111. package/src/Mermaid.tsx +2 -0
  112. package/src/Monogram.tsx +14 -5
  113. package/src/OverflowMenu.tsx +9 -2
  114. package/src/Shell.tsx +13 -0
  115. package/src/Skeleton.tsx +30 -0
  116. package/src/Split.tsx +32 -7
  117. package/src/Tabs.tsx +194 -0
  118. package/src/Toast.tsx +12 -1
  119. package/src/Tooltip.tsx +33 -8
  120. package/src/controls.tsx +159 -0
  121. package/src/fenceInfo.ts +5 -2
  122. package/src/formControls.tsx +249 -0
  123. package/src/index.ts +5 -9
  124. package/src/layout.tsx +141 -0
  125. package/src/primitives.tsx +10 -864
  126. package/src/progress.tsx +129 -0
  127. 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 CHANGED
@@ -2,27 +2,23 @@
2
2
  * @ignite-ember/ui-react — the components an extension is allowed to build on.
3
3
  *
4
4
  * This list is not a guess at what an extension might want. It is
5
- * what the first two extensions actually import. CodeIndex needs
6
- * none of it — its only app dependency is the client type, which is
7
- * why porting its panel behind the bridge cost one line. Artifacts
8
- * is 7,737 lines and imports exactly seven of the app's components,
9
- * measured rather than estimated.
5
+ * what the extensions actually import, measured rather than estimated.
10
6
  *
11
- * Seven was never the whole floor, though. Artifacts also writes
7
+ * Those components were never the whole floor, though. An extension also writes
12
8
  * `className="btn btn-primary"` by hand, and so would every
13
- * extension — the primitives existed as CSS and not as an API, which
9
+ * other — the primitives existed as CSS and not as an API, which
14
10
  * is no autocomplete, no way to learn a variant name short of
15
11
  * reading `theme.css`, and nothing to stop `btn-primery` shipping as
16
12
  * an invisible bug. `./primitives` closes that: thin typed wrappers
17
13
  * over classes the app already uses.
18
14
  *
19
- * They are React, not web components, because six of the seven are
15
+ * They are React, not web components, because most of them are
20
16
  * worse as web components: `MarkdownInline` and `RichFences` are a
21
17
  * react-markdown pipeline with remark and rehype plugins, and
22
18
  * `Tooltip` and `OverflowMenu` are positioning behaviour that wants
23
19
  * the light DOM. Rewriting those inside a shadow root would mean
24
20
  * maintaining a second implementation of something the app already
25
- * has — the drift this repository has been bitten by twice.
21
+ * has — the drift this repository has been bitten by.
26
22
  *
27
23
  * An extension runs in its own frame and bundles its own React, so
28
24
  * consuming a React package costs it nothing it was not already
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
+ }