oneslash-design-system 2.24.0 → 2.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +1 -1
  2. package/dist/DESIGN.md +8 -4
  3. package/dist/cases/ask-page/answered.jsx +10 -2
  4. package/dist/cases/ask-page.md +12 -3
  5. package/dist/cases/billing-page/self-serve.jsx +4 -4
  6. package/dist/cases/billing-page/trial.d.ts +1 -0
  7. package/dist/cases/billing-page/trial.jsx +115 -0
  8. package/dist/cases/billing-page.md +166 -5
  9. package/dist/cases/collapsible-search/popover.jsx +1 -1
  10. package/dist/cases/collapsible-search.md +2 -2
  11. package/dist/cases/cookie-choice/banner.d.ts +1 -0
  12. package/dist/cases/cookie-choice/banner.jsx +82 -0
  13. package/dist/cases/cookie-choice/settings.d.ts +1 -0
  14. package/dist/cases/cookie-choice/settings.jsx +75 -0
  15. package/dist/cases/cookie-choice.md +234 -0
  16. package/dist/cases/dashboard/numbers-first.jsx +1 -1
  17. package/dist/cases/dashboard/work-first.jsx +1 -1
  18. package/dist/cases/dashboard.md +2 -2
  19. package/dist/cases/data-table-page/all-rows.jsx +1 -1
  20. package/dist/cases/data-table-page/paged.jsx +1 -1
  21. package/dist/cases/data-table-page.md +2 -2
  22. package/dist/cases/invoice-list/table.jsx +21 -9
  23. package/dist/cases/invoice-list.md +27 -12
  24. package/dist/cases/message-reactions/picker.jsx +1 -1
  25. package/dist/cases/message-reactions.md +2 -2
  26. package/dist/cases/message-row.md +2 -1
  27. package/dist/cases/newsletter-signup/inline.d.ts +1 -0
  28. package/dist/cases/newsletter-signup/inline.jsx +72 -0
  29. package/dist/cases/newsletter-signup/section.d.ts +1 -0
  30. package/dist/cases/newsletter-signup/section.jsx +72 -0
  31. package/dist/cases/newsletter-signup.md +234 -0
  32. package/dist/cases/number-format.md +6 -2
  33. package/dist/cases/people-row/stack.jsx +1 -1
  34. package/dist/cases/people-row.md +2 -2
  35. package/dist/cases/plan-comparison/table.d.ts +1 -0
  36. package/dist/cases/plan-comparison/table.jsx +47 -0
  37. package/dist/cases/plan-comparison.md +94 -0
  38. package/dist/cases/plan-picker.md +1 -0
  39. package/dist/cases/pricing-section.md +1 -1
  40. package/dist/cases/site-footer/columns.jsx +2 -1
  41. package/dist/cases/site-footer.md +3 -1
  42. package/dist/cases/stat-row/tiles.jsx +2 -1
  43. package/dist/cases/stat-row.md +4 -1
  44. package/dist/cases/task-header/agent-sets-status.jsx +1 -1
  45. package/dist/cases/task-header/people-change-status.jsx +1 -1
  46. package/dist/cases/task-header.md +2 -2
  47. package/dist/cases.json +243 -28
  48. package/dist/components/alert.d.ts +3 -1
  49. package/dist/components/alert.jsx +5 -5
  50. package/dist/components/barChart.jsx +4 -2
  51. package/dist/components/dateField.jsx +1 -1
  52. package/dist/components/formatNumber.d.ts +10 -2
  53. package/dist/components/formatNumber.js +44 -9
  54. package/dist/components/layout.d.ts +4 -2
  55. package/dist/components/layout.jsx +13 -2
  56. package/dist/components/markdown.d.ts +24 -0
  57. package/dist/components/markdown.jsx +81 -0
  58. package/dist/components/pageShell.d.ts +3 -3
  59. package/dist/components/pageShell.jsx +6 -5
  60. package/dist/components/popover.d.ts +5 -1
  61. package/dist/components/popover.jsx +3 -2
  62. package/dist/components/progress.jsx +1 -1
  63. package/dist/components/select.jsx +5 -2
  64. package/dist/components/statTile.d.ts +1 -1
  65. package/dist/components/statTile.jsx +7 -2
  66. package/dist/components/tableCell.d.ts +4 -3
  67. package/dist/components/tableCell.jsx +2 -2
  68. package/dist/components/toaster.jsx +81 -11
  69. package/dist/index.d.ts +1 -0
  70. package/dist/index.js +1 -0
  71. package/dist/internal/markdown.d.ts +40 -0
  72. package/dist/internal/markdown.js +577 -0
  73. package/dist/internal/toaster.d.ts +2 -0
  74. package/dist/internal/toaster.js +8 -0
  75. package/dist/native-mapping.json +9 -3
  76. package/dist/stories/Cases.generated.stories.d.ts +6 -0
  77. package/dist/stories/Cases.generated.stories.jsx +12 -0
  78. package/dist/stories/Markdown.stories.d.ts +9 -0
  79. package/dist/stories/Markdown.stories.jsx +66 -0
  80. package/dist/stories/Popover.stories.d.ts +2 -0
  81. package/dist/stories/Popover.stories.jsx +33 -0
  82. package/dist/stories/StatTile.stories.d.ts +4 -0
  83. package/dist/stories/StatTile.stories.jsx +47 -2
  84. package/dist/stories/Toaster.stories.d.ts +4 -0
  85. package/dist/stories/Toaster.stories.jsx +30 -0
  86. package/package.json +1 -1
@@ -21,9 +21,13 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
21
21
  };
22
22
  import React, { useEffect, useReducer, useRef, useState, useSyncExternalStore } from 'react';
23
23
  import Alert from './alert';
24
- import { addToast, removeToast, visibleToasts, pauseReducer, isPaused } from '../internal/toaster';
24
+ import { addToast, removeToast, visibleToasts, pauseReducer, isPaused, announcementText, liveRegionFor } from '../internal/toaster';
25
25
  // Matches Alert's exit transition
26
26
  var EXIT_MS = 150;
27
+ // The announcer writes one toast per tick, so a screen reader hears each one in a burst
28
+ var ANNOUNCE_EVERY_MS = 150;
29
+ // An announced text leaves its region, so a reader browsing the page later does not find it
30
+ var ANNOUNCE_CLEAR_MS = 5000;
27
31
  var store = { toasts: [], mounts: [] };
28
32
  var serverStore = { toasts: [], mounts: [] };
29
33
  var listeners = new Set();
@@ -78,26 +82,92 @@ function Toast(_a) {
78
82
  // Focus moving to another element inside the same toast has not left it
79
83
  onBlur={function (e) { if (!e.currentTarget.contains(e.relatedTarget))
80
84
  dispatch('blur'); }}>
81
- <Alert variant="inline" showCloseButton autoDismiss={false} open={open} type={item.type} message={item.message} secondMessage={item.secondMessage} onClose={function () { return dismissToast(item.id); }}/>
85
+ <Alert variant="inline" showCloseButton autoDismiss={false} open={open} type={item.type} message={item.message} secondMessage={item.secondMessage}
86
+ // The Toaster's live regions announce it; a role here would make it heard twice
87
+ announce={false} onClose={function () { return dismissToast(item.id); }}/>
82
88
  </div>);
83
89
  }
84
90
  // Mount once near the app root. A second Toaster renders nothing.
85
91
  export default function Toaster() {
86
92
  var _a = useSyncExternalStore(subscribe, function () { return store; }, function () { return serverStore; }), toasts = _a.toasts, mounts = _a.mounts;
87
93
  var me = useState(function () { return Symbol('Toaster'); })[0];
94
+ var first = mounts[0] === me;
95
+ // The live regions are in the page before any text goes in, since a region that arrives filled is often not read
96
+ var polite = useRef(null);
97
+ var assertive = useRef(null);
98
+ var seen = useRef(new Set());
99
+ var queue = useRef([]);
100
+ // The tick runs only while toasts wait to be announced, so a page with no toast starts no timer
101
+ var tickRef = useRef(null);
102
+ var frame = useRef(null);
103
+ var clearTimers = useRef({});
88
104
  useEffect(function () {
89
105
  setStore(__assign(__assign({}, store), { mounts: __spreadArray(__spreadArray([], store.mounts, true), [me], false) }));
90
106
  return function () { return setStore(__assign(__assign({}, store), { mounts: store.mounts.filter(function (m) { return m !== me; }) })); };
91
107
  }, [me]);
92
- if (mounts[0] !== me)
108
+ // Each tick: empty the next toast's region, then write its text on the next frame, so the same text twice is heard twice
109
+ var tick = function () {
110
+ if (frame.current !== null)
111
+ return;
112
+ var next = queue.current[0];
113
+ if (!next) {
114
+ clearInterval(tickRef.current);
115
+ tickRef.current = null;
116
+ return;
117
+ }
118
+ var el = (next.region === 'assertive' ? assertive : polite).current;
119
+ if (!el)
120
+ return;
121
+ queue.current.shift();
122
+ el.textContent = '';
123
+ frame.current = requestAnimationFrame(function () {
124
+ frame.current = null;
125
+ el.textContent = next.text;
126
+ clearTimeout(clearTimers.current[next.region]);
127
+ clearTimers.current[next.region] = setTimeout(function () { el.textContent = ''; }, ANNOUNCE_CLEAR_MS);
128
+ });
129
+ };
130
+ // Each new toast is queued once, oldest first; a dismissed toast does not change the queue
131
+ useEffect(function () {
132
+ var _a;
133
+ var fresh = toasts.filter(function (t) { return !seen.current.has(t.id); }).reverse();
134
+ seen.current = new Set(toasts.map(function (t) { return t.id; }));
135
+ // Another Toaster announces
136
+ if (mounts.length > 0 && !first) {
137
+ queue.current = [];
138
+ return;
139
+ }
140
+ (_a = queue.current).push.apply(_a, fresh.map(function (t) { return ({ text: announcementText(t), region: liveRegionFor(t.type) }); }));
141
+ if (first && queue.current.length > 0 && tickRef.current === null)
142
+ tickRef.current = setInterval(tick, ANNOUNCE_EVERY_MS);
143
+ }, [toasts, mounts, first]);
144
+ // Stop everything when this Toaster stops announcing or unmounts
145
+ useEffect(function () {
146
+ if (!first)
147
+ return;
148
+ return function () {
149
+ if (tickRef.current !== null)
150
+ clearInterval(tickRef.current);
151
+ tickRef.current = null;
152
+ if (frame.current !== null)
153
+ cancelAnimationFrame(frame.current);
154
+ frame.current = null;
155
+ Object.values(clearTimers.current).forEach(clearTimeout);
156
+ clearTimers.current = {};
157
+ };
158
+ }, [first]);
159
+ if (!first)
93
160
  return null;
94
161
  var shown = visibleToasts(toasts);
95
- if (shown.length === 0)
96
- return null;
97
- // Above modals; the column lets clicks through beside and between the toasts
98
- return (<div className="fixed top-4 inset-x-0 z-[var(--os-z-tooltip)] flex justify-center px-4 pointer-events-none">
99
- <div className="flex flex-col gap-2 w-full max-w-md">
100
- {shown.map(function (item) { return <Toast key={item.id} item={item}/>; })}
101
- </div>
102
- </div>);
162
+ return (<>
163
+ <div ref={polite} className="sr-only" role="status" aria-live="polite" aria-atomic="true"/>
164
+ <div ref={assertive} className="sr-only" role="alert" aria-live="assertive" aria-atomic="true"/>
165
+ {shown.length > 0 && (
166
+ // Above modals; the column lets clicks through beside and between the toasts
167
+ <div className="fixed top-4 inset-x-0 z-[var(--os-z-tooltip)] flex justify-center px-4 pointer-events-none">
168
+ <div className="flex flex-col gap-2 w-full max-w-md">
169
+ {shown.map(function (item) { return <Toast key={item.id} item={item}/>; })}
170
+ </div>
171
+ </div>)}
172
+ </>);
103
173
  }
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export * from './components/iconButton';
14
14
  export * from './components/layout';
15
15
  export * from './components/lightbox';
16
16
  export * from './components/loadingScreen';
17
+ export * from './components/markdown';
17
18
  export * from './components/menu';
18
19
  export * from './components/menuItem';
19
20
  export * from './components/modal';
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ export * from './components/iconButton';
14
14
  export * from './components/layout';
15
15
  export * from './components/lightbox';
16
16
  export * from './components/loadingScreen';
17
+ export * from './components/markdown';
17
18
  export * from './components/menu';
18
19
  export * from './components/menuItem';
19
20
  export * from './components/modal';
@@ -0,0 +1,40 @@
1
+ export type MdInline = {
2
+ type: 'text';
3
+ text: string;
4
+ } | {
5
+ type: 'strong' | 'em';
6
+ children: MdInline[];
7
+ } | {
8
+ type: 'code';
9
+ text: string;
10
+ } | {
11
+ type: 'link';
12
+ href: string;
13
+ children: MdInline[];
14
+ };
15
+ export type MdBlock = {
16
+ type: 'heading';
17
+ depth: 1 | 2 | 3;
18
+ children: MdInline[];
19
+ } | {
20
+ type: 'paragraph';
21
+ children: MdInline[];
22
+ } | {
23
+ type: 'list';
24
+ ordered: boolean;
25
+ items: MdBlock[][];
26
+ } | {
27
+ type: 'code';
28
+ language?: string;
29
+ code: string;
30
+ table?: boolean;
31
+ } | {
32
+ type: 'rule';
33
+ };
34
+ /**
35
+ * Only `http:`, `https:` and `mailto:` links, with the scheme in lower case. Anything else gives null:
36
+ * `javascript:`, `data:`, `vbscript:`, relative paths, and any URL with a space or a control character
37
+ * in it (which a browser would strip before it reads the scheme). Entities are never decoded.
38
+ */
39
+ export declare function safeHref(href: string): string | null;
40
+ export declare function parseMarkdown(text: string): MdBlock[];