@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
package/src/Tabs.tsx ADDED
@@ -0,0 +1,194 @@
1
+ /**
2
+ * A tab strip and the panels it controls.
3
+ *
4
+ * Part of the primitives; see `primitives.tsx`. **Under the
5
+ * compatibility floor.**
6
+ */
7
+
8
+ import type { HTMLAttributes, KeyboardEvent, ReactNode } from "react";
9
+ import { useEffect, useId, useRef } from "react";
10
+
11
+ import { cx } from "./cx.js";
12
+
13
+ /**
14
+ * The index a navigation key moves the selection to, from tab `i` of
15
+ * `count`, or `null` for a key the strip does not handle. The arrows
16
+ * wrap at either end.
17
+ */
18
+ function tabAfterKey(key: string, i: number, count: number): number | null {
19
+ switch (key) {
20
+ case "ArrowRight":
21
+ return (i + 1) % count;
22
+ case "ArrowLeft":
23
+ return (i - 1 + count) % count;
24
+ case "Home":
25
+ return 0;
26
+ case "End":
27
+ return count - 1;
28
+ default:
29
+ return null;
30
+ }
31
+ }
32
+
33
+ /** What a {@link Tabs} takes. */
34
+ export interface TabsProps extends Omit<
35
+ HTMLAttributes<HTMLDivElement>,
36
+ "onChange"
37
+ > {
38
+ /** The tabs. The `id` is what {@link TabPanel}s match on. */
39
+ tabs: { id: string; label: ReactNode }[];
40
+ /** Which tab is showing. */
41
+ active: string;
42
+ /** Called with the id of the tab the reader chose. */
43
+ onChange: (id: string) => void;
44
+ /** The strip's name, for a screen reader. */
45
+ label: string;
46
+ /**
47
+ * The id prefix shared with this strip's {@link TabPanel}s.
48
+ *
49
+ * Optional, and generated when it is absent — but a `TabPanel`
50
+ * *requires* one, so a caller that renders panels passes the same
51
+ * `base` to both: a generated one is never visible to the panels.
52
+ */
53
+ base?: string;
54
+ }
55
+
56
+ /**
57
+ * Tabs with the arrow keys wired, because a tab strip that only
58
+ * responds to clicks is a tab strip half the people cannot use.
59
+ *
60
+ * @param tabs — the tabs; the `id` is what the panels match on.
61
+ * @param active — which tab is showing.
62
+ * @param onChange — called with the id of the tab the reader chose.
63
+ * @param label — the strip's name, for a screen reader.
64
+ * @param base — the id prefix shared with this strip's panels; one is
65
+ * generated when it is left out, and the panels need the same one.
66
+ * @param className — added to the element's classes, beside the one the
67
+ * theme gives it.
68
+ * @param rest — the remaining props, spread onto the element.
69
+ */
70
+ export function Tabs({
71
+ tabs,
72
+ active,
73
+ onChange,
74
+ label,
75
+ base: givenBase,
76
+ className,
77
+ ...rest
78
+ }: TabsProps) {
79
+ // Hooks run unconditionally; the generated id is simply unused
80
+ // when a caller supplied one.
81
+ const generated = useId();
82
+ const base = givenBase ?? generated;
83
+ const strip = useRef<HTMLDivElement | null>(null);
84
+
85
+ // Focus follows selection, as the ARIA practices require: otherwise
86
+ // the focus ring sits on a tab that is now tabIndex={-1} while a
87
+ // different one is selected, and the next Tab leaves the strip from
88
+ // somewhere the reader cannot see.
89
+ useEffect(() => {
90
+ const el = strip.current?.querySelector<HTMLElement>(
91
+ '[aria-selected="true"]',
92
+ );
93
+ if (el && strip.current?.contains(document.activeElement)) el.focus();
94
+ }, [active]);
95
+
96
+ const onKeyDown = (event: KeyboardEvent) => {
97
+ if (tabs.length === 0) return;
98
+ const i = Math.max(
99
+ tabs.findIndex((t) => t.id === active),
100
+ 0,
101
+ );
102
+ const next = tabAfterKey(event.key, i, tabs.length);
103
+ if (next === null) return;
104
+ event.preventDefault();
105
+ onChange(tabs[next].id);
106
+ };
107
+
108
+ return (
109
+ <div
110
+ {...rest}
111
+ ref={strip}
112
+ role="tablist"
113
+ aria-label={label}
114
+ aria-orientation="horizontal"
115
+ className={cx("ui-tabs", className)}
116
+ onKeyDown={onKeyDown}
117
+ >
118
+ {tabs.map((tab) => (
119
+ <button
120
+ key={tab.id}
121
+ // Real DOM ids, so a panel can point back with
122
+ // aria-labelledby and this one can point at it. Without
123
+ // them a screen reader announces "tab, 1 of 2" controlling
124
+ // nothing.
125
+ id={`${base}-${tab.id}`}
126
+ aria-controls={`${base}-${tab.id}-panel`}
127
+ type="button"
128
+ role="tab"
129
+ aria-selected={tab.id === active}
130
+ tabIndex={tab.id === active ? 0 : -1}
131
+ className="ui-tab"
132
+ onClick={() => onChange(tab.id)}
133
+ >
134
+ {tab.label}
135
+ </button>
136
+ ))}
137
+ </div>
138
+ );
139
+ }
140
+
141
+ /**
142
+ * The panel a tab controls. Needs the same `base` the strip used.
143
+ *
144
+ * `Tabs` without it is half the ARIA pattern: a strip that announces
145
+ * it controls something needs something for it to control.
146
+ */
147
+ export interface TabPanelProps extends HTMLAttributes<HTMLDivElement> {
148
+ /** The id prefix shared with its {@link Tabs}, so the two agree. */
149
+ base: string;
150
+ /** Which tab this panel belongs to. */
151
+ id: string;
152
+ /** Which tab is showing. The panel renders only when they match. */
153
+ active: string;
154
+ }
155
+
156
+ /**
157
+ * The panel a tab controls.
158
+ *
159
+ * See {@link TabPanelProps}. It renders nothing at all when its tab is
160
+ * not the active one, so the content of a panel that is not showing
161
+ * is not in the page.
162
+ *
163
+ * @param base — the id prefix shared with its tabs, so the two agree.
164
+ * @param id — which tab this panel belongs to.
165
+ * @param active — which tab is showing; the panel renders only when
166
+ * they match.
167
+ * @param children — the content of the panel, shown while its tab is
168
+ * the active one.
169
+ * @param className — the panel's own class; the theme gives it
170
+ * none.
171
+ * @param rest — the remaining props, spread onto the element.
172
+ */
173
+ export function TabPanel({
174
+ base,
175
+ id,
176
+ active,
177
+ children,
178
+ className,
179
+ ...rest
180
+ }: TabPanelProps) {
181
+ if (id !== active) return null;
182
+ return (
183
+ <div
184
+ {...rest}
185
+ id={`${base}-${id}-panel`}
186
+ role="tabpanel"
187
+ aria-labelledby={`${base}-${id}`}
188
+ tabIndex={0}
189
+ className={className}
190
+ >
191
+ {children}
192
+ </div>
193
+ );
194
+ }
package/src/Toast.tsx CHANGED
@@ -34,7 +34,7 @@ import {
34
34
  type ReactNode,
35
35
  } from "react";
36
36
 
37
- import type { Tone } from "./primitives.js";
37
+ import type { Tone } from "./controls.js";
38
38
 
39
39
  function cx(...parts: (string | false | null | undefined)[]): string {
40
40
  return parts.filter(Boolean).join(" ");
@@ -86,6 +86,8 @@ let counter = 0;
86
86
  *
87
87
  * Renders the stack itself, so there is nothing to place and no way
88
88
  * to forget to place it.
89
+ *
90
+ * @param children — the part of the app that raises toasts.
89
91
  */
90
92
  export function ToastHost({ children }: { children: ReactNode }) {
91
93
  const [toasts, setToasts] = useState<Toast[]>([]);
@@ -227,6 +229,15 @@ export interface BannerProps extends HTMLAttributes<HTMLDivElement> {
227
229
  * Not a toast: a toast is about something that just happened and
228
230
  * goes away, a banner is about a state — offline, read-only, licence
229
231
  * expiring — and stays until the state does not.
232
+ *
233
+ * @param tone — how loud it is: `neutral` for a state nothing is wrong
234
+ * with, and the three that mean something.
235
+ * @param onDismiss — asked to dismiss the banner; the affordance
236
+ * appears when this is given.
237
+ * @param children — the message the banner says.
238
+ * @param className — added to the element's classes, beside the one the
239
+ * theme gives it.
240
+ * @param rest — the remaining props, spread onto the element.
230
241
  */
231
242
  export function Banner({
232
243
  tone = "neutral",
package/src/Tooltip.tsx CHANGED
@@ -9,8 +9,10 @@
9
9
  * somebody on a keyboard. That is not an explanation, it is a
10
10
  * consolation prize.
11
11
  *
12
- * **It replaces ``title``, it does not sit beside it.** Leaving both
13
- * on gives two tooltips saying the same thing a second apart.
12
+ * **It replaces ``title``, it does not sit beside it.** A ``title`` left
13
+ * on the control would give two tooltips saying the same thing a second
14
+ * apart, so the Tooltip takes it off the control while it is in charge,
15
+ * and says it itself when it was given no ``text``.
14
16
  *
15
17
  * **Focus shows it immediately; hover waits.** A pointer crossing a
16
18
  * row of buttons on its way somewhere else should not leave a trail
@@ -38,7 +40,10 @@ interface At {
38
40
 
39
41
  /** What a {@link Tooltip} takes. */
40
42
  export interface TooltipProps {
41
- /** The word. Nothing is rendered when it is empty. */
43
+ /**
44
+ * The word. When it is empty, the control's own `title` is used
45
+ * instead; nothing is rendered when there is neither.
46
+ */
42
47
  text: string;
43
48
  /** The control the word is about. */
44
49
  children: React.ReactNode;
@@ -47,16 +52,36 @@ export interface TooltipProps {
47
52
  /**
48
53
  * What an icon means, on hover and on focus.
49
54
  *
50
- * See the note at the top of this file. It replaces the browser's own
51
- * `title` rather than sitting beside it.
55
+ * It replaces the browser's own `title` rather than sitting beside it:
56
+ * a `title` on the control is removed from it, so the browser never
57
+ * shows a second tooltip, and is the word when `text` is empty. Focus
58
+ * shows it at once; hover waits 350 ms.
59
+ *
60
+ * @param text — the word; when it is empty the control's `title` is
61
+ * used, and nothing is rendered when there is neither.
62
+ * @param children — the control the word is about.
52
63
  */
53
64
  export function Tooltip({ text, children }: TooltipProps) {
65
+ const [fromTitle, setFromTitle] = useState("");
66
+ const label = text || fromTitle;
54
67
  const wrap = useRef<HTMLSpanElement>(null);
55
68
  const bubble = useRef<HTMLDivElement>(null);
56
69
  const timer = useRef<number | null>(null);
57
70
  const [at, setAt] = useState<At | null>(null);
58
71
  const id = useId();
59
72
 
73
+ // The control's own ``title`` is taken off it, and kept as the word
74
+ // for when none was given. Run after every render, because React
75
+ // writes the attribute back whenever the control's ``title`` prop
76
+ // changes.
77
+ useEffect(() => {
78
+ const control = wrap.current?.firstElementChild;
79
+ const title = control?.getAttribute("title");
80
+ if (title === null || title === undefined) return;
81
+ control?.removeAttribute("title");
82
+ setFromTitle(title);
83
+ });
84
+
60
85
  const hide = useCallback(() => {
61
86
  if (timer.current !== null) window.clearTimeout(timer.current);
62
87
  timer.current = null;
@@ -79,7 +104,7 @@ export function Tooltip({ text, children }: TooltipProps) {
79
104
 
80
105
  const show = useCallback(
81
106
  (immediately: boolean) => {
82
- if (!text) return;
107
+ if (!label) return;
83
108
  if (timer.current !== null) window.clearTimeout(timer.current);
84
109
  if (immediately) {
85
110
  place();
@@ -87,7 +112,7 @@ export function Tooltip({ text, children }: TooltipProps) {
87
112
  }
88
113
  timer.current = window.setTimeout(place, DWELL_MS);
89
114
  },
90
- [text, place],
115
+ [label, place],
91
116
  );
92
117
 
93
118
  useEffect(
@@ -179,7 +204,7 @@ export function Tooltip({ text, children }: TooltipProps) {
179
204
  transform: `translate(-50%, ${at.below ? "0" : "-100%"})`,
180
205
  }}
181
206
  >
182
- {text}
207
+ {label}
183
208
  </div>,
184
209
  document.body,
185
210
  )}
@@ -0,0 +1,159 @@
1
+ /**
2
+ * The controls a reader acts on or scans past: a button, a text field,
3
+ * a chip and a badge, and the tone the last two share.
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
+ } from "react";
14
+
15
+ import { cx } from "./cx.js";
16
+
17
+ /**
18
+ * How a button reads.
19
+ *
20
+ * `default` is a plain button, `primary` is the one action on the
21
+ * panel, `danger` is the one that destroys something, `warn` says the
22
+ * action is not what it sounds like, and `quiet` is a button that
23
+ * should not be the first thing the eye lands on.
24
+ */
25
+ export type ButtonVariant = "default" | "primary" | "danger" | "warn" | "quiet";
26
+
27
+ /** `md` unless the row is dense, in which case `sm` or `xs`. */
28
+ export type ButtonSize = "md" | "sm" | "xs";
29
+
30
+ /** What a {@link Button} takes. */
31
+ export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
32
+ /** How it reads. */
33
+ variant?: ButtonVariant;
34
+ /** Its size. */
35
+ size?: ButtonSize;
36
+ }
37
+
38
+ /**
39
+ * A button.
40
+ *
41
+ * The variant is a prop rather than a class name you spell:
42
+ * `btn-primery` is a typo that renders as a plain button and looks
43
+ * like nothing at all, which is exactly why the name is one the
44
+ * compiler checks.
45
+ *
46
+ * @param variant — how it reads: plain, the one action on the panel,
47
+ * the one that destroys something, a warning, or one that should not
48
+ * be the first thing the eye lands on.
49
+ * @param size — its size: `md` unless the row is dense, in which case
50
+ * `sm` or `xs`.
51
+ * @param className — added to the element's classes, beside the one the
52
+ * theme gives it.
53
+ * @param rest — the remaining props, spread onto the button.
54
+ */
55
+ export function Button({
56
+ variant = "default",
57
+ size = "md",
58
+ className,
59
+ ...rest
60
+ }: ButtonProps) {
61
+ return (
62
+ <button
63
+ type="button"
64
+ {...rest}
65
+ className={cx(
66
+ "btn",
67
+ variant !== "default" && `btn-${variant}`,
68
+ size !== "md" && `btn-${size}`,
69
+ className,
70
+ )}
71
+ />
72
+ );
73
+ }
74
+
75
+ /** What an {@link Input} takes. */
76
+ export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {}
77
+
78
+ /**
79
+ * A single-line text field.
80
+ *
81
+ * @param className — added to the element's classes, beside the one the
82
+ * theme gives it.
83
+ * @param rest — the remaining props, spread onto the input.
84
+ */
85
+ export function Input({ className, ...rest }: InputProps) {
86
+ return <input {...rest} className={cx("panel-input", className)} />;
87
+ }
88
+
89
+ /**
90
+ * How loud a status is.
91
+ *
92
+ * `neutral` for a state nothing is wrong with, and the three that
93
+ * mean something.
94
+ */
95
+ export type Tone = "neutral" | "success" | "warning" | "danger";
96
+
97
+ /**
98
+ * A tag the reader can scan past.
99
+ *
100
+ * Bordered, pill-shaped, muted, `--text-sm`. Use it for a filter, a
101
+ * label, a piece of metadata — something that describes the row it
102
+ * sits on.
103
+ *
104
+ * `Chip` and `Badge` take the same props and are not
105
+ * interchangeable. If the thing you are showing is a *state* that
106
+ * changes — ready, failed, three unread — it is a {@link Badge},
107
+ * which is filled by tone and bold so it is noticed. If it is a fact
108
+ * about the thing, it is a `Chip`.
109
+ */
110
+ export interface ChipProps extends HTMLAttributes<HTMLSpanElement> {
111
+ /** How loud it is. */
112
+ tone?: Tone;
113
+ }
114
+
115
+ /**
116
+ * A tag the reader can scan past. See {@link ChipProps} for when to
117
+ * reach for a chip and when for a badge.
118
+ *
119
+ * @param tone — how loud it is: `neutral` for a state nothing is wrong
120
+ * with, and the three that mean something.
121
+ * @param className — added to the element's classes, beside the one the
122
+ * theme gives it.
123
+ * @param rest — the remaining props, spread onto the span.
124
+ */
125
+ export function Chip({ tone = "neutral", className, ...rest }: ChipProps) {
126
+ return <span {...rest} data-tone={tone} className={cx("chip", className)} />;
127
+ }
128
+
129
+ /**
130
+ * A state the reader is meant to notice.
131
+ *
132
+ * Filled by tone, bold, `--text-xs`, no border. See {@link ChipProps}
133
+ * for which of the two to reach for.
134
+ *
135
+ * The tone is colour, and colour alone is not a message: put the
136
+ * state in the text too. "Failed" in a danger badge survives being
137
+ * read aloud and being looked at by somebody who cannot tell it from
138
+ * the success one; an empty red badge does not.
139
+ */
140
+ export interface BadgeProps extends HTMLAttributes<HTMLSpanElement> {
141
+ /** How loud it is. */
142
+ tone?: Tone;
143
+ }
144
+
145
+ /**
146
+ * A state the reader is meant to notice. See {@link BadgeProps} for
147
+ * what the tone does and does not say.
148
+ *
149
+ * @param tone — how loud it is: `neutral` for a state nothing is wrong
150
+ * with, and the three that mean something.
151
+ * @param className — added to the element's classes, beside the one the
152
+ * theme gives it.
153
+ * @param rest — the remaining props, spread onto the span.
154
+ */
155
+ export function Badge({ tone = "neutral", className, ...rest }: BadgeProps) {
156
+ return (
157
+ <span {...rest} data-tone={tone} className={cx("ui-badge", className)} />
158
+ );
159
+ }
package/src/fenceInfo.ts CHANGED
@@ -10,7 +10,7 @@ import { isValidElement } from "react";
10
10
 
11
11
  /** The language on a fenced block, and the block's source. */
12
12
  export interface Fence {
13
- /** The language, lower-cased. `mermaid`, `ts`, `python`. */
13
+ /** The language, lower-cased. `mermaid`, `ts`, `python`, `c++`. */
14
14
  lang: string;
15
15
  /** The text inside the fence. */
16
16
  source: string;
@@ -21,12 +21,15 @@ export interface Fence {
21
21
  *
22
22
  * Null when the child is not a code element, or carries no
23
23
  * `language-` class — an unfenced block, or a fence with no language.
24
+ *
25
+ * @param children — the `<pre>` a fenced block renders as; its `<code>`
26
+ * child carries the language class.
24
27
  */
25
28
  export function fenceInfo(children: ReactNode): Fence | null {
26
29
  const only = Array.isArray(children) ? children[0] : children;
27
30
  if (!isValidElement(only)) return null;
28
31
  const props = only.props as { className?: string; children?: ReactNode };
29
- const match = /\blanguage-([\w-]+)\b/.exec(props.className ?? "");
32
+ const match = /\blanguage-([\w+#.-]+)/.exec(props.className ?? "");
30
33
  if (!match) return null;
31
34
  const source = typeof props.children === "string" ? props.children : "";
32
35
  return { lang: match[1].toLowerCase(), source: source.replace(/\n$/, "") };