@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,85 @@
1
+ /**
2
+ * Two panes and a rule you can move.
3
+ *
4
+ * Both extensions built against this floor wanted one and neither
5
+ * could have it: `ColumnHandle` is 180 lines in the app, does exactly
6
+ * this, and was not published. `examples/release-notes` hand-rolls
7
+ * the grid, the pointer capture, the clamping and the separator, and
8
+ * says so in its README. Every two-pane extension would write that
9
+ * again, differently — which is how two panels in one product end up
10
+ * resizing differently.
11
+ *
12
+ * **It drives a CSS variable, not React state.** A `pointermove`
13
+ * handler that re-rendered would re-render the whole document on
14
+ * every frame of the drag, and would stutter on exactly the documents
15
+ * busy enough to be worth resizing. Writing the variable lets the
16
+ * browser reflow and leaves the tree alone.
17
+ *
18
+ * **It does not remember the width**, and that is the deliberate
19
+ * difference from the app's version. An extension is served from an
20
+ * ephemeral port, a port is part of an origin, so its `localStorage`
21
+ * is wiped whenever the backend restarts — persisting there would be
22
+ * a promise this cannot keep. `onResize` hands the width back
23
+ * instead, and an extension that wants it remembered puts it
24
+ * somewhere that survives: `bridge.setLocation`, or its own backend.
25
+ *
26
+ * The other difference is `aria-valuenow`. A focusable `separator`
27
+ * that never says where it is tells a screen-reader user that
28
+ * something is adjustable and not what it is adjusted to.
29
+ */
30
+ import { type HTMLAttributes, type ReactNode } from "react";
31
+ /** What a {@link Split} takes. */
32
+ export interface SplitProps extends Omit<HTMLAttributes<HTMLDivElement>, "onResize"> {
33
+ /** The fixed-width pane. */
34
+ aside: ReactNode;
35
+ /** The pane that takes what is left. */
36
+ children: ReactNode;
37
+ /** Which side `aside` is on. Defaults to the left. */
38
+ side?: "start" | "end";
39
+ /** Starting width of `aside`, in pixels. */
40
+ defaultWidth?: number;
41
+ /** The narrowest `aside` may be, in pixels. */
42
+ min?: number;
43
+ /** The widest `aside` may be, in pixels — and never more than 60% of the window. */
44
+ max?: number;
45
+ /**
46
+ * Said to a screen reader, and shown on hover.
47
+ *
48
+ * Required: "separator" is what the role already announces, and a
49
+ * page with two of them needs to say which is which.
50
+ */
51
+ label: string;
52
+ /**
53
+ * The width changed. Called on release, on each keypress and on a
54
+ * double-click back to `defaultWidth`, not on every pointer move.
55
+ *
56
+ * A handler that fires sixty times a second is a handler somebody
57
+ * writes a round trip into.
58
+ */
59
+ onResize?: (width: number) => void;
60
+ }
61
+ /**
62
+ * Two panes and a rule you can move.
63
+ *
64
+ * It drives a CSS variable rather than React state, and it does not
65
+ * remember the width: `onResize` hands the width back, and an
66
+ * extension that wants it kept stores it somewhere that survives a
67
+ * restart (`bridge.setLocation`, or its own backend).
68
+ *
69
+ * @param aside — the fixed-width pane.
70
+ * @param children — the pane that takes what is left.
71
+ * @param side — which side `aside` is on; the left by default.
72
+ * @param defaultWidth — the starting width of `aside`, in pixels.
73
+ * @param min — the narrowest `aside` may be, in pixels.
74
+ * @param max — the widest `aside` may be, in pixels, and never more
75
+ * than 60% of the window.
76
+ * @param label — said to a screen reader, and shown on hover.
77
+ * @param onResize — the width changed; called on release, on each
78
+ * keypress and on a double-click back to `defaultWidth`, not on every
79
+ * pointer move.
80
+ * @param className — added to the element's classes, beside the one the
81
+ * theme gives it.
82
+ * @param rest — the remaining props, spread onto the element.
83
+ */
84
+ export declare function Split({ aside, children, side, defaultWidth, min, max, label, onResize, className, ...rest }: SplitProps): import("react").JSX.Element;
85
+ //# sourceMappingURL=Split.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Split.d.ts","sourceRoot":"","sources":["../src/Split.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,EAML,KAAK,cAAc,EAGnB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAiBf,kCAAkC;AAClC,MAAM,WAAW,UAAW,SAAQ,IAAI,CACtC,cAAc,CAAC,cAAc,CAAC,EAC9B,UAAU,CACX;IACC,4BAA4B;IAC5B,KAAK,EAAE,SAAS,CAAC;IACjB,wCAAwC;IACxC,QAAQ,EAAE,SAAS,CAAC;IACpB,sDAAsD;IACtD,IAAI,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IACvB,4CAA4C;IAC5C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+CAA+C;IAC/C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,oFAAoF;IACpF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,KAAK,CAAC,EACpB,KAAK,EACL,QAAQ,EACR,IAAc,EACd,YAAkB,EAClB,GAAS,EACT,GAAS,EACT,KAAK,EACL,QAAQ,EACR,SAAS,EACT,GAAG,IAAI,EACR,EAAE,UAAU,+BA8IZ"}
package/dist/Split.js ADDED
@@ -0,0 +1,156 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Two panes and a rule you can move.
4
+ *
5
+ * Both extensions built against this floor wanted one and neither
6
+ * could have it: `ColumnHandle` is 180 lines in the app, does exactly
7
+ * this, and was not published. `examples/release-notes` hand-rolls
8
+ * the grid, the pointer capture, the clamping and the separator, and
9
+ * says so in its README. Every two-pane extension would write that
10
+ * again, differently — which is how two panels in one product end up
11
+ * resizing differently.
12
+ *
13
+ * **It drives a CSS variable, not React state.** A `pointermove`
14
+ * handler that re-rendered would re-render the whole document on
15
+ * every frame of the drag, and would stutter on exactly the documents
16
+ * busy enough to be worth resizing. Writing the variable lets the
17
+ * browser reflow and leaves the tree alone.
18
+ *
19
+ * **It does not remember the width**, and that is the deliberate
20
+ * difference from the app's version. An extension is served from an
21
+ * ephemeral port, a port is part of an origin, so its `localStorage`
22
+ * is wiped whenever the backend restarts — persisting there would be
23
+ * a promise this cannot keep. `onResize` hands the width back
24
+ * instead, and an extension that wants it remembered puts it
25
+ * somewhere that survives: `bridge.setLocation`, or its own backend.
26
+ *
27
+ * The other difference is `aria-valuenow`. A focusable `separator`
28
+ * that never says where it is tells a screen-reader user that
29
+ * something is adjustable and not what it is adjusted to.
30
+ */
31
+ import { useCallback, useId, useRef, useState, } from "react";
32
+ import { cx } from "./cx.js";
33
+ /** Keyboard step, and the larger one with Shift held. */
34
+ const STEP = 12;
35
+ const BIG_STEP = 48;
36
+ /**
37
+ * How much of the window one pane may take, whatever `max` says.
38
+ *
39
+ * A pane dragged wide on a narrow laptop otherwise leaves the other
40
+ * a few characters across — a state the reader has to drag their way
41
+ * back out of.
42
+ */
43
+ const MOST_OF_WINDOW = 0.6;
44
+ /**
45
+ * Two panes and a rule you can move.
46
+ *
47
+ * It drives a CSS variable rather than React state, and it does not
48
+ * remember the width: `onResize` hands the width back, and an
49
+ * extension that wants it kept stores it somewhere that survives a
50
+ * restart (`bridge.setLocation`, or its own backend).
51
+ *
52
+ * @param aside — the fixed-width pane.
53
+ * @param children — the pane that takes what is left.
54
+ * @param side — which side `aside` is on; the left by default.
55
+ * @param defaultWidth — the starting width of `aside`, in pixels.
56
+ * @param min — the narrowest `aside` may be, in pixels.
57
+ * @param max — the widest `aside` may be, in pixels, and never more
58
+ * than 60% of the window.
59
+ * @param label — said to a screen reader, and shown on hover.
60
+ * @param onResize — the width changed; called on release, on each
61
+ * keypress and on a double-click back to `defaultWidth`, not on every
62
+ * pointer move.
63
+ * @param className — added to the element's classes, beside the one the
64
+ * theme gives it.
65
+ * @param rest — the remaining props, spread onto the element.
66
+ */
67
+ export function Split({ aside, children, side = "start", defaultWidth = 280, min = 160, max = 640, label, onResize, className, ...rest }) {
68
+ // Scoped to this instance, so two splits on one page do not fight
69
+ // over one custom property.
70
+ const variable = `--ui-split-${useId().replace(/[^a-zA-Z0-9]/g, "")}`;
71
+ const root = useRef(null);
72
+ // The aside itself, not "the first child": with `side="end"` the
73
+ // first child is the main pane.
74
+ const asidePane = useRef(null);
75
+ const drag = useRef(null);
76
+ // Mirrored into state only so `aria-valuenow` is right. The layout
77
+ // itself never reads this.
78
+ const [announced, setAnnounced] = useState(defaultWidth);
79
+ const clamp = useCallback((px) => {
80
+ const ceiling = Math.min(max, Math.round((typeof window === "undefined" ? max : window.innerWidth) *
81
+ MOST_OF_WINDOW));
82
+ // `min` wins over the ceiling on a very narrow window: a pane
83
+ // below its minimum is unreadable, and unreadable is worse
84
+ // than wide.
85
+ return Math.round(Math.max(min, Math.min(px, Math.max(min, ceiling))));
86
+ }, [min, max]);
87
+ const apply = useCallback((px) => {
88
+ const width = clamp(px);
89
+ root.current?.style.setProperty(variable, `${width}px`);
90
+ setAnnounced(width);
91
+ return width;
92
+ }, [clamp, variable]);
93
+ const currentWidth = () => asidePane.current?.getBoundingClientRect().width ?? defaultWidth;
94
+ const onPointerDown = (event) => {
95
+ event.preventDefault();
96
+ event.currentTarget.setPointerCapture(event.pointerId);
97
+ drag.current = { startX: event.clientX, startWidth: currentWidth() };
98
+ // On the root rather than the strip, so it survives the pointer
99
+ // leaving — which it does on any drag faster than the reflow.
100
+ root.current?.classList.add("ui-split-resizing");
101
+ };
102
+ const onPointerMove = (event) => {
103
+ const from = drag.current;
104
+ if (from === null)
105
+ return;
106
+ const travelled = event.clientX - from.startX;
107
+ apply(from.startWidth + (side === "start" ? travelled : -travelled));
108
+ };
109
+ const finish = (event) => {
110
+ if (drag.current === null)
111
+ return;
112
+ drag.current = null;
113
+ root.current?.classList.remove("ui-split-resizing");
114
+ event.currentTarget.releasePointerCapture?.(event.pointerId);
115
+ onResize?.(clamp(currentWidth()));
116
+ };
117
+ const onKeyDown = (event) => {
118
+ // A 5px strip is a hard target with a trackpad and an impossible
119
+ // one without a pointer, and this is the only way to move a pane
120
+ // that is otherwise fixed.
121
+ const step = event.shiftKey ? BIG_STEP : STEP;
122
+ const wider = side === "start" ? "ArrowRight" : "ArrowLeft";
123
+ const narrower = side === "start" ? "ArrowLeft" : "ArrowRight";
124
+ let next = null;
125
+ if (event.key === wider)
126
+ next = currentWidth() + step;
127
+ else if (event.key === narrower)
128
+ next = currentWidth() - step;
129
+ else if (event.key === "Home")
130
+ next = min;
131
+ else if (event.key === "End")
132
+ next = max;
133
+ if (next === null)
134
+ return;
135
+ event.preventDefault();
136
+ // Applied first: `onResize?.(apply(next))` skips the argument
137
+ // when there is no `onResize`, and the pane never moved.
138
+ const width = apply(next);
139
+ onResize?.(width);
140
+ };
141
+ const handle = (_jsx("div", { className: "ui-split-handle", role: "separator", "aria-orientation": "vertical", "aria-label": label, title: label, "aria-valuenow": announced, "aria-valuemin": min, "aria-valuemax": max, tabIndex: 0, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: finish, onPointerCancel: finish, onKeyDown: onKeyDown,
142
+ // Back to where it started. A pane dragged somewhere silly is
143
+ // otherwise a slow drag back to a width nobody remembers.
144
+ onDoubleClick: () => {
145
+ const width = apply(defaultWidth);
146
+ onResize?.(width);
147
+ } }, "handle"));
148
+ const asideElement = (_jsx("div", { ref: asidePane, className: "ui-split-aside", children: aside }, "aside"));
149
+ const mainElement = (_jsx("div", { className: "ui-split-main", children: children }, "main"));
150
+ // Keyed, so flipping `side` reorders the panes instead of remounting them.
151
+ const panes = side === "start"
152
+ ? [asideElement, handle, mainElement]
153
+ : [mainElement, handle, asideElement];
154
+ return (_jsx("div", { ...rest, ref: root, className: cx("ui-split", side === "end" && "ui-split-end", className), style: { [variable]: `${defaultWidth}px`, ...rest.style }, "data-split-var": variable, children: panes }));
155
+ }
156
+ //# sourceMappingURL=Split.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Split.js","sourceRoot":"","sources":["../src/Split.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,EACL,WAAW,EACX,KAAK,EACL,MAAM,EACN,QAAQ,GAMT,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,yDAAyD;AACzD,MAAM,IAAI,GAAG,EAAE,CAAC;AAChB,MAAM,QAAQ,GAAG,EAAE,CAAC;AAEpB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,CAAC,EAAE,GAAG,YAAY,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,EAAmB,oBAErD,QAAQ,YAEvB,KAAK,GACF,CACP,CAAC;AACJ,CAAC"}
package/dist/Tabs.d.ts ADDED
@@ -0,0 +1,77 @@
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
+ import type { HTMLAttributes, ReactNode } from "react";
8
+ /** What a {@link Tabs} takes. */
9
+ export interface TabsProps extends Omit<HTMLAttributes<HTMLDivElement>, "onChange"> {
10
+ /** The tabs. The `id` is what {@link TabPanel}s match on. */
11
+ tabs: {
12
+ id: string;
13
+ label: ReactNode;
14
+ }[];
15
+ /** Which tab is showing. */
16
+ active: string;
17
+ /** Called with the id of the tab the reader chose. */
18
+ onChange: (id: string) => void;
19
+ /** The strip's name, for a screen reader. */
20
+ label: string;
21
+ /**
22
+ * The id prefix shared with this strip's {@link TabPanel}s.
23
+ *
24
+ * Optional, and generated when it is absent — but a `TabPanel`
25
+ * *requires* one, so a caller that renders panels passes the same
26
+ * `base` to both: a generated one is never visible to the panels.
27
+ */
28
+ base?: string;
29
+ }
30
+ /**
31
+ * Tabs with the arrow keys wired, because a tab strip that only
32
+ * responds to clicks is a tab strip half the people cannot use.
33
+ *
34
+ * @param tabs — the tabs; the `id` is what the panels match on.
35
+ * @param active — which tab is showing.
36
+ * @param onChange — called with the id of the tab the reader chose.
37
+ * @param label — the strip's name, for a screen reader.
38
+ * @param base — the id prefix shared with this strip's panels; one is
39
+ * generated when it is left out, and the panels need the same one.
40
+ * @param className — added to the element's classes, beside the one the
41
+ * theme gives it.
42
+ * @param rest — the remaining props, spread onto the element.
43
+ */
44
+ export declare function Tabs({ tabs, active, onChange, label, base: givenBase, className, ...rest }: TabsProps): import("react").JSX.Element;
45
+ /**
46
+ * The panel a tab controls. Needs the same `base` the strip used.
47
+ *
48
+ * `Tabs` without it is half the ARIA pattern: a strip that announces
49
+ * it controls something needs something for it to control.
50
+ */
51
+ export interface TabPanelProps extends HTMLAttributes<HTMLDivElement> {
52
+ /** The id prefix shared with its {@link Tabs}, so the two agree. */
53
+ base: string;
54
+ /** Which tab this panel belongs to. */
55
+ id: string;
56
+ /** Which tab is showing. The panel renders only when they match. */
57
+ active: string;
58
+ }
59
+ /**
60
+ * The panel a tab controls.
61
+ *
62
+ * See {@link TabPanelProps}. It renders nothing at all when its tab is
63
+ * not the active one, so the content of a panel that is not showing
64
+ * is not in the page.
65
+ *
66
+ * @param base — the id prefix shared with its tabs, so the two agree.
67
+ * @param id — which tab this panel belongs to.
68
+ * @param active — which tab is showing; the panel renders only when
69
+ * they match.
70
+ * @param children — the content of the panel, shown while its tab is
71
+ * the active one.
72
+ * @param className — the panel's own class; the theme gives it
73
+ * none.
74
+ * @param rest — the remaining props, spread onto the element.
75
+ */
76
+ export declare function TabPanel({ base, id, active, children, className, ...rest }: TabPanelProps): import("react").JSX.Element | null;
77
+ //# sourceMappingURL=Tabs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tabs.d.ts","sourceRoot":"","sources":["../src/Tabs.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAiB,SAAS,EAAE,MAAM,OAAO,CAAC;AAyBtE,iCAAiC;AACjC,MAAM,WAAW,SAAU,SAAQ,IAAI,CACrC,cAAc,CAAC,cAAc,CAAC,EAC9B,UAAU,CACX;IACC,6DAA6D;IAC7D,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,SAAS,CAAA;KAAE,EAAE,CAAC;IACzC,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,IAAI,CAAC,EACnB,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,KAAK,EACL,IAAI,EAAE,SAAS,EACf,SAAS,EACT,GAAG,IAAI,EACR,EAAE,SAAS,+BA6DX;AAED;;;;;GAKG;AACH,MAAM,WAAW,aAAc,SAAQ,cAAc,CAAC,cAAc,CAAC;IACnE,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,oEAAoE;IACpE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,EAAE,EACF,MAAM,EACN,QAAQ,EACR,SAAS,EACT,GAAG,IAAI,EACR,EAAE,aAAa,sCAcf"}
package/dist/Tabs.js ADDED
@@ -0,0 +1,91 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useId, useRef } from "react";
3
+ import { cx } from "./cx.js";
4
+ /**
5
+ * The index a navigation key moves the selection to, from tab `i` of
6
+ * `count`, or `null` for a key the strip does not handle. The arrows
7
+ * wrap at either end.
8
+ */
9
+ function tabAfterKey(key, i, count) {
10
+ switch (key) {
11
+ case "ArrowRight":
12
+ return (i + 1) % count;
13
+ case "ArrowLeft":
14
+ return (i - 1 + count) % count;
15
+ case "Home":
16
+ return 0;
17
+ case "End":
18
+ return count - 1;
19
+ default:
20
+ return null;
21
+ }
22
+ }
23
+ /**
24
+ * Tabs with the arrow keys wired, because a tab strip that only
25
+ * responds to clicks is a tab strip half the people cannot use.
26
+ *
27
+ * @param tabs — the tabs; the `id` is what the panels match on.
28
+ * @param active — which tab is showing.
29
+ * @param onChange — called with the id of the tab the reader chose.
30
+ * @param label — the strip's name, for a screen reader.
31
+ * @param base — the id prefix shared with this strip's panels; one is
32
+ * generated when it is left out, and the panels need the same one.
33
+ * @param className — added to the element's classes, beside the one the
34
+ * theme gives it.
35
+ * @param rest — the remaining props, spread onto the element.
36
+ */
37
+ export function Tabs({ tabs, active, onChange, label, base: givenBase, className, ...rest }) {
38
+ // Hooks run unconditionally; the generated id is simply unused
39
+ // when a caller supplied one.
40
+ const generated = useId();
41
+ const base = givenBase ?? generated;
42
+ const strip = useRef(null);
43
+ // Focus follows selection, as the ARIA practices require: otherwise
44
+ // the focus ring sits on a tab that is now tabIndex={-1} while a
45
+ // different one is selected, and the next Tab leaves the strip from
46
+ // somewhere the reader cannot see.
47
+ useEffect(() => {
48
+ const el = strip.current?.querySelector('[aria-selected="true"]');
49
+ if (el && strip.current?.contains(document.activeElement))
50
+ el.focus();
51
+ }, [active]);
52
+ const onKeyDown = (event) => {
53
+ if (tabs.length === 0)
54
+ return;
55
+ const i = Math.max(tabs.findIndex((t) => t.id === active), 0);
56
+ const next = tabAfterKey(event.key, i, tabs.length);
57
+ if (next === null)
58
+ return;
59
+ event.preventDefault();
60
+ onChange(tabs[next].id);
61
+ };
62
+ return (_jsx("div", { ...rest, ref: strip, role: "tablist", "aria-label": label, "aria-orientation": "horizontal", className: cx("ui-tabs", className), onKeyDown: onKeyDown, children: tabs.map((tab) => (_jsx("button", {
63
+ // Real DOM ids, so a panel can point back with
64
+ // aria-labelledby and this one can point at it. Without
65
+ // them a screen reader announces "tab, 1 of 2" controlling
66
+ // nothing.
67
+ id: `${base}-${tab.id}`, "aria-controls": `${base}-${tab.id}-panel`, type: "button", role: "tab", "aria-selected": tab.id === active, tabIndex: tab.id === active ? 0 : -1, className: "ui-tab", onClick: () => onChange(tab.id), children: tab.label }, tab.id))) }));
68
+ }
69
+ /**
70
+ * The panel a tab controls.
71
+ *
72
+ * See {@link TabPanelProps}. It renders nothing at all when its tab is
73
+ * not the active one, so the content of a panel that is not showing
74
+ * is not in the page.
75
+ *
76
+ * @param base — the id prefix shared with its tabs, so the two agree.
77
+ * @param id — which tab this panel belongs to.
78
+ * @param active — which tab is showing; the panel renders only when
79
+ * they match.
80
+ * @param children — the content of the panel, shown while its tab is
81
+ * the active one.
82
+ * @param className — the panel's own class; the theme gives it
83
+ * none.
84
+ * @param rest — the remaining props, spread onto the element.
85
+ */
86
+ export function TabPanel({ base, id, active, children, className, ...rest }) {
87
+ if (id !== active)
88
+ return null;
89
+ return (_jsx("div", { ...rest, id: `${base}-${id}-panel`, role: "tabpanel", "aria-labelledby": `${base}-${id}`, tabIndex: 0, className: className, children: children }));
90
+ }
91
+ //# sourceMappingURL=Tabs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tabs.js","sourceRoot":"","sources":["../src/Tabs.tsx"],"names":[],"mappings":";AAQA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEjD,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B;;;;GAIG;AACH,SAAS,WAAW,CAAC,GAAW,EAAE,CAAS,EAAE,KAAa;IACxD,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,YAAY;YACf,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;QACzB,KAAK,WAAW;YACd,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC;QACjC,KAAK,MAAM;YACT,OAAO,CAAC,CAAC;QACX,KAAK,KAAK;YACR,OAAO,KAAK,GAAG,CAAC,CAAC;QACnB;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC;AAyBD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,IAAI,CAAC,EACnB,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,KAAK,EACL,IAAI,EAAE,SAAS,EACf,SAAS,EACT,GAAG,IAAI,EACG;IACV,+DAA+D;IAC/D,8BAA8B;IAC9B,MAAM,SAAS,GAAG,KAAK,EAAE,CAAC;IAC1B,MAAM,IAAI,GAAG,SAAS,IAAI,SAAS,CA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YACX,EAAE,EAAE,GAAG,IAAI,IAAI,GAAG,CAAC,EAAE,EAAE,mBACR,GAAG,IAAI,IAAI,GAAG,CAAC,EAAE,QAAQ,EACxC,IAAI,EAAC,QAAQ,EACb,IAAI,EAAC,KAAK,mBACK,GAAG,CAAC,EAAE,KAAK,MAAM,EAChC,QAAQ,EAAE,GAAG,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACpC,SAAS,EAAC,QAAQ,EAClB,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,YAE9B,GAAG,CAAC,KAAK,IAdL,GAAG,CAAC,EAAE,CAeJ,CACV,CAAC,GACE,CACP,CAAC;AACJ,CAAC;AAiBD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,QAAQ,CAAC,EACvB,IAAI,EACJ,EAAE,EACF,MAAM,EACN,QAAQ,EACR,SAAS,EACT,GAAG,IAAI,EACO;IACd,IAAI,EAAE,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IAC/B,OAAO,CACL,iBACM,IAAI,EACR,EAAE,EAAE,GAAG,IAAI,IAAI,EAAE,QAAQ,EACzB,IAAI,EAAC,UAAU,qBACE,GAAG,IAAI,IAAI,EAAE,EAAE,EAChC,QAAQ,EAAE,CAAC,EACX,SAAS,EAAE,SAAS,YAEnB,QAAQ,GACL,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * "It saved." — the message every extension needs and none had.
3
+ *
4
+ * EXTENSIBILITY §5 names `notify` in the list of bridge APIs that do
5
+ * not exist. A specified-and-absent API is worse than a missing one,
6
+ * because a partner designs against it and finds out on demo day.
7
+ *
8
+ * This is the in-frame half: an extension's own toasts, in its own
9
+ * frame. It is not `bridge.notify` — that would put a message in
10
+ * igni's chrome, outside the frame, and needs a host envelope that
11
+ * does not exist yet. The distinction matters because they are not
12
+ * interchangeable: a toast about something inside this panel belongs
13
+ * inside this panel, and only something the user must see after
14
+ * navigating away belongs to the host.
15
+ *
16
+ * **Announced, not just drawn.** The stack is a polite live region,
17
+ * so a toast reaches somebody who is not looking at that corner. A
18
+ * `danger` toast is assertive instead: it is the one case where
19
+ * interrupting is correct.
20
+ *
21
+ * Toasts do not stack indefinitely and do not auto-dismiss when they
22
+ * carry an action — a message that disappears while you are reaching
23
+ * for its button is a message that was never actionable.
24
+ */
25
+ import { type HTMLAttributes, type ReactNode } from "react";
26
+ import type { Tone } from "./controls.js";
27
+ /** What a toast says and how long it stays. */
28
+ export interface ToastOptions {
29
+ /** How loud it is. `danger` interrupts; the rest wait for a pause. */
30
+ tone?: Tone;
31
+ /**
32
+ * Milliseconds before it goes. `null` keeps it until dismissed,
33
+ * which is the default when there is an `action`.
34
+ */
35
+ duration?: number | null;
36
+ /** One thing to do about it. Keeps the toast until dismissed. */
37
+ action?: ReactNode;
38
+ }
39
+ /** A toast that is on screen. */
40
+ export interface Toast extends ToastOptions {
41
+ /** Its id, so it can be dismissed early. */
42
+ id: string;
43
+ /** What it says. */
44
+ message: ReactNode;
45
+ }
46
+ /** How to raise and dismiss toasts. */
47
+ export interface ToastApi {
48
+ /** Show one. Returns its id, so it can be dismissed early. */
49
+ show: (message: ReactNode, options?: ToastOptions) => string;
50
+ /** Take one away before its time is up. */
51
+ dismiss: (id: string) => void;
52
+ /** Take every one away. */
53
+ clear: () => void;
54
+ }
55
+ /**
56
+ * Wrap the part of the app that raises toasts.
57
+ *
58
+ * Renders the stack itself, so there is nothing to place and no way
59
+ * to forget to place it.
60
+ *
61
+ * @param children — the part of the app that raises toasts.
62
+ */
63
+ export declare function ToastHost({ children }: {
64
+ children: ReactNode;
65
+ }): import("react").JSX.Element;
66
+ /**
67
+ * Raise a toast.
68
+ *
69
+ * Throws outside a {@link ToastHost} rather than returning a no-op.
70
+ * A silent no-op here means a save that reports success by showing
71
+ * nothing, which looks exactly like a save that did not happen.
72
+ */
73
+ export declare function useToast(): ToastApi;
74
+ /** What a {@link Banner} takes. */
75
+ export interface BannerProps extends HTMLAttributes<HTMLDivElement> {
76
+ /** How loud it is. */
77
+ tone?: Tone;
78
+ /** A dismiss affordance appears when this is given. */
79
+ onDismiss?: () => void;
80
+ }
81
+ /**
82
+ * A condition that is still true.
83
+ *
84
+ * Not a toast: a toast is about something that just happened and
85
+ * goes away, a banner is about a state — offline, read-only, licence
86
+ * expiring — and stays until the state does not.
87
+ *
88
+ * @param tone — how loud it is: `neutral` for a state nothing is wrong
89
+ * with, and the three that mean something.
90
+ * @param onDismiss — asked to dismiss the banner; the affordance
91
+ * appears when this is given.
92
+ * @param children — the message the banner says.
93
+ * @param className — added to the element's classes, beside the one the
94
+ * theme gives it.
95
+ * @param rest — the remaining props, spread onto the element.
96
+ */
97
+ export declare function Banner({ tone, onDismiss, children, className, ...rest }: BannerProps): import("react").JSX.Element;
98
+ //# sourceMappingURL=Toast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Toast.d.ts","sourceRoot":"","sources":["../src/Toast.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAQL,KAAK,cAAc,EACnB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAY1C,+CAA+C;AAC/C,MAAM,WAAW,YAAY;IAC3B,sEAAsE;IACtE,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,iEAAiE;IACjE,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB;AAED,iCAAiC;AACjC,MAAM,WAAW,KAAM,SAAQ,YAAY;IACzC,4CAA4C;IAC5C,EAAE,EAAE,MAAM,CAAC;IACX,oBAAoB;IACpB,OAAO,EAAE,SAAS,CAAC;CACpB;AAED,uCAAuC;AACvC,MAAM,WAAW,QAAQ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