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
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# Cookie choice
|
|
2
|
+
|
|
3
|
+
A site sets cookies it does not need to run, and asks the visitor whether it may.
|
|
4
|
+
|
|
5
|
+
## Do
|
|
6
|
+
|
|
7
|
+
- Ask only when the site sets a cookie it does not need. A cookie that keeps a person logged in needs no question.
|
|
8
|
+
- Put the banner in a `Surface` at the top of the page, in the normal flow, before the `SiteHeader`, so Tab reaches it first and it covers nothing.
|
|
9
|
+
- Name it with a `Heading level={2}` 'Cookies on Acme', and say in one `Paragraph` what each choice does: 'Acme uses cookies to keep you logged in. Accept All also allows cookies that count visits and cookies for marketing. Reject All turns both off.'
|
|
10
|
+
- Make Reject as easy as Accept: 'Accept All' and 'Reject All' are both secondary, side by side, then a tertiary 'Choose Cookies'.
|
|
11
|
+
- Remove the banner on any choice and move focus to the page's `main`. Give `PageShell` a `ref` and `tabIndex={-1}`.
|
|
12
|
+
- Show the choices in a `Modal` 'Cookie Settings' with one `Switch` for each kind: 'Needed to run the site' on and `disabled`, then 'Visit counts' and 'Marketing'.
|
|
13
|
+
- Leave every choice off until the visitor turns it on.
|
|
14
|
+
- Give the group one Save Button, 'Save Choices', with 'Cancel' beside it, as the rule 'A setting saves in place, or with one Save Button' says. Every Switch here waits for it, and none saves on its own.
|
|
15
|
+
- Keep it disabled until a switch changes from what was saved, then show 'Saved' in place of the label for 2 seconds. From the banner nothing is saved yet, so 'Save Choices' is enabled at once.
|
|
16
|
+
- Link 'Cookie Settings' in the footer to the page that holds the choice, such as the privacy page, and open the `Modal` there. The visitor can change the choice at any time.
|
|
17
|
+
|
|
18
|
+
## Don't
|
|
19
|
+
|
|
20
|
+
- Do not fix a banner over the page. It hides content at 375px and at 400% zoom.
|
|
21
|
+
- Do not make 'Accept' the only primary Button. Consent is not the page's main action.
|
|
22
|
+
- Do not block the page behind a wall until the visitor chooses.
|
|
23
|
+
- Do not turn a switch on before the visitor chooses.
|
|
24
|
+
- Do not hide Reject in the settings. It sits beside Accept.
|
|
25
|
+
|
|
26
|
+
## Option: Banner at the top of the page
|
|
27
|
+
|
|
28
|
+
Use when: The site sets cookies it does not need to run, such as for visit counts, and the visitor has not chosen yet.
|
|
29
|
+
|
|
30
|
+
Uses: `Button`, `Center`, `Cluster`, `Heading`, `Modal`, `PageShell`, `Paragraph`, `SiteHeader`, `Stack`, `Surface`, `Switch`
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
'use client';
|
|
34
|
+
import { useEffect, useRef, useState } from 'react';
|
|
35
|
+
import Surface from 'oneslash-design-system/components/surface';
|
|
36
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
37
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
38
|
+
import Button from 'oneslash-design-system/components/button';
|
|
39
|
+
import Modal from 'oneslash-design-system/components/modal';
|
|
40
|
+
import Switch from 'oneslash-design-system/components/switch';
|
|
41
|
+
import SiteHeader from 'oneslash-design-system/components/siteHeader';
|
|
42
|
+
import PageShell from 'oneslash-design-system/components/pageShell';
|
|
43
|
+
import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
|
|
44
|
+
|
|
45
|
+
const links = [
|
|
46
|
+
{ label: 'Features', href: '#features' },
|
|
47
|
+
{ label: 'Pricing', href: '#pricing' },
|
|
48
|
+
{ label: 'Docs', href: '#docs' },
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
export default function CookieChoiceBanner() {
|
|
52
|
+
const [chosen, setChosen] = useState(false);
|
|
53
|
+
const [choosing, setChoosing] = useState(false);
|
|
54
|
+
// Every optional cookie starts off. Only the visitor turns one on.
|
|
55
|
+
const [visits, setVisits] = useState(false);
|
|
56
|
+
const [marketing, setMarketing] = useState(false);
|
|
57
|
+
const main = useRef<HTMLElement>(null);
|
|
58
|
+
|
|
59
|
+
// The banner is gone, so focus moves to the page the visitor came to read.
|
|
60
|
+
// This runs after the Modal has tried to give focus back to 'Choose Cookies', which is gone too.
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (chosen) main.current?.focus({ preventScroll: true });
|
|
63
|
+
}, [chosen]);
|
|
64
|
+
|
|
65
|
+
// A real site keeps the choice in the browser, and sets a visit count or marketing cookie only when it is on.
|
|
66
|
+
function choose(next: { visits: boolean; marketing: boolean }) {
|
|
67
|
+
setVisits(next.visits);
|
|
68
|
+
setMarketing(next.marketing);
|
|
69
|
+
setChoosing(false);
|
|
70
|
+
setChosen(true);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Cancel puts every switch back off. The banner stays until the visitor chooses.
|
|
74
|
+
function handleCancel() {
|
|
75
|
+
setVisits(false);
|
|
76
|
+
setMarketing(false);
|
|
77
|
+
setChoosing(false);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<>
|
|
82
|
+
{/* In the page flow, before the header, so Tab reaches it first. It never covers the page, and the page stays usable. */}
|
|
83
|
+
{!chosen && (
|
|
84
|
+
<Center width="page">
|
|
85
|
+
<Surface padding="small">
|
|
86
|
+
<Stack gap="medium">
|
|
87
|
+
<Stack gap="small">
|
|
88
|
+
<Heading level={2} size="h6">Cookies on Acme</Heading>
|
|
89
|
+
<Paragraph size="body2" measure="none">Acme uses cookies to keep you logged in. Accept All also allows cookies that count visits and cookies for marketing. Reject All turns both off.</Paragraph>
|
|
90
|
+
</Stack>
|
|
91
|
+
{/* Accept and Reject have the same weight, side by side. Neither is the page's main action. */}
|
|
92
|
+
<Cluster gap="small">
|
|
93
|
+
<Button size="medium" type="secondary" state="enabled" label="Accept All" onClickButton={() => choose({ visits: true, marketing: true })} />
|
|
94
|
+
<Button size="medium" type="secondary" state="enabled" label="Reject All" onClickButton={() => choose({ visits: false, marketing: false })} />
|
|
95
|
+
<Button size="medium" type="tertiary" state="enabled" label="Choose Cookies" onClickButton={() => setChoosing(true)} />
|
|
96
|
+
</Cluster>
|
|
97
|
+
</Stack>
|
|
98
|
+
</Surface>
|
|
99
|
+
</Center>
|
|
100
|
+
)}
|
|
101
|
+
<SiteHeader
|
|
102
|
+
brand={{ href: '#top', name: 'Acme' }}
|
|
103
|
+
links={links}
|
|
104
|
+
actions={<Button size="medium" type="tertiary" state="enabled" label="Log In" href="#log-in" />}
|
|
105
|
+
phoneAction={<Button size="medium" type="primary" state="enabled" label="Sign Up" href="#sign-up" />}
|
|
106
|
+
mainId="cookie-choice-banner-main"
|
|
107
|
+
/>
|
|
108
|
+
{/* tabIndex -1 lets the skip link and the banner move focus here. */}
|
|
109
|
+
<PageShell ref={main} id="cookie-choice-banner-main" tabIndex={-1}>
|
|
110
|
+
<Stack gap="large">
|
|
111
|
+
<Heading level={1} size="h5">Share files and decide together</Heading>
|
|
112
|
+
<Paragraph tone="secondary" measure="none">Acme keeps a small team's files, notes and decisions in one place.</Paragraph>
|
|
113
|
+
</Stack>
|
|
114
|
+
</PageShell>
|
|
115
|
+
<Modal
|
|
116
|
+
isOpen={choosing}
|
|
117
|
+
size="small"
|
|
118
|
+
title="Cookie Settings"
|
|
119
|
+
onClose={handleCancel}
|
|
120
|
+
actions={
|
|
121
|
+
<>
|
|
122
|
+
<Button size="small" type="tertiary" state="enabled" label="Cancel" onClickButton={handleCancel} />
|
|
123
|
+
{/* No choice is saved yet, so Save is enabled at once: saving every switch off is a choice. */}
|
|
124
|
+
<Button size="small" type="primary" state="enabled" label="Save Choices" onClickButton={() => choose({ visits, marketing })} />
|
|
125
|
+
</>
|
|
126
|
+
}
|
|
127
|
+
>
|
|
128
|
+
<Stack gap="medium">
|
|
129
|
+
<Switch id="cookie-choice-banner-needed" label="Needed to run the site" description="Keeps you logged in. Always on." checked disabled onChange={() => {}} />
|
|
130
|
+
<Switch id="cookie-choice-banner-visits" label="Visit counts" checked={visits} onChange={setVisits} />
|
|
131
|
+
<Switch id="cookie-choice-banner-marketing" label="Marketing" checked={marketing} onChange={setMarketing} />
|
|
132
|
+
</Stack>
|
|
133
|
+
</Modal>
|
|
134
|
+
</>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Option: Settings from the footer
|
|
140
|
+
|
|
141
|
+
Use when: The visitor opens 'Cookie Settings' from the footer to change a choice.
|
|
142
|
+
|
|
143
|
+
Uses: `Button`, `Center`, `Heading`, `Modal`, `Paragraph`, `SiteFooter`, `Stack`, `Switch`
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
'use client';
|
|
147
|
+
import { useEffect, useRef, useState } from 'react';
|
|
148
|
+
import Modal from 'oneslash-design-system/components/modal';
|
|
149
|
+
import Switch from 'oneslash-design-system/components/switch';
|
|
150
|
+
import Button from 'oneslash-design-system/components/button';
|
|
151
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
152
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
153
|
+
import SiteFooter from 'oneslash-design-system/components/siteFooter';
|
|
154
|
+
import { Center, Stack } from 'oneslash-design-system/components/layout';
|
|
155
|
+
|
|
156
|
+
type Choices = { visits: boolean; marketing: boolean };
|
|
157
|
+
|
|
158
|
+
export default function CookieChoiceSettings() {
|
|
159
|
+
// Opens on the Modal, as if the visitor just chose 'Cookie Settings' in the footer.
|
|
160
|
+
const [open, setOpen] = useState(true);
|
|
161
|
+
// The visitor's last choice, kept in the browser. Here they chose Reject All, so every optional cookie is off.
|
|
162
|
+
const [saved, setSaved] = useState<Choices>({ visits: false, marketing: false });
|
|
163
|
+
const [draft, setDraft] = useState<Choices>(saved);
|
|
164
|
+
const [justSaved, setJustSaved] = useState(false);
|
|
165
|
+
const savedTimer = useRef<ReturnType<typeof setTimeout>>();
|
|
166
|
+
// Save is disabled while the switches match what was saved, and while 'Saved' shows it stays enabled.
|
|
167
|
+
const changed = draft.visits !== saved.visits || draft.marketing !== saved.marketing;
|
|
168
|
+
|
|
169
|
+
// Stops the 'Saved' timer if the example goes away before it ends.
|
|
170
|
+
useEffect(() => () => clearTimeout(savedTimer.current), []);
|
|
171
|
+
|
|
172
|
+
// One Save for the group. The choice is kept in the browser, so it saves at once, and 'Saved' shows for 2 seconds.
|
|
173
|
+
// A press while 'Saved' shows and nothing changed does nothing.
|
|
174
|
+
function handleSave() {
|
|
175
|
+
if (!changed) return;
|
|
176
|
+
setSaved(draft);
|
|
177
|
+
setJustSaved(true);
|
|
178
|
+
clearTimeout(savedTimer.current);
|
|
179
|
+
savedTimer.current = setTimeout(() => setJustSaved(false), 2000);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Cancel, Escape and a click outside drop what was not saved.
|
|
183
|
+
function handleClose() {
|
|
184
|
+
setDraft(saved);
|
|
185
|
+
setJustSaved(false);
|
|
186
|
+
setOpen(false);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return (
|
|
190
|
+
<>
|
|
191
|
+
<Stack gap="huge">
|
|
192
|
+
<Center width="page">
|
|
193
|
+
<Stack gap="large">
|
|
194
|
+
<Heading level={1} size="h5">Privacy</Heading>
|
|
195
|
+
<Paragraph tone="secondary" measure="none">Acme uses cookies to keep you logged in. Visit counts and marketing stay off until you turn them on.</Paragraph>
|
|
196
|
+
</Stack>
|
|
197
|
+
</Center>
|
|
198
|
+
{/* The footer's 'Cookie Settings' link comes to this page, which opens the Modal. The visitor can change the choice at any time. */}
|
|
199
|
+
<SiteFooter
|
|
200
|
+
brand={{ href: '#top', name: 'Acme' }}
|
|
201
|
+
links={[
|
|
202
|
+
{ label: 'Terms', href: '#terms' },
|
|
203
|
+
{ label: 'Privacy', href: '#privacy' },
|
|
204
|
+
{ label: 'Cookie Settings', href: '#cookie-settings' },
|
|
205
|
+
]}
|
|
206
|
+
legal="© 2026 Acme. All rights reserved."
|
|
207
|
+
/>
|
|
208
|
+
</Stack>
|
|
209
|
+
<Modal
|
|
210
|
+
isOpen={open}
|
|
211
|
+
size="small"
|
|
212
|
+
title="Cookie Settings"
|
|
213
|
+
onClose={handleClose}
|
|
214
|
+
actions={
|
|
215
|
+
<>
|
|
216
|
+
<Button size="small" type="tertiary" state="enabled" label="Cancel" onClickButton={handleClose} />
|
|
217
|
+
<Button size="small" type="primary" state={changed || justSaved ? 'enabled' : 'disabled'} label={justSaved ? 'Saved' : 'Save Choices'} onClickButton={handleSave} />
|
|
218
|
+
</>
|
|
219
|
+
}
|
|
220
|
+
>
|
|
221
|
+
<Stack gap="medium">
|
|
222
|
+
<Switch id="cookie-choice-settings-needed" label="Needed to run the site" description="Keeps you logged in. Always on." checked disabled onChange={() => {}} />
|
|
223
|
+
<Switch id="cookie-choice-settings-visits" label="Visit counts" checked={draft.visits} onChange={(visits) => setDraft((d) => ({ ...d, visits }))} />
|
|
224
|
+
<Switch id="cookie-choice-settings-marketing" label="Marketing" checked={draft.marketing} onChange={(marketing) => setDraft((d) => ({ ...d, marketing }))} />
|
|
225
|
+
</Stack>
|
|
226
|
+
</Modal>
|
|
227
|
+
</>
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Native
|
|
233
|
+
|
|
234
|
+
An app uses the system tracking prompt (App Tracking Transparency on Apple) and never a banner.
|
|
@@ -1,4 +1,13 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
import { useEffect, useRef, useState } from 'react';
|
|
3
12
|
import AppShell from '../../components/appShell';
|
|
4
13
|
import TitleBar from '../../components/titleBar';
|
|
@@ -14,6 +23,7 @@ import Button from '../../components/button';
|
|
|
14
23
|
import Paragraph from '../../components/paragraph';
|
|
15
24
|
import EmptyBox from '../../components/emptyBox';
|
|
16
25
|
import List from '../../components/list';
|
|
26
|
+
import BarChart from '../../components/barChart';
|
|
17
27
|
import { formatCount } from '../../components/formatNumber';
|
|
18
28
|
import { Cluster, Grid, Stack } from '../../components/layout';
|
|
19
29
|
var ranges = [
|
|
@@ -58,6 +68,32 @@ var data = {
|
|
|
58
68
|
},
|
|
59
69
|
};
|
|
60
70
|
var noun = { week: 'this week', month: 'this month', quarter: 'this quarter' };
|
|
71
|
+
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
72
|
+
// 'Nov 14' for the day `back` days before Nov 16, 2026. Written from UTC, so the server and the browser agree.
|
|
73
|
+
function day(back) {
|
|
74
|
+
var d = new Date(Date.UTC(2026, 10, 16 - back));
|
|
75
|
+
return "".concat(months[d.getUTCMonth()], " ").concat(d.getUTCDate());
|
|
76
|
+
}
|
|
77
|
+
// New comments per day, adding up to the tile above. The quarter is counted by week: 13 weeks, the last from Nov 10 to Nov 16.
|
|
78
|
+
var week = [152, 168, 149, 181, 190, 186, 214];
|
|
79
|
+
var month = __spreadArray([144, 157, 148, 162, 153, 145, 159, 150, 164, 155, 147, 160, 152, 166, 157, 149, 162, 153, 168, 159, 151, 164, 155], week, true);
|
|
80
|
+
var quarter = [1181, 1234, 1216, 1198, 1251, 1233, 1215, 1197, 1250, 1232, 1214, 1219, 1240];
|
|
81
|
+
var perDay = {
|
|
82
|
+
week: week.map(function (value, i) { return ({ label: day(6 - i), value: value }); }),
|
|
83
|
+
month: month.map(function (value, i) { return ({ label: day(29 - i), value: value }); }),
|
|
84
|
+
quarter: quarter.map(function (value, i) { return ({ label: day(6 + (12 - i) * 7), value: value }); }),
|
|
85
|
+
};
|
|
86
|
+
// The summary says what changed, written from the same data the chart draws.
|
|
87
|
+
function summary(range) {
|
|
88
|
+
var points = perDay[range];
|
|
89
|
+
var first = points[0];
|
|
90
|
+
var last = points[points.length - 1];
|
|
91
|
+
var when = function (p) { return (range === 'quarter' ? "in the week of ".concat(p.label) : "on ".concat(p.label)); };
|
|
92
|
+
var move = last.value > first.value ? 'rose' : last.value < first.value ? 'fell' : 'stayed';
|
|
93
|
+
return move === 'stayed'
|
|
94
|
+
? "Comments stayed at ".concat(formatCount(first.value), " from ").concat(first.label, " to ").concat(last.label, ".")
|
|
95
|
+
: "Comments ".concat(move, " from ").concat(formatCount(first.value), " ").concat(when(first), " to ").concat(formatCount(last.value), " ").concat(when(last), ".");
|
|
96
|
+
}
|
|
61
97
|
export default function DashboardNumbersFirst() {
|
|
62
98
|
var _a = useState('week'), range = _a[0], setRange = _a[1];
|
|
63
99
|
// The numbers load again when the range changes.
|
|
@@ -65,13 +101,18 @@ export default function DashboardNumbersFirst() {
|
|
|
65
101
|
// The projects section fails first, so the rest of the page shows that one section can fail alone.
|
|
66
102
|
var _c = useState(true), projectsFailed = _c[0], setProjectsFailed = _c[1];
|
|
67
103
|
var _d = useState(false), retrying = _d[0], setRetrying = _d[1];
|
|
68
|
-
|
|
104
|
+
// The chart starts loaded. A real app sets this when the chart's request fails.
|
|
105
|
+
var _e = useState(false), trendFailed = _e[0], setTrendFailed = _e[1];
|
|
106
|
+
var _f = useState(false), trendRetrying = _f[0], setTrendRetrying = _f[1];
|
|
107
|
+
var _g = useState(false), navOpen = _g[0], setNavOpen = _g[1];
|
|
69
108
|
var timer = useRef();
|
|
70
109
|
var retryTimer = useRef();
|
|
110
|
+
var trendTimer = useRef();
|
|
71
111
|
// Stops the requests if the example goes away before they end.
|
|
72
112
|
useEffect(function () { return function () {
|
|
73
113
|
clearTimeout(timer.current);
|
|
74
114
|
clearTimeout(retryTimer.current);
|
|
115
|
+
clearTimeout(trendTimer.current);
|
|
75
116
|
}; }, []);
|
|
76
117
|
function changeRange(next) {
|
|
77
118
|
clearTimeout(timer.current);
|
|
@@ -89,6 +130,15 @@ export default function DashboardNumbersFirst() {
|
|
|
89
130
|
setProjectsFailed(false);
|
|
90
131
|
}, 1200);
|
|
91
132
|
}
|
|
133
|
+
function tryTrendAgain() {
|
|
134
|
+
if (trendRetrying)
|
|
135
|
+
return;
|
|
136
|
+
setTrendRetrying(true);
|
|
137
|
+
trendTimer.current = setTimeout(function () {
|
|
138
|
+
setTrendRetrying(false);
|
|
139
|
+
setTrendFailed(false);
|
|
140
|
+
}, 1200);
|
|
141
|
+
}
|
|
92
142
|
var d = data[range];
|
|
93
143
|
var period = range;
|
|
94
144
|
var projectTotal = d.projects.reduce(function (sum, p) { return sum + p[1]; }, 0);
|
|
@@ -108,13 +158,23 @@ export default function DashboardNumbersFirst() {
|
|
|
108
158
|
})}
|
|
109
159
|
</Navigation>);
|
|
110
160
|
var statRow = (<SettingsSection key="stats" title={"Numbers ".concat(noun[range])} id="dashboard-stats">
|
|
111
|
-
<Grid compact columns={4}>
|
|
161
|
+
<Grid compact columns={4} from="lg">
|
|
112
162
|
<StatTile label="New comments" value={d.stats.comments[0]} previous={d.stats.comments[1]} period={period} loading={loading}/>
|
|
113
163
|
<StatTile label="Marked done" value={d.stats.done[0]} previous={d.stats.done[1]} period={period} loading={loading}/>
|
|
114
164
|
<StatTile label="People engaged" value={d.stats.people[0]} previous={d.stats.people[1]} period={period} loading={loading}/>
|
|
115
165
|
<StatTile label="Average reply time" value={d.stats.reply[0]} format="duration" previous={d.stats.reply[1]} period={period} loading={loading}/>
|
|
116
166
|
</Grid>
|
|
117
167
|
</SettingsSection>);
|
|
168
|
+
// A trend over the range goes under the stat row, over the same range.
|
|
169
|
+
var trend = (<SettingsSection key="trend" title={"Comments ".concat(noun[range])} id="dashboard-trend">
|
|
170
|
+
{trendFailed ? (<>
|
|
171
|
+
{/* Only the chart failed, as the case 'Load failure' says. The rest of the page still shows. */}
|
|
172
|
+
<Alert type="error" variant="inline" message="Could not load comments." autoDismiss={false}/>
|
|
173
|
+
<Cluster>
|
|
174
|
+
<Button size="small" type="primary" state="enabled" label="Try Again" loading={trendRetrying} onClickButton={tryTrendAgain}/>
|
|
175
|
+
</Cluster>
|
|
176
|
+
</>) : (<BarChart id="dashboard-comments-per-day" title={range === 'quarter' ? 'Comments per week' : 'Comments per day'} summary={summary(range)} data={perDay[range]} unit="comments" labelHeader={range === 'quarter' ? 'Week of' : 'Date'} loading={loading} emptyText={"No comments ".concat(noun[range])}/>)}
|
|
177
|
+
</SettingsSection>);
|
|
118
178
|
var projects = (<SettingsSection key="projects" title="Projects" description={"".concat(formatCount(projectTotal), " comments ").concat(noun[range], ", by project")} id="dashboard-projects">
|
|
119
179
|
{projectsFailed ? (<>
|
|
120
180
|
{/* Only this section failed. The rest of the page still shows. */}
|
|
@@ -157,6 +217,7 @@ export default function DashboardNumbersFirst() {
|
|
|
157
217
|
{/* Below md the range switch takes its own line under the title. */}
|
|
158
218
|
<TitleBar title="Dashboard" actionsBelow actions={<SegmentedControl size="small" width="fit" aria-label="Range" options={ranges} value={range} onChange={changeRange}/>}/>
|
|
159
219
|
{statRow}
|
|
220
|
+
{trend}
|
|
160
221
|
{projects}
|
|
161
222
|
{waiting}
|
|
162
223
|
{questions}
|
|
@@ -108,7 +108,7 @@ export default function DashboardWorkFirst() {
|
|
|
108
108
|
})}
|
|
109
109
|
</Navigation>);
|
|
110
110
|
var statRow = (<SettingsSection key="stats" title={"Numbers ".concat(noun[range])} id="dashboard-stats">
|
|
111
|
-
<Grid compact columns={4}>
|
|
111
|
+
<Grid compact columns={4} from="lg">
|
|
112
112
|
<StatTile label="New comments" value={d.stats.comments[0]} previous={d.stats.comments[1]} period={period} loading={loading}/>
|
|
113
113
|
<StatTile label="Marked done" value={d.stats.done[0]} previous={d.stats.done[1]} period={period} loading={loading}/>
|
|
114
114
|
<StatTile label="People engaged" value={d.stats.people[0]} previous={d.stats.people[1]} period={period} loading={loading}/>
|
package/dist/cases/dashboard.md
CHANGED
|
@@ -8,6 +8,7 @@ A page that opens an app and says how things are going and what waits on the per
|
|
|
8
8
|
- Put the page in `AppShell`, with a `TitleBar` named 'Dashboard' and a 'Range' `SegmentedControl` as its `actions`, as the case 'Range switch' says. Set `actionsBelow` so the switch takes its own line under the title on a phone.
|
|
9
9
|
- Let the one range drive every number on the page, and name it in every heading and caption: 'this week'.
|
|
10
10
|
- Show the stat row as the case 'Stat row' says, and a share of a total as the case 'Breakdown of a total' says.
|
|
11
|
+
- Show a trend over the range as the case 'Chart' says, under the stat row, over the same range.
|
|
11
12
|
- Make each section a `SettingsSection`: a hairline, a title and its content. Do not put a section in a box.
|
|
12
13
|
- Put the list of what waits on the person in a section titled with its count and unit: '3 comments waiting on you'. Make each row a link.
|
|
13
14
|
- Show a list that can be longer than its section as the case 'Short list on a dashboard' says.
|
|
@@ -17,7 +18,7 @@ A page that opens an app and says how things are going and what waits on the per
|
|
|
17
18
|
|
|
18
19
|
## Don't
|
|
19
20
|
|
|
20
|
-
- Do not draw a chart
|
|
21
|
+
- Do not draw a chart for one number or for a share. A trend over the range follows the case 'Chart'.
|
|
21
22
|
- Do not count different sections over different ranges.
|
|
22
23
|
- Do not replace the whole page when one section failed.
|
|
23
24
|
- Do not put more than four tiles in the stat row.
|
|
@@ -28,7 +29,7 @@ A page that opens an app and says how things are going and what waits on the per
|
|
|
28
29
|
|
|
29
30
|
Use when: The page reports how things went, for a lead who checks on a team.
|
|
30
31
|
|
|
31
|
-
Uses: `Alert`, `AppShell`, `Button`, `Cluster`, `EmptyBox`, `Grid`, `List`, `MenuItem`, `Navigation`, `Paragraph`, `Progress`, `SegmentedControl`, `SettingsSection`, `Skeleton`, `Stack`, `StatTile`, `TitleBar`, `formatCount`
|
|
32
|
+
Uses: `Alert`, `AppShell`, `BarChart`, `Button`, `Cluster`, `EmptyBox`, `Grid`, `List`, `MenuItem`, `Navigation`, `Paragraph`, `Progress`, `SegmentedControl`, `SettingsSection`, `Skeleton`, `Stack`, `StatTile`, `TitleBar`, `formatCount`
|
|
32
33
|
|
|
33
34
|
```tsx
|
|
34
35
|
'use client';
|
|
@@ -47,6 +48,7 @@ import Button from 'oneslash-design-system/components/button';
|
|
|
47
48
|
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
48
49
|
import EmptyBox from 'oneslash-design-system/components/emptyBox';
|
|
49
50
|
import List from 'oneslash-design-system/components/list';
|
|
51
|
+
import BarChart from 'oneslash-design-system/components/barChart';
|
|
50
52
|
import { formatCount } from 'oneslash-design-system/components/formatNumber';
|
|
51
53
|
import { Cluster, Grid, Stack } from 'oneslash-design-system/components/layout';
|
|
52
54
|
|
|
@@ -96,6 +98,35 @@ const data = {
|
|
|
96
98
|
|
|
97
99
|
const noun: Record<Range, string> = { week: 'this week', month: 'this month', quarter: 'this quarter' };
|
|
98
100
|
|
|
101
|
+
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
102
|
+
// 'Nov 14' for the day `back` days before Nov 16, 2026. Written from UTC, so the server and the browser agree.
|
|
103
|
+
function day(back: number) {
|
|
104
|
+
const d = new Date(Date.UTC(2026, 10, 16 - back));
|
|
105
|
+
return `${months[d.getUTCMonth()]} ${d.getUTCDate()}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// New comments per day, adding up to the tile above. The quarter is counted by week: 13 weeks, the last from Nov 10 to Nov 16.
|
|
109
|
+
const week = [152, 168, 149, 181, 190, 186, 214];
|
|
110
|
+
const month = [144, 157, 148, 162, 153, 145, 159, 150, 164, 155, 147, 160, 152, 166, 157, 149, 162, 153, 168, 159, 151, 164, 155, ...week];
|
|
111
|
+
const quarter = [1181, 1234, 1216, 1198, 1251, 1233, 1215, 1197, 1250, 1232, 1214, 1219, 1240];
|
|
112
|
+
const perDay: Record<Range, { label: string; value: number }[]> = {
|
|
113
|
+
week: week.map((value, i) => ({ label: day(6 - i), value })),
|
|
114
|
+
month: month.map((value, i) => ({ label: day(29 - i), value })),
|
|
115
|
+
quarter: quarter.map((value, i) => ({ label: day(6 + (12 - i) * 7), value })),
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// The summary says what changed, written from the same data the chart draws.
|
|
119
|
+
function summary(range: Range) {
|
|
120
|
+
const points = perDay[range];
|
|
121
|
+
const first = points[0];
|
|
122
|
+
const last = points[points.length - 1];
|
|
123
|
+
const when = (p: { label: string }) => (range === 'quarter' ? `in the week of ${p.label}` : `on ${p.label}`);
|
|
124
|
+
const move = last.value > first.value ? 'rose' : last.value < first.value ? 'fell' : 'stayed';
|
|
125
|
+
return move === 'stayed'
|
|
126
|
+
? `Comments stayed at ${formatCount(first.value)} from ${first.label} to ${last.label}.`
|
|
127
|
+
: `Comments ${move} from ${formatCount(first.value)} ${when(first)} to ${formatCount(last.value)} ${when(last)}.`;
|
|
128
|
+
}
|
|
129
|
+
|
|
99
130
|
export default function DashboardNumbersFirst() {
|
|
100
131
|
const [range, setRange] = useState<Range>('week');
|
|
101
132
|
// The numbers load again when the range changes.
|
|
@@ -103,14 +134,19 @@ export default function DashboardNumbersFirst() {
|
|
|
103
134
|
// The projects section fails first, so the rest of the page shows that one section can fail alone.
|
|
104
135
|
const [projectsFailed, setProjectsFailed] = useState(true);
|
|
105
136
|
const [retrying, setRetrying] = useState(false);
|
|
137
|
+
// The chart starts loaded. A real app sets this when the chart's request fails.
|
|
138
|
+
const [trendFailed, setTrendFailed] = useState(false);
|
|
139
|
+
const [trendRetrying, setTrendRetrying] = useState(false);
|
|
106
140
|
const [navOpen, setNavOpen] = useState(false);
|
|
107
141
|
const timer = useRef<ReturnType<typeof setTimeout>>();
|
|
108
142
|
const retryTimer = useRef<ReturnType<typeof setTimeout>>();
|
|
143
|
+
const trendTimer = useRef<ReturnType<typeof setTimeout>>();
|
|
109
144
|
|
|
110
145
|
// Stops the requests if the example goes away before they end.
|
|
111
146
|
useEffect(() => () => {
|
|
112
147
|
clearTimeout(timer.current);
|
|
113
148
|
clearTimeout(retryTimer.current);
|
|
149
|
+
clearTimeout(trendTimer.current);
|
|
114
150
|
}, []);
|
|
115
151
|
|
|
116
152
|
function changeRange(next: string) {
|
|
@@ -130,6 +166,15 @@ export default function DashboardNumbersFirst() {
|
|
|
130
166
|
}, 1200);
|
|
131
167
|
}
|
|
132
168
|
|
|
169
|
+
function tryTrendAgain() {
|
|
170
|
+
if (trendRetrying) return;
|
|
171
|
+
setTrendRetrying(true);
|
|
172
|
+
trendTimer.current = setTimeout(() => {
|
|
173
|
+
setTrendRetrying(false);
|
|
174
|
+
setTrendFailed(false);
|
|
175
|
+
}, 1200);
|
|
176
|
+
}
|
|
177
|
+
|
|
133
178
|
const d = data[range];
|
|
134
179
|
const period = range;
|
|
135
180
|
const projectTotal = d.projects.reduce((sum, p) => sum + p[1], 0);
|
|
@@ -162,7 +207,7 @@ export default function DashboardNumbersFirst() {
|
|
|
162
207
|
|
|
163
208
|
const statRow = (
|
|
164
209
|
<SettingsSection key="stats" title={`Numbers ${noun[range]}`} id="dashboard-stats">
|
|
165
|
-
<Grid compact columns={4}>
|
|
210
|
+
<Grid compact columns={4} from="lg">
|
|
166
211
|
<StatTile label="New comments" value={d.stats.comments[0]} previous={d.stats.comments[1]} period={period} loading={loading} />
|
|
167
212
|
<StatTile label="Marked done" value={d.stats.done[0]} previous={d.stats.done[1]} period={period} loading={loading} />
|
|
168
213
|
<StatTile label="People engaged" value={d.stats.people[0]} previous={d.stats.people[1]} period={period} loading={loading} />
|
|
@@ -171,6 +216,32 @@ export default function DashboardNumbersFirst() {
|
|
|
171
216
|
</SettingsSection>
|
|
172
217
|
);
|
|
173
218
|
|
|
219
|
+
// A trend over the range goes under the stat row, over the same range.
|
|
220
|
+
const trend = (
|
|
221
|
+
<SettingsSection key="trend" title={`Comments ${noun[range]}`} id="dashboard-trend">
|
|
222
|
+
{trendFailed ? (
|
|
223
|
+
<>
|
|
224
|
+
{/* Only the chart failed, as the case 'Load failure' says. The rest of the page still shows. */}
|
|
225
|
+
<Alert type="error" variant="inline" message="Could not load comments." autoDismiss={false} />
|
|
226
|
+
<Cluster>
|
|
227
|
+
<Button size="small" type="primary" state="enabled" label="Try Again" loading={trendRetrying} onClickButton={tryTrendAgain} />
|
|
228
|
+
</Cluster>
|
|
229
|
+
</>
|
|
230
|
+
) : (
|
|
231
|
+
<BarChart
|
|
232
|
+
id="dashboard-comments-per-day"
|
|
233
|
+
title={range === 'quarter' ? 'Comments per week' : 'Comments per day'}
|
|
234
|
+
summary={summary(range)}
|
|
235
|
+
data={perDay[range]}
|
|
236
|
+
unit="comments"
|
|
237
|
+
labelHeader={range === 'quarter' ? 'Week of' : 'Date'}
|
|
238
|
+
loading={loading}
|
|
239
|
+
emptyText={`No comments ${noun[range]}`}
|
|
240
|
+
/>
|
|
241
|
+
)}
|
|
242
|
+
</SettingsSection>
|
|
243
|
+
);
|
|
244
|
+
|
|
174
245
|
const projects = (
|
|
175
246
|
<SettingsSection key="projects" title="Projects" description={`${formatCount(projectTotal)} comments ${noun[range]}, by project`} id="dashboard-projects">
|
|
176
247
|
{projectsFailed ? (
|
|
@@ -254,6 +325,7 @@ export default function DashboardNumbersFirst() {
|
|
|
254
325
|
actions={<SegmentedControl size="small" width="fit" aria-label="Range" options={ranges} value={range} onChange={changeRange} />}
|
|
255
326
|
/>
|
|
256
327
|
{statRow}
|
|
328
|
+
{trend}
|
|
257
329
|
{projects}
|
|
258
330
|
{waiting}
|
|
259
331
|
{questions}
|
|
@@ -401,7 +473,7 @@ export default function DashboardWorkFirst() {
|
|
|
401
473
|
|
|
402
474
|
const statRow = (
|
|
403
475
|
<SettingsSection key="stats" title={`Numbers ${noun[range]}`} id="dashboard-stats">
|
|
404
|
-
<Grid compact columns={4}>
|
|
476
|
+
<Grid compact columns={4} from="lg">
|
|
405
477
|
<StatTile label="New comments" value={d.stats.comments[0]} previous={d.stats.comments[1]} period={period} loading={loading} />
|
|
406
478
|
<StatTile label="Marked done" value={d.stats.done[0]} previous={d.stats.done[1]} period={period} loading={loading} />
|
|
407
479
|
<StatTile label="People engaged" value={d.stats.people[0]} previous={d.stats.people[1]} period={period} loading={loading} />
|
|
@@ -504,4 +576,4 @@ export default function DashboardWorkFirst() {
|
|
|
504
576
|
|
|
505
577
|
## Native
|
|
506
578
|
|
|
507
|
-
On Apple use a `List` of `Section`s in a `NavigationStack`, with a `Picker` in the `.segmented` style in the toolbar. On Android use a `LazyColumn` with a `SingleChoiceSegmentedButtonRow` in the top bar.
|
|
579
|
+
On Apple use a `List` of `Section`s in a `NavigationStack`, with a `Picker` in the `.segmented` style in the toolbar. On Android use a `LazyColumn` with a `SingleChoiceSegmentedButtonRow` in the top bar. Draw a trend over the range with Swift Charts as the case 'Chart' says; on Android draw it on a `Canvas` or show the table.
|
|
@@ -187,7 +187,7 @@ export default function DataTablePageAllRows() {
|
|
|
187
187
|
</TableContainer>)}
|
|
188
188
|
</Stack>
|
|
189
189
|
|
|
190
|
-
<Popover open={searchOpen} anchorEl={searchAnchor} onClose={function () { return setSearchOpen(false); }} returnFocus>
|
|
190
|
+
<Popover open={searchOpen} anchorEl={searchAnchor} onClose={function () { return setSearchOpen(false); }} returnFocus aria-label="Search">
|
|
191
191
|
<Menu width={288}>
|
|
192
192
|
<TextField id="data-table-page-all-rows-search" type="search" size="small" autoFocus aria-label="Search invoices" placeholder="Search invoices" value={query} onChange={function (e) { return setQuery(e.target.value); }} onKeyDown={function (e) {
|
|
193
193
|
// Escape clears the search and closes. Enter closes and keeps it.
|
|
@@ -245,7 +245,7 @@ export default function DataTablePagePaged() {
|
|
|
245
245
|
<Pagination aria-label="Invoice pages" page={page} pageCount={pageCount} onPageChange={goToPage} scrollTargetId="data-table-page-paged-top"/>
|
|
246
246
|
</Stack>
|
|
247
247
|
|
|
248
|
-
<Popover open={searchOpen} anchorEl={searchAnchor} onClose={function () { return setSearchOpen(false); }} returnFocus>
|
|
248
|
+
<Popover open={searchOpen} anchorEl={searchAnchor} onClose={function () { return setSearchOpen(false); }} returnFocus aria-label="Search">
|
|
249
249
|
<Menu width={288}>
|
|
250
250
|
<TextField id="data-table-page-paged-search" type="search" size="small" autoFocus aria-label="Search invoices" placeholder="Search invoices" value={query} onChange={function (e) { return change({ query: e.target.value }); }} onKeyDown={function (e) {
|
|
251
251
|
// Escape clears the search and closes. Enter closes and keeps it.
|
|
@@ -369,7 +369,7 @@ export default function DataTablePagePaged() {
|
|
|
369
369
|
<Pagination aria-label="Invoice pages" page={page} pageCount={pageCount} onPageChange={goToPage} scrollTargetId="data-table-page-paged-top" />
|
|
370
370
|
</Stack>
|
|
371
371
|
|
|
372
|
-
<Popover open={searchOpen} anchorEl={searchAnchor} onClose={() => setSearchOpen(false)} returnFocus>
|
|
372
|
+
<Popover open={searchOpen} anchorEl={searchAnchor} onClose={() => setSearchOpen(false)} returnFocus aria-label="Search">
|
|
373
373
|
<Menu width={288}>
|
|
374
374
|
<TextField
|
|
375
375
|
id="data-table-page-paged-search"
|
|
@@ -701,7 +701,7 @@ export default function DataTablePageAllRows() {
|
|
|
701
701
|
)}
|
|
702
702
|
</Stack>
|
|
703
703
|
|
|
704
|
-
<Popover open={searchOpen} anchorEl={searchAnchor} onClose={() => setSearchOpen(false)} returnFocus>
|
|
704
|
+
<Popover open={searchOpen} anchorEl={searchAnchor} onClose={() => setSearchOpen(false)} returnFocus aria-label="Search">
|
|
705
705
|
<Menu width={288}>
|
|
706
706
|
<TextField
|
|
707
707
|
id="data-table-page-all-rows-search"
|
|
@@ -14,13 +14,25 @@ import { formatMoney } from '../../components/formatNumber';
|
|
|
14
14
|
import { Center, Stack } from '../../components/layout';
|
|
15
15
|
// A real app reads these from the server, newest first.
|
|
16
16
|
var months = ['Nov 1, 2026', 'Oct 1, 2026', 'Sep 1, 2026', 'Aug 1, 2026', 'Jul 1, 2026', 'Jun 1, 2026', 'May 1, 2026', 'Apr 1, 2026', 'Mar 1, 2026', 'Feb 1, 2026', 'Jan 1, 2026', 'Dec 1, 2025', 'Nov 1, 2025', 'Oct 1, 2025'];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
date:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
// Each refund by the charge it refunds: all of August, and 15 days of October.
|
|
18
|
+
var refunds = {
|
|
19
|
+
'Aug 1, 2026': { id: 'ref-0', kind: 'refund', date: 'Aug 6, 2026', description: 'Refund for Pro plan, Aug 2026', amount: -24, status: 'Issued' },
|
|
20
|
+
'Oct 1, 2026': { id: 'ref-1', kind: 'refund', date: 'Oct 16, 2026', description: 'Refund for 15 days of Pro, Oct 2026', amount: -12, status: 'Issued' },
|
|
21
|
+
};
|
|
22
|
+
var invoices = months.flatMap(function (date, i) {
|
|
23
|
+
var amount = 24;
|
|
24
|
+
var charge = {
|
|
25
|
+
id: "inv-".concat(i),
|
|
26
|
+
kind: 'charge',
|
|
27
|
+
date: date,
|
|
28
|
+
description: "Pro plan, ".concat(date.split(' ')[0], " ").concat(date.split(', ')[1]),
|
|
29
|
+
amount: amount,
|
|
30
|
+
// Refunded in full, or still Paid when only part came back
|
|
31
|
+
status: refunds[date] && -refunds[date].amount === amount ? 'Refunded' : 'Paid',
|
|
32
|
+
};
|
|
33
|
+
// The refund came later, so it sits above its charge
|
|
34
|
+
return refunds[date] ? [refunds[date], charge] : [charge];
|
|
35
|
+
});
|
|
24
36
|
var PAGE_SIZE = 12;
|
|
25
37
|
export default function InvoiceListTable() {
|
|
26
38
|
var _a = useState(1), page = _a[0], setPage = _a[1];
|
|
@@ -45,14 +57,14 @@ export default function InvoiceListTable() {
|
|
|
45
57
|
{rows.map(function (inv) { return (<TableRow key={inv.id}>
|
|
46
58
|
<TableCell width="130px">{inv.date}</TableCell>
|
|
47
59
|
<TableCell>{inv.description}</TableCell>
|
|
48
|
-
{/* A table shows the exact amount, right-aligned. */}
|
|
60
|
+
{/* A table shows the exact amount, right-aligned. A refund has a minus: '-$24.00'. */}
|
|
49
61
|
<TableCell width="100px" align="right">{formatMoney(inv.amount)}</TableCell>
|
|
50
62
|
<TableCell width="110px">
|
|
51
63
|
<Tag variant="textOnly" size="small" label={inv.status}/>
|
|
52
64
|
</TableCell>
|
|
53
65
|
<TableCell width="130px">
|
|
54
66
|
{/* A real app links to the file on its own server. The name says which invoice and that it opens a tab. */}
|
|
55
|
-
<Button size="small" type="tertiary" state="enabled" label="Download" aria-label={"Download invoice for ".concat(inv.date, ", opens in a new tab")} actionIcon="ExternalLink" href={"https://acme.example/invoices/".concat(inv.id, ".pdf")} openInNewTab/>
|
|
67
|
+
<Button size="small" type="tertiary" state="enabled" label="Download" aria-label={"Download ".concat(inv.kind === 'refund' ? 'refund' : 'invoice', " for ").concat(inv.date, ", opens in a new tab")} actionIcon="ExternalLink" href={"https://acme.example/invoices/".concat(inv.id, ".pdf")} openInNewTab/>
|
|
56
68
|
</TableCell>
|
|
57
69
|
</TableRow>); })}
|
|
58
70
|
</TableContainer>
|