oneslash-design-system 2.24.0 → 2.26.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 (91) 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/on-this-page.md +2 -0
  34. package/dist/cases/people-row/stack.jsx +1 -1
  35. package/dist/cases/people-row.md +2 -2
  36. package/dist/cases/plan-comparison/table.d.ts +1 -0
  37. package/dist/cases/plan-comparison/table.jsx +47 -0
  38. package/dist/cases/plan-comparison.md +94 -0
  39. package/dist/cases/plan-picker.md +1 -0
  40. package/dist/cases/pricing-section.md +1 -1
  41. package/dist/cases/site-footer/columns.jsx +2 -1
  42. package/dist/cases/site-footer.md +3 -1
  43. package/dist/cases/stat-row/tiles.jsx +2 -1
  44. package/dist/cases/stat-row.md +4 -1
  45. package/dist/cases/task-header/agent-sets-status.jsx +1 -1
  46. package/dist/cases/task-header/people-change-status.jsx +1 -1
  47. package/dist/cases/task-header.md +2 -2
  48. package/dist/cases.json +245 -28
  49. package/dist/components/alert.d.ts +3 -1
  50. package/dist/components/alert.jsx +5 -5
  51. package/dist/components/barChart.jsx +4 -2
  52. package/dist/components/dateField.jsx +1 -1
  53. package/dist/components/formatNumber.d.ts +10 -2
  54. package/dist/components/formatNumber.js +44 -9
  55. package/dist/components/layout.d.ts +4 -2
  56. package/dist/components/layout.jsx +13 -2
  57. package/dist/components/markdown.d.ts +24 -0
  58. package/dist/components/markdown.jsx +81 -0
  59. package/dist/components/onThisPage.d.ts +14 -3
  60. package/dist/components/onThisPage.jsx +72 -8
  61. package/dist/components/pageShell.d.ts +3 -3
  62. package/dist/components/pageShell.jsx +6 -5
  63. package/dist/components/popover.d.ts +5 -1
  64. package/dist/components/popover.jsx +3 -2
  65. package/dist/components/progress.jsx +1 -1
  66. package/dist/components/select.jsx +5 -2
  67. package/dist/components/statTile.d.ts +1 -1
  68. package/dist/components/statTile.jsx +7 -2
  69. package/dist/components/tableCell.d.ts +4 -3
  70. package/dist/components/tableCell.jsx +2 -2
  71. package/dist/components/toaster.jsx +81 -11
  72. package/dist/index.d.ts +1 -0
  73. package/dist/index.js +1 -0
  74. package/dist/internal/markdown.d.ts +40 -0
  75. package/dist/internal/markdown.js +577 -0
  76. package/dist/internal/toaster.d.ts +2 -0
  77. package/dist/internal/toaster.js +8 -0
  78. package/dist/native-mapping.json +9 -3
  79. package/dist/stories/Cases.generated.stories.d.ts +6 -0
  80. package/dist/stories/Cases.generated.stories.jsx +12 -0
  81. package/dist/stories/Markdown.stories.d.ts +9 -0
  82. package/dist/stories/Markdown.stories.jsx +66 -0
  83. package/dist/stories/OnThisPage.stories.d.ts +1 -0
  84. package/dist/stories/OnThisPage.stories.jsx +11 -0
  85. package/dist/stories/Popover.stories.d.ts +2 -0
  86. package/dist/stories/Popover.stories.jsx +33 -0
  87. package/dist/stories/StatTile.stories.d.ts +4 -0
  88. package/dist/stories/StatTile.stories.jsx +47 -2
  89. package/dist/stories/Toaster.stories.d.ts +4 -0
  90. package/dist/stories/Toaster.stories.jsx +30 -0
  91. package/package.json +1 -1
@@ -11,7 +11,7 @@ interface StatTileProps {
11
11
  currency?: string;
12
12
  /** What is counted, e.g. "responses", set after the number. */
13
13
  unit?: string;
14
- /** The value for the period before, in the same unit. Gives the change line; without it there is none. */
14
+ /** The value for the period before, in the same unit. Gives the change line; without it there is none. For `percent` it is a fraction too, and the change reads in points ('Up 3 pts from last week'), which a screen reader hears as 'percentage points'. */
15
15
  previous?: number | null;
16
16
  /** The period `previous` is from. Defaults to week. */
17
17
  period?: ChangePeriod;
@@ -36,7 +36,9 @@ export default function StatTile(_a) {
36
36
  }
37
37
  }
38
38
  var compact = shown !== null && exact !== null && shown !== exact;
39
- var change = loading ? null : formatChange(value, previous, period);
39
+ var change = loading ? null : formatChange(value, previous, period, { as: format === 'percent' ? 'points' : 'relative' });
40
+ // The tile shows 'pts', which a screen reader may spell out, so it hears 'percentage points' in words
41
+ var spoken = change === null || change === void 0 ? void 0 : change.text.replace(/ (pts?) /, function (_, pts) { return (pts === 'pt' ? ' percentage point ' : ' percentage points '); });
40
42
  return (<dl id={id} aria-busy={loading || undefined} className="flex min-w-0 flex-col gap-1">
41
43
  <dt className="text-caption text-fg-secondary">{label}</dt>
42
44
  <dd className={"flex items-center ".concat(valueLine)}>
@@ -54,7 +56,10 @@ export default function StatTile(_a) {
54
56
  change.direction !== null && (<dd className="m-0 flex items-center gap-1 text-body2 text-fg-secondary">
55
57
  {change.direction === 'up' && <ArrowUp aria-hidden="true" className="size-4 shrink-0"/>}
56
58
  {change.direction === 'down' && <ArrowDown aria-hidden="true" className="size-4 shrink-0"/>}
57
- {change.text}
59
+ {format === 'percent' && spoken !== change.text ? (<>
60
+ <span aria-hidden="true">{change.text}</span>
61
+ <span className="sr-only">{spoken}</span>
62
+ </>) : (change.text)}
58
63
  </dd>))}
59
64
  {caption && <dd className="m-0 text-body2 text-fg-secondary">{caption}</dd>}
60
65
  </dl>);
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
- interface TableCellProps {
2
+ export interface TableCellProps {
3
3
  children: React.ReactNode;
4
4
  width?: string;
5
5
  minWidth?: string;
6
6
  align?: 'left' | 'center' | 'right';
7
+ /** Makes the cell its row's header, such as a feature name in the first column of a comparison: `role="rowheader"` in place of `role="cell"`. A screen reader then reads it with each cell of the row. */
8
+ rowHeader?: boolean;
7
9
  }
8
- export default function TableCell({ children, width, minWidth, align }: TableCellProps): React.JSX.Element;
9
- export {};
10
+ export default function TableCell({ children, width, minWidth, align, rowHeader }: TableCellProps): React.JSX.Element;
@@ -1,11 +1,11 @@
1
1
  'use client';
2
2
  import React from 'react';
3
3
  export default function TableCell(_a) {
4
- var children = _a.children, width = _a.width, minWidth = _a.minWidth, _b = _a.align, align = _b === void 0 ? 'left' : _b;
4
+ var children = _a.children, width = _a.width, minWidth = _a.minWidth, _b = _a.align, align = _b === void 0 ? 'left' : _b, _c = _a.rowHeader, rowHeader = _c === void 0 ? false : _c;
5
5
  var alignClass = align === 'center' ? 'text-center' : align === 'right' ? 'text-right' : 'text-left';
6
6
  var widthStyle = width ? { width: width, minWidth: minWidth || width } : {};
7
7
  var flexClass = width ? '' : 'flex-1';
8
- return (<div role="cell" className={"".concat(flexClass, " p-2 text-body2 text-fg-primary border-t border-misc-divider ").concat(alignClass)} style={widthStyle}>
8
+ return (<div role={rowHeader ? 'rowheader' : 'cell'} className={"".concat(flexClass, " p-2 text-body2 text-fg-primary border-t border-misc-divider ").concat(alignClass)} style={widthStyle}>
9
9
  {children}
10
10
  </div>);
11
11
  }
@@ -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[];