oneslash-design-system 2.19.0 → 2.20.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 +28 -4
- package/dist/cases/billing-page/billed-elsewhere.d.ts +1 -0
- package/dist/cases/billing-page/billed-elsewhere.jsx +28 -0
- package/dist/cases/billing-page/self-serve.d.ts +1 -0
- package/dist/cases/billing-page/self-serve.jsx +134 -0
- package/dist/cases/billing-page.md +247 -0
- package/dist/cases/breakdown-list/bars.d.ts +1 -0
- package/dist/cases/breakdown-list/bars.jsx +47 -0
- package/dist/cases/breakdown-list/table.d.ts +1 -0
- package/dist/cases/breakdown-list/table.jsx +69 -0
- package/dist/cases/breakdown-list.md +158 -0
- package/dist/cases/composer-limit/notice-with-action.jsx +3 -3
- package/dist/cases/composer-limit/notice.jsx +3 -3
- package/dist/cases/composer-limit.md +8 -8
- package/dist/cases/dashboard/numbers-first.d.ts +1 -0
- package/dist/cases/dashboard/numbers-first.jsx +165 -0
- package/dist/cases/dashboard/work-first.d.ts +1 -0
- package/dist/cases/dashboard/work-first.jsx +165 -0
- package/dist/cases/dashboard.md +507 -0
- package/dist/cases/data-table-page/all-rows.d.ts +1 -0
- package/dist/cases/data-table-page/all-rows.jsx +226 -0
- package/dist/cases/data-table-page/paged.d.ts +1 -0
- package/dist/cases/data-table-page/paged.jsx +284 -0
- package/dist/cases/data-table-page.md +771 -0
- package/dist/cases/invoice-list/table.d.ts +1 -0
- package/dist/cases/invoice-list/table.jsx +64 -0
- package/dist/cases/invoice-list/with-upcoming.d.ts +1 -0
- package/dist/cases/invoice-list/with-upcoming.jsx +75 -0
- package/dist/cases/invoice-list.md +237 -0
- package/dist/cases/load-failure/inline.jsx +2 -2
- package/dist/cases/load-failure.md +2 -2
- package/dist/cases/members-list/rows.jsx +2 -1
- package/dist/cases/members-list/table.jsx +8 -9
- package/dist/cases/members-list.md +12 -13
- package/dist/cases/number-format.md +36 -0
- package/dist/cases/paged-card/pager.d.ts +1 -0
- package/dist/cases/paged-card/pager.jsx +41 -0
- package/dist/cases/paged-card/see-all.d.ts +1 -0
- package/dist/cases/paged-card/see-all.jsx +34 -0
- package/dist/cases/paged-card.md +147 -0
- package/dist/cases/payment-method/none.d.ts +1 -0
- package/dist/cases/payment-method/none.jsx +17 -0
- package/dist/cases/payment-method/on-file.d.ts +1 -0
- package/dist/cases/payment-method/on-file.jsx +92 -0
- package/dist/cases/payment-method.md +182 -0
- package/dist/cases/plan-change-confirm/blocked.d.ts +1 -0
- package/dist/cases/plan-change-confirm/blocked.jsx +48 -0
- package/dist/cases/plan-change-confirm/downgrade.d.ts +1 -0
- package/dist/cases/plan-change-confirm/downgrade.jsx +52 -0
- package/dist/cases/plan-change-confirm/upgrade.d.ts +1 -0
- package/dist/cases/plan-change-confirm/upgrade.jsx +51 -0
- package/dist/cases/plan-change-confirm.md +261 -0
- package/dist/cases/plan-picker/cards.d.ts +1 -0
- package/dist/cases/plan-picker/cards.jsx +97 -0
- package/dist/cases/plan-picker/list.d.ts +1 -0
- package/dist/cases/plan-picker/list.jsx +103 -0
- package/dist/cases/plan-picker.md +297 -0
- package/dist/cases/range-switch/segmented.jsx +11 -7
- package/dist/cases/range-switch.md +16 -11
- package/dist/cases/settings-page/top-tabs.jsx +4 -3
- package/dist/cases/settings-page.md +5 -4
- package/dist/cases/stat-row/featured.d.ts +1 -0
- package/dist/cases/stat-row/featured.jsx +17 -0
- package/dist/cases/stat-row/tiles.d.ts +1 -0
- package/dist/cases/stat-row/tiles.jsx +34 -0
- package/dist/cases/stat-row.md +104 -0
- package/dist/cases/status-label/dot.d.ts +1 -0
- package/dist/cases/status-label/dot.jsx +39 -0
- package/dist/cases/status-label/text.d.ts +1 -0
- package/dist/cases/status-label/text.jsx +44 -0
- package/dist/cases/status-label.md +143 -0
- package/dist/cases/upgrade-prompt/inline.jsx +4 -2
- package/dist/cases/upgrade-prompt/modal.jsx +2 -1
- package/dist/cases/upgrade-prompt.md +10 -6
- package/dist/cases/usage-meters/by-person.d.ts +1 -0
- package/dist/cases/usage-meters/by-person.jsx +72 -0
- package/dist/cases/usage-meters/meters.d.ts +1 -0
- package/dist/cases/usage-meters/meters.jsx +49 -0
- package/dist/cases/usage-meters/with-cap.d.ts +1 -0
- package/dist/cases/usage-meters/with-cap.jsx +73 -0
- package/dist/cases/usage-meters.md +303 -0
- package/dist/cases.json +956 -19
- package/dist/components/button.d.ts +1 -1
- package/dist/components/button.jsx +11 -5
- package/dist/components/formatNumber.d.ts +25 -0
- package/dist/components/formatNumber.js +125 -0
- package/dist/components/iconButton.jsx +12 -7
- package/dist/components/pagination.d.ts +28 -0
- package/dist/components/pagination.jsx +89 -0
- package/dist/components/progress.d.ts +33 -0
- package/dist/components/progress.jsx +50 -0
- package/dist/components/skeleton.d.ts +21 -0
- package/dist/components/skeleton.jsx +41 -0
- package/dist/components/statTile.d.ts +32 -0
- package/dist/components/statTile.jsx +61 -0
- package/dist/components/tableContainer.d.ts +5 -1
- package/dist/components/tableContainer.jsx +9 -1
- package/dist/components/tableHeaderCell.d.ts +3 -1
- package/dist/components/tableHeaderCell.jsx +2 -2
- package/dist/components/titleBar.d.ts +3 -1
- package/dist/components/titleBar.jsx +4 -3
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/native-mapping.json +26 -2
- package/dist/stories/Button.stories.d.ts +1 -0
- package/dist/stories/Button.stories.jsx +19 -1
- package/dist/stories/Cases.generated.stories.d.ts +26 -0
- package/dist/stories/Cases.generated.stories.jsx +52 -0
- package/dist/stories/Pagination.stories.d.ts +9 -0
- package/dist/stories/Pagination.stories.jsx +75 -0
- package/dist/stories/Progress.stories.d.ts +9 -0
- package/dist/stories/Progress.stories.jsx +43 -0
- package/dist/stories/Skeleton.stories.d.ts +7 -0
- package/dist/stories/Skeleton.stories.jsx +27 -0
- package/dist/stories/StatTile.stories.d.ts +10 -0
- package/dist/stories/StatTile.stories.jsx +55 -0
- package/dist/stories/Table.stories.d.ts +1 -0
- package/dist/stories/Table.stories.jsx +49 -1
- package/dist/stories/TitleBar.stories.d.ts +1 -0
- package/dist/stories/TitleBar.stories.jsx +7 -0
- package/package.json +5 -1
|
@@ -18,7 +18,7 @@ interface ButtonProps extends React.AriaAttributes {
|
|
|
18
18
|
onClickButton?: any;
|
|
19
19
|
onClickActionIcon?: () => void;
|
|
20
20
|
className?: string;
|
|
21
|
-
/** Shows a spinner in the icon slot
|
|
21
|
+
/** Shows a spinner in the icon slot and keeps the label. The button stays focusable (`aria-disabled`) and ignores presses, so a form cannot submit twice. */
|
|
22
22
|
loading?: boolean;
|
|
23
23
|
/** Renders a link that looks like the button. A path goes through `next/link`; an `http(s)://` URL is a plain `<a>`. */
|
|
24
24
|
href?: string;
|
|
@@ -94,11 +94,13 @@ var Button = forwardRef(function Button(_a, ref) {
|
|
|
94
94
|
// gets the press feedback for non-buttons and a zero-specificity fit width that `w-full` overrides.
|
|
95
95
|
var linkClasses = state === 'disabled' || loading ? '[:where(&)]:w-fit' : "[:where(&)]:w-fit ".concat(pressFeedbackAny);
|
|
96
96
|
// Hover is pure CSS; `state="hovered"` and `state="focused"` only exist to show those states in docs
|
|
97
|
-
var buttonClasses = "\n flex flex-row items-center rounded-control ".concat(justify, " ").concat(stateTransition, " ").concat(isLink ? linkClasses : pressFeedback, "\n ").concat(color === 'danger' ? focusRingDanger : focusRing, "\n ").concat(sizeClasses, "\n ").concat(state === 'selected' ? stateClasses.selected : '', "\n ").concat(state === 'enabled' || state === 'hovered' ? "".concat(baseTypeClasses, " ").concat(loading ? 'cursor-wait' : "".concat(stateClasses.enabled, " ").concat(hoverTypeClasses)) : '', "\n ").concat(state === 'focused' ? "".concat(baseTypeClasses, " ").concat(hoverTypeClasses, " ").concat(stateClasses.focused) : '', "\n ").concat(state === 'disabled' ? stateClasses.disabled : '', "\n ").concat(className, "\n ");
|
|
97
|
+
var buttonClasses = "\n flex flex-row items-center rounded-control ".concat(justify, " ").concat(stateTransition, " ").concat(isLink ? linkClasses : loading ? '' : pressFeedback, "\n ").concat(color === 'danger' ? focusRingDanger : focusRing, "\n ").concat(sizeClasses, "\n ").concat(state === 'selected' ? stateClasses.selected : '', "\n ").concat(state === 'enabled' || state === 'hovered' ? "".concat(baseTypeClasses, " ").concat(loading ? 'cursor-wait' : "".concat(stateClasses.enabled, " ").concat(hoverTypeClasses)) : '', "\n ").concat(state === 'focused' ? "".concat(baseTypeClasses, " ").concat(hoverTypeClasses, " ").concat(stateClasses.focused) : '', "\n ").concat(state === 'disabled' ? stateClasses.disabled : '', "\n ").concat(className, "\n ");
|
|
98
98
|
var content = (<>
|
|
99
99
|
{/* Group IconLeft and label in a flex container for left alignment */}
|
|
100
100
|
<div className={"flex items-center ".concat(size === 'tiny' ? 'gap-0.5' : 'gap-1')}>
|
|
101
|
-
{loading ? (
|
|
101
|
+
{loading ? (
|
|
102
|
+
// The spinner's own "Loading" status is hidden: the button keeps its name and says it is busy
|
|
103
|
+
<div aria-hidden="true"><LoadingSmall size={spinnerSize}/></div>) : (<IconSlot icon={decoIcon} className={"".concat(sizeIcon, " flex-shrink-0")}/>)}
|
|
102
104
|
<div className={"flex flex-col text-center px-1"}>
|
|
103
105
|
<span className="whitespace-nowrap overflow-hidden truncate">{label}</span>
|
|
104
106
|
{secondLabel && (<span className={"whitespace-nowrap overflow-hidden truncate ".concat(size === 'tiny' ? 'text-caption' : 'text-body2', " opacity-70")}>{secondLabel}</span>)}
|
|
@@ -106,7 +108,7 @@ var Button = forwardRef(function Button(_a, ref) {
|
|
|
106
108
|
</div>
|
|
107
109
|
{actionIcon && (<span onClick={function (e) {
|
|
108
110
|
// With no handler of its own, the icon is part of the button and the click goes through
|
|
109
|
-
if (!onClickActionIcon)
|
|
111
|
+
if (!onClickActionIcon || loading)
|
|
110
112
|
return;
|
|
111
113
|
// Don't also trigger the button's own click, or follow the link
|
|
112
114
|
e.stopPropagation();
|
|
@@ -120,7 +122,7 @@ var Button = forwardRef(function Button(_a, ref) {
|
|
|
120
122
|
if (isLink) {
|
|
121
123
|
// A link cannot be disabled: without an href it is not focusable and does nothing
|
|
122
124
|
if (state === 'disabled' || loading) {
|
|
123
|
-
return (<a {...rest} ref={ref} role="link" aria-disabled="true" aria-busy
|
|
125
|
+
return (<a {...rest} ref={ref} role="link" aria-disabled="true" {...(loading ? { 'aria-busy': true } : {})} className={buttonClasses}>
|
|
124
126
|
{content}
|
|
125
127
|
</a>);
|
|
126
128
|
}
|
|
@@ -131,7 +133,11 @@ var Button = forwardRef(function Button(_a, ref) {
|
|
|
131
133
|
}
|
|
132
134
|
return <NextLink href={href} replace={replace} {...linkProps} ref={ref}>{content}</NextLink>;
|
|
133
135
|
}
|
|
134
|
-
return (<button {...rest} ref={ref} type={htmlType} className={buttonClasses} disabled={state === 'disabled'
|
|
136
|
+
return (<button {...rest} ref={ref} type={htmlType} className={buttonClasses} disabled={state === 'disabled'}
|
|
137
|
+
// Spread, so a consumer's own aria-disabled and aria-busy survive when it is not loading
|
|
138
|
+
{...(loading ? { 'aria-disabled': true, 'aria-busy': true } : {})}
|
|
139
|
+
// While loading the button stays focusable but ignores presses; preventDefault also stops a form submit
|
|
140
|
+
onClick={loading ? function (e) { return e.preventDefault(); } : onClickButton}>
|
|
135
141
|
{content}
|
|
136
142
|
</button>);
|
|
137
143
|
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** '1,240'. With `compact`, from 10,000 up: '12.4K', '1.2M', '10B', '3.5T'. Below 10,000 it stays exact. */
|
|
2
|
+
export declare function formatCount(n: number, { compact }?: {
|
|
3
|
+
compact?: boolean;
|
|
4
|
+
}): string;
|
|
5
|
+
/** '$1,240.00' (two decimals). A non-zero amount under a cent is '< $0.01'. With `compact`, from 10,000 up: '$12.4K'. */
|
|
6
|
+
export declare function formatMoney(n: number, { currency, compact }?: {
|
|
7
|
+
currency?: string;
|
|
8
|
+
compact?: boolean;
|
|
9
|
+
}): string;
|
|
10
|
+
/** A fraction as a whole percent: 0.124 is '12%'. A small non-zero share is '< 1%'. */
|
|
11
|
+
export declare function formatPercent(fraction: number): string;
|
|
12
|
+
/** Base 1024. 'B' as is; KB and MB keep one decimal under 10 ('1.5 KB') and are whole from 10; GB and TB have one decimal. */
|
|
13
|
+
export declare function formatBytes(n: number): string;
|
|
14
|
+
/** '340 ms', '1.2 s', '4 min 10 s', '1 h 5 min'. */
|
|
15
|
+
export declare function formatDuration(ms: number): string;
|
|
16
|
+
export type ChangePeriod = 'day' | 'week' | 'month' | 'quarter' | 'year';
|
|
17
|
+
export type Change = {
|
|
18
|
+
direction: 'up' | 'down' | 'same' | 'new' | null;
|
|
19
|
+
text: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The change line under a stat: 'Up 12% from last week', 'Down 5% from last week', 'No change from last week',
|
|
23
|
+
* 'New this week' (the previous value was 0). With no previous value there is nothing to compare: direction null, no text.
|
|
24
|
+
*/
|
|
25
|
+
export declare function formatChange(value: number | null | undefined, previous: number | null | undefined, period?: ChangePeriod): Change;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
// Number formatting for counts, money, shares, sizes, durations and change lines.
|
|
13
|
+
// One fixed locale ('en-US') so a server and a browser print the same string and nothing mismatches on hydration.
|
|
14
|
+
var LOCALE = 'en-US';
|
|
15
|
+
var COMPACT_FROM = 10000;
|
|
16
|
+
var DASH = '–';
|
|
17
|
+
var finite = function (n) { return typeof n === 'number' && Number.isFinite(n); };
|
|
18
|
+
var exact = new Intl.NumberFormat(LOCALE, { maximumFractionDigits: 20 });
|
|
19
|
+
var whole = new Intl.NumberFormat(LOCALE, { maximumFractionDigits: 0 });
|
|
20
|
+
var oneDecimal = new Intl.NumberFormat(LOCALE, { maximumFractionDigits: 1 });
|
|
21
|
+
var compactCount = new Intl.NumberFormat(LOCALE, { notation: 'compact', maximumFractionDigits: 1 });
|
|
22
|
+
var percent = new Intl.NumberFormat(LOCALE, { style: 'percent', maximumFractionDigits: 0 });
|
|
23
|
+
var money = function (currency, compact) {
|
|
24
|
+
return new Intl.NumberFormat(LOCALE, __assign({ style: 'currency', currency: currency }, (compact
|
|
25
|
+
? { notation: 'compact', minimumFractionDigits: 0, maximumFractionDigits: 1 }
|
|
26
|
+
: { minimumFractionDigits: 2, maximumFractionDigits: 2 })));
|
|
27
|
+
};
|
|
28
|
+
/** '1,240'. With `compact`, from 10,000 up: '12.4K', '1.2M', '10B', '3.5T'. Below 10,000 it stays exact. */
|
|
29
|
+
export function formatCount(n, _a) {
|
|
30
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.compact, compact = _c === void 0 ? false : _c;
|
|
31
|
+
if (!finite(n))
|
|
32
|
+
return DASH;
|
|
33
|
+
// -0 would print '-0'
|
|
34
|
+
if (n === 0)
|
|
35
|
+
n = 0;
|
|
36
|
+
if (compact && Math.abs(n) >= COMPACT_FROM)
|
|
37
|
+
return compactCount.format(n);
|
|
38
|
+
return exact.format(n);
|
|
39
|
+
}
|
|
40
|
+
/** '$1,240.00' (two decimals). A non-zero amount under a cent is '< $0.01'. With `compact`, from 10,000 up: '$12.4K'. */
|
|
41
|
+
export function formatMoney(n, _a) {
|
|
42
|
+
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
|
+
if (!finite(n))
|
|
44
|
+
return DASH;
|
|
45
|
+
// -0 would print '-$0.00'
|
|
46
|
+
if (n === 0)
|
|
47
|
+
n = 0;
|
|
48
|
+
if (n !== 0 && Math.abs(n) < 0.005) {
|
|
49
|
+
var cent = money(currency, false).format(0.01);
|
|
50
|
+
return n > 0 ? "< ".concat(cent) : "> -".concat(cent);
|
|
51
|
+
}
|
|
52
|
+
return money(currency, compact && Math.abs(n) >= COMPACT_FROM).format(n);
|
|
53
|
+
}
|
|
54
|
+
/** A fraction as a whole percent: 0.124 is '12%'. A small non-zero share is '< 1%'. */
|
|
55
|
+
export function formatPercent(fraction) {
|
|
56
|
+
if (!finite(fraction))
|
|
57
|
+
return DASH;
|
|
58
|
+
// -0 would print '-0%'
|
|
59
|
+
if (fraction === 0)
|
|
60
|
+
fraction = 0;
|
|
61
|
+
var whole100 = Math.round(Math.abs(fraction) * 100);
|
|
62
|
+
if (fraction !== 0 && whole100 === 0)
|
|
63
|
+
return fraction > 0 ? '< 1%' : '> -1%';
|
|
64
|
+
// A share that is not full never reads 100%
|
|
65
|
+
if (Math.abs(fraction) < 1 && whole100 >= 100)
|
|
66
|
+
return fraction > 0 ? '99%' : '-99%';
|
|
67
|
+
return percent.format(fraction);
|
|
68
|
+
}
|
|
69
|
+
/** Base 1024. 'B' as is; KB and MB keep one decimal under 10 ('1.5 KB') and are whole from 10; GB and TB have one decimal. */
|
|
70
|
+
export function formatBytes(n) {
|
|
71
|
+
if (!finite(n))
|
|
72
|
+
return DASH;
|
|
73
|
+
var sign = n < 0 ? '-' : '';
|
|
74
|
+
var v = Math.abs(n);
|
|
75
|
+
if (v < 1024)
|
|
76
|
+
return "".concat(sign).concat(whole.format(v), " B");
|
|
77
|
+
var units = ['KB', 'MB', 'GB', 'TB'];
|
|
78
|
+
var i = 0;
|
|
79
|
+
v /= 1024;
|
|
80
|
+
// Rounding can carry into the next unit ('1,023.99 KB' is '1 MB')
|
|
81
|
+
while (i < units.length - 1 && (v >= 1024 || Math.round(v) >= 1024)) {
|
|
82
|
+
v /= 1024;
|
|
83
|
+
i += 1;
|
|
84
|
+
}
|
|
85
|
+
var unit = units[i];
|
|
86
|
+
var text = unit === 'KB' || unit === 'MB' ? (v < 10 ? oneDecimal.format(v) : whole.format(v)) : oneDecimal.format(v);
|
|
87
|
+
return "".concat(sign).concat(text, " ").concat(unit);
|
|
88
|
+
}
|
|
89
|
+
/** '340 ms', '1.2 s', '4 min 10 s', '1 h 5 min'. */
|
|
90
|
+
export function formatDuration(ms) {
|
|
91
|
+
if (!finite(ms))
|
|
92
|
+
return DASH;
|
|
93
|
+
var t = Math.max(0, ms);
|
|
94
|
+
if (t < 999.5)
|
|
95
|
+
return "".concat(whole.format(t), " ms");
|
|
96
|
+
if (t < 59950)
|
|
97
|
+
return "".concat(oneDecimal.format(t / 1000), " s");
|
|
98
|
+
var total = Math.round(t / 1000);
|
|
99
|
+
var h = Math.floor(total / 3600);
|
|
100
|
+
var m = Math.floor((total % 3600) / 60);
|
|
101
|
+
var s = total % 60;
|
|
102
|
+
if (h > 0)
|
|
103
|
+
return m > 0 ? "".concat(h, " h ").concat(m, " min") : "".concat(h, " h");
|
|
104
|
+
return s > 0 ? "".concat(m, " min ").concat(s, " s") : "".concat(m, " min");
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The change line under a stat: 'Up 12% from last week', 'Down 5% from last week', 'No change from last week',
|
|
108
|
+
* 'New this week' (the previous value was 0). With no previous value there is nothing to compare: direction null, no text.
|
|
109
|
+
*/
|
|
110
|
+
export function formatChange(value, previous, period) {
|
|
111
|
+
if (period === void 0) { period = 'week'; }
|
|
112
|
+
if (!finite(value) || !finite(previous))
|
|
113
|
+
return { direction: null, text: '' };
|
|
114
|
+
// 'last day' and 'this day' are not English
|
|
115
|
+
var from = period === 'day' ? 'yesterday' : "last ".concat(period);
|
|
116
|
+
var now = period === 'day' ? 'today' : "this ".concat(period);
|
|
117
|
+
if (value === previous)
|
|
118
|
+
return { direction: 'same', text: "No change from ".concat(from) };
|
|
119
|
+
if (previous === 0)
|
|
120
|
+
return { direction: 'new', text: "New ".concat(now) };
|
|
121
|
+
var share = formatPercent(Math.abs(value - previous) / Math.abs(previous));
|
|
122
|
+
return value > previous
|
|
123
|
+
? { direction: 'up', text: "Up ".concat(share, " from ").concat(from) }
|
|
124
|
+
: { direction: 'down', text: "Down ".concat(share, " from ").concat(from) };
|
|
125
|
+
}
|
|
@@ -69,10 +69,10 @@ var IconButton = forwardRef(function IconButton(_a, ref) {
|
|
|
69
69
|
: color === 'secondary'
|
|
70
70
|
? 'hover:bg-secondary-dark/75' // Secondary
|
|
71
71
|
: 'hover:bg-background-accent200/75'; // Tertiary and iconOnly
|
|
72
|
-
// Background hover color; `enabled:` skips it while disabled
|
|
72
|
+
// Background hover color; `enabled:` skips it while disabled, and a loading button gets none
|
|
73
73
|
var bgColorHover = isLink
|
|
74
74
|
? bgColorHoverLink
|
|
75
|
-
: state === 'selected'
|
|
75
|
+
: state === 'selected' || loading
|
|
76
76
|
? '' // No hover effect when selected
|
|
77
77
|
: color === 'primary'
|
|
78
78
|
? 'enabled:hover:bg-accent-dark/75' // Primary
|
|
@@ -103,13 +103,15 @@ var IconButton = forwardRef(function IconButton(_a, ref) {
|
|
|
103
103
|
: 'cursor-pointer';
|
|
104
104
|
// A <button> shrinks to its content and `enabled:` matches it. An <a> does neither, so a link
|
|
105
105
|
// gets the press feedback for non-buttons and a zero-specificity fit width a width class overrides.
|
|
106
|
-
var press = isLink ? "[:where(&)]:w-fit ".concat(isDisabled || loading ? '' : pressFeedbackAny) : pressFeedback;
|
|
106
|
+
var press = isLink ? "[:where(&)]:w-fit ".concat(isDisabled || loading ? '' : pressFeedbackAny) : loading ? '' : pressFeedback;
|
|
107
107
|
var className = "".concat(baseClasses, " ").concat(bgColor, " ").concat(iconColor, " ").concat(bgColorHover, " ").concat(stateClasses, " ").concat(stateTransition, " ").concat(press, " ").concat(focusRing, " flex items-center justify-center");
|
|
108
|
-
var content = loading ? (
|
|
108
|
+
var content = loading ? (
|
|
109
|
+
// The spinner's own "Loading" status is hidden: the button keeps its name and says it is busy
|
|
110
|
+
<div aria-hidden="true"><LoadingSmall size={size}/></div>) : (<IconSlot icon={icon !== null && icon !== void 0 ? icon : iconName} className={iconSizeClasses[size]}/>);
|
|
109
111
|
if (isLink) {
|
|
110
112
|
// A link cannot be disabled: without an href it is not focusable and does nothing
|
|
111
113
|
if (isDisabled || loading) {
|
|
112
|
-
return (<a {...rest} ref={ref} role="link" aria-disabled="true" className={className} aria-label={
|
|
114
|
+
return (<a {...rest} ref={ref} role="link" aria-disabled="true" {...(loading ? { 'aria-busy': true } : {})} className={className} aria-label={label}>
|
|
113
115
|
{content}
|
|
114
116
|
</a>);
|
|
115
117
|
}
|
|
@@ -120,8 +122,11 @@ var IconButton = forwardRef(function IconButton(_a, ref) {
|
|
|
120
122
|
}
|
|
121
123
|
return <NextLink href={href} replace={replace} {...linkProps} ref={ref}>{content}</NextLink>;
|
|
122
124
|
}
|
|
123
|
-
return (<button {...rest} ref={ref} type="button" className={className} disabled={isDisabled
|
|
124
|
-
|
|
125
|
+
return (<button {...rest} ref={ref} type="button" className={className} disabled={isDisabled}
|
|
126
|
+
// Spread, so a consumer's own aria-disabled and aria-busy survive when it is not loading
|
|
127
|
+
{...(loading ? { 'aria-disabled': true, 'aria-busy': true } : {})}
|
|
128
|
+
// While loading the button stays focusable but ignores presses
|
|
129
|
+
onClick={loading ? function (e) { return e.preventDefault(); } : onClick} aria-label={label}>
|
|
125
130
|
{content}
|
|
126
131
|
</button>);
|
|
127
132
|
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface PaginationProps {
|
|
3
|
+
/** The page being shown, counted from 1. */
|
|
4
|
+
page: number;
|
|
5
|
+
/** How many pages there are. With 1 or fewer, nothing renders. */
|
|
6
|
+
pageCount: number;
|
|
7
|
+
/** Called with the page asked for. Also called with the last page when `page` is past `pageCount` (a filter left fewer pages). */
|
|
8
|
+
onPageChange?: (page: number) => void;
|
|
9
|
+
/** Names the navigation. Defaults to 'Pages'. */
|
|
10
|
+
'aria-label'?: string;
|
|
11
|
+
/** `default` is 'Previous', 'Page 3 of 12' and 'Next'. `compact` is two small arrows and '2 of 5', for a card. */
|
|
12
|
+
variant?: 'default' | 'compact';
|
|
13
|
+
/** Makes Previous and Next links to the address of that page, with `rel="prev"` and `rel="next"`. `onPageChange` is still called. */
|
|
14
|
+
getHref?: (page: number) => string;
|
|
15
|
+
/**
|
|
16
|
+
* The id of the element (the table) to scroll to the top of the view after a press of Previous or Next. Instant under
|
|
17
|
+
* reduced motion. Focus stays on Next so a keyboard user keeps paging, and the live region announces the page.
|
|
18
|
+
* A page set from outside (a filter reset) does not scroll.
|
|
19
|
+
*/
|
|
20
|
+
scrollTargetId?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Previous and Next with the page named in words. There are no numbered buttons: they do not fit a phone or 500 pages.
|
|
24
|
+
* The page text is a polite live region. When the press that reaches the first or last page leaves focus on a
|
|
25
|
+
* disabled button, focus moves to the other one.
|
|
26
|
+
*/
|
|
27
|
+
export default function Pagination({ page, pageCount, onPageChange, 'aria-label': ariaLabel, variant, getHref, scrollTargetId, }: PaginationProps): React.JSX.Element | null;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { useEffect, useRef } from 'react';
|
|
3
|
+
import Button from './button';
|
|
4
|
+
import IconButton from './iconButton';
|
|
5
|
+
import { formatCount } from './formatNumber';
|
|
6
|
+
/**
|
|
7
|
+
* Previous and Next with the page named in words. There are no numbered buttons: they do not fit a phone or 500 pages.
|
|
8
|
+
* The page text is a polite live region. When the press that reaches the first or last page leaves focus on a
|
|
9
|
+
* disabled button, focus moves to the other one.
|
|
10
|
+
*/
|
|
11
|
+
export default function Pagination(_a) {
|
|
12
|
+
var page = _a.page, pageCount = _a.pageCount, onPageChange = _a.onPageChange, _b = _a["aria-label"], ariaLabel = _b === void 0 ? 'Pages' : _b, _c = _a.variant, variant = _c === void 0 ? 'default' : _c, getHref = _a.getHref, scrollTargetId = _a.scrollTargetId;
|
|
13
|
+
var navRef = useRef(null);
|
|
14
|
+
var prevRef = useRef(null);
|
|
15
|
+
var nextRef = useRef(null);
|
|
16
|
+
var pending = useRef(null);
|
|
17
|
+
var onChange = useRef(onPageChange);
|
|
18
|
+
onChange.current = onPageChange;
|
|
19
|
+
var lastPage = useRef(page);
|
|
20
|
+
// The page a press of Previous or Next asked for, so only reaching it scrolls: a parent resetting the page, the clamp and the first render do not
|
|
21
|
+
var pressed = useRef(null);
|
|
22
|
+
var last = Math.max(1, pageCount);
|
|
23
|
+
var shown = Math.max(1, Math.min(page, last));
|
|
24
|
+
// A filter that leaves fewer pages than the one being shown
|
|
25
|
+
useEffect(function () {
|
|
26
|
+
var _a;
|
|
27
|
+
if (page > pageCount)
|
|
28
|
+
(_a = onChange.current) === null || _a === void 0 ? void 0 : _a.call(onChange, last);
|
|
29
|
+
}, [page, pageCount, last]);
|
|
30
|
+
// Focus must not drop to the page when the Button it was on turns disabled
|
|
31
|
+
useEffect(function () {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
var p = pending.current;
|
|
34
|
+
if (!p || p.to !== shown)
|
|
35
|
+
return;
|
|
36
|
+
pending.current = null;
|
|
37
|
+
var active = document.activeElement;
|
|
38
|
+
if (active && active !== document.body && !((_a = navRef.current) === null || _a === void 0 ? void 0 : _a.contains(active)))
|
|
39
|
+
return;
|
|
40
|
+
(_b = (p.focus === 'prev' ? prevRef : nextRef).current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
41
|
+
}, [shown]);
|
|
42
|
+
useEffect(function () {
|
|
43
|
+
var _a;
|
|
44
|
+
if (lastPage.current === shown)
|
|
45
|
+
return;
|
|
46
|
+
lastPage.current = shown;
|
|
47
|
+
var byPress = pressed.current === shown;
|
|
48
|
+
pressed.current = null;
|
|
49
|
+
if (!scrollTargetId || !byPress)
|
|
50
|
+
return;
|
|
51
|
+
var reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
52
|
+
(_a = document.getElementById(scrollTargetId)) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ block: 'start', behavior: reduced ? 'instant' : 'smooth' });
|
|
53
|
+
}, [shown, scrollTargetId]);
|
|
54
|
+
if (pageCount <= 1)
|
|
55
|
+
return null;
|
|
56
|
+
var atFirst = shown <= 1;
|
|
57
|
+
var atLast = shown >= last;
|
|
58
|
+
var go = function (to, from) {
|
|
59
|
+
var _a;
|
|
60
|
+
if (to < 1 || to > last || to === shown)
|
|
61
|
+
return;
|
|
62
|
+
if (to === 1 || to === last)
|
|
63
|
+
pending.current = { to: to, focus: from === 'prev' ? 'next' : 'prev' };
|
|
64
|
+
pressed.current = to;
|
|
65
|
+
(_a = onChange.current) === null || _a === void 0 ? void 0 : _a.call(onChange, to);
|
|
66
|
+
};
|
|
67
|
+
var prevHref = getHref && !atFirst ? getHref(shown - 1) : undefined;
|
|
68
|
+
var nextHref = getHref && !atLast ? getHref(shown + 1) : undefined;
|
|
69
|
+
// `rel` is not a Button prop; it lands on the anchor with the rest
|
|
70
|
+
var prevRel = prevHref ? { rel: 'prev' } : {};
|
|
71
|
+
var nextRel = nextHref ? { rel: 'next' } : {};
|
|
72
|
+
var of = "".concat(formatCount(shown), " of ").concat(formatCount(pageCount));
|
|
73
|
+
var text = variant === 'compact' ? of : "Page ".concat(of);
|
|
74
|
+
var live = (<span aria-live="polite" aria-atomic="true" className={"tabular-nums text-fg-secondary ".concat(variant === 'compact' ? 'text-caption' : 'text-body2')}>
|
|
75
|
+
{text}
|
|
76
|
+
</span>);
|
|
77
|
+
if (variant === 'compact') {
|
|
78
|
+
return (<nav ref={navRef} aria-label={ariaLabel} className="flex items-center gap-1">
|
|
79
|
+
<IconButton ref={prevRef} color="iconOnly" size="tiny" state={atFirst ? 'disabled' : 'enabled'} iconName="ChevronLeft" ariaLabel="Previous page" href={prevHref} onClick={function () { return go(shown - 1, 'prev'); }} {...prevRel}/>
|
|
80
|
+
{live}
|
|
81
|
+
<IconButton ref={nextRef} color="iconOnly" size="tiny" state={atLast ? 'disabled' : 'enabled'} iconName="ChevronRight" ariaLabel="Next page" href={nextHref} onClick={function () { return go(shown + 1, 'next'); }} {...nextRel}/>
|
|
82
|
+
</nav>);
|
|
83
|
+
}
|
|
84
|
+
return (<nav ref={navRef} aria-label={ariaLabel} className="flex items-center justify-between gap-2">
|
|
85
|
+
<Button ref={prevRef} size="small" type="tertiary" state={atFirst ? 'disabled' : 'enabled'} label="Previous" decoIcon="ChevronLeft" aria-label="Previous page" href={prevHref} onClickButton={function () { return go(shown - 1, 'prev'); }} {...prevRel}/>
|
|
86
|
+
{live}
|
|
87
|
+
<Button ref={nextRef} size="small" type="tertiary" state={atLast ? 'disabled' : 'enabled'} label="Next" actionIcon="ChevronRight" aria-label="Next page" href={nextHref} onClickButton={function () { return go(shown + 1, 'next'); }} {...nextRel}/>
|
|
88
|
+
</nav>);
|
|
89
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface ProgressProps {
|
|
3
|
+
/** What is measured, e.g. "Responses". Always the meter's name, even with `hideLabel`. */
|
|
4
|
+
label: string;
|
|
5
|
+
/** The amount used. */
|
|
6
|
+
value: number;
|
|
7
|
+
/** The limit. `null` means there is no limit: the label and the text show, with no bar and no `meter` role. */
|
|
8
|
+
max: number | null;
|
|
9
|
+
/** The words for the amount, in place of '<value> of <max> <unit>'. */
|
|
10
|
+
valueText?: string;
|
|
11
|
+
/** What is counted, e.g. "responses". Goes after the numbers in the default text. */
|
|
12
|
+
unit?: string;
|
|
13
|
+
/**
|
|
14
|
+
* `limit` (default) is how much of a limit is used: the bar turns to a warning near it and to an error at it.
|
|
15
|
+
* `share` is one part of a total (`max` is the total): always the main color, no status words, and the text is
|
|
16
|
+
* '42%, 1,240 responses'. A share is not a limit.
|
|
17
|
+
*/
|
|
18
|
+
kind?: 'limit' | 'share';
|
|
19
|
+
/** The share of `max` where the bar turns to a warning. Defaults to 0.8. */
|
|
20
|
+
warnAt?: number;
|
|
21
|
+
/** Keeps the name for a screen reader and hides the row of words, for a bar in a table cell. */
|
|
22
|
+
hideLabel?: boolean;
|
|
23
|
+
/** Bar thickness: 4px or 6px. */
|
|
24
|
+
size?: 'small' | 'medium';
|
|
25
|
+
id?: string;
|
|
26
|
+
'aria-describedby'?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A meter: how much of a limit is used. It is not a task progress bar and not a spinner. The bar turns to a
|
|
30
|
+
* warning near the limit and to an error at it, and says so in words, never by color alone.
|
|
31
|
+
*/
|
|
32
|
+
export default function Progress({ label, value, max, valueText, unit, kind, warnAt, hideLabel, size, id, 'aria-describedby': describedBy, }: ProgressProps): React.JSX.Element;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { useId } from 'react';
|
|
3
|
+
import { formatCount, formatPercent } from './formatNumber';
|
|
4
|
+
/**
|
|
5
|
+
* A meter: how much of a limit is used. It is not a task progress bar and not a spinner. The bar turns to a
|
|
6
|
+
* warning near the limit and to an error at it, and says so in words, never by color alone.
|
|
7
|
+
*/
|
|
8
|
+
export default function Progress(_a) {
|
|
9
|
+
var label = _a.label, value = _a.value, max = _a.max, valueText = _a.valueText, unit = _a.unit, _b = _a.kind, kind = _b === void 0 ? 'limit' : _b, _c = _a.warnAt, warnAt = _c === void 0 ? 0.8 : _c, _d = _a.hideLabel, hideLabel = _d === void 0 ? false : _d, _e = _a.size, size = _e === void 0 ? 'medium' : _e, id = _a.id, describedBy = _a["aria-describedby"];
|
|
10
|
+
var autoId = useId();
|
|
11
|
+
var labelId = "".concat(id !== null && id !== void 0 ? id : autoId, "-label");
|
|
12
|
+
var withUnit = function (text) { return (unit ? "".concat(text, " ").concat(unit) : text); };
|
|
13
|
+
var rowClasses = "flex items-baseline justify-between gap-2 text-body2".concat(hideLabel ? ' sr-only' : '');
|
|
14
|
+
if (max === null) {
|
|
15
|
+
var text_1 = valueText !== null && valueText !== void 0 ? valueText : "".concat(withUnit(formatCount(value)), ", no limit");
|
|
16
|
+
return (
|
|
17
|
+
// No meter here, so there is nothing for aria-describedby to describe: it is ignored
|
|
18
|
+
<div id={id} className="w-full">
|
|
19
|
+
<div className={rowClasses}>
|
|
20
|
+
<span className="text-fg-primary">{label}</span>
|
|
21
|
+
<span className="text-fg-secondary">{text_1}</span>
|
|
22
|
+
</div>
|
|
23
|
+
</div>);
|
|
24
|
+
}
|
|
25
|
+
var fraction = max > 0 ? value / max : value > 0 ? 1 : 0;
|
|
26
|
+
var now = Math.min(max, Math.max(0, value));
|
|
27
|
+
var status = kind === 'share' ? 'primary' : fraction >= 1 ? 'error' : fraction >= warnAt ? 'warning' : 'primary';
|
|
28
|
+
var share = kind === 'share';
|
|
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
|
+
var suffix = share ? '' : status === 'error' ? (value > max ? ', over the limit' : ', at the limit') : status === 'warning' ? ', almost at the limit' : '';
|
|
31
|
+
var statusWords = { error: 'Limit reached', warning: 'Almost at the limit', primary: '' }[status];
|
|
32
|
+
var bar = { error: 'bg-error-main', warning: 'bg-warning-main', primary: 'bg-accent-main' }[status];
|
|
33
|
+
var wordColor = { error: 'text-error-text', warning: 'text-warning-text', primary: '' }[status];
|
|
34
|
+
var percent = Math.min(100, Math.max(0, fraction * 100));
|
|
35
|
+
return (
|
|
36
|
+
// The wrapper is the meter: a meter's children are presentational, so a reader that supports the role says the
|
|
37
|
+
// name and value text once, and one that does not reads the visible words
|
|
38
|
+
<div id={id} role="meter" aria-labelledby={labelId} aria-valuemin={0} aria-valuenow={now} aria-valuemax={max} aria-valuetext={"".concat(text).concat(suffix)} aria-describedby={describedBy} className="w-full">
|
|
39
|
+
<div className={rowClasses}>
|
|
40
|
+
<span id={labelId} className="text-fg-primary">{label}</span>
|
|
41
|
+
<span className="text-fg-secondary">
|
|
42
|
+
{text}
|
|
43
|
+
{statusWords && <span className={"ml-1 ".concat(wordColor)}>{statusWords}</span>}
|
|
44
|
+
</span>
|
|
45
|
+
</div>
|
|
46
|
+
<div className={"".concat(hideLabel ? '' : 'mt-1 ', "w-full overflow-hidden rounded-full bg-fg-primary/10 ").concat(size === 'small' ? 'h-1' : 'h-[6px]')}>
|
|
47
|
+
<div className={"h-full rounded-full ".concat(bar, " transition-[width] duration-[var(--os-duration-fast)] ease-out motion-reduce:transition-none")} style={{ width: "".concat(percent, "%") }}/>
|
|
48
|
+
</div>
|
|
49
|
+
</div>);
|
|
50
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type Width = 'full' | 'large' | 'medium' | 'small';
|
|
3
|
+
interface SkeletonProps {
|
|
4
|
+
/** The shape of what will load. `text` is one body line (`lines` stacks several), `block` a card or a row, `circle` an avatar. */
|
|
5
|
+
variant?: 'text' | 'block' | 'circle';
|
|
6
|
+
/** `full` is 100%, `large` 75%, `medium` 50%, `small` 25%. A `circle` ignores it. */
|
|
7
|
+
width?: Width;
|
|
8
|
+
/** For `text`: how many lines. The last one is shorter. */
|
|
9
|
+
lines?: number;
|
|
10
|
+
/** For `block`: 24px, 48px or 120px. */
|
|
11
|
+
height?: 'small' | 'medium' | 'large';
|
|
12
|
+
/** Names the loading for a screen reader, e.g. "Loading invoices", in a visually hidden `role="status"`. Without it the skeleton is silent. */
|
|
13
|
+
label?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A still block in the shape of what will load, so a table or a tile keeps its size while it loads.
|
|
17
|
+
* It is hidden from the accessibility tree; give it a `label` once per region so the loading is announced once.
|
|
18
|
+
* The slow pulse stops under reduced motion. A status region announces most reliably when it stays mounted and its text changes.
|
|
19
|
+
*/
|
|
20
|
+
export default function Skeleton({ variant, width, lines, height, label }: SkeletonProps): React.JSX.Element;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
var widthClasses = { full: 'w-full', large: 'w-3/4', medium: 'w-1/2', small: 'w-1/4' };
|
|
3
|
+
var shorter = { full: 'large', large: 'medium', medium: 'small', small: 'small' };
|
|
4
|
+
var heightClasses = { small: 'h-6', medium: 'h-12', large: 'h-[120px]' };
|
|
5
|
+
var base = 'bg-fg-primary/10 animate-pulse motion-reduce:animate-none';
|
|
6
|
+
// A body line is 24px tall: each bar sits in a 24px slot so the text that replaces it does not move the page
|
|
7
|
+
var TextLine = function (_a) {
|
|
8
|
+
var width = _a.width;
|
|
9
|
+
return (<div className="flex h-6 items-center">
|
|
10
|
+
<div className={"".concat(widthClasses[width], " h-4 rounded-control ").concat(base)}/>
|
|
11
|
+
</div>);
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A still block in the shape of what will load, so a table or a tile keeps its size while it loads.
|
|
15
|
+
* It is hidden from the accessibility tree; give it a `label` once per region so the loading is announced once.
|
|
16
|
+
* The slow pulse stops under reduced motion. A status region announces most reliably when it stays mounted and its text changes.
|
|
17
|
+
*/
|
|
18
|
+
export default function Skeleton(_a) {
|
|
19
|
+
var _b = _a.variant, variant = _b === void 0 ? 'text' : _b, _c = _a.width, width = _c === void 0 ? 'full' : _c, _d = _a.lines, lines = _d === void 0 ? 1 : _d, _e = _a.height, height = _e === void 0 ? 'medium' : _e, label = _a.label;
|
|
20
|
+
var shape;
|
|
21
|
+
if (variant === 'circle') {
|
|
22
|
+
shape = <div aria-hidden="true" className={"h-7 w-7 shrink-0 rounded-full ".concat(base)}/>;
|
|
23
|
+
}
|
|
24
|
+
else if (variant === 'block') {
|
|
25
|
+
shape = <div aria-hidden="true" className={"".concat(widthClasses[width], " ").concat(heightClasses[height], " rounded-container ").concat(base)}/>;
|
|
26
|
+
}
|
|
27
|
+
else if (lines > 1) {
|
|
28
|
+
shape = (<div aria-hidden="true" className="flex flex-col w-full">
|
|
29
|
+
{Array.from({ length: lines }, function (_, i) { return (<TextLine key={i} width={i === lines - 1 ? shorter[width] : width}/>); })}
|
|
30
|
+
</div>);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
shape = <div aria-hidden="true" className="w-full"><TextLine width={width}/></div>;
|
|
34
|
+
}
|
|
35
|
+
if (!label)
|
|
36
|
+
return <>{shape}</>;
|
|
37
|
+
return (<>
|
|
38
|
+
{shape}
|
|
39
|
+
<span role="status" className="sr-only">{label}</span>
|
|
40
|
+
</>);
|
|
41
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type ChangePeriod } from './formatNumber';
|
|
3
|
+
interface StatTileProps {
|
|
4
|
+
/** What the number is, e.g. "Responses". It is the tile's name. */
|
|
5
|
+
label: string;
|
|
6
|
+
/** The number. `null` means there is no data yet; it shows 'No data yet', never 0. A percent is a fraction (0.124 is 12%). */
|
|
7
|
+
value: number | null;
|
|
8
|
+
/** How the number reads: a count (default), money, a percent, bytes (base 1024) or a duration in milliseconds. */
|
|
9
|
+
format?: 'count' | 'money' | 'percent' | 'bytes' | 'duration';
|
|
10
|
+
/** For `money`: the currency code. Defaults to USD. */
|
|
11
|
+
currency?: string;
|
|
12
|
+
/** What is counted, e.g. "responses", set after the number. */
|
|
13
|
+
unit?: string;
|
|
14
|
+
/** The value for the period before, in the same unit. Gives the change line; without it there is none. */
|
|
15
|
+
previous?: number | null;
|
|
16
|
+
/** The period `previous` is from. Defaults to week. */
|
|
17
|
+
period?: ChangePeriod;
|
|
18
|
+
/** A line under the number, e.g. "7 of 8 seats used". */
|
|
19
|
+
caption?: string;
|
|
20
|
+
/** Shows a skeleton in place of the number and the change line, and marks the tile busy. */
|
|
21
|
+
loading?: boolean;
|
|
22
|
+
/** The number is h5 at every width. `large` sets it h4, and h3 from `md` up. */
|
|
23
|
+
size?: 'default' | 'large';
|
|
24
|
+
id?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* One headline number: a label, the number, how it changed and an optional note. From 10,000 up a count or an amount
|
|
28
|
+
* shows in its short form ('1.2M') and the exact number is in hidden text, so a screen reader hears '1,234,567'.
|
|
29
|
+
* The change line is never colored: more is not good or bad by itself. A row of tiles is `<Grid compact columns={4}>`.
|
|
30
|
+
*/
|
|
31
|
+
export default function StatTile({ label, value, format, currency, unit, previous, period, caption, loading, size, id, }: StatTileProps): React.JSX.Element;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ArrowDown, ArrowUp } from 'lucide-react';
|
|
3
|
+
import Skeleton from './skeleton';
|
|
4
|
+
import { formatBytes, formatChange, formatCount, formatDuration, formatMoney, formatPercent, } from './formatNumber';
|
|
5
|
+
/**
|
|
6
|
+
* One headline number: a label, the number, how it changed and an optional note. From 10,000 up a count or an amount
|
|
7
|
+
* shows in its short form ('1.2M') and the exact number is in hidden text, so a screen reader hears '1,234,567'.
|
|
8
|
+
* The change line is never colored: more is not good or bad by itself. A row of tiles is `<Grid compact columns={4}>`.
|
|
9
|
+
*/
|
|
10
|
+
export default function StatTile(_a) {
|
|
11
|
+
var label = _a.label, value = _a.value, _b = _a.format, format = _b === void 0 ? 'count' : _b, _c = _a.currency, currency = _c === void 0 ? 'USD' : _c, unit = _a.unit, previous = _a.previous, _d = _a.period, period = _d === void 0 ? 'week' : _d, caption = _a.caption, _e = _a.loading, loading = _e === void 0 ? false : _e, _f = _a.size, size = _f === void 0 ? 'default' : _f, id = _a.id;
|
|
12
|
+
// The default number is h5 at every width, so four tiles across keep '2 h 24 min' on one line
|
|
13
|
+
var valueSize = size === 'large' ? 'text-h4 md:text-h3' : 'text-h5';
|
|
14
|
+
// A line keeps its height while it loads, so the tile does not jump
|
|
15
|
+
var valueLine = size === 'large' ? 'min-h-[41px] md:min-h-[58px]' : 'min-h-[29px]';
|
|
16
|
+
var shown = null;
|
|
17
|
+
var exact = null;
|
|
18
|
+
if (value !== null) {
|
|
19
|
+
switch (format) {
|
|
20
|
+
case 'money':
|
|
21
|
+
exact = formatMoney(value, { currency: currency });
|
|
22
|
+
shown = formatMoney(value, { currency: currency, compact: true });
|
|
23
|
+
break;
|
|
24
|
+
case 'percent':
|
|
25
|
+
shown = formatPercent(value);
|
|
26
|
+
break;
|
|
27
|
+
case 'bytes':
|
|
28
|
+
shown = formatBytes(value);
|
|
29
|
+
break;
|
|
30
|
+
case 'duration':
|
|
31
|
+
shown = formatDuration(value);
|
|
32
|
+
break;
|
|
33
|
+
default:
|
|
34
|
+
exact = formatCount(value);
|
|
35
|
+
shown = formatCount(value, { compact: true });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
var compact = shown !== null && exact !== null && shown !== exact;
|
|
39
|
+
var change = loading ? null : formatChange(value, previous, period);
|
|
40
|
+
return (<dl id={id} aria-busy={loading || undefined} className="flex min-w-0 flex-col gap-1">
|
|
41
|
+
<dt className="text-caption text-fg-secondary">{label}</dt>
|
|
42
|
+
<dd className={"flex items-center ".concat(valueLine)}>
|
|
43
|
+
{loading ? (<Skeleton width="medium" label={"Loading ".concat(label)}/>) : shown === null ? (<span className="text-body1 text-fg-secondary">No data yet</span>) : (<span className={"min-w-0 break-words font-mono tabular-nums text-fg-primary ".concat(valueSize)}>
|
|
44
|
+
{compact ? (<>
|
|
45
|
+
<span aria-hidden="true">{shown}</span>
|
|
46
|
+
<span className="sr-only">{exact}</span>
|
|
47
|
+
</>) : (shown)}
|
|
48
|
+
{unit && <span className="font-sans text-body2 text-fg-secondary">{' '}{unit}</span>}
|
|
49
|
+
</span>)}
|
|
50
|
+
</dd>
|
|
51
|
+
{loading ? (<dd className="m-0">
|
|
52
|
+
<Skeleton width="large"/>
|
|
53
|
+
</dd>) : (change &&
|
|
54
|
+
change.direction !== null && (<dd className="m-0 flex items-center gap-1 text-body2 text-fg-secondary">
|
|
55
|
+
{change.direction === 'up' && <ArrowUp aria-hidden="true" className="size-4 shrink-0"/>}
|
|
56
|
+
{change.direction === 'down' && <ArrowDown aria-hidden="true" className="size-4 shrink-0"/>}
|
|
57
|
+
{change.text}
|
|
58
|
+
</dd>))}
|
|
59
|
+
{caption && <dd className="m-0 text-body2 text-fg-secondary">{caption}</dd>}
|
|
60
|
+
</dl>);
|
|
61
|
+
}
|