oneslash-design-system 2.23.1 → 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 +20 -5
- package/dist/cases/activity-timeline/activity.d.ts +1 -0
- package/dist/cases/activity-timeline/activity.jsx +43 -0
- package/dist/cases/activity-timeline/versions.d.ts +1 -0
- package/dist/cases/activity-timeline/versions.jsx +130 -0
- package/dist/cases/activity-timeline.md +315 -0
- package/dist/cases/agent-plan-proposal.md +1 -0
- package/dist/cases/ask-page/answered.d.ts +1 -0
- package/dist/cases/ask-page/answered.jsx +248 -0
- package/dist/cases/ask-page/first-visit.d.ts +1 -0
- package/dist/cases/ask-page/first-visit.jsx +118 -0
- package/dist/cases/ask-page.md +551 -0
- 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/chart/bars.d.ts +1 -0
- package/dist/cases/chart/bars.jsx +83 -0
- package/dist/cases/chart/lines.d.ts +1 -0
- package/dist/cases/chart/lines.jsx +71 -0
- package/dist/cases/chart.md +258 -0
- package/dist/cases/collapsible-search/popover.jsx +1 -1
- package/dist/cases/collapsible-search.md +2 -2
- package/dist/cases/comment-thread/card.d.ts +1 -0
- package/dist/cases/comment-thread/card.jsx +141 -0
- package/dist/cases/comment-thread/thread.d.ts +1 -0
- package/dist/cases/comment-thread/thread.jsx +87 -0
- package/dist/cases/comment-thread.md +349 -0
- 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 +63 -2
- package/dist/cases/dashboard/work-first.jsx +1 -1
- package/dist/cases/dashboard.md +77 -5
- 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/leaderboard/ranked.d.ts +1 -0
- package/dist/cases/leaderboard/ranked.jsx +44 -0
- package/dist/cases/leaderboard/table.d.ts +1 -0
- package/dist/cases/leaderboard/table.jsx +87 -0
- package/dist/cases/leaderboard.md +177 -0
- 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 +9 -3
- package/dist/cases/onboarding/checklist.d.ts +1 -0
- package/dist/cases/onboarding/checklist.jsx +92 -0
- package/dist/cases/onboarding/steps.d.ts +3 -0
- package/dist/cases/onboarding/steps.jsx +177 -0
- package/dist/cases/onboarding.md +368 -0
- 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/plan-sign-off/one-approver.d.ts +1 -0
- package/dist/cases/plan-sign-off/one-approver.jsx +129 -0
- package/dist/cases/plan-sign-off/team.d.ts +1 -0
- package/dist/cases/plan-sign-off/team.jsx +213 -0
- package/dist/cases/plan-sign-off.md +541 -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 +5 -2
- package/dist/cases/task-header/agent-sets-status.d.ts +1 -0
- package/dist/cases/task-header/agent-sets-status.jsx +164 -0
- package/dist/cases/task-header/people-change-status.d.ts +1 -0
- package/dist/cases/task-header/people-change-status.jsx +175 -0
- package/dist/cases/task-header.md +576 -0
- package/dist/cases.json +883 -30
- package/dist/components/alert.d.ts +3 -1
- package/dist/components/alert.jsx +5 -5
- package/dist/components/barChart.d.ts +35 -0
- package/dist/components/barChart.jsx +92 -0
- 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/heading.d.ts +2 -2
- package/dist/components/heading.jsx +5 -3
- package/dist/components/layout.d.ts +4 -2
- package/dist/components/layout.jsx +13 -2
- package/dist/components/lineChart.d.ts +39 -0
- package/dist/components/lineChart.jsx +128 -0
- 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/timeline.d.ts +32 -0
- package/dist/components/timeline.jsx +54 -0
- package/dist/components/titleBar.d.ts +3 -1
- package/dist/components/titleBar.jsx +9 -4
- package/dist/components/toaster.jsx +81 -11
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/chart.d.ts +39 -0
- package/dist/internal/chart.js +110 -0
- package/dist/internal/chartFrame.d.ts +29 -0
- package/dist/internal/chartFrame.jsx +57 -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 +28 -4
- package/dist/stories/BarChart.stories.d.ts +10 -0
- package/dist/stories/BarChart.stories.jsx +104 -0
- package/dist/stories/Cases.generated.stories.d.ts +22 -0
- package/dist/stories/Cases.generated.stories.jsx +44 -0
- package/dist/stories/Heading.stories.d.ts +1 -0
- package/dist/stories/Heading.stories.jsx +17 -0
- package/dist/stories/LineChart.stories.d.ts +9 -0
- package/dist/stories/LineChart.stories.jsx +34 -0
- package/dist/stories/Markdown.stories.d.ts +9 -0
- package/dist/stories/Markdown.stories.jsx +66 -0
- package/dist/stories/Onboarding.probe.stories.d.ts +6 -0
- package/dist/stories/Onboarding.probe.stories.jsx +12 -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/Timeline.stories.d.ts +8 -0
- package/dist/stories/Timeline.stories.jsx +49 -0
- package/dist/stories/TitleBar.stories.d.ts +1 -0
- package/dist/stories/TitleBar.stories.jsx +13 -0
- 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]' : '')}>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type ChartFormat } from '../internal/chart';
|
|
3
|
+
export interface BarChartPoint {
|
|
4
|
+
/** The x label as the caller wrote it: 'Nov 14' */
|
|
5
|
+
label: string;
|
|
6
|
+
/** `null` is no data: no bar, and 'No data' in the readout and the table. Never drawn as 0. */
|
|
7
|
+
value: number | null;
|
|
8
|
+
}
|
|
9
|
+
export interface BarChartProps {
|
|
10
|
+
id?: string;
|
|
11
|
+
title: string;
|
|
12
|
+
/** One sentence written from the data: 'Comments rose from 40 on Nov 10 to 72 on Nov 16.' */
|
|
13
|
+
summary: string;
|
|
14
|
+
data: BarChartPoint[];
|
|
15
|
+
/** What is counted, after the number in the readout ('58 comments') and as the table's value column */
|
|
16
|
+
unit?: string;
|
|
17
|
+
/** The table's first column, naming the labels. 'Date' fits days and weeks; name it for anything else ('Team'). */
|
|
18
|
+
labelHeader?: string;
|
|
19
|
+
format?: ChartFormat;
|
|
20
|
+
/** The plot's height in px */
|
|
21
|
+
height?: number;
|
|
22
|
+
loading?: boolean;
|
|
23
|
+
/** Shown in the plot's place when no point has a value */
|
|
24
|
+
emptyText?: string;
|
|
25
|
+
/** Names the plot in place of the title */
|
|
26
|
+
'aria-label'?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A column chart of one count per day or week, drawn by ODS: HTML columns sized in percent, so the server
|
|
30
|
+
* and the browser render the same markup. The y axis starts at 0 with round ticks, short on the axis and
|
|
31
|
+
* exact in the readout and the table. The plot is one tab stop: Left, Right, Home and End move the
|
|
32
|
+
* highlighted bar, and the readout line under the title says its value. 'Show Table' gives the exact values.
|
|
33
|
+
* A 0 or a value below 0 draws no bar (the axis starts at 0); its readout and table row give the value.
|
|
34
|
+
*/
|
|
35
|
+
export default function BarChart({ id, title, summary, data, unit, labelHeader, format, height, loading, emptyText, 'aria-label': ariaLabel, }: BarChartProps): React.JSX.Element;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
import React, { useId, useRef, useState } from 'react';
|
|
12
|
+
import ChartFrame, { labelRow, plotTop } from '../internal/chartFrame';
|
|
13
|
+
import { axisText, exactText, labelEvery, nextPoint, niceTicks } from '../internal/chart';
|
|
14
|
+
import { focusRing } from './sharedStyles';
|
|
15
|
+
var pct = function (n) { return "".concat(Math.round(n * 10000) / 100, "%"); };
|
|
16
|
+
/**
|
|
17
|
+
* A column chart of one count per day or week, drawn by ODS: HTML columns sized in percent, so the server
|
|
18
|
+
* and the browser render the same markup. The y axis starts at 0 with round ticks, short on the axis and
|
|
19
|
+
* exact in the readout and the table. The plot is one tab stop: Left, Right, Home and End move the
|
|
20
|
+
* highlighted bar, and the readout line under the title says its value. 'Show Table' gives the exact values.
|
|
21
|
+
* A 0 or a value below 0 draws no bar (the axis starts at 0); its readout and table row give the value.
|
|
22
|
+
*/
|
|
23
|
+
export default function BarChart(_a) {
|
|
24
|
+
var id = _a.id, title = _a.title, summary = _a.summary, data = _a.data, unit = _a.unit, _b = _a.labelHeader, labelHeader = _b === void 0 ? 'Date' : _b, _c = _a.format, format = _c === void 0 ? 'count' : _c, _d = _a.height, height = _d === void 0 ? 200 : _d, _e = _a.loading, loading = _e === void 0 ? false : _e, _f = _a.emptyText, emptyText = _f === void 0 ? 'No data for this range yet' : _f, ariaLabel = _a["aria-label"];
|
|
25
|
+
var autoId = useId();
|
|
26
|
+
var base = id !== null && id !== void 0 ? id : "bar-chart-".concat(autoId.replace(/:/g, ''));
|
|
27
|
+
var _g = useState(-1), active = _g[0], setActive = _g[1];
|
|
28
|
+
var plotRef = useRef(null);
|
|
29
|
+
var values = data.map(function (d) { return d.value; }).filter(function (v) { return v !== null && Number.isFinite(v); });
|
|
30
|
+
var empty = values.length === 0;
|
|
31
|
+
// A count never gets a fractional tick
|
|
32
|
+
var ticks = niceTicks(Math.max.apply(Math, __spreadArray([0], values, false)), 4, { integer: format === 'count' });
|
|
33
|
+
var top = ticks[ticks.length - 1];
|
|
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;
|
|
38
|
+
var point = data[active];
|
|
39
|
+
var readout = point ? "".concat(point.label, ": ").concat(exactText(point.value, format, unit)) : '';
|
|
40
|
+
var table = {
|
|
41
|
+
columns: [labelHeader, unit ? unit.charAt(0).toUpperCase() + unit.slice(1) : 'Value'],
|
|
42
|
+
rows: data.map(function (d) { return [d.label, exactText(d.value, format)]; }),
|
|
43
|
+
};
|
|
44
|
+
var onKeyDown = function (e) {
|
|
45
|
+
if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(e.key))
|
|
46
|
+
return;
|
|
47
|
+
// The keys move the bar, not the page
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
setActive(nextPoint(e.key, active, data.length));
|
|
50
|
+
};
|
|
51
|
+
// Pointer leave keeps the bar a keyboard user chose
|
|
52
|
+
var onPointerLeave = function () {
|
|
53
|
+
if (typeof document !== 'undefined' && document.activeElement === plotRef.current)
|
|
54
|
+
return;
|
|
55
|
+
setActive(-1);
|
|
56
|
+
};
|
|
57
|
+
var plot = (<div ref={plotRef} role="group" tabIndex={0} aria-label={ariaLabel} aria-labelledby={ariaLabel ? undefined : "".concat(base, "-title")} aria-describedby={"".concat(base, "-summary")} onKeyDown={onKeyDown} onPointerLeave={onPointerLeave} onBlur={function () { return setActive(-1); }} className={"rounded-control ".concat(focusRing)}>
|
|
58
|
+
<div aria-hidden="true" className={"flex ".concat(plotTop)}>
|
|
59
|
+
{/* Each tick is a line of no height, so justify-between puts it on its gridline */}
|
|
60
|
+
<div className="flex min-w-[16px] flex-col justify-between pr-medium text-caption text-fg-secondary" style={{ height: height }}>
|
|
61
|
+
{__spreadArray([], ticks, true).reverse().map(function (t) { return (<span key={t} className="flex h-0 items-center justify-end whitespace-nowrap">{axisText(t, format)}</span>); })}
|
|
62
|
+
</div>
|
|
63
|
+
<div className="flex min-w-0 flex-1 flex-col">
|
|
64
|
+
<div className="relative" style={{ height: height }}>
|
|
65
|
+
{ticks.map(function (t) { return (<div key={t} className="absolute inset-x-0 border-t border-misc-divider" style={{ bottom: pct(t / top) }}/>); })}
|
|
66
|
+
<div className="absolute inset-0 flex items-end gap-0.5">
|
|
67
|
+
{data.map(function (d, i) { return (<div key={i} className="flex h-full min-w-0 flex-1 items-end justify-center" onPointerEnter={function () { return setActive(i); }}>
|
|
68
|
+
{d.value !== null && d.value > 0 && Number.isFinite(d.value) && (<div className={"w-full max-w-[64px] rounded-t border-2 border-transparent ".concat(i === active ? 'bg-fg-primary outline outline-2 outline-offset-1 outline-fg-primary' : 'bg-primary-main')} style={{ height: pct(d.value / top) }}/>)}
|
|
69
|
+
</div>); })}
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
<div className={"".concat(labelRow, " text-caption text-fg-secondary")}>
|
|
73
|
+
{data.map(function (d, i) {
|
|
74
|
+
if (!labels.has(i))
|
|
75
|
+
return null;
|
|
76
|
+
var slot = 1 / data.length;
|
|
77
|
+
// A label may take the room up to the next label. The last keeps to the plot's right edge; the first may
|
|
78
|
+
// reach 16px into the tick column, which is never narrower, so nothing scrolls sideways
|
|
79
|
+
var room = pct(step * slot);
|
|
80
|
+
var style = step > 1 && i === data.length - 1
|
|
81
|
+
? { right: 0, maxWidth: room }
|
|
82
|
+
: { left: pct((i + 0.5) * slot), maxWidth: i === 0 ? "min(".concat(room, ", calc(").concat(pct(slot), " + 32px))") : room, transform: 'translateX(-50%)' };
|
|
83
|
+
return (<span key={i} title={d.label} className="absolute top-0 truncate text-center" style={style}>
|
|
84
|
+
{d.label}
|
|
85
|
+
</span>);
|
|
86
|
+
})}
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
</div>);
|
|
91
|
+
return (<ChartFrame id={base} title={title} summary={summary} readout={readout} loading={loading} empty={empty} emptyText={emptyText} table={table} plot={plot} height={height}/>);
|
|
92
|
+
}
|
|
@@ -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));
|
|
@@ -12,5 +12,5 @@ interface HeadingProps {
|
|
|
12
12
|
/** -1 lets a page move focus to the heading (a pane's title on open) without putting it in the tab order. */
|
|
13
13
|
tabIndex?: number;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
export
|
|
15
|
+
declare const Heading: React.ForwardRefExoticComponent<HeadingProps & React.RefAttributes<HTMLHeadingElement>>;
|
|
16
|
+
export default Heading;
|
|
@@ -5,10 +5,12 @@ var sizes = {
|
|
|
5
5
|
h6: 'text-h6',
|
|
6
6
|
subtitle1: 'text-subtitle1',
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
// The ref lands on the heading element, so a screen can move focus to a step's heading (with tabIndex -1).
|
|
9
|
+
var Heading = React.forwardRef(function Heading(_a, ref) {
|
|
9
10
|
var children = _a.children, _b = _a.level, level = _b === void 0 ? 3 : _b, _c = _a.size, size = _c === void 0 ? 'h6' : _c, _d = _a.color, color = _d === void 0 ? 'default' : _d, id = _a.id, _e = _a.className, className = _e === void 0 ? '' : _e, tabIndex = _a.tabIndex;
|
|
10
11
|
var Tag = "h".concat(level);
|
|
11
|
-
return (<Tag id={id} tabIndex={tabIndex} className={"".concat(sizes[size], " ").concat(color === 'danger' ? 'text-error-text' : 'text-fg-primary', " ").concat(className)}>
|
|
12
|
+
return (<Tag ref={ref} id={id} tabIndex={tabIndex} className={"".concat(sizes[size], " ").concat(color === 'danger' ? 'text-error-text' : 'text-fg-primary', " ").concat(className)}>
|
|
12
13
|
{children}
|
|
13
14
|
</Tag>);
|
|
14
|
-
}
|
|
15
|
+
});
|
|
16
|
+
export default Heading;
|
|
@@ -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,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type ChartFormat } from '../internal/chart';
|
|
3
|
+
export interface LineSeries {
|
|
4
|
+
/** Read after each value, so a lower-case word fits: 'opened' reads '58 opened'. The legend and the table capitalize it. */
|
|
5
|
+
name: string;
|
|
6
|
+
/**
|
|
7
|
+
* One value per label. `null` is no data: the line breaks there, and the readout and the table say 'No data'.
|
|
8
|
+
* The y axis starts at 0, so a value below 0 is drawn at 0; the readout and the table keep the value.
|
|
9
|
+
*/
|
|
10
|
+
values: (number | null)[];
|
|
11
|
+
}
|
|
12
|
+
export interface LineChartProps {
|
|
13
|
+
id?: string;
|
|
14
|
+
title: string;
|
|
15
|
+
/** One sentence written from the data: 'More tasks were opened than done on every day but Nov 12.' */
|
|
16
|
+
summary: string;
|
|
17
|
+
/** The x labels as the caller wrote them: 'Nov 14' */
|
|
18
|
+
labels: string[];
|
|
19
|
+
/** One or two series. The first is a solid `primary.main` line, the second a dashed `text.secondary` one. */
|
|
20
|
+
series: [LineSeries] | [LineSeries, LineSeries];
|
|
21
|
+
/** What is counted, after each number in the readout and the table: unit 'tasks' reads '58 tasks opened' */
|
|
22
|
+
unit?: string;
|
|
23
|
+
/** The table's first column, naming the labels */
|
|
24
|
+
labelHeader?: string;
|
|
25
|
+
format?: ChartFormat;
|
|
26
|
+
/** The plot's height in px */
|
|
27
|
+
height?: number;
|
|
28
|
+
loading?: boolean;
|
|
29
|
+
/** Shown in the plot's place when no point has a value */
|
|
30
|
+
emptyText?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A line chart of one or two trends, drawn by ODS: one SVG path per series stretched over the plot with a
|
|
34
|
+
* stroke that does not scale, and every label in HTML, so the server and the browser render the same markup.
|
|
35
|
+
* A `null` breaks the line; a point with no neighbour on either side shows as a dot. The plot is one tab stop:
|
|
36
|
+
* Left, Right, Home and End move the highlighted day, and the readout line under the title names every series.
|
|
37
|
+
* 'Show Table' gives the exact values.
|
|
38
|
+
*/
|
|
39
|
+
export default function LineChart({ id, title, summary, labels, series, unit, labelHeader, format, height, loading, emptyText, }: LineChartProps): React.JSX.Element;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
import React, { useId, useRef, useState } from 'react';
|
|
12
|
+
import ChartFrame, { labelRow, plotTop } from '../internal/chartFrame';
|
|
13
|
+
import { axisText, exactText, labelEvery, linePath, nextPoint, niceTicks, pointX, seriesReadout } from '../internal/chart';
|
|
14
|
+
import { focusRing } from './sharedStyles';
|
|
15
|
+
var pct = function (n) { return "".concat(Math.round(n * 10000) / 100, "%"); };
|
|
16
|
+
var has = function (v) { return typeof v === 'number' && Number.isFinite(v); };
|
|
17
|
+
var capitalize = function (s) { return s.charAt(0).toUpperCase() + s.slice(1); };
|
|
18
|
+
// Series 1 solid in primary.main, series 2 dashed in text.secondary, so they never rely on hue. In forced colors
|
|
19
|
+
// the stroke is CanvasText: the system keeps an SVG's own colour, which can be dark grey on a black Canvas
|
|
20
|
+
var forced = '[@media(forced-colors:active)]:[stroke:CanvasText]';
|
|
21
|
+
var looks = [
|
|
22
|
+
{ stroke: "stroke-current text-primary-main ".concat(forced), dot: 'bg-primary-main', dash: undefined },
|
|
23
|
+
{ stroke: "stroke-current text-fg-secondary ".concat(forced), dot: 'bg-fg-secondary', dash: '6 4' },
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
* A line chart of one or two trends, drawn by ODS: one SVG path per series stretched over the plot with a
|
|
27
|
+
* stroke that does not scale, and every label in HTML, so the server and the browser render the same markup.
|
|
28
|
+
* A `null` breaks the line; a point with no neighbour on either side shows as a dot. The plot is one tab stop:
|
|
29
|
+
* Left, Right, Home and End move the highlighted day, and the readout line under the title names every series.
|
|
30
|
+
* 'Show Table' gives the exact values.
|
|
31
|
+
*/
|
|
32
|
+
export default function LineChart(_a) {
|
|
33
|
+
var id = _a.id, title = _a.title, summary = _a.summary, labels = _a.labels, series = _a.series, unit = _a.unit, _b = _a.labelHeader, labelHeader = _b === void 0 ? 'Date' : _b, _c = _a.format, format = _c === void 0 ? 'count' : _c, _d = _a.height, height = _d === void 0 ? 200 : _d, _e = _a.loading, loading = _e === void 0 ? false : _e, _f = _a.emptyText, emptyText = _f === void 0 ? 'No data for this range yet' : _f;
|
|
34
|
+
var autoId = useId();
|
|
35
|
+
var base = id !== null && id !== void 0 ? id : "line-chart-".concat(autoId.replace(/:/g, ''));
|
|
36
|
+
var _g = useState(-1), active = _g[0], setActive = _g[1];
|
|
37
|
+
var plotRef = useRef(null);
|
|
38
|
+
var n = labels.length;
|
|
39
|
+
var values = series.flatMap(function (s) { return s.values.slice(0, n); }).filter(has);
|
|
40
|
+
var empty = n === 0 || values.length === 0;
|
|
41
|
+
var ticks = niceTicks(Math.max.apply(Math, __spreadArray([0], values, false)), 4, { integer: format === 'count' });
|
|
42
|
+
var top = ticks[ticks.length - 1];
|
|
43
|
+
// Past 24 points six labels leave too little room for 'Oct 18' on a phone, so a month gets four
|
|
44
|
+
var most = n > 24 ? 4 : 6;
|
|
45
|
+
var shown = labelEvery(n, most);
|
|
46
|
+
// Labels sit a step apart or more: each may take two thirds of a step, so a centered one and its neighbour never touch
|
|
47
|
+
var room = n > 1 ? (Math.ceil(n / most) / (n - 1)) * (2 / 3) : 1;
|
|
48
|
+
var readout = active >= 0 && active < n
|
|
49
|
+
? seriesReadout(labels[active], series.map(function (s) { var _a; return ({ name: s.name, value: (_a = s.values[active]) !== null && _a !== void 0 ? _a : null }); }), format, unit)
|
|
50
|
+
: '';
|
|
51
|
+
var table = {
|
|
52
|
+
columns: __spreadArray([labelHeader], series.map(function (s) { return capitalize(s.name); }), true),
|
|
53
|
+
rows: labels.map(function (label, i) { return __spreadArray([label], series.map(function (s) { var _a; return exactText((_a = s.values[i]) !== null && _a !== void 0 ? _a : null, format, unit); }), true); }),
|
|
54
|
+
};
|
|
55
|
+
var onKeyDown = function (e) {
|
|
56
|
+
if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(e.key))
|
|
57
|
+
return;
|
|
58
|
+
// The keys move the day, not the page
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
setActive(nextPoint(e.key, active, n));
|
|
61
|
+
};
|
|
62
|
+
// Pointer leave keeps the day a keyboard user chose
|
|
63
|
+
var onPointerLeave = function () {
|
|
64
|
+
if (typeof document !== 'undefined' && document.activeElement === plotRef.current)
|
|
65
|
+
return;
|
|
66
|
+
setActive(-1);
|
|
67
|
+
};
|
|
68
|
+
// Shown while loading too, so the plot does not move down when the data arrives
|
|
69
|
+
var legend = series.length > 1 && (loading || !empty) ? (<ul className="flex flex-wrap gap-x-large gap-y-small">
|
|
70
|
+
{series.map(function (s, k) { return (<li key={k} className="flex items-center gap-small">
|
|
71
|
+
<svg width="24" height="8" viewBox="0 0 24 8" aria-hidden="true">
|
|
72
|
+
<line x1="0" y1="4" x2="24" y2="4" className={looks[k].stroke} strokeDasharray={looks[k].dash} strokeWidth={2}/>
|
|
73
|
+
</svg>
|
|
74
|
+
<span className="text-body2 text-fg-primary">{capitalize(s.name)}</span>
|
|
75
|
+
</li>); })}
|
|
76
|
+
</ul>) : undefined;
|
|
77
|
+
var plot = (<div ref={plotRef} role="group" tabIndex={0} aria-labelledby={"".concat(base, "-title")} aria-describedby={"".concat(base, "-summary")} onKeyDown={onKeyDown} onPointerLeave={onPointerLeave} onBlur={function () { return setActive(-1); }} className={"rounded-control ".concat(focusRing)}>
|
|
78
|
+
{/* Room on the right for the last point's dot, so it never reaches past the figure */}
|
|
79
|
+
<div aria-hidden="true" className={"flex pr-1.5 ".concat(plotTop)}>
|
|
80
|
+
{/* Each tick is a line of no height, so justify-between puts it on its gridline */}
|
|
81
|
+
<div className="flex min-w-[16px] flex-col justify-between pr-medium text-caption text-fg-secondary" style={{ height: height }}>
|
|
82
|
+
{__spreadArray([], ticks, true).reverse().map(function (t) { return (<span key={t} className="flex h-0 items-center justify-end whitespace-nowrap">{axisText(t, format)}</span>); })}
|
|
83
|
+
</div>
|
|
84
|
+
<div className="flex min-w-0 flex-1 flex-col">
|
|
85
|
+
<div className="relative" style={{ height: height }}>
|
|
86
|
+
{ticks.map(function (t) { return (<div key={t} className="absolute inset-x-0 border-t border-misc-divider" style={{ bottom: pct(t / top) }}/>); })}
|
|
87
|
+
{active >= 0 && active < n && (<div className="absolute inset-y-0 border-l border-misc-divider" style={{ left: pct(pointX(active, n) / 100) }}/>)}
|
|
88
|
+
<svg viewBox="0 0 100 100" preserveAspectRatio="none" aria-hidden="true" className="absolute inset-0 h-full w-full overflow-visible">
|
|
89
|
+
{series.map(function (s, k) { return (<path key={k} d={linePath(s.values.slice(0, n), top)} fill="none" vectorEffect="non-scaling-stroke" strokeWidth={2} strokeLinejoin="round" strokeLinecap="round" className={looks[k].stroke} strokeDasharray={looks[k].dash}/>); })}
|
|
90
|
+
</svg>
|
|
91
|
+
{series.map(function (s, k) {
|
|
92
|
+
return labels.map(function (_, i) {
|
|
93
|
+
var v = s.values[i];
|
|
94
|
+
if (!has(v))
|
|
95
|
+
return null;
|
|
96
|
+
// A point with no neighbour draws no line, so it shows as a dot; the chosen day shows one per series
|
|
97
|
+
var lone = !has(s.values[i - 1]) && !has(s.values[i + 1]);
|
|
98
|
+
if (!lone && i !== active)
|
|
99
|
+
return null;
|
|
100
|
+
return (<span key={"".concat(k, "-").concat(i)} className={"absolute h-3 w-3 rounded-full border-2 border-background-default ".concat(looks[k].dot)} style={{ left: pct(pointX(i, n) / 100), bottom: pct(Math.max(0, v) / top), transform: 'translate(-50%, 50%)' }}/>);
|
|
101
|
+
});
|
|
102
|
+
})}
|
|
103
|
+
{/* One hit area per day, reaching halfway to its neighbours */}
|
|
104
|
+
<div className="absolute inset-0 flex">
|
|
105
|
+
{labels.map(function (_, i) { return (<div key={i} className="h-full" style={{ flexGrow: n > 1 && (i === 0 || i === n - 1) ? 1 : 2, flexBasis: 0 }} onPointerEnter={function () { return setActive(i); }}/>); })}
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
<div className={"".concat(labelRow, " text-caption text-fg-secondary")}>
|
|
109
|
+
{shown.map(function (i) {
|
|
110
|
+
var x = pointX(i, n) / 100;
|
|
111
|
+
// The first and the last keep to the plot's edges; the rest are centered on their point
|
|
112
|
+
var style = n === 1
|
|
113
|
+
? { left: '50%', maxWidth: '100%', transform: 'translateX(-50%)' }
|
|
114
|
+
: i === 0
|
|
115
|
+
? { left: 0, maxWidth: pct(room) }
|
|
116
|
+
: i === n - 1
|
|
117
|
+
? { right: 0, maxWidth: pct(room) }
|
|
118
|
+
: { left: pct(x), maxWidth: pct(room), transform: 'translateX(-50%)' };
|
|
119
|
+
return (<span key={i} title={labels[i]} className="absolute top-0 truncate text-center" style={style}>
|
|
120
|
+
{labels[i]}
|
|
121
|
+
</span>);
|
|
122
|
+
})}
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
</div>);
|
|
127
|
+
return (<ChartFrame id={base} title={title} summary={summary} readout={readout} loading={loading} empty={empty} emptyText={emptyText} table={table} plot={plot} height={height} legend={legend}/>);
|
|
128
|
+
}
|
|
@@ -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 };
|