oneslash-design-system 2.17.0 → 2.19.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 +2 -2
- package/dist/DESIGN.md +55 -14
- package/dist/cases/accept-invite.md +1 -5
- package/dist/cases/account-menu/menu.d.ts +1 -0
- package/dist/cases/account-menu/menu.jsx +99 -0
- package/dist/cases/account-menu.md +164 -0
- package/dist/cases/agent-asks-before-risky-action.md +0 -4
- package/dist/cases/agent-cancels-when-unanswered.md +0 -4
- package/dist/cases/agent-options.md +0 -4
- package/dist/cases/agent-pending-reply.md +0 -4
- package/dist/cases/agent-plan-proposal.md +0 -4
- package/dist/cases/agent-question.md +0 -4
- package/dist/cases/agent-refuses-clearly.md +0 -4
- package/dist/cases/agent-says-what-it-is.md +0 -2
- package/dist/cases/agent-settings/form.d.ts +1 -0
- package/dist/cases/agent-settings/form.jsx +164 -0
- package/dist/cases/agent-settings.md +259 -0
- package/dist/cases/agent-shows-progress.md +0 -2
- package/dist/cases/agent-shows-sources.md +0 -2
- package/dist/cases/api-keys/list.d.ts +1 -0
- package/dist/cases/api-keys/list.jsx +162 -0
- package/dist/cases/api-keys.md +229 -0
- package/dist/cases/app-shell/sidebar.d.ts +1 -0
- package/dist/cases/app-shell/sidebar.jsx +124 -0
- package/dist/cases/app-shell/top-tabs.d.ts +1 -0
- package/dist/cases/app-shell/top-tabs.jsx +106 -0
- package/dist/cases/app-shell.md +364 -0
- package/dist/cases/artifact-card/card.jsx +32 -6
- package/dist/cases/artifact-card.md +55 -11
- package/dist/cases/auth-gate-loading.md +0 -4
- package/dist/cases/check-your-email.md +0 -4
- package/dist/cases/collapsible-search/popover.d.ts +1 -0
- package/dist/cases/collapsible-search/popover.jsx +74 -0
- package/dist/cases/collapsible-search.md +143 -0
- package/dist/cases/composer-limit.md +0 -4
- package/dist/cases/confirm-destructive-action.md +0 -4
- package/dist/cases/confirm-dialogs.md +0 -4
- package/dist/cases/conversation-starters.md +0 -4
- package/dist/cases/create-modal.md +0 -4
- package/dist/cases/danger-zone/collapsed.d.ts +1 -0
- package/dist/cases/danger-zone/collapsed.jsx +75 -0
- package/dist/cases/danger-zone/shown.d.ts +1 -0
- package/dist/cases/danger-zone/shown.jsx +95 -0
- package/dist/cases/danger-zone.md +263 -0
- package/dist/cases/device-login.md +0 -4
- package/dist/cases/email-confirmed.md +0 -4
- package/dist/cases/empty-list.md +0 -4
- package/dist/cases/empty-lists.md +0 -4
- package/dist/cases/empty-not-set-up.md +0 -4
- package/dist/cases/empty-search.md +0 -4
- package/dist/cases/error-page/in-shell.jsx +26 -17
- package/dist/cases/error-page.md +42 -25
- package/dist/cases/feedback-form.md +0 -4
- package/dist/cases/filter-menu/presets.d.ts +1 -0
- package/dist/cases/filter-menu/presets.jsx +53 -0
- package/dist/cases/filter-menu/with-clear.d.ts +1 -0
- package/dist/cases/filter-menu/with-clear.jsx +56 -0
- package/dist/cases/filter-menu.md +204 -0
- package/dist/cases/forgot-password.md +0 -4
- package/dist/cases/form-errors.md +0 -4
- package/dist/cases/import-checklist.md +0 -4
- package/dist/cases/inline-form-feedback.md +0 -4
- package/dist/cases/integrations-list/nested.d.ts +1 -0
- package/dist/cases/integrations-list/nested.jsx +164 -0
- package/dist/cases/integrations-list/rows.d.ts +1 -0
- package/dist/cases/integrations-list/rows.jsx +134 -0
- package/dist/cases/integrations-list.md +379 -0
- package/dist/cases/invite-member.md +0 -4
- package/dist/cases/load-failure.md +0 -4
- package/dist/cases/log-out-confirm.md +0 -4
- package/dist/cases/login-page.md +0 -4
- package/dist/cases/master-detail/list-then-page.d.ts +1 -0
- package/dist/cases/master-detail/list-then-page.jsx +65 -0
- package/dist/cases/master-detail/split.d.ts +1 -0
- package/dist/cases/master-detail/split.jsx +49 -0
- package/dist/cases/master-detail.md +213 -0
- package/dist/cases/members-list/rows.d.ts +1 -0
- package/dist/cases/members-list/rows.jsx +318 -0
- package/dist/cases/members-list/table.d.ts +1 -0
- package/dist/cases/members-list/table.jsx +351 -0
- package/dist/cases/members-list.md +799 -0
- package/dist/cases/mention-list.md +0 -4
- package/dist/cases/message-actions.md +0 -4
- package/dist/cases/message-attachments.md +0 -4
- package/dist/cases/message-composer.md +0 -4
- package/dist/cases/message-edit.md +0 -4
- package/dist/cases/message-reactions.md +0 -4
- package/dist/cases/message-row.md +0 -4
- package/dist/cases/mobile-menu/links.d.ts +1 -0
- package/dist/cases/mobile-menu/links.jsx +24 -0
- package/dist/cases/mobile-menu/sections.d.ts +1 -0
- package/dist/cases/mobile-menu/sections.jsx +61 -0
- package/dist/cases/mobile-menu.md +170 -0
- package/dist/cases/not-found-page/in-shell.jsx +26 -17
- package/dist/cases/not-found-page.md +41 -24
- package/dist/cases/notification-menu/menu.d.ts +1 -0
- package/dist/cases/notification-menu/menu.jsx +74 -0
- package/dist/cases/notification-menu.md +135 -0
- package/dist/cases/oauth-consent.md +0 -4
- package/dist/cases/on-off-settings/list.d.ts +1 -0
- package/dist/cases/on-off-settings/list.jsx +97 -0
- package/dist/cases/on-off-settings.md +116 -0
- package/dist/cases/on-this-page/aside.d.ts +1 -0
- package/dist/cases/on-this-page/aside.jsx +39 -0
- package/dist/cases/on-this-page.md +80 -0
- package/dist/cases/overflow-menu/in-a-header.d.ts +1 -0
- package/dist/cases/overflow-menu/in-a-header.jsx +128 -0
- package/dist/cases/overflow-menu/on-a-row.d.ts +1 -0
- package/dist/cases/overflow-menu/on-a-row.jsx +183 -0
- package/dist/cases/overflow-menu.md +410 -0
- package/dist/cases/page-header/actions.d.ts +1 -0
- package/dist/cases/page-header/actions.jsx +65 -0
- package/dist/cases/page-header/sub-page.d.ts +1 -0
- package/dist/cases/page-header/sub-page.jsx +37 -0
- package/dist/cases/page-header.md +195 -0
- package/dist/cases/phone-navigation.md +32 -0
- package/dist/cases/profile-form/form.d.ts +1 -0
- package/dist/cases/profile-form/form.jsx +153 -0
- package/dist/cases/profile-form.md +236 -0
- package/dist/cases/quick-switcher/modal.d.ts +1 -0
- package/dist/cases/quick-switcher/modal.jsx +114 -0
- package/dist/cases/quick-switcher.md +205 -0
- package/dist/cases/range-switch/segmented.d.ts +1 -0
- package/dist/cases/range-switch/segmented.jsx +30 -0
- package/dist/cases/range-switch.md +67 -0
- package/dist/cases/rename.md +0 -4
- package/dist/cases/reply-feedback.md +0 -4
- package/dist/cases/reply-sources.md +0 -4
- package/dist/cases/route-loading/region.jsx +27 -18
- package/dist/cases/route-loading.md +42 -23
- package/dist/cases/scope-picker/menu.d.ts +1 -0
- package/dist/cases/scope-picker/menu.jsx +47 -0
- package/dist/cases/scope-picker.md +97 -0
- package/dist/cases/set-new-password.md +0 -4
- package/dist/cases/settings-page/side-nav.d.ts +1 -0
- package/dist/cases/settings-page/side-nav.jsx +171 -0
- package/dist/cases/settings-page/top-tabs.d.ts +1 -0
- package/dist/cases/settings-page/top-tabs.jsx +129 -0
- package/dist/cases/settings-page.md +378 -0
- package/dist/cases/settings-save.md +35 -0
- package/dist/cases/side-pane/beside.d.ts +1 -0
- package/dist/cases/side-pane/beside.jsx +79 -0
- package/dist/cases/side-pane/over.d.ts +1 -0
- package/dist/cases/side-pane/over.jsx +58 -0
- package/dist/cases/side-pane.md +238 -0
- package/dist/cases/sidebar-nav/flat.d.ts +1 -0
- package/dist/cases/sidebar-nav/flat.jsx +81 -0
- package/dist/cases/sidebar-nav/nested.d.ts +1 -0
- package/dist/cases/sidebar-nav/nested.jsx +122 -0
- package/dist/cases/sidebar-nav.md +261 -0
- package/dist/cases/sign-up-page.md +1 -5
- package/dist/cases/site-footer/columns.d.ts +1 -0
- package/dist/cases/site-footer/columns.jsx +51 -0
- package/dist/cases/site-footer/simple.d.ts +1 -0
- package/dist/cases/site-footer/simple.jsx +24 -0
- package/dist/cases/site-footer.md +133 -0
- package/dist/cases/site-header/links.d.ts +1 -0
- package/dist/cases/site-header/links.jsx +26 -0
- package/dist/cases/site-header/sections.d.ts +1 -0
- package/dist/cases/site-header/sections.jsx +64 -0
- package/dist/cases/site-header.md +183 -0
- package/dist/cases/slash-command-list.md +0 -4
- package/dist/cases/success-feedback.md +0 -4
- package/dist/cases/tag-filter/tags.d.ts +1 -0
- package/dist/cases/tag-filter/tags.jsx +226 -0
- package/dist/cases/tag-filter.md +298 -0
- package/dist/cases/theme-switcher/menu.d.ts +1 -0
- package/dist/cases/theme-switcher/menu.jsx +47 -0
- package/dist/cases/theme-switcher/segmented.d.ts +1 -0
- package/dist/cases/theme-switcher/segmented.jsx +26 -0
- package/dist/cases/theme-switcher.md +149 -0
- package/dist/cases/type-to-confirm.md +0 -4
- package/dist/cases/typing-and-status.md +0 -4
- package/dist/cases/unsaved-changes-guard.md +0 -4
- package/dist/cases/upgrade-prompt.md +0 -4
- package/dist/cases.json +1737 -315
- package/dist/components/alert.d.ts +3 -1
- package/dist/components/alert.jsx +2 -2
- package/dist/components/appShell.d.ts +44 -0
- package/dist/components/appShell.jsx +121 -0
- package/dist/components/button.jsx +5 -2
- package/dist/components/checkBox.d.ts +5 -1
- package/dist/components/checkBox.jsx +2 -2
- package/dist/components/copyField.d.ts +20 -0
- package/dist/components/copyField.jsx +99 -0
- package/dist/components/drawer.d.ts +31 -0
- package/dist/components/drawer.jsx +121 -0
- package/dist/components/formField.d.ts +34 -0
- package/dist/components/formField.jsx +28 -0
- package/dist/components/heading.d.ts +5 -1
- package/dist/components/heading.jsx +2 -2
- package/dist/components/link.d.ts +6 -1
- package/dist/components/link.jsx +11 -3
- package/dist/components/menu.jsx +2 -2
- package/dist/components/menuItem.d.ts +10 -2
- package/dist/components/menuItem.jsx +4 -3
- package/dist/components/modal.jsx +12 -23
- package/dist/components/navigation.d.ts +9 -1
- package/dist/components/navigation.jsx +15 -3
- package/dist/components/onThisPage.d.ts +29 -0
- package/dist/components/onThisPage.jsx +151 -0
- package/dist/components/pageShell.d.ts +7 -1
- package/dist/components/pageShell.jsx +14 -1
- package/dist/components/popover.jsx +4 -0
- package/dist/components/radioGroup.d.ts +5 -1
- package/dist/components/radioGroup.jsx +2 -2
- package/dist/components/segmentedControl.d.ts +22 -0
- package/dist/components/segmentedControl.jsx +54 -0
- package/dist/components/select.d.ts +5 -1
- package/dist/components/select.jsx +2 -2
- package/dist/components/settingsSection.d.ts +36 -0
- package/dist/components/settingsSection.jsx +65 -0
- package/dist/components/sidePane.d.ts +32 -0
- package/dist/components/sidePane.jsx +128 -0
- package/dist/components/siteFooter.d.ts +24 -0
- package/dist/components/siteFooter.jsx +48 -0
- package/dist/components/siteHeader.d.ts +55 -0
- package/dist/components/siteHeader.jsx +125 -0
- package/dist/components/slidingIndicator.d.ts +50 -0
- package/dist/components/slidingIndicator.jsx +102 -0
- package/dist/components/switch.d.ts +25 -0
- package/dist/components/switch.jsx +55 -0
- package/dist/components/tab.jsx +5 -11
- package/dist/components/tabsContainer.jsx +5 -67
- package/dist/components/textField.d.ts +12 -2
- package/dist/components/textField.jsx +11 -4
- package/dist/components/textarea.d.ts +5 -1
- package/dist/components/textarea.jsx +3 -3
- package/dist/components/titleBar.d.ts +17 -0
- package/dist/components/titleBar.jsx +17 -0
- package/dist/components/useHotkey.d.ts +7 -0
- package/dist/components/useHotkey.js +24 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/internal/copyField.d.ts +5 -0
- package/dist/internal/copyField.js +61 -0
- package/dist/internal/hotkey.d.ts +16 -0
- package/dist/internal/hotkey.js +20 -0
- package/dist/internal/overlayStack.d.ts +24 -0
- package/dist/internal/overlayStack.js +71 -0
- package/dist/internal/resize.d.ts +9 -0
- package/dist/internal/resize.js +31 -0
- package/dist/internal/scrollSpy.d.ts +24 -0
- package/dist/internal/scrollSpy.js +53 -0
- package/dist/internal/siteBrand.d.ts +6 -0
- package/dist/internal/siteBrand.jsx +11 -0
- package/dist/internal/switch.d.ts +5 -0
- package/dist/internal/switch.js +9 -0
- package/dist/native-mapping.json +72 -0
- package/dist/stories/AppShell.stories.d.ts +15 -0
- package/dist/stories/AppShell.stories.jsx +137 -0
- package/dist/stories/Cases.generated.stories.d.ts +42 -0
- package/dist/stories/Cases.generated.stories.jsx +84 -0
- package/dist/stories/CopyField.stories.d.ts +11 -0
- package/dist/stories/CopyField.stories.jsx +65 -0
- package/dist/stories/Drawer.stories.d.ts +10 -0
- package/dist/stories/Drawer.stories.jsx +123 -0
- package/dist/stories/FormField.stories.d.ts +6 -0
- package/dist/stories/FormField.stories.jsx +44 -0
- package/dist/stories/Link.stories.d.ts +1 -0
- package/dist/stories/Link.stories.jsx +8 -0
- package/dist/stories/Navigation.stories.d.ts +1 -0
- package/dist/stories/Navigation.stories.jsx +17 -1
- package/dist/stories/OnThisPage.stories.d.ts +10 -0
- package/dist/stories/OnThisPage.stories.jsx +105 -0
- package/dist/stories/SegmentedControl.stories.d.ts +8 -0
- package/dist/stories/SegmentedControl.stories.jsx +33 -0
- package/dist/stories/SettingsSection.stories.d.ts +12 -0
- package/dist/stories/SettingsSection.stories.jsx +91 -0
- package/dist/stories/SidePane.stories.d.ts +6 -0
- package/dist/stories/SidePane.stories.jsx +37 -0
- package/dist/stories/SiteFooter.stories.d.ts +7 -0
- package/dist/stories/SiteFooter.stories.jsx +63 -0
- package/dist/stories/SiteHeader.stories.d.ts +10 -0
- package/dist/stories/SiteHeader.stories.jsx +94 -0
- package/dist/stories/Switch.stories.d.ts +14 -0
- package/dist/stories/Switch.stories.jsx +87 -0
- package/dist/stories/TextField.stories.d.ts +1 -0
- package/dist/stories/TextField.stories.jsx +13 -0
- package/dist/stories/TitleBar.stories.d.ts +6 -0
- package/dist/stories/TitleBar.stories.jsx +34 -0
- package/package.json +5 -1
|
@@ -0,0 +1,183 @@
|
|
|
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 { useEffect, useRef, useState } from 'react';
|
|
12
|
+
import Toaster, { toast, dismissToast } from '../../components/toaster';
|
|
13
|
+
import Heading from '../../components/heading';
|
|
14
|
+
import Paragraph from '../../components/paragraph';
|
|
15
|
+
import Button from '../../components/button';
|
|
16
|
+
import IconButton from '../../components/iconButton';
|
|
17
|
+
import Tooltip from '../../components/tooltip';
|
|
18
|
+
import Popover from '../../components/popover';
|
|
19
|
+
import Menu from '../../components/menu';
|
|
20
|
+
import MenuItem from '../../components/menuItem';
|
|
21
|
+
import Line from '../../components/line';
|
|
22
|
+
import EmptyBox from '../../components/emptyBox';
|
|
23
|
+
import TableContainer from '../../components/tableContainer';
|
|
24
|
+
import TableRow from '../../components/tableRow';
|
|
25
|
+
import TableCell from '../../components/tableCell';
|
|
26
|
+
import { Center, Cluster, Stack } from '../../components/layout';
|
|
27
|
+
// A real app reads these from the server.
|
|
28
|
+
var firstReports = [
|
|
29
|
+
{ id: 'q3', name: 'Q3 report', updated: 'Updated 2 days ago' },
|
|
30
|
+
{ id: 'budget', name: 'Budget review', updated: 'Updated last week' },
|
|
31
|
+
{ id: 'hiring', name: 'Hiring plan', updated: 'Updated 3 weeks ago' },
|
|
32
|
+
{ id: 'roadmap', name: 'Roadmap', updated: 'Updated last month' },
|
|
33
|
+
];
|
|
34
|
+
export default function OverflowMenuOnARow() {
|
|
35
|
+
var _a = useState(firstReports), reports = _a[0], setReports = _a[1];
|
|
36
|
+
// The row whose menu is open, and the More button it opens from. Both stay set while the menu fades out.
|
|
37
|
+
var _b = useState(null), menuRow = _b[0], setMenuRow = _b[1];
|
|
38
|
+
var _c = useState(null), menuAnchor = _c[0], setMenuAnchor = _c[1];
|
|
39
|
+
var _d = useState(false), menuOpen = _d[0], setMenuOpen = _d[1];
|
|
40
|
+
// The row that asks to confirm the delete. One row at a time.
|
|
41
|
+
var _e = useState(null), confirmingId = _e[0], setConfirmingId = _e[1];
|
|
42
|
+
var _f = useState(false), deleting = _f[0], setDeleting = _f[1];
|
|
43
|
+
var timer = useRef();
|
|
44
|
+
var toastIds = useRef([]);
|
|
45
|
+
var cancelDelete = useRef(null);
|
|
46
|
+
// Each row's More button by row id, so focus can move to one when the thing that had it is gone.
|
|
47
|
+
var moreButtons = useRef({});
|
|
48
|
+
// Where focus goes after the next render, once the element it goes to is on screen.
|
|
49
|
+
var focusNext = useRef();
|
|
50
|
+
// The clipboard answers later; by then the example may be gone.
|
|
51
|
+
var mounted = useRef(true);
|
|
52
|
+
// Gives each copy its own id, so no two rows share a key.
|
|
53
|
+
var copies = useRef(0);
|
|
54
|
+
// On unmount it stops the request and closes every toast it opened.
|
|
55
|
+
useEffect(function () { return function () {
|
|
56
|
+
mounted.current = false;
|
|
57
|
+
clearTimeout(timer.current);
|
|
58
|
+
toastIds.current.forEach(function (id) { return dismissToast(id); });
|
|
59
|
+
toastIds.current = [];
|
|
60
|
+
}; }, []);
|
|
61
|
+
useEffect(function () {
|
|
62
|
+
var move = focusNext.current;
|
|
63
|
+
focusNext.current = undefined;
|
|
64
|
+
move === null || move === void 0 ? void 0 : move();
|
|
65
|
+
});
|
|
66
|
+
function openMenu(r, anchor) {
|
|
67
|
+
if (menuOpen && (menuRow === null || menuRow === void 0 ? void 0 : menuRow.id) === r.id) {
|
|
68
|
+
setMenuOpen(false);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
setMenuRow(r);
|
|
72
|
+
setMenuAnchor(anchor);
|
|
73
|
+
setMenuOpen(true);
|
|
74
|
+
}
|
|
75
|
+
// Every item closes the menu, and Escape and a click outside do too. The Popover gives focus back to More.
|
|
76
|
+
function choose(action) {
|
|
77
|
+
if (!menuRow)
|
|
78
|
+
return;
|
|
79
|
+
var r = menuRow;
|
|
80
|
+
setMenuOpen(false);
|
|
81
|
+
action(r);
|
|
82
|
+
}
|
|
83
|
+
// The copy shows under the row, so it needs no toast. Focus goes to the copy's More button.
|
|
84
|
+
function duplicate(r) {
|
|
85
|
+
copies.current += 1;
|
|
86
|
+
var copy = { id: "".concat(r.id, "-copy-").concat(copies.current), name: "".concat(r.name, " copy"), updated: 'Updated just now' };
|
|
87
|
+
setReports(function (list) {
|
|
88
|
+
var at = list.findIndex(function (x) { return x.id === r.id; });
|
|
89
|
+
return __spreadArray(__spreadArray(__spreadArray([], list.slice(0, at + 1), true), [copy], false), list.slice(at + 1), true);
|
|
90
|
+
});
|
|
91
|
+
focusNext.current = function () { var _a; return (_a = moreButtons.current[copy.id]) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
92
|
+
}
|
|
93
|
+
// The menu is gone, so the result shows in a toast. A clipboard that is missing or refuses says to copy by hand,
|
|
94
|
+
// in an error toast that stays until the person closes it.
|
|
95
|
+
function copyLink(r) {
|
|
96
|
+
var link = "https://example.com/reports/".concat(r.id);
|
|
97
|
+
var failed = function () {
|
|
98
|
+
if (!mounted.current)
|
|
99
|
+
return;
|
|
100
|
+
toastIds.current.push(toast({ type: 'error', message: "Copying is blocked here. Select the link and copy it: ".concat(link) }));
|
|
101
|
+
};
|
|
102
|
+
if (!navigator.clipboard)
|
|
103
|
+
return failed();
|
|
104
|
+
navigator.clipboard.writeText(link).then(function () {
|
|
105
|
+
if (!mounted.current)
|
|
106
|
+
return;
|
|
107
|
+
toastIds.current.push(toast({ type: 'success', message: 'Link copied.' }));
|
|
108
|
+
}, failed);
|
|
109
|
+
}
|
|
110
|
+
// The confirm opens in the row, with focus on 'Cancel'.
|
|
111
|
+
function askToDelete(r) {
|
|
112
|
+
setConfirmingId(r.id);
|
|
113
|
+
focusNext.current = function () { var _a; return (_a = cancelDelete.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
114
|
+
}
|
|
115
|
+
// 'Cancel' goes away with the confirm, so focus goes back to the row's More button.
|
|
116
|
+
function keepReport() {
|
|
117
|
+
if (deleting || !confirmingId)
|
|
118
|
+
return;
|
|
119
|
+
var id = confirmingId;
|
|
120
|
+
setConfirmingId(null);
|
|
121
|
+
focusNext.current = function () { var _a; return (_a = moreButtons.current[id]) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
122
|
+
}
|
|
123
|
+
function confirmDelete() {
|
|
124
|
+
var _a;
|
|
125
|
+
if (deleting || !confirmingId)
|
|
126
|
+
return;
|
|
127
|
+
var id = confirmingId;
|
|
128
|
+
var at = reports.findIndex(function (r) { return r.id === id; });
|
|
129
|
+
var gone = reports[at];
|
|
130
|
+
var neighbor = (_a = reports[at + 1]) !== null && _a !== void 0 ? _a : reports[at - 1];
|
|
131
|
+
setDeleting(true);
|
|
132
|
+
// Stands in for the request to the server.
|
|
133
|
+
timer.current = setTimeout(function () {
|
|
134
|
+
setDeleting(false);
|
|
135
|
+
setConfirmingId(null);
|
|
136
|
+
setReports(function (list) { return list.filter(function (r) { return r.id !== id; }); });
|
|
137
|
+
toastIds.current.push(toast({ type: 'success', message: "".concat(gone.name, " deleted.") }));
|
|
138
|
+
// The row is gone: focus goes to the next row's More button, or the one before it when it was the last.
|
|
139
|
+
focusNext.current = function () { var _a; return (_a = (neighbor ? moreButtons.current[neighbor.id] : null)) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
140
|
+
}, 1200);
|
|
141
|
+
}
|
|
142
|
+
return (<Center width="page">
|
|
143
|
+
{/* A real app mounts one Toaster near its root. */}
|
|
144
|
+
<Toaster />
|
|
145
|
+
<Stack gap="large">
|
|
146
|
+
<Heading level={1} size="h5">Reports</Heading>
|
|
147
|
+
{reports.length > 0 ? (<TableContainer>
|
|
148
|
+
{reports.map(function (r) {
|
|
149
|
+
var confirming = r.id === confirmingId;
|
|
150
|
+
return (<TableRow key={r.id}>
|
|
151
|
+
<TableCell>
|
|
152
|
+
<Stack gap="small">
|
|
153
|
+
{r.name}
|
|
154
|
+
{confirming && <Paragraph size="body2" tone="secondary" measure="none">Delete this report?</Paragraph>}
|
|
155
|
+
</Stack>
|
|
156
|
+
</TableCell>
|
|
157
|
+
<TableCell width="160px">{r.updated}</TableCell>
|
|
158
|
+
{/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}
|
|
159
|
+
<TableCell width="168px" align="right">
|
|
160
|
+
{confirming ? (<Cluster gap="small" justify="end">
|
|
161
|
+
<Button ref={cancelDelete} size="small" type="tertiary" state={deleting ? 'disabled' : 'enabled'} label="Cancel" aria-label={"Cancel deleting ".concat(r.name)} onClickButton={keepReport}/>
|
|
162
|
+
<Button size="small" type="primary" color="danger" state="enabled" label="Delete" aria-label={"Delete ".concat(r.name)} loading={deleting} onClickButton={confirmDelete}/>
|
|
163
|
+
</Cluster>) : (<Cluster justify="end">
|
|
164
|
+
<Tooltip title="More">
|
|
165
|
+
<IconButton ref={function (el) { moreButtons.current[r.id] = el; }} color="iconOnly" state={menuOpen && (menuRow === null || menuRow === void 0 ? void 0 : menuRow.id) === r.id ? 'selected' : 'enabled'} size="small" iconName="Ellipsis" ariaLabel={"More actions for ".concat(r.name)} aria-haspopup="menu" aria-expanded={menuOpen && (menuRow === null || menuRow === void 0 ? void 0 : menuRow.id) === r.id} onClick={function (e) { return openMenu(r, e.currentTarget); }}/>
|
|
166
|
+
</Tooltip>
|
|
167
|
+
</Cluster>)}
|
|
168
|
+
</TableCell>
|
|
169
|
+
</TableRow>);
|
|
170
|
+
})}
|
|
171
|
+
</TableContainer>) : (<EmptyBox size="small" text="No reports yet" secondText="Reports you create appear here."/>)}
|
|
172
|
+
</Stack>
|
|
173
|
+
<Popover open={menuOpen} anchorEl={menuAnchor} onClose={function () { return setMenuOpen(false); }} returnFocus>
|
|
174
|
+
<Menu navigable aria-label={menuRow ? "Actions for ".concat(menuRow.name) : 'Report actions'} width={200}>
|
|
175
|
+
<MenuItem size="small" iconName="Copy" label="Duplicate" onClick={function () { return choose(duplicate); }}/>
|
|
176
|
+
<MenuItem size="small" iconName="Link" label="Copy Link" onClick={function () { return choose(copyLink); }}/>
|
|
177
|
+
<Line />
|
|
178
|
+
{/* Delete is last, and danger. */}
|
|
179
|
+
<MenuItem size="small" color="danger" iconName="Trash2" label="Delete" onClick={function () { return choose(askToDelete); }}/>
|
|
180
|
+
</Menu>
|
|
181
|
+
</Popover>
|
|
182
|
+
</Center>);
|
|
183
|
+
}
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
# More menu
|
|
2
|
+
|
|
3
|
+
A person opens a menu of less common actions, behind one button, for a thing or for the page.
|
|
4
|
+
|
|
5
|
+
## Do
|
|
6
|
+
|
|
7
|
+
- Use an `IconButton` with `iconName="Ellipsis"` and a `Tooltip` of 'More'.
|
|
8
|
+
- Name the thing in the button's `ariaLabel`, in sentence case: 'More actions for Q3 report'. In a list, each row names its own item.
|
|
9
|
+
- Open `<Popover returnFocus>` around `<Menu navigable aria-label="Actions for Q3 report">` with `onClick` items, from the button the person pressed: pass `event.currentTarget` as `anchorEl`.
|
|
10
|
+
- Set `aria-haspopup="menu"` and `aria-expanded` on the button, and `state="selected"` while the menu is open.
|
|
11
|
+
- Order the items by how often they are used. Put a destructive item last, after a `Line`, as a `MenuItem` with `color="danger"`.
|
|
12
|
+
- Show a toast when an item has no other sign, such as 'Link copied.', since the menu is gone.
|
|
13
|
+
- Show no toast for Duplicate on a row: the copy shows under it. Move focus to the copy's More button.
|
|
14
|
+
- Confirm a delete on a row in the row, as the case 'Delete confirm' says: 'Cancel' and a danger 'Delete' take the place of the button, and focus goes to 'Cancel'.
|
|
15
|
+
- Move focus after a row is deleted to the next row's More button, or the one before it when it was the last.
|
|
16
|
+
- Confirm a delete from a header in a small Modal: 'Delete Report', 'Cancel' first, then a danger 'Delete'. 'Cancel' puts focus back on the More button.
|
|
17
|
+
- Go back to the list the thing was in after a delete from a header, and show a toast that names it.
|
|
18
|
+
- Show an error toast when Copy Link fails, because the clipboard is missing or refuses: 'Copying is blocked here. Select the link and copy it:' and the link. It stays until the person closes it.
|
|
19
|
+
- Check that the example is still mounted before the clipboard promise starts a toast, for success and failure.
|
|
20
|
+
|
|
21
|
+
## Don't
|
|
22
|
+
|
|
23
|
+
- Do not name the button only 'More'. Say what it acts on.
|
|
24
|
+
- Do not put a frequent action only in the menu. A person needs it in one press.
|
|
25
|
+
- Do not put a destructive item first, or color it by hand. It is last, with `color="danger"`.
|
|
26
|
+
- Do not delete on the first click.
|
|
27
|
+
- Do not open a Modal to confirm a delete on a row in a dense list. The row keeps the place.
|
|
28
|
+
|
|
29
|
+
## Option: More button on a row
|
|
30
|
+
|
|
31
|
+
Use when: The actions are for one item in a list, and each row has its own button.
|
|
32
|
+
|
|
33
|
+
Uses: `Button`, `Center`, `Cluster`, `EmptyBox`, `Heading`, `IconButton`, `Line`, `Menu`, `MenuItem`, `Paragraph`, `Popover`, `Stack`, `TableCell`, `TableContainer`, `TableRow`, `Toaster`, `Tooltip`, `dismissToast`, `toast`
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
'use client';
|
|
37
|
+
import { useEffect, useRef, useState } from 'react';
|
|
38
|
+
import Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';
|
|
39
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
40
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
41
|
+
import Button from 'oneslash-design-system/components/button';
|
|
42
|
+
import IconButton from 'oneslash-design-system/components/iconButton';
|
|
43
|
+
import Tooltip from 'oneslash-design-system/components/tooltip';
|
|
44
|
+
import Popover from 'oneslash-design-system/components/popover';
|
|
45
|
+
import Menu from 'oneslash-design-system/components/menu';
|
|
46
|
+
import MenuItem from 'oneslash-design-system/components/menuItem';
|
|
47
|
+
import Line from 'oneslash-design-system/components/line';
|
|
48
|
+
import EmptyBox from 'oneslash-design-system/components/emptyBox';
|
|
49
|
+
import TableContainer from 'oneslash-design-system/components/tableContainer';
|
|
50
|
+
import TableRow from 'oneslash-design-system/components/tableRow';
|
|
51
|
+
import TableCell from 'oneslash-design-system/components/tableCell';
|
|
52
|
+
import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
|
|
53
|
+
|
|
54
|
+
type Report = { id: string; name: string; updated: string };
|
|
55
|
+
type Focusable = HTMLButtonElement | HTMLAnchorElement | null;
|
|
56
|
+
|
|
57
|
+
// A real app reads these from the server.
|
|
58
|
+
const firstReports: Report[] = [
|
|
59
|
+
{ id: 'q3', name: 'Q3 report', updated: 'Updated 2 days ago' },
|
|
60
|
+
{ id: 'budget', name: 'Budget review', updated: 'Updated last week' },
|
|
61
|
+
{ id: 'hiring', name: 'Hiring plan', updated: 'Updated 3 weeks ago' },
|
|
62
|
+
{ id: 'roadmap', name: 'Roadmap', updated: 'Updated last month' },
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
export default function OverflowMenuOnARow() {
|
|
66
|
+
const [reports, setReports] = useState(firstReports);
|
|
67
|
+
// The row whose menu is open, and the More button it opens from. Both stay set while the menu fades out.
|
|
68
|
+
const [menuRow, setMenuRow] = useState<Report | null>(null);
|
|
69
|
+
const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);
|
|
70
|
+
const [menuOpen, setMenuOpen] = useState(false);
|
|
71
|
+
// The row that asks to confirm the delete. One row at a time.
|
|
72
|
+
const [confirmingId, setConfirmingId] = useState<string | null>(null);
|
|
73
|
+
const [deleting, setDeleting] = useState(false);
|
|
74
|
+
const timer = useRef<ReturnType<typeof setTimeout>>();
|
|
75
|
+
const toastIds = useRef<string[]>([]);
|
|
76
|
+
const cancelDelete = useRef<Focusable>(null);
|
|
77
|
+
// Each row's More button by row id, so focus can move to one when the thing that had it is gone.
|
|
78
|
+
const moreButtons = useRef<Record<string, Focusable>>({});
|
|
79
|
+
// Where focus goes after the next render, once the element it goes to is on screen.
|
|
80
|
+
const focusNext = useRef<() => void>();
|
|
81
|
+
// The clipboard answers later; by then the example may be gone.
|
|
82
|
+
const mounted = useRef(true);
|
|
83
|
+
// Gives each copy its own id, so no two rows share a key.
|
|
84
|
+
const copies = useRef(0);
|
|
85
|
+
|
|
86
|
+
// On unmount it stops the request and closes every toast it opened.
|
|
87
|
+
useEffect(() => () => {
|
|
88
|
+
mounted.current = false;
|
|
89
|
+
clearTimeout(timer.current);
|
|
90
|
+
toastIds.current.forEach((id) => dismissToast(id));
|
|
91
|
+
toastIds.current = [];
|
|
92
|
+
}, []);
|
|
93
|
+
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
const move = focusNext.current;
|
|
96
|
+
focusNext.current = undefined;
|
|
97
|
+
move?.();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
function openMenu(r: Report, anchor: HTMLElement) {
|
|
101
|
+
if (menuOpen && menuRow?.id === r.id) {
|
|
102
|
+
setMenuOpen(false);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
setMenuRow(r);
|
|
106
|
+
setMenuAnchor(anchor);
|
|
107
|
+
setMenuOpen(true);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Every item closes the menu, and Escape and a click outside do too. The Popover gives focus back to More.
|
|
111
|
+
function choose(action: (r: Report) => void) {
|
|
112
|
+
if (!menuRow) return;
|
|
113
|
+
const r = menuRow;
|
|
114
|
+
setMenuOpen(false);
|
|
115
|
+
action(r);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// The copy shows under the row, so it needs no toast. Focus goes to the copy's More button.
|
|
119
|
+
function duplicate(r: Report) {
|
|
120
|
+
copies.current += 1;
|
|
121
|
+
const copy = { id: `${r.id}-copy-${copies.current}`, name: `${r.name} copy`, updated: 'Updated just now' };
|
|
122
|
+
setReports((list) => {
|
|
123
|
+
const at = list.findIndex((x) => x.id === r.id);
|
|
124
|
+
return [...list.slice(0, at + 1), copy, ...list.slice(at + 1)];
|
|
125
|
+
});
|
|
126
|
+
focusNext.current = () => moreButtons.current[copy.id]?.focus();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// The menu is gone, so the result shows in a toast. A clipboard that is missing or refuses says to copy by hand,
|
|
130
|
+
// in an error toast that stays until the person closes it.
|
|
131
|
+
function copyLink(r: Report) {
|
|
132
|
+
const link = `https://example.com/reports/${r.id}`;
|
|
133
|
+
const failed = () => {
|
|
134
|
+
if (!mounted.current) return;
|
|
135
|
+
toastIds.current.push(toast({ type: 'error', message: `Copying is blocked here. Select the link and copy it: ${link}` }));
|
|
136
|
+
};
|
|
137
|
+
if (!navigator.clipboard) return failed();
|
|
138
|
+
navigator.clipboard.writeText(link).then(() => {
|
|
139
|
+
if (!mounted.current) return;
|
|
140
|
+
toastIds.current.push(toast({ type: 'success', message: 'Link copied.' }));
|
|
141
|
+
}, failed);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// The confirm opens in the row, with focus on 'Cancel'.
|
|
145
|
+
function askToDelete(r: Report) {
|
|
146
|
+
setConfirmingId(r.id);
|
|
147
|
+
focusNext.current = () => cancelDelete.current?.focus();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// 'Cancel' goes away with the confirm, so focus goes back to the row's More button.
|
|
151
|
+
function keepReport() {
|
|
152
|
+
if (deleting || !confirmingId) return;
|
|
153
|
+
const id = confirmingId;
|
|
154
|
+
setConfirmingId(null);
|
|
155
|
+
focusNext.current = () => moreButtons.current[id]?.focus();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function confirmDelete() {
|
|
159
|
+
if (deleting || !confirmingId) return;
|
|
160
|
+
const id = confirmingId;
|
|
161
|
+
const at = reports.findIndex((r) => r.id === id);
|
|
162
|
+
const gone = reports[at];
|
|
163
|
+
const neighbor = reports[at + 1] ?? reports[at - 1];
|
|
164
|
+
setDeleting(true);
|
|
165
|
+
// Stands in for the request to the server.
|
|
166
|
+
timer.current = setTimeout(() => {
|
|
167
|
+
setDeleting(false);
|
|
168
|
+
setConfirmingId(null);
|
|
169
|
+
setReports((list) => list.filter((r) => r.id !== id));
|
|
170
|
+
toastIds.current.push(toast({ type: 'success', message: `${gone.name} deleted.` }));
|
|
171
|
+
// The row is gone: focus goes to the next row's More button, or the one before it when it was the last.
|
|
172
|
+
focusNext.current = () => (neighbor ? moreButtons.current[neighbor.id] : null)?.focus();
|
|
173
|
+
}, 1200);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<Center width="page">
|
|
178
|
+
{/* A real app mounts one Toaster near its root. */}
|
|
179
|
+
<Toaster />
|
|
180
|
+
<Stack gap="large">
|
|
181
|
+
<Heading level={1} size="h5">Reports</Heading>
|
|
182
|
+
{reports.length > 0 ? (
|
|
183
|
+
<TableContainer>
|
|
184
|
+
{reports.map((r) => {
|
|
185
|
+
const confirming = r.id === confirmingId;
|
|
186
|
+
return (
|
|
187
|
+
<TableRow key={r.id}>
|
|
188
|
+
<TableCell>
|
|
189
|
+
<Stack gap="small">
|
|
190
|
+
{r.name}
|
|
191
|
+
{confirming && <Paragraph size="body2" tone="secondary" measure="none">Delete this report?</Paragraph>}
|
|
192
|
+
</Stack>
|
|
193
|
+
</TableCell>
|
|
194
|
+
<TableCell width="160px">{r.updated}</TableCell>
|
|
195
|
+
{/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}
|
|
196
|
+
<TableCell width="168px" align="right">
|
|
197
|
+
{confirming ? (
|
|
198
|
+
<Cluster gap="small" justify="end">
|
|
199
|
+
<Button ref={cancelDelete} size="small" type="tertiary" state={deleting ? 'disabled' : 'enabled'} label="Cancel" aria-label={`Cancel deleting ${r.name}`} onClickButton={keepReport} />
|
|
200
|
+
<Button size="small" type="primary" color="danger" state="enabled" label="Delete" aria-label={`Delete ${r.name}`} loading={deleting} onClickButton={confirmDelete} />
|
|
201
|
+
</Cluster>
|
|
202
|
+
) : (
|
|
203
|
+
<Cluster justify="end">
|
|
204
|
+
<Tooltip title="More">
|
|
205
|
+
<IconButton
|
|
206
|
+
ref={(el) => { moreButtons.current[r.id] = el; }}
|
|
207
|
+
color="iconOnly"
|
|
208
|
+
state={menuOpen && menuRow?.id === r.id ? 'selected' : 'enabled'}
|
|
209
|
+
size="small"
|
|
210
|
+
iconName="Ellipsis"
|
|
211
|
+
ariaLabel={`More actions for ${r.name}`}
|
|
212
|
+
aria-haspopup="menu"
|
|
213
|
+
aria-expanded={menuOpen && menuRow?.id === r.id}
|
|
214
|
+
onClick={(e: { currentTarget: HTMLElement }) => openMenu(r, e.currentTarget)}
|
|
215
|
+
/>
|
|
216
|
+
</Tooltip>
|
|
217
|
+
</Cluster>
|
|
218
|
+
)}
|
|
219
|
+
</TableCell>
|
|
220
|
+
</TableRow>
|
|
221
|
+
);
|
|
222
|
+
})}
|
|
223
|
+
</TableContainer>
|
|
224
|
+
) : (
|
|
225
|
+
<EmptyBox size="small" text="No reports yet" secondText="Reports you create appear here." />
|
|
226
|
+
)}
|
|
227
|
+
</Stack>
|
|
228
|
+
<Popover open={menuOpen} anchorEl={menuAnchor} onClose={() => setMenuOpen(false)} returnFocus>
|
|
229
|
+
<Menu navigable aria-label={menuRow ? `Actions for ${menuRow.name}` : 'Report actions'} width={200}>
|
|
230
|
+
<MenuItem size="small" iconName="Copy" label="Duplicate" onClick={() => choose(duplicate)} />
|
|
231
|
+
<MenuItem size="small" iconName="Link" label="Copy Link" onClick={() => choose(copyLink)} />
|
|
232
|
+
<Line />
|
|
233
|
+
{/* Delete is last, and danger. */}
|
|
234
|
+
<MenuItem size="small" color="danger" iconName="Trash2" label="Delete" onClick={() => choose(askToDelete)} />
|
|
235
|
+
</Menu>
|
|
236
|
+
</Popover>
|
|
237
|
+
</Center>
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Option: More button in a header
|
|
243
|
+
|
|
244
|
+
Use when: The actions are for the whole page, and the header has one button.
|
|
245
|
+
|
|
246
|
+
Uses: `Button`, `Center`, `Cluster`, `Heading`, `IconButton`, `Line`, `List`, `Menu`, `MenuItem`, `Modal`, `Paragraph`, `Popover`, `Stack`, `Surface`, `Toaster`, `Tooltip`, `dismissToast`, `toast`
|
|
247
|
+
|
|
248
|
+
```tsx
|
|
249
|
+
'use client';
|
|
250
|
+
import { useEffect, useRef, useState } from 'react';
|
|
251
|
+
import Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';
|
|
252
|
+
import Modal from 'oneslash-design-system/components/modal';
|
|
253
|
+
import Surface from 'oneslash-design-system/components/surface';
|
|
254
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
255
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
256
|
+
import List from 'oneslash-design-system/components/list';
|
|
257
|
+
import Button from 'oneslash-design-system/components/button';
|
|
258
|
+
import IconButton from 'oneslash-design-system/components/iconButton';
|
|
259
|
+
import Tooltip from 'oneslash-design-system/components/tooltip';
|
|
260
|
+
import Popover from 'oneslash-design-system/components/popover';
|
|
261
|
+
import Menu from 'oneslash-design-system/components/menu';
|
|
262
|
+
import MenuItem from 'oneslash-design-system/components/menuItem';
|
|
263
|
+
import Line from 'oneslash-design-system/components/line';
|
|
264
|
+
import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
|
|
265
|
+
|
|
266
|
+
const otherReports = ['Budget review', 'Hiring plan', 'Roadmap'];
|
|
267
|
+
|
|
268
|
+
export default function OverflowMenuInAHeader() {
|
|
269
|
+
const [anchor, setAnchor] = useState<HTMLElement | null>(null);
|
|
270
|
+
const [open, setOpen] = useState(false);
|
|
271
|
+
const [confirming, setConfirming] = useState(false);
|
|
272
|
+
const [deleting, setDeleting] = useState(false);
|
|
273
|
+
const [deleted, setDeleted] = useState(false);
|
|
274
|
+
const timer = useRef<ReturnType<typeof setTimeout>>();
|
|
275
|
+
const toastIds = useRef<string[]>([]);
|
|
276
|
+
const moreButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);
|
|
277
|
+
// Where focus goes after the next render, once the element it goes to is on screen.
|
|
278
|
+
const focusNext = useRef<() => void>();
|
|
279
|
+
// The clipboard answers later; by then the example may be gone.
|
|
280
|
+
const mounted = useRef(true);
|
|
281
|
+
|
|
282
|
+
// On unmount it stops the request and closes every toast it opened.
|
|
283
|
+
useEffect(() => () => {
|
|
284
|
+
mounted.current = false;
|
|
285
|
+
clearTimeout(timer.current);
|
|
286
|
+
toastIds.current.forEach((id) => dismissToast(id));
|
|
287
|
+
toastIds.current = [];
|
|
288
|
+
}, []);
|
|
289
|
+
|
|
290
|
+
useEffect(() => {
|
|
291
|
+
const move = focusNext.current;
|
|
292
|
+
focusNext.current = undefined;
|
|
293
|
+
move?.();
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
function toggle(anchorEl: HTMLElement) {
|
|
297
|
+
setAnchor(anchorEl);
|
|
298
|
+
setOpen((o) => !o);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Every item closes the menu, and Escape and a click outside do too. The Popover gives focus back to More.
|
|
302
|
+
function duplicate() {
|
|
303
|
+
setOpen(false);
|
|
304
|
+
toastIds.current.push(toast({ type: 'success', message: 'Q3 report duplicated.' }));
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// The menu is gone, so the result shows in a toast. A clipboard that is missing or refuses says to copy by hand.
|
|
308
|
+
function copyLink() {
|
|
309
|
+
setOpen(false);
|
|
310
|
+
const link = 'https://example.com/reports/q3';
|
|
311
|
+
const failed = () => {
|
|
312
|
+
if (!mounted.current) return;
|
|
313
|
+
toastIds.current.push(toast({ type: 'error', message: `Copying is blocked here. Select the link and copy it: ${link}` }));
|
|
314
|
+
};
|
|
315
|
+
if (!navigator.clipboard) return failed();
|
|
316
|
+
navigator.clipboard.writeText(link).then(() => {
|
|
317
|
+
if (!mounted.current) return;
|
|
318
|
+
toastIds.current.push(toast({ type: 'success', message: 'Link copied.' }));
|
|
319
|
+
}, failed);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function askToDelete() {
|
|
323
|
+
setOpen(false);
|
|
324
|
+
setConfirming(true);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// The Modal opens while the menu fades, so it cannot take focus back from the menu item: 'Cancel' sends it to More.
|
|
328
|
+
function keepReport() {
|
|
329
|
+
if (deleting) return;
|
|
330
|
+
setConfirming(false);
|
|
331
|
+
focusNext.current = () => moreButton.current?.focus();
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function confirmDelete() {
|
|
335
|
+
if (deleting) return;
|
|
336
|
+
setDeleting(true);
|
|
337
|
+
// Stands in for the request to the server.
|
|
338
|
+
timer.current = setTimeout(() => {
|
|
339
|
+
setDeleting(false);
|
|
340
|
+
setConfirming(false);
|
|
341
|
+
setDeleted(true);
|
|
342
|
+
toastIds.current.push(toast({ type: 'success', message: 'Q3 report deleted.' }));
|
|
343
|
+
}, 1200);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return (
|
|
347
|
+
<Center width="page">
|
|
348
|
+
{/* A real app mounts one Toaster near its root. */}
|
|
349
|
+
<Toaster />
|
|
350
|
+
{deleted ? (
|
|
351
|
+
// A real app goes back to the list of reports here.
|
|
352
|
+
<Stack gap="large">
|
|
353
|
+
<Heading level={1} size="h5">Reports</Heading>
|
|
354
|
+
<Surface padding="large">
|
|
355
|
+
<List items={otherReports} size="body1" />
|
|
356
|
+
</Surface>
|
|
357
|
+
</Stack>
|
|
358
|
+
) : (
|
|
359
|
+
<Stack gap="medium">
|
|
360
|
+
<Cluster justify="between">
|
|
361
|
+
<Heading level={1} size="h5">Q3 report</Heading>
|
|
362
|
+
<Tooltip title="More">
|
|
363
|
+
<IconButton
|
|
364
|
+
ref={moreButton}
|
|
365
|
+
color="iconOnly"
|
|
366
|
+
state={open ? 'selected' : 'enabled'}
|
|
367
|
+
size="small"
|
|
368
|
+
iconName="Ellipsis"
|
|
369
|
+
ariaLabel="More actions for Q3 report"
|
|
370
|
+
aria-haspopup="menu"
|
|
371
|
+
aria-expanded={open}
|
|
372
|
+
onClick={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}
|
|
373
|
+
/>
|
|
374
|
+
</Tooltip>
|
|
375
|
+
</Cluster>
|
|
376
|
+
<Paragraph tone="secondary" size="body2" measure="none">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>
|
|
377
|
+
</Stack>
|
|
378
|
+
)}
|
|
379
|
+
<Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>
|
|
380
|
+
<Menu navigable aria-label="Actions for Q3 report" width={200}>
|
|
381
|
+
<MenuItem size="small" iconName="Copy" label="Duplicate" onClick={duplicate} />
|
|
382
|
+
<MenuItem size="small" iconName="Link" label="Copy Link" onClick={copyLink} />
|
|
383
|
+
<Line />
|
|
384
|
+
{/* Delete is last, and danger. */}
|
|
385
|
+
<MenuItem size="small" color="danger" iconName="Trash2" label="Delete" onClick={askToDelete} />
|
|
386
|
+
</Menu>
|
|
387
|
+
</Popover>
|
|
388
|
+
{/* The page is not a row in a list, so the confirm is a small Modal, as the case 'Delete confirm' says. */}
|
|
389
|
+
<Modal
|
|
390
|
+
isOpen={confirming}
|
|
391
|
+
size="small"
|
|
392
|
+
title="Delete Report"
|
|
393
|
+
onClose={keepReport}
|
|
394
|
+
actions={
|
|
395
|
+
<>
|
|
396
|
+
<Button size="small" type="tertiary" state={deleting ? 'disabled' : 'enabled'} label="Cancel" onClickButton={keepReport} />
|
|
397
|
+
<Button size="small" type="primary" color="danger" state="enabled" label="Delete" loading={deleting} onClickButton={confirmDelete} />
|
|
398
|
+
</>
|
|
399
|
+
}
|
|
400
|
+
>
|
|
401
|
+
<Paragraph measure="none">This deletes 'Q3 report' and its 12 tasks.</Paragraph>
|
|
402
|
+
</Modal>
|
|
403
|
+
</Center>
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
## Native
|
|
409
|
+
|
|
410
|
+
On Apple use a toolbar `Menu` with an `ellipsis.circle` label, or a row's `contextMenu`, with Delete last in the `.destructive` role. Delete asks in a `confirmationDialog`. On Android use an `IconButton` with a `DropdownMenu`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function PageHeaderActions(): import("react").JSX.Element;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import PageShell from '../../components/pageShell';
|
|
4
|
+
import TitleBar from '../../components/titleBar';
|
|
5
|
+
import Button from '../../components/button';
|
|
6
|
+
import IconButton from '../../components/iconButton';
|
|
7
|
+
import Tooltip from '../../components/tooltip';
|
|
8
|
+
import Popover from '../../components/popover';
|
|
9
|
+
import Menu from '../../components/menu';
|
|
10
|
+
import MenuItem from '../../components/menuItem';
|
|
11
|
+
import Line from '../../components/line';
|
|
12
|
+
import Paragraph from '../../components/paragraph';
|
|
13
|
+
import { Stack } from '../../components/layout';
|
|
14
|
+
export default function PageHeaderActions() {
|
|
15
|
+
var _a = useState(null), anchor = _a[0], setAnchor = _a[1];
|
|
16
|
+
// Which More button opened the menu: on a phone the menu also holds Search and Filter.
|
|
17
|
+
var _b = useState('wide'), from = _b[0], setFrom = _b[1];
|
|
18
|
+
var _c = useState(false), open = _c[0], setOpen = _c[1];
|
|
19
|
+
var _d = useState(''), chosen = _d[0], setChosen = _d[1];
|
|
20
|
+
function openMore(kind, el) {
|
|
21
|
+
setFrom(kind);
|
|
22
|
+
setAnchor(el);
|
|
23
|
+
setOpen(function (o) { return !o; });
|
|
24
|
+
}
|
|
25
|
+
// Every item closes the menu. Its Popover gives focus back to the More button.
|
|
26
|
+
function choose(label) {
|
|
27
|
+
setOpen(false);
|
|
28
|
+
setChosen(label);
|
|
29
|
+
}
|
|
30
|
+
var newTask = <Button size="medium" type="primary" state="enabled" label="New Task" decoIcon="Plus" onClickButton={function () { return setChosen('New Task'); }}/>;
|
|
31
|
+
var more = function (kind) { return (<Tooltip title="More">
|
|
32
|
+
<IconButton color="iconOnly" state={open && from === kind ? 'selected' : 'enabled'} size="medium" iconName="Ellipsis" ariaLabel="More actions for Home page" aria-haspopup="menu" aria-expanded={open && from === kind} onClick={function (e) { return openMore(kind, e.currentTarget); }}/>
|
|
33
|
+
</Tooltip>); };
|
|
34
|
+
return (<PageShell>
|
|
35
|
+
<Stack gap="large">
|
|
36
|
+
{/* The title is the page's level 1 heading. One primary Button, then icon buttons, then More last. Below md only the primary and More stay. */}
|
|
37
|
+
<TitleBar title="Home page" actions={<>
|
|
38
|
+
{newTask}
|
|
39
|
+
<Tooltip title="Search">
|
|
40
|
+
<IconButton color="iconOnly" state="enabled" size="medium" iconName="Search" ariaLabel="Search Home page" onClick={function () { return setChosen('Search'); }}/>
|
|
41
|
+
</Tooltip>
|
|
42
|
+
<Tooltip title="Filter">
|
|
43
|
+
<IconButton color="iconOnly" state="enabled" size="medium" iconName="Filter" ariaLabel="Filter Home page" onClick={function () { return setChosen('Filter'); }}/>
|
|
44
|
+
</Tooltip>
|
|
45
|
+
{more('wide')}
|
|
46
|
+
</>} phoneActions={<>
|
|
47
|
+
{newTask}
|
|
48
|
+
{more('phone')}
|
|
49
|
+
</>}/>
|
|
50
|
+
<Paragraph tone="secondary" size="body2" measure="none">{chosen ? "You chose ".concat(chosen, ".") : '12 tasks are open. Updated 2 days ago by Dana Lee.'}</Paragraph>
|
|
51
|
+
</Stack>
|
|
52
|
+
<Popover open={open} anchorEl={anchor} onClose={function () { return setOpen(false); }} returnFocus>
|
|
53
|
+
<Menu navigable aria-label="Actions for Home page" width={200}>
|
|
54
|
+
{from === 'phone' && (<>
|
|
55
|
+
<MenuItem size="small" iconName="Search" label="Search" onClick={function () { return choose('Search'); }}/>
|
|
56
|
+
<MenuItem size="small" iconName="Filter" label="Filter" onClick={function () { return choose('Filter'); }}/>
|
|
57
|
+
<Line />
|
|
58
|
+
</>)}
|
|
59
|
+
<MenuItem size="small" iconName="Pencil" label="Rename" onClick={function () { return choose('Rename'); }}/>
|
|
60
|
+
<MenuItem size="small" iconName="Copy" label="Duplicate" onClick={function () { return choose('Duplicate'); }}/>
|
|
61
|
+
<MenuItem size="small" iconName="Archive" label="Archive" onClick={function () { return choose('Archive'); }}/>
|
|
62
|
+
</Menu>
|
|
63
|
+
</Popover>
|
|
64
|
+
</PageShell>);
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function PageHeaderSubPage(): import("react").JSX.Element;
|