oneslash-design-system 2.17.0 → 2.18.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 +30 -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/artifact-card.md +0 -4
- 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.md +0 -4
- 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/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/not-found-page.md +0 -4
- 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/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/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.md +0 -2
- 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/sign-up-page.md +1 -5
- 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/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 +1038 -263
- package/dist/components/alert.d.ts +3 -1
- package/dist/components/alert.jsx +2 -2
- 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/formField.d.ts +34 -0
- package/dist/components/formField.jsx +28 -0
- package/dist/components/heading.d.ts +3 -1
- package/dist/components/heading.jsx +2 -2
- package/dist/components/menu.jsx +2 -2
- package/dist/components/menuItem.d.ts +4 -2
- package/dist/components/menuItem.jsx +3 -3
- package/dist/components/navigation.d.ts +9 -1
- package/dist/components/navigation.jsx +15 -3
- 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 +31 -0
- package/dist/components/settingsSection.jsx +58 -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/useHotkey.d.ts +7 -0
- package/dist/components/useHotkey.js +24 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -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/switch.d.ts +5 -0
- package/dist/internal/switch.js +9 -0
- package/dist/native-mapping.json +30 -0
- package/dist/stories/Cases.generated.stories.d.ts +23 -0
- package/dist/stories/Cases.generated.stories.jsx +46 -0
- package/dist/stories/CopyField.stories.d.ts +11 -0
- package/dist/stories/CopyField.stories.jsx +65 -0
- package/dist/stories/FormField.stories.d.ts +6 -0
- package/dist/stories/FormField.stories.jsx +44 -0
- package/dist/stories/Navigation.stories.d.ts +1 -0
- package/dist/stories/Navigation.stories.jsx +17 -1
- package/dist/stories/SegmentedControl.stories.d.ts +8 -0
- package/dist/stories/SegmentedControl.stories.jsx +33 -0
- package/dist/stories/SettingsSection.stories.d.ts +11 -0
- package/dist/stories/SettingsSection.stories.jsx +64 -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/package.json +5 -1
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import Toaster, { toast, dismissToast } from '../../components/toaster';
|
|
4
|
+
import Modal from '../../components/modal';
|
|
5
|
+
import Surface from '../../components/surface';
|
|
6
|
+
import Heading from '../../components/heading';
|
|
7
|
+
import Paragraph from '../../components/paragraph';
|
|
8
|
+
import List from '../../components/list';
|
|
9
|
+
import Button from '../../components/button';
|
|
10
|
+
import IconButton from '../../components/iconButton';
|
|
11
|
+
import Tooltip from '../../components/tooltip';
|
|
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 { Center, Cluster, Stack } from '../../components/layout';
|
|
17
|
+
var otherReports = ['Budget review', 'Hiring plan', 'Roadmap'];
|
|
18
|
+
export default function OverflowMenuInAHeader() {
|
|
19
|
+
var _a = useState(null), anchor = _a[0], setAnchor = _a[1];
|
|
20
|
+
var _b = useState(false), open = _b[0], setOpen = _b[1];
|
|
21
|
+
var _c = useState(false), confirming = _c[0], setConfirming = _c[1];
|
|
22
|
+
var _d = useState(false), deleting = _d[0], setDeleting = _d[1];
|
|
23
|
+
var _e = useState(false), deleted = _e[0], setDeleted = _e[1];
|
|
24
|
+
var timer = useRef();
|
|
25
|
+
var toastIds = useRef([]);
|
|
26
|
+
var moreButton = useRef(null);
|
|
27
|
+
// Where focus goes after the next render, once the element it goes to is on screen.
|
|
28
|
+
var focusNext = useRef();
|
|
29
|
+
// The clipboard answers later; by then the example may be gone.
|
|
30
|
+
var mounted = useRef(true);
|
|
31
|
+
// On unmount it stops the request and closes every toast it opened.
|
|
32
|
+
useEffect(function () { return function () {
|
|
33
|
+
mounted.current = false;
|
|
34
|
+
clearTimeout(timer.current);
|
|
35
|
+
toastIds.current.forEach(function (id) { return dismissToast(id); });
|
|
36
|
+
toastIds.current = [];
|
|
37
|
+
}; }, []);
|
|
38
|
+
useEffect(function () {
|
|
39
|
+
var move = focusNext.current;
|
|
40
|
+
focusNext.current = undefined;
|
|
41
|
+
move === null || move === void 0 ? void 0 : move();
|
|
42
|
+
});
|
|
43
|
+
function toggle(anchorEl) {
|
|
44
|
+
setAnchor(anchorEl);
|
|
45
|
+
setOpen(function (o) { return !o; });
|
|
46
|
+
}
|
|
47
|
+
// Every item closes the menu, and Escape and a click outside do too. The Popover gives focus back to More.
|
|
48
|
+
function duplicate() {
|
|
49
|
+
setOpen(false);
|
|
50
|
+
toastIds.current.push(toast({ type: 'success', message: 'Q3 report duplicated.' }));
|
|
51
|
+
}
|
|
52
|
+
// The menu is gone, so the result shows in a toast. A clipboard that is missing or refuses says to copy by hand.
|
|
53
|
+
function copyLink() {
|
|
54
|
+
setOpen(false);
|
|
55
|
+
var link = 'https://example.com/reports/q3';
|
|
56
|
+
var failed = function () {
|
|
57
|
+
if (!mounted.current)
|
|
58
|
+
return;
|
|
59
|
+
toastIds.current.push(toast({ type: 'error', message: "Copying is blocked here. Select the link and copy it: ".concat(link) }));
|
|
60
|
+
};
|
|
61
|
+
if (!navigator.clipboard)
|
|
62
|
+
return failed();
|
|
63
|
+
navigator.clipboard.writeText(link).then(function () {
|
|
64
|
+
if (!mounted.current)
|
|
65
|
+
return;
|
|
66
|
+
toastIds.current.push(toast({ type: 'success', message: 'Link copied.' }));
|
|
67
|
+
}, failed);
|
|
68
|
+
}
|
|
69
|
+
function askToDelete() {
|
|
70
|
+
setOpen(false);
|
|
71
|
+
setConfirming(true);
|
|
72
|
+
}
|
|
73
|
+
// The Modal opens while the menu fades, so it cannot take focus back from the menu item: 'Cancel' sends it to More.
|
|
74
|
+
function keepReport() {
|
|
75
|
+
if (deleting)
|
|
76
|
+
return;
|
|
77
|
+
setConfirming(false);
|
|
78
|
+
focusNext.current = function () { var _a; return (_a = moreButton.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
79
|
+
}
|
|
80
|
+
function confirmDelete() {
|
|
81
|
+
if (deleting)
|
|
82
|
+
return;
|
|
83
|
+
setDeleting(true);
|
|
84
|
+
// Stands in for the request to the server.
|
|
85
|
+
timer.current = setTimeout(function () {
|
|
86
|
+
setDeleting(false);
|
|
87
|
+
setConfirming(false);
|
|
88
|
+
setDeleted(true);
|
|
89
|
+
toastIds.current.push(toast({ type: 'success', message: 'Q3 report deleted.' }));
|
|
90
|
+
}, 1200);
|
|
91
|
+
}
|
|
92
|
+
return (<Center width="page">
|
|
93
|
+
{/* A real app mounts one Toaster near its root. */}
|
|
94
|
+
<Toaster />
|
|
95
|
+
{deleted ? (
|
|
96
|
+
// A real app goes back to the list of reports here.
|
|
97
|
+
<Stack gap="large">
|
|
98
|
+
<Heading level={1} size="h5">Reports</Heading>
|
|
99
|
+
<Surface padding="large">
|
|
100
|
+
<List items={otherReports} size="body1"/>
|
|
101
|
+
</Surface>
|
|
102
|
+
</Stack>) : (<Stack gap="medium">
|
|
103
|
+
<Cluster justify="between">
|
|
104
|
+
<Heading level={1} size="h5">Q3 report</Heading>
|
|
105
|
+
<Tooltip title="More">
|
|
106
|
+
<IconButton ref={moreButton} color="iconOnly" state={open ? 'selected' : 'enabled'} size="small" iconName="Ellipsis" ariaLabel="More actions for Q3 report" aria-haspopup="menu" aria-expanded={open} onClick={function (e) { return toggle(e.currentTarget); }}/>
|
|
107
|
+
</Tooltip>
|
|
108
|
+
</Cluster>
|
|
109
|
+
<Paragraph tone="secondary" size="body2" measure="none">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>
|
|
110
|
+
</Stack>)}
|
|
111
|
+
<Popover open={open} anchorEl={anchor} onClose={function () { return setOpen(false); }} returnFocus>
|
|
112
|
+
<Menu navigable aria-label="Actions for Q3 report" width={200}>
|
|
113
|
+
<MenuItem size="small" iconName="Copy" label="Duplicate" onClick={duplicate}/>
|
|
114
|
+
<MenuItem size="small" iconName="Link" label="Copy Link" onClick={copyLink}/>
|
|
115
|
+
<Line />
|
|
116
|
+
{/* Delete is last, and danger. */}
|
|
117
|
+
<MenuItem size="small" color="danger" iconName="Trash2" label="Delete" onClick={askToDelete}/>
|
|
118
|
+
</Menu>
|
|
119
|
+
</Popover>
|
|
120
|
+
{/* The page is not a row in a list, so the confirm is a small Modal, as the case 'Delete confirm' says. */}
|
|
121
|
+
<Modal isOpen={confirming} size="small" title="Delete Report" onClose={keepReport} actions={<>
|
|
122
|
+
<Button size="small" type="tertiary" state={deleting ? 'disabled' : 'enabled'} label="Cancel" onClickButton={keepReport}/>
|
|
123
|
+
<Button size="small" type="primary" color="danger" state="enabled" label="Delete" loading={deleting} onClickButton={confirmDelete}/>
|
|
124
|
+
</>}>
|
|
125
|
+
<Paragraph measure="none">This deletes 'Q3 report' and its 12 tasks.</Paragraph>
|
|
126
|
+
</Modal>
|
|
127
|
+
</Center>);
|
|
128
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function OverflowMenuOnARow(): import("react").JSX.Element;
|
|
@@ -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
|
+
}
|