oneslash-design-system 2.18.0 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/README.md +1 -1
  2. package/dist/DESIGN.md +54 -5
  3. package/dist/cases/app-shell/sidebar.d.ts +1 -0
  4. package/dist/cases/app-shell/sidebar.jsx +124 -0
  5. package/dist/cases/app-shell/top-tabs.d.ts +1 -0
  6. package/dist/cases/app-shell/top-tabs.jsx +106 -0
  7. package/dist/cases/app-shell.md +364 -0
  8. package/dist/cases/artifact-card/card.jsx +32 -6
  9. package/dist/cases/artifact-card.md +55 -7
  10. package/dist/cases/billing-page/billed-elsewhere.d.ts +1 -0
  11. package/dist/cases/billing-page/billed-elsewhere.jsx +28 -0
  12. package/dist/cases/billing-page/self-serve.d.ts +1 -0
  13. package/dist/cases/billing-page/self-serve.jsx +134 -0
  14. package/dist/cases/billing-page.md +247 -0
  15. package/dist/cases/breakdown-list/bars.d.ts +1 -0
  16. package/dist/cases/breakdown-list/bars.jsx +47 -0
  17. package/dist/cases/breakdown-list/table.d.ts +1 -0
  18. package/dist/cases/breakdown-list/table.jsx +69 -0
  19. package/dist/cases/breakdown-list.md +158 -0
  20. package/dist/cases/composer-limit/notice-with-action.jsx +3 -3
  21. package/dist/cases/composer-limit/notice.jsx +3 -3
  22. package/dist/cases/composer-limit.md +8 -8
  23. package/dist/cases/dashboard/numbers-first.d.ts +1 -0
  24. package/dist/cases/dashboard/numbers-first.jsx +165 -0
  25. package/dist/cases/dashboard/work-first.d.ts +1 -0
  26. package/dist/cases/dashboard/work-first.jsx +165 -0
  27. package/dist/cases/dashboard.md +507 -0
  28. package/dist/cases/data-table-page/all-rows.d.ts +1 -0
  29. package/dist/cases/data-table-page/all-rows.jsx +226 -0
  30. package/dist/cases/data-table-page/paged.d.ts +1 -0
  31. package/dist/cases/data-table-page/paged.jsx +284 -0
  32. package/dist/cases/data-table-page.md +771 -0
  33. package/dist/cases/error-page/in-shell.jsx +26 -17
  34. package/dist/cases/error-page.md +42 -21
  35. package/dist/cases/invoice-list/table.d.ts +1 -0
  36. package/dist/cases/invoice-list/table.jsx +64 -0
  37. package/dist/cases/invoice-list/with-upcoming.d.ts +1 -0
  38. package/dist/cases/invoice-list/with-upcoming.jsx +75 -0
  39. package/dist/cases/invoice-list.md +237 -0
  40. package/dist/cases/load-failure/inline.jsx +2 -2
  41. package/dist/cases/load-failure.md +2 -2
  42. package/dist/cases/master-detail/list-then-page.d.ts +1 -0
  43. package/dist/cases/master-detail/list-then-page.jsx +65 -0
  44. package/dist/cases/master-detail/split.d.ts +1 -0
  45. package/dist/cases/master-detail/split.jsx +49 -0
  46. package/dist/cases/master-detail.md +213 -0
  47. package/dist/cases/members-list/rows.jsx +2 -1
  48. package/dist/cases/members-list/table.jsx +8 -9
  49. package/dist/cases/members-list.md +12 -13
  50. package/dist/cases/mobile-menu/links.d.ts +1 -0
  51. package/dist/cases/mobile-menu/links.jsx +24 -0
  52. package/dist/cases/mobile-menu/sections.d.ts +1 -0
  53. package/dist/cases/mobile-menu/sections.jsx +61 -0
  54. package/dist/cases/mobile-menu.md +170 -0
  55. package/dist/cases/not-found-page/in-shell.jsx +26 -17
  56. package/dist/cases/not-found-page.md +41 -20
  57. package/dist/cases/number-format.md +36 -0
  58. package/dist/cases/on-this-page/aside.d.ts +1 -0
  59. package/dist/cases/on-this-page/aside.jsx +39 -0
  60. package/dist/cases/on-this-page.md +80 -0
  61. package/dist/cases/page-header/actions.d.ts +1 -0
  62. package/dist/cases/page-header/actions.jsx +65 -0
  63. package/dist/cases/page-header/sub-page.d.ts +1 -0
  64. package/dist/cases/page-header/sub-page.jsx +37 -0
  65. package/dist/cases/page-header.md +195 -0
  66. package/dist/cases/paged-card/pager.d.ts +1 -0
  67. package/dist/cases/paged-card/pager.jsx +41 -0
  68. package/dist/cases/paged-card/see-all.d.ts +1 -0
  69. package/dist/cases/paged-card/see-all.jsx +34 -0
  70. package/dist/cases/paged-card.md +147 -0
  71. package/dist/cases/payment-method/none.d.ts +1 -0
  72. package/dist/cases/payment-method/none.jsx +17 -0
  73. package/dist/cases/payment-method/on-file.d.ts +1 -0
  74. package/dist/cases/payment-method/on-file.jsx +92 -0
  75. package/dist/cases/payment-method.md +182 -0
  76. package/dist/cases/phone-navigation.md +32 -0
  77. package/dist/cases/plan-change-confirm/blocked.d.ts +1 -0
  78. package/dist/cases/plan-change-confirm/blocked.jsx +48 -0
  79. package/dist/cases/plan-change-confirm/downgrade.d.ts +1 -0
  80. package/dist/cases/plan-change-confirm/downgrade.jsx +52 -0
  81. package/dist/cases/plan-change-confirm/upgrade.d.ts +1 -0
  82. package/dist/cases/plan-change-confirm/upgrade.jsx +51 -0
  83. package/dist/cases/plan-change-confirm.md +261 -0
  84. package/dist/cases/plan-picker/cards.d.ts +1 -0
  85. package/dist/cases/plan-picker/cards.jsx +97 -0
  86. package/dist/cases/plan-picker/list.d.ts +1 -0
  87. package/dist/cases/plan-picker/list.jsx +103 -0
  88. package/dist/cases/plan-picker.md +297 -0
  89. package/dist/cases/range-switch/segmented.jsx +11 -7
  90. package/dist/cases/range-switch.md +16 -11
  91. package/dist/cases/route-loading/region.jsx +27 -18
  92. package/dist/cases/route-loading.md +42 -21
  93. package/dist/cases/settings-page/top-tabs.jsx +4 -3
  94. package/dist/cases/settings-page.md +5 -4
  95. package/dist/cases/side-pane/beside.d.ts +1 -0
  96. package/dist/cases/side-pane/beside.jsx +79 -0
  97. package/dist/cases/side-pane/over.d.ts +1 -0
  98. package/dist/cases/side-pane/over.jsx +58 -0
  99. package/dist/cases/side-pane.md +238 -0
  100. package/dist/cases/sidebar-nav/flat.d.ts +1 -0
  101. package/dist/cases/sidebar-nav/flat.jsx +81 -0
  102. package/dist/cases/sidebar-nav/nested.d.ts +1 -0
  103. package/dist/cases/sidebar-nav/nested.jsx +122 -0
  104. package/dist/cases/sidebar-nav.md +261 -0
  105. package/dist/cases/site-footer/columns.d.ts +1 -0
  106. package/dist/cases/site-footer/columns.jsx +51 -0
  107. package/dist/cases/site-footer/simple.d.ts +1 -0
  108. package/dist/cases/site-footer/simple.jsx +24 -0
  109. package/dist/cases/site-footer.md +133 -0
  110. package/dist/cases/site-header/links.d.ts +1 -0
  111. package/dist/cases/site-header/links.jsx +26 -0
  112. package/dist/cases/site-header/sections.d.ts +1 -0
  113. package/dist/cases/site-header/sections.jsx +64 -0
  114. package/dist/cases/site-header.md +183 -0
  115. package/dist/cases/stat-row/featured.d.ts +1 -0
  116. package/dist/cases/stat-row/featured.jsx +17 -0
  117. package/dist/cases/stat-row/tiles.d.ts +1 -0
  118. package/dist/cases/stat-row/tiles.jsx +34 -0
  119. package/dist/cases/stat-row.md +104 -0
  120. package/dist/cases/status-label/dot.d.ts +1 -0
  121. package/dist/cases/status-label/dot.jsx +39 -0
  122. package/dist/cases/status-label/text.d.ts +1 -0
  123. package/dist/cases/status-label/text.jsx +44 -0
  124. package/dist/cases/status-label.md +143 -0
  125. package/dist/cases/theme-switcher/menu.d.ts +1 -0
  126. package/dist/cases/theme-switcher/menu.jsx +47 -0
  127. package/dist/cases/theme-switcher/segmented.d.ts +1 -0
  128. package/dist/cases/theme-switcher/segmented.jsx +26 -0
  129. package/dist/cases/theme-switcher.md +149 -0
  130. package/dist/cases/upgrade-prompt/inline.jsx +4 -2
  131. package/dist/cases/upgrade-prompt/modal.jsx +2 -1
  132. package/dist/cases/upgrade-prompt.md +10 -6
  133. package/dist/cases/usage-meters/by-person.d.ts +1 -0
  134. package/dist/cases/usage-meters/by-person.jsx +72 -0
  135. package/dist/cases/usage-meters/meters.d.ts +1 -0
  136. package/dist/cases/usage-meters/meters.jsx +49 -0
  137. package/dist/cases/usage-meters/with-cap.d.ts +1 -0
  138. package/dist/cases/usage-meters/with-cap.jsx +73 -0
  139. package/dist/cases/usage-meters.md +303 -0
  140. package/dist/cases.json +1756 -172
  141. package/dist/components/appShell.d.ts +44 -0
  142. package/dist/components/appShell.jsx +121 -0
  143. package/dist/components/button.d.ts +1 -1
  144. package/dist/components/button.jsx +11 -5
  145. package/dist/components/drawer.d.ts +31 -0
  146. package/dist/components/drawer.jsx +121 -0
  147. package/dist/components/formatNumber.d.ts +25 -0
  148. package/dist/components/formatNumber.js +125 -0
  149. package/dist/components/heading.d.ts +3 -1
  150. package/dist/components/heading.jsx +2 -2
  151. package/dist/components/iconButton.jsx +12 -7
  152. package/dist/components/link.d.ts +6 -1
  153. package/dist/components/link.jsx +11 -3
  154. package/dist/components/menuItem.d.ts +7 -1
  155. package/dist/components/menuItem.jsx +4 -3
  156. package/dist/components/modal.jsx +12 -23
  157. package/dist/components/onThisPage.d.ts +29 -0
  158. package/dist/components/onThisPage.jsx +151 -0
  159. package/dist/components/pageShell.d.ts +7 -1
  160. package/dist/components/pageShell.jsx +14 -1
  161. package/dist/components/pagination.d.ts +28 -0
  162. package/dist/components/pagination.jsx +89 -0
  163. package/dist/components/popover.jsx +4 -0
  164. package/dist/components/progress.d.ts +33 -0
  165. package/dist/components/progress.jsx +50 -0
  166. package/dist/components/settingsSection.d.ts +6 -1
  167. package/dist/components/settingsSection.jsx +10 -3
  168. package/dist/components/sidePane.d.ts +32 -0
  169. package/dist/components/sidePane.jsx +128 -0
  170. package/dist/components/siteFooter.d.ts +24 -0
  171. package/dist/components/siteFooter.jsx +48 -0
  172. package/dist/components/siteHeader.d.ts +55 -0
  173. package/dist/components/siteHeader.jsx +125 -0
  174. package/dist/components/skeleton.d.ts +21 -0
  175. package/dist/components/skeleton.jsx +41 -0
  176. package/dist/components/statTile.d.ts +32 -0
  177. package/dist/components/statTile.jsx +61 -0
  178. package/dist/components/tableContainer.d.ts +5 -1
  179. package/dist/components/tableContainer.jsx +9 -1
  180. package/dist/components/tableHeaderCell.d.ts +3 -1
  181. package/dist/components/tableHeaderCell.jsx +2 -2
  182. package/dist/components/titleBar.d.ts +19 -0
  183. package/dist/components/titleBar.jsx +18 -0
  184. package/dist/index.d.ts +12 -0
  185. package/dist/index.js +12 -0
  186. package/dist/internal/overlayStack.d.ts +24 -0
  187. package/dist/internal/overlayStack.js +71 -0
  188. package/dist/internal/resize.d.ts +9 -0
  189. package/dist/internal/resize.js +31 -0
  190. package/dist/internal/scrollSpy.d.ts +24 -0
  191. package/dist/internal/scrollSpy.js +53 -0
  192. package/dist/internal/siteBrand.d.ts +6 -0
  193. package/dist/internal/siteBrand.jsx +11 -0
  194. package/dist/native-mapping.json +69 -3
  195. package/dist/stories/AppShell.stories.d.ts +15 -0
  196. package/dist/stories/AppShell.stories.jsx +137 -0
  197. package/dist/stories/Button.stories.d.ts +1 -0
  198. package/dist/stories/Button.stories.jsx +19 -1
  199. package/dist/stories/Cases.generated.stories.d.ts +45 -0
  200. package/dist/stories/Cases.generated.stories.jsx +90 -0
  201. package/dist/stories/Drawer.stories.d.ts +10 -0
  202. package/dist/stories/Drawer.stories.jsx +123 -0
  203. package/dist/stories/Link.stories.d.ts +1 -0
  204. package/dist/stories/Link.stories.jsx +8 -0
  205. package/dist/stories/OnThisPage.stories.d.ts +10 -0
  206. package/dist/stories/OnThisPage.stories.jsx +105 -0
  207. package/dist/stories/Pagination.stories.d.ts +9 -0
  208. package/dist/stories/Pagination.stories.jsx +75 -0
  209. package/dist/stories/Progress.stories.d.ts +9 -0
  210. package/dist/stories/Progress.stories.jsx +43 -0
  211. package/dist/stories/SettingsSection.stories.d.ts +1 -0
  212. package/dist/stories/SettingsSection.stories.jsx +27 -0
  213. package/dist/stories/SidePane.stories.d.ts +6 -0
  214. package/dist/stories/SidePane.stories.jsx +37 -0
  215. package/dist/stories/SiteFooter.stories.d.ts +7 -0
  216. package/dist/stories/SiteFooter.stories.jsx +63 -0
  217. package/dist/stories/SiteHeader.stories.d.ts +10 -0
  218. package/dist/stories/SiteHeader.stories.jsx +94 -0
  219. package/dist/stories/Skeleton.stories.d.ts +7 -0
  220. package/dist/stories/Skeleton.stories.jsx +27 -0
  221. package/dist/stories/StatTile.stories.d.ts +10 -0
  222. package/dist/stories/StatTile.stories.jsx +55 -0
  223. package/dist/stories/Table.stories.d.ts +1 -0
  224. package/dist/stories/Table.stories.jsx +49 -1
  225. package/dist/stories/TitleBar.stories.d.ts +7 -0
  226. package/dist/stories/TitleBar.stories.jsx +41 -0
  227. package/package.json +5 -1
@@ -0,0 +1,226 @@
1
+ 'use client';
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import Toaster, { toast, dismissToast } from '../../components/toaster';
4
+ import TitleBar from '../../components/titleBar';
5
+ import Paragraph from '../../components/paragraph';
6
+ import Surface from '../../components/surface';
7
+ import EmptyBox from '../../components/emptyBox';
8
+ import Button from '../../components/button';
9
+ import IconButton from '../../components/iconButton';
10
+ import Tooltip from '../../components/tooltip';
11
+ import TextField from '../../components/textField';
12
+ import Popover from '../../components/popover';
13
+ import Menu from '../../components/menu';
14
+ import MenuItem from '../../components/menuItem';
15
+ import Line from '../../components/line';
16
+ import Tag from '../../components/tag';
17
+ import TableContainer from '../../components/tableContainer';
18
+ import TableHeader from '../../components/tableHeader';
19
+ import TableHeaderCell from '../../components/tableHeaderCell';
20
+ import TableRow from '../../components/tableRow';
21
+ import TableCell from '../../components/tableCell';
22
+ import { formatCount, formatMoney } from '../../components/formatNumber';
23
+ import { Center, Cluster, Stack } from '../../components/layout';
24
+ var customers = ['Northwind', 'Harbor Studio', 'Lumen Labs', 'Pine and Co', 'Cedar Works', 'Bright Dental', 'Maple Design', 'Atlas Freight', 'Juniper Foods', 'Orchard Legal'];
25
+ var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
26
+ // A real app reads all of them in one request: 42 is few enough to hold, sort and filter in the page.
27
+ var all = Array.from({ length: 42 }, function (_, i) {
28
+ var day = new Date(Date.UTC(2026, 10, 28 - i));
29
+ return {
30
+ id: "inv-".concat(i),
31
+ number: "INV-".concat(1042 - i),
32
+ customer: customers[(i * 7 + 3) % customers.length],
33
+ day: i,
34
+ date: "".concat(monthNames[day.getUTCMonth()], " ").concat(day.getUTCDate(), ", ").concat(day.getUTCFullYear()),
35
+ cents: 2400 + ((i * 5303) % 40000),
36
+ status: i % 11 === 4 ? 'Past due' : i % 9 === 5 ? 'Refunded' : 'Paid',
37
+ };
38
+ });
39
+ var statuses = ['Paid', 'Past due', 'Refunded'];
40
+ export default function DataTablePageAllRows() {
41
+ var _a = useState(''), query = _a[0], setQuery = _a[1];
42
+ var _b = useState(null), status = _b[0], setStatus = _b[1];
43
+ // Opens newest first.
44
+ var _c = useState({ by: 'date', dir: 'descending' }), sort = _c[0], setSort = _c[1];
45
+ var _d = useState(null), searchAnchor = _d[0], setSearchAnchor = _d[1];
46
+ var _e = useState(false), searchOpen = _e[0], setSearchOpen = _e[1];
47
+ var _f = useState(null), filterAnchor = _f[0], setFilterAnchor = _f[1];
48
+ var _g = useState(false), filterOpen = _g[0], setFilterOpen = _g[1];
49
+ var _h = useState(null), menuRow = _h[0], setMenuRow = _h[1];
50
+ var _j = useState(null), menuAnchor = _j[0], setMenuAnchor = _j[1];
51
+ var _k = useState(false), menuOpen = _k[0], setMenuOpen = _k[1];
52
+ var mounted = useRef(true);
53
+ var toastIds = useRef([]);
54
+ var searchButton = useRef(null);
55
+ // On unmount it closes every toast it opened.
56
+ useEffect(function () {
57
+ mounted.current = true;
58
+ return function () {
59
+ mounted.current = false;
60
+ toastIds.current.forEach(function (id) { return dismissToast(id); });
61
+ toastIds.current = [];
62
+ };
63
+ }, []);
64
+ // The first press on a column sorts it A to Z, and the next one reverses it. The rows are here, so it answers at once.
65
+ function handleSort(by) {
66
+ setSort(function (current) { return ({ by: by, dir: current.by === by && current.dir === 'ascending' ? 'descending' : 'ascending' }); });
67
+ }
68
+ var words = query.trim();
69
+ var rows = all
70
+ .filter(function (inv) { return (status === null || inv.status === status) && (words === '' || "".concat(inv.number, " ").concat(inv.customer).toLowerCase().includes(words.toLowerCase())); })
71
+ .sort(function (a, b) {
72
+ var order = sort.by === 'customer' ? a.customer.localeCompare(b.customer) : sort.by === 'amount' ? a.cents - b.cents : b.day - a.day;
73
+ return (sort.dir === 'ascending' ? order : -order) || a.day - b.day;
74
+ });
75
+ var filtering = words !== '' || status !== null;
76
+ // The line under the title says the total, and what the search and the filter leave.
77
+ var matching = [words !== '' ? "\"".concat(words, "\"") : null, status !== null ? status.toLowerCase() : null].filter(Boolean).join(', ');
78
+ var countLine = filtering ? "".concat(formatCount(rows.length), " of ").concat(formatCount(all.length), " invoices match ").concat(matching, ".") : "".concat(formatCount(all.length), " ").concat(all.length === 1 ? 'invoice' : 'invoices');
79
+ // The Button clears the words and the filter. Focus goes to the search button, because the field is in the closed Popover.
80
+ function clearFilter() {
81
+ var _a;
82
+ setQuery('');
83
+ setStatus(null);
84
+ (_a = searchButton.current) === null || _a === void 0 ? void 0 : _a.focus();
85
+ }
86
+ function openMenu(inv, anchor) {
87
+ if (menuOpen && (menuRow === null || menuRow === void 0 ? void 0 : menuRow.id) === inv.id) {
88
+ setMenuOpen(false);
89
+ return;
90
+ }
91
+ setMenuRow(inv);
92
+ setMenuAnchor(anchor);
93
+ setMenuOpen(true);
94
+ }
95
+ function choose(action) {
96
+ if (!menuRow)
97
+ return;
98
+ var inv = menuRow;
99
+ setMenuOpen(false);
100
+ action(inv);
101
+ }
102
+ function sendReceipt(inv) {
103
+ toastIds.current.push(toast({ type: 'success', message: "Receipt for ".concat(inv.number, " sent to ").concat(inv.customer, ".") }));
104
+ }
105
+ // Only reads 'copied' when the number reached the clipboard.
106
+ function copyNumber(inv) {
107
+ var failedCopy = function () {
108
+ if (!mounted.current)
109
+ return;
110
+ toastIds.current.push(toast({ type: 'error', message: "Copying is blocked here. Select the number and copy it: ".concat(inv.number) }));
111
+ };
112
+ if (!navigator.clipboard)
113
+ return failedCopy();
114
+ navigator.clipboard.writeText(inv.number).then(function () {
115
+ if (!mounted.current)
116
+ return;
117
+ toastIds.current.push(toast({ type: 'success', message: 'Invoice number copied.' }));
118
+ }, failedCopy);
119
+ }
120
+ // The sorted column has `sort`; the others leave it unset, so exactly one header carries `aria-sort`.
121
+ function sortHeader(by, label, width, align) {
122
+ var active = sort.by === by;
123
+ var button = (<Button size="small" type="tertiary" state={active ? 'selected' : 'enabled'} label={label} decoIcon={active ? (sort.dir === 'ascending' ? 'ArrowUp' : 'ArrowDown') : undefined} onClickButton={function () { return handleSort(by); }}/>);
124
+ return (<TableHeaderCell width={width} align={align} sort={active ? sort.dir : undefined}>
125
+ {align === 'right' ? <Cluster justify="end">{button}</Cluster> : button}
126
+ </TableHeaderCell>);
127
+ }
128
+ function statusTag(s) {
129
+ // The case 'Status in a row': a dot and a color only for a state that needs action.
130
+ return s === 'Past due' ? <Tag variant="dot" size="small" color="error" label={s}/> : <Tag variant="textOnly" size="small" label={s}/>;
131
+ }
132
+ return (<Center width="page">
133
+ {/* A real app mounts one Toaster near its root. */}
134
+ <Toaster />
135
+ <Stack gap="large">
136
+ <Stack gap="small">
137
+ <TitleBar title="Invoices"/>
138
+ <Paragraph tone="secondary" size="body2" measure="none">{countLine}</Paragraph>
139
+ </Stack>
140
+
141
+ {/* Search and the filter sit above the table, as the cases 'Collapsible search' and 'Filter menu' say. */}
142
+ <Cluster gap="small" justify="end">
143
+ <Tooltip title={words !== '' ? "Search: ".concat(words) : 'Search'}>
144
+ <IconButton ref={searchButton} color={words !== '' ? 'secondary' : 'iconOnly'} state={searchOpen ? 'selected' : 'enabled'} size="small" iconName="Search" ariaLabel={words !== '' ? "Search: ".concat(words) : 'Search'} aria-haspopup="dialog" aria-expanded={searchOpen} onClick={function (e) {
145
+ setSearchAnchor(e.currentTarget);
146
+ setSearchOpen(function (o) { return !o; });
147
+ }}/>
148
+ </Tooltip>
149
+ <Tooltip title={status ? status : 'Filter by status'}>
150
+ <IconButton color={status ? 'secondary' : 'iconOnly'} state={filterOpen ? 'selected' : 'enabled'} size="small" iconName="ListFilter" ariaLabel={status ? "Filter by status: ".concat(status) : 'Filter by status'} aria-haspopup="menu" aria-expanded={filterOpen} onClick={function (e) {
151
+ setFilterAnchor(e.currentTarget);
152
+ setFilterOpen(function (o) { return !o; });
153
+ }}/>
154
+ </Tooltip>
155
+ </Cluster>
156
+
157
+ {all.length === 0 ? (
158
+ // A new workspace has none. The case 'Empty list' says what to write.
159
+ <Surface minHeight="tall" align="center">
160
+ <EmptyBox size="large" text="No invoices yet" secondText="Your first invoice appears here after your first payment."/>
161
+ </Surface>) : rows.length === 0 ? (<Surface minHeight="tall" align="center">
162
+ <EmptyBox size="large" icon="Search" text={words !== '' ? "No ".concat(status ? "".concat(status.toLowerCase(), " ") : '', "invoices match \"").concat(words, "\"") : "No ".concat(status === null || status === void 0 ? void 0 : status.toLowerCase(), " invoices")} secondText={words !== '' ? 'Check the spelling, or search for fewer words.' : 'Choose another status, or clear the filter.'} action={<Button size="medium" type="secondary" state="enabled" label={status !== null ? 'Clear Filter' : 'Clear Search'} onClickButton={clearFilter}/>}/>
163
+ </Surface>) : (<TableContainer aria-label="Invoices" minWidth="640px">
164
+ <TableHeader>
165
+ <TableRow>
166
+ <TableHeaderCell width="110px">Invoice</TableHeaderCell>
167
+ {sortHeader('customer', 'Customer')}
168
+ {sortHeader('date', 'Date', '140px')}
169
+ {sortHeader('amount', 'Amount', '130px', 'right')}
170
+ <TableHeaderCell width="120px">Status</TableHeaderCell>
171
+ <TableHeaderCell width="90px">Actions</TableHeaderCell>
172
+ </TableRow>
173
+ </TableHeader>
174
+ {rows.map(function (inv) { return (<TableRow key={inv.id}>
175
+ <TableCell width="110px">{inv.number}</TableCell>
176
+ <TableCell>{inv.customer}</TableCell>
177
+ <TableCell width="140px">{inv.date}</TableCell>
178
+ {/* A table shows the exact amount, right-aligned. */}
179
+ <TableCell width="130px" align="right">{formatMoney(inv.cents / 100)}</TableCell>
180
+ <TableCell width="120px">{statusTag(inv.status)}</TableCell>
181
+ <TableCell width="90px">
182
+ <Tooltip title="More">
183
+ <IconButton color="iconOnly" state={menuOpen && (menuRow === null || menuRow === void 0 ? void 0 : menuRow.id) === inv.id ? 'selected' : 'enabled'} size="small" iconName="Ellipsis" ariaLabel={"More actions for ".concat(inv.number)} aria-haspopup="menu" aria-expanded={menuOpen && (menuRow === null || menuRow === void 0 ? void 0 : menuRow.id) === inv.id} onClick={function (e) { return openMenu(inv, e.currentTarget); }}/>
184
+ </Tooltip>
185
+ </TableCell>
186
+ </TableRow>); })}
187
+ </TableContainer>)}
188
+ </Stack>
189
+
190
+ <Popover open={searchOpen} anchorEl={searchAnchor} onClose={function () { return setSearchOpen(false); }} returnFocus>
191
+ <Menu width={288}>
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
+ // Escape clears the search and closes. Enter closes and keeps it.
194
+ if (e.key === 'Escape') {
195
+ e.preventDefault();
196
+ setQuery('');
197
+ setSearchOpen(false);
198
+ }
199
+ else if (e.key === 'Enter') {
200
+ e.preventDefault();
201
+ setSearchOpen(false);
202
+ }
203
+ }}/>
204
+ </Menu>
205
+ </Popover>
206
+ <Popover open={filterOpen} anchorEl={filterAnchor} onClose={function () { return setFilterOpen(false); }} returnFocus>
207
+ <Menu navigable aria-label="Filter by status" width={200}>
208
+ {statuses.map(function (s) { return (<MenuItem key={s} size="small" label={s === 'Past due' ? 'Past Due' : s} isSelected={s === status} role="menuitemradio" onClick={function () {
209
+ setFilterOpen(false);
210
+ setStatus(s);
211
+ }}/>); })}
212
+ {status && <Line />}
213
+ {status && (<MenuItem size="small" iconName="X" label="Clear Filter" onClick={function () {
214
+ setFilterOpen(false);
215
+ setStatus(null);
216
+ }}/>)}
217
+ </Menu>
218
+ </Popover>
219
+ <Popover open={menuOpen} anchorEl={menuAnchor} onClose={function () { return setMenuOpen(false); }} returnFocus>
220
+ <Menu navigable aria-label={menuRow ? "Actions for ".concat(menuRow.number) : 'Invoice actions'} width={220}>
221
+ <MenuItem size="small" iconName="Copy" label="Copy Invoice Number" onClick={function () { return choose(copyNumber); }}/>
222
+ <MenuItem size="small" iconName="Mail" label="Send Receipt" onClick={function () { return choose(sendReceipt); }}/>
223
+ </Menu>
224
+ </Popover>
225
+ </Center>);
226
+ }
@@ -0,0 +1 @@
1
+ export default function DataTablePagePaged(): import("react").JSX.Element;
@@ -0,0 +1,284 @@
1
+ 'use client';
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import Toaster, { toast, dismissToast } from '../../components/toaster';
4
+ import TitleBar from '../../components/titleBar';
5
+ import Paragraph from '../../components/paragraph';
6
+ import Skeleton from '../../components/skeleton';
7
+ import Surface from '../../components/surface';
8
+ import EmptyBox from '../../components/emptyBox';
9
+ import Button from '../../components/button';
10
+ import IconButton from '../../components/iconButton';
11
+ import Tooltip from '../../components/tooltip';
12
+ import TextField from '../../components/textField';
13
+ import Popover from '../../components/popover';
14
+ import Menu from '../../components/menu';
15
+ import MenuItem from '../../components/menuItem';
16
+ import Line from '../../components/line';
17
+ import Tag from '../../components/tag';
18
+ import Pagination from '../../components/pagination';
19
+ import TableContainer from '../../components/tableContainer';
20
+ import TableHeader from '../../components/tableHeader';
21
+ import TableHeaderCell from '../../components/tableHeaderCell';
22
+ import TableRow from '../../components/tableRow';
23
+ import TableCell from '../../components/tableCell';
24
+ import { formatCount, formatMoney } from '../../components/formatNumber';
25
+ import { Center, Cluster, Stack } from '../../components/layout';
26
+ var customers = ['Northwind', 'Harbor Studio', 'Lumen Labs', 'Pine and Co', 'Cedar Works', 'Bright Dental', 'Maple Design', 'Atlas Freight', 'Juniper Foods', 'Orchard Legal'];
27
+ var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
28
+ // A real app asks the server for one page. This makes the 290 invoices the server would hold, newest first.
29
+ var all = Array.from({ length: 290 }, function (_, i) {
30
+ var day = new Date(Date.UTC(2026, 10, 28 - i));
31
+ return {
32
+ id: "inv-".concat(i),
33
+ number: "INV-".concat(1290 - i),
34
+ customer: customers[(i * 7 + 3) % customers.length],
35
+ day: i,
36
+ date: "".concat(monthNames[day.getUTCMonth()], " ").concat(day.getUTCDate(), ", ").concat(day.getUTCFullYear()),
37
+ cents: 2400 + ((i * 5303) % 40000),
38
+ status: i % 11 === 4 ? 'Past due' : i % 9 === 5 ? 'Refunded' : 'Paid',
39
+ };
40
+ });
41
+ var statuses = ['Paid', 'Past due', 'Refunded'];
42
+ var PAGE_SIZE = 25;
43
+ export default function DataTablePagePaged() {
44
+ var _a = useState(''), query = _a[0], setQuery = _a[1];
45
+ var _b = useState(null), status = _b[0], setStatus = _b[1];
46
+ // Opens newest first.
47
+ var _c = useState({ by: 'date', dir: 'descending' }), sort = _c[0], setSort = _c[1];
48
+ var _d = useState(1), page = _d[0], setPage = _d[1];
49
+ var _e = useState(false), loading = _e[0], setLoading = _e[1];
50
+ var _f = useState(false), failed = _f[0], setFailed = _f[1];
51
+ var _g = useState(null), searchAnchor = _g[0], setSearchAnchor = _g[1];
52
+ var _h = useState(false), searchOpen = _h[0], setSearchOpen = _h[1];
53
+ var _j = useState(null), filterAnchor = _j[0], setFilterAnchor = _j[1];
54
+ var _k = useState(false), filterOpen = _k[0], setFilterOpen = _k[1];
55
+ var _l = useState(null), menuRow = _l[0], setMenuRow = _l[1];
56
+ var _m = useState(null), menuAnchor = _m[0], setMenuAnchor = _m[1];
57
+ var _o = useState(false), menuOpen = _o[0], setMenuOpen = _o[1];
58
+ var timer = useRef();
59
+ var failedOnce = useRef(false);
60
+ var mounted = useRef(true);
61
+ var toastIds = useRef([]);
62
+ var searchButton = useRef(null);
63
+ // On unmount it stops the request and closes every toast it opened.
64
+ useEffect(function () {
65
+ mounted.current = true;
66
+ return function () {
67
+ mounted.current = false;
68
+ clearTimeout(timer.current);
69
+ toastIds.current.forEach(function (id) { return dismissToast(id); });
70
+ toastIds.current = [];
71
+ };
72
+ }, []);
73
+ // The server sorts and filters, so the page asks it again for every change. The header and the pager stay while it answers.
74
+ function request(forPage) {
75
+ clearTimeout(timer.current);
76
+ setLoading(true);
77
+ timer.current = setTimeout(function () {
78
+ setLoading(false);
79
+ // The failure stays on screen, with its Button, until the new answer arrives.
80
+ setFailed(false);
81
+ // Stands in for a network failure, once: page 3 fails the first time it is asked for.
82
+ if (forPage === 3 && !failedOnce.current) {
83
+ failedOnce.current = true;
84
+ setFailed(true);
85
+ }
86
+ }, 600);
87
+ }
88
+ // A sort, a search or a filter goes back to page 1: page 4 of the old list means nothing in the new one.
89
+ // A real app waits a moment after the last key before it asks the server for a search.
90
+ function change(next) {
91
+ if (next.query !== undefined)
92
+ setQuery(next.query);
93
+ if (next.status !== undefined)
94
+ setStatus(next.status);
95
+ if (next.sort !== undefined)
96
+ setSort(next.sort);
97
+ setPage(1);
98
+ request(1);
99
+ }
100
+ function goToPage(next) {
101
+ setPage(next);
102
+ request(next);
103
+ }
104
+ // The first press on a column sorts it A to Z, and the next one reverses it.
105
+ function handleSort(by) {
106
+ change({ sort: { by: by, dir: sort.by === by && sort.dir === 'ascending' ? 'descending' : 'ascending' } });
107
+ }
108
+ var words = query.trim();
109
+ var found = all
110
+ .filter(function (inv) { return (status === null || inv.status === status) && (words === '' || "".concat(inv.number, " ").concat(inv.customer).toLowerCase().includes(words.toLowerCase())); })
111
+ .sort(function (a, b) {
112
+ var order = sort.by === 'customer' ? a.customer.localeCompare(b.customer) : sort.by === 'amount' ? a.cents - b.cents : b.day - a.day;
113
+ return (sort.dir === 'ascending' ? order : -order) || a.day - b.day;
114
+ });
115
+ var pageCount = Math.ceil(found.length / PAGE_SIZE);
116
+ var rows = found.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE);
117
+ var filtering = words !== '' || status !== null;
118
+ // The line under the title says the total, and what the search and the filter leave.
119
+ var matching = [words !== '' ? "\"".concat(words, "\"") : null, status !== null ? status.toLowerCase() : null].filter(Boolean).join(', ');
120
+ var countLine = filtering ? "".concat(formatCount(found.length), " of ").concat(formatCount(all.length), " invoices match ").concat(matching, ".") : "".concat(formatCount(all.length), " ").concat(all.length === 1 ? 'invoice' : 'invoices');
121
+ // The Button clears the words and the filter. Focus goes to the search button, because the field is in the closed Popover.
122
+ function clearFilter() {
123
+ var _a;
124
+ change({ query: '', status: null });
125
+ (_a = searchButton.current) === null || _a === void 0 ? void 0 : _a.focus();
126
+ }
127
+ function openMenu(inv, anchor) {
128
+ if (menuOpen && (menuRow === null || menuRow === void 0 ? void 0 : menuRow.id) === inv.id) {
129
+ setMenuOpen(false);
130
+ return;
131
+ }
132
+ setMenuRow(inv);
133
+ setMenuAnchor(anchor);
134
+ setMenuOpen(true);
135
+ }
136
+ function choose(action) {
137
+ if (!menuRow)
138
+ return;
139
+ var inv = menuRow;
140
+ setMenuOpen(false);
141
+ action(inv);
142
+ }
143
+ function sendReceipt(inv) {
144
+ toastIds.current.push(toast({ type: 'success', message: "Receipt for ".concat(inv.number, " sent to ").concat(inv.customer, ".") }));
145
+ }
146
+ // Only reads 'copied' when the number reached the clipboard.
147
+ function copyNumber(inv) {
148
+ var failedCopy = function () {
149
+ if (!mounted.current)
150
+ return;
151
+ toastIds.current.push(toast({ type: 'error', message: "Copying is blocked here. Select the number and copy it: ".concat(inv.number) }));
152
+ };
153
+ if (!navigator.clipboard)
154
+ return failedCopy();
155
+ navigator.clipboard.writeText(inv.number).then(function () {
156
+ if (!mounted.current)
157
+ return;
158
+ toastIds.current.push(toast({ type: 'success', message: 'Invoice number copied.' }));
159
+ }, failedCopy);
160
+ }
161
+ // The sorted column has `sort`; the others leave it unset, so exactly one header carries `aria-sort`.
162
+ function sortHeader(by, label, width, align) {
163
+ var active = sort.by === by;
164
+ var button = (<Button size="small" type="tertiary" state={active ? 'selected' : 'enabled'} label={label} decoIcon={active ? (sort.dir === 'ascending' ? 'ArrowUp' : 'ArrowDown') : undefined} onClickButton={function () { return handleSort(by); }}/>);
165
+ return (<TableHeaderCell width={width} align={align} sort={active ? sort.dir : undefined}>
166
+ {align === 'right' ? <Cluster justify="end">{button}</Cluster> : button}
167
+ </TableHeaderCell>);
168
+ }
169
+ function statusTag(s) {
170
+ // The case 'Status in a row': a dot and a color only for a state that needs action.
171
+ return s === 'Past due' ? <Tag variant="dot" size="small" color="error" label={s}/> : <Tag variant="textOnly" size="small" label={s}/>;
172
+ }
173
+ return (<Center width="page">
174
+ {/* A real app mounts one Toaster near its root. */}
175
+ <Toaster />
176
+ <Stack gap="large">
177
+ <Stack gap="small">
178
+ <TitleBar title="Invoices" id="data-table-page-paged-top"/>
179
+ {loading ? <Skeleton variant="text" width="medium"/> : <Paragraph tone="secondary" size="body2" measure="none">{countLine}</Paragraph>}
180
+ </Stack>
181
+
182
+ {/* Search and the filter sit above the table, as the cases 'Collapsible search' and 'Filter menu' say. */}
183
+ <Cluster gap="small" justify="end">
184
+ <Tooltip title={words !== '' ? "Search: ".concat(words) : 'Search'}>
185
+ <IconButton ref={searchButton} color={words !== '' ? 'secondary' : 'iconOnly'} state={searchOpen ? 'selected' : 'enabled'} size="small" iconName="Search" ariaLabel={words !== '' ? "Search: ".concat(words) : 'Search'} aria-haspopup="dialog" aria-expanded={searchOpen} onClick={function (e) {
186
+ setSearchAnchor(e.currentTarget);
187
+ setSearchOpen(function (o) { return !o; });
188
+ }}/>
189
+ </Tooltip>
190
+ <Tooltip title={status ? status : 'Filter by status'}>
191
+ <IconButton color={status ? 'secondary' : 'iconOnly'} state={filterOpen ? 'selected' : 'enabled'} size="small" iconName="ListFilter" ariaLabel={status ? "Filter by status: ".concat(status) : 'Filter by status'} aria-haspopup="menu" aria-expanded={filterOpen} onClick={function (e) {
192
+ setFilterAnchor(e.currentTarget);
193
+ setFilterOpen(function (o) { return !o; });
194
+ }}/>
195
+ </Tooltip>
196
+ </Cluster>
197
+
198
+ {all.length === 0 ? (
199
+ // A new workspace has none. The case 'Empty list' says what to write.
200
+ <Surface minHeight="tall" align="center">
201
+ <EmptyBox size="large" text="No invoices yet" secondText="Your first invoice appears here after your first payment."/>
202
+ </Surface>) : failed ? (
203
+ // The table's place: the header goes too, because nothing is left to sort. The pager stays.
204
+ <Surface minHeight="tall" align="center">
205
+ <EmptyBox size="large" icon="CloudOff" text="Could not load invoices" secondText="Check your connection and try again." action={<Button size="medium" type="primary" state="enabled" label="Try Again" loading={loading} onClickButton={function () { return request(page); }}/>}/>
206
+ </Surface>) : !loading && found.length === 0 ? (<Surface minHeight="tall" align="center">
207
+ <EmptyBox size="large" icon="Search" text={words !== '' ? "No ".concat(status ? "".concat(status.toLowerCase(), " ") : '', "invoices match \"").concat(words, "\"") : "No ".concat(status === null || status === void 0 ? void 0 : status.toLowerCase(), " invoices")} secondText={words !== '' ? 'Check the spelling, or search for fewer words.' : 'Choose another status, or clear the filter.'} action={<Button size="medium" type="secondary" state="enabled" label={status !== null ? 'Clear Filter' : 'Clear Search'} onClickButton={clearFilter}/>}/>
208
+ </Surface>) : (<TableContainer aria-label="Invoices" minWidth="640px">
209
+ <TableHeader>
210
+ <TableRow>
211
+ <TableHeaderCell width="110px">Invoice</TableHeaderCell>
212
+ {sortHeader('customer', 'Customer')}
213
+ {sortHeader('date', 'Date', '140px')}
214
+ {sortHeader('amount', 'Amount', '130px', 'right')}
215
+ <TableHeaderCell width="120px">Status</TableHeaderCell>
216
+ <TableHeaderCell width="90px">Actions</TableHeaderCell>
217
+ </TableRow>
218
+ </TableHeader>
219
+ {loading
220
+ ? Array.from({ length: 10 }, function (_, i) { return (<TableRow key={i}>
221
+ {/* One status for the ten rows: the Skeleton with a label is announced once. */}
222
+ <TableCell width="110px">{i === 0 ? <Skeleton label="Loading invoices"/> : <Skeleton />}</TableCell>
223
+ <TableCell><Skeleton width="large"/></TableCell>
224
+ <TableCell width="140px"><Skeleton /></TableCell>
225
+ <TableCell width="130px"><Skeleton /></TableCell>
226
+ <TableCell width="120px"><Skeleton width="large"/></TableCell>
227
+ <TableCell width="90px"><Skeleton width="small"/></TableCell>
228
+ </TableRow>); })
229
+ : rows.map(function (inv) { return (<TableRow key={inv.id}>
230
+ <TableCell width="110px">{inv.number}</TableCell>
231
+ <TableCell>{inv.customer}</TableCell>
232
+ <TableCell width="140px">{inv.date}</TableCell>
233
+ {/* A table shows the exact amount, right-aligned. */}
234
+ <TableCell width="130px" align="right">{formatMoney(inv.cents / 100)}</TableCell>
235
+ <TableCell width="120px">{statusTag(inv.status)}</TableCell>
236
+ <TableCell width="90px">
237
+ <Tooltip title="More">
238
+ <IconButton color="iconOnly" state={menuOpen && (menuRow === null || menuRow === void 0 ? void 0 : menuRow.id) === inv.id ? 'selected' : 'enabled'} size="small" iconName="Ellipsis" ariaLabel={"More actions for ".concat(inv.number)} aria-haspopup="menu" aria-expanded={menuOpen && (menuRow === null || menuRow === void 0 ? void 0 : menuRow.id) === inv.id} onClick={function (e) { return openMenu(inv, e.currentTarget); }}/>
239
+ </Tooltip>
240
+ </TableCell>
241
+ </TableRow>); })}
242
+ </TableContainer>)}
243
+
244
+ {/* It shows nothing with one page. A real app also passes `getHref`, so each page has an address. */}
245
+ <Pagination aria-label="Invoice pages" page={page} pageCount={pageCount} onPageChange={goToPage} scrollTargetId="data-table-page-paged-top"/>
246
+ </Stack>
247
+
248
+ <Popover open={searchOpen} anchorEl={searchAnchor} onClose={function () { return setSearchOpen(false); }} returnFocus>
249
+ <Menu width={288}>
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
+ // Escape clears the search and closes. Enter closes and keeps it.
252
+ if (e.key === 'Escape') {
253
+ e.preventDefault();
254
+ change({ query: '' });
255
+ setSearchOpen(false);
256
+ }
257
+ else if (e.key === 'Enter') {
258
+ e.preventDefault();
259
+ setSearchOpen(false);
260
+ }
261
+ }}/>
262
+ </Menu>
263
+ </Popover>
264
+ <Popover open={filterOpen} anchorEl={filterAnchor} onClose={function () { return setFilterOpen(false); }} returnFocus>
265
+ <Menu navigable aria-label="Filter by status" width={200}>
266
+ {statuses.map(function (s) { return (<MenuItem key={s} size="small" label={s === 'Past due' ? 'Past Due' : s} isSelected={s === status} role="menuitemradio" onClick={function () {
267
+ setFilterOpen(false);
268
+ change({ status: s });
269
+ }}/>); })}
270
+ {status && <Line />}
271
+ {status && (<MenuItem size="small" iconName="X" label="Clear Filter" onClick={function () {
272
+ setFilterOpen(false);
273
+ change({ status: null });
274
+ }}/>)}
275
+ </Menu>
276
+ </Popover>
277
+ <Popover open={menuOpen} anchorEl={menuAnchor} onClose={function () { return setMenuOpen(false); }} returnFocus>
278
+ <Menu navigable aria-label={menuRow ? "Actions for ".concat(menuRow.number) : 'Invoice actions'} width={220}>
279
+ <MenuItem size="small" iconName="Copy" label="Copy Invoice Number" onClick={function () { return choose(copyNumber); }}/>
280
+ <MenuItem size="small" iconName="Mail" label="Send Receipt" onClick={function () { return choose(sendReceipt); }}/>
281
+ </Menu>
282
+ </Popover>
283
+ </Center>);
284
+ }