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,229 @@
|
|
|
1
|
+
# API keys
|
|
2
|
+
|
|
3
|
+
A person makes keys that let a script or a service use the product as them, and revokes keys they no longer use.
|
|
4
|
+
|
|
5
|
+
## Do
|
|
6
|
+
|
|
7
|
+
- List each key with its name, the start of the key in the mono face, when it was created and when it was last used. Say 'Never used' when it was not.
|
|
8
|
+
- Show only a prefix of 14 characters in the list, with an ellipsis. Never show a whole key again once the Modal is closed.
|
|
9
|
+
- Open a Modal titled 'Create Key' from a 'Create Key' Button, with one field, 'Name', and 'Cancel' then 'Create'.
|
|
10
|
+
- Say under the name what to put in it: 'Say what will use it, such as CI pipeline.'
|
|
11
|
+
- Keep the Modal open when the key is made, change its title to 'Key Created' and show the key in a `CopyField` with `reveal="once"` and `mono`. The field says 'Copy it now. You will not see it again.'
|
|
12
|
+
- Give the Modal one Button, 'Done'. Ignore Escape and a click outside while the key shows, so a stray click cannot lose it.
|
|
13
|
+
- Confirm 'Revoke' in the row, as the case 'Delete confirm' does: the row asks 'Revoke CI pipeline?' and shows 'Cancel' and a danger 'Revoke'. Then show a toast: 'CI pipeline key revoked.'
|
|
14
|
+
- Give each row's 'Revoke', and the confirm's 'Cancel' and 'Revoke', an `aria-label` that names the key: 'Revoke CI pipeline' and 'Cancel revoking CI pipeline'.
|
|
15
|
+
- Show `EmptyBox` with 'No API keys' when the list is empty, as the rule 'An empty list says what is empty' says.
|
|
16
|
+
- Disable the name field while the key is made, and show `loading` on the Button without changing its label.
|
|
17
|
+
|
|
18
|
+
## Don't
|
|
19
|
+
|
|
20
|
+
- Do not show a whole key in the list, in a toast or in a URL.
|
|
21
|
+
- Do not revoke a key on the first click.
|
|
22
|
+
- Do not label the Button 'Create' on the page. Name the thing: 'Create Key'.
|
|
23
|
+
- Do not close the Modal when the key is made, because the person has not copied it yet.
|
|
24
|
+
- Do not put the key in a plain field the person has to select by hand. Use `CopyField`.
|
|
25
|
+
- Do not use an icon-only Button for Revoke. It names no key.
|
|
26
|
+
|
|
27
|
+
## Example: A list of keys with a create Modal
|
|
28
|
+
|
|
29
|
+
Uses: `Button`, `Center`, `Cluster`, `CopyField`, `EmptyBox`, `Form`, `Heading`, `Modal`, `Paragraph`, `Stack`, `TableCell`, `TableContainer`, `TableHeader`, `TableHeaderCell`, `TableRow`, `TextField`, `Toaster`, `dismissToast`, `toast`
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
'use client';
|
|
33
|
+
import { useEffect, useRef, useState } from 'react';
|
|
34
|
+
import Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';
|
|
35
|
+
import Modal from 'oneslash-design-system/components/modal';
|
|
36
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
37
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
38
|
+
import TableContainer from 'oneslash-design-system/components/tableContainer';
|
|
39
|
+
import TableHeader from 'oneslash-design-system/components/tableHeader';
|
|
40
|
+
import TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';
|
|
41
|
+
import TableRow from 'oneslash-design-system/components/tableRow';
|
|
42
|
+
import TableCell from 'oneslash-design-system/components/tableCell';
|
|
43
|
+
import Form from 'oneslash-design-system/components/form';
|
|
44
|
+
import TextField from 'oneslash-design-system/components/textField';
|
|
45
|
+
import CopyField from 'oneslash-design-system/components/copyField';
|
|
46
|
+
import EmptyBox from 'oneslash-design-system/components/emptyBox';
|
|
47
|
+
import Button from 'oneslash-design-system/components/button';
|
|
48
|
+
import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
|
|
49
|
+
|
|
50
|
+
type Key = { id: string; name: string; prefix: string; created: string; lastUsed: string };
|
|
51
|
+
|
|
52
|
+
const firstKeys: Key[] = [
|
|
53
|
+
{ id: 'k1', name: 'CI pipeline', prefix: 'acme_live_7Hd2', created: 'Oct 3, 2026', lastUsed: 'Today' },
|
|
54
|
+
{ id: 'k2', name: 'Reporting script', prefix: 'acme_live_Qm4x', created: 'Aug 19, 2026', lastUsed: 'Nov 20, 2026' },
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
// The key the server made. A real app gets it once, in the reply to the create request, and never again.
|
|
58
|
+
const madeKey = 'acme_live_4f9kQ27xLmT4vB8cRw1ZdN6yHs3P';
|
|
59
|
+
const prefixLength = 14;
|
|
60
|
+
|
|
61
|
+
export default function ApiKeysList() {
|
|
62
|
+
// Opens on the new key, as if the person just chose Create. The list already holds it, without the key.
|
|
63
|
+
const [keys, setKeys] = useState<Key[]>(() => [
|
|
64
|
+
{ id: 'k3', name: 'Deploy bot', prefix: madeKey.slice(0, prefixLength), created: 'Today', lastUsed: 'Never used' },
|
|
65
|
+
...firstKeys,
|
|
66
|
+
]);
|
|
67
|
+
const [open, setOpen] = useState(true);
|
|
68
|
+
const [shownKey, setShownKey] = useState<string | null>(madeKey);
|
|
69
|
+
const [name, setName] = useState('');
|
|
70
|
+
const [nameError, setNameError] = useState('');
|
|
71
|
+
const [creating, setCreating] = useState(false);
|
|
72
|
+
const [confirming, setConfirming] = useState<string | null>(null);
|
|
73
|
+
const [revoking, setRevoking] = useState<string | null>(null);
|
|
74
|
+
const timers = useRef<ReturnType<typeof setTimeout>[]>([]);
|
|
75
|
+
// Gives each new key its own id, so no two rows share a key.
|
|
76
|
+
const keyCount = useRef(0);
|
|
77
|
+
const toastIds = useRef<string[]>([]);
|
|
78
|
+
|
|
79
|
+
// On unmount it stops every request and closes every toast it opened.
|
|
80
|
+
useEffect(() => () => {
|
|
81
|
+
timers.current.forEach(clearTimeout);
|
|
82
|
+
toastIds.current.forEach((id) => dismissToast(id));
|
|
83
|
+
toastIds.current = [];
|
|
84
|
+
}, []);
|
|
85
|
+
|
|
86
|
+
// Stands in for the request to the server.
|
|
87
|
+
function later(callback: () => void, ms: number) {
|
|
88
|
+
timers.current.push(setTimeout(callback, ms));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function handleOpen() {
|
|
92
|
+
setName('');
|
|
93
|
+
setNameError('');
|
|
94
|
+
setShownKey(null);
|
|
95
|
+
setOpen(true);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Escape, a click outside and Cancel close the first step, except while the request runs.
|
|
99
|
+
// Once the key shows, only 'Done' closes it, so a stray click cannot throw the key away.
|
|
100
|
+
function handleClose() {
|
|
101
|
+
if (creating || shownKey) return;
|
|
102
|
+
setOpen(false);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 'Done' drops the key from the page. It is not kept anywhere else.
|
|
106
|
+
function handleDone() {
|
|
107
|
+
setOpen(false);
|
|
108
|
+
setShownKey(null);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function handleCreate() {
|
|
112
|
+
if (creating) return;
|
|
113
|
+
if (!name.trim()) {
|
|
114
|
+
setNameError('Enter a name for the key.');
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
setNameError('');
|
|
118
|
+
setCreating(true);
|
|
119
|
+
later(() => {
|
|
120
|
+
setCreating(false);
|
|
121
|
+
keyCount.current += 1;
|
|
122
|
+
const id = `new-${keyCount.current}`;
|
|
123
|
+
setKeys((list) => [{ id, name: name.trim(), prefix: madeKey.slice(0, prefixLength), created: 'Today', lastUsed: 'Never used' }, ...list]);
|
|
124
|
+
setShownKey(madeKey);
|
|
125
|
+
}, 1200);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function handleRevoke(key: Key) {
|
|
129
|
+
if (revoking) return;
|
|
130
|
+
setRevoking(key.id);
|
|
131
|
+
later(() => {
|
|
132
|
+
setRevoking(null);
|
|
133
|
+
setConfirming(null);
|
|
134
|
+
setKeys((list) => list.filter((k) => k.id !== key.id));
|
|
135
|
+
toastIds.current.push(toast({ type: 'success', message: `${key.name} key revoked.` }));
|
|
136
|
+
}, 1200);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<Center width="page">
|
|
141
|
+
{/* A real app mounts one Toaster near its root. */}
|
|
142
|
+
<Toaster />
|
|
143
|
+
<Stack gap="large">
|
|
144
|
+
<Stack gap="small">
|
|
145
|
+
<Cluster justify="between">
|
|
146
|
+
<Heading level={1} size="h5">API keys</Heading>
|
|
147
|
+
<Button size="small" type="primary" state="enabled" label="Create Key" decoIcon="Plus" onClickButton={handleOpen} />
|
|
148
|
+
</Cluster>
|
|
149
|
+
<Paragraph tone="secondary" size="body2" measure="none">Keys let a script or a service use Acme as you. The list shows the start of each key, never the whole key.</Paragraph>
|
|
150
|
+
</Stack>
|
|
151
|
+
|
|
152
|
+
{keys.length > 0 ? (
|
|
153
|
+
<TableContainer>
|
|
154
|
+
<TableHeader>
|
|
155
|
+
<TableRow>
|
|
156
|
+
<TableHeaderCell>Name</TableHeaderCell>
|
|
157
|
+
<TableHeaderCell width="150px">Key</TableHeaderCell>
|
|
158
|
+
<TableHeaderCell width="100px">Created</TableHeaderCell>
|
|
159
|
+
<TableHeaderCell width="100px">Last used</TableHeaderCell>
|
|
160
|
+
<TableHeaderCell width="200px">Actions</TableHeaderCell>
|
|
161
|
+
</TableRow>
|
|
162
|
+
</TableHeader>
|
|
163
|
+
{keys.map((k) => (
|
|
164
|
+
<TableRow key={k.id}>
|
|
165
|
+
<TableCell>{k.name}</TableCell>
|
|
166
|
+
<TableCell width="150px">
|
|
167
|
+
<Paragraph mono size="body2" measure="none">{k.prefix}…</Paragraph>
|
|
168
|
+
</TableCell>
|
|
169
|
+
<TableCell width="100px">{k.created}</TableCell>
|
|
170
|
+
<TableCell width="100px">{k.lastUsed}</TableCell>
|
|
171
|
+
{/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}
|
|
172
|
+
<TableCell width="200px">
|
|
173
|
+
{confirming === k.id ? (
|
|
174
|
+
<Stack gap="small">
|
|
175
|
+
<Paragraph size="body2" measure="none">Revoke {k.name}?</Paragraph>
|
|
176
|
+
<Cluster gap="small">
|
|
177
|
+
<Button size="small" type="tertiary" state={revoking === k.id ? 'disabled' : 'enabled'} label="Cancel" aria-label={`Cancel revoking ${k.name}`} onClickButton={() => setConfirming(null)} />
|
|
178
|
+
<Button size="small" type="primary" color="danger" state="enabled" label="Revoke" aria-label={`Revoke ${k.name}`} loading={revoking === k.id} onClickButton={() => handleRevoke(k)} />
|
|
179
|
+
</Cluster>
|
|
180
|
+
</Stack>
|
|
181
|
+
) : (
|
|
182
|
+
<Button size="small" type="tertiary" state={revoking ? 'disabled' : 'enabled'} label="Revoke" aria-label={`Revoke ${k.name}`} onClickButton={() => setConfirming(k.id)} />
|
|
183
|
+
)}
|
|
184
|
+
</TableCell>
|
|
185
|
+
</TableRow>
|
|
186
|
+
))}
|
|
187
|
+
</TableContainer>
|
|
188
|
+
) : (
|
|
189
|
+
<EmptyBox size="small" icon="KeyRound" text="No API keys" secondText="Keys you create appear here." />
|
|
190
|
+
)}
|
|
191
|
+
</Stack>
|
|
192
|
+
|
|
193
|
+
<Modal
|
|
194
|
+
isOpen={open}
|
|
195
|
+
size="medium"
|
|
196
|
+
initialFocus="body"
|
|
197
|
+
title={shownKey ? 'Key Created' : 'Create Key'}
|
|
198
|
+
onClose={handleClose}
|
|
199
|
+
actions={
|
|
200
|
+
shownKey ? (
|
|
201
|
+
<Button size="small" type="primary" state="enabled" label="Done" onClickButton={handleDone} />
|
|
202
|
+
) : (
|
|
203
|
+
<>
|
|
204
|
+
<Button size="small" type="tertiary" state={creating ? 'disabled' : 'enabled'} label="Cancel" onClickButton={handleClose} />
|
|
205
|
+
<Button size="small" type="primary" state="enabled" label="Create" loading={creating} onClickButton={handleCreate} />
|
|
206
|
+
</>
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
>
|
|
210
|
+
{shownKey ? (
|
|
211
|
+
<Stack gap="medium">
|
|
212
|
+
<Paragraph measure="none">Use this key where the service asks for one. Anyone who has it can use Acme as you.</Paragraph>
|
|
213
|
+
{/* `reveal="once"` adds the line that says the key will not show again. */}
|
|
214
|
+
<CopyField id="api-keys-key" label="API key" value={shownKey} mono reveal="once" />
|
|
215
|
+
</Stack>
|
|
216
|
+
) : (
|
|
217
|
+
<Form aria-label="Create key" onSubmit={handleCreate}>
|
|
218
|
+
<TextField id="api-keys-name" label="Name" value={name} disabled={creating} error={Boolean(nameError)} errorText={nameError} helperText="Say what will use it, such as CI pipeline." onChange={(e) => { setName(e.target.value); setNameError(''); }} />
|
|
219
|
+
</Form>
|
|
220
|
+
)}
|
|
221
|
+
</Modal>
|
|
222
|
+
</Center>
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Native
|
|
228
|
+
|
|
229
|
+
On Apple use a `Table` with a monospaced prefix, a `.destructive` Button that asks in a `confirmationDialog`, and a sheet that shows the new key once with a Copy Button.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function ArtifactCardCard(): import("react").JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Bot, FileText } from 'lucide-react';
|
|
3
|
+
import Message from '../../components/message';
|
|
4
|
+
import UserImage from '../../components/userImage';
|
|
5
|
+
import Tag from '../../components/tag';
|
|
6
|
+
import TimeStamp from '../../components/timeStamp';
|
|
7
|
+
import Heading from '../../components/heading';
|
|
8
|
+
import Paragraph from '../../components/paragraph';
|
|
9
|
+
import SourceCard from '../../components/sourceCard';
|
|
10
|
+
import { Center, Grid, Stack } from '../../components/layout';
|
|
11
|
+
var agentName = 'Acme Agent';
|
|
12
|
+
var request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you write up the launch plan as a document?' };
|
|
13
|
+
var repliedAt = new Date('2025-01-15T11:41:00Z');
|
|
14
|
+
// One sentence on what the agent made. The document itself stays out of the thread.
|
|
15
|
+
var reply = 'I wrote the launch plan for March 3 as a document.';
|
|
16
|
+
var doc = { title: 'Launch plan for March 3', meta: 'Document · 4 pages' };
|
|
17
|
+
// The agent's marks, as the rule 'An agent says what it is' says.
|
|
18
|
+
function agentMeta(at) {
|
|
19
|
+
return (<>
|
|
20
|
+
<Tag variant="contained" size="small" label="Agent"/>
|
|
21
|
+
<TimeStamp createdAt={at} dateFormat="absolute" data="time"/>
|
|
22
|
+
<Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
|
|
23
|
+
</>);
|
|
24
|
+
}
|
|
25
|
+
// A real app opens the document in a pane beside the thread and moves focus into it.
|
|
26
|
+
// ODS has no side pane part yet, so this example shows the card only.
|
|
27
|
+
function openDocument() { }
|
|
28
|
+
export default function ArtifactCardCard() {
|
|
29
|
+
return (<Center width="page">
|
|
30
|
+
<Stack gap="large">
|
|
31
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
32
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
33
|
+
<Stack gap="small">
|
|
34
|
+
<Message aria-label={request.from} avatar={<UserImage userHandle={request.from} decorative/>} name={request.from} meta={<TimeStamp createdAt={request.at} dateFormat="absolute" data="time"/>}>
|
|
35
|
+
<Paragraph measure="none">{request.text}</Paragraph>
|
|
36
|
+
</Message>
|
|
37
|
+
<Message aria-label={"".concat(agentName, ", agent")} avatar={<UserImage userHandle={agentName} icon={Bot} decorative/>} name={agentName} meta={agentMeta(repliedAt)} footer={<Grid columns={2} gap="medium">
|
|
38
|
+
<SourceCard icon={FileText} title={doc.title} meta={doc.meta} action="Open" onClick={openDocument}/>
|
|
39
|
+
</Grid>}>
|
|
40
|
+
<Paragraph measure="none">{reply}</Paragraph>
|
|
41
|
+
</Message>
|
|
42
|
+
</Stack>
|
|
43
|
+
</Stack>
|
|
44
|
+
</Center>);
|
|
45
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Document card
|
|
2
|
+
|
|
3
|
+
The agent made a document for the person, such as a plan or a report.
|
|
4
|
+
|
|
5
|
+
## Do
|
|
6
|
+
|
|
7
|
+
- Keep the reply to one sentence on what the agent made. Then put the card in the reply's `footer`.
|
|
8
|
+
- Show the document as a `SourceCard`: an icon for its kind, its title, its kind and length in `meta` ('Document · 4 pages'), and `action="Open"`.
|
|
9
|
+
- Open the document from the card with `onClick`, in a pane beside the thread.
|
|
10
|
+
- Move focus into the pane when it opens.
|
|
11
|
+
- Give the pane a Close control, and move focus back to the card when the pane closes.
|
|
12
|
+
- Bring the open pane forward when the person presses the card again, instead of opening a second one.
|
|
13
|
+
- Mark the agent's row as the rule 'An agent says what it is' says.
|
|
14
|
+
- Give the list that holds the rows `role="log"`.
|
|
15
|
+
|
|
16
|
+
## Don't
|
|
17
|
+
|
|
18
|
+
- Do not paste the document into the thread.
|
|
19
|
+
- Do not repeat or list what the document says in the reply.
|
|
20
|
+
- Do not show the document's card on a person's message.
|
|
21
|
+
|
|
22
|
+
## Example: In the thread
|
|
23
|
+
|
|
24
|
+
Uses: `Center`, `Grid`, `Heading`, `Message`, `Paragraph`, `SourceCard`, `Stack`, `Tag`, `TimeStamp`, `UserImage`
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
'use client';
|
|
28
|
+
import { Bot, FileText } from 'lucide-react';
|
|
29
|
+
import Message from 'oneslash-design-system/components/message';
|
|
30
|
+
import UserImage from 'oneslash-design-system/components/userImage';
|
|
31
|
+
import Tag from 'oneslash-design-system/components/tag';
|
|
32
|
+
import TimeStamp from 'oneslash-design-system/components/timeStamp';
|
|
33
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
34
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
35
|
+
import SourceCard from 'oneslash-design-system/components/sourceCard';
|
|
36
|
+
import { Center, Grid, Stack } from 'oneslash-design-system/components/layout';
|
|
37
|
+
|
|
38
|
+
const agentName = 'Acme Agent';
|
|
39
|
+
|
|
40
|
+
const request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you write up the launch plan as a document?' };
|
|
41
|
+
const repliedAt = new Date('2025-01-15T11:41:00Z');
|
|
42
|
+
// One sentence on what the agent made. The document itself stays out of the thread.
|
|
43
|
+
const reply = 'I wrote the launch plan for March 3 as a document.';
|
|
44
|
+
|
|
45
|
+
const doc = { title: 'Launch plan for March 3', meta: 'Document · 4 pages' };
|
|
46
|
+
|
|
47
|
+
// The agent's marks, as the rule 'An agent says what it is' says.
|
|
48
|
+
function agentMeta(at: Date) {
|
|
49
|
+
return (
|
|
50
|
+
<>
|
|
51
|
+
<Tag variant="contained" size="small" label="Agent" />
|
|
52
|
+
<TimeStamp createdAt={at} dateFormat="absolute" data="time" />
|
|
53
|
+
<Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
|
|
54
|
+
</>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// A real app opens the document in a pane beside the thread and moves focus into it.
|
|
59
|
+
// ODS has no side pane part yet, so this example shows the card only.
|
|
60
|
+
function openDocument() {}
|
|
61
|
+
|
|
62
|
+
export default function ArtifactCardCard() {
|
|
63
|
+
return (
|
|
64
|
+
<Center width="page">
|
|
65
|
+
<Stack gap="large">
|
|
66
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
67
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
68
|
+
<Stack gap="small">
|
|
69
|
+
<Message
|
|
70
|
+
aria-label={request.from}
|
|
71
|
+
avatar={<UserImage userHandle={request.from} decorative />}
|
|
72
|
+
name={request.from}
|
|
73
|
+
meta={<TimeStamp createdAt={request.at} dateFormat="absolute" data="time" />}
|
|
74
|
+
>
|
|
75
|
+
<Paragraph measure="none">{request.text}</Paragraph>
|
|
76
|
+
</Message>
|
|
77
|
+
<Message
|
|
78
|
+
aria-label={`${agentName}, agent`}
|
|
79
|
+
avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}
|
|
80
|
+
name={agentName}
|
|
81
|
+
meta={agentMeta(repliedAt)}
|
|
82
|
+
footer={
|
|
83
|
+
<Grid columns={2} gap="medium">
|
|
84
|
+
<SourceCard icon={FileText} title={doc.title} meta={doc.meta} action="Open" onClick={openDocument} />
|
|
85
|
+
</Grid>
|
|
86
|
+
}
|
|
87
|
+
>
|
|
88
|
+
<Paragraph measure="none">{reply}</Paragraph>
|
|
89
|
+
</Message>
|
|
90
|
+
</Stack>
|
|
91
|
+
</Stack>
|
|
92
|
+
</Center>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Native
|
|
98
|
+
|
|
99
|
+
On Mac the card opens the document in the canvas beside the thread. On iPhone it opens the document in a read-only sheet.
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
The app is checking whether the person is logged in, or running a step such as checking an invite, before it knows what to show.
|
|
4
4
|
|
|
5
|
-
**Not built yet:** Scindo on the web shows 'Please wait' under the step while it checks an invite, and a small spinner instead of `LoadingScreen` while onboarding checks for a workspace.
|
|
6
|
-
|
|
7
5
|
## Do
|
|
8
6
|
|
|
9
7
|
- Show the spinner from the first render, before anything else, as `LoadingScreen` in `Center` with `fill`.
|
|
@@ -66,5 +64,3 @@ export default function AuthGateLoadingSpinnerWithLine() {
|
|
|
66
64
|
## Native
|
|
67
65
|
|
|
68
66
|
On Apple use `ProgressView()` centered in the window, with a label only for a named step that can take longer.
|
|
69
|
-
|
|
70
|
-
Seen in: Commentify admin, Scindo.
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
A person signed up, and the product sent a link to confirm their email.
|
|
4
4
|
|
|
5
|
-
**Not built yet:** Neither Commentify nor Scindo can send the email again from the check-your-email screen. Both show their success Alert above the login form with a close button, and it starts 'Account created.', even for an address that already had an account.
|
|
6
|
-
|
|
7
5
|
## Do
|
|
8
6
|
|
|
9
7
|
- Name the page 'Check your email' in a `Heading` with `level={1}`, with a `Mail` icon above it.
|
|
@@ -180,5 +178,3 @@ export default function CheckYourEmailAlertOnLogin() {
|
|
|
180
178
|
);
|
|
181
179
|
}
|
|
182
180
|
```
|
|
183
|
-
|
|
184
|
-
Seen in: Commentify, Scindo.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function CollapsibleSearchPopover(): import("react").JSX.Element;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useRef, useState } from 'react';
|
|
3
|
+
import Heading from '../../components/heading';
|
|
4
|
+
import Paragraph from '../../components/paragraph';
|
|
5
|
+
import TextField from '../../components/textField';
|
|
6
|
+
import IconButton from '../../components/iconButton';
|
|
7
|
+
import Button from '../../components/button';
|
|
8
|
+
import Tooltip from '../../components/tooltip';
|
|
9
|
+
import Popover from '../../components/popover';
|
|
10
|
+
import Menu from '../../components/menu';
|
|
11
|
+
import List from '../../components/list';
|
|
12
|
+
import Surface from '../../components/surface';
|
|
13
|
+
import EmptyBox from '../../components/emptyBox';
|
|
14
|
+
import { Center, Cluster, Stack } from '../../components/layout';
|
|
15
|
+
// A real app reads these from the server.
|
|
16
|
+
var invoices = ['Northwind, March', 'Harbor Studio, March', 'Lumen Labs, February', 'Northstar Dental, February', 'Pine and Co, January'];
|
|
17
|
+
export default function CollapsibleSearchPopover() {
|
|
18
|
+
// The filter belongs to the page, not to the Popover: it stays when the Popover closes.
|
|
19
|
+
var _a = useState('north'), query = _a[0], setQuery = _a[1];
|
|
20
|
+
var _b = useState(null), anchor = _b[0], setAnchor = _b[1];
|
|
21
|
+
var _c = useState(false), open = _c[0], setOpen = _c[1];
|
|
22
|
+
var trigger = useRef(null);
|
|
23
|
+
var words = query.trim();
|
|
24
|
+
var on = words !== '';
|
|
25
|
+
var found = invoices.filter(function (name) { return name.toLowerCase().includes(words.toLowerCase()); });
|
|
26
|
+
function toggle(anchorEl) {
|
|
27
|
+
setAnchor(anchorEl);
|
|
28
|
+
setOpen(function (o) { return !o; });
|
|
29
|
+
}
|
|
30
|
+
// Escape clears the search and closes. The field handles it before the Popover's own Escape, which only closes.
|
|
31
|
+
// Enter closes and keeps the filter. A click outside and Tab close and keep it too.
|
|
32
|
+
function keyDown(e) {
|
|
33
|
+
if (e.key === 'Escape') {
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
setQuery('');
|
|
36
|
+
setOpen(false);
|
|
37
|
+
}
|
|
38
|
+
else if (e.key === 'Enter') {
|
|
39
|
+
e.preventDefault();
|
|
40
|
+
setOpen(false);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// The field is closed, so 'Clear Search' clears the filter and focus goes to the search button.
|
|
44
|
+
function clearSearch() {
|
|
45
|
+
var _a;
|
|
46
|
+
setQuery('');
|
|
47
|
+
(_a = trigger.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
48
|
+
}
|
|
49
|
+
return (<Center width="page">
|
|
50
|
+
<Stack gap="large">
|
|
51
|
+
<Cluster gap="small">
|
|
52
|
+
<Heading level={1} size="h5">Invoices</Heading>
|
|
53
|
+
{/* A search that is on shows in a filled button and says what it is looking for. */}
|
|
54
|
+
<Tooltip title={on ? "Search: ".concat(words) : 'Search'}>
|
|
55
|
+
<IconButton ref={trigger} color={on ? 'secondary' : 'iconOnly'} state={open ? 'selected' : 'enabled'} size="small" iconName="Search" ariaLabel={on ? "Search: ".concat(words) : 'Search'} aria-haspopup="dialog" aria-expanded={open} onClick={function (e) { return toggle(e.currentTarget); }}/>
|
|
56
|
+
</Tooltip>
|
|
57
|
+
</Cluster>
|
|
58
|
+
<Paragraph tone="secondary" size="body2" measure="none">
|
|
59
|
+
{on ? "".concat(found.length, " of ").concat(invoices.length, " invoices match \"").concat(words, "\".") : "All ".concat(invoices.length, " invoices.")}
|
|
60
|
+
</Paragraph>
|
|
61
|
+
{found.length > 0 ? (<Surface>
|
|
62
|
+
<List items={found} size="body1"/>
|
|
63
|
+
</Surface>) : (<Surface align="center" minHeight="short">
|
|
64
|
+
<EmptyBox size="large" icon="Search" text={"No invoices match \"".concat(words, "\"")} secondText="Check the spelling, or search for fewer words." action={<Button size="medium" type="secondary" state="enabled" label="Clear Search" onClickButton={clearSearch}/>}/>
|
|
65
|
+
</Surface>)}
|
|
66
|
+
</Stack>
|
|
67
|
+
<Popover open={open} anchorEl={anchor} onClose={function () { return setOpen(false); }} returnFocus>
|
|
68
|
+
{/* Menu gives the Popover its surface and a width. It holds a field here, not items. */}
|
|
69
|
+
<Menu width={288}>
|
|
70
|
+
<TextField id="collapsible-search-query" type="search" size="small" autoFocus aria-label="Search invoices" placeholder="Search invoices" value={query} onChange={function (e) { return setQuery(e.target.value); }} onKeyDown={keyDown}/>
|
|
71
|
+
</Menu>
|
|
72
|
+
</Popover>
|
|
73
|
+
</Center>);
|
|
74
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Collapsible search
|
|
2
|
+
|
|
3
|
+
A person filters a list by a word, and the list should keep its room when they are not typing.
|
|
4
|
+
|
|
5
|
+
## Do
|
|
6
|
+
|
|
7
|
+
- Use an `IconButton` with `iconName="Search"` beside the list's heading, and open a `<Popover returnFocus>` with a search `TextField` from it.
|
|
8
|
+
- Keep the words in the page, not in the Popover. The list stays filtered while the Popover is closed.
|
|
9
|
+
- Show that a search is on: `color="secondary"` on the button, and a line such as '2 of 5 invoices match "north".'.
|
|
10
|
+
- Say the current search in the button's `ariaLabel`: 'Search: north'. It is plain 'Search' when no search is on.
|
|
11
|
+
- Set `aria-haspopup="dialog"` and `aria-expanded` on the button, and `state="selected"` while the Popover is open.
|
|
12
|
+
- Focus the field with `autoFocus` when the Popover opens, and name it with `aria-label`, such as `aria-label="Search invoices"`.
|
|
13
|
+
- Clear the search and close the Popover on Escape. Focus goes back to the button.
|
|
14
|
+
- Keep the search when the Popover closes any other way: Enter, a click outside, or Tab.
|
|
15
|
+
- Follow the case 'Empty search' when nothing matches. Its 'Clear Search' Button clears the filter. Focus goes to the search button, not the field, because the field is in the closed Popover.
|
|
16
|
+
|
|
17
|
+
## Don't
|
|
18
|
+
|
|
19
|
+
- Do not clear the search when the Popover closes, except with Escape.
|
|
20
|
+
- Do not name the button 'Search' while a search is on. Its name says what is searched for.
|
|
21
|
+
- Do not show the filter only in color. The line under the heading says it too.
|
|
22
|
+
- Do not open the Popover when the page loads.
|
|
23
|
+
|
|
24
|
+
## Example: Search button with a Popover
|
|
25
|
+
|
|
26
|
+
Uses: `Button`, `Center`, `Cluster`, `EmptyBox`, `Heading`, `IconButton`, `List`, `Menu`, `Paragraph`, `Popover`, `Stack`, `Surface`, `TextField`, `Tooltip`
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
'use client';
|
|
30
|
+
import { useRef, useState } from 'react';
|
|
31
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
32
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
33
|
+
import TextField from 'oneslash-design-system/components/textField';
|
|
34
|
+
import IconButton from 'oneslash-design-system/components/iconButton';
|
|
35
|
+
import Button from 'oneslash-design-system/components/button';
|
|
36
|
+
import Tooltip from 'oneslash-design-system/components/tooltip';
|
|
37
|
+
import Popover from 'oneslash-design-system/components/popover';
|
|
38
|
+
import Menu from 'oneslash-design-system/components/menu';
|
|
39
|
+
import List from 'oneslash-design-system/components/list';
|
|
40
|
+
import Surface from 'oneslash-design-system/components/surface';
|
|
41
|
+
import EmptyBox from 'oneslash-design-system/components/emptyBox';
|
|
42
|
+
import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
|
|
43
|
+
|
|
44
|
+
// A real app reads these from the server.
|
|
45
|
+
const invoices = ['Northwind, March', 'Harbor Studio, March', 'Lumen Labs, February', 'Northstar Dental, February', 'Pine and Co, January'];
|
|
46
|
+
|
|
47
|
+
export default function CollapsibleSearchPopover() {
|
|
48
|
+
// The filter belongs to the page, not to the Popover: it stays when the Popover closes.
|
|
49
|
+
const [query, setQuery] = useState('north');
|
|
50
|
+
const [anchor, setAnchor] = useState<HTMLElement | null>(null);
|
|
51
|
+
const [open, setOpen] = useState(false);
|
|
52
|
+
const trigger = useRef<HTMLButtonElement | HTMLAnchorElement>(null);
|
|
53
|
+
const words = query.trim();
|
|
54
|
+
const on = words !== '';
|
|
55
|
+
const found = invoices.filter((name) => name.toLowerCase().includes(words.toLowerCase()));
|
|
56
|
+
|
|
57
|
+
function toggle(anchorEl: HTMLElement) {
|
|
58
|
+
setAnchor(anchorEl);
|
|
59
|
+
setOpen((o) => !o);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Escape clears the search and closes. The field handles it before the Popover's own Escape, which only closes.
|
|
63
|
+
// Enter closes and keeps the filter. A click outside and Tab close and keep it too.
|
|
64
|
+
function keyDown(e: { key: string; preventDefault(): void }) {
|
|
65
|
+
if (e.key === 'Escape') {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
setQuery('');
|
|
68
|
+
setOpen(false);
|
|
69
|
+
} else if (e.key === 'Enter') {
|
|
70
|
+
e.preventDefault();
|
|
71
|
+
setOpen(false);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// The field is closed, so 'Clear Search' clears the filter and focus goes to the search button.
|
|
76
|
+
function clearSearch() {
|
|
77
|
+
setQuery('');
|
|
78
|
+
trigger.current?.focus();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<Center width="page">
|
|
83
|
+
<Stack gap="large">
|
|
84
|
+
<Cluster gap="small">
|
|
85
|
+
<Heading level={1} size="h5">Invoices</Heading>
|
|
86
|
+
{/* A search that is on shows in a filled button and says what it is looking for. */}
|
|
87
|
+
<Tooltip title={on ? `Search: ${words}` : 'Search'}>
|
|
88
|
+
<IconButton
|
|
89
|
+
ref={trigger}
|
|
90
|
+
color={on ? 'secondary' : 'iconOnly'}
|
|
91
|
+
state={open ? 'selected' : 'enabled'}
|
|
92
|
+
size="small"
|
|
93
|
+
iconName="Search"
|
|
94
|
+
ariaLabel={on ? `Search: ${words}` : 'Search'}
|
|
95
|
+
aria-haspopup="dialog"
|
|
96
|
+
aria-expanded={open}
|
|
97
|
+
onClick={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}
|
|
98
|
+
/>
|
|
99
|
+
</Tooltip>
|
|
100
|
+
</Cluster>
|
|
101
|
+
<Paragraph tone="secondary" size="body2" measure="none">
|
|
102
|
+
{on ? `${found.length} of ${invoices.length} invoices match "${words}".` : `All ${invoices.length} invoices.`}
|
|
103
|
+
</Paragraph>
|
|
104
|
+
{found.length > 0 ? (
|
|
105
|
+
<Surface>
|
|
106
|
+
<List items={found} size="body1" />
|
|
107
|
+
</Surface>
|
|
108
|
+
) : (
|
|
109
|
+
<Surface align="center" minHeight="short">
|
|
110
|
+
<EmptyBox
|
|
111
|
+
size="large"
|
|
112
|
+
icon="Search"
|
|
113
|
+
text={`No invoices match "${words}"`}
|
|
114
|
+
secondText="Check the spelling, or search for fewer words."
|
|
115
|
+
action={<Button size="medium" type="secondary" state="enabled" label="Clear Search" onClickButton={clearSearch} />}
|
|
116
|
+
/>
|
|
117
|
+
</Surface>
|
|
118
|
+
)}
|
|
119
|
+
</Stack>
|
|
120
|
+
<Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>
|
|
121
|
+
{/* Menu gives the Popover its surface and a width. It holds a field here, not items. */}
|
|
122
|
+
<Menu width={288}>
|
|
123
|
+
<TextField
|
|
124
|
+
id="collapsible-search-query"
|
|
125
|
+
type="search"
|
|
126
|
+
size="small"
|
|
127
|
+
autoFocus
|
|
128
|
+
aria-label="Search invoices"
|
|
129
|
+
placeholder="Search invoices"
|
|
130
|
+
value={query}
|
|
131
|
+
onChange={(e) => setQuery(e.target.value)}
|
|
132
|
+
onKeyDown={keyDown}
|
|
133
|
+
/>
|
|
134
|
+
</Menu>
|
|
135
|
+
</Popover>
|
|
136
|
+
</Center>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Native
|
|
142
|
+
|
|
143
|
+
On Apple use `.searchable` on the list, which collapses into the toolbar and keeps its text. On Android use a `SearchBar` that expands from the app bar.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function ComposerLimitNoticeWithAction(): import("react").JSX.Element;
|