oneslash-design-system 2.16.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 +56 -17
- package/dist/cases/accept-invite/signed-in.jsx +1 -1
- package/dist/cases/accept-invite/signed-out.jsx +1 -1
- package/dist/cases/accept-invite.md +3 -7
- 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/cards.d.ts +1 -0
- package/dist/cases/agent-options/cards.jsx +91 -0
- package/dist/cases/agent-options.md +164 -0
- package/dist/cases/agent-pending-reply/steps.d.ts +1 -0
- package/dist/cases/agent-pending-reply/steps.jsx +149 -0
- package/dist/cases/agent-pending-reply/streaming.d.ts +1 -0
- package/dist/cases/agent-pending-reply/streaming.jsx +146 -0
- package/dist/cases/agent-pending-reply.md +428 -0
- package/dist/cases/agent-plan-proposal/changes.d.ts +1 -0
- package/dist/cases/agent-plan-proposal/changes.jsx +224 -0
- package/dist/cases/agent-plan-proposal/steps.d.ts +1 -0
- package/dist/cases/agent-plan-proposal/steps.jsx +211 -0
- package/dist/cases/agent-plan-proposal.md +652 -0
- package/dist/cases/agent-question/choices.d.ts +1 -0
- package/dist/cases/agent-question/choices.jsx +132 -0
- package/dist/cases/agent-question/free-text.d.ts +1 -0
- package/dist/cases/agent-question/free-text.jsx +81 -0
- package/dist/cases/agent-question.md +334 -0
- 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 +2 -4
- 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/card.d.ts +1 -0
- package/dist/cases/artifact-card/card.jsx +45 -0
- package/dist/cases/artifact-card.md +99 -0
- 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/notice-with-action.d.ts +1 -0
- package/dist/cases/composer-limit/notice-with-action.jsx +87 -0
- package/dist/cases/composer-limit/notice.d.ts +1 -0
- package/dist/cases/composer-limit/notice.jsx +84 -0
- package/dist/cases/composer-limit.md +282 -0
- package/dist/cases/confirm-destructive-action.md +0 -4
- package/dist/cases/confirm-dialogs.md +0 -4
- package/dist/cases/conversation-starters/chips.d.ts +1 -0
- package/dist/cases/conversation-starters/chips.jsx +69 -0
- package/dist/cases/conversation-starters/none.d.ts +1 -0
- package/dist/cases/conversation-starters/none.jsx +45 -0
- package/dist/cases/conversation-starters.md +204 -0
- 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/in-composer.d.ts +1 -0
- package/dist/cases/mention-list/in-composer.jsx +169 -0
- package/dist/cases/mention-list.md +248 -0
- package/dist/cases/message-actions/hover-toolbar.d.ts +1 -0
- package/dist/cases/message-actions/hover-toolbar.jsx +229 -0
- package/dist/cases/message-actions/menu.d.ts +1 -0
- package/dist/cases/message-actions/menu.jsx +258 -0
- package/dist/cases/message-actions.md +647 -0
- package/dist/cases/message-attachments/in-composer.d.ts +1 -0
- package/dist/cases/message-attachments/in-composer.jsx +134 -0
- package/dist/cases/message-attachments/in-message.d.ts +1 -0
- package/dist/cases/message-attachments/in-message.jsx +46 -0
- package/dist/cases/message-attachments.md +306 -0
- package/dist/cases/message-composer/plain.d.ts +1 -0
- package/dist/cases/message-composer/plain.jsx +57 -0
- package/dist/cases/message-composer/with-tools.d.ts +1 -0
- package/dist/cases/message-composer/with-tools.jsx +182 -0
- package/dist/cases/message-composer.md +352 -0
- package/dist/cases/message-edit/in-place.d.ts +1 -0
- package/dist/cases/message-edit/in-place.jsx +99 -0
- package/dist/cases/message-edit.md +175 -0
- package/dist/cases/message-reactions/chips.d.ts +1 -0
- package/dist/cases/message-reactions/chips.jsx +118 -0
- package/dist/cases/message-reactions/quick-pick.d.ts +1 -0
- package/dist/cases/message-reactions/quick-pick.jsx +155 -0
- package/dist/cases/message-reactions.md +367 -0
- package/dist/cases/message-row/grouped.d.ts +1 -0
- package/dist/cases/message-row/grouped.jsx +56 -0
- package/dist/cases/message-row/person-and-agent.d.ts +1 -0
- package/dist/cases/message-row/person-and-agent.jsx +41 -0
- package/dist/cases/message-row.md +185 -0
- 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/thumbs.d.ts +1 -0
- package/dist/cases/reply-feedback/thumbs.jsx +191 -0
- package/dist/cases/reply-feedback/with-reason.d.ts +1 -0
- package/dist/cases/reply-feedback/with-reason.jsx +221 -0
- package/dist/cases/reply-feedback.md +548 -0
- package/dist/cases/reply-sources/cards.d.ts +1 -0
- package/dist/cases/reply-sources/cards.jsx +83 -0
- package/dist/cases/reply-sources/tag-only.d.ts +1 -0
- package/dist/cases/reply-sources/tag-only.jsx +45 -0
- package/dist/cases/reply-sources.md +243 -0
- 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/in-composer.d.ts +1 -0
- package/dist/cases/slash-command-list/in-composer.jsx +162 -0
- package/dist/cases/slash-command-list.md +243 -0
- package/dist/cases/success-feedback.md +1 -5
- 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/line.d.ts +1 -0
- package/dist/cases/typing-and-status/line.jsx +50 -0
- package/dist/cases/typing-and-status.md +92 -0
- package/dist/cases/unsaved-changes-guard.md +0 -4
- package/dist/cases/upgrade-prompt.md +0 -4
- package/dist/cases.json +2331 -294
- package/dist/components/alert.d.ts +3 -1
- package/dist/components/alert.jsx +2 -2
- package/dist/components/button.d.ts +3 -2
- package/dist/components/button.jsx +14 -9
- package/dist/components/checkBox.d.ts +5 -1
- package/dist/components/checkBox.jsx +2 -2
- package/dist/components/composer.d.ts +74 -0
- package/dist/components/composer.jsx +122 -0
- package/dist/components/copyField.d.ts +20 -0
- package/dist/components/copyField.jsx +99 -0
- package/dist/components/fileChip.d.ts +33 -0
- package/dist/components/fileChip.jsx +61 -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/iconButton.d.ts +3 -3
- package/dist/components/iconButton.jsx +9 -7
- package/dist/components/layout.d.ts +7 -1
- package/dist/components/layout.jsx +5 -2
- package/dist/components/menu.d.ts +21 -0
- package/dist/components/menu.jsx +27 -3
- package/dist/components/menuItem.d.ts +12 -2
- package/dist/components/menuItem.jsx +6 -5
- package/dist/components/message.d.ts +28 -0
- package/dist/components/message.jsx +25 -0
- package/dist/components/navigation.d.ts +9 -1
- package/dist/components/navigation.jsx +15 -3
- package/dist/components/paragraph.d.ts +3 -1
- package/dist/components/paragraph.jsx +2 -2
- package/dist/components/popover.d.ts +7 -1
- package/dist/components/popover.jsx +35 -9
- package/dist/components/radioGroup.d.ts +12 -1
- package/dist/components/radioGroup.jsx +20 -9
- 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/sourceCard.d.ts +23 -0
- package/dist/components/sourceCard.jsx +56 -0
- package/dist/components/stepList.d.ts +17 -0
- package/dist/components/stepList.jsx +79 -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/tag.d.ts +9 -1
- package/dist/components/tag.jsx +6 -4
- 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 +6 -21
- package/dist/components/useHotkey.d.ts +7 -0
- package/dist/components/useHotkey.js +24 -0
- package/dist/components/userImage.d.ts +9 -1
- package/dist/components/userImage.jsx +10 -3
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/internal/autoGrow.d.ts +11 -0
- package/dist/internal/autoGrow.js +28 -0
- package/dist/internal/composer.d.ts +16 -0
- package/dist/internal/composer.js +18 -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/menu.d.ts +6 -0
- package/dist/internal/menu.js +31 -0
- package/dist/internal/switch.d.ts +5 -0
- package/dist/internal/switch.js +9 -0
- package/dist/native-mapping.json +62 -1
- package/dist/stories/Button.stories.d.ts +1 -0
- package/dist/stories/Button.stories.jsx +17 -1
- package/dist/stories/Cases.generated.stories.d.ts +53 -0
- package/dist/stories/Cases.generated.stories.jsx +106 -0
- package/dist/stories/Composer.stories.d.ts +23 -0
- package/dist/stories/Composer.stories.jsx +121 -0
- package/dist/stories/CopyField.stories.d.ts +11 -0
- package/dist/stories/CopyField.stories.jsx +65 -0
- package/dist/stories/FileChip.stories.d.ts +7 -0
- package/dist/stories/FileChip.stories.jsx +35 -0
- package/dist/stories/FormField.stories.d.ts +6 -0
- package/dist/stories/FormField.stories.jsx +44 -0
- package/dist/stories/IconButton.stories.d.ts +1 -0
- package/dist/stories/IconButton.stories.jsx +18 -1
- package/dist/stories/Menu.stories.d.ts +4 -0
- package/dist/stories/Menu.stories.jsx +46 -1
- package/dist/stories/MenuItem.stories.d.ts +1 -0
- package/dist/stories/MenuItem.stories.jsx +8 -0
- package/dist/stories/Message.stories.d.ts +10 -0
- package/dist/stories/Message.stories.jsx +77 -0
- package/dist/stories/Navigation.stories.d.ts +1 -0
- package/dist/stories/Navigation.stories.jsx +17 -1
- package/dist/stories/PageComponents.stories.d.ts +1 -0
- package/dist/stories/PageComponents.stories.jsx +21 -0
- package/dist/stories/RadioGroup.stories.d.ts +2 -0
- package/dist/stories/RadioGroup.stories.jsx +40 -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/SourceCard.stories.d.ts +8 -0
- package/dist/stories/SourceCard.stories.jsx +33 -0
- package/dist/stories/StepList.stories.d.ts +8 -0
- package/dist/stories/StepList.stories.jsx +35 -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/UserImage.stories.d.ts +2 -0
- package/dist/stories/UserImage.stories.jsx +19 -0
- package/package.json +8 -3
|
@@ -0,0 +1,162 @@
|
|
|
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 Message from '../../components/message';
|
|
13
|
+
import UserImage from '../../components/userImage';
|
|
14
|
+
import TimeStamp from '../../components/timeStamp';
|
|
15
|
+
import Heading from '../../components/heading';
|
|
16
|
+
import Paragraph from '../../components/paragraph';
|
|
17
|
+
import Composer from '../../components/composer';
|
|
18
|
+
import Menu from '../../components/menu';
|
|
19
|
+
import MenuItem from '../../components/menuItem';
|
|
20
|
+
import { Center, Stack } from '../../components/layout';
|
|
21
|
+
// A real app reads this from the session.
|
|
22
|
+
var me = 'Dana Lee';
|
|
23
|
+
var commands = [
|
|
24
|
+
{ name: 'plan', does: 'Ask the agent for a plan before it acts' },
|
|
25
|
+
{ name: 'summarize', does: 'Sum up this thread', argument: '[topic]' },
|
|
26
|
+
{ name: 'remind', does: 'Set a reminder for this thread', argument: '[time]' },
|
|
27
|
+
{ name: 'status', does: 'Show what the agent is working on' },
|
|
28
|
+
];
|
|
29
|
+
var listId = 'slash-command-list-commands';
|
|
30
|
+
// The list shows at most this many commands; typing more letters narrows it.
|
|
31
|
+
var MAX_MATCHES = 8;
|
|
32
|
+
var optionId = function (c) { return "slash-command-list-option-".concat(c.name); };
|
|
33
|
+
var firstThread = [
|
|
34
|
+
{ id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },
|
|
35
|
+
{ id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'I missed the morning. What did we decide?' },
|
|
36
|
+
];
|
|
37
|
+
// Opens with a / typed, so the list shows every command.
|
|
38
|
+
var firstText = '/';
|
|
39
|
+
// The word after a / at the start of the text before the caret, or null once there is a space or no /.
|
|
40
|
+
function commandQuery(before) {
|
|
41
|
+
var match = before.match(/^\/(\S*)$/);
|
|
42
|
+
return match ? match[1] : null;
|
|
43
|
+
}
|
|
44
|
+
// The query for where the caret is now.
|
|
45
|
+
function queryAtCaret(field) {
|
|
46
|
+
var _a;
|
|
47
|
+
return commandQuery(field.value.slice(0, (_a = field.selectionStart) !== null && _a !== void 0 ? _a : field.value.length));
|
|
48
|
+
}
|
|
49
|
+
var matches = function (query) { return commands.filter(function (c) { return c.name.startsWith(query.toLowerCase()); }).slice(0, MAX_MATCHES); };
|
|
50
|
+
export default function SlashCommandListInComposer() {
|
|
51
|
+
var _a = useState(firstThread), thread = _a[0], setThread = _a[1];
|
|
52
|
+
var _b = useState(firstText), text = _b[0], setText = _b[1];
|
|
53
|
+
var _c = useState(commandQuery(firstText)), query = _c[0], setQuery = _c[1];
|
|
54
|
+
var _d = useState(0), active = _d[0], setActive = _d[1];
|
|
55
|
+
// Where the caret goes after a pick; the effect below puts it there once the new text is in the field.
|
|
56
|
+
var _e = useState(null), caret = _e[0], setCaret = _e[1];
|
|
57
|
+
var field = useRef(null);
|
|
58
|
+
var results = query === null ? [] : matches(query);
|
|
59
|
+
// No match: the list closes.
|
|
60
|
+
var open = results.length > 0;
|
|
61
|
+
// The field opens with the caret at the end, after the /.
|
|
62
|
+
useEffect(function () {
|
|
63
|
+
var _a, _b, _c;
|
|
64
|
+
var end = (_b = (_a = field.current) === null || _a === void 0 ? void 0 : _a.value.length) !== null && _b !== void 0 ? _b : 0;
|
|
65
|
+
(_c = field.current) === null || _c === void 0 ? void 0 : _c.setSelectionRange(end, end);
|
|
66
|
+
}, []);
|
|
67
|
+
useEffect(function () {
|
|
68
|
+
if (caret === null || !field.current)
|
|
69
|
+
return;
|
|
70
|
+
field.current.focus();
|
|
71
|
+
field.current.setSelectionRange(caret, caret);
|
|
72
|
+
setCaret(null);
|
|
73
|
+
}, [caret]);
|
|
74
|
+
function change(value) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
setText(value);
|
|
77
|
+
var at = (_b = (_a = field.current) === null || _a === void 0 ? void 0 : _a.selectionStart) !== null && _b !== void 0 ? _b : value.length;
|
|
78
|
+
setQuery(commandQuery(value.slice(0, at)));
|
|
79
|
+
setActive(0);
|
|
80
|
+
}
|
|
81
|
+
// The caret moved (an arrow key, a click, Home or End): the list follows the word at the caret, and
|
|
82
|
+
// closes when the caret leaves it.
|
|
83
|
+
function caretMoved(e) {
|
|
84
|
+
var next = queryAtCaret(e.currentTarget);
|
|
85
|
+
if (next === query)
|
|
86
|
+
return;
|
|
87
|
+
setQuery(next);
|
|
88
|
+
setActive(0);
|
|
89
|
+
}
|
|
90
|
+
// Puts '/name ' in place of the '/word' before the caret and keeps the text after it. The caret goes
|
|
91
|
+
// after the space, so the person can type the argument. Nothing runs yet.
|
|
92
|
+
function pick(c) {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
var at = (_b = (_a = field.current) === null || _a === void 0 ? void 0 : _a.selectionStart) !== null && _b !== void 0 ? _b : text.length;
|
|
95
|
+
var insert = "/".concat(c.name, " ");
|
|
96
|
+
// One space between the command and what follows, not two.
|
|
97
|
+
var after = text.slice(at).replace(/^ /, '');
|
|
98
|
+
setText(insert + after);
|
|
99
|
+
setQuery(null);
|
|
100
|
+
setCaret(insert.length);
|
|
101
|
+
}
|
|
102
|
+
// While the list is open it takes the arrows, Enter, Tab and Escape, so Enter picks instead of sending.
|
|
103
|
+
function keyDown(e) {
|
|
104
|
+
// An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.
|
|
105
|
+
if (e.nativeEvent.isComposing || e.keyCode === 229)
|
|
106
|
+
return;
|
|
107
|
+
if (!open)
|
|
108
|
+
return;
|
|
109
|
+
if (e.key === 'ArrowDown') {
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
setActive(function (i) { return Math.min(i + 1, results.length - 1); });
|
|
112
|
+
}
|
|
113
|
+
else if (e.key === 'ArrowUp') {
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
setActive(function (i) { return Math.max(i - 1, 0); });
|
|
116
|
+
}
|
|
117
|
+
else if (e.key === 'Enter' || (e.key === 'Tab' && !e.shiftKey)) {
|
|
118
|
+
// Check the word at the caret again before taking the key. If nothing matches now, the list
|
|
119
|
+
// closes and the key does what it always does: Enter sends, Tab moves on. Shift+Tab is never a pick.
|
|
120
|
+
var now = queryAtCaret(e.currentTarget);
|
|
121
|
+
var found = now === null ? [] : matches(now);
|
|
122
|
+
if (found.length === 0) {
|
|
123
|
+
setQuery(null);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
e.preventDefault();
|
|
127
|
+
pick(found[now === query ? Math.min(active, found.length - 1) : 0]);
|
|
128
|
+
}
|
|
129
|
+
else if (e.key === 'Escape') {
|
|
130
|
+
e.preventDefault();
|
|
131
|
+
e.stopPropagation();
|
|
132
|
+
setQuery(null);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// A real app runs the command here. This one shows it in the thread.
|
|
136
|
+
function send() {
|
|
137
|
+
var value = text.trim();
|
|
138
|
+
setThread(function (rows) { return __spreadArray(__spreadArray([], rows, true), [{ id: "m".concat(rows.length + 1), from: me, at: new Date(), text: value, command: value.startsWith('/') }], false); });
|
|
139
|
+
setText('');
|
|
140
|
+
setQuery(null);
|
|
141
|
+
}
|
|
142
|
+
return (<Center width="page">
|
|
143
|
+
<Stack gap="large">
|
|
144
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
145
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
146
|
+
<Stack gap="small">
|
|
147
|
+
{thread.map(function (m) { return (<Message key={m.id} aria-label={m.from} avatar={<UserImage userHandle={m.from} decorative/>} name={m.from} meta={<TimeStamp createdAt={m.at} dateFormat="absolute" data="time"/>}>
|
|
148
|
+
<Paragraph measure="none" mono={m.command}>{m.text}</Paragraph>
|
|
149
|
+
</Message>); })}
|
|
150
|
+
</Stack>
|
|
151
|
+
<Composer ref={field} id="slash-command-list-message" aria-label="Message" placeholder="Message the team, or type / for commands" value={text} onChange={change} onSubmit={send} onKeyDown={keyDown} onSelect={caretMoved}
|
|
152
|
+
// A press on a row keeps focus in the field, so this runs only when focus leaves for good.
|
|
153
|
+
onBlur={function () { return setQuery(null); }}
|
|
154
|
+
// Focus stays in the field; the field points at the list and at the highlighted row.
|
|
155
|
+
role="combobox" aria-autocomplete="list" aria-expanded={open} aria-controls={open ? listId : undefined} aria-activedescendant={open ? optionId(results[active]) : undefined} above={open ? (<Menu role="listbox" id={listId} aria-label="Commands" width={400}>
|
|
156
|
+
{results.map(function (c, i) { return (<MenuItem key={c.name} id={optionId(c)} role="option" tabIndex={-1} isActive={i === active} aria-selected={i === active} size="small" iconName="SquareSlash"
|
|
157
|
+
// MenuItem has no mono label, so the command is plain text.
|
|
158
|
+
label={"/".concat(c.name)} secondLabel={c.does} tag={c.argument ? { label: c.argument, variant: 'textOnly' } : undefined} onClick={function () { return pick(c); }}/>); })}
|
|
159
|
+
</Menu>) : undefined}/>
|
|
160
|
+
</Stack>
|
|
161
|
+
</Center>);
|
|
162
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# Command list
|
|
2
|
+
|
|
3
|
+
A person types / at the start of the message box to run a command.
|
|
4
|
+
|
|
5
|
+
## Do
|
|
6
|
+
|
|
7
|
+
- Open the list when the text starts with /. A bare / opens it, each letter after it narrows it, and a space closes it.
|
|
8
|
+
- Show at most 8 commands. Typing more letters finds the rest.
|
|
9
|
+
- Build it as a combobox. The text area gets `role="combobox"`, `aria-expanded`, `aria-controls` and `aria-activedescendant`, and the list in `above` is a `Menu role="listbox"` of `MenuItem role="option"` rows with `isActive` and `aria-selected`.
|
|
10
|
+
- Show each command with one line on what it does, and the argument it takes, such as '[topic]'. A menu row has no code font yet, so the command is plain text.
|
|
11
|
+
- Keep focus in the message box while the list is open, so the person keeps typing.
|
|
12
|
+
- Use the same keys as the case 'Mention list': the arrows move, Enter or Tab picks, Escape closes.
|
|
13
|
+
- Leave Enter and the arrow keys to an input method while it is still composing, such as for Korean or Japanese.
|
|
14
|
+
- Close the list when the caret moves out of the command being typed, and when focus leaves the message box.
|
|
15
|
+
- Check the word at the caret again on Enter or Tab, and pick only if a command still matches. Shift+Tab picks nothing.
|
|
16
|
+
- Put the command and a space in place of the '/word' before the caret, and keep the text after it.
|
|
17
|
+
- Put the caret after that space, so the person can type the argument.
|
|
18
|
+
- Run the command when the person sends it. Every command works this way, even one that takes no argument.
|
|
19
|
+
- Close the list when no command matches.
|
|
20
|
+
|
|
21
|
+
## Don't
|
|
22
|
+
|
|
23
|
+
- Do not move focus into the list. The person keeps typing in the field.
|
|
24
|
+
- Do not run a command on the Enter that picks it.
|
|
25
|
+
- Do not show an empty list.
|
|
26
|
+
- Do not open the list for a / in the middle of the text.
|
|
27
|
+
|
|
28
|
+
## Example: List in the composer
|
|
29
|
+
|
|
30
|
+
Uses: `Center`, `Composer`, `Heading`, `Menu`, `MenuItem`, `Message`, `Paragraph`, `Stack`, `TimeStamp`, `UserImage`
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
'use client';
|
|
34
|
+
import { useEffect, useRef, useState, type KeyboardEvent, type SyntheticEvent } from 'react';
|
|
35
|
+
import Message from 'oneslash-design-system/components/message';
|
|
36
|
+
import UserImage from 'oneslash-design-system/components/userImage';
|
|
37
|
+
import TimeStamp from 'oneslash-design-system/components/timeStamp';
|
|
38
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
39
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
40
|
+
import Composer from 'oneslash-design-system/components/composer';
|
|
41
|
+
import Menu from 'oneslash-design-system/components/menu';
|
|
42
|
+
import MenuItem from 'oneslash-design-system/components/menuItem';
|
|
43
|
+
import { Center, Stack } from 'oneslash-design-system/components/layout';
|
|
44
|
+
|
|
45
|
+
// A real app reads this from the session.
|
|
46
|
+
const me = 'Dana Lee';
|
|
47
|
+
|
|
48
|
+
type Command = { name: string; does: string; argument?: string };
|
|
49
|
+
const commands: Command[] = [
|
|
50
|
+
{ name: 'plan', does: 'Ask the agent for a plan before it acts' },
|
|
51
|
+
{ name: 'summarize', does: 'Sum up this thread', argument: '[topic]' },
|
|
52
|
+
{ name: 'remind', does: 'Set a reminder for this thread', argument: '[time]' },
|
|
53
|
+
{ name: 'status', does: 'Show what the agent is working on' },
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
const listId = 'slash-command-list-commands';
|
|
57
|
+
// The list shows at most this many commands; typing more letters narrows it.
|
|
58
|
+
const MAX_MATCHES = 8;
|
|
59
|
+
const optionId = (c: Command) => `slash-command-list-option-${c.name}`;
|
|
60
|
+
|
|
61
|
+
type Row = { id: string; from: string; at: Date; text: string; command?: boolean };
|
|
62
|
+
|
|
63
|
+
const firstThread: Row[] = [
|
|
64
|
+
{ id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },
|
|
65
|
+
{ id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'I missed the morning. What did we decide?' },
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
// Opens with a / typed, so the list shows every command.
|
|
69
|
+
const firstText = '/';
|
|
70
|
+
|
|
71
|
+
// The word after a / at the start of the text before the caret, or null once there is a space or no /.
|
|
72
|
+
function commandQuery(before: string) {
|
|
73
|
+
const match = before.match(/^\/(\S*)$/);
|
|
74
|
+
return match ? match[1] : null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// The query for where the caret is now.
|
|
78
|
+
function queryAtCaret(field: HTMLTextAreaElement) {
|
|
79
|
+
return commandQuery(field.value.slice(0, field.selectionStart ?? field.value.length));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const matches = (query: string) => commands.filter((c) => c.name.startsWith(query.toLowerCase())).slice(0, MAX_MATCHES);
|
|
83
|
+
|
|
84
|
+
export default function SlashCommandListInComposer() {
|
|
85
|
+
const [thread, setThread] = useState(firstThread);
|
|
86
|
+
const [text, setText] = useState(firstText);
|
|
87
|
+
const [query, setQuery] = useState<string | null>(commandQuery(firstText));
|
|
88
|
+
const [active, setActive] = useState(0);
|
|
89
|
+
// Where the caret goes after a pick; the effect below puts it there once the new text is in the field.
|
|
90
|
+
const [caret, setCaret] = useState<number | null>(null);
|
|
91
|
+
const field = useRef<HTMLTextAreaElement>(null);
|
|
92
|
+
|
|
93
|
+
const results = query === null ? [] : matches(query);
|
|
94
|
+
// No match: the list closes.
|
|
95
|
+
const open = results.length > 0;
|
|
96
|
+
|
|
97
|
+
// The field opens with the caret at the end, after the /.
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
const end = field.current?.value.length ?? 0;
|
|
100
|
+
field.current?.setSelectionRange(end, end);
|
|
101
|
+
}, []);
|
|
102
|
+
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (caret === null || !field.current) return;
|
|
105
|
+
field.current.focus();
|
|
106
|
+
field.current.setSelectionRange(caret, caret);
|
|
107
|
+
setCaret(null);
|
|
108
|
+
}, [caret]);
|
|
109
|
+
|
|
110
|
+
function change(value: string) {
|
|
111
|
+
setText(value);
|
|
112
|
+
const at = field.current?.selectionStart ?? value.length;
|
|
113
|
+
setQuery(commandQuery(value.slice(0, at)));
|
|
114
|
+
setActive(0);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// The caret moved (an arrow key, a click, Home or End): the list follows the word at the caret, and
|
|
118
|
+
// closes when the caret leaves it.
|
|
119
|
+
function caretMoved(e: SyntheticEvent<HTMLTextAreaElement>) {
|
|
120
|
+
const next = queryAtCaret(e.currentTarget);
|
|
121
|
+
if (next === query) return;
|
|
122
|
+
setQuery(next);
|
|
123
|
+
setActive(0);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Puts '/name ' in place of the '/word' before the caret and keeps the text after it. The caret goes
|
|
127
|
+
// after the space, so the person can type the argument. Nothing runs yet.
|
|
128
|
+
function pick(c: Command) {
|
|
129
|
+
const at = field.current?.selectionStart ?? text.length;
|
|
130
|
+
const insert = `/${c.name} `;
|
|
131
|
+
// One space between the command and what follows, not two.
|
|
132
|
+
const after = text.slice(at).replace(/^ /, '');
|
|
133
|
+
setText(insert + after);
|
|
134
|
+
setQuery(null);
|
|
135
|
+
setCaret(insert.length);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// While the list is open it takes the arrows, Enter, Tab and Escape, so Enter picks instead of sending.
|
|
139
|
+
function keyDown(e: KeyboardEvent<HTMLTextAreaElement>) {
|
|
140
|
+
// An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.
|
|
141
|
+
if (e.nativeEvent.isComposing || e.keyCode === 229) return;
|
|
142
|
+
if (!open) return;
|
|
143
|
+
if (e.key === 'ArrowDown') {
|
|
144
|
+
e.preventDefault();
|
|
145
|
+
setActive((i) => Math.min(i + 1, results.length - 1));
|
|
146
|
+
} else if (e.key === 'ArrowUp') {
|
|
147
|
+
e.preventDefault();
|
|
148
|
+
setActive((i) => Math.max(i - 1, 0));
|
|
149
|
+
} else if (e.key === 'Enter' || (e.key === 'Tab' && !e.shiftKey)) {
|
|
150
|
+
// Check the word at the caret again before taking the key. If nothing matches now, the list
|
|
151
|
+
// closes and the key does what it always does: Enter sends, Tab moves on. Shift+Tab is never a pick.
|
|
152
|
+
const now = queryAtCaret(e.currentTarget);
|
|
153
|
+
const found = now === null ? [] : matches(now);
|
|
154
|
+
if (found.length === 0) {
|
|
155
|
+
setQuery(null);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
pick(found[now === query ? Math.min(active, found.length - 1) : 0]);
|
|
160
|
+
} else if (e.key === 'Escape') {
|
|
161
|
+
e.preventDefault();
|
|
162
|
+
e.stopPropagation();
|
|
163
|
+
setQuery(null);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// A real app runs the command here. This one shows it in the thread.
|
|
168
|
+
function send() {
|
|
169
|
+
const value = text.trim();
|
|
170
|
+
setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: value, command: value.startsWith('/') }]);
|
|
171
|
+
setText('');
|
|
172
|
+
setQuery(null);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<Center width="page">
|
|
177
|
+
<Stack gap="large">
|
|
178
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
179
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
180
|
+
<Stack gap="small">
|
|
181
|
+
{thread.map((m) => (
|
|
182
|
+
<Message
|
|
183
|
+
key={m.id}
|
|
184
|
+
aria-label={m.from}
|
|
185
|
+
avatar={<UserImage userHandle={m.from} decorative />}
|
|
186
|
+
name={m.from}
|
|
187
|
+
meta={<TimeStamp createdAt={m.at} dateFormat="absolute" data="time" />}
|
|
188
|
+
>
|
|
189
|
+
<Paragraph measure="none" mono={m.command}>{m.text}</Paragraph>
|
|
190
|
+
</Message>
|
|
191
|
+
))}
|
|
192
|
+
</Stack>
|
|
193
|
+
<Composer
|
|
194
|
+
ref={field}
|
|
195
|
+
id="slash-command-list-message"
|
|
196
|
+
aria-label="Message"
|
|
197
|
+
placeholder="Message the team, or type / for commands"
|
|
198
|
+
value={text}
|
|
199
|
+
onChange={change}
|
|
200
|
+
onSubmit={send}
|
|
201
|
+
onKeyDown={keyDown}
|
|
202
|
+
onSelect={caretMoved}
|
|
203
|
+
// A press on a row keeps focus in the field, so this runs only when focus leaves for good.
|
|
204
|
+
onBlur={() => setQuery(null)}
|
|
205
|
+
// Focus stays in the field; the field points at the list and at the highlighted row.
|
|
206
|
+
role="combobox"
|
|
207
|
+
aria-autocomplete="list"
|
|
208
|
+
aria-expanded={open}
|
|
209
|
+
aria-controls={open ? listId : undefined}
|
|
210
|
+
aria-activedescendant={open ? optionId(results[active]) : undefined}
|
|
211
|
+
above={
|
|
212
|
+
open ? (
|
|
213
|
+
<Menu role="listbox" id={listId} aria-label="Commands" width={400}>
|
|
214
|
+
{results.map((c, i) => (
|
|
215
|
+
<MenuItem
|
|
216
|
+
key={c.name}
|
|
217
|
+
id={optionId(c)}
|
|
218
|
+
role="option"
|
|
219
|
+
tabIndex={-1}
|
|
220
|
+
isActive={i === active}
|
|
221
|
+
aria-selected={i === active}
|
|
222
|
+
size="small"
|
|
223
|
+
iconName="SquareSlash"
|
|
224
|
+
// MenuItem has no mono label, so the command is plain text.
|
|
225
|
+
label={`/${c.name}`}
|
|
226
|
+
secondLabel={c.does}
|
|
227
|
+
tag={c.argument ? { label: c.argument, variant: 'textOnly' } : undefined}
|
|
228
|
+
onClick={() => pick(c)}
|
|
229
|
+
/>
|
|
230
|
+
))}
|
|
231
|
+
</Menu>
|
|
232
|
+
) : undefined
|
|
233
|
+
}
|
|
234
|
+
/>
|
|
235
|
+
</Stack>
|
|
236
|
+
</Center>
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Native
|
|
242
|
+
|
|
243
|
+
On Apple the list shows above the field with the command, what it does and, when it takes an argument, its usage. Escape closes the list on a Mac.
|
|
@@ -4,9 +4,7 @@ Something the person did has worked.
|
|
|
4
4
|
|
|
5
5
|
## Answer
|
|
6
6
|
|
|
7
|
-
The feedback depends on where the result shows. A Button that is `loading` keeps its label, and the spinner shows that it is working. Only success changes a label, and there are three success labels: 'Saved', 'Copied' and 'Sent', each for 2 seconds. When a form saves in place, its Button is `loading`, then reads 'Saved' for 2 seconds, then its own label again. There is no toast. Sometimes the result is somewhere else or gone. Something was deleted, sent, moved or duplicated somewhere else, or a long job has finished. Then call `toast({ type: 'success', message: '…' })` with one short sentence in the past tense, in sentence case. It closes after 5 seconds. When something is copied to the clipboard, a Button reads 'Copied' for 2 seconds, and an IconButton swaps its icon to `Check` for 2 seconds. When a Button sends an email again, it reads 'Sent' for 2 seconds. The message names the thing and does not say 'successfully'.
|
|
8
|
-
|
|
9
|
-
**Not built yet:** Scindo on the web has no toast. It shows success in five ways: a 'Saved' Button label, a green caption, an inline Alert, a thank-you that replaces a dialog and a 'Copied' label. The timed ones clear after 1.5, 2, 3 or 4 seconds. Commentify shows toasts through `Alert`, one at a time, and many of them say 'successfully'.
|
|
7
|
+
The feedback depends on where the result shows. A Button that is `loading` keeps its label, and the spinner shows that it is working. Only success changes a label, and there are three success labels: 'Saved', 'Copied' and 'Sent', each for 2 seconds. When a form saves in place, its Button is `loading`, then reads 'Saved' for 2 seconds, then its own label again. There is no toast. Sometimes the result is somewhere else or gone. Something was deleted, sent, moved or duplicated somewhere else, or a long job has finished. Then call `toast({ type: 'success', message: '…' })` with one short sentence in the past tense, in sentence case. It closes after 5 seconds. When something is copied to the clipboard, a Button reads 'Copied' for 2 seconds, and an IconButton swaps its icon to `Check` for 2 seconds. When Copy is a menu item, the menu closes, so a toast says 'Message copied.' instead. When a Button sends an email again, it reads 'Sent' for 2 seconds. The message names the thing and does not say 'successfully'.
|
|
10
8
|
|
|
11
9
|
## Why
|
|
12
10
|
|
|
@@ -31,5 +29,3 @@ Feedback belongs where the person is looking. A change they can see needs only a
|
|
|
31
29
|
## Native
|
|
32
30
|
|
|
33
31
|
On Apple there is no toast. Show the result in place.
|
|
34
|
-
|
|
35
|
-
Seen in: Commentify, Scindo.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function TagFilterTags(): import("react").JSX.Element;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
+
if (ar || !(i in from)) {
|
|
16
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
+
ar[i] = from[i];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
+
};
|
|
22
|
+
import { useEffect, useRef, useState } from 'react';
|
|
23
|
+
import Toaster, { toast, dismissToast } from '../../components/toaster';
|
|
24
|
+
import Modal from '../../components/modal';
|
|
25
|
+
import Heading from '../../components/heading';
|
|
26
|
+
import Paragraph from '../../components/paragraph';
|
|
27
|
+
import TextField from '../../components/textField';
|
|
28
|
+
import Tag from '../../components/tag';
|
|
29
|
+
import Button from '../../components/button';
|
|
30
|
+
import IconButton from '../../components/iconButton';
|
|
31
|
+
import Tooltip from '../../components/tooltip';
|
|
32
|
+
import Popover from '../../components/popover';
|
|
33
|
+
import Menu from '../../components/menu';
|
|
34
|
+
import MenuItem from '../../components/menuItem';
|
|
35
|
+
import EmptyBox from '../../components/emptyBox';
|
|
36
|
+
import TableContainer from '../../components/tableContainer';
|
|
37
|
+
import TableRow from '../../components/tableRow';
|
|
38
|
+
import TableCell from '../../components/tableCell';
|
|
39
|
+
import { Center, Cluster, Stack } from '../../components/layout';
|
|
40
|
+
var firstTags = [
|
|
41
|
+
{ id: 'design', name: 'Design' },
|
|
42
|
+
{ id: 'research', name: 'Research' },
|
|
43
|
+
{ id: 'ideas', name: 'Ideas' },
|
|
44
|
+
];
|
|
45
|
+
var firstItems = [
|
|
46
|
+
{ id: 'i1', title: 'Pricing page teardown', tagId: 'research' },
|
|
47
|
+
{ id: 'i2', title: 'Color tokens for dark mode', tagId: 'design' },
|
|
48
|
+
{ id: 'i3', title: 'Onboarding checklist patterns', tagId: 'design' },
|
|
49
|
+
{ id: 'i4', title: 'Interview notes, March', tagId: 'research' },
|
|
50
|
+
{ id: 'i5', title: 'A weekly digest email', tagId: 'ideas' },
|
|
51
|
+
{ id: 'i6', title: 'Keyboard shortcut cheat sheet', tagId: null },
|
|
52
|
+
];
|
|
53
|
+
export default function TagFilterTags() {
|
|
54
|
+
var _a = useState(firstTags), tags = _a[0], setTags = _a[1];
|
|
55
|
+
var _b = useState(firstItems), items = _b[0], setItems = _b[1];
|
|
56
|
+
// null is 'All'.
|
|
57
|
+
var _c = useState('design'), selected = _c[0], setSelected = _c[1];
|
|
58
|
+
var _d = useState(null), editing = _d[0], setEditing = _d[1];
|
|
59
|
+
var _e = useState(''), draft = _e[0], setDraft = _e[1];
|
|
60
|
+
var _f = useState(false), taken = _f[0], setTaken = _f[1];
|
|
61
|
+
var _g = useState(null), menuAnchor = _g[0], setMenuAnchor = _g[1];
|
|
62
|
+
var _h = useState(false), menuOpen = _h[0], setMenuOpen = _h[1];
|
|
63
|
+
var _j = useState(false), confirming = _j[0], setConfirming = _j[1];
|
|
64
|
+
var _k = useState(false), deleting = _k[0], setDeleting = _k[1];
|
|
65
|
+
// The tag the confirm is about, kept until the Modal is closed, so its text stays while it fades out.
|
|
66
|
+
var _l = useState({ name: '', count: 0 }), doomed = _l[0], setDoomed = _l[1];
|
|
67
|
+
var timer = useRef();
|
|
68
|
+
var toastIds = useRef([]);
|
|
69
|
+
var moreButton = useRef(null);
|
|
70
|
+
var addButton = useRef(null);
|
|
71
|
+
// Enter and Escape end the edit before the field goes away, so its blur must not save again.
|
|
72
|
+
var ended = useRef(false);
|
|
73
|
+
// Where focus goes after the next render, once the element it goes to is on screen.
|
|
74
|
+
var focusNext = useRef();
|
|
75
|
+
var tag = tags.find(function (t) { return t.id === selected; });
|
|
76
|
+
var shown = selected === null ? items : items.filter(function (i) { return i.tagId === selected; });
|
|
77
|
+
var nameOf = function (tagId) { var _a, _b; return (_b = (_a = tags.find(function (t) { return t.id === tagId; })) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : 'No tag'; };
|
|
78
|
+
// On unmount it stops the request and closes every toast it opened.
|
|
79
|
+
useEffect(function () { return function () {
|
|
80
|
+
clearTimeout(timer.current);
|
|
81
|
+
toastIds.current.forEach(function (id) { return dismissToast(id); });
|
|
82
|
+
toastIds.current = [];
|
|
83
|
+
}; }, []);
|
|
84
|
+
useEffect(function () {
|
|
85
|
+
var move = focusNext.current;
|
|
86
|
+
focusNext.current = undefined;
|
|
87
|
+
move === null || move === void 0 ? void 0 : move();
|
|
88
|
+
});
|
|
89
|
+
function startEditing(kind) {
|
|
90
|
+
ended.current = false;
|
|
91
|
+
setDraft(kind === 'rename' && tag ? tag.name : '');
|
|
92
|
+
setTaken(false);
|
|
93
|
+
setEditing(kind);
|
|
94
|
+
}
|
|
95
|
+
// Enter and a click away save. An empty or unchanged name cancels. A name that is taken stays in the field with
|
|
96
|
+
// the error, so what the person typed is not lost. `byKey` is true for Enter, where focus goes back to where it was.
|
|
97
|
+
function finish(byKey) {
|
|
98
|
+
if (ended.current || !editing)
|
|
99
|
+
return;
|
|
100
|
+
var name = draft.trim();
|
|
101
|
+
var unchanged = editing === 'rename' && name === (tag === null || tag === void 0 ? void 0 : tag.name);
|
|
102
|
+
if (!name || unchanged)
|
|
103
|
+
return cancel(byKey);
|
|
104
|
+
if (tags.some(function (t) { return !(editing === 'rename' && t.id === selected) && t.name.toLowerCase() === name.toLowerCase(); })) {
|
|
105
|
+
setTaken(true);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
ended.current = true;
|
|
109
|
+
// A real app sends the name to the server here and shows it at once.
|
|
110
|
+
if (editing === 'rename') {
|
|
111
|
+
setTags(function (list) { return list.map(function (t) { return (t.id === selected ? __assign(__assign({}, t), { name: name }) : t); }); });
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
var id_1 = "tag-".concat(name.toLowerCase().replace(/\s+/g, '-'));
|
|
115
|
+
setTags(function (list) { return __spreadArray(__spreadArray([], list, true), [{ id: id_1, name: name }], false); });
|
|
116
|
+
setSelected(id_1);
|
|
117
|
+
}
|
|
118
|
+
leave(byKey);
|
|
119
|
+
}
|
|
120
|
+
function cancel(byKey) {
|
|
121
|
+
if (ended.current)
|
|
122
|
+
return;
|
|
123
|
+
ended.current = true;
|
|
124
|
+
leave(byKey);
|
|
125
|
+
}
|
|
126
|
+
function leave(byKey) {
|
|
127
|
+
var kind = editing;
|
|
128
|
+
setEditing(null);
|
|
129
|
+
setTaken(false);
|
|
130
|
+
if (byKey)
|
|
131
|
+
focusNext.current = function () { var _a; return (_a = (kind === 'rename' ? moreButton.current : addButton.current)) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
132
|
+
}
|
|
133
|
+
function openMenu(anchorEl) {
|
|
134
|
+
setMenuAnchor(anchorEl);
|
|
135
|
+
setMenuOpen(function (o) { return !o; });
|
|
136
|
+
}
|
|
137
|
+
// The menu closes on any choice. Its Popover gives focus back to the More button.
|
|
138
|
+
function rename() {
|
|
139
|
+
setMenuOpen(false);
|
|
140
|
+
startEditing('rename');
|
|
141
|
+
}
|
|
142
|
+
function askToDelete() {
|
|
143
|
+
setMenuOpen(false);
|
|
144
|
+
if (tag)
|
|
145
|
+
setDoomed({ name: tag.name, count: items.filter(function (i) { return i.tagId === tag.id; }).length });
|
|
146
|
+
setConfirming(true);
|
|
147
|
+
}
|
|
148
|
+
// 'Cancel' ends the confirm; the More button is still there, so focus goes back to it.
|
|
149
|
+
function keepTag() {
|
|
150
|
+
if (deleting)
|
|
151
|
+
return;
|
|
152
|
+
setConfirming(false);
|
|
153
|
+
focusNext.current = function () { var _a; return (_a = moreButton.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
154
|
+
}
|
|
155
|
+
// The items keep their place in 'All' and lose the tag. The tag and its More button are gone, so focus goes to 'Add Tag'.
|
|
156
|
+
function confirmDelete() {
|
|
157
|
+
if (deleting || !tag)
|
|
158
|
+
return;
|
|
159
|
+
var gone = tag;
|
|
160
|
+
setDeleting(true);
|
|
161
|
+
// Stands in for the request to the server.
|
|
162
|
+
timer.current = setTimeout(function () {
|
|
163
|
+
setDeleting(false);
|
|
164
|
+
setConfirming(false);
|
|
165
|
+
setTags(function (list) { return list.filter(function (t) { return t.id !== gone.id; }); });
|
|
166
|
+
setItems(function (list) { return list.map(function (i) { return (i.tagId === gone.id ? __assign(__assign({}, i), { tagId: null }) : i); }); });
|
|
167
|
+
setSelected(null);
|
|
168
|
+
toastIds.current.push(toast({ type: 'success', message: "".concat(gone.name, " tag deleted.") }));
|
|
169
|
+
focusNext.current = function () { var _a; return (_a = addButton.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
170
|
+
}, 1200);
|
|
171
|
+
}
|
|
172
|
+
return (<Center width="page">
|
|
173
|
+
{/* A real app mounts one Toaster near its root. */}
|
|
174
|
+
<Toaster />
|
|
175
|
+
<Stack gap="large">
|
|
176
|
+
<Heading level={1} size="h5">Reading list</Heading>
|
|
177
|
+
{editing ? (
|
|
178
|
+
// The row of tags becomes the field, as the case 'Rename' says for a name that is on screen. Enter and a click away save, Escape cancels.
|
|
179
|
+
<TextField key={editing} id="tag-filter-name" size="small" autoFocus aria-label={editing === 'rename' ? "Rename tag ".concat(tag === null || tag === void 0 ? void 0 : tag.name) : 'New tag name'} placeholder={editing === 'add' ? 'Tag name' : undefined} value={draft} error={taken} errorText="A tag with this name already exists." onChange={function (e) {
|
|
180
|
+
setDraft(e.target.value);
|
|
181
|
+
setTaken(false);
|
|
182
|
+
}} onKeyDown={function (e) {
|
|
183
|
+
if (e.key === 'Enter') {
|
|
184
|
+
e.preventDefault();
|
|
185
|
+
finish(true);
|
|
186
|
+
}
|
|
187
|
+
else if (e.key === 'Escape') {
|
|
188
|
+
e.preventDefault();
|
|
189
|
+
cancel(true);
|
|
190
|
+
}
|
|
191
|
+
}} onBlur={function () { return finish(false); }}/>) : (
|
|
192
|
+
// Tags that people add, rename and delete are not a fixed short set, so they are toggle Tags in a row that wraps.
|
|
193
|
+
<Cluster gap="small">
|
|
194
|
+
<Tag variant="contained" size="medium" label="All" state={selected === null ? 'selected' : 'enabled'} onClick={function () { return setSelected(null); }}/>
|
|
195
|
+
{tags.map(function (t) { return (<Tag key={t.id} variant="contained" size="medium" label={t.name} state={t.id === selected ? 'selected' : 'enabled'} onClick={function () { return setSelected(t.id); }}/>); })}
|
|
196
|
+
{/* One More button, for the tag that is selected, so the row has one extra stop and not one per tag. */}
|
|
197
|
+
{tag && (<Tooltip title="More">
|
|
198
|
+
<IconButton ref={moreButton} color="iconOnly" state={menuOpen ? 'selected' : 'enabled'} size="small" iconName="Ellipsis" ariaLabel={"More actions for tag ".concat(tag.name)} aria-haspopup="menu" aria-expanded={menuOpen} onClick={function (e) { return openMenu(e.currentTarget); }}/>
|
|
199
|
+
</Tooltip>)}
|
|
200
|
+
<Button ref={addButton} size="small" type="tertiary" state="enabled" label="Add Tag" decoIcon="Plus" onClickButton={function () { return startEditing('add'); }}/>
|
|
201
|
+
</Cluster>)}
|
|
202
|
+
{shown.length > 0 ? (<TableContainer>
|
|
203
|
+
{shown.map(function (i) { return (<TableRow key={i.id}>
|
|
204
|
+
<TableCell>{i.title}</TableCell>
|
|
205
|
+
<TableCell width="120px">{nameOf(i.tagId)}</TableCell>
|
|
206
|
+
</TableRow>); })}
|
|
207
|
+
</TableContainer>) : (<EmptyBox size="small" icon="Tag" text={"No items tagged '".concat(tag === null || tag === void 0 ? void 0 : tag.name, "'")} secondText="Items you tag appear here."/>)}
|
|
208
|
+
</Stack>
|
|
209
|
+
<Popover open={menuOpen} anchorEl={menuAnchor} onClose={function () { return setMenuOpen(false); }} returnFocus>
|
|
210
|
+
<Menu navigable aria-label="Tag actions" width={180}>
|
|
211
|
+
<MenuItem size="small" iconName="Pencil" label="Rename" onClick={rename}/>
|
|
212
|
+
{/* Delete is last, and danger. */}
|
|
213
|
+
<MenuItem size="small" color="danger" iconName="Trash2" label="Delete" onClick={askToDelete}/>
|
|
214
|
+
</Menu>
|
|
215
|
+
</Popover>
|
|
216
|
+
<Modal isOpen={confirming} size="small" title="Delete Tag" onClose={keepTag} actions={<>
|
|
217
|
+
<Button size="small" type="tertiary" state={deleting ? 'disabled' : 'enabled'} label="Cancel" onClickButton={keepTag}/>
|
|
218
|
+
<Button size="small" type="primary" color="danger" state="enabled" label="Delete" loading={deleting} onClickButton={confirmDelete}/>
|
|
219
|
+
</>}>
|
|
220
|
+
<Paragraph measure="none">{"This deletes the tag '".concat(doomed.name, "'.")}</Paragraph>
|
|
221
|
+
<Paragraph tone="secondary" size="body2" measure="none">
|
|
222
|
+
{doomed.count === 1 ? 'Its 1 item stays in All, with no tag.' : "Its ".concat(doomed.count, " items stay in All, with no tag.")}
|
|
223
|
+
</Paragraph>
|
|
224
|
+
</Modal>
|
|
225
|
+
</Center>);
|
|
226
|
+
}
|