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.
- package/README.md +1 -1
- package/dist/DESIGN.md +8 -4
- package/dist/cases/ask-page/answered.jsx +10 -2
- package/dist/cases/ask-page.md +12 -3
- package/dist/cases/billing-page/self-serve.jsx +4 -4
- package/dist/cases/billing-page/trial.d.ts +1 -0
- package/dist/cases/billing-page/trial.jsx +115 -0
- package/dist/cases/billing-page.md +166 -5
- package/dist/cases/collapsible-search/popover.jsx +1 -1
- package/dist/cases/collapsible-search.md +2 -2
- package/dist/cases/cookie-choice/banner.d.ts +1 -0
- package/dist/cases/cookie-choice/banner.jsx +82 -0
- package/dist/cases/cookie-choice/settings.d.ts +1 -0
- package/dist/cases/cookie-choice/settings.jsx +75 -0
- package/dist/cases/cookie-choice.md +234 -0
- package/dist/cases/dashboard/numbers-first.jsx +1 -1
- package/dist/cases/dashboard/work-first.jsx +1 -1
- package/dist/cases/dashboard.md +2 -2
- package/dist/cases/data-table-page/all-rows.jsx +1 -1
- package/dist/cases/data-table-page/paged.jsx +1 -1
- package/dist/cases/data-table-page.md +2 -2
- package/dist/cases/invoice-list/table.jsx +21 -9
- package/dist/cases/invoice-list.md +27 -12
- package/dist/cases/message-reactions/picker.jsx +1 -1
- package/dist/cases/message-reactions.md +2 -2
- package/dist/cases/message-row.md +2 -1
- package/dist/cases/newsletter-signup/inline.d.ts +1 -0
- package/dist/cases/newsletter-signup/inline.jsx +72 -0
- package/dist/cases/newsletter-signup/section.d.ts +1 -0
- package/dist/cases/newsletter-signup/section.jsx +72 -0
- package/dist/cases/newsletter-signup.md +234 -0
- package/dist/cases/number-format.md +6 -2
- package/dist/cases/people-row/stack.jsx +1 -1
- package/dist/cases/people-row.md +2 -2
- package/dist/cases/plan-comparison/table.d.ts +1 -0
- package/dist/cases/plan-comparison/table.jsx +47 -0
- package/dist/cases/plan-comparison.md +94 -0
- package/dist/cases/plan-picker.md +1 -0
- package/dist/cases/pricing-section.md +1 -1
- package/dist/cases/site-footer/columns.jsx +2 -1
- package/dist/cases/site-footer.md +3 -1
- package/dist/cases/stat-row/tiles.jsx +2 -1
- package/dist/cases/stat-row.md +4 -1
- package/dist/cases/task-header/agent-sets-status.jsx +1 -1
- package/dist/cases/task-header/people-change-status.jsx +1 -1
- package/dist/cases/task-header.md +2 -2
- package/dist/cases.json +243 -28
- package/dist/components/alert.d.ts +3 -1
- package/dist/components/alert.jsx +5 -5
- package/dist/components/barChart.jsx +4 -2
- package/dist/components/dateField.jsx +1 -1
- package/dist/components/formatNumber.d.ts +10 -2
- package/dist/components/formatNumber.js +44 -9
- package/dist/components/layout.d.ts +4 -2
- package/dist/components/layout.jsx +13 -2
- package/dist/components/markdown.d.ts +24 -0
- package/dist/components/markdown.jsx +81 -0
- package/dist/components/pageShell.d.ts +3 -3
- package/dist/components/pageShell.jsx +6 -5
- package/dist/components/popover.d.ts +5 -1
- package/dist/components/popover.jsx +3 -2
- package/dist/components/progress.jsx +1 -1
- package/dist/components/select.jsx +5 -2
- package/dist/components/statTile.d.ts +1 -1
- package/dist/components/statTile.jsx +7 -2
- package/dist/components/tableCell.d.ts +4 -3
- package/dist/components/tableCell.jsx +2 -2
- package/dist/components/toaster.jsx +81 -11
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/markdown.d.ts +40 -0
- package/dist/internal/markdown.js +577 -0
- package/dist/internal/toaster.d.ts +2 -0
- package/dist/internal/toaster.js +8 -0
- package/dist/native-mapping.json +9 -3
- package/dist/stories/Cases.generated.stories.d.ts +6 -0
- package/dist/stories/Cases.generated.stories.jsx +12 -0
- package/dist/stories/Markdown.stories.d.ts +9 -0
- package/dist/stories/Markdown.stories.jsx +66 -0
- package/dist/stories/Popover.stories.d.ts +2 -0
- package/dist/stories/Popover.stories.jsx +33 -0
- package/dist/stories/StatTile.stories.d.ts +4 -0
- package/dist/stories/StatTile.stories.jsx +47 -2
- package/dist/stories/Toaster.stories.d.ts +4 -0
- package/dist/stories/Toaster.stories.jsx +30 -0
- package/package.json +1 -1
|
@@ -11,6 +11,8 @@ interface AlertProps {
|
|
|
11
11
|
variant?: 'toast' | 'inline';
|
|
12
12
|
/** Not set: the alert dismisses itself after 5 seconds unless it has a close button. `false` keeps it open; `true` dismisses it even with a close button. */
|
|
13
13
|
autoDismiss?: boolean;
|
|
14
|
+
/** Default `true`: the alert is a live region (`role="alert"` for errors, `role="status"` otherwise). `false` drops the role, for an alert whose text is announced elsewhere, as Toaster does. */
|
|
15
|
+
announce?: boolean;
|
|
14
16
|
}
|
|
15
|
-
export default function Alert({ id, open, type, message, secondMessage, onClose, showCloseButton, variant, autoDismiss, }: AlertProps): React.JSX.Element | null;
|
|
17
|
+
export default function Alert({ id, open, type, message, secondMessage, onClose, showCloseButton, variant, autoDismiss, announce, }: AlertProps): React.JSX.Element | null;
|
|
16
18
|
export {};
|
|
@@ -18,11 +18,11 @@ var motionClasses = {
|
|
|
18
18
|
};
|
|
19
19
|
export default function Alert(_a) {
|
|
20
20
|
var _b;
|
|
21
|
-
var id = _a.id, _c = _a.open, open = _c === void 0 ? true : _c, type = _a.type, message = _a.message, secondMessage = _a.secondMessage, onClose = _a.onClose, _d = _a.showCloseButton, showCloseButton = _d === void 0 ? false : _d, _e = _a.variant, variant = _e === void 0 ? 'toast' : _e, autoDismiss = _a.autoDismiss;
|
|
22
|
-
var
|
|
23
|
-
var
|
|
21
|
+
var id = _a.id, _c = _a.open, open = _c === void 0 ? true : _c, type = _a.type, message = _a.message, secondMessage = _a.secondMessage, onClose = _a.onClose, _d = _a.showCloseButton, showCloseButton = _d === void 0 ? false : _d, _e = _a.variant, variant = _e === void 0 ? 'toast' : _e, autoDismiss = _a.autoDismiss, _f = _a.announce, announce = _f === void 0 ? true : _f;
|
|
22
|
+
var _g = useState(false), isVisible = _g[0], setIsVisible = _g[1];
|
|
23
|
+
var _h = useState(false), shouldRender = _h[0], setShouldRender = _h[1];
|
|
24
24
|
// Auto-dismiss pauses while the toast is hovered or focused
|
|
25
|
-
var
|
|
25
|
+
var _j = useState(false), isPaused = _j[0], setIsPaused = _j[1];
|
|
26
26
|
var remainingMs = useRef(AUTO_DISMISS_MS);
|
|
27
27
|
useEffect(function () {
|
|
28
28
|
if (open) {
|
|
@@ -68,7 +68,7 @@ export default function Alert(_a) {
|
|
|
68
68
|
var textClasses = bgClasses === bgClassMap.default ? 'text-secondary-contrast' : 'text-fg-primary';
|
|
69
69
|
var alertContent = (<div id={id}
|
|
70
70
|
// Errors interrupt screen readers; everything else is announced politely
|
|
71
|
-
role={type === 'error' ? 'alert' : 'status'} onMouseEnter={function () { return setIsPaused(true); }} onMouseLeave={function () { return setIsPaused(false); }} onFocus={function () { return setIsPaused(true); }} onBlur={function () { return setIsPaused(false); }} className={"flex ".concat(secondMessage ? 'items-start' : 'items-center', " justify-between w-full p-2 rounded-control transition-[opacity,transform] ").concat(isVisible ? motionClasses.enter : motionClasses.exit, " motion-reduce:transition-none ").concat(bgClasses, " ").concat(isVisible ? 'opacity-100 translate-y-0' : variant === 'toast' ? 'opacity-0 -translate-y-[calc(100%+1rem)]' : 'opacity-0', " ").concat(variant === 'toast' ? 'max-w-md pointer-events-auto' : '')}>
|
|
71
|
+
role={announce ? (type === 'error' ? 'alert' : 'status') : undefined} onMouseEnter={function () { return setIsPaused(true); }} onMouseLeave={function () { return setIsPaused(false); }} onFocus={function () { return setIsPaused(true); }} onBlur={function () { return setIsPaused(false); }} className={"flex ".concat(secondMessage ? 'items-start' : 'items-center', " justify-between w-full p-2 rounded-control transition-[opacity,transform] ").concat(isVisible ? motionClasses.enter : motionClasses.exit, " motion-reduce:transition-none ").concat(bgClasses, " ").concat(isVisible ? 'opacity-100 translate-y-0' : variant === 'toast' ? 'opacity-0 -translate-y-[calc(100%+1rem)]' : 'opacity-0', " ").concat(variant === 'toast' ? 'max-w-md pointer-events-auto' : '')}>
|
|
72
72
|
<div className={"flex items-start gap-2 ".concat(textClasses)}>
|
|
73
73
|
{/* With two lines, nudge the text so its first line centers on the close button */}
|
|
74
74
|
<div className={"flex flex-col text-left ".concat(secondMessage && showCloseButton ? 'pt-[3px]' : '')}>
|
|
@@ -31,8 +31,10 @@ export default function BarChart(_a) {
|
|
|
31
31
|
// A count never gets a fractional tick
|
|
32
32
|
var ticks = niceTicks(Math.max.apply(Math, __spreadArray([0], values, false)), 4, { integer: format === 'count' });
|
|
33
33
|
var top = ticks[ticks.length - 1];
|
|
34
|
-
|
|
35
|
-
var
|
|
34
|
+
// Past 24 points six labels leave too little room for 'Oct 18' on a phone, so a month gets four (as LineChart does)
|
|
35
|
+
var most = data.length > 24 ? 4 : 6;
|
|
36
|
+
var labels = new Set(labelEvery(data.length, most));
|
|
37
|
+
var step = data.length > 0 ? Math.ceil(data.length / most) : 1;
|
|
36
38
|
var point = data[active];
|
|
37
39
|
var readout = point ? "".concat(point.label, ": ").concat(exactText(point.value, format, unit)) : '';
|
|
38
40
|
var table = {
|
|
@@ -69,7 +69,7 @@ export default function DateField(_a) {
|
|
|
69
69
|
</p>) : (helperText && (<p id={helperId} className="mt-1 text-fg-secondary text-body2">
|
|
70
70
|
{helperText}
|
|
71
71
|
</p>))}
|
|
72
|
-
<Popover id={"".concat(id, "-popover")} anchorEl={button} open={open} onClose={function () { return setOpen(false); }} returnFocus>
|
|
72
|
+
<Popover id={"".concat(id, "-popover")} anchorEl={button} open={open} onClose={function () { return setOpen(false); }} returnFocus aria-label={label || 'Choose date'}>
|
|
73
73
|
<Calendar id={"".concat(id, "-calendar")} value={value} min={min} max={max} aria-label={label || 'Choose date'} autoFocus onChange={pick}/>
|
|
74
74
|
</Popover>
|
|
75
75
|
</div>);
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
export declare function formatCount(n: number, { compact }?: {
|
|
3
3
|
compact?: boolean;
|
|
4
4
|
}): string;
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* '$1,240.00' in the currency's own decimals: two for USD and EUR, none for JPY ('¥1,240'), three for KWD ('KWD 1,240.000').
|
|
7
|
+
* A non-zero amount under half the smallest unit is '< $0.01', '< ¥1', '< KWD 0.001'. With `compact`, from 10,000 up: '$12.4K'.
|
|
8
|
+
* A currency code Intl rejects is '–'.
|
|
9
|
+
*/
|
|
6
10
|
export declare function formatMoney(n: number, { currency, compact }?: {
|
|
7
11
|
currency?: string;
|
|
8
12
|
compact?: boolean;
|
|
@@ -21,5 +25,9 @@ export type Change = {
|
|
|
21
25
|
/**
|
|
22
26
|
* The change line under a stat: 'Up 12% from last week', 'Down 5% from last week', 'No change from last week',
|
|
23
27
|
* 'New this week' (the previous value was 0). With no previous value there is nothing to compare: direction null, no text.
|
|
28
|
+
* With `as: 'points'`, `value` and `previous` are shares (fractions) and the change is in percentage points:
|
|
29
|
+
* 'Up 3 pts from last week', 'Down 1 pt from last week', 'Up < 1 pt from last week'. A share of 0 is a value, so there is no 'New'.
|
|
24
30
|
*/
|
|
25
|
-
export declare function formatChange(value: number | null | undefined, previous: number | null | undefined, period?: ChangePeriod
|
|
31
|
+
export declare function formatChange(value: number | null | undefined, previous: number | null | undefined, period?: ChangePeriod, { as }?: {
|
|
32
|
+
as?: 'relative' | 'points';
|
|
33
|
+
}): Change;
|
|
@@ -20,10 +20,27 @@ var whole = new Intl.NumberFormat(LOCALE, { maximumFractionDigits: 0 });
|
|
|
20
20
|
var oneDecimal = new Intl.NumberFormat(LOCALE, { maximumFractionDigits: 1 });
|
|
21
21
|
var compactCount = new Intl.NumberFormat(LOCALE, { notation: 'compact', maximumFractionDigits: 1 });
|
|
22
22
|
var percent = new Intl.NumberFormat(LOCALE, { style: 'percent', maximumFractionDigits: 0 });
|
|
23
|
+
// One formatter per currency and compact flag. A code Intl rejects is cached as null.
|
|
24
|
+
var moneyCache = new Map();
|
|
23
25
|
var money = function (currency, compact) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
var _a, _b;
|
|
27
|
+
var key = "".concat(currency, ":").concat(compact ? 'compact' : 'full');
|
|
28
|
+
if (moneyCache.has(key))
|
|
29
|
+
return (_a = moneyCache.get(key)) !== null && _a !== void 0 ? _a : null;
|
|
30
|
+
var made = null;
|
|
31
|
+
try {
|
|
32
|
+
// The currency's own decimals: 2 for USD, 0 for JPY and KRW, 3 for KWD and BHD
|
|
33
|
+
var digits = (_b = new Intl.NumberFormat(LOCALE, { style: 'currency', currency: currency }).resolvedOptions().maximumFractionDigits) !== null && _b !== void 0 ? _b : 2;
|
|
34
|
+
var formatter = new Intl.NumberFormat(LOCALE, __assign({ style: 'currency', currency: currency }, (compact
|
|
35
|
+
? { notation: 'compact', minimumFractionDigits: 0, maximumFractionDigits: 1 }
|
|
36
|
+
: { minimumFractionDigits: digits, maximumFractionDigits: digits })));
|
|
37
|
+
made = { format: formatter.format.bind(formatter), digits: digits };
|
|
38
|
+
}
|
|
39
|
+
catch (_c) {
|
|
40
|
+
// RangeError: not a currency code
|
|
41
|
+
}
|
|
42
|
+
moneyCache.set(key, made);
|
|
43
|
+
return made;
|
|
27
44
|
};
|
|
28
45
|
/** '1,240'. With `compact`, from 10,000 up: '12.4K', '1.2M', '10B', '3.5T'. Below 10,000 it stays exact. */
|
|
29
46
|
export function formatCount(n, _a) {
|
|
@@ -37,7 +54,11 @@ export function formatCount(n, _a) {
|
|
|
37
54
|
return compactCount.format(n);
|
|
38
55
|
return exact.format(n);
|
|
39
56
|
}
|
|
40
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* '$1,240.00' in the currency's own decimals: two for USD and EUR, none for JPY ('¥1,240'), three for KWD ('KWD 1,240.000').
|
|
59
|
+
* A non-zero amount under half the smallest unit is '< $0.01', '< ¥1', '< KWD 0.001'. With `compact`, from 10,000 up: '$12.4K'.
|
|
60
|
+
* A currency code Intl rejects is '–'.
|
|
61
|
+
*/
|
|
41
62
|
export function formatMoney(n, _a) {
|
|
42
63
|
var _b = _a === void 0 ? {} : _a, _c = _b.currency, currency = _c === void 0 ? 'USD' : _c, _d = _b.compact, compact = _d === void 0 ? false : _d;
|
|
43
64
|
if (!finite(n))
|
|
@@ -45,11 +66,15 @@ export function formatMoney(n, _a) {
|
|
|
45
66
|
// -0 would print '-$0.00'
|
|
46
67
|
if (n === 0)
|
|
47
68
|
n = 0;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return
|
|
69
|
+
var full = money(currency, false);
|
|
70
|
+
if (!full)
|
|
71
|
+
return DASH;
|
|
72
|
+
var unit = Math.pow(10, -full.digits);
|
|
73
|
+
if (n !== 0 && Math.abs(n) < unit / 2) {
|
|
74
|
+
var smallest = full.format(unit);
|
|
75
|
+
return n > 0 ? "< ".concat(smallest) : "> -".concat(smallest);
|
|
51
76
|
}
|
|
52
|
-
return
|
|
77
|
+
return (compact && Math.abs(n) >= COMPACT_FROM ? money(currency, true) : full).format(n);
|
|
53
78
|
}
|
|
54
79
|
/** A fraction as a whole percent: 0.124 is '12%'. A small non-zero share is '< 1%'. */
|
|
55
80
|
export function formatPercent(fraction) {
|
|
@@ -106,9 +131,12 @@ export function formatDuration(ms) {
|
|
|
106
131
|
/**
|
|
107
132
|
* The change line under a stat: 'Up 12% from last week', 'Down 5% from last week', 'No change from last week',
|
|
108
133
|
* 'New this week' (the previous value was 0). With no previous value there is nothing to compare: direction null, no text.
|
|
134
|
+
* With `as: 'points'`, `value` and `previous` are shares (fractions) and the change is in percentage points:
|
|
135
|
+
* 'Up 3 pts from last week', 'Down 1 pt from last week', 'Up < 1 pt from last week'. A share of 0 is a value, so there is no 'New'.
|
|
109
136
|
*/
|
|
110
|
-
export function formatChange(value, previous, period) {
|
|
137
|
+
export function formatChange(value, previous, period, _a) {
|
|
111
138
|
if (period === void 0) { period = 'week'; }
|
|
139
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.as, as = _c === void 0 ? 'relative' : _c;
|
|
112
140
|
if (!finite(value) || !finite(previous))
|
|
113
141
|
return { direction: null, text: '' };
|
|
114
142
|
// 'last day' and 'this day' are not English
|
|
@@ -116,6 +144,13 @@ export function formatChange(value, previous, period) {
|
|
|
116
144
|
var now = period === 'day' ? 'today' : "this ".concat(period);
|
|
117
145
|
if (value === previous)
|
|
118
146
|
return { direction: 'same', text: "No change from ".concat(from) };
|
|
147
|
+
if (as === 'points') {
|
|
148
|
+
var points = Math.round(Math.abs(value - previous) * 100);
|
|
149
|
+
var amount = points === 0 ? '< 1 pt' : "".concat(points, " ").concat(points === 1 ? 'pt' : 'pts');
|
|
150
|
+
return value > previous
|
|
151
|
+
? { direction: 'up', text: "Up ".concat(amount, " from ").concat(from) }
|
|
152
|
+
: { direction: 'down', text: "Down ".concat(amount, " from ").concat(from) };
|
|
153
|
+
}
|
|
119
154
|
if (previous === 0)
|
|
120
155
|
return { direction: 'new', text: "New ".concat(now) };
|
|
121
156
|
var share = formatPercent(Math.abs(value - previous) / Math.abs(previous));
|
|
@@ -18,13 +18,15 @@ interface ClusterProps extends LayoutProps {
|
|
|
18
18
|
}
|
|
19
19
|
export declare function Cluster({ children, gap, justify, align, className }: ClusterProps): React.JSX.Element;
|
|
20
20
|
interface GridProps extends LayoutProps {
|
|
21
|
-
/** How many columns from the
|
|
21
|
+
/** How many columns from the breakpoint `from` up. Below it: two for `compact`, otherwise one. */
|
|
22
22
|
columns?: 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
|
23
|
+
/** The breakpoint the columns start at. Default `md`. Use `lg` inside an `AppShell`, where the sidebar takes the room from md. */
|
|
24
|
+
from?: 'md' | 'lg';
|
|
23
25
|
compact?: boolean;
|
|
24
26
|
/** `stretch` makes the items in a row the same height; `start` lets each keep its own. */
|
|
25
27
|
align?: 'stretch' | 'start';
|
|
26
28
|
}
|
|
27
|
-
export declare function Grid({ children, columns, compact, align, gap, className }: GridProps): React.JSX.Element;
|
|
29
|
+
export declare function Grid({ children, columns, from, compact, align, gap, className }: GridProps): React.JSX.Element;
|
|
28
30
|
export declare function PageSection({ children, gap, className }: LayoutProps): React.JSX.Element;
|
|
29
31
|
interface CenterProps {
|
|
30
32
|
children: React.ReactNode;
|
|
@@ -32,9 +32,20 @@ var mdColumns = {
|
|
|
32
32
|
9: 'md:grid-cols-9',
|
|
33
33
|
10: 'md:grid-cols-10',
|
|
34
34
|
};
|
|
35
|
+
var lgColumns = {
|
|
36
|
+
2: 'lg:grid-cols-2',
|
|
37
|
+
3: 'lg:grid-cols-3',
|
|
38
|
+
4: 'lg:grid-cols-4',
|
|
39
|
+
5: 'lg:grid-cols-5',
|
|
40
|
+
6: 'lg:grid-cols-6',
|
|
41
|
+
7: 'lg:grid-cols-7',
|
|
42
|
+
8: 'lg:grid-cols-8',
|
|
43
|
+
9: 'lg:grid-cols-9',
|
|
44
|
+
10: 'lg:grid-cols-10',
|
|
45
|
+
};
|
|
35
46
|
export function Grid(_a) {
|
|
36
|
-
var children = _a.children, _b = _a.columns, columns = _b === void 0 ? 2 : _b, _c = _a.
|
|
37
|
-
return (<div className={"grid ".concat(compact ? 'grid-cols-2' : 'grid-cols-1', " ").concat(mdColumns[columns], " ").concat(align === 'start' ? 'items-start' : '', " ").concat(gaps[gap], " ").concat(className)}>
|
|
47
|
+
var children = _a.children, _b = _a.columns, columns = _b === void 0 ? 2 : _b, _c = _a.from, from = _c === void 0 ? 'md' : _c, _d = _a.compact, compact = _d === void 0 ? false : _d, _e = _a.align, align = _e === void 0 ? 'stretch' : _e, _f = _a.gap, gap = _f === void 0 ? 'large' : _f, _g = _a.className, className = _g === void 0 ? '' : _g;
|
|
48
|
+
return (<div className={"grid ".concat(compact ? 'grid-cols-2' : 'grid-cols-1', " ").concat((from === 'lg' ? lgColumns : mdColumns)[columns], " ").concat(align === 'start' ? 'items-start' : '', " ").concat(gaps[gap], " ").concat(className)}>
|
|
38
49
|
{children}
|
|
39
50
|
</div>);
|
|
40
51
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type MdBlock, type MdInline } from '../internal/markdown';
|
|
3
|
+
export type { MdBlock, MdInline };
|
|
4
|
+
export interface MarkdownProps {
|
|
5
|
+
/** Prefixes the ids of the code blocks: `${id}-code-0`, `${id}-code-1` */
|
|
6
|
+
id: string;
|
|
7
|
+
/** The message's markdown. Only a subset is read; the rest shows as text, and HTML is never run. */
|
|
8
|
+
text: string;
|
|
9
|
+
/**
|
|
10
|
+
* The element a `#` heading becomes; `##` and `###` go one level down, never past h4.
|
|
11
|
+
* Pick the level under the heading the message sits beneath, so the page's outline holds.
|
|
12
|
+
*/
|
|
13
|
+
headingLevel?: 2 | 3;
|
|
14
|
+
/** The size of paragraphs and lists */
|
|
15
|
+
size?: 'body1' | 'body2';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A message's markdown set in ODS parts: Heading, Paragraph, List, CodeBlock, Link and Line. The subset is
|
|
19
|
+
* headings (`#` to `###`), lists one level deep, fenced code, rules, bold, italic, inline code and links.
|
|
20
|
+
* A table shows as a code block named 'Table', an image as its alt text, and HTML as text. Only http, https
|
|
21
|
+
* and mailto links become links. A fence that is still open (a reply still streaming) runs to the end.
|
|
22
|
+
*/
|
|
23
|
+
export default function Markdown({ id, text, headingLevel, size }: MarkdownProps): React.JSX.Element;
|
|
24
|
+
export { Markdown };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { parseMarkdown } from '../internal/markdown';
|
|
3
|
+
import CodeBlock from './codeBlock';
|
|
4
|
+
import Heading from './heading';
|
|
5
|
+
import { Stack } from './layout';
|
|
6
|
+
import Line from './line';
|
|
7
|
+
import Link from './link';
|
|
8
|
+
import List from './list';
|
|
9
|
+
import Paragraph from './paragraph';
|
|
10
|
+
function Inline(_a) {
|
|
11
|
+
var nodes = _a.nodes, size = _a.size;
|
|
12
|
+
return (<>
|
|
13
|
+
{nodes.map(function (node, i) {
|
|
14
|
+
switch (node.type) {
|
|
15
|
+
case 'text':
|
|
16
|
+
return <React.Fragment key={i}>{node.text}</React.Fragment>;
|
|
17
|
+
case 'strong':
|
|
18
|
+
return (<strong key={i}>
|
|
19
|
+
<Inline nodes={node.children} size={size}/>
|
|
20
|
+
</strong>);
|
|
21
|
+
case 'em':
|
|
22
|
+
return (<em key={i}>
|
|
23
|
+
<Inline nodes={node.children} size={size}/>
|
|
24
|
+
</em>);
|
|
25
|
+
case 'code':
|
|
26
|
+
return (<code key={i} className="font-mono text-[0.9em] rounded bg-background-accent200 px-1">
|
|
27
|
+
{node.text}
|
|
28
|
+
</code>);
|
|
29
|
+
case 'link':
|
|
30
|
+
// A link in a reply opens a new tab and says so, so the person keeps the conversation. mailto stays.
|
|
31
|
+
return node.href.startsWith('mailto:') ? (<Link key={i} href={node.href} size={size}>
|
|
32
|
+
<Inline nodes={node.children} size={size}/>
|
|
33
|
+
</Link>) : (<Link key={i} href={node.href} size={size} openInNewTab announceNewTab>
|
|
34
|
+
<Inline nodes={node.children} size={size}/>
|
|
35
|
+
</Link>);
|
|
36
|
+
}
|
|
37
|
+
})}
|
|
38
|
+
</>);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A message's markdown set in ODS parts: Heading, Paragraph, List, CodeBlock, Link and Line. The subset is
|
|
42
|
+
* headings (`#` to `###`), lists one level deep, fenced code, rules, bold, italic, inline code and links.
|
|
43
|
+
* A table shows as a code block named 'Table', an image as its alt text, and HTML as text. Only http, https
|
|
44
|
+
* and mailto links become links. A fence that is still open (a reply still streaming) runs to the end.
|
|
45
|
+
*/
|
|
46
|
+
export default function Markdown(_a) {
|
|
47
|
+
var id = _a.id, text = _a.text, _b = _a.headingLevel, headingLevel = _b === void 0 ? 3 : _b, _c = _a.size, size = _c === void 0 ? 'body1' : _c;
|
|
48
|
+
var blocks = parseMarkdown(text);
|
|
49
|
+
var codeCount = 0;
|
|
50
|
+
var renderBlock = function (block, key, className) {
|
|
51
|
+
if (className === void 0) { className = ''; }
|
|
52
|
+
switch (block.type) {
|
|
53
|
+
case 'heading':
|
|
54
|
+
return (<Heading key={key} level={Math.min(headingLevel + block.depth - 1, 4)} size={block.depth === 1 ? 'h6' : 'subtitle1'} className={className}>
|
|
55
|
+
<Inline nodes={block.children} size={block.depth === 1 ? 'h6' : 'subtitle1'}/>
|
|
56
|
+
</Heading>);
|
|
57
|
+
case 'paragraph':
|
|
58
|
+
return (<Paragraph key={key} measure="none" size={size} className={className}>
|
|
59
|
+
<Inline nodes={block.children} size={size}/>
|
|
60
|
+
</Paragraph>);
|
|
61
|
+
case 'list':
|
|
62
|
+
return (<List key={key} marker={block.ordered ? 'number' : 'dot'} size={size} className={className} items={block.items.map(function (item) {
|
|
63
|
+
return item.map(function (child, j) {
|
|
64
|
+
// The item's first line sits beside its marker; what follows starts a little below
|
|
65
|
+
return j === 0 && child.type === 'paragraph' ? (<Inline key={j} nodes={child.children} size={size}/>) : child.type === 'code' ? (<div key={j} className={j === 0 ? '' : 'mt-medium'}>
|
|
66
|
+
{renderBlock(child, j)}
|
|
67
|
+
</div>) : (renderBlock(child, j, j === 0 ? '' : 'mt-medium'));
|
|
68
|
+
});
|
|
69
|
+
})}/>);
|
|
70
|
+
case 'code': {
|
|
71
|
+
var n = codeCount;
|
|
72
|
+
codeCount += 1;
|
|
73
|
+
return (<CodeBlock key={key} id={"".concat(id, "-code-").concat(n)} label={block.table ? 'Table' : block.language ? "".concat(block.language, " code") : 'Code'} code={block.code}/>);
|
|
74
|
+
}
|
|
75
|
+
case 'rule':
|
|
76
|
+
return <Line key={key} className={className}/>;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
return <Stack gap="medium">{blocks.map(function (block, i) { return renderBlock(block, i); })}</Stack>;
|
|
80
|
+
}
|
|
81
|
+
export { Markdown };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
interface PageShellProps extends React.ComponentPropsWithoutRef<'main'> {
|
|
2
|
+
export interface PageShellProps extends React.ComponentPropsWithoutRef<'main'> {
|
|
3
3
|
children: React.ReactNode;
|
|
4
4
|
/** Let the column grow from the 2xl breakpoint, for pages with wide figures. */
|
|
5
5
|
wide?: boolean;
|
|
@@ -12,5 +12,5 @@ interface PageShellProps extends React.ComponentPropsWithoutRef<'main'> {
|
|
|
12
12
|
*/
|
|
13
13
|
aside?: React.ReactNode;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
export
|
|
15
|
+
declare const PageShell: React.ForwardRefExoticComponent<PageShellProps & React.RefAttributes<HTMLElement>>;
|
|
16
|
+
export default PageShell;
|
|
@@ -11,12 +11,12 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import React from 'react';
|
|
13
13
|
// The frame of a page: the column, its side space, and the space between sections.
|
|
14
|
-
// Anything else given (data-* attributes, an id) goes to the <main>.
|
|
15
|
-
|
|
14
|
+
// Anything else given (data-* attributes, an id) goes to the <main>. So does a ref, so a page can move focus there (with tabIndex -1).
|
|
15
|
+
var PageShell = React.forwardRef(function PageShell(_a, ref) {
|
|
16
16
|
var children = _a.children, _b = _a.wide, wide = _b === void 0 ? false : _b, _c = _a.fluid, fluid = _c === void 0 ? false : _c, aside = _a.aside, _d = _a.className, className = _d === void 0 ? '' : _d, rest = __rest(_a, ["children", "wide", "fluid", "aside", "className"]);
|
|
17
17
|
if (aside) {
|
|
18
18
|
// The page column and the aside sit side by side from xl, centered together
|
|
19
|
-
return (<main className={"min-h-screen [&_:is(h2,h3)[id]]:scroll-mt-[var(--os-header-offset,0px)] ".concat(className)} {...rest}>
|
|
19
|
+
return (<main ref={ref} className={"min-h-screen [&_:is(h2,h3)[id]]:scroll-mt-[var(--os-header-offset,0px)] ".concat(className)} {...rest}>
|
|
20
20
|
<div className="mx-auto flex w-full items-start justify-center">
|
|
21
21
|
<div className={"flex min-w-0 w-full flex-col gap-section px-xlarge pb-page pt-giant md:px-xxlarge ".concat(fluid ? '' : "max-w-page ".concat(wide ? '2xl:max-w-page-wide' : ''))}>
|
|
22
22
|
{children}
|
|
@@ -27,9 +27,10 @@ export default function PageShell(_a) {
|
|
|
27
27
|
</div>
|
|
28
28
|
</main>);
|
|
29
29
|
}
|
|
30
|
-
return (<main className={"min-h-screen ".concat(className)} {...rest}>
|
|
30
|
+
return (<main ref={ref} className={"min-h-screen ".concat(className)} {...rest}>
|
|
31
31
|
<div className={"mx-auto flex w-full flex-col gap-section px-xlarge pb-page pt-giant md:px-xxlarge ".concat(fluid ? '' : "max-w-page ".concat(wide ? '2xl:max-w-page-wide' : ''))}>
|
|
32
32
|
{children}
|
|
33
33
|
</div>
|
|
34
34
|
</main>);
|
|
35
|
-
}
|
|
35
|
+
});
|
|
36
|
+
export default PageShell;
|
|
@@ -11,6 +11,10 @@ interface PopoverProps {
|
|
|
11
11
|
* Popover also closes it (`onClose`) and focuses `anchorEl`. Pass the focusable trigger as `anchorEl`.
|
|
12
12
|
*/
|
|
13
13
|
returnFocus?: boolean;
|
|
14
|
+
/** The dialog's name. Give one unless the content is a `navigable` (or `role`d) `Menu` with its own `aria-label`: that Menu names itself, and the Popover around it stays unnamed so it is not heard twice. */
|
|
15
|
+
'aria-label'?: string;
|
|
16
|
+
/** The id of the element that names the dialog, as an alternative to `aria-label`. */
|
|
17
|
+
'aria-labelledby'?: string;
|
|
14
18
|
}
|
|
15
|
-
export default function Popover({ id, anchorEl, open, onClose, children, returnFocus, }: PopoverProps): React.ReactPortal | null;
|
|
19
|
+
export default function Popover({ id, anchorEl, open, onClose, children, returnFocus, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, }: PopoverProps): React.ReactPortal | null;
|
|
16
20
|
export {};
|
|
@@ -7,7 +7,7 @@ import { useOverlayTransition } from './useOverlayTransition';
|
|
|
7
7
|
import Menu from './menu';
|
|
8
8
|
import { isInTopOverlay } from '../internal/overlayStack';
|
|
9
9
|
export default function Popover(_a) {
|
|
10
|
-
var id = _a.id, anchorEl = _a.anchorEl, open = _a.open, onClose = _a.onClose, children = _a.children, _b = _a.returnFocus, returnFocus = _b === void 0 ? false : _b;
|
|
10
|
+
var id = _a.id, anchorEl = _a.anchorEl, open = _a.open, onClose = _a.onClose, children = _a.children, _b = _a.returnFocus, returnFocus = _b === void 0 ? false : _b, ariaLabel = _a["aria-label"], ariaLabelledby = _a["aria-labelledby"];
|
|
11
11
|
var _c = useState(null), popoverElement = _c[0], setPopoverElement = _c[1];
|
|
12
12
|
var _d = useState(false), hasMounted = _d[0], setHasMounted = _d[1];
|
|
13
13
|
var _e = useOverlayTransition(open), mounted = _e.mounted, visible = _e.visible;
|
|
@@ -83,12 +83,13 @@ export default function Popover(_a) {
|
|
|
83
83
|
// A Menu brings its own surface (4px inset, container corners), so the
|
|
84
84
|
// popover adds none around it rather than doubling the padding and edges.
|
|
85
85
|
var isMenu = isValidElement(children) && children.type === Menu;
|
|
86
|
+
var dialogLabel = ariaLabelledby ? undefined : ariaLabel;
|
|
86
87
|
var panelClass = isMenu
|
|
87
88
|
? ''
|
|
88
89
|
: 'bg-background-overlay dark:ring-1 dark:ring-misc-divider rounded-control shadow-overlay p-2';
|
|
89
90
|
// Render popover in a portal to prevent layout shifts and positioning issues
|
|
90
91
|
// dark-only edge: a ring only in dark mode, so it keeps a dark: variant (it follows whatever dark variant the app's preset/@theme defines, class-only or OS-aware)
|
|
91
|
-
return createPortal(<div id={id} ref={setPopoverElement} style={styles.popper} {...attributes.popper} className="z-[var(--os-z-overlay)]" role="dialog">
|
|
92
|
+
return createPortal(<div id={id} ref={setPopoverElement} style={styles.popper} {...attributes.popper} className="z-[var(--os-z-overlay)]" role="dialog" aria-label={dialogLabel} aria-labelledby={ariaLabelledby}>
|
|
92
93
|
{/* Popper owns the outer transform, so the fade and scale go on this inner panel */}
|
|
93
94
|
<div className={"".concat(panelClass, " origin-top-left\n ").concat(overlayTransition, " ").concat(visible ? overlayVisible : overlayHidden)}>
|
|
94
95
|
{children}
|
|
@@ -29,7 +29,7 @@ export default function Progress(_a) {
|
|
|
29
29
|
var text = valueText !== null && valueText !== void 0 ? valueText : (share ? withUnit("".concat(formatPercent(max > 0 ? value / max : 0), ", ").concat(formatCount(value))) : withUnit("".concat(formatCount(value), " of ").concat(formatCount(max))));
|
|
30
30
|
var suffix = share ? '' : status === 'error' ? (value > max ? ', over the limit' : ', at the limit') : status === 'warning' ? ', almost at the limit' : '';
|
|
31
31
|
var statusWords = { error: 'Limit reached', warning: 'Almost at the limit', primary: '' }[status];
|
|
32
|
-
var bar = { error: 'bg-error-main', warning: 'bg-warning-
|
|
32
|
+
var bar = { error: 'bg-error-main', warning: 'bg-warning-fill', primary: 'bg-accent-main' }[status];
|
|
33
33
|
var wordColor = { error: 'text-error-text', warning: 'text-warning-text', primary: '' }[status];
|
|
34
34
|
var percent = Math.min(100, Math.max(0, fraction * 100));
|
|
35
35
|
return (
|
|
@@ -59,6 +59,9 @@ export default function Select(_a) {
|
|
|
59
59
|
var menuRef = useRef(null);
|
|
60
60
|
var listboxId = useId();
|
|
61
61
|
var optionId = function (index) { return "".concat(listboxId, "-option-").concat(index); };
|
|
62
|
+
// Without an aria-label the shown value is the name. With one, the label is the name and the
|
|
63
|
+
// value is the combobox's value, which browsers expose from its contents.
|
|
64
|
+
var valueId = ariaLabel ? undefined : "".concat(listboxId, "-value");
|
|
62
65
|
// Synchronous lookup so the icon renders on the first paint
|
|
63
66
|
// Close menu when clicking outside
|
|
64
67
|
useEffect(function () {
|
|
@@ -210,7 +213,7 @@ export default function Select(_a) {
|
|
|
210
213
|
};
|
|
211
214
|
return (<div className={"relative ".concat(className)} style={{ width: width || '100%' }}>
|
|
212
215
|
{/* Select Button */}
|
|
213
|
-
<div ref={setTrigger} role="combobox" id={id} aria-label={ariaLabel} aria-describedby={ariaDescribedBy} aria-haspopup="listbox" aria-expanded={isOpen} aria-controls={listboxId} aria-activedescendant={isOpen && activeIndex >= 0 ? optionId(activeIndex) : undefined} aria-disabled={disabled || undefined} className={"\n rounded-control\n ".concat(getStateStyles(), "\n ").concat(disabled ? 'cursor-not-allowed' : 'cursor-pointer', "\n ").concat(stateTransition, "\n ").concat(focusRing, "\n ")} onClick={handleToggle} tabIndex={disabled ? -1 : 0} onKeyDown={handleKeyDown}>
|
|
216
|
+
<div ref={setTrigger} role="combobox" id={id} aria-label={ariaLabel} aria-labelledby={valueId} aria-describedby={ariaDescribedBy} aria-haspopup="listbox" aria-expanded={isOpen} aria-controls={listboxId} aria-activedescendant={isOpen && activeIndex >= 0 ? optionId(activeIndex) : undefined} aria-disabled={disabled || undefined} className={"\n rounded-control\n ".concat(getStateStyles(), "\n ").concat(disabled ? 'cursor-not-allowed' : 'cursor-pointer', "\n ").concat(stateTransition, "\n ").concat(focusRing, "\n ")} onClick={handleToggle} tabIndex={disabled ? -1 : 0} onKeyDown={handleKeyDown}>
|
|
214
217
|
{/* Inner Content Container; 7px vertical padding makes the control 40px like Button and TextField */}
|
|
215
218
|
<div className={"flex items-center justify-between px-2 py-[7px] ".concat(getTextColor())}>
|
|
216
219
|
{/* Content Container */}
|
|
@@ -219,7 +222,7 @@ export default function Select(_a) {
|
|
|
219
222
|
<IconSlot icon={decoIconName} className={"w-6 h-6 flex-shrink-0 ".concat(getIconColor())}/>
|
|
220
223
|
|
|
221
224
|
{/* Display Text */}
|
|
222
|
-
<span className="text-body1 truncate">
|
|
225
|
+
<span id={valueId} className="text-body1 truncate">
|
|
223
226
|
{getDisplayLabel()}
|
|
224
227
|
</span>
|
|
225
228
|
</div>
|
|
@@ -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=
|
|
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
|
}
|