oneslash-design-system 2.17.0 → 2.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/DESIGN.md +55 -14
- package/dist/cases/accept-invite.md +1 -5
- package/dist/cases/account-menu/menu.d.ts +1 -0
- package/dist/cases/account-menu/menu.jsx +99 -0
- package/dist/cases/account-menu.md +164 -0
- package/dist/cases/agent-asks-before-risky-action.md +0 -4
- package/dist/cases/agent-cancels-when-unanswered.md +0 -4
- package/dist/cases/agent-options.md +0 -4
- package/dist/cases/agent-pending-reply.md +0 -4
- package/dist/cases/agent-plan-proposal.md +0 -4
- package/dist/cases/agent-question.md +0 -4
- package/dist/cases/agent-refuses-clearly.md +0 -4
- package/dist/cases/agent-says-what-it-is.md +0 -2
- package/dist/cases/agent-settings/form.d.ts +1 -0
- package/dist/cases/agent-settings/form.jsx +164 -0
- package/dist/cases/agent-settings.md +259 -0
- package/dist/cases/agent-shows-progress.md +0 -2
- package/dist/cases/agent-shows-sources.md +0 -2
- package/dist/cases/api-keys/list.d.ts +1 -0
- package/dist/cases/api-keys/list.jsx +162 -0
- package/dist/cases/api-keys.md +229 -0
- package/dist/cases/app-shell/sidebar.d.ts +1 -0
- package/dist/cases/app-shell/sidebar.jsx +124 -0
- package/dist/cases/app-shell/top-tabs.d.ts +1 -0
- package/dist/cases/app-shell/top-tabs.jsx +106 -0
- package/dist/cases/app-shell.md +364 -0
- package/dist/cases/artifact-card/card.jsx +32 -6
- package/dist/cases/artifact-card.md +55 -11
- package/dist/cases/auth-gate-loading.md +0 -4
- package/dist/cases/check-your-email.md +0 -4
- package/dist/cases/collapsible-search/popover.d.ts +1 -0
- package/dist/cases/collapsible-search/popover.jsx +74 -0
- package/dist/cases/collapsible-search.md +143 -0
- package/dist/cases/composer-limit.md +0 -4
- package/dist/cases/confirm-destructive-action.md +0 -4
- package/dist/cases/confirm-dialogs.md +0 -4
- package/dist/cases/conversation-starters.md +0 -4
- package/dist/cases/create-modal.md +0 -4
- package/dist/cases/danger-zone/collapsed.d.ts +1 -0
- package/dist/cases/danger-zone/collapsed.jsx +75 -0
- package/dist/cases/danger-zone/shown.d.ts +1 -0
- package/dist/cases/danger-zone/shown.jsx +95 -0
- package/dist/cases/danger-zone.md +263 -0
- package/dist/cases/device-login.md +0 -4
- package/dist/cases/email-confirmed.md +0 -4
- package/dist/cases/empty-list.md +0 -4
- package/dist/cases/empty-lists.md +0 -4
- package/dist/cases/empty-not-set-up.md +0 -4
- package/dist/cases/empty-search.md +0 -4
- package/dist/cases/error-page/in-shell.jsx +26 -17
- package/dist/cases/error-page.md +42 -25
- package/dist/cases/feedback-form.md +0 -4
- package/dist/cases/filter-menu/presets.d.ts +1 -0
- package/dist/cases/filter-menu/presets.jsx +53 -0
- package/dist/cases/filter-menu/with-clear.d.ts +1 -0
- package/dist/cases/filter-menu/with-clear.jsx +56 -0
- package/dist/cases/filter-menu.md +204 -0
- package/dist/cases/forgot-password.md +0 -4
- package/dist/cases/form-errors.md +0 -4
- package/dist/cases/import-checklist.md +0 -4
- package/dist/cases/inline-form-feedback.md +0 -4
- package/dist/cases/integrations-list/nested.d.ts +1 -0
- package/dist/cases/integrations-list/nested.jsx +164 -0
- package/dist/cases/integrations-list/rows.d.ts +1 -0
- package/dist/cases/integrations-list/rows.jsx +134 -0
- package/dist/cases/integrations-list.md +379 -0
- package/dist/cases/invite-member.md +0 -4
- package/dist/cases/load-failure.md +0 -4
- package/dist/cases/log-out-confirm.md +0 -4
- package/dist/cases/login-page.md +0 -4
- package/dist/cases/master-detail/list-then-page.d.ts +1 -0
- package/dist/cases/master-detail/list-then-page.jsx +65 -0
- package/dist/cases/master-detail/split.d.ts +1 -0
- package/dist/cases/master-detail/split.jsx +49 -0
- package/dist/cases/master-detail.md +213 -0
- package/dist/cases/members-list/rows.d.ts +1 -0
- package/dist/cases/members-list/rows.jsx +318 -0
- package/dist/cases/members-list/table.d.ts +1 -0
- package/dist/cases/members-list/table.jsx +351 -0
- package/dist/cases/members-list.md +799 -0
- package/dist/cases/mention-list.md +0 -4
- package/dist/cases/message-actions.md +0 -4
- package/dist/cases/message-attachments.md +0 -4
- package/dist/cases/message-composer.md +0 -4
- package/dist/cases/message-edit.md +0 -4
- package/dist/cases/message-reactions.md +0 -4
- package/dist/cases/message-row.md +0 -4
- package/dist/cases/mobile-menu/links.d.ts +1 -0
- package/dist/cases/mobile-menu/links.jsx +24 -0
- package/dist/cases/mobile-menu/sections.d.ts +1 -0
- package/dist/cases/mobile-menu/sections.jsx +61 -0
- package/dist/cases/mobile-menu.md +170 -0
- package/dist/cases/not-found-page/in-shell.jsx +26 -17
- package/dist/cases/not-found-page.md +41 -24
- package/dist/cases/notification-menu/menu.d.ts +1 -0
- package/dist/cases/notification-menu/menu.jsx +74 -0
- package/dist/cases/notification-menu.md +135 -0
- package/dist/cases/oauth-consent.md +0 -4
- package/dist/cases/on-off-settings/list.d.ts +1 -0
- package/dist/cases/on-off-settings/list.jsx +97 -0
- package/dist/cases/on-off-settings.md +116 -0
- package/dist/cases/on-this-page/aside.d.ts +1 -0
- package/dist/cases/on-this-page/aside.jsx +39 -0
- package/dist/cases/on-this-page.md +80 -0
- package/dist/cases/overflow-menu/in-a-header.d.ts +1 -0
- package/dist/cases/overflow-menu/in-a-header.jsx +128 -0
- package/dist/cases/overflow-menu/on-a-row.d.ts +1 -0
- package/dist/cases/overflow-menu/on-a-row.jsx +183 -0
- package/dist/cases/overflow-menu.md +410 -0
- package/dist/cases/page-header/actions.d.ts +1 -0
- package/dist/cases/page-header/actions.jsx +65 -0
- package/dist/cases/page-header/sub-page.d.ts +1 -0
- package/dist/cases/page-header/sub-page.jsx +37 -0
- package/dist/cases/page-header.md +195 -0
- package/dist/cases/phone-navigation.md +32 -0
- package/dist/cases/profile-form/form.d.ts +1 -0
- package/dist/cases/profile-form/form.jsx +153 -0
- package/dist/cases/profile-form.md +236 -0
- package/dist/cases/quick-switcher/modal.d.ts +1 -0
- package/dist/cases/quick-switcher/modal.jsx +114 -0
- package/dist/cases/quick-switcher.md +205 -0
- package/dist/cases/range-switch/segmented.d.ts +1 -0
- package/dist/cases/range-switch/segmented.jsx +30 -0
- package/dist/cases/range-switch.md +67 -0
- package/dist/cases/rename.md +0 -4
- package/dist/cases/reply-feedback.md +0 -4
- package/dist/cases/reply-sources.md +0 -4
- package/dist/cases/route-loading/region.jsx +27 -18
- package/dist/cases/route-loading.md +42 -23
- package/dist/cases/scope-picker/menu.d.ts +1 -0
- package/dist/cases/scope-picker/menu.jsx +47 -0
- package/dist/cases/scope-picker.md +97 -0
- package/dist/cases/set-new-password.md +0 -4
- package/dist/cases/settings-page/side-nav.d.ts +1 -0
- package/dist/cases/settings-page/side-nav.jsx +171 -0
- package/dist/cases/settings-page/top-tabs.d.ts +1 -0
- package/dist/cases/settings-page/top-tabs.jsx +129 -0
- package/dist/cases/settings-page.md +378 -0
- package/dist/cases/settings-save.md +35 -0
- package/dist/cases/side-pane/beside.d.ts +1 -0
- package/dist/cases/side-pane/beside.jsx +79 -0
- package/dist/cases/side-pane/over.d.ts +1 -0
- package/dist/cases/side-pane/over.jsx +58 -0
- package/dist/cases/side-pane.md +238 -0
- package/dist/cases/sidebar-nav/flat.d.ts +1 -0
- package/dist/cases/sidebar-nav/flat.jsx +81 -0
- package/dist/cases/sidebar-nav/nested.d.ts +1 -0
- package/dist/cases/sidebar-nav/nested.jsx +122 -0
- package/dist/cases/sidebar-nav.md +261 -0
- package/dist/cases/sign-up-page.md +1 -5
- package/dist/cases/site-footer/columns.d.ts +1 -0
- package/dist/cases/site-footer/columns.jsx +51 -0
- package/dist/cases/site-footer/simple.d.ts +1 -0
- package/dist/cases/site-footer/simple.jsx +24 -0
- package/dist/cases/site-footer.md +133 -0
- package/dist/cases/site-header/links.d.ts +1 -0
- package/dist/cases/site-header/links.jsx +26 -0
- package/dist/cases/site-header/sections.d.ts +1 -0
- package/dist/cases/site-header/sections.jsx +64 -0
- package/dist/cases/site-header.md +183 -0
- package/dist/cases/slash-command-list.md +0 -4
- package/dist/cases/success-feedback.md +0 -4
- package/dist/cases/tag-filter/tags.d.ts +1 -0
- package/dist/cases/tag-filter/tags.jsx +226 -0
- package/dist/cases/tag-filter.md +298 -0
- package/dist/cases/theme-switcher/menu.d.ts +1 -0
- package/dist/cases/theme-switcher/menu.jsx +47 -0
- package/dist/cases/theme-switcher/segmented.d.ts +1 -0
- package/dist/cases/theme-switcher/segmented.jsx +26 -0
- package/dist/cases/theme-switcher.md +149 -0
- package/dist/cases/type-to-confirm.md +0 -4
- package/dist/cases/typing-and-status.md +0 -4
- package/dist/cases/unsaved-changes-guard.md +0 -4
- package/dist/cases/upgrade-prompt.md +0 -4
- package/dist/cases.json +1737 -315
- package/dist/components/alert.d.ts +3 -1
- package/dist/components/alert.jsx +2 -2
- package/dist/components/appShell.d.ts +44 -0
- package/dist/components/appShell.jsx +121 -0
- package/dist/components/button.jsx +5 -2
- package/dist/components/checkBox.d.ts +5 -1
- package/dist/components/checkBox.jsx +2 -2
- package/dist/components/copyField.d.ts +20 -0
- package/dist/components/copyField.jsx +99 -0
- package/dist/components/drawer.d.ts +31 -0
- package/dist/components/drawer.jsx +121 -0
- package/dist/components/formField.d.ts +34 -0
- package/dist/components/formField.jsx +28 -0
- package/dist/components/heading.d.ts +5 -1
- package/dist/components/heading.jsx +2 -2
- package/dist/components/link.d.ts +6 -1
- package/dist/components/link.jsx +11 -3
- package/dist/components/menu.jsx +2 -2
- package/dist/components/menuItem.d.ts +10 -2
- package/dist/components/menuItem.jsx +4 -3
- package/dist/components/modal.jsx +12 -23
- package/dist/components/navigation.d.ts +9 -1
- package/dist/components/navigation.jsx +15 -3
- package/dist/components/onThisPage.d.ts +29 -0
- package/dist/components/onThisPage.jsx +151 -0
- package/dist/components/pageShell.d.ts +7 -1
- package/dist/components/pageShell.jsx +14 -1
- package/dist/components/popover.jsx +4 -0
- package/dist/components/radioGroup.d.ts +5 -1
- package/dist/components/radioGroup.jsx +2 -2
- package/dist/components/segmentedControl.d.ts +22 -0
- package/dist/components/segmentedControl.jsx +54 -0
- package/dist/components/select.d.ts +5 -1
- package/dist/components/select.jsx +2 -2
- package/dist/components/settingsSection.d.ts +36 -0
- package/dist/components/settingsSection.jsx +65 -0
- package/dist/components/sidePane.d.ts +32 -0
- package/dist/components/sidePane.jsx +128 -0
- package/dist/components/siteFooter.d.ts +24 -0
- package/dist/components/siteFooter.jsx +48 -0
- package/dist/components/siteHeader.d.ts +55 -0
- package/dist/components/siteHeader.jsx +125 -0
- package/dist/components/slidingIndicator.d.ts +50 -0
- package/dist/components/slidingIndicator.jsx +102 -0
- package/dist/components/switch.d.ts +25 -0
- package/dist/components/switch.jsx +55 -0
- package/dist/components/tab.jsx +5 -11
- package/dist/components/tabsContainer.jsx +5 -67
- package/dist/components/textField.d.ts +12 -2
- package/dist/components/textField.jsx +11 -4
- package/dist/components/textarea.d.ts +5 -1
- package/dist/components/textarea.jsx +3 -3
- package/dist/components/titleBar.d.ts +17 -0
- package/dist/components/titleBar.jsx +17 -0
- package/dist/components/useHotkey.d.ts +7 -0
- package/dist/components/useHotkey.js +24 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/internal/copyField.d.ts +5 -0
- package/dist/internal/copyField.js +61 -0
- package/dist/internal/hotkey.d.ts +16 -0
- package/dist/internal/hotkey.js +20 -0
- package/dist/internal/overlayStack.d.ts +24 -0
- package/dist/internal/overlayStack.js +71 -0
- package/dist/internal/resize.d.ts +9 -0
- package/dist/internal/resize.js +31 -0
- package/dist/internal/scrollSpy.d.ts +24 -0
- package/dist/internal/scrollSpy.js +53 -0
- package/dist/internal/siteBrand.d.ts +6 -0
- package/dist/internal/siteBrand.jsx +11 -0
- package/dist/internal/switch.d.ts +5 -0
- package/dist/internal/switch.js +9 -0
- package/dist/native-mapping.json +72 -0
- package/dist/stories/AppShell.stories.d.ts +15 -0
- package/dist/stories/AppShell.stories.jsx +137 -0
- package/dist/stories/Cases.generated.stories.d.ts +42 -0
- package/dist/stories/Cases.generated.stories.jsx +84 -0
- package/dist/stories/CopyField.stories.d.ts +11 -0
- package/dist/stories/CopyField.stories.jsx +65 -0
- package/dist/stories/Drawer.stories.d.ts +10 -0
- package/dist/stories/Drawer.stories.jsx +123 -0
- package/dist/stories/FormField.stories.d.ts +6 -0
- package/dist/stories/FormField.stories.jsx +44 -0
- package/dist/stories/Link.stories.d.ts +1 -0
- package/dist/stories/Link.stories.jsx +8 -0
- package/dist/stories/Navigation.stories.d.ts +1 -0
- package/dist/stories/Navigation.stories.jsx +17 -1
- package/dist/stories/OnThisPage.stories.d.ts +10 -0
- package/dist/stories/OnThisPage.stories.jsx +105 -0
- package/dist/stories/SegmentedControl.stories.d.ts +8 -0
- package/dist/stories/SegmentedControl.stories.jsx +33 -0
- package/dist/stories/SettingsSection.stories.d.ts +12 -0
- package/dist/stories/SettingsSection.stories.jsx +91 -0
- package/dist/stories/SidePane.stories.d.ts +6 -0
- package/dist/stories/SidePane.stories.jsx +37 -0
- package/dist/stories/SiteFooter.stories.d.ts +7 -0
- package/dist/stories/SiteFooter.stories.jsx +63 -0
- package/dist/stories/SiteHeader.stories.d.ts +10 -0
- package/dist/stories/SiteHeader.stories.jsx +94 -0
- package/dist/stories/Switch.stories.d.ts +14 -0
- package/dist/stories/Switch.stories.jsx +87 -0
- package/dist/stories/TextField.stories.d.ts +1 -0
- package/dist/stories/TextField.stories.jsx +13 -0
- package/dist/stories/TitleBar.stories.d.ts +6 -0
- package/dist/stories/TitleBar.stories.jsx +34 -0
- package/package.json +5 -1
package/dist/cases.json
CHANGED
|
@@ -27,11 +27,7 @@
|
|
|
27
27
|
"Do not show the login form before the invite is checked.",
|
|
28
28
|
"Do not remember the invite before the person chooses to log in or sign up, so an old link does not take over a later login."
|
|
29
29
|
],
|
|
30
|
-
"native": "On Apple,
|
|
31
|
-
"notBuiltYet": "Scindo on the web labels its Buttons 'Log in' and 'Create account' in sentence case, and shows 'Please wait' under its spinner. Its wrong-account Button reads 'Sign out and switch accounts'.",
|
|
32
|
-
"seenIn": [
|
|
33
|
-
"Scindo"
|
|
34
|
-
],
|
|
30
|
+
"native": "On Apple, joining works from a sheet with the invite link or code in a field. 'Cancel' and 'Join' sit in the toolbar. While it checks the invite, a small `ProgressView` sits beside a line naming the step.",
|
|
35
31
|
"options": [
|
|
36
32
|
{
|
|
37
33
|
"id": "signed-out",
|
|
@@ -68,6 +64,54 @@
|
|
|
68
64
|
}
|
|
69
65
|
]
|
|
70
66
|
},
|
|
67
|
+
{
|
|
68
|
+
"id": "account-menu",
|
|
69
|
+
"title": "Account menu",
|
|
70
|
+
"kind": "design",
|
|
71
|
+
"level": "organism",
|
|
72
|
+
"area": "menu",
|
|
73
|
+
"situation": "A person opens a menu for their own account to change settings, get help or log out.",
|
|
74
|
+
"do": [
|
|
75
|
+
"Use a small tertiary `Button` whose label is the person's name, with their `UserImage` as `decoIcon`: `decoIcon={<UserImage userHandle={name} size={20} decorative />}`.",
|
|
76
|
+
"Make the avatar `decorative`. It sits beside the same name, so a screen reader reads the name once.",
|
|
77
|
+
"Give the Button an `aria-label` that starts with the visible name: 'Dana Lee, account menu'.",
|
|
78
|
+
"Set `aria-haspopup=\"menu\"` and `aria-expanded` on the Button, and `state=\"selected\"` while the menu is open.",
|
|
79
|
+
"Open `<Popover returnFocus>` around `<Menu navigable aria-label=\"Account\">` with 'Settings' and 'Help', then a `Line`, then 'Log Out' last.",
|
|
80
|
+
"Use `onClick` items. A navigable menu's arrow keys skip an item with `href`.",
|
|
81
|
+
"Leave 'Log Out' a plain item. It destroys nothing.",
|
|
82
|
+
"Confirm 'Log Out' as the case 'Log-out confirm' says, in a small Modal. 'Cancel' puts focus back on the Button."
|
|
83
|
+
],
|
|
84
|
+
"dont": [
|
|
85
|
+
"Do not show only the avatar as the trigger when the name fits. The name says whose account it is.",
|
|
86
|
+
"Do not give the avatar its own name beside the same name.",
|
|
87
|
+
"Do not use 'Sign Out'. The words are 'Log In' and 'Log Out'.",
|
|
88
|
+
"Do not give 'Log Out' `color=\"danger\"`.",
|
|
89
|
+
"Do not open the menu when the page loads."
|
|
90
|
+
],
|
|
91
|
+
"native": "On Apple use a toolbar `Menu` with a `Label` of the person's name, or the sidebar's account row. Put 'Log Out' last, and leave out the `.destructive` role. On Android use an avatar `IconButton` with a `DropdownMenu`.",
|
|
92
|
+
"options": [
|
|
93
|
+
{
|
|
94
|
+
"id": "menu",
|
|
95
|
+
"title": "Avatar and name with a menu",
|
|
96
|
+
"useWhen": "The product has an account, and its header or sidebar has room for a name.",
|
|
97
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\nexport default function AccountMenuExample() {\n const [view, setView] = useState('Home');\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [loggingOut, setLoggingOut] = useState(false);\n const [loggedOut, setLoggedOut] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const trigger = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n function toggle(anchorEl: HTMLElement) {\n setAnchor(anchorEl);\n setOpen((o) => !o);\n }\n\n // The menu closes on any choice. Its Popover gives focus back to the trigger.\n function go(next: string) {\n setOpen(false);\n setView(next);\n }\n\n // The confirm is the one in the case 'Log-out confirm'. Its Modal opens while the menu fades, so the Modal cannot\n // take focus back from the menu item: 'Cancel' sends it to the trigger.\n function askToLogOut() {\n setOpen(false);\n setConfirming(true);\n }\n\n function cancel() {\n if (loggingOut) return;\n setConfirming(false);\n focusNext.current = () => trigger.current?.focus();\n }\n\n function logOut() {\n if (loggingOut) return;\n setLoggingOut(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoggingOut(false);\n setConfirming(false);\n setLoggedOut(true);\n }, 1200);\n }\n\n // A real app goes to its login page here. The example shows a short logged-out page instead.\n if (loggedOut) {\n return (\n <Center fill>\n <Heading level={1} size=\"h5\">You are logged out</Heading>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" onClickButton={() => { setLoggedOut(false); setView('Home'); }} />\n </Cluster>\n </Center>\n );\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Acme</Heading>\n {/* The avatar and the name are the trigger. The avatar sits beside the same name, so it is not read aloud. */}\n <Button\n ref={trigger}\n size=\"small\"\n type=\"tertiary\"\n state={open ? 'selected' : 'enabled'}\n label={me}\n decoIcon={<UserImage userHandle={me} size={20} decorative />}\n aria-label={`${me}, account menu`}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n onClickButton={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}\n />\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{view === 'Home' ? 'Logged in as dana@example.com.' : `You opened ${view}.`}</Paragraph>\n </Stack>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Account\" width={200}>\n <MenuItem size=\"small\" iconName=\"Settings\" label=\"Settings\" onClick={() => go('Settings')} />\n <MenuItem size=\"small\" iconName=\"CircleHelp\" label=\"Help\" onClick={() => go('Help')} />\n <Line />\n {/* Log Out is last. It destroys nothing, so it is a plain item, not a danger one. */}\n <MenuItem size=\"small\" iconName=\"LogOut\" label=\"Log Out\" onClick={askToLogOut} />\n </Menu>\n </Popover>\n <Modal\n isOpen={confirming}\n size=\"small\"\n title=\"Log Out\"\n onClose={cancel}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={loggingOut ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={cancel} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Log Out\" loading={loggingOut} onClickButton={logOut} />\n </>\n }\n >\n <Paragraph measure=\"none\">You will need to log in again to use Acme on this device.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
|
|
98
|
+
"uses": [
|
|
99
|
+
"Button",
|
|
100
|
+
"Center",
|
|
101
|
+
"Cluster",
|
|
102
|
+
"Heading",
|
|
103
|
+
"Line",
|
|
104
|
+
"Menu",
|
|
105
|
+
"MenuItem",
|
|
106
|
+
"Modal",
|
|
107
|
+
"Paragraph",
|
|
108
|
+
"Popover",
|
|
109
|
+
"Stack",
|
|
110
|
+
"UserImage"
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
},
|
|
71
115
|
{
|
|
72
116
|
"id": "agent-asks-before-risky-action",
|
|
73
117
|
"title": "An agent asks before a risky action",
|
|
@@ -88,10 +132,6 @@
|
|
|
88
132
|
"Do not replace the steps or the changes with a one-line summary.",
|
|
89
133
|
"Do not let the agent write the label of an approve or merge button.",
|
|
90
134
|
"Do not let a second click on a decided card approve or cancel it again."
|
|
91
|
-
],
|
|
92
|
-
"notBuiltYet": "In Scindo the agent asks before carrying out a plan, opening a pull request and merging one. It does not yet ask before deleting files, closing an issue or rolling back a release.",
|
|
93
|
-
"seenIn": [
|
|
94
|
-
"Scindo"
|
|
95
135
|
]
|
|
96
136
|
},
|
|
97
137
|
{
|
|
@@ -112,10 +152,6 @@
|
|
|
112
152
|
"dont": [
|
|
113
153
|
"Do not treat no answer as approval.",
|
|
114
154
|
"Do not cancel a request without saying so in the thread."
|
|
115
|
-
],
|
|
116
|
-
"notBuiltYet": "No product cancels a waiting request on its own yet. In Scindo a request waits until a person answers, cancels or skips it, and the waiting time is not decided.",
|
|
117
|
-
"seenIn": [
|
|
118
|
-
"Scindo"
|
|
119
155
|
]
|
|
120
156
|
},
|
|
121
157
|
{
|
|
@@ -151,10 +187,6 @@
|
|
|
151
187
|
"Do not act on an option before the person presses Choose.",
|
|
152
188
|
"Do not change a Button's label while it is loading, such as to 'Confirming...'."
|
|
153
189
|
],
|
|
154
|
-
"notBuiltYet": "Scindo's options card labels its button 'Confirm Selection', which reads 'Confirming...' while it loads, and marks a decided card 'Selected'. With no recommended option it preselects the first one. Scindo's Apple app shows no options card.",
|
|
155
|
-
"seenIn": [
|
|
156
|
-
"Scindo"
|
|
157
|
-
],
|
|
158
190
|
"options": [
|
|
159
191
|
{
|
|
160
192
|
"id": "cards",
|
|
@@ -209,10 +241,6 @@
|
|
|
209
241
|
"Do not say the agent stopped before the run has really ended.",
|
|
210
242
|
"Do not report a failed run only in a toast away from the row."
|
|
211
243
|
],
|
|
212
|
-
"notBuiltYet": "Scindo on the web shows no 'Agent' tag on the progress row, its Stop is an icon button with a cross, and its current step is a blinking dot. Scindo's Apple app shows no progress row: while the agent works, Send turns into Stop.",
|
|
213
|
-
"seenIn": [
|
|
214
|
-
"Scindo"
|
|
215
|
-
],
|
|
216
244
|
"options": [
|
|
217
245
|
{
|
|
218
246
|
"id": "steps",
|
|
@@ -300,10 +328,6 @@
|
|
|
300
328
|
"Do not treat no answer as approval.",
|
|
301
329
|
"Do not show the run's steps as running on the card. The run has its own row."
|
|
302
330
|
],
|
|
303
|
-
"notBuiltYet": "Scindo's plan button reads 'Proceed' and comes first, and its buttons change label while loading, such as 'Proceeding...' and 'Cancelling...'. Its plan card has no View Changes button and shows no waiting time. Scindo's Apple app shows no plan card.",
|
|
304
|
-
"seenIn": [
|
|
305
|
-
"Scindo"
|
|
306
|
-
],
|
|
307
331
|
"options": [
|
|
308
332
|
{
|
|
309
333
|
"id": "steps",
|
|
@@ -386,10 +410,6 @@
|
|
|
386
410
|
"Do not hide 'Skip'.",
|
|
387
411
|
"Do not change a Button's label while it is loading, such as to 'Submitting...'."
|
|
388
412
|
],
|
|
389
|
-
"notBuiltYet": "A waiting question in Scindo never times out: it stays open until someone answers or skips it. Its answer button reads 'Submit', and its buttons read 'Submitting...' and 'Skipping...' while they load. With no recommended answer it preselects the first one. Scindo's Apple app shows no question card.",
|
|
390
|
-
"seenIn": [
|
|
391
|
-
"Scindo"
|
|
392
|
-
],
|
|
393
413
|
"options": [
|
|
394
414
|
{
|
|
395
415
|
"id": "choices",
|
|
@@ -452,11 +472,7 @@
|
|
|
452
472
|
"Do not show a general error message for a refusal.",
|
|
453
473
|
"Do not show an Upgrade button to someone who cannot upgrade."
|
|
454
474
|
],
|
|
455
|
-
"native": "On Apple the refusal is a row above the composer, with an Upgrade or Change Budget Cap button for admins and never a link to a web page."
|
|
456
|
-
"notBuiltYet": "Scindo on the web does not follow this yet: it shows the Upgrade button to everyone. Scindo's Apple app shows it only to admins.",
|
|
457
|
-
"seenIn": [
|
|
458
|
-
"Scindo"
|
|
459
|
-
]
|
|
475
|
+
"native": "On Apple the refusal is a row above the composer, with an Upgrade or Change Budget Cap button for admins and never a link to a web page."
|
|
460
476
|
},
|
|
461
477
|
{
|
|
462
478
|
"id": "agent-says-what-it-is",
|
|
@@ -477,9 +493,56 @@
|
|
|
477
493
|
"Do not show a photo for an agent, even when one is set.",
|
|
478
494
|
"Do not show the product's logo on an agent the product does not run."
|
|
479
495
|
],
|
|
480
|
-
"native": "On Apple an 'Agent' label with a sparkles icon sits next to a named agent's name, and the app draws the agent's avatar itself."
|
|
481
|
-
|
|
482
|
-
|
|
496
|
+
"native": "On Apple an 'Agent' label with a sparkles icon sits next to a named agent's name, and the app draws the agent's avatar itself."
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
"id": "agent-settings",
|
|
500
|
+
"title": "Agent settings",
|
|
501
|
+
"kind": "design",
|
|
502
|
+
"level": "organism",
|
|
503
|
+
"area": "settings",
|
|
504
|
+
"situation": "An admin sets which model the agent uses, how it picks one, what it should know about the team and how much it may spend.",
|
|
505
|
+
"do": [
|
|
506
|
+
"Follow the rule 'A setting saves in place, or with one Save Button'. Keep the choices and the two groups of fields in their own `SettingsSection`s.",
|
|
507
|
+
"Show the provider as `<RadioGroup variant=\"card\">`, with the models in the `secondLabel`. It saves as soon as the person chooses.",
|
|
508
|
+
"Disable the group while it saves and show nothing when it works. When the save fails, put the old choice back and say why under it: 'Could not save. Try again.'",
|
|
509
|
+
"Show the routing as a `RadioGroup` too. Each choice needs a line that says what it does, such as 'Use cheaper models when they can do the job.' A `SegmentedControl` fits two to four short choices that need no line.",
|
|
510
|
+
"Wrap each field in a `FormField` and pass `id` and `aria-describedby` to the control, and `aria-invalid` to a `TextField` or `Textarea`. Give a `RadioGroup` an `aria-label` that starts with the visible label: 'AI provider'.",
|
|
511
|
+
"Put the instructions in a `Textarea` inside a `Form` with one Save Button. Say the limit in the help line, and show a problem with it under the field.",
|
|
512
|
+
"Put the budget cap in a `TextField type=\"number\"` inside its own `Form` with one Save Button. Say what happens at the cap and when it resets.",
|
|
513
|
+
"Keep each Save Button `state=\"disabled\"` while nothing has changed. It shows `loading`, keeps its label, then reads 'Saved' for 2 seconds. Name each one with an `aria-label`: 'Save instructions' and 'Save budget'.",
|
|
514
|
+
"Show everything read-only to a person who is not an admin, with one line at the top: 'Only admins can change this.' Remove the Save Buttons."
|
|
515
|
+
],
|
|
516
|
+
"dont": [
|
|
517
|
+
"Do not mix a choice that saves on change and a Save Button in one section.",
|
|
518
|
+
"Do not label the Button 'Saving…'. It keeps its label.",
|
|
519
|
+
"Do not show a toast or a green caption when a setting saves. The control shows the new value, and the Button says Saved.",
|
|
520
|
+
"Do not hide a choice from a person who cannot change it with `pointer-events-none`. Show it disabled, with the line.",
|
|
521
|
+
"Do not use a `Select` for three choices that need a line each. Show them all in a `RadioGroup`.",
|
|
522
|
+
"Do not show a failed save as red text written by hand. Use the error line of `FormField`."
|
|
523
|
+
],
|
|
524
|
+
"native": "On Apple use a grouped `Form` with a `Picker` for the provider and the routing. Use a `TextEditor` for the instructions and a `TextField` for the cap, each with one Save Button.",
|
|
525
|
+
"options": [
|
|
526
|
+
{
|
|
527
|
+
"id": "form",
|
|
528
|
+
"title": "Choices that save, and two groups with a Save Button",
|
|
529
|
+
"useWhen": "An admin sets the agent once for the whole workspace.",
|
|
530
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport RadioGroup from 'oneslash-design-system/components/radioGroup';\nimport Textarea from 'oneslash-design-system/components/textarea';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads this from the person's role. Only an admin can change the agent.\nconst canChange = true;\n\nconst providerOptions = [\n { value: 'anthropic', label: 'Anthropic', secondLabel: 'Claude Sonnet, Opus and Haiku' },\n { value: 'openai', label: 'OpenAI', secondLabel: 'GPT-4o and GPT-4.1' },\n { value: 'google', label: 'Google Gemini', secondLabel: 'Gemini Pro and Flash' },\n];\n\n// Each choice needs a line that says what it does, so this is a RadioGroup and not a SegmentedControl.\nconst routingOptions = [\n { value: 'auto', label: 'Auto', secondLabel: 'The best model for each request. The default.' },\n { value: 'cost', label: 'Lower cost', secondLabel: 'Use cheaper models when they can do the job.' },\n { value: 'quality', label: 'Higher quality', secondLabel: 'Use the most capable model for every request.' },\n];\n\nconst maxInstructions = 1000;\nconst failedMessage = 'Could not save. Try again.';\n\nexport default function AgentSettingsForm() {\n const [provider, setProvider] = useState('anthropic');\n const [providerError, setProviderError] = useState('');\n const [savingProvider, setSavingProvider] = useState(false);\n\n const [routing, setRouting] = useState('auto');\n const [routingError, setRoutingError] = useState('');\n const [savingRouting, setSavingRouting] = useState(false);\n\n const [savedInstructions, setSavedInstructions] = useState('Answer in short sentences. Link the task when you mention one.');\n const [instructions, setInstructions] = useState('Answer in short sentences. Link the task when you mention one.');\n const [instructionsError, setInstructionsError] = useState('');\n const [savingInstructions, setSavingInstructions] = useState(false);\n const [instructionsSaved, setInstructionsSaved] = useState(false);\n\n const [savedBudget, setSavedBudget] = useState('200');\n const [budget, setBudget] = useState('200');\n const [budgetError, setBudgetError] = useState('');\n const [savingBudget, setSavingBudget] = useState(false);\n const [budgetSaved, setBudgetSaved] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // One 'Saved' timer per group, cleared before a new one starts, so an old one cannot end a new 'Saved' early.\n const instructionsSavedTimer = useRef<ReturnType<typeof setTimeout>>();\n const budgetSavedTimer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops every request and every 'Saved' if the example goes away before they end.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n clearTimeout(instructionsSavedTimer.current);\n clearTimeout(budgetSavedTimer.current);\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // A choice stands alone, so it saves as soon as it is made. Nothing shows when it works.\n // While the request runs the group is disabled. When it fails, the old choice comes back and a line says why.\n function handleProvider(next: string) {\n if (savingProvider || next === provider) return;\n const before = provider;\n setProviderError('');\n setProvider(next);\n setSavingProvider(true);\n later(() => {\n setSavingProvider(false);\n // Stands in for a connection that is down: Google Gemini never saves.\n if (next === 'google') {\n setProvider(before);\n setProviderError(failedMessage);\n }\n }, 900);\n }\n\n function handleRouting(next: string) {\n if (savingRouting || next === routing) return;\n setRoutingError('');\n setRouting(next);\n setSavingRouting(true);\n later(() => setSavingRouting(false), 900);\n }\n\n // Instructions are a group with one Save Button: 'Saved' shows for 2 seconds, and the Button is disabled while nothing changed.\n function handleSaveInstructions() {\n if (savingInstructions) return;\n if (instructions.length > maxInstructions) {\n setInstructionsError(`Use up to ${maxInstructions.toLocaleString('en-US')} characters.`);\n return;\n }\n setInstructionsError('');\n setSavingInstructions(true);\n later(() => {\n setSavedInstructions(instructions);\n setSavingInstructions(false);\n setInstructionsSaved(true);\n clearTimeout(instructionsSavedTimer.current);\n instructionsSavedTimer.current = setTimeout(() => setInstructionsSaved(false), 2000);\n }, 1200);\n }\n\n function handleSaveBudget() {\n if (savingBudget) return;\n if (!/^\\d+$/.test(budget.trim())) {\n setBudgetError('Enter a whole number of dollars, like 200.');\n return;\n }\n setBudgetError('');\n setSavingBudget(true);\n later(() => {\n setSavedBudget(budget.trim());\n setBudget(budget.trim());\n setSavingBudget(false);\n setBudgetSaved(true);\n clearTimeout(budgetSavedTimer.current);\n budgetSavedTimer.current = setTimeout(() => setBudgetSaved(false), 2000);\n }, 1200);\n }\n\n const instructionsChanged = instructions !== savedInstructions;\n const budgetChanged = budget.trim() !== savedBudget;\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Heading level={1} size=\"h5\">Agent</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">How the Acme agent works for everyone in this workspace.</Paragraph>\n {!canChange && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change this.</Paragraph>}\n </Stack>\n\n {/* Both choices save as soon as they change, so this section has no Save Button. */}\n <SettingsSection title=\"Model\" description=\"Each choice saves as soon as you make it.\">\n <FormField id=\"agent-settings-provider\" label=\"AI provider\" error={providerError}>\n {(f) => (\n <RadioGroup\n id={f.id}\n aria-describedby={f['aria-describedby']}\n aria-label=\"AI provider\"\n variant=\"card\"\n options={providerOptions}\n selectedValue={provider}\n disabled={!canChange || savingProvider}\n onChange={handleProvider}\n />\n )}\n </FormField>\n <FormField id=\"agent-settings-routing\" label=\"Routing\" help=\"How the agent picks a model for each request.\" error={routingError}>\n {(f) => (\n <RadioGroup\n id={f.id}\n aria-describedby={f['aria-describedby']}\n aria-label=\"Routing\"\n options={routingOptions}\n selectedValue={routing}\n disabled={!canChange || savingRouting}\n onChange={handleRouting}\n />\n )}\n </FormField>\n </SettingsSection>\n\n <SettingsSection title=\"Instructions\" description=\"What the agent should know about how your team works.\">\n <Form aria-label=\"Instructions\" gap=\"medium\" onSubmit={handleSaveInstructions}>\n <FormField id=\"agent-settings-instructions\" label=\"Instructions\" help={`Up to ${maxInstructions.toLocaleString('en-US')} characters. Every conversation uses them.`} error={instructionsError}>\n {(f) => (\n <Textarea\n id={f.id}\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={instructions}\n disabled={!canChange || savingInstructions}\n onChange={(e) => { setInstructions(e.target.value); setInstructionsError(''); setInstructionsSaved(false); }}\n />\n )}\n </FormField>\n {canChange && (\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={instructionsChanged || savingInstructions ? 'enabled' : 'disabled'} label={instructionsSaved ? 'Saved' : 'Save'} aria-label={`${instructionsSaved ? 'Saved' : 'Save'} instructions`} htmlType=\"submit\" loading={savingInstructions} />\n </Cluster>\n )}\n </Form>\n </SettingsSection>\n\n <SettingsSection title=\"Budget\" description=\"This month the agent has used $84.\">\n <Form aria-label=\"Budget\" gap=\"medium\" onSubmit={handleSaveBudget}>\n <FormField id=\"agent-settings-budget\" label=\"Monthly cap in US dollars\" help=\"The agent stops when this month's use reaches the cap, and starts again next month.\" error={budgetError}>\n {(f) => (\n <TextField\n id={f.id}\n type=\"number\"\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={budget}\n disabled={!canChange || savingBudget}\n autoComplete=\"off\"\n onChange={(e) => { setBudget(e.target.value); setBudgetError(''); setBudgetSaved(false); }}\n />\n )}\n </FormField>\n {canChange && (\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={budgetChanged || savingBudget ? 'enabled' : 'disabled'} label={budgetSaved ? 'Saved' : 'Save'} aria-label={`${budgetSaved ? 'Saved' : 'Save'} budget`} htmlType=\"submit\" loading={savingBudget} />\n </Cluster>\n )}\n </Form>\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
|
|
531
|
+
"uses": [
|
|
532
|
+
"Button",
|
|
533
|
+
"Center",
|
|
534
|
+
"Cluster",
|
|
535
|
+
"Form",
|
|
536
|
+
"FormField",
|
|
537
|
+
"Heading",
|
|
538
|
+
"Paragraph",
|
|
539
|
+
"RadioGroup",
|
|
540
|
+
"SettingsSection",
|
|
541
|
+
"Stack",
|
|
542
|
+
"TextField",
|
|
543
|
+
"Textarea"
|
|
544
|
+
]
|
|
545
|
+
}
|
|
483
546
|
]
|
|
484
547
|
},
|
|
485
548
|
{
|
|
@@ -502,10 +565,7 @@
|
|
|
502
565
|
"Do not hide the Stop button while the agent writes its reply.",
|
|
503
566
|
"Do not say the agent stopped before the run has really ended."
|
|
504
567
|
],
|
|
505
|
-
"native": "On Apple the Send button turns into Stop while the agent works, and the note reads 'Stopped.' only once the run has really ended."
|
|
506
|
-
"seenIn": [
|
|
507
|
-
"Scindo"
|
|
508
|
-
]
|
|
568
|
+
"native": "On Apple the Send button turns into Stop while the agent works, and the note reads 'Stopped.' only once the run has really ended."
|
|
509
569
|
},
|
|
510
570
|
{
|
|
511
571
|
"id": "agent-shows-sources",
|
|
@@ -526,9 +586,144 @@
|
|
|
526
586
|
"Do not show a sources section when the reply used no sources.",
|
|
527
587
|
"Do not show source cards on a person's message.",
|
|
528
588
|
"Do not link a source card to any site other than the product or the service the source came from."
|
|
589
|
+
]
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
"id": "api-keys",
|
|
593
|
+
"title": "API keys",
|
|
594
|
+
"kind": "design",
|
|
595
|
+
"level": "organism",
|
|
596
|
+
"area": "settings",
|
|
597
|
+
"situation": "A person makes keys that let a script or a service use the product as them, and revokes keys they no longer use.",
|
|
598
|
+
"do": [
|
|
599
|
+
"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.",
|
|
600
|
+
"Show only a prefix of 14 characters in the list, with an ellipsis. Never show a whole key again once the Modal is closed.",
|
|
601
|
+
"Open a Modal titled 'Create Key' from a 'Create Key' Button, with one field, 'Name', and 'Cancel' then 'Create'.",
|
|
602
|
+
"Say under the name what to put in it: 'Say what will use it, such as CI pipeline.'",
|
|
603
|
+
"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.'",
|
|
604
|
+
"Give the Modal one Button, 'Done'. Ignore Escape and a click outside while the key shows, so a stray click cannot lose it.",
|
|
605
|
+
"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.'",
|
|
606
|
+
"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'.",
|
|
607
|
+
"Show `EmptyBox` with 'No API keys' when the list is empty, as the rule 'An empty list says what is empty' says.",
|
|
608
|
+
"Disable the name field while the key is made, and show `loading` on the Button without changing its label."
|
|
609
|
+
],
|
|
610
|
+
"dont": [
|
|
611
|
+
"Do not show a whole key in the list, in a toast or in a URL.",
|
|
612
|
+
"Do not revoke a key on the first click.",
|
|
613
|
+
"Do not label the Button 'Create' on the page. Name the thing: 'Create Key'.",
|
|
614
|
+
"Do not close the Modal when the key is made, because the person has not copied it yet.",
|
|
615
|
+
"Do not put the key in a plain field the person has to select by hand. Use `CopyField`.",
|
|
616
|
+
"Do not use an icon-only Button for Revoke. It names no key."
|
|
617
|
+
],
|
|
618
|
+
"native": "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.",
|
|
619
|
+
"options": [
|
|
620
|
+
{
|
|
621
|
+
"id": "list",
|
|
622
|
+
"title": "A list of keys with a create Modal",
|
|
623
|
+
"useWhen": "Scripts or services act as the person with a key they paste.",
|
|
624
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport CopyField from 'oneslash-design-system/components/copyField';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Key = { id: string; name: string; prefix: string; created: string; lastUsed: string };\n\nconst firstKeys: Key[] = [\n { id: 'k1', name: 'CI pipeline', prefix: 'acme_live_7Hd2', created: 'Oct 3, 2026', lastUsed: 'Today' },\n { id: 'k2', name: 'Reporting script', prefix: 'acme_live_Qm4x', created: 'Aug 19, 2026', lastUsed: 'Nov 20, 2026' },\n];\n\n// The key the server made. A real app gets it once, in the reply to the create request, and never again.\nconst madeKey = 'acme_live_4f9kQ27xLmT4vB8cRw1ZdN6yHs3P';\nconst prefixLength = 14;\n\nexport default function ApiKeysList() {\n // Opens on the new key, as if the person just chose Create. The list already holds it, without the key.\n const [keys, setKeys] = useState<Key[]>(() => [\n { id: 'k3', name: 'Deploy bot', prefix: madeKey.slice(0, prefixLength), created: 'Today', lastUsed: 'Never used' },\n ...firstKeys,\n ]);\n const [open, setOpen] = useState(true);\n const [shownKey, setShownKey] = useState<string | null>(madeKey);\n const [name, setName] = useState('');\n const [nameError, setNameError] = useState('');\n const [creating, setCreating] = useState(false);\n const [confirming, setConfirming] = useState<string | null>(null);\n const [revoking, setRevoking] = useState<string | null>(null);\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // Gives each new key its own id, so no two rows share a key.\n const keyCount = useRef(0);\n const toastIds = useRef<string[]>([]);\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n function handleOpen() {\n setName('');\n setNameError('');\n setShownKey(null);\n setOpen(true);\n }\n\n // Escape, a click outside and Cancel close the first step, except while the request runs.\n // Once the key shows, only 'Done' closes it, so a stray click cannot throw the key away.\n function handleClose() {\n if (creating || shownKey) return;\n setOpen(false);\n }\n\n // 'Done' drops the key from the page. It is not kept anywhere else.\n function handleDone() {\n setOpen(false);\n setShownKey(null);\n }\n\n function handleCreate() {\n if (creating) return;\n if (!name.trim()) {\n setNameError('Enter a name for the key.');\n return;\n }\n setNameError('');\n setCreating(true);\n later(() => {\n setCreating(false);\n keyCount.current += 1;\n const id = `new-${keyCount.current}`;\n setKeys((list) => [{ id, name: name.trim(), prefix: madeKey.slice(0, prefixLength), created: 'Today', lastUsed: 'Never used' }, ...list]);\n setShownKey(madeKey);\n }, 1200);\n }\n\n function handleRevoke(key: Key) {\n if (revoking) return;\n setRevoking(key.id);\n later(() => {\n setRevoking(null);\n setConfirming(null);\n setKeys((list) => list.filter((k) => k.id !== key.id));\n toastIds.current.push(toast({ type: 'success', message: `${key.name} key revoked.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">API keys</Heading>\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Create Key\" decoIcon=\"Plus\" onClickButton={handleOpen} />\n </Cluster>\n <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>\n </Stack>\n\n {keys.length > 0 ? (\n <TableContainer>\n <TableHeader>\n <TableRow>\n <TableHeaderCell>Name</TableHeaderCell>\n <TableHeaderCell width=\"150px\">Key</TableHeaderCell>\n <TableHeaderCell width=\"100px\">Created</TableHeaderCell>\n <TableHeaderCell width=\"100px\">Last used</TableHeaderCell>\n <TableHeaderCell width=\"200px\">Actions</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {keys.map((k) => (\n <TableRow key={k.id}>\n <TableCell>{k.name}</TableCell>\n <TableCell width=\"150px\">\n <Paragraph mono size=\"body2\" measure=\"none\">{k.prefix}…</Paragraph>\n </TableCell>\n <TableCell width=\"100px\">{k.created}</TableCell>\n <TableCell width=\"100px\">{k.lastUsed}</TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"200px\">\n {confirming === k.id ? (\n <Stack gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke {k.name}?</Paragraph>\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={revoking === k.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking ${k.name}`} onClickButton={() => setConfirming(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke ${k.name}`} loading={revoking === k.id} onClickButton={() => handleRevoke(k)} />\n </Cluster>\n </Stack>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state={revoking ? 'disabled' : 'enabled'} label=\"Revoke\" aria-label={`Revoke ${k.name}`} onClickButton={() => setConfirming(k.id)} />\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n ) : (\n <EmptyBox size=\"small\" icon=\"KeyRound\" text=\"No API keys\" secondText=\"Keys you create appear here.\" />\n )}\n </Stack>\n\n <Modal\n isOpen={open}\n size=\"medium\"\n initialFocus=\"body\"\n title={shownKey ? 'Key Created' : 'Create Key'}\n onClose={handleClose}\n actions={\n shownKey ? (\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Done\" onClickButton={handleDone} />\n ) : (\n <>\n <Button size=\"small\" type=\"tertiary\" state={creating ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Create\" loading={creating} onClickButton={handleCreate} />\n </>\n )\n }\n >\n {shownKey ? (\n <Stack gap=\"medium\">\n <Paragraph measure=\"none\">Use this key where the service asks for one. Anyone who has it can use Acme as you.</Paragraph>\n {/* `reveal=\"once\"` adds the line that says the key will not show again. */}\n <CopyField id=\"api-keys-key\" label=\"API key\" value={shownKey} mono reveal=\"once\" />\n </Stack>\n ) : (\n <Form aria-label=\"Create key\" onSubmit={handleCreate}>\n <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(''); }} />\n </Form>\n )}\n </Modal>\n </Center>\n );\n}\n",
|
|
625
|
+
"uses": [
|
|
626
|
+
"Button",
|
|
627
|
+
"Center",
|
|
628
|
+
"Cluster",
|
|
629
|
+
"CopyField",
|
|
630
|
+
"EmptyBox",
|
|
631
|
+
"Form",
|
|
632
|
+
"Heading",
|
|
633
|
+
"Modal",
|
|
634
|
+
"Paragraph",
|
|
635
|
+
"Stack",
|
|
636
|
+
"TableCell",
|
|
637
|
+
"TableContainer",
|
|
638
|
+
"TableHeader",
|
|
639
|
+
"TableHeaderCell",
|
|
640
|
+
"TableRow",
|
|
641
|
+
"TextField",
|
|
642
|
+
"Toaster",
|
|
643
|
+
"dismissToast",
|
|
644
|
+
"toast"
|
|
645
|
+
]
|
|
646
|
+
}
|
|
647
|
+
]
|
|
648
|
+
},
|
|
649
|
+
{
|
|
650
|
+
"id": "app-shell",
|
|
651
|
+
"title": "App shell",
|
|
652
|
+
"kind": "design",
|
|
653
|
+
"level": "page",
|
|
654
|
+
"area": "shell",
|
|
655
|
+
"situation": "A person opens the product and moves between its places, such as Inbox, Tasks and Settings, from every page.",
|
|
656
|
+
"do": [
|
|
657
|
+
"Follow the rule 'On a phone, a sidebar opens as a drawer and a list opens its detail'.",
|
|
658
|
+
"Build the sidebar frame with `AppShell`. Its places are a `Navigation` of `NavigationGroup`s.",
|
|
659
|
+
"Make each place a `MenuItem` with an `href`, and mark the open one with `isSelected` and `aria-current=\"page\"`.",
|
|
660
|
+
"Put the account menu last in the sidebar, built as the case 'Account menu' says.",
|
|
661
|
+
"Give the page's `TitleBar` the page's name as the level 1 heading, and give `AppShell` the place's name as `title`. When the page is the place, the two are the same.",
|
|
662
|
+
"Pass `onSidebarHiddenChange` to `AppShell` so a person can hide the sidebar from `md` up. It adds a 'Hide sidebar' IconButton at the top of the column and a 'Show sidebar' IconButton when it is hidden, and moves focus between them. The phone menu has neither.",
|
|
663
|
+
"Add Cmd+B, or Ctrl+B, with `useHotkey('b', …)`, and have it change the same state. It does nothing while the person types in a field. Ignore it while a Modal, such as the 'Log Out' confirm, is open.",
|
|
664
|
+
"Close the phone menu in the `onClick` of an item in a Popover, such as Settings in the account menu. A choice in a Popover does not close the Drawer by itself.",
|
|
665
|
+
"Render a Modal that the sidebar opens, such as the 'Log Out' confirm, inside the sidebar node, so it is mounted once: in the column or in the Drawer.",
|
|
666
|
+
"Use `TabsContainer fill` with a `Tab` for each place, each with an `href` and the app's `router`, when there are four places or fewer. Name each with one short word.",
|
|
667
|
+
"With tabs across the top, put the name of the app at the start of the bar and the account menu at the end."
|
|
668
|
+
],
|
|
669
|
+
"dont": [
|
|
670
|
+
"Do not use tabs for more than four places, or for places the person makes.",
|
|
671
|
+
"Do not show the sidebar beside the page on a phone.",
|
|
672
|
+
"Do not hide the sidebar with the shortcut alone. Give a person a visible 'Hide sidebar' button as well.",
|
|
673
|
+
"Do not let the tabs scroll sideways. When they do not fit at 375px, use the sidebar.",
|
|
674
|
+
"Do not mount the sidebar twice, once for the column and once for the menu."
|
|
529
675
|
],
|
|
530
|
-
"
|
|
531
|
-
|
|
676
|
+
"native": "On macOS and iPad use a `NavigationSplitView` with a sidebar `List` in `Section`s. The system adds the hide button and its shortcut. On iPhone use a `TabView` for five places or fewer. On Android use a navigation drawer.",
|
|
677
|
+
"options": [
|
|
678
|
+
{
|
|
679
|
+
"id": "sidebar",
|
|
680
|
+
"title": "Sidebar in groups",
|
|
681
|
+
"useWhen": "There are more than four places, or the person makes some of them, such as projects or channels.",
|
|
682
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport AppShell from 'oneslash-design-system/components/appShell';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport Navigation, { NavigationGroup } from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport Line from 'oneslash-design-system/components/line';\nimport useHotkey from 'oneslash-design-system/components/useHotkey';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Place = { id: string; label: string; icon: string; group: string; page: string; text: string };\n\n// The places. The top bar on a phone names the place; the page's own title is the level 1 heading, so a phone never shows the same words twice.\nconst places: Place[] = [\n { id: 'inbox', label: 'Inbox', icon: 'Inbox', group: 'Mail', page: 'Unread messages', text: 'Ben Carter shared the launch plan. Omar Reyes asked for the new screens by Friday.' },\n { id: 'sent', label: 'Sent', icon: 'Send', group: 'Mail', page: 'Sent this week', text: 'You sent 4 messages this week.' },\n { id: 'website', label: 'Website', icon: 'Globe', group: 'Projects', page: 'Home page redesign', text: '12 tasks are open. The next review is on Thursday.' },\n { id: 'mobile', label: 'Mobile App', icon: 'Smartphone', group: 'Projects', page: 'Version 2 release', text: '5 tasks are open. Dana Lee owns the release.' },\n];\n\nconst groups = ['Mail', 'Projects'];\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\nexport default function AppShellSidebar() {\n const [placeId, setPlaceId] = useState('inbox');\n // Below md the sidebar is a Drawer; this says whether it is open.\n const [navOpen, setNavOpen] = useState(false);\n // From md up the person can hide the column for room. The phone menu still has it.\n const [hidden, setHidden] = useState(false);\n const [accountAnchor, setAccountAnchor] = useState<HTMLElement | null>(null);\n const [accountOpen, setAccountOpen] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [loggingOut, setLoggingOut] = useState(false);\n const [loggedOut, setLoggedOut] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const accountButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n // Cmd+B, or Ctrl+B. It does nothing while the person types in a field, and nothing while the Log Out confirm is open.\n useHotkey('b', () => {\n if (!confirming) setHidden((h) => !h);\n });\n\n const place = places.find((p) => p.id === placeId) ?? places[0];\n\n // Cancel, Escape and a click outside. 'Cancel' puts focus back on the account Button, inside the Drawer on a phone.\n function cancelLogOut() {\n if (loggingOut) return;\n setConfirming(false);\n focusNext.current = () => accountButton.current?.focus();\n }\n\n function logOut() {\n if (loggingOut) return;\n setLoggingOut(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoggingOut(false);\n setConfirming(false);\n setLoggedOut(true);\n }, 1200);\n }\n\n // A real app goes to its login page here. The example shows a short logged-out page instead.\n if (loggedOut) {\n return (\n <Center fill>\n <Heading level={1} size=\"h5\">You are logged out</Heading>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" onClickButton={() => { setLoggedOut(false); setPlaceId('inbox'); }} />\n </Cluster>\n </Center>\n );\n }\n\n // The sidebar is mounted once: in the column from md up, in the Drawer below it. Its Modal lives inside it.\n const sidebar = (\n <Navigation aria-label=\"Main\">\n <Paragraph size=\"body1\" measure=\"none\">Acme</Paragraph>\n {groups.map((group) => (\n <NavigationGroup key={group} label={group}>\n {places.filter((p) => p.group === group).map((p) => (\n <MenuItem\n key={p.id}\n size=\"small\"\n label={p.label}\n iconName={p.icon}\n href={`/${p.id}`}\n isSelected={p.id === place.id}\n aria-current={p.id === place.id ? 'page' : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example keeps the choice in state.\n event.preventDefault();\n setPlaceId(p.id);\n }}\n />\n ))}\n </NavigationGroup>\n ))}\n <Line />\n {/* The account menu is last. */}\n <Cluster>\n <Button\n ref={accountButton}\n size=\"small\"\n type=\"tertiary\"\n state={accountOpen ? 'selected' : 'enabled'}\n label={me}\n decoIcon={<UserImage userHandle={me} size={20} decorative />}\n aria-label={`${me}, account menu`}\n aria-haspopup=\"menu\"\n aria-expanded={accountOpen}\n onClickButton={(e: { currentTarget: HTMLElement }) => {\n setAccountAnchor(e.currentTarget);\n setAccountOpen((o) => !o);\n }}\n />\n </Cluster>\n <Popover open={accountOpen} anchorEl={accountAnchor} onClose={() => setAccountOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Account\" width={200}>\n {/* A choice in a Popover does not close the phone menu: close it here. */}\n <MenuItem size=\"small\" iconName=\"Settings\" label=\"Settings\" onClick={() => { setAccountOpen(false); setNavOpen(false); }} />\n <MenuItem size=\"small\" iconName=\"CircleHelp\" label=\"Help\" onClick={() => { setAccountOpen(false); setNavOpen(false); }} />\n <Line />\n <MenuItem size=\"small\" iconName=\"LogOut\" label=\"Log Out\" onClick={() => { setAccountOpen(false); setConfirming(true); }} />\n </Menu>\n </Popover>\n <Modal\n isOpen={confirming}\n size=\"small\"\n title=\"Log Out\"\n onClose={cancelLogOut}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={loggingOut ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={cancelLogOut} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Log Out\" loading={loggingOut} onClickButton={logOut} />\n </>\n }\n >\n <Paragraph measure=\"none\">You will need to log in again to use Acme on this device.</Paragraph>\n </Modal>\n </Navigation>\n );\n\n const newMessage = <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"New Message\" decoIcon=\"Plus\" />;\n\n return (\n <AppShell title={place.label} navOpen={navOpen} onNavOpenChange={setNavOpen} sidebar={sidebar} sidebarHidden={hidden} onSidebarHiddenChange={setHidden}>\n <Stack gap=\"large\">\n <TitleBar\n title={place.page}\n actions={newMessage}\n />\n <Paragraph tone=\"secondary\" measure=\"none\">{place.text}</Paragraph>\n </Stack>\n </AppShell>\n );\n}\n",
|
|
683
|
+
"uses": [
|
|
684
|
+
"AppShell",
|
|
685
|
+
"Button",
|
|
686
|
+
"Center",
|
|
687
|
+
"Cluster",
|
|
688
|
+
"Heading",
|
|
689
|
+
"Line",
|
|
690
|
+
"Menu",
|
|
691
|
+
"MenuItem",
|
|
692
|
+
"Modal",
|
|
693
|
+
"Navigation",
|
|
694
|
+
"NavigationGroup",
|
|
695
|
+
"Paragraph",
|
|
696
|
+
"Popover",
|
|
697
|
+
"Stack",
|
|
698
|
+
"TitleBar",
|
|
699
|
+
"UserImage",
|
|
700
|
+
"useHotkey"
|
|
701
|
+
]
|
|
702
|
+
},
|
|
703
|
+
{
|
|
704
|
+
"id": "top-tabs",
|
|
705
|
+
"title": "Tabs across the top",
|
|
706
|
+
"useWhen": "There are four places or fewer, all fixed, each with a short name that fits on a phone.",
|
|
707
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Place = { id: string; label: string; page: string; text: string };\n\n// Four fixed places, one short word each, so the tabs fit on a phone.\nconst places: Place[] = [\n { id: 'inbox', label: 'Inbox', page: 'Unread messages', text: 'Ben Carter shared the launch plan. Omar Reyes asked for the new screens by Friday.' },\n { id: 'tasks', label: 'Tasks', page: 'My tasks', text: '7 tasks are open. 2 are due this week.' },\n { id: 'files', label: 'Files', page: 'Recent files', text: 'Omar Reyes added the new screens an hour ago.' },\n { id: 'team', label: 'Team', page: 'People and roles', text: 'Dana Lee, Ben Carter and Omar Reyes are in Acme.' },\n];\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\nexport default function AppShellTopTabs() {\n const [placeId, setPlaceId] = useState('inbox');\n const [accountAnchor, setAccountAnchor] = useState<HTMLElement | null>(null);\n const [accountOpen, setAccountOpen] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [loggingOut, setLoggingOut] = useState(false);\n const [loggedOut, setLoggedOut] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const accountButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const place = places.find((p) => p.id === placeId) ?? places[0];\n // A real app passes the router from its framework, such as Next's useRouter(). Here it sets the open place.\n const router = { push: (url: string) => setPlaceId(url.split('/').pop() ?? 'inbox') };\n\n // 'Cancel' puts focus back on the account Button.\n function cancelLogOut() {\n if (loggingOut) return;\n setConfirming(false);\n focusNext.current = () => accountButton.current?.focus();\n }\n\n function logOut() {\n if (loggingOut) return;\n setLoggingOut(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLoggingOut(false);\n setConfirming(false);\n setLoggedOut(true);\n }, 1200);\n }\n\n // A real app goes to its login page here. The example shows a short logged-out page instead.\n if (loggedOut) {\n return (\n <Center fill>\n <Heading level={1} size=\"h5\">You are logged out</Heading>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" onClickButton={() => { setLoggedOut(false); setPlaceId('inbox'); }} />\n </Cluster>\n </Center>\n );\n }\n\n return (\n <PageShell>\n <Stack gap=\"large\">\n {/* The app's name at the start, the account menu at the end. */}\n <Cluster justify=\"between\">\n <Paragraph size=\"body1\" measure=\"none\">Acme</Paragraph>\n <Button\n ref={accountButton}\n size=\"small\"\n type=\"tertiary\"\n state={accountOpen ? 'selected' : 'enabled'}\n label={me}\n decoIcon={<UserImage userHandle={me} size={20} decorative />}\n aria-label={`${me}, account menu`}\n aria-haspopup=\"menu\"\n aria-expanded={accountOpen}\n onClickButton={(e: { currentTarget: HTMLElement }) => {\n setAccountAnchor(e.currentTarget);\n setAccountOpen((o) => !o);\n }}\n />\n </Cluster>\n <TabsContainer fill>\n {places.map((p) => (\n <Tab key={p.id} label={p.label} href={`/${p.id}`} router={router} isSelected={p.id === place.id} onClickTab={() => setPlaceId(p.id)} />\n ))}\n </TabsContainer>\n <TitleBar title={place.page} actions={<Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"New Message\" decoIcon=\"Plus\" />} />\n <Paragraph tone=\"secondary\" measure=\"none\">{place.text}</Paragraph>\n </Stack>\n <Popover open={accountOpen} anchorEl={accountAnchor} onClose={() => setAccountOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Account\" width={200}>\n <MenuItem size=\"small\" iconName=\"Settings\" label=\"Settings\" onClick={() => setAccountOpen(false)} />\n <MenuItem size=\"small\" iconName=\"CircleHelp\" label=\"Help\" onClick={() => setAccountOpen(false)} />\n <Line />\n <MenuItem size=\"small\" iconName=\"LogOut\" label=\"Log Out\" onClick={() => { setAccountOpen(false); setConfirming(true); }} />\n </Menu>\n </Popover>\n <Modal\n isOpen={confirming}\n size=\"small\"\n title=\"Log Out\"\n onClose={cancelLogOut}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={loggingOut ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={cancelLogOut} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Log Out\" loading={loggingOut} onClickButton={logOut} />\n </>\n }\n >\n <Paragraph measure=\"none\">You will need to log in again to use Acme on this device.</Paragraph>\n </Modal>\n </PageShell>\n );\n}\n",
|
|
708
|
+
"uses": [
|
|
709
|
+
"Button",
|
|
710
|
+
"Center",
|
|
711
|
+
"Cluster",
|
|
712
|
+
"Heading",
|
|
713
|
+
"Line",
|
|
714
|
+
"Menu",
|
|
715
|
+
"MenuItem",
|
|
716
|
+
"Modal",
|
|
717
|
+
"PageShell",
|
|
718
|
+
"Paragraph",
|
|
719
|
+
"Popover",
|
|
720
|
+
"Stack",
|
|
721
|
+
"Tab",
|
|
722
|
+
"TabsContainer",
|
|
723
|
+
"TitleBar",
|
|
724
|
+
"UserImage"
|
|
725
|
+
]
|
|
726
|
+
}
|
|
532
727
|
]
|
|
533
728
|
},
|
|
534
729
|
{
|
|
@@ -554,22 +749,21 @@
|
|
|
554
749
|
"Do not show the document's card on a person's message."
|
|
555
750
|
],
|
|
556
751
|
"native": "On Mac the card opens the document in the canvas beside the thread. On iPhone it opens the document in a read-only sheet.",
|
|
557
|
-
"notBuiltYet": "Scindo's card shows the kind, the title and 'Open' on one line, with no icon and no length. Its reply is not short: it is cut to its first lines.",
|
|
558
|
-
"seenIn": [
|
|
559
|
-
"Scindo"
|
|
560
|
-
],
|
|
561
752
|
"options": [
|
|
562
753
|
{
|
|
563
754
|
"id": "card",
|
|
564
755
|
"title": "In the thread",
|
|
565
756
|
"useWhen": "A reply made a document.",
|
|
566
|
-
"source": "'use client';\nimport { Bot, FileText } from 'lucide-react';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport SourceCard from 'oneslash-design-system/components/sourceCard';\nimport {
|
|
757
|
+
"source": "'use client';\nimport { useRef, useState } from 'react';\nimport { Bot, FileText } from 'lucide-react';\nimport AppShell from 'oneslash-design-system/components/appShell';\nimport SidePane, { type SidePaneHandle } from 'oneslash-design-system/components/sidePane';\nimport Navigation from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport SourceCard from 'oneslash-design-system/components/sourceCard';\nimport { Grid, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\nconst request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'Can you write up the launch plan as a document?' };\nconst repliedAt = new Date('2025-01-15T11:41:00Z');\n// One sentence on what the agent made. The document itself stays out of the thread.\nconst reply = 'I wrote the launch plan for March 3 as a document.';\n\nconst doc = { title: 'Launch plan for March 3', meta: 'Document · 4 pages' };\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nconst docParagraphs = [\n 'Acme ships the new home page on March 3. Omar Reyes owns the copy and Dana Lee the screens.',\n 'Ben Carter writes the announcement once the screens are approved.',\n];\n\n// The threads. A real app lets each link go to its page.\nconst sidebar = (\n <Navigation aria-label=\"Main\">\n <MenuItem\n size=\"small\"\n label=\"Launch plan\"\n iconName=\"MessageSquare\"\n href=\"/launch-plan\"\n isSelected\n aria-current=\"page\"\n onClick={(event: { preventDefault: () => void }) => event.preventDefault()}\n />\n </Navigation>\n);\n\nexport default function ArtifactCardCard() {\n const [navOpen, setNavOpen] = useState(false);\n // The pane opens from the card, so focus moves into it and goes back to the card on close.\n const [open, setOpen] = useState(false);\n const pane = useRef<SidePaneHandle>(null);\n\n // Pressed again while the pane is open, the card brings the pane forward instead of opening a second one.\n function openDocument() {\n if (open) pane.current?.focus();\n else setOpen(true);\n }\n\n return (\n <AppShell\n title=\"Launch plan\"\n navOpen={navOpen}\n onNavOpenChange={setNavOpen}\n sidebar={sidebar}\n pane={\n open && (\n <SidePane ref={pane} title={doc.title} onClose={() => setOpen(false)}>\n <Stack gap=\"medium\">\n {docParagraphs.map((text) => (\n <Paragraph key={text} measure=\"none\">{text}</Paragraph>\n ))}\n </Stack>\n </SidePane>\n )\n }\n >\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch plan</Heading>\n {/* A real app gives the list that holds the rows role=\"log\". */}\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(repliedAt)}\n footer={\n <Grid columns={2} gap=\"medium\">\n <SourceCard icon={FileText} title={doc.title} meta={doc.meta} action=\"Open\" onClick={openDocument} />\n </Grid>\n }\n >\n <Paragraph measure=\"none\">{reply}</Paragraph>\n </Message>\n </Stack>\n </Stack>\n </AppShell>\n );\n}\n",
|
|
567
758
|
"uses": [
|
|
568
|
-
"
|
|
759
|
+
"AppShell",
|
|
569
760
|
"Grid",
|
|
570
761
|
"Heading",
|
|
762
|
+
"MenuItem",
|
|
571
763
|
"Message",
|
|
764
|
+
"Navigation",
|
|
572
765
|
"Paragraph",
|
|
766
|
+
"SidePane",
|
|
573
767
|
"SourceCard",
|
|
574
768
|
"Stack",
|
|
575
769
|
"Tag",
|
|
@@ -600,11 +794,6 @@
|
|
|
600
794
|
"Do not put more than one line under the spinner, or write it in a separate Paragraph."
|
|
601
795
|
],
|
|
602
796
|
"native": "On Apple use `ProgressView()` centered in the window, with a label only for a named step that can take longer.",
|
|
603
|
-
"notBuiltYet": "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.",
|
|
604
|
-
"seenIn": [
|
|
605
|
-
"Commentify admin",
|
|
606
|
-
"Scindo"
|
|
607
|
-
],
|
|
608
797
|
"options": [
|
|
609
798
|
{
|
|
610
799
|
"id": "spinner",
|
|
@@ -649,11 +838,6 @@
|
|
|
649
838
|
"Do not make the person close the success Alert, and do not let it close on its own before they have read it.",
|
|
650
839
|
"Do not change 'Send Again' to 'Sending…' while it sends."
|
|
651
840
|
],
|
|
652
|
-
"notBuiltYet": "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.",
|
|
653
|
-
"seenIn": [
|
|
654
|
-
"Commentify",
|
|
655
|
-
"Scindo"
|
|
656
|
-
],
|
|
657
841
|
"options": [
|
|
658
842
|
{
|
|
659
843
|
"id": "page",
|
|
@@ -689,6 +873,56 @@
|
|
|
689
873
|
}
|
|
690
874
|
]
|
|
691
875
|
},
|
|
876
|
+
{
|
|
877
|
+
"id": "collapsible-search",
|
|
878
|
+
"title": "Collapsible search",
|
|
879
|
+
"kind": "design",
|
|
880
|
+
"level": "organism",
|
|
881
|
+
"area": "menu",
|
|
882
|
+
"situation": "A person filters a list by a word, and the list should keep its room when they are not typing.",
|
|
883
|
+
"do": [
|
|
884
|
+
"Use an `IconButton` with `iconName=\"Search\"` beside the list's heading, and open a `<Popover returnFocus>` with a search `TextField` from it.",
|
|
885
|
+
"Keep the words in the page, not in the Popover. The list stays filtered while the Popover is closed.",
|
|
886
|
+
"Show that a search is on: `color=\"secondary\"` on the button, and a line such as '2 of 5 invoices match \"north\".'.",
|
|
887
|
+
"Say the current search in the button's `ariaLabel`: 'Search: north'. It is plain 'Search' when no search is on.",
|
|
888
|
+
"Set `aria-haspopup=\"dialog\"` and `aria-expanded` on the button, and `state=\"selected\"` while the Popover is open.",
|
|
889
|
+
"Focus the field with `autoFocus` when the Popover opens, and name it with `aria-label`, such as `aria-label=\"Search invoices\"`.",
|
|
890
|
+
"Clear the search and close the Popover on Escape. Focus goes back to the button.",
|
|
891
|
+
"Keep the search when the Popover closes any other way: Enter, a click outside, or Tab.",
|
|
892
|
+
"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."
|
|
893
|
+
],
|
|
894
|
+
"dont": [
|
|
895
|
+
"Do not clear the search when the Popover closes, except with Escape.",
|
|
896
|
+
"Do not name the button 'Search' while a search is on. Its name says what is searched for.",
|
|
897
|
+
"Do not show the filter only in color. The line under the heading says it too.",
|
|
898
|
+
"Do not open the Popover when the page loads."
|
|
899
|
+
],
|
|
900
|
+
"native": "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.",
|
|
901
|
+
"options": [
|
|
902
|
+
{
|
|
903
|
+
"id": "popover",
|
|
904
|
+
"title": "Search button with a Popover",
|
|
905
|
+
"useWhen": "A list has a header with little room, and a search is a filter the person sets once in a while.",
|
|
906
|
+
"source": "'use client';\nimport { useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Button from 'oneslash-design-system/components/button';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport List from 'oneslash-design-system/components/list';\nimport Surface from 'oneslash-design-system/components/surface';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server.\nconst invoices = ['Northwind, March', 'Harbor Studio, March', 'Lumen Labs, February', 'Northstar Dental, February', 'Pine and Co, January'];\n\nexport default function CollapsibleSearchPopover() {\n // The filter belongs to the page, not to the Popover: it stays when the Popover closes.\n const [query, setQuery] = useState('north');\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const trigger = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n const words = query.trim();\n const on = words !== '';\n const found = invoices.filter((name) => name.toLowerCase().includes(words.toLowerCase()));\n\n function toggle(anchorEl: HTMLElement) {\n setAnchor(anchorEl);\n setOpen((o) => !o);\n }\n\n // Escape clears the search and closes. The field handles it before the Popover's own Escape, which only closes.\n // Enter closes and keeps the filter. A click outside and Tab close and keep it too.\n function keyDown(e: { key: string; preventDefault(): void }) {\n if (e.key === 'Escape') {\n e.preventDefault();\n setQuery('');\n setOpen(false);\n } else if (e.key === 'Enter') {\n e.preventDefault();\n setOpen(false);\n }\n }\n\n // The field is closed, so 'Clear Search' clears the filter and focus goes to the search button.\n function clearSearch() {\n setQuery('');\n trigger.current?.focus();\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster gap=\"small\">\n <Heading level={1} size=\"h5\">Invoices</Heading>\n {/* A search that is on shows in a filled button and says what it is looking for. */}\n <Tooltip title={on ? `Search: ${words}` : 'Search'}>\n <IconButton\n ref={trigger}\n color={on ? 'secondary' : 'iconOnly'}\n state={open ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Search\"\n ariaLabel={on ? `Search: ${words}` : 'Search'}\n aria-haspopup=\"dialog\"\n aria-expanded={open}\n onClick={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {on ? `${found.length} of ${invoices.length} invoices match \"${words}\".` : `All ${invoices.length} invoices.`}\n </Paragraph>\n {found.length > 0 ? (\n <Surface>\n <List items={found} size=\"body1\" />\n </Surface>\n ) : (\n <Surface align=\"center\" minHeight=\"short\">\n <EmptyBox\n size=\"large\"\n icon=\"Search\"\n text={`No invoices match \"${words}\"`}\n secondText=\"Check the spelling, or search for fewer words.\"\n action={<Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Clear Search\" onClickButton={clearSearch} />}\n />\n </Surface>\n )}\n </Stack>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n {/* Menu gives the Popover its surface and a width. It holds a field here, not items. */}\n <Menu width={288}>\n <TextField\n id=\"collapsible-search-query\"\n type=\"search\"\n size=\"small\"\n autoFocus\n aria-label=\"Search invoices\"\n placeholder=\"Search invoices\"\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n onKeyDown={keyDown}\n />\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
|
|
907
|
+
"uses": [
|
|
908
|
+
"Button",
|
|
909
|
+
"Center",
|
|
910
|
+
"Cluster",
|
|
911
|
+
"EmptyBox",
|
|
912
|
+
"Heading",
|
|
913
|
+
"IconButton",
|
|
914
|
+
"List",
|
|
915
|
+
"Menu",
|
|
916
|
+
"Paragraph",
|
|
917
|
+
"Popover",
|
|
918
|
+
"Stack",
|
|
919
|
+
"Surface",
|
|
920
|
+
"TextField",
|
|
921
|
+
"Tooltip"
|
|
922
|
+
]
|
|
923
|
+
}
|
|
924
|
+
]
|
|
925
|
+
},
|
|
692
926
|
{
|
|
693
927
|
"id": "composer-limit",
|
|
694
928
|
"title": "Composer at a limit",
|
|
@@ -716,10 +950,6 @@
|
|
|
716
950
|
"Do not cover the thread with a Modal when the agent is refused."
|
|
717
951
|
],
|
|
718
952
|
"native": "On Apple the notice is a row above the composer, with an Upgrade or Change Budget Cap button for admins and never a link to a web page.",
|
|
719
|
-
"notBuiltYet": "Scindo on the web shows the monthly limit in an overlay over the thread, and shows its Upgrade button to everyone. Its other limits show as an error Alert that the person closes.",
|
|
720
|
-
"seenIn": [
|
|
721
|
-
"Scindo"
|
|
722
|
-
],
|
|
723
953
|
"options": [
|
|
724
954
|
{
|
|
725
955
|
"id": "notice",
|
|
@@ -788,11 +1018,6 @@
|
|
|
788
1018
|
"Do not ask a question in place of the action, such as 'Are you sure?'."
|
|
789
1019
|
],
|
|
790
1020
|
"native": "On Apple use a system `confirmationDialog` or `.alert`, with the action in the `.destructive` role and 'Cancel' in the `.cancel` role.",
|
|
791
|
-
"notBuiltYet": "Commentify's Delete project confirm is not danger-colored and asks a question in its body. Scindo on the web confirms removing a saved card in place, but asks 'Are you sure?' and labels its Buttons 'Confirm' and 'No'.",
|
|
792
|
-
"seenIn": [
|
|
793
|
-
"Commentify",
|
|
794
|
-
"Scindo"
|
|
795
|
-
],
|
|
796
1021
|
"options": [
|
|
797
1022
|
{
|
|
798
1023
|
"id": "modal",
|
|
@@ -860,12 +1085,7 @@
|
|
|
860
1085
|
"Do not replace the Modal body with a spinner, or close the Modal, while the request runs.",
|
|
861
1086
|
"Do not ask for a confirm when the action is easy to undo."
|
|
862
1087
|
],
|
|
863
|
-
"native": "On Apple use a system `confirmationDialog` or `.alert`, with the action in the `.destructive` role when it destroys or removes something. Never build a sheet by hand for a confirm."
|
|
864
|
-
"notBuiltYet": "No Commentify confirm Modal uses `color=\"danger\"`, and two of them label Cancel 'No'. Scindo on the web makes Cancel a secondary Button in some confirms and a tertiary one in others. It leaves its Delete Task and Remove Member confirms uncolored. Scindo on the web revokes an API key, and Commentify revokes an agent client, with no confirm.",
|
|
865
|
-
"seenIn": [
|
|
866
|
-
"Commentify",
|
|
867
|
-
"Scindo"
|
|
868
|
-
]
|
|
1088
|
+
"native": "On Apple use a system `confirmationDialog` or `.alert`, with the action in the `.destructive` role when it destroys or removes something. Never build a sheet by hand for a confirm."
|
|
869
1089
|
},
|
|
870
1090
|
{
|
|
871
1091
|
"id": "conversation-starters",
|
|
@@ -890,10 +1110,6 @@
|
|
|
890
1110
|
"Do not offer more than four starters.",
|
|
891
1111
|
"Do not write starters in the system's words, such as 'Run summary'."
|
|
892
1112
|
],
|
|
893
|
-
"notBuiltYet": "Scindo on the web shows its starters as `Tag`s under the `EmptyBox`, not as its `action`. It shows them in threads between people too, and puts '@Agent' before the text.",
|
|
894
|
-
"seenIn": [
|
|
895
|
-
"Scindo"
|
|
896
|
-
],
|
|
897
1113
|
"options": [
|
|
898
1114
|
{
|
|
899
1115
|
"id": "chips",
|
|
@@ -960,10 +1176,6 @@
|
|
|
960
1176
|
"Do not show a toast when the new thing is on screen. It shows where it lives."
|
|
961
1177
|
],
|
|
962
1178
|
"native": "On Apple use a sheet with a `Form`. Put 'Cancel' in the `.cancellationAction` placement and 'Create' in `.confirmationAction`, and create on `.onSubmit` from the name field.",
|
|
963
|
-
"notBuiltYet": "Scindo on the web replaces the fields with a spinner while it creates a workspace or a task, and makes Cancel a secondary Button. Scindo's Apple app labels the Button 'Creating...' while it runs.",
|
|
964
|
-
"seenIn": [
|
|
965
|
-
"Scindo"
|
|
966
|
-
],
|
|
967
1179
|
"options": [
|
|
968
1180
|
{
|
|
969
1181
|
"id": "quick",
|
|
@@ -1006,6 +1218,69 @@
|
|
|
1006
1218
|
}
|
|
1007
1219
|
]
|
|
1008
1220
|
},
|
|
1221
|
+
{
|
|
1222
|
+
"id": "danger-zone",
|
|
1223
|
+
"title": "Danger zone",
|
|
1224
|
+
"kind": "design",
|
|
1225
|
+
"level": "organism",
|
|
1226
|
+
"area": "settings",
|
|
1227
|
+
"situation": "A settings page offers actions that are hard or impossible to undo, such as deleting an account or a workspace, or leaving one.",
|
|
1228
|
+
"do": [
|
|
1229
|
+
"Put the actions in a `SettingsSection tone=\"danger\"` titled 'Danger zone', or titled with the action, such as 'Delete workspace'. It is the last section on the page.",
|
|
1230
|
+
"Hide them behind a 'Show Danger Zone' Button when the page has more above it. Give the Button `aria-expanded`, and change its label to 'Hide Danger Zone' while they show. This label says what a press does next. It is not a status, so it may change.",
|
|
1231
|
+
"Say what is deleted and what is kept, above the action: 'Messages and tasks you shared stay with your team.'",
|
|
1232
|
+
"Delete an account or a workspace as the case 'Type to confirm' says: the field shows in place, 'Cancel' comes first, and the danger Button stays disabled until the text matches exactly.",
|
|
1233
|
+
"Type a fixed word such as DELETE for an account. Type the name for a workspace: 'Type Acme to confirm'.",
|
|
1234
|
+
"Leave a workspace with a plain confirm in a small Modal, as the rule 'A confirm says exactly what will happen' says. Name the action with the title's verb: the title is 'Leave Workspace' and the Button is 'Leave'.",
|
|
1235
|
+
"Give 'Leave' the plain primary color. Leaving destroys nothing: the workspace and its work stay.",
|
|
1236
|
+
"Show a page that says it is done when the account or workspace is gone, in place of the toast in the rule 'A confirm says exactly what will happen'. The page that showed it is gone too, and the person may be logged out.",
|
|
1237
|
+
"Mark the section with the danger color on the title and the hairline. `SettingsSection` does both."
|
|
1238
|
+
],
|
|
1239
|
+
"dont": [
|
|
1240
|
+
"Do not put a danger zone above the settings that people use every day.",
|
|
1241
|
+
"Do not delete on the first click. Ask the person to type, or to confirm.",
|
|
1242
|
+
"Do not ask someone to type for leaving a workspace. A plain confirm is enough.",
|
|
1243
|
+
"Do not change the Button's label while it is loading, such as to 'Deleting…'.",
|
|
1244
|
+
"Do not hide what is kept. Say it before the person confirms.",
|
|
1245
|
+
"Do not use a native `details` element. Use a Button with `aria-expanded`."
|
|
1246
|
+
],
|
|
1247
|
+
"native": "On Apple put the actions in their own `Section` of the settings `Form`, with the Delete Button in the `.destructive` role. Delete asks in an `.alert` with a `TextField`, as the case 'Type to confirm' says.",
|
|
1248
|
+
"options": [
|
|
1249
|
+
{
|
|
1250
|
+
"id": "collapsed",
|
|
1251
|
+
"title": "Hidden until asked for",
|
|
1252
|
+
"useWhen": "The page has more above it, and most visits have no use for these actions.",
|
|
1253
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// An account has no name to type, so the person types a fixed word.\nconst word = 'DELETE';\n\nexport default function DangerZoneCollapsed() {\n const [shown, setShown] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [typed, setTyped] = useState('');\n const [deleting, setDeleting] = useState(false);\n const [deleted, setDeleted] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // An exact match, with case. Pasting the word is fine.\n const matches = typed === word;\n\n function handleToggle() {\n if (deleting) return;\n setShown(!shown);\n setConfirming(false);\n setTyped('');\n }\n\n function handleCancel() {\n setConfirming(false);\n setTyped('');\n }\n\n function handleDelete() {\n if (deleting || !matches) return;\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n setDeleted(true);\n }, 1200);\n }\n\n // The account is gone, so the page that showed it is gone too.\n if (deleted) {\n return (\n <Center fill>\n <Heading level={1} size=\"h5\">Your account is deleted</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">We sent a note to dana@acme.example to say so.</Paragraph>\n </Center>\n );\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Heading level={1} size=\"h5\">Account</Heading>\n <SettingsSection title=\"Profile\" description=\"Dana Lee, dana@acme.example.\">\n <Paragraph size=\"body2\" measure=\"none\">Your name and picture are in Profile Settings.</Paragraph>\n </SettingsSection>\n <SettingsSection tone=\"danger\" title=\"Danger zone\" description=\"These actions cannot be undone.\">\n <Cluster>\n <Button\n size=\"small\"\n type=\"textOnly\"\n state={deleting ? 'disabled' : 'enabled'}\n label={shown ? 'Hide Danger Zone' : 'Show Danger Zone'}\n aria-expanded={shown}\n onClickButton={handleToggle}\n />\n </Cluster>\n {shown && (\n <Stack gap=\"medium\">\n <Paragraph size=\"body2\" measure=\"none\">This deletes your account and your private documents. Messages and tasks you shared stay with your team and show as 'Deleted user'.</Paragraph>\n {confirming ? (\n <>\n <TextField id=\"danger-zone-collapsed-word\" label={`Type ${word} to confirm`} value={typed} disabled={deleting} onChange={(e) => setTyped(e.target.value)} />\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleCancel} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state={matches ? 'enabled' : 'disabled'} label=\"Delete Account\" loading={deleting} onClickButton={handleDelete} />\n </Cluster>\n </>\n ) : (\n <Cluster>\n <Button size=\"small\" type=\"secondary\" color=\"danger\" state=\"enabled\" label=\"Delete Account\" onClickButton={() => setConfirming(true)} />\n </Cluster>\n )}\n </Stack>\n )}\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
|
|
1254
|
+
"uses": [
|
|
1255
|
+
"Button",
|
|
1256
|
+
"Center",
|
|
1257
|
+
"Cluster",
|
|
1258
|
+
"Heading",
|
|
1259
|
+
"Paragraph",
|
|
1260
|
+
"SettingsSection",
|
|
1261
|
+
"Stack",
|
|
1262
|
+
"TextField"
|
|
1263
|
+
]
|
|
1264
|
+
},
|
|
1265
|
+
{
|
|
1266
|
+
"id": "shown",
|
|
1267
|
+
"title": "Shown on its own page",
|
|
1268
|
+
"useWhen": "The page is about the one thing to delete or leave, such as a workspace.",
|
|
1269
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A workspace has a name, so the person types it.\nconst workspaceName = 'Acme';\n\nexport default function DangerZoneShown() {\n const [leaving, setLeaving] = useState(false);\n const [leaveOpen, setLeaveOpen] = useState(false);\n const [left, setLeft] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [typed, setTyped] = useState('');\n const [deleting, setDeleting] = useState(false);\n const [deleted, setDeleted] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // An exact match, with case. Pasting the name is fine.\n const matches = typed === workspaceName;\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleLeaveClose() {\n if (leaving) return;\n setLeaveOpen(false);\n }\n\n function handleLeave() {\n if (leaving) return;\n setLeaving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setLeaving(false);\n setLeaveOpen(false);\n setLeft(true);\n }, 1200);\n }\n\n function handleCancelDelete() {\n setConfirming(false);\n setTyped('');\n }\n\n function handleDelete() {\n if (deleting || !matches) return;\n setDeleting(true);\n timer.current = setTimeout(() => {\n setDeleting(false);\n setDeleted(true);\n }, 1200);\n }\n\n // The workspace is gone, or the person is out of it, so the page that showed it is gone too.\n if (left || deleted) {\n return (\n <Center fill>\n <Heading level={1} size=\"h5\">{deleted ? `${workspaceName} is deleted` : `You left ${workspaceName}`}</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">{deleted ? 'Everyone in it was told.' : 'An owner can invite you again.'}</Paragraph>\n </Center>\n );\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Heading level={1} size=\"h5\">Danger zone</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Leave or delete the Acme workspace.</Paragraph>\n </Stack>\n <SettingsSection tone=\"danger\" title=\"Leave workspace\" description=\"You lose access to Acme.\">\n <Paragraph size=\"body2\" measure=\"none\">Your messages and tasks stay in Acme. An owner can invite you again.</Paragraph>\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Leave Workspace\" onClickButton={() => setLeaveOpen(true)} />\n </Cluster>\n </SettingsSection>\n <SettingsSection tone=\"danger\" title=\"Delete workspace\" description=\"This cannot be undone.\">\n <Paragraph size=\"body2\" measure=\"none\">This deletes Acme, its 128 messages, 42 tasks and 9 documents. Every member keeps their own account, and files exported earlier stay where they are.</Paragraph>\n {confirming ? (\n <>\n <TextField id=\"danger-zone-shown-name\" label={`Type ${workspaceName} to confirm`} value={typed} disabled={deleting} onChange={(e) => setTyped(e.target.value)} />\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleCancelDelete} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state={matches ? 'enabled' : 'disabled'} label=\"Delete Workspace\" loading={deleting} onClickButton={handleDelete} />\n </Cluster>\n </>\n ) : (\n <Cluster>\n <Button size=\"small\" type=\"secondary\" color=\"danger\" state=\"enabled\" label=\"Delete Workspace\" onClickButton={() => setConfirming(true)} />\n </Cluster>\n )}\n </SettingsSection>\n </Stack>\n <Modal\n isOpen={leaveOpen}\n size=\"small\"\n title=\"Leave Workspace\"\n onClose={handleLeaveClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={leaving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleLeaveClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Leave\" loading={leaving} onClickButton={handleLeave} />\n </>\n }\n >\n <Paragraph measure=\"none\">You will lose access to Acme.</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Your messages and tasks stay in Acme. An owner can invite you again.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
|
|
1270
|
+
"uses": [
|
|
1271
|
+
"Button",
|
|
1272
|
+
"Center",
|
|
1273
|
+
"Cluster",
|
|
1274
|
+
"Heading",
|
|
1275
|
+
"Modal",
|
|
1276
|
+
"Paragraph",
|
|
1277
|
+
"SettingsSection",
|
|
1278
|
+
"Stack",
|
|
1279
|
+
"TextField"
|
|
1280
|
+
]
|
|
1281
|
+
}
|
|
1282
|
+
]
|
|
1283
|
+
},
|
|
1009
1284
|
{
|
|
1010
1285
|
"id": "device-login",
|
|
1011
1286
|
"title": "Device login",
|
|
@@ -1028,11 +1303,6 @@
|
|
|
1028
1303
|
"Do not leave a popup blank while it finishes.",
|
|
1029
1304
|
"Do not label a provider Button with its name alone, such as 'Google'. Write 'Continue with Google'."
|
|
1030
1305
|
],
|
|
1031
|
-
"notBuiltYet": "Scindo's CLI login shows 'Login successful!' as soon as its request to the CLI gets any reply. It sends that request in a way that leaves the page unable to read the CLI's reply, so it cannot tell whether the CLI took the login. Its provider Buttons read 'GitHub' and 'Google'. Commentify's popup shows nothing while it finishes.",
|
|
1032
|
-
"seenIn": [
|
|
1033
|
-
"Commentify",
|
|
1034
|
-
"Scindo"
|
|
1035
|
-
],
|
|
1036
1306
|
"options": [
|
|
1037
1307
|
{
|
|
1038
1308
|
"id": "provider-first",
|
|
@@ -1083,11 +1353,6 @@
|
|
|
1083
1353
|
"Do not ask the person to log in again in the browser where they are already logged in.",
|
|
1084
1354
|
"Do not make the person close the success Alert."
|
|
1085
1355
|
],
|
|
1086
|
-
"notBuiltYet": "Scindo on the web shows its success Alert above the login form with a close button. Commentify has no confirmed page and no Alert for it: the link goes straight to the dashboard.",
|
|
1087
|
-
"seenIn": [
|
|
1088
|
-
"Commentify",
|
|
1089
|
-
"Scindo"
|
|
1090
|
-
],
|
|
1091
1356
|
"options": [
|
|
1092
1357
|
{
|
|
1093
1358
|
"id": "page",
|
|
@@ -1141,11 +1406,6 @@
|
|
|
1141
1406
|
"Do not show the empty text while the list is still loading."
|
|
1142
1407
|
],
|
|
1143
1408
|
"native": "On Apple use `ContentUnavailableView`, with the same words.",
|
|
1144
|
-
"notBuiltYet": "Commentify writes most of its empty lists in Title Case, such as 'No Comments Available', and gives them no `secondText`.",
|
|
1145
|
-
"seenIn": [
|
|
1146
|
-
"Commentify",
|
|
1147
|
-
"Scindo"
|
|
1148
|
-
],
|
|
1149
1409
|
"options": [
|
|
1150
1410
|
{
|
|
1151
1411
|
"id": "region",
|
|
@@ -1198,14 +1458,7 @@
|
|
|
1198
1458
|
"Do not use the system's words, such as 'No data' or 'No records found'.",
|
|
1199
1459
|
"Do not pass an `action` the person is not allowed to use."
|
|
1200
1460
|
],
|
|
1201
|
-
"native": "On Apple use `ContentUnavailableView`, with the same words."
|
|
1202
|
-
"notBuiltYet": "Scindo on the web uses `EmptyBox` in three places and bare text elsewhere, such as 'No API keys yet.' Commentify uses `EmptyBox` in most lists and bare text in a few. Commentify admin and jinhwankim.com show bare text. No product passes an `action` yet.",
|
|
1203
|
-
"seenIn": [
|
|
1204
|
-
"Commentify",
|
|
1205
|
-
"Commentify admin",
|
|
1206
|
-
"Scindo",
|
|
1207
|
-
"jinhwankim.com"
|
|
1208
|
-
]
|
|
1461
|
+
"native": "On Apple use `ContentUnavailableView`, with the same words."
|
|
1209
1462
|
},
|
|
1210
1463
|
{
|
|
1211
1464
|
"id": "empty-not-set-up",
|
|
@@ -1225,11 +1478,6 @@
|
|
|
1225
1478
|
"Do not offer more than one Button."
|
|
1226
1479
|
],
|
|
1227
1480
|
"native": "On Apple use `ContentUnavailableView`, with the Button in its `actions`.",
|
|
1228
|
-
"notBuiltYet": "Commentify puts its 'Open Settings' Button under `EmptyBox`, not in its `action`, and writes the text in Title Case: 'No App, Team, or User Connected'.",
|
|
1229
|
-
"seenIn": [
|
|
1230
|
-
"Commentify",
|
|
1231
|
-
"Scindo"
|
|
1232
|
-
],
|
|
1233
1481
|
"options": [
|
|
1234
1482
|
{
|
|
1235
1483
|
"id": "action",
|
|
@@ -1278,11 +1526,6 @@
|
|
|
1278
1526
|
"Do not clear the search field unless the person asks."
|
|
1279
1527
|
],
|
|
1280
1528
|
"native": "On Apple use `ContentUnavailableView.search(text:)`.",
|
|
1281
|
-
"notBuiltYet": "Scindo on the web shows a bare line, 'No results found', with no words and no way to clear them. Scindo on Apple shows 'No results found' in a `ContentUnavailableView`, without the words. Commentify shows the words in an `EmptyBox`, with no Clear Search Button.",
|
|
1282
|
-
"seenIn": [
|
|
1283
|
-
"Commentify",
|
|
1284
|
-
"Scindo"
|
|
1285
|
-
],
|
|
1286
1529
|
"options": [
|
|
1287
1530
|
{
|
|
1288
1531
|
"id": "clear-search",
|
|
@@ -1318,12 +1561,6 @@
|
|
|
1318
1561
|
"Do not show a line of text with no way out.",
|
|
1319
1562
|
"Do not hide the navigation when only one route failed."
|
|
1320
1563
|
],
|
|
1321
|
-
"notBuiltYet": "Scindo on the web shows the error's own message and its id. Commentify shows one line and 'Try again', with no heading and no way home. jinhwankim.com shows an `EmptyBox` with no Button.",
|
|
1322
|
-
"seenIn": [
|
|
1323
|
-
"Commentify",
|
|
1324
|
-
"Scindo",
|
|
1325
|
-
"jinhwankim.com"
|
|
1326
|
-
],
|
|
1327
1564
|
"options": [
|
|
1328
1565
|
{
|
|
1329
1566
|
"id": "full-page",
|
|
@@ -1343,17 +1580,18 @@
|
|
|
1343
1580
|
"id": "in-shell",
|
|
1344
1581
|
"title": "Inside the shell",
|
|
1345
1582
|
"useWhen": "One route failed and the navigation still works.",
|
|
1346
|
-
"source": "'use client';\nimport
|
|
1583
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport AppShell from 'oneslash-design-system/components/appShell';\nimport Navigation, { NavigationGroup } from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app passes the reset() its framework gives the error page, such as Next's error.tsx.\nconst reset = () => console.info('Render the page again');\n\n// The places, and the projects the person made. The page that failed or loads is the current one.\nconst places = [\n { label: 'Home', icon: 'House', href: '/' },\n { label: 'Settings', icon: 'Settings', href: '/settings' },\n];\nconst projects = [\n { label: 'Website', icon: 'Globe', href: '/projects/website' },\n { label: 'Mobile App', icon: 'Smartphone', href: '/projects/mobile-app' },\n];\nconst current = '/projects/website';\n\nconst row = (p: { label: string; icon: string; href: string }) => (\n <MenuItem\n key={p.href}\n size=\"small\"\n label={p.label}\n iconName={p.icon}\n href={p.href}\n isSelected={p.href === current}\n aria-current={p.href === current ? 'page' : undefined}\n // A real app lets the link go to its page.\n onClick={(event: { preventDefault: () => void }) => event.preventDefault()}\n />\n);\n\nconst sidebar = (\n <Navigation aria-label=\"Main\">\n <Paragraph size=\"body1\" measure=\"none\">Acme</Paragraph>\n {places.map(row)}\n <NavigationGroup label=\"Projects\">{projects.map(row)}</NavigationGroup>\n </Navigation>\n);\n\nexport default function ErrorPageInShell() {\n // Below md the sidebar is a Drawer; this says whether it is open.\n const [navOpen, setNavOpen] = useState(false);\n return (\n <AppShell title=\"Website\" navOpen={navOpen} onNavOpenChange={setNavOpen} sidebar={sidebar}>\n <Surface minHeight=\"tall\" align=\"center\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Something went wrong</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">This page could not load. Try again, or go back to the home page.</Paragraph>\n </Stack>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Try Again\" onClickButton={reset} />\n <Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Go Home\" href=\"/\" />\n </Cluster>\n </Stack>\n </Surface>\n </AppShell>\n );\n}\n",
|
|
1347
1584
|
"uses": [
|
|
1585
|
+
"AppShell",
|
|
1348
1586
|
"Button",
|
|
1349
1587
|
"Cluster",
|
|
1350
1588
|
"Heading",
|
|
1351
|
-
"
|
|
1589
|
+
"MenuItem",
|
|
1590
|
+
"Navigation",
|
|
1591
|
+
"NavigationGroup",
|
|
1352
1592
|
"Paragraph",
|
|
1353
1593
|
"Stack",
|
|
1354
|
-
"Surface"
|
|
1355
|
-
"Tab",
|
|
1356
|
-
"TabsContainer"
|
|
1594
|
+
"Surface"
|
|
1357
1595
|
]
|
|
1358
1596
|
}
|
|
1359
1597
|
]
|
|
@@ -1382,10 +1620,6 @@
|
|
|
1382
1620
|
"Do not fail without a word. Say that the feedback was not sent.",
|
|
1383
1621
|
"Do not clear what the person wrote when sending fails."
|
|
1384
1622
|
],
|
|
1385
|
-
"notBuiltYet": "Scindo's feedback form labels the Button 'Sending...' while it runs, shows no error when sending fails, and replaces the form with a thank-you that closes after 1.5 seconds. It labels its fields with captions written by hand.",
|
|
1386
|
-
"seenIn": [
|
|
1387
|
-
"Scindo"
|
|
1388
|
-
],
|
|
1389
1623
|
"options": [
|
|
1390
1624
|
{
|
|
1391
1625
|
"id": "modal",
|
|
@@ -1410,6 +1644,73 @@
|
|
|
1410
1644
|
}
|
|
1411
1645
|
]
|
|
1412
1646
|
},
|
|
1647
|
+
{
|
|
1648
|
+
"id": "filter-menu",
|
|
1649
|
+
"title": "Filter menu",
|
|
1650
|
+
"kind": "design",
|
|
1651
|
+
"level": "organism",
|
|
1652
|
+
"area": "menu",
|
|
1653
|
+
"situation": "A person narrows a list by one choice, such as a date range, or turns the filter off.",
|
|
1654
|
+
"do": [
|
|
1655
|
+
"Open a navigable menu from an `IconButton`: `<Popover returnFocus>` around `<Menu navigable aria-label=\"Filter by date\">` with `onClick` items.",
|
|
1656
|
+
"Pass `event.currentTarget` to the Popover as `anchorEl`, and set `state=\"selected\"` on the button while the menu is open.",
|
|
1657
|
+
"Give the button `color=\"secondary\"` while a filter is on.",
|
|
1658
|
+
"Say the current filter in the button's `ariaLabel`: 'Filter by date: Last 7 days'.",
|
|
1659
|
+
"Show the current filter in a `Tooltip` on the button, such as 'Last 7 days'.",
|
|
1660
|
+
"Give each item `role=\"menuitemradio\"` and mark the current one with `isSelected`. It sets `aria-checked`, so a screen reader says which one is on.",
|
|
1661
|
+
"Write each choice in Title Case, such as 'Last 24 Hours', and close the menu when one is chosen.",
|
|
1662
|
+
"Add 'Clear Filter' last, after a `Line`, when the filter can be off. Show it only while a filter is on.",
|
|
1663
|
+
"Show what the list holds under the heading, such as how many comments the filter leaves.",
|
|
1664
|
+
"Use the case 'Range switch' instead when two to four ranges are the page's main view and the header has room."
|
|
1665
|
+
],
|
|
1666
|
+
"dont": [
|
|
1667
|
+
"Do not use a Tooltip as the only place that names the current filter.",
|
|
1668
|
+
"Do not mark the current choice with color only.",
|
|
1669
|
+
"Do not keep the menu open after a choice.",
|
|
1670
|
+
"Do not add a custom date range in a menu. ODS has no date picker yet.",
|
|
1671
|
+
"Do not put a destructive item in a filter menu."
|
|
1672
|
+
],
|
|
1673
|
+
"native": "On Apple use a `Menu` with a `Picker` inside it, so the current choice gets a check mark. On Android use a dropdown menu with radio items.",
|
|
1674
|
+
"options": [
|
|
1675
|
+
{
|
|
1676
|
+
"id": "presets",
|
|
1677
|
+
"title": "Presets",
|
|
1678
|
+
"useWhen": "The choices are dates or a few fixed choices, and one is always on.",
|
|
1679
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app counts these on the server. `label` is the menu item, in Title Case. `current` names the\n// choice in the button's name, its tooltip and the line, in sentence case.\nconst filters = [\n { value: 'day', label: 'Last 24 Hours', current: 'Last 24 hours', count: 4 },\n { value: 'week', label: 'Last 7 Days', current: 'Last 7 days', count: 18 },\n { value: 'month', label: 'Last 30 Days', current: 'Last 30 days', count: 64 },\n { value: 'quarter', label: 'Last 90 Days', current: 'Last 90 days', count: 171 },\n { value: 'all', label: 'All Time', current: 'All time', count: 240 },\n];\n\nexport default function FilterMenuPresets() {\n const [value, setValue] = useState('week');\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const current = filters.find((f) => f.value === value) ?? filters[1];\n\n // The trigger toggles the menu. Popover's returnFocus gives focus back to it on close.\n function toggle(anchorEl: HTMLElement) {\n setAnchor(anchorEl);\n setOpen((o) => !o);\n }\n\n function choose(next: string) {\n setValue(next);\n setOpen(false);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Comments</Heading>\n {/* The tooltip names the current filter, and so does the button's name. A filter that is on\n shows in a filled button; 'All Time' filters nothing, so the button is plain. */}\n <Tooltip title={current.current}>\n <IconButton\n color={value === 'all' ? 'iconOnly' : 'secondary'}\n state={open ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"ListFilter\"\n ariaLabel={`Filter by date: ${current.current}`}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n onClick={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{current.count} comments, {current.current.toLowerCase()}.</Paragraph>\n </Stack>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Filter by date\" width={200}>\n {filters.map((f) => (\n <MenuItem\n key={f.value}\n size=\"small\"\n label={f.label}\n isSelected={f.value === value}\n role=\"menuitemradio\"\n onClick={() => choose(f.value)}\n />\n ))}\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
|
|
1680
|
+
"uses": [
|
|
1681
|
+
"Center",
|
|
1682
|
+
"Cluster",
|
|
1683
|
+
"Heading",
|
|
1684
|
+
"IconButton",
|
|
1685
|
+
"Menu",
|
|
1686
|
+
"MenuItem",
|
|
1687
|
+
"Paragraph",
|
|
1688
|
+
"Popover",
|
|
1689
|
+
"Stack",
|
|
1690
|
+
"Tooltip"
|
|
1691
|
+
]
|
|
1692
|
+
},
|
|
1693
|
+
{
|
|
1694
|
+
"id": "with-clear",
|
|
1695
|
+
"title": "Presets with Clear Filter",
|
|
1696
|
+
"useWhen": "The filter can be off, so the list shows everything until the person picks a choice.",
|
|
1697
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server. `label` is the menu item, in Title Case. `current` names the\n// choice in the button's name, its tooltip and the line, in sentence case.\nconst filters = [\n { value: 'mentions', label: 'Mentions', current: 'Mentions', count: 3 },\n { value: 'unread', label: 'Unread', current: 'Unread', count: 5 },\n { value: 'assigned', label: 'Assigned to Me', current: 'Assigned to me', count: 2 },\n];\nconst total = 12;\n\nexport default function FilterMenuWithClear() {\n // null means the filter is off.\n const [value, setValue] = useState<string | null>('unread');\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const current = filters.find((f) => f.value === value);\n\n function toggle(anchorEl: HTMLElement) {\n setAnchor(anchorEl);\n setOpen((o) => !o);\n }\n\n function choose(next: string | null) {\n setValue(next);\n setOpen(false);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Inbox</Heading>\n {/* A filter that is on shows in a filled button. When it is off the button is plain. */}\n <Tooltip title={current ? current.current : 'Filter messages'}>\n <IconButton\n color={current ? 'secondary' : 'iconOnly'}\n state={open ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"ListFilter\"\n ariaLabel={current ? `Filter messages: ${current.current}` : 'Filter messages'}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n onClick={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {current ? `${current.count} of ${total} messages, ${current.current.toLowerCase()}.` : `All ${total} messages.`}\n </Paragraph>\n </Stack>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Filter messages\" width={200}>\n {filters.map((f) => (\n <MenuItem\n key={f.value}\n size=\"small\"\n label={f.label}\n isSelected={f.value === value}\n role=\"menuitemradio\"\n onClick={() => choose(f.value)}\n />\n ))}\n {/* Clear is last, and shows only while a filter is on. */}\n {current && <Line />}\n {current && <MenuItem size=\"small\" iconName=\"X\" label=\"Clear Filter\" onClick={() => choose(null)} />}\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
|
|
1698
|
+
"uses": [
|
|
1699
|
+
"Center",
|
|
1700
|
+
"Cluster",
|
|
1701
|
+
"Heading",
|
|
1702
|
+
"IconButton",
|
|
1703
|
+
"Line",
|
|
1704
|
+
"Menu",
|
|
1705
|
+
"MenuItem",
|
|
1706
|
+
"Paragraph",
|
|
1707
|
+
"Popover",
|
|
1708
|
+
"Stack",
|
|
1709
|
+
"Tooltip"
|
|
1710
|
+
]
|
|
1711
|
+
}
|
|
1712
|
+
]
|
|
1713
|
+
},
|
|
1413
1714
|
{
|
|
1414
1715
|
"id": "forgot-password",
|
|
1415
1716
|
"title": "Forgot password",
|
|
@@ -1433,11 +1734,6 @@
|
|
|
1433
1734
|
"Do not replace the form with a spinner while sending the link."
|
|
1434
1735
|
],
|
|
1435
1736
|
"native": "On Apple, put 'Forgot Password?' under the 'Log In' Button and open the web reset form from it.",
|
|
1436
|
-
"notBuiltYet": "Commentify and Scindo on the web replace the form with a spinner while sending the link. Both then say 'We sent a password reset link to' the address, even when it has no account.",
|
|
1437
|
-
"seenIn": [
|
|
1438
|
-
"Commentify",
|
|
1439
|
-
"Scindo"
|
|
1440
|
-
],
|
|
1441
1737
|
"options": [
|
|
1442
1738
|
{
|
|
1443
1739
|
"id": "in-place",
|
|
@@ -1504,12 +1800,6 @@
|
|
|
1504
1800
|
"Do not use the browser's `alert()`.",
|
|
1505
1801
|
"Do not clear the form after a failed submit.",
|
|
1506
1802
|
"Do not change the submit Button's label while it is loading, such as to 'Saving…'."
|
|
1507
|
-
],
|
|
1508
|
-
"notBuiltYet": "Commentify writes red captions by hand on its consent screen and in its Figma import dialog. Scindo on the web does the same in its dialogs, such as renaming a workspace or a task. Commentify uses the browser's `alert()` in three files, and Scindo on the web in one.",
|
|
1509
|
-
"seenIn": [
|
|
1510
|
-
"Commentify",
|
|
1511
|
-
"Scindo",
|
|
1512
|
-
"jinhwankim.com"
|
|
1513
1803
|
]
|
|
1514
1804
|
},
|
|
1515
1805
|
{
|
|
@@ -1537,10 +1827,6 @@
|
|
|
1537
1827
|
"Do not clear the selection when the person searches.",
|
|
1538
1828
|
"Do not show a bare line of text when the list is empty or nothing matches."
|
|
1539
1829
|
],
|
|
1540
|
-
"notBuiltYet": "Scindo's Notion import labels its Buttons 'Select all' and 'Import', changes the action to 'Importing… 1/2' while it runs, and shows bare text when nothing matches.",
|
|
1541
|
-
"seenIn": [
|
|
1542
|
-
"Scindo"
|
|
1543
|
-
],
|
|
1544
1830
|
"options": [
|
|
1545
1831
|
{
|
|
1546
1832
|
"id": "modal",
|
|
@@ -1584,10 +1870,6 @@
|
|
|
1584
1870
|
"Do not say 'successfully'."
|
|
1585
1871
|
],
|
|
1586
1872
|
"native": "On Apple there is no toast. Show the result in place.",
|
|
1587
|
-
"notBuiltYet": "Scindo on the web labels its save Buttons 'Saving...' while they save. Its profile settings show nothing when a save fails. Its instructions settings show the error's own message in an inline Alert with no close button.",
|
|
1588
|
-
"seenIn": [
|
|
1589
|
-
"Scindo"
|
|
1590
|
-
],
|
|
1591
1873
|
"options": [
|
|
1592
1874
|
{
|
|
1593
1875
|
"id": "button-label",
|
|
@@ -1643,6 +1925,77 @@
|
|
|
1643
1925
|
}
|
|
1644
1926
|
]
|
|
1645
1927
|
},
|
|
1928
|
+
{
|
|
1929
|
+
"id": "integrations-list",
|
|
1930
|
+
"title": "Integrations",
|
|
1931
|
+
"kind": "design",
|
|
1932
|
+
"level": "organism",
|
|
1933
|
+
"area": "settings",
|
|
1934
|
+
"situation": "A person connects the product to other tools, sees which ones are connected and disconnects them.",
|
|
1935
|
+
"do": [
|
|
1936
|
+
"Show each provider in a row: its logo, its name and one line on what connecting does: 'Link pull requests to tasks and close tasks when they merge.'",
|
|
1937
|
+
"Use `BrandIcon` for a logo it has, and a Lucide icon in `Icon` for the others. Both are decorative, because the name sits beside them.",
|
|
1938
|
+
"Show 'Connect' on a provider that is not connected, and its account beside 'Disconnect' once it is. Name the provider in each `aria-label`: 'Connect Slack'.",
|
|
1939
|
+
"Show a `Tag` with `color=\"warning\"` that reads 'Needs attention', and a primary 'Reconnect', on a connection whose access ran out. Say in the line what is wrong.",
|
|
1940
|
+
"Confirm 'Disconnect' in a small Modal, as the rule 'A confirm says exactly what will happen' says, because what it stops does not come back by itself. Title it with the verb and the thing: 'Disconnect Slack', or 'Disconnect acme-labs' for one account. Say what stops and that the person can connect again.",
|
|
1941
|
+
"Show `loading` on 'Connect' and 'Reconnect' while the sign-in runs, and keep the label. Disable the other Buttons until it ends.",
|
|
1942
|
+
"Group the accounts under their provider, with 'Add Account' on the provider's row, for a provider that holds several. Each account has its own 'Reconnect' and 'Disconnect'.",
|
|
1943
|
+
"Name the account in each account's `aria-label`: 'Disconnect acme-labs'. Disconnecting one account leaves the others connected.",
|
|
1944
|
+
"Show a connection the person cannot change as read-only, with one line that says who can: 'Only admins can change this.'"
|
|
1945
|
+
],
|
|
1946
|
+
"dont": [
|
|
1947
|
+
"Do not use an icon-only Button for Disconnect. It names no provider.",
|
|
1948
|
+
"Do not label a running Button 'Connecting…'. It keeps its label and shows `loading`.",
|
|
1949
|
+
"Do not disconnect on the first click.",
|
|
1950
|
+
"Do not show red text as the only sign that access ran out. Add the 'Needs attention' Tag and a 'Reconnect' Button.",
|
|
1951
|
+
"Do not give each provider its own page section with a heading and no logo. Put them in one list."
|
|
1952
|
+
],
|
|
1953
|
+
"native": "On Apple use a grouped `Form` with one `Section` per provider, 'Connect' as a Button, and 'Disconnect' in the `.destructive` role in a `confirmationDialog`. On Android use a list of rows that opens a confirm.",
|
|
1954
|
+
"options": [
|
|
1955
|
+
{
|
|
1956
|
+
"id": "rows",
|
|
1957
|
+
"title": "One row per provider",
|
|
1958
|
+
"useWhen": "A few providers, and each one holds a single account.",
|
|
1959
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { Figma, Slack } from 'lucide-react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport BrandIcon from 'oneslash-design-system/components/brandIcon';\nimport Icon from 'oneslash-design-system/components/icon';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Provider = {\n id: string;\n name: string;\n /** One line on what connecting does. */\n does: string;\n /** What stops when it is disconnected, for the confirm. */\n stops: string;\n /** The account a person connects as, once connected. */\n account: string;\n brand?: 'google' | 'github';\n};\n\nconst providers: Provider[] = [\n { id: 'slack', name: 'Slack', does: 'Post the weekly digest and link previews in your channels.', stops: 'The weekly digest and link previews stop.', account: 'Acme workspace' },\n { id: 'github', name: 'GitHub', does: 'Link pull requests to tasks and close tasks when they merge.', stops: 'Pull requests stop linking to tasks.', account: 'acme', brand: 'github' },\n { id: 'google', name: 'Google Calendar', does: 'Show your calendar events beside your tasks.', stops: 'Calendar events stop showing beside tasks.', account: 'dana@acme.example', brand: 'google' },\n { id: 'figma', name: 'Figma', does: 'Show a preview when someone pastes a Figma link.', stops: 'Figma links stop showing a preview.', account: 'Acme team' },\n];\n\nfunction renderLogo(p: Provider) {\n if (p.brand) return <BrandIcon name={p.brand} size={24} />;\n return <Icon icon={p.id === 'slack' ? Slack : Figma} size=\"medium\" color=\"secondary\" />;\n}\n\nexport default function IntegrationsListRows() {\n // Opens with GitHub needing attention, as if its access ran out.\n const [connected, setConnected] = useState<Record<string, boolean>>({ github: true, google: true });\n const [needsAttention, setNeedsAttention] = useState<Record<string, boolean>>({ github: true });\n const [working, setWorking] = useState<string | null>(null);\n const [confirming, setConfirming] = useState<Provider | null>(null);\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n\n // Stops every request if the example goes away before they end.\n useEffect(() => () => timers.current.forEach(clearTimeout), []);\n\n // Stands in for the sign-in a provider asks for, and the request that follows.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n function handleConnect(p: Provider) {\n if (working) return;\n setWorking(p.id);\n later(() => {\n setWorking(null);\n setConnected((current) => ({ ...current, [p.id]: true }));\n setNeedsAttention((current) => ({ ...current, [p.id]: false }));\n }, 1200);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (working) return;\n setConfirming(null);\n }\n\n function handleDisconnect(p: Provider) {\n if (working) return;\n setWorking(p.id);\n later(() => {\n setWorking(null);\n setConfirming(null);\n setConnected((current) => ({ ...current, [p.id]: false }));\n setNeedsAttention((current) => ({ ...current, [p.id]: false }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <Heading level={1} size=\"h5\">Integrations</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Connect the tools your team already uses.</Paragraph>\n </Stack>\n <TableContainer>\n {providers.map((p) => {\n const isConnected = Boolean(connected[p.id]);\n const attention = isConnected && Boolean(needsAttention[p.id]);\n const busy = working === p.id;\n return (\n <TableRow key={p.id}>\n <TableCell width=\"56px\">{renderLogo(p)}</TableCell>\n <TableCell>\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Heading level={2} size=\"subtitle1\">{p.name}</Heading>\n {attention && <Tag variant=\"contained\" size=\"small\" color=\"warning\" label=\"Needs attention\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {attention ? 'Access ran out. Reconnect to keep it working.' : p.does}\n </Paragraph>\n </Stack>\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"340px\">\n {isConnected ? (\n <Cluster gap=\"small\" justify=\"end\">\n <Paragraph size=\"body2\" measure=\"none\">{p.account}</Paragraph>\n {attention && <Button size=\"small\" type=\"primary\" state={working && !busy ? 'disabled' : 'enabled'} label=\"Reconnect\" aria-label={`Reconnect ${p.name}`} loading={busy} onClickButton={() => handleConnect(p)} />}\n <Button size=\"small\" type=\"tertiary\" state={working ? 'disabled' : 'enabled'} label=\"Disconnect\" aria-label={`Disconnect ${p.name}`} onClickButton={() => setConfirming(p)} />\n </Cluster>\n ) : (\n <Cluster gap=\"small\" justify=\"end\">\n <Button size=\"small\" type=\"secondary\" state={working && !busy ? 'disabled' : 'enabled'} label=\"Connect\" aria-label={`Connect ${p.name}`} loading={busy} onClickButton={() => handleConnect(p)} />\n </Cluster>\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n </Stack>\n <Modal\n isOpen={confirming !== null}\n size=\"small\"\n title={confirming ? `Disconnect ${confirming.name}` : 'Disconnect'}\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={working ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Disconnect\" loading={Boolean(working)} onClickButton={() => confirming && handleDisconnect(confirming)} />\n </>\n }\n >\n {confirming && (\n <Paragraph measure=\"none\">{confirming.stops} You can connect {confirming.name} again any time.</Paragraph>\n )}\n </Modal>\n </Center>\n );\n}\n",
|
|
1960
|
+
"uses": [
|
|
1961
|
+
"BrandIcon",
|
|
1962
|
+
"Button",
|
|
1963
|
+
"Center",
|
|
1964
|
+
"Cluster",
|
|
1965
|
+
"Heading",
|
|
1966
|
+
"Icon",
|
|
1967
|
+
"Modal",
|
|
1968
|
+
"Paragraph",
|
|
1969
|
+
"Stack",
|
|
1970
|
+
"TableCell",
|
|
1971
|
+
"TableContainer",
|
|
1972
|
+
"TableRow",
|
|
1973
|
+
"Tag"
|
|
1974
|
+
]
|
|
1975
|
+
},
|
|
1976
|
+
{
|
|
1977
|
+
"id": "nested",
|
|
1978
|
+
"title": "Accounts under each provider",
|
|
1979
|
+
"useWhen": "A provider can hold several accounts or teams, such as the organizations of one GitHub login.",
|
|
1980
|
+
"source": "'use client';\nimport { Fragment, useEffect, useRef, useState } from 'react';\nimport { Slack } from 'lucide-react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport BrandIcon from 'oneslash-design-system/components/brandIcon';\nimport Icon from 'oneslash-design-system/components/icon';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Account = { id: string; name: string; detail: string; attention?: boolean };\ntype Provider = {\n id: string;\n name: string;\n /** One line on what connecting does. */\n does: string;\n /** What stops when one account is disconnected, for the confirm. */\n stops: string;\n brand?: 'github';\n accounts: Account[];\n};\n\nconst firstProviders: Provider[] = [\n {\n id: 'github',\n name: 'GitHub',\n does: 'Link pull requests to tasks and close tasks when they merge.',\n stops: 'Pull requests from it stop linking to tasks.',\n brand: 'github',\n accounts: [\n { id: 'acme', name: 'acme', detail: 'Connected Oct 3 · 14 repositories' },\n { id: 'acme-labs', name: 'acme-labs', detail: 'Access ran out. Reconnect to keep it working.', attention: true },\n ],\n },\n {\n id: 'slack',\n name: 'Slack',\n does: 'Post the weekly digest and link previews in your channels.',\n stops: 'The digest and link previews stop in its channels.',\n accounts: [],\n },\n];\n\nexport default function IntegrationsListNested() {\n const [providers, setProviders] = useState(firstProviders);\n // Which Button is working: it shows `loading`, and every other Button waits.\n const [working, setWorking] = useState<string | null>(null);\n const [confirming, setConfirming] = useState<{ provider: Provider; account: Account } | null>(null);\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n\n // Stops every request if the example goes away before they end.\n useEffect(() => () => timers.current.forEach(clearTimeout), []);\n\n // Stands in for the sign-in a provider asks for, and the request that follows.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n function update(providerId: string, change: (accounts: Account[]) => Account[]) {\n setProviders((list) => list.map((p) => (p.id === providerId ? { ...p, accounts: change(p.accounts) } : p)));\n }\n\n // 'Connect' and 'Add Account' both start a sign-in, and the account that comes back joins its provider.\n function handleAdd(p: Provider) {\n if (working) return;\n setWorking(`add-${p.id}`);\n later(() => {\n setWorking(null);\n const next: Account = p.id === 'github'\n ? { id: 'acme-design', name: 'acme-design', detail: 'Connected today · 3 repositories' }\n : { id: 'acme-slack', name: 'Acme', detail: 'Connected today · 6 channels' };\n update(p.id, (accounts) => [...accounts, next]);\n }, 1200);\n }\n\n function handleReconnect(p: Provider, a: Account) {\n if (working) return;\n setWorking(`reconnect-${a.id}`);\n later(() => {\n setWorking(null);\n update(p.id, (accounts) => accounts.map((x) => (x.id === a.id ? { ...x, detail: 'Connected today · 5 repositories', attention: false } : x)));\n }, 1200);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (working) return;\n setConfirming(null);\n }\n\n function handleDisconnect(p: Provider, a: Account) {\n if (working) return;\n setWorking(`remove-${a.id}`);\n later(() => {\n setWorking(null);\n setConfirming(null);\n update(p.id, (accounts) => accounts.filter((x) => x.id !== a.id));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Stack gap=\"small\">\n <Heading level={1} size=\"h5\">Integrations</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">A tool can hold several accounts. Each one connects and disconnects on its own.</Paragraph>\n </Stack>\n <TableContainer>\n {providers.map((p) => (\n <Fragment key={p.id}>\n <TableRow>\n <TableCell width=\"56px\">\n {p.brand ? <BrandIcon name={p.brand} size={24} /> : <Icon icon={Slack} size=\"medium\" color=\"secondary\" />}\n </TableCell>\n <TableCell>\n <Stack gap=\"small\">\n <Heading level={2} size=\"subtitle1\">{p.name}</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{p.does}</Paragraph>\n </Stack>\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"240px\">\n <Cluster justify=\"end\">\n <Button\n size=\"small\"\n type=\"secondary\"\n state={working && working !== `add-${p.id}` ? 'disabled' : 'enabled'}\n label={p.accounts.length === 0 ? 'Connect' : 'Add Account'}\n aria-label={p.accounts.length === 0 ? `Connect ${p.name}` : `Add Account to ${p.name}`}\n loading={working === `add-${p.id}`}\n onClickButton={() => handleAdd(p)}\n />\n </Cluster>\n </TableCell>\n </TableRow>\n {/* The accounts sit under their provider, indented by an empty first cell. */}\n {p.accounts.map((a) => (\n <TableRow key={a.id}>\n <TableCell width=\"56px\">{''}</TableCell>\n <TableCell>\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Heading level={3} size=\"subtitle1\">{a.name}</Heading>\n {a.attention && <Tag variant=\"contained\" size=\"small\" color=\"warning\" label=\"Needs attention\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{a.detail}</Paragraph>\n </Stack>\n </TableCell>\n <TableCell width=\"240px\">\n <Cluster gap=\"small\" justify=\"end\">\n {a.attention && (\n <Button size=\"small\" type=\"primary\" state={working && working !== `reconnect-${a.id}` ? 'disabled' : 'enabled'} label=\"Reconnect\" aria-label={`Reconnect ${a.name}`} loading={working === `reconnect-${a.id}`} onClickButton={() => handleReconnect(p, a)} />\n )}\n <Button size=\"small\" type=\"tertiary\" state={working ? 'disabled' : 'enabled'} label=\"Disconnect\" aria-label={`Disconnect ${a.name}`} onClickButton={() => setConfirming({ provider: p, account: a })} />\n </Cluster>\n </TableCell>\n </TableRow>\n ))}\n </Fragment>\n ))}\n </TableContainer>\n </Stack>\n <Modal\n isOpen={confirming !== null}\n size=\"small\"\n title={confirming ? `Disconnect ${confirming.account.name}` : 'Disconnect'}\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={working ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Disconnect\" loading={Boolean(working)} onClickButton={() => confirming && handleDisconnect(confirming.provider, confirming.account)} />\n </>\n }\n >\n {confirming && (\n <Paragraph measure=\"none\">\n {confirming.provider.stops} You can connect {confirming.account.name} again any time.\n </Paragraph>\n )}\n </Modal>\n </Center>\n );\n}\n",
|
|
1981
|
+
"uses": [
|
|
1982
|
+
"BrandIcon",
|
|
1983
|
+
"Button",
|
|
1984
|
+
"Center",
|
|
1985
|
+
"Cluster",
|
|
1986
|
+
"Heading",
|
|
1987
|
+
"Icon",
|
|
1988
|
+
"Modal",
|
|
1989
|
+
"Paragraph",
|
|
1990
|
+
"Stack",
|
|
1991
|
+
"TableCell",
|
|
1992
|
+
"TableContainer",
|
|
1993
|
+
"TableRow",
|
|
1994
|
+
"Tag"
|
|
1995
|
+
]
|
|
1996
|
+
}
|
|
1997
|
+
]
|
|
1998
|
+
},
|
|
1646
1999
|
{
|
|
1647
2000
|
"id": "invite-member",
|
|
1648
2001
|
"title": "Member invite",
|
|
@@ -1674,10 +2027,6 @@
|
|
|
1674
2027
|
"Do not touch `navigator` while the page renders. Copy only in the click handler."
|
|
1675
2028
|
],
|
|
1676
2029
|
"native": "On Apple use a sheet with a `Form`, share the link with `ShareLink`, and revoke a link with a `.destructive` Button that asks first in a `confirmationDialog`.",
|
|
1677
|
-
"notBuiltYet": "Scindo on the web replaces the fields with a spinner while it creates an invite, labels the way out 'Close' and reads 'Copied!'. It cancels an invite link on one click with no confirm. Scindo's Apple app cancels a pending invite with no confirm too.",
|
|
1678
|
-
"seenIn": [
|
|
1679
|
-
"Scindo"
|
|
1680
|
-
],
|
|
1681
2030
|
"options": [
|
|
1682
2031
|
{
|
|
1683
2032
|
"id": "by-email",
|
|
@@ -1747,11 +2096,6 @@
|
|
|
1747
2096
|
"Do not replace the whole page when only one section failed."
|
|
1748
2097
|
],
|
|
1749
2098
|
"native": "On Apple use `ContentUnavailableView`, with a 'Try Again' Button in its `actions`.",
|
|
1750
|
-
"notBuiltYet": "Scindo on the web shows its empty list, with no Try Again, when its API keys or its members fail to load. Commentify puts its 'Try again' Button under `EmptyBox`, not in its `action`.",
|
|
1751
|
-
"seenIn": [
|
|
1752
|
-
"Commentify",
|
|
1753
|
-
"Scindo"
|
|
1754
|
-
],
|
|
1755
2099
|
"options": [
|
|
1756
2100
|
{
|
|
1757
2101
|
"id": "region",
|
|
@@ -1807,12 +2151,6 @@
|
|
|
1807
2151
|
"Do not show a toast after logging out. The logged-out page says it."
|
|
1808
2152
|
],
|
|
1809
2153
|
"native": "On Apple use a system `confirmationDialog` titled 'Log Out', with a 'Log Out' Button and 'Cancel' in the `.cancel` role. Leave out the `.destructive` role: nothing is destroyed.",
|
|
1810
|
-
"notBuiltYet": "Scindo on the web says 'Log Out' but colors it as danger. Scindo on Apple says 'Sign Out' and puts it in the destructive role. Commentify and Commentify admin say 'Sign Out', title the Modal 'Confirm Sign Out', label the action 'Yes, Sign Out' and ask 'Are you sure you want to sign out?'.",
|
|
1811
|
-
"seenIn": [
|
|
1812
|
-
"Commentify",
|
|
1813
|
-
"Commentify admin",
|
|
1814
|
-
"Scindo"
|
|
1815
|
-
],
|
|
1816
2154
|
"options": [
|
|
1817
2155
|
{
|
|
1818
2156
|
"id": "modal",
|
|
@@ -1853,12 +2191,6 @@
|
|
|
1853
2191
|
"Do not say which of the email or the password was wrong."
|
|
1854
2192
|
],
|
|
1855
2193
|
"native": "On Apple use `SignInWithAppleButton` for Apple, a grouped form for the fields, and system buttons.",
|
|
1856
|
-
"notBuiltYet": "Commentify and Scindo on the web replace the form with a spinner while logging in. They do not use the Button's loading state yet.",
|
|
1857
|
-
"seenIn": [
|
|
1858
|
-
"Commentify",
|
|
1859
|
-
"Commentify admin",
|
|
1860
|
-
"Scindo"
|
|
1861
|
-
],
|
|
1862
2194
|
"options": [
|
|
1863
2195
|
{
|
|
1864
2196
|
"id": "centered",
|
|
@@ -1936,6 +2268,162 @@
|
|
|
1936
2268
|
}
|
|
1937
2269
|
]
|
|
1938
2270
|
},
|
|
2271
|
+
{
|
|
2272
|
+
"id": "master-detail",
|
|
2273
|
+
"title": "List and detail",
|
|
2274
|
+
"kind": "design",
|
|
2275
|
+
"level": "page",
|
|
2276
|
+
"area": "shell",
|
|
2277
|
+
"situation": "A person opens an item from a list, such as a message or a report, and reads or acts on it.",
|
|
2278
|
+
"do": [
|
|
2279
|
+
"Follow the rule 'On a phone, a sidebar opens as a drawer and a list opens its detail'.",
|
|
2280
|
+
"Use `SettingsLayout` with `navWidth=\"wide\"` for a list beside its detail. The list is a `Navigation` of `MenuItem` rows.",
|
|
2281
|
+
"Make each row a link with an `href`, so the open item has an address that can be shared and reloaded. Mark the open row with `isSelected` and `aria-current=\"page\"`.",
|
|
2282
|
+
"Keep one item open at all times from `md` up, the first at the start.",
|
|
2283
|
+
"Name the row with the sender or the title, and put the subject or the summary in `secondLabel`.",
|
|
2284
|
+
"Show the list first on a phone, then the detail alone with a Back Button named for the list: 'Back to Inbox'. Pass it as `back` of `SettingsLayout`.",
|
|
2285
|
+
"Title the page with a level 1 heading, such as 'Inbox'. The open item's title is a level 2 heading.",
|
|
2286
|
+
"Make each row of a list of long items a link to a page of its own. Put 'Back to Reports' in the page's `TitleBar` as `back`.",
|
|
2287
|
+
"Let 'Back to Reports' call the router's `back()` when the person came from the list, so the list keeps its scroll. Otherwise link to the list's address.",
|
|
2288
|
+
"After the person acts on an item, such as Archive, open the next one."
|
|
2289
|
+
],
|
|
2290
|
+
"dont": [
|
|
2291
|
+
"Do not show the list and the detail together on a phone.",
|
|
2292
|
+
"Do not leave the detail empty with nothing open on a wide screen. Open the first item.",
|
|
2293
|
+
"Do not keep the open item only in state. Give it an address.",
|
|
2294
|
+
"Do not name the Back Button 'Back'. Name the list it goes to.",
|
|
2295
|
+
"Do not use a split for long items that need the whole width."
|
|
2296
|
+
],
|
|
2297
|
+
"native": "On Apple use a `NavigationSplitView` with a list and a detail. On iPhone it shows the list, then pushes the detail with the system back button. On Android use a list-detail layout that shows one pane on a phone.",
|
|
2298
|
+
"options": [
|
|
2299
|
+
{
|
|
2300
|
+
"id": "split",
|
|
2301
|
+
"title": "List beside the detail",
|
|
2302
|
+
"useWhen": "The person works down the list, one item after another, such as an inbox.",
|
|
2303
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport Navigation from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport { SettingsLayout } from 'oneslash-design-system/components/settingsSection';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Message = { id: string; from: string; subject: string; time: string; body: string[] };\n\nconst messages: Message[] = [\n { id: 'launch-plan', from: 'Ben Carter', subject: 'Launch plan is ready', time: '9:12 AM', body: ['The plan is in the shared folder. It covers the announcement, the pricing page and the support hand-off.', 'Can you read the pricing part before noon? Omar Reyes is waiting on it.'] },\n { id: 'new-screens', from: 'Omar Reyes', subject: 'New screens for Friday', time: '8:40 AM', body: ['I added the new home page screens. The sign-up form now sits above the pricing table.', 'Tell me what to change by Thursday.'] },\n { id: 'invoice', from: 'Ben Carter', subject: 'Invoice for October', time: 'Yesterday', body: ['The invoice for October is attached. It includes the three new seats.'] },\n { id: 'offsite', from: 'Omar Reyes', subject: 'Team offsite in March', time: 'Monday', body: ['I found two dates for the offsite. Please say which one works for you.'] },\n];\n\nexport default function MasterDetailSplit() {\n // One message is always open, the first at the start.\n const [openId, setOpenId] = useState(messages[0].id);\n // On a phone the list is the screen until a message is chosen, and Back returns to it.\n const [showDetail, setShowDetail] = useState(false);\n\n const message = messages.find((m) => m.id === openId) ?? messages[0];\n\n const list = (\n <Navigation aria-label=\"Messages\">\n {messages.map((m) => (\n <MenuItem\n key={m.id}\n size=\"medium\"\n label={m.from}\n secondLabel={m.subject}\n href={`/inbox/${m.id}`}\n isSelected={m.id === message.id}\n aria-current={m.id === message.id ? 'page' : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to the message's own address, so it can be shared and reloaded. The example keeps the choice in state.\n event.preventDefault();\n setOpenId(m.id);\n setShowDetail(true);\n }}\n />\n ))}\n </Navigation>\n );\n\n return (\n <PageShell>\n <Stack gap=\"xlarge\">\n <Heading level={1} size=\"h5\">Inbox</Heading>\n <SettingsLayout\n navWidth=\"wide\"\n nav={list}\n showContent={showDetail}\n back={<Button size=\"small\" type=\"tertiary\" state=\"enabled\" decoIcon=\"ChevronLeft\" label=\"Back to Inbox\" onClickButton={() => setShowDetail(false)} />}\n >\n <Stack gap=\"small\">\n <Heading level={2} size=\"h6\">{message.subject}</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{message.from}, {message.time}</Paragraph>\n </Stack>\n <Stack gap=\"medium\">\n {message.body.map((paragraph) => (\n <Paragraph key={paragraph} measure=\"none\">{paragraph}</Paragraph>\n ))}\n </Stack>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Reply\" decoIcon=\"Reply\" />\n </Cluster>\n </SettingsLayout>\n </Stack>\n </PageShell>\n );\n}\n",
|
|
2304
|
+
"uses": [
|
|
2305
|
+
"Button",
|
|
2306
|
+
"Cluster",
|
|
2307
|
+
"Heading",
|
|
2308
|
+
"MenuItem",
|
|
2309
|
+
"Navigation",
|
|
2310
|
+
"PageShell",
|
|
2311
|
+
"Paragraph",
|
|
2312
|
+
"SettingsLayout",
|
|
2313
|
+
"Stack"
|
|
2314
|
+
]
|
|
2315
|
+
},
|
|
2316
|
+
{
|
|
2317
|
+
"id": "list-then-page",
|
|
2318
|
+
"title": "List, then a page for each item",
|
|
2319
|
+
"useWhen": "Each item is long and has its own address, such as a report.",
|
|
2320
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport Navigation from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\ntype Report = { id: string; title: string; summary: string; body: string[] };\n\nconst reports: Report[] = [\n {\n id: 'q3-review',\n title: 'Q3 review',\n summary: 'Revenue, churn and what changed since June.',\n body: [\n 'Revenue grew 12 percent over the quarter, led by the new team plan. Churn fell to 2.1 percent.',\n 'Support tickets about sign-up dropped by a third after the new form shipped in August.',\n 'The main risk is the pricing page, which still sends people to a contact form. Ben Carter owns the fix.',\n ],\n },\n {\n id: 'hiring-plan',\n title: 'Hiring plan',\n summary: 'Roles to open next half, and why.',\n body: [\n 'Two roles open in January: a designer for the web app and a support lead.',\n 'Omar Reyes will write both job posts. Dana Lee approves the budget on Monday.',\n ],\n },\n {\n id: 'roadmap',\n title: 'Roadmap',\n summary: 'What ships, in order, through March.',\n body: [\n 'The mobile app and the new billing page ship first. Integrations follow in February.',\n 'Each item lists its owner, its date and what must be true before it starts.',\n ],\n },\n];\n\nexport default function MasterDetailListThenPage() {\n const [openId, setOpenId] = useState<string | null>(null);\n const report = reports.find((r) => r.id === openId);\n\n // A real app goes to the page's address. Back calls the router's back() when the person came from the list, so the list keeps its scroll,\n // and otherwise links to the list's address. The example swaps the view.\n if (report) {\n return (\n <PageShell>\n <Stack gap=\"large\">\n <TitleBar\n title={report.title}\n back={<Button size=\"small\" type=\"tertiary\" state=\"enabled\" decoIcon=\"ChevronLeft\" label=\"Back to Reports\" onClickButton={() => setOpenId(null)} />}\n />\n {report.body.map((paragraph) => (\n <Paragraph key={paragraph} measure=\"body\">{paragraph}</Paragraph>\n ))}\n </Stack>\n </PageShell>\n );\n }\n\n return (\n <PageShell>\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Reports</Heading>\n <Navigation aria-label=\"Reports\">\n {reports.map((r) => (\n <MenuItem\n key={r.id}\n size=\"medium\"\n label={r.title}\n secondLabel={r.summary}\n iconRight=\"ChevronRight\"\n href={`/reports/${r.id}`}\n onClick={(event: { preventDefault: () => void }) => {\n event.preventDefault();\n setOpenId(r.id);\n }}\n />\n ))}\n </Navigation>\n </Stack>\n </PageShell>\n );\n}\n",
|
|
2321
|
+
"uses": [
|
|
2322
|
+
"Button",
|
|
2323
|
+
"Heading",
|
|
2324
|
+
"MenuItem",
|
|
2325
|
+
"Navigation",
|
|
2326
|
+
"PageShell",
|
|
2327
|
+
"Paragraph",
|
|
2328
|
+
"Stack",
|
|
2329
|
+
"TitleBar"
|
|
2330
|
+
]
|
|
2331
|
+
}
|
|
2332
|
+
]
|
|
2333
|
+
},
|
|
2334
|
+
{
|
|
2335
|
+
"id": "members-list",
|
|
2336
|
+
"title": "Members",
|
|
2337
|
+
"kind": "design",
|
|
2338
|
+
"level": "organism",
|
|
2339
|
+
"area": "settings",
|
|
2340
|
+
"situation": "An admin sees who is in the workspace, changes their roles, removes people and invites more.",
|
|
2341
|
+
"do": [
|
|
2342
|
+
"Show each member in a row: `UserImage` with `decorative`, the name, the email and the role. The avatar sits beside the same name, so it is hidden from a screen reader.",
|
|
2343
|
+
"Give an admin a `Select` for the role in each row. It saves as soon as it changes, as the rule 'A setting saves in place, or with one Save Button' says. Show no toast. When the save fails, put the old role back and show an inline `Alert` with `type=\"error\"` under the Select, which a screen reader announces. Point the Select's `aria-describedby` at the Alert's `id`.",
|
|
2344
|
+
"Give each role `Select` an `aria-label` that names the person: 'Role for Ben Carter'.",
|
|
2345
|
+
"Show a person who is not an admin the role as plain text, with one line at the top: 'Only admins can change this.' They get no Select, Remove or invites.",
|
|
2346
|
+
"Show your own role as text with a 'You' Tag, and give your row no Remove.",
|
|
2347
|
+
"Confirm 'Remove' in the row, as the case 'Delete confirm' does: the row asks 'Remove Ben Carter?' and shows 'Cancel' and a danger 'Remove'. Then show a toast: 'Ben Carter removed from Acme.'",
|
|
2348
|
+
"Give each row's 'Remove', and the confirm's 'Cancel' and 'Remove', an `aria-label` that names the person: 'Remove Ben Carter' and 'Cancel removing Ben Carter'.",
|
|
2349
|
+
"List pending invites under the members. Each has 'Copy Link', which reads 'Copied' for 2 seconds, and 'Revoke Invite'.",
|
|
2350
|
+
"Confirm 'Revoke Invite' in the row before it ends the link: the row shows 'Cancel' and a danger 'Revoke'. Then show a toast: 'Invite for sam@partner.example revoked.'",
|
|
2351
|
+
"Name the invite in each `aria-label`: 'Revoke invite for sam@partner.example' and 'Cancel revoking the invite for sam@partner.example'.",
|
|
2352
|
+
"Open the Modal of the case 'Member invite' from an 'Invite Member' Button. Count a pending invite as a seat, because it holds one until it is accepted or revoked.",
|
|
2353
|
+
"Keep 'Invite Member' pressable at the seat limit. Open the Modal of the case 'Upgrade prompt', titled 'Upgrade to Pro', that says all the seats are filled.",
|
|
2354
|
+
"Say how many seats are used under the title: '7 of 8 seats used on the Free plan.'",
|
|
2355
|
+
"Sort a table by a Button in the header cell. `TableHeaderCell` has no `aria-sort`, so the Button's `aria-label` says the state and what a press does: 'Name, sorted ascending. Sort descending.'",
|
|
2356
|
+
"Use `state=\"selected\"` and an arrow on the Button of the column that is sorted. The first press sorts A to Z and the next one reverses it."
|
|
2357
|
+
],
|
|
2358
|
+
"dont": [
|
|
2359
|
+
"Do not show a role Select in a row of a person who cannot change roles, or in your own row.",
|
|
2360
|
+
"Do not remove a member on the first click of 'Remove'.",
|
|
2361
|
+
"Do not ask 'Are you sure?'. Name the person in the question.",
|
|
2362
|
+
"Do not disable 'Invite Member' at the seat limit. Let the person press it and learn why.",
|
|
2363
|
+
"Do not leave a Select without a name that says whose role it sets.",
|
|
2364
|
+
"Do not show a failed role save as red text written by hand. Use an inline `Alert`, or the error line of `FormField` when the control has a visible label.",
|
|
2365
|
+
"Do not label a running Button 'Removing…'. It keeps its label and shows `loading`."
|
|
2366
|
+
],
|
|
2367
|
+
"native": "On Apple use a `Table` with a `Picker` for the role, and a `.destructive` Button that asks in a `confirmationDialog`. On Android use a list with a menu for the role and a confirm for Remove.",
|
|
2368
|
+
"options": [
|
|
2369
|
+
{
|
|
2370
|
+
"id": "rows",
|
|
2371
|
+
"title": "A list of rows",
|
|
2372
|
+
"useWhen": "A workspace of a few dozen people, so the whole list fits and a person finds someone by looking.",
|
|
2373
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Select from 'oneslash-design-system/components/select';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Member = { id: string; name: string; email: string; role: string };\ntype Invite = { id: string; email: string; sent: string; link: string };\n\n// A real app reads these from the signed-in person and the plan.\nconst youId = 'dana';\nconst canManage = true;\nconst seatLimit = 8;\n\nconst roleOptions = [\n { value: 'Admin', label: 'Admin' },\n { value: 'Member', label: 'Member' },\n { value: 'Guest', label: 'Guest' },\n];\n\nconst firstMembers: Member[] = [\n { id: 'dana', name: 'Dana Lee', email: 'dana@acme.example', role: 'Admin' },\n { id: 'ben', name: 'Ben Carter', email: 'ben@acme.example', role: 'Member' },\n { id: 'omar', name: 'Omar Reyes', email: 'omar@acme.example', role: 'Member' },\n { id: 'mei', name: 'Mei Tanaka', email: 'mei@acme.example', role: 'Member' },\n { id: 'luis', name: 'Luis Ortega', email: 'luis@acme.example', role: 'Guest' },\n];\n\nconst firstInvites: Invite[] = [\n { id: 'i1', email: 'priya@acme.example', sent: 'Sent 2 days ago', link: 'https://acme.example/join/k7Qm2xLp' },\n { id: 'i2', email: 'sam@partner.example', sent: 'Sent 5 days ago', link: 'https://acme.example/join/b4Tn8zVw' },\n];\n\n// Stands in for a save that does not go through: Omar's role never saves.\nconst failsFor = 'omar';\nconst failedMessage = 'Could not save. Try again.';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function MembersListRows() {\n const [members, setMembers] = useState(firstMembers);\n const [invites, setInvites] = useState(firstInvites);\n const [roles, setRoles] = useState<Record<string, string>>(() => Object.fromEntries(firstMembers.map((m) => [m.id, m.role])));\n const [savingRole, setSavingRole] = useState<string | null>(null);\n // Opens on a failed save, as if the person just changed Omar Reyes's role.\n const [roleErrors, setRoleErrors] = useState<Record<string, string>>({ omar: failedMessage });\n // Opens with one row confirming, as if the person just chose Remove on it.\n const [confirmingMember, setConfirmingMember] = useState<string | null>('ben');\n const [confirmingInvite, setConfirmingInvite] = useState<string | null>(null);\n const [busyRow, setBusyRow] = useState<string | null>(null);\n const [copiedInvite, setCopiedInvite] = useState<string | null>(null);\n const [copyBlocked, setCopyBlocked] = useState<string | null>(null);\n\n const [inviteOpen, setInviteOpen] = useState(false);\n const [email, setEmail] = useState('');\n const [emailError, setEmailError] = useState('');\n const [sending, setSending] = useState(false);\n const [upgradeOpen, setUpgradeOpen] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n // Gives each new invite its own id, so no two rows share a key.\n const inviteCount = useRef(0);\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n timers.current.forEach(clearTimeout);\n clearTimeout(copyTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // A pending invite holds a seat until it is accepted or revoked.\n const seatsUsed = members.length + invites.length;\n const atSeatLimit = seatsUsed >= seatLimit;\n const address = email.trim();\n\n // The role is one control on its own, so it saves as soon as it changes. Nothing shows when it works.\n function handleRoleChange(member: Member, next: string) {\n if (savingRole) return;\n const before = roles[member.id];\n setRoleErrors((current) => ({ ...current, [member.id]: '' }));\n setSavingRole(member.id);\n setRoles((current) => ({ ...current, [member.id]: next }));\n later(() => {\n setSavingRole(null);\n if (member.id === failsFor) {\n setRoles((current) => ({ ...current, [member.id]: before }));\n setRoleErrors((current) => ({ ...current, [member.id]: failedMessage }));\n }\n }, 900);\n }\n\n // Starting a confirm on one row cancels the confirm on any other.\n function startConfirm(kind: 'member' | 'invite', id: string) {\n setConfirmingMember(kind === 'member' ? id : null);\n setConfirmingInvite(kind === 'invite' ? id : null);\n }\n\n function handleRemove(member: Member) {\n if (busyRow) return;\n setBusyRow(member.id);\n later(() => {\n setBusyRow(null);\n setConfirmingMember(null);\n setMembers((list) => list.filter((m) => m.id !== member.id));\n toastIds.current.push(toast({ type: 'success', message: `${member.name} removed from Acme.` }));\n }, 1200);\n }\n\n function handleRevokeInvite(invite: Invite) {\n if (busyRow) return;\n setBusyRow(invite.id);\n later(() => {\n setBusyRow(null);\n setConfirmingInvite(null);\n setInvites((list) => list.filter((i) => i.id !== invite.id));\n toastIds.current.push(toast({ type: 'success', message: `Invite for ${invite.email} revoked.` }));\n }, 1200);\n }\n\n // Only reads 'Copied' when the link reached the clipboard. When the browser has no\n // clipboard or refuses the write, a line under the row says so.\n function handleCopy(invite: Invite) {\n clearTimeout(copyTimer.current);\n setCopiedInvite(null);\n const blocked = () => {\n if (mounted.current) setCopyBlocked(invite.id);\n };\n if (!navigator.clipboard) {\n blocked();\n return;\n }\n navigator.clipboard.writeText(invite.link).then(() => {\n if (!mounted.current) return;\n setCopyBlocked(null);\n setCopiedInvite(invite.id);\n copyTimer.current = setTimeout(() => setCopiedInvite(null), 2000);\n }, blocked);\n }\n\n // At the seat limit the Button still works: it tells the person why they cannot invite.\n function handleInviteMember() {\n if (atSeatLimit) {\n setUpgradeOpen(true);\n return;\n }\n setEmail('');\n setEmailError('');\n setInviteOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleInviteClose() {\n if (sending) return;\n setInviteOpen(false);\n }\n\n function handleSendInvite() {\n if (sending || address === '') return;\n setEmailError('');\n if (!looksLikeEmail(address)) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n const member = members.find((m) => m.email === address.toLowerCase());\n if (member) {\n setEmailError(`${member.name} is already a member of Acme.`);\n return;\n }\n setSending(true);\n later(() => {\n setSending(false);\n setInviteOpen(false);\n inviteCount.current += 1;\n const id = `new-${inviteCount.current}`;\n setInvites((list) => [...list, { id, email: address, sent: 'Sent just now', link: 'https://acme.example/join/p9Rd3cYs' }]);\n toastIds.current.push(toast({ type: 'success', message: `Invite sent to ${address}.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Members</Heading>\n {canManage && <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Invite Member\" decoIcon=\"UserPlus\" onClickButton={handleInviteMember} />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>\n {!canManage && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change this.</Paragraph>}\n </Stack>\n\n <TableContainer>\n {members.map((m) => {\n const isYou = m.id === youId;\n return (\n <TableRow key={m.id}>\n <TableCell>\n <Cluster gap=\"small\" align=\"start\">\n {/* The avatar sits beside the same name, so it is hidden from a screen reader. */}\n <UserImage userHandle={m.name} size={28} decorative />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {m.name}\n {isYou && <Tag variant=\"textOnly\" size=\"small\" label=\"You\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">{m.email}</Paragraph>\n </Stack>\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">\n {/* Only an admin gets the Select, and nobody changes their own role. */}\n {canManage && !isYou ? (\n <Stack gap=\"small\">\n <Select\n width={140}\n aria-label={`Role for ${m.name}`}\n aria-describedby={roleErrors[m.id] ? `members-list-rows-${m.id}-role-error` : undefined}\n value={roles[m.id]}\n options={roleOptions}\n disabled={savingRole === m.id || busyRow === m.id}\n onChange={(v) => handleRoleChange(m, typeof v === 'string' ? v : v[0])}\n />\n {roleErrors[m.id] && <Alert id={`members-list-rows-${m.id}-role-error`} type=\"error\" variant=\"inline\" autoDismiss={false} message={roleErrors[m.id]} />}\n </Stack>\n ) : (\n roles[m.id]\n )}\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"340px\">\n {canManage && !isYou && (\n confirmingMember === m.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Remove {m.name}?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === m.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel removing ${m.name}`} onClickButton={() => setConfirmingMember(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Remove\" aria-label={`Remove ${m.name}`} loading={busyRow === m.id} onClickButton={() => handleRemove(m)} />\n </Cluster>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Remove\" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />\n )\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n\n {canManage && invites.length > 0 && (\n <Stack gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Pending invites</Heading>\n <TableContainer>\n {invites.map((i) => (\n <TableRow key={i.id}>\n <TableCell>\n <Cluster gap=\"small\">\n <UserImage userHandle={i.email} size={28} decorative />\n {i.email}\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">{i.sent}</TableCell>\n <TableCell width=\"340px\">\n {confirmingInvite === i.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke this invite?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === i.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => setConfirmingInvite(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke invite for ${i.email}`} loading={busyRow === i.id} onClickButton={() => handleRevokeInvite(i)} />\n </Cluster>\n ) : (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={`${copiedInvite === i.id ? 'Copied' : 'Copy Link'} for ${i.email}`} onClickButton={() => handleCopy(i)} />\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Revoke Invite\" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />\n </Cluster>\n {copyBlocked === i.id && <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}\n </Stack>\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n )}\n </Stack>\n\n <Modal\n isOpen={inviteOpen}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Invite Member\"\n onClose={handleInviteClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={sending ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleInviteClose} />\n <Button size=\"small\" type=\"primary\" state={address === '' ? 'disabled' : 'enabled'} label=\"Invite\" loading={sending} onClickButton={handleSendInvite} />\n </>\n }\n >\n <Paragraph measure=\"none\">We email them a link to join Acme as a member. The link works for 7 days.</Paragraph>\n <Form aria-label=\"Invite member\" onSubmit={handleSendInvite}>\n <TextField id=\"members-list-invite-email\" label=\"Email\" type=\"email\" value={email} disabled={sending} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n </Form>\n </Modal>\n\n <Modal\n isOpen={upgradeOpen}\n size=\"small\"\n title=\"Upgrade to Pro\"\n onClose={() => setUpgradeOpen(false)}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setUpgradeOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => setUpgradeOpen(false)} />\n </>\n }\n >\n <Paragraph measure=\"none\">All {seatLimit} seats on the Free plan are filled. Pro adds seats for $8 per member each month.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
|
|
2374
|
+
"uses": [
|
|
2375
|
+
"Alert",
|
|
2376
|
+
"Button",
|
|
2377
|
+
"Center",
|
|
2378
|
+
"Cluster",
|
|
2379
|
+
"Form",
|
|
2380
|
+
"Heading",
|
|
2381
|
+
"Modal",
|
|
2382
|
+
"Paragraph",
|
|
2383
|
+
"Select",
|
|
2384
|
+
"Stack",
|
|
2385
|
+
"TableCell",
|
|
2386
|
+
"TableContainer",
|
|
2387
|
+
"TableRow",
|
|
2388
|
+
"Tag",
|
|
2389
|
+
"TextField",
|
|
2390
|
+
"Toaster",
|
|
2391
|
+
"UserImage",
|
|
2392
|
+
"dismissToast",
|
|
2393
|
+
"toast"
|
|
2394
|
+
]
|
|
2395
|
+
},
|
|
2396
|
+
{
|
|
2397
|
+
"id": "table",
|
|
2398
|
+
"title": "A table with sorting",
|
|
2399
|
+
"useWhen": "More people than a person can scan. The columns Name and Role sort.",
|
|
2400
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Select from 'oneslash-design-system/components/select';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Member = { id: string; name: string; email: string; role: string };\ntype Invite = { id: string; email: string; sent: string; link: string };\n\n// A real app reads these from the signed-in person and the plan.\nconst youId = 'dana';\nconst canManage = true;\nconst seatLimit = 14;\n\nconst roleOptions = [\n { value: 'Admin', label: 'Admin' },\n { value: 'Member', label: 'Member' },\n { value: 'Guest', label: 'Guest' },\n];\n\nconst firstMembers: Member[] = [\n { id: 'dana', name: 'Dana Lee', email: 'dana@acme.example', role: 'Admin' },\n { id: 'ben', name: 'Ben Carter', email: 'ben@acme.example', role: 'Member' },\n { id: 'omar', name: 'Omar Reyes', email: 'omar@acme.example', role: 'Member' },\n { id: 'mei', name: 'Mei Tanaka', email: 'mei@acme.example', role: 'Member' },\n { id: 'luis', name: 'Luis Ortega', email: 'luis@acme.example', role: 'Guest' },\n { id: 'ana', name: 'Ana Silva', email: 'ana@acme.example', role: 'Member' },\n { id: 'kofi', name: 'Kofi Mensah', email: 'kofi@acme.example', role: 'Admin' },\n { id: 'hana', name: 'Hana Sato', email: 'hana@acme.example', role: 'Member' },\n { id: 'jonas', name: 'Jonas Weber', email: 'jonas@acme.example', role: 'Guest' },\n { id: 'nia', name: 'Nia Brown', email: 'nia@acme.example', role: 'Member' },\n { id: 'tomas', name: 'Tomas Novak', email: 'tomas@acme.example', role: 'Member' },\n { id: 'rhea', name: 'Rhea Kapoor', email: 'rhea@acme.example', role: 'Member' },\n];\n\nconst firstInvites: Invite[] = [\n { id: 'i1', email: 'priya@acme.example', sent: 'Sent 2 days ago', link: 'https://acme.example/join/k7Qm2xLp' },\n { id: 'i2', email: 'sam@partner.example', sent: 'Sent 5 days ago', link: 'https://acme.example/join/b4Tn8zVw' },\n];\n\n// Stands in for a save that does not go through: Omar's role never saves.\nconst failsFor = 'omar';\nconst failedMessage = 'Could not save. Try again.';\n\n// A small check: some text, an @, then some text.\nfunction looksLikeEmail(value: string) {\n return /^[^@\\s]+@[^@\\s]+$/.test(value);\n}\n\nexport default function MembersListTable() {\n const [members, setMembers] = useState(firstMembers);\n const [invites, setInvites] = useState(firstInvites);\n const [roles, setRoles] = useState<Record<string, string>>(() => Object.fromEntries(firstMembers.map((m) => [m.id, m.role])));\n const [savingRole, setSavingRole] = useState<string | null>(null);\n const [roleErrors, setRoleErrors] = useState<Record<string, string>>({});\n const [confirmingMember, setConfirmingMember] = useState<string | null>(null);\n // Opens sorted by name, A to Z.\n const [sort, setSort] = useState<{ by: 'name' | 'role'; dir: 'ascending' | 'descending' }>({ by: 'name', dir: 'ascending' });\n const [confirmingInvite, setConfirmingInvite] = useState<string | null>(null);\n const [busyRow, setBusyRow] = useState<string | null>(null);\n const [copiedInvite, setCopiedInvite] = useState<string | null>(null);\n const [copyBlocked, setCopyBlocked] = useState<string | null>(null);\n\n const [inviteOpen, setInviteOpen] = useState(false);\n const [email, setEmail] = useState('');\n const [emailError, setEmailError] = useState('');\n const [sending, setSending] = useState(false);\n const [upgradeOpen, setUpgradeOpen] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const copyTimer = useRef<ReturnType<typeof setTimeout>>();\n const mounted = useRef(true);\n const toastIds = useRef<string[]>([]);\n // Gives each new invite its own id, so no two rows share a key.\n const inviteCount = useRef(0);\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n timers.current.forEach(clearTimeout);\n clearTimeout(copyTimer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n };\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // A pending invite holds a seat until it is accepted or revoked.\n const seatsUsed = members.length + invites.length;\n const atSeatLimit = seatsUsed >= seatLimit;\n const address = email.trim();\n\n // The first press on a column sorts it A to Z, and the next one reverses it.\n function handleSort(by: 'name' | 'role') {\n setSort((current) => ({ by, dir: current.by === by && current.dir === 'ascending' ? 'descending' : 'ascending' }));\n }\n\n const roleRank = (role: string) => roleOptions.findIndex((o) => o.value === role);\n const sorted = [...members].sort((a, b) => {\n const byName = a.name.localeCompare(b.name);\n const order = sort.by === 'name' ? byName : roleRank(roles[a.id]) - roleRank(roles[b.id]) || byName;\n return sort.dir === 'ascending' ? order : -order;\n });\n\n // The header cell has no `aria-sort`, so the Button's name says the state and what a press does.\n function sortButton(by: 'name' | 'role', label: string) {\n const active = sort.by === by;\n const next = active && sort.dir === 'ascending' ? 'descending' : 'ascending';\n const now = active ? `sorted ${sort.dir}` : 'not sorted';\n return (\n <Button\n size=\"small\"\n type=\"tertiary\"\n state={active ? 'selected' : 'enabled'}\n label={label}\n aria-label={`${label}, ${now}. Sort ${next}.`}\n decoIcon={active ? (sort.dir === 'ascending' ? 'ArrowUp' : 'ArrowDown') : undefined}\n onClickButton={() => handleSort(by)}\n />\n );\n }\n\n // The role is one control on its own, so it saves as soon as it changes. Nothing shows when it works.\n function handleRoleChange(member: Member, next: string) {\n if (savingRole) return;\n const before = roles[member.id];\n setRoleErrors((current) => ({ ...current, [member.id]: '' }));\n setSavingRole(member.id);\n setRoles((current) => ({ ...current, [member.id]: next }));\n later(() => {\n setSavingRole(null);\n if (member.id === failsFor) {\n setRoles((current) => ({ ...current, [member.id]: before }));\n setRoleErrors((current) => ({ ...current, [member.id]: failedMessage }));\n }\n }, 900);\n }\n\n // Starting a confirm on one row cancels the confirm on any other.\n function startConfirm(kind: 'member' | 'invite', id: string) {\n setConfirmingMember(kind === 'member' ? id : null);\n setConfirmingInvite(kind === 'invite' ? id : null);\n }\n\n function handleRemove(member: Member) {\n if (busyRow) return;\n setBusyRow(member.id);\n later(() => {\n setBusyRow(null);\n setConfirmingMember(null);\n setMembers((list) => list.filter((m) => m.id !== member.id));\n toastIds.current.push(toast({ type: 'success', message: `${member.name} removed from Acme.` }));\n }, 1200);\n }\n\n function handleRevokeInvite(invite: Invite) {\n if (busyRow) return;\n setBusyRow(invite.id);\n later(() => {\n setBusyRow(null);\n setConfirmingInvite(null);\n setInvites((list) => list.filter((i) => i.id !== invite.id));\n toastIds.current.push(toast({ type: 'success', message: `Invite for ${invite.email} revoked.` }));\n }, 1200);\n }\n\n // Only reads 'Copied' when the link reached the clipboard. When the browser has no\n // clipboard or refuses the write, a line under the row says so.\n function handleCopy(invite: Invite) {\n clearTimeout(copyTimer.current);\n setCopiedInvite(null);\n const blocked = () => {\n if (mounted.current) setCopyBlocked(invite.id);\n };\n if (!navigator.clipboard) {\n blocked();\n return;\n }\n navigator.clipboard.writeText(invite.link).then(() => {\n if (!mounted.current) return;\n setCopyBlocked(null);\n setCopiedInvite(invite.id);\n copyTimer.current = setTimeout(() => setCopiedInvite(null), 2000);\n }, blocked);\n }\n\n // At the seat limit the Button still works: it tells the person why they cannot invite.\n function handleInviteMember() {\n if (atSeatLimit) {\n setUpgradeOpen(true);\n return;\n }\n setEmail('');\n setEmailError('');\n setInviteOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleInviteClose() {\n if (sending) return;\n setInviteOpen(false);\n }\n\n function handleSendInvite() {\n if (sending || address === '') return;\n setEmailError('');\n if (!looksLikeEmail(address)) {\n setEmailError('Enter an email address, like name@example.com.');\n return;\n }\n const member = members.find((m) => m.email === address.toLowerCase());\n if (member) {\n setEmailError(`${member.name} is already a member of Acme.`);\n return;\n }\n setSending(true);\n later(() => {\n setSending(false);\n setInviteOpen(false);\n inviteCount.current += 1;\n const id = `new-${inviteCount.current}`;\n setInvites((list) => [...list, { id, email: address, sent: 'Sent just now', link: 'https://acme.example/join/p9Rd3cYs' }]);\n toastIds.current.push(toast({ type: 'success', message: `Invite sent to ${address}.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Members</Heading>\n {canManage && <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Invite Member\" decoIcon=\"UserPlus\" onClickButton={handleInviteMember} />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{seatsUsed} of {seatLimit} seats used on the Free plan.</Paragraph>\n {!canManage && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change this.</Paragraph>}\n </Stack>\n\n <TableContainer>\n <TableHeader>\n <TableRow>\n <TableHeaderCell>{sortButton('name', 'Name')}</TableHeaderCell>\n <TableHeaderCell width=\"170px\">{sortButton('role', 'Role')}</TableHeaderCell>\n <TableHeaderCell width=\"340px\">Actions</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {sorted.map((m) => {\n const isYou = m.id === youId;\n return (\n <TableRow key={m.id}>\n <TableCell>\n <Cluster gap=\"small\" align=\"start\">\n {/* The avatar sits beside the same name, so it is hidden from a screen reader. */}\n <UserImage userHandle={m.name} size={28} decorative />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n {m.name}\n {isYou && <Tag variant=\"textOnly\" size=\"small\" label=\"You\" />}\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">{m.email}</Paragraph>\n </Stack>\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">\n {/* Only an admin gets the Select, and nobody changes their own role. */}\n {canManage && !isYou ? (\n <Stack gap=\"small\">\n <Select\n width={140}\n aria-label={`Role for ${m.name}`}\n aria-describedby={roleErrors[m.id] ? `members-list-table-${m.id}-role-error` : undefined}\n value={roles[m.id]}\n options={roleOptions}\n disabled={savingRole === m.id || busyRow === m.id}\n onChange={(v) => handleRoleChange(m, typeof v === 'string' ? v : v[0])}\n />\n {roleErrors[m.id] && <Alert id={`members-list-table-${m.id}-role-error`} type=\"error\" variant=\"inline\" autoDismiss={false} message={roleErrors[m.id]} />}\n </Stack>\n ) : (\n roles[m.id]\n )}\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"340px\">\n {canManage && !isYou && (\n confirmingMember === m.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Remove {m.name}?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === m.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel removing ${m.name}`} onClickButton={() => setConfirmingMember(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Remove\" aria-label={`Remove ${m.name}`} loading={busyRow === m.id} onClickButton={() => handleRemove(m)} />\n </Cluster>\n ) : (\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Remove\" aria-label={`Remove ${m.name}`} onClickButton={() => startConfirm('member', m.id)} />\n )\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n\n {canManage && invites.length > 0 && (\n <Stack gap=\"small\">\n <Heading level={2} size=\"subtitle1\">Pending invites</Heading>\n <TableContainer>\n {invites.map((i) => (\n <TableRow key={i.id}>\n <TableCell>\n <Cluster gap=\"small\">\n <UserImage userHandle={i.email} size={28} decorative />\n {i.email}\n </Cluster>\n </TableCell>\n <TableCell width=\"170px\">{i.sent}</TableCell>\n <TableCell width=\"340px\">\n {confirmingInvite === i.id ? (\n <Cluster gap=\"small\">\n <Paragraph size=\"body2\" measure=\"none\">Revoke this invite?</Paragraph>\n <Button size=\"small\" type=\"tertiary\" state={busyRow === i.id ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking the invite for ${i.email}`} onClickButton={() => setConfirmingInvite(null)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke invite for ${i.email}`} loading={busyRow === i.id} onClickButton={() => handleRevokeInvite(i)} />\n </Cluster>\n ) : (\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label={copiedInvite === i.id ? 'Copied' : 'Copy Link'} aria-label={`${copiedInvite === i.id ? 'Copied' : 'Copy Link'} for ${i.email}`} onClickButton={() => handleCopy(i)} />\n <Button size=\"small\" type=\"tertiary\" state={busyRow ? 'disabled' : 'enabled'} label=\"Revoke Invite\" aria-label={`Revoke invite for ${i.email}`} onClickButton={() => startConfirm('invite', i.id)} />\n </Cluster>\n {copyBlocked === i.id && <Paragraph tone=\"secondary\" size=\"caption\" measure=\"none\">Copying is blocked here. Select the link and copy it: {i.link}</Paragraph>}\n </Stack>\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </Stack>\n )}\n </Stack>\n\n <Modal\n isOpen={inviteOpen}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Invite Member\"\n onClose={handleInviteClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={sending ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleInviteClose} />\n <Button size=\"small\" type=\"primary\" state={address === '' ? 'disabled' : 'enabled'} label=\"Invite\" loading={sending} onClickButton={handleSendInvite} />\n </>\n }\n >\n <Paragraph measure=\"none\">We email them a link to join Acme as a member. The link works for 7 days.</Paragraph>\n <Form aria-label=\"Invite member\" onSubmit={handleSendInvite}>\n <TextField id=\"members-list-invite-email\" label=\"Email\" type=\"email\" value={email} disabled={sending} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />\n </Form>\n </Modal>\n\n <Modal\n isOpen={upgradeOpen}\n size=\"small\"\n title=\"Upgrade to Pro\"\n onClose={() => setUpgradeOpen(false)}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Not Now\" onClickButton={() => setUpgradeOpen(false)} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Upgrade to Pro\" onClickButton={() => setUpgradeOpen(false)} />\n </>\n }\n >\n <Paragraph measure=\"none\">All {seatLimit} seats on the Free plan are filled. Pro adds seats for $8 per member each month.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
|
|
2401
|
+
"uses": [
|
|
2402
|
+
"Alert",
|
|
2403
|
+
"Button",
|
|
2404
|
+
"Center",
|
|
2405
|
+
"Cluster",
|
|
2406
|
+
"Form",
|
|
2407
|
+
"Heading",
|
|
2408
|
+
"Modal",
|
|
2409
|
+
"Paragraph",
|
|
2410
|
+
"Select",
|
|
2411
|
+
"Stack",
|
|
2412
|
+
"TableCell",
|
|
2413
|
+
"TableContainer",
|
|
2414
|
+
"TableHeader",
|
|
2415
|
+
"TableHeaderCell",
|
|
2416
|
+
"TableRow",
|
|
2417
|
+
"Tag",
|
|
2418
|
+
"TextField",
|
|
2419
|
+
"Toaster",
|
|
2420
|
+
"UserImage",
|
|
2421
|
+
"dismissToast",
|
|
2422
|
+
"toast"
|
|
2423
|
+
]
|
|
2424
|
+
}
|
|
2425
|
+
]
|
|
2426
|
+
},
|
|
1939
2427
|
{
|
|
1940
2428
|
"id": "mention-list",
|
|
1941
2429
|
"title": "Mention list",
|
|
@@ -1966,10 +2454,6 @@
|
|
|
1966
2454
|
"Do not show the agent with a photo or an initial."
|
|
1967
2455
|
],
|
|
1968
2456
|
"native": "On Apple the list shows above the field, the agent with a sparkles icon and people with a person icon. A name is picked with a click or a tap.",
|
|
1969
|
-
"notBuiltYet": "Scindo on the web builds its list from buttons, so a screen reader in the field does not hear which name is highlighted. It shows no 'Agent' tag on the agent's row.",
|
|
1970
|
-
"seenIn": [
|
|
1971
|
-
"Scindo"
|
|
1972
|
-
],
|
|
1973
2457
|
"options": [
|
|
1974
2458
|
{
|
|
1975
2459
|
"id": "in-composer",
|
|
@@ -2027,10 +2511,6 @@
|
|
|
2027
2511
|
"Do not open the menu when the page loads."
|
|
2028
2512
|
],
|
|
2029
2513
|
"native": "On Apple put the actions in the row's `contextMenu`: Copy, Edit, Add Reaction, Create Task and Report, with Delete last in the `.destructive` role. Delete asks in a system `confirmationDialog`, not in the row.",
|
|
2030
|
-
"notBuiltYet": "Scindo on the web deletes a message with no confirm and has no Copy. Its row actions show only while the pointer is on the row, so a keyboard or a phone cannot reach them.",
|
|
2031
|
-
"seenIn": [
|
|
2032
|
-
"Scindo"
|
|
2033
|
-
],
|
|
2034
2514
|
"options": [
|
|
2035
2515
|
{
|
|
2036
2516
|
"id": "hover-toolbar",
|
|
@@ -2116,10 +2596,6 @@
|
|
|
2116
2596
|
"Do not clear the waiting files when a send is blocked."
|
|
2117
2597
|
],
|
|
2118
2598
|
"native": "On Apple the attach button opens a menu with Photo Library and Files on iPhone, and opens Files on a Mac. Waiting files show as chips with a remove button. Sent images open full screen.",
|
|
2119
|
-
"notBuiltYet": "No product shows upload progress or a failed upload on the file itself. Scindo on the web shows a rejected file in an error Alert above the field, and its images use the file name as `alt` text.",
|
|
2120
|
-
"seenIn": [
|
|
2121
|
-
"Scindo"
|
|
2122
|
-
],
|
|
2123
2599
|
"options": [
|
|
2124
2600
|
{
|
|
2125
2601
|
"id": "in-composer",
|
|
@@ -2195,11 +2671,6 @@
|
|
|
2195
2671
|
"Do not turn Send into Stop in a thread that people also write in."
|
|
2196
2672
|
],
|
|
2197
2673
|
"native": "On Apple use a `TextField` with `axis: .vertical`. On a Mac, Return sends and Shift-Return adds a line. On an iPhone, Return adds a line. While the agent works, Send becomes Stop.",
|
|
2198
|
-
"notBuiltYet": "Scindo's Apple app shows only 'Message' as its placeholder when the agent is not called, so it does not say who will read the message.",
|
|
2199
|
-
"seenIn": [
|
|
2200
|
-
"Commentify",
|
|
2201
|
-
"Scindo"
|
|
2202
|
-
],
|
|
2203
2674
|
"options": [
|
|
2204
2675
|
{
|
|
2205
2676
|
"id": "plain",
|
|
@@ -2268,10 +2739,6 @@
|
|
|
2268
2739
|
"Do not let Escape in the field close a Modal or a panel around the thread."
|
|
2269
2740
|
],
|
|
2270
2741
|
"native": "On Apple the text becomes a field in the row, with 'Cancel' and 'Save', and the row shows '(edited)' after.",
|
|
2271
|
-
"notBuiltYet": "Scindo on the web saves and cancels with two icon buttons, a check and a cross, under the field. Scindo's Apple app shows 'Saving...' on its Save button while it saves.",
|
|
2272
|
-
"seenIn": [
|
|
2273
|
-
"Scindo"
|
|
2274
|
-
],
|
|
2275
2742
|
"options": [
|
|
2276
2743
|
{
|
|
2277
2744
|
"id": "in-place",
|
|
@@ -2322,11 +2789,6 @@
|
|
|
2322
2789
|
"Do not open the quick pick on hover. Open it on a press."
|
|
2323
2790
|
],
|
|
2324
2791
|
"native": "On Apple a reaction is added from the row's `contextMenu`, with Add Reaction.",
|
|
2325
|
-
"notBuiltYet": "Commentify's reaction chips do not show which are the person's, and cannot be pressed. Commentify adds a reaction from a full emoji picker.",
|
|
2326
|
-
"seenIn": [
|
|
2327
|
-
"Commentify",
|
|
2328
|
-
"Scindo"
|
|
2329
|
-
],
|
|
2330
2792
|
"options": [
|
|
2331
2793
|
{
|
|
2332
2794
|
"id": "chips",
|
|
@@ -2398,11 +2860,6 @@
|
|
|
2398
2860
|
"Do not put the agent's model in its name. It goes on the model line."
|
|
2399
2861
|
],
|
|
2400
2862
|
"native": "On Apple a row shows the avatar, the name and the time, with an 'Agent' label next to an agent's name.",
|
|
2401
|
-
"notBuiltYet": "Scindo on the web shows no 'Agent' tag on an agent's row, and its message list is not a log for screen readers. Scindo's Apple app shows no model name and does not group messages.",
|
|
2402
|
-
"seenIn": [
|
|
2403
|
-
"Commentify",
|
|
2404
|
-
"Scindo"
|
|
2405
|
-
],
|
|
2406
2863
|
"options": [
|
|
2407
2864
|
{
|
|
2408
2865
|
"id": "person-and-agent",
|
|
@@ -2438,6 +2895,68 @@
|
|
|
2438
2895
|
}
|
|
2439
2896
|
]
|
|
2440
2897
|
},
|
|
2898
|
+
{
|
|
2899
|
+
"id": "mobile-menu",
|
|
2900
|
+
"title": "Menu on a phone",
|
|
2901
|
+
"kind": "design",
|
|
2902
|
+
"level": "organism",
|
|
2903
|
+
"area": "shell",
|
|
2904
|
+
"situation": "A site's links and actions do not fit in the bar on a phone, and the person still needs to reach every one.",
|
|
2905
|
+
"do": [
|
|
2906
|
+
"Follow the rule 'On a phone, a sidebar opens as a drawer and a list opens its detail'. The menu is a `Drawer` from the start side.",
|
|
2907
|
+
"Open it from an `IconButton` named 'Menu' at the start of the bar, with `aria-expanded` and `aria-controls`.",
|
|
2908
|
+
"Use the menu that `SiteHeader` builds for a few links. The links come first, then the actions. One main action stays in the bar as `phoneAction`.",
|
|
2909
|
+
"Build the menu from a `Drawer` for sections: the pages of the open section as `MenuItem` links in a `Navigation`. Put a `TabsContainer` of section `Tab`s above them when the bar does not show the sections.",
|
|
2910
|
+
"Put the 'Menu' IconButton in a real bar with a skip link, as `SiteHeader` builds.",
|
|
2911
|
+
"Open the menu on the section of the current page, and mark the current page with `isSelected` and `aria-current=\"page\"`.",
|
|
2912
|
+
"Close the menu when a page is chosen. A `Drawer` also closes on Close, Escape and the scrim.",
|
|
2913
|
+
"Close the menu when the window widens past `md`, so the page is never left locked. A `SiteHeader` does it; give your own `Drawer` `closeFrom=\"md\"`.",
|
|
2914
|
+
"Give the Drawer a name with `aria-label`, the same as the button that opens it."
|
|
2915
|
+
],
|
|
2916
|
+
"dont": [
|
|
2917
|
+
"Do not leave a link without a way to reach it on a phone.",
|
|
2918
|
+
"Do not keep the menu open after a page is chosen.",
|
|
2919
|
+
"Do not put a Button that opens a Modal in the menu. On a phone the menu closes when it is chosen, so the Modal has no Button to give focus back to. Link to a page instead.",
|
|
2920
|
+
"Do not name the button only by its icon. Name it 'Menu'.",
|
|
2921
|
+
"Do not use more than four section tabs, or long names. They will not fit on a phone."
|
|
2922
|
+
],
|
|
2923
|
+
"native": "On iPhone use a `TabView` for the main places and a `NavigationStack` for the pages in a section. On Android use a navigation drawer.",
|
|
2924
|
+
"options": [
|
|
2925
|
+
{
|
|
2926
|
+
"id": "links",
|
|
2927
|
+
"title": "Links and actions in one menu",
|
|
2928
|
+
"useWhen": "A site has a few links and its actions, such as 'Log In'.",
|
|
2929
|
+
"source": "'use client';\nimport SiteHeader from 'oneslash-design-system/components/siteHeader';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport Button from 'oneslash-design-system/components/button';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\nconst links = [\n { label: 'Features', href: '#features', current: true },\n { label: 'Pricing', href: '#pricing' },\n { label: 'Docs', href: '#docs' },\n];\n\nexport default function MobileMenuLinks() {\n return (\n <>\n {/* Below md the Menu IconButton opens a Drawer: the links first, then 'Log In'. Choosing one closes it. 'Sign Up' stays in the bar. */}\n <SiteHeader\n brand={{ href: '#top', name: 'Acme' }}\n links={links}\n actions={<Button size=\"medium\" type=\"tertiary\" state=\"enabled\" label=\"Log In\" href=\"#log-in\" />}\n phoneAction={<Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Sign Up\" href=\"#sign-up\" />}\n mainId=\"mobile-menu-links-main\"\n />\n <PageShell id=\"mobile-menu-links-main\" tabIndex={-1}>\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Features</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">On a phone, open Menu to reach every page. It closes when you choose one.</Paragraph>\n </Stack>\n </PageShell>\n </>\n );\n}\n",
|
|
2930
|
+
"uses": [
|
|
2931
|
+
"Button",
|
|
2932
|
+
"Heading",
|
|
2933
|
+
"PageShell",
|
|
2934
|
+
"Paragraph",
|
|
2935
|
+
"SiteHeader",
|
|
2936
|
+
"Stack"
|
|
2937
|
+
]
|
|
2938
|
+
},
|
|
2939
|
+
{
|
|
2940
|
+
"id": "sections",
|
|
2941
|
+
"title": "Sections with their pages",
|
|
2942
|
+
"useWhen": "A site has sections that each hold many pages, and the person picks a section first.",
|
|
2943
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport Drawer from 'oneslash-design-system/components/drawer';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport Navigation from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Page = { id: string; label: string };\ntype Section = { id: string; label: string; pages: Page[] };\n\n// Four sections, one short word each. A real site reads these from its navigation.\nconst sections: Section[] = [\n { id: 'start', label: 'Start', pages: [{ id: 'install', label: 'Install' }, { id: 'first-steps', label: 'First steps' }] },\n { id: 'guides', label: 'Guides', pages: [{ id: 'sharing', label: 'Share a folder' }, { id: 'roles', label: 'Roles and access' }, { id: 'billing', label: 'Billing' }] },\n { id: 'reference', label: 'API', pages: [{ id: 'api', label: 'Endpoints' }, { id: 'limits', label: 'Limits' }] },\n { id: 'updates', label: 'News', pages: [{ id: 'changelog', label: 'Changelog' }] },\n];\n\nconst drawerId = 'mobile-menu-sections-drawer';\n\nexport default function MobileMenuSections() {\n const [open, setOpen] = useState(false);\n const [pageId, setPageId] = useState('sharing');\n const currentSection = sections.find((s) => s.pages.some((p) => p.id === pageId)) ?? sections[0];\n // The tabs show the section of the current page each time the menu opens.\n const [sectionId, setSectionId] = useState(currentSection.id);\n const shown = sections.find((s) => s.id === sectionId) ?? sections[0];\n const page = currentSection.pages.find((p) => p.id === pageId) ?? currentSection.pages[0];\n\n function openMenu() {\n setSectionId(currentSection.id);\n setOpen(true);\n }\n\n return (\n <PageShell>\n <Stack gap=\"large\">\n <Cluster gap=\"small\">\n {/* A real site shows this IconButton only below md, where the links are not in the bar. */}\n <IconButton\n color=\"iconOnly\"\n state=\"enabled\"\n size=\"medium\"\n iconName=\"Menu\"\n ariaLabel=\"Menu\"\n aria-expanded={open}\n aria-controls={drawerId}\n onClick={openMenu}\n />\n <Paragraph size=\"body1\" measure=\"none\">Acme Docs</Paragraph>\n </Cluster>\n <Heading level={1} size=\"h5\">{page.label}</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">This page is in {currentSection.label}. Open Menu to move to another section.</Paragraph>\n </Stack>\n {/* Section tabs at the top, the section's pages under them, the current page marked. A choice closes the Drawer. */}\n <Drawer id={drawerId} isOpen={open} onClose={() => setOpen(false)} aria-label=\"Menu\" side=\"start\" size=\"small\" closeFrom=\"md\">\n <Stack gap=\"large\">\n <TabsContainer fill>\n {sections.map((s) => (\n <Tab key={s.id} label={s.label} size=\"small\" isSelected={s.id === shown.id} onClickTab={() => setSectionId(s.id)} />\n ))}\n </TabsContainer>\n <Navigation aria-label={`${shown.label} pages`}>\n {shown.pages.map((p) => (\n <MenuItem\n key={p.id}\n size=\"small\"\n label={p.label}\n href={`/${shown.id}/${p.id}`}\n isSelected={p.id === pageId}\n aria-current={p.id === pageId ? 'page' : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example keeps the choice in state.\n event.preventDefault();\n setPageId(p.id);\n setOpen(false);\n }}\n />\n ))}\n </Navigation>\n </Stack>\n </Drawer>\n </PageShell>\n );\n}\n",
|
|
2944
|
+
"uses": [
|
|
2945
|
+
"Cluster",
|
|
2946
|
+
"Drawer",
|
|
2947
|
+
"Heading",
|
|
2948
|
+
"IconButton",
|
|
2949
|
+
"MenuItem",
|
|
2950
|
+
"Navigation",
|
|
2951
|
+
"PageShell",
|
|
2952
|
+
"Paragraph",
|
|
2953
|
+
"Stack",
|
|
2954
|
+
"Tab",
|
|
2955
|
+
"TabsContainer"
|
|
2956
|
+
]
|
|
2957
|
+
}
|
|
2958
|
+
]
|
|
2959
|
+
},
|
|
2441
2960
|
{
|
|
2442
2961
|
"id": "not-found-page",
|
|
2443
2962
|
"title": "Page not found",
|
|
@@ -2455,12 +2974,6 @@
|
|
|
2455
2974
|
"Do not show a line of text with no way home.",
|
|
2456
2975
|
"Do not blame the person for the link."
|
|
2457
2976
|
],
|
|
2458
|
-
"notBuiltYet": "Commentify's page not found is one line of bare text, 'Page not found.', with no way home. Scindo on the web shows '404' as its heading, then bare text and a text link home. jinhwankim.com has no heading: it puts '404:' at the start of its `EmptyBox` text and labels its Button 'Go to Home'.",
|
|
2459
|
-
"seenIn": [
|
|
2460
|
-
"Commentify",
|
|
2461
|
-
"Scindo",
|
|
2462
|
-
"jinhwankim.com"
|
|
2463
|
-
],
|
|
2464
2977
|
"options": [
|
|
2465
2978
|
{
|
|
2466
2979
|
"id": "full-page",
|
|
@@ -2480,17 +2993,68 @@
|
|
|
2480
2993
|
"id": "in-shell",
|
|
2481
2994
|
"title": "Inside the shell",
|
|
2482
2995
|
"useWhen": "The address is inside the app and the navigation still works.",
|
|
2483
|
-
"source": "'use client';\nimport
|
|
2996
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport AppShell from 'oneslash-design-system/components/appShell';\nimport Navigation, { NavigationGroup } from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// The places, and the projects the person made. The page that failed or loads is the current one.\nconst places = [\n { label: 'Home', icon: 'House', href: '/' },\n { label: 'Settings', icon: 'Settings', href: '/settings' },\n];\nconst projects = [\n { label: 'Website', icon: 'Globe', href: '/projects/website' },\n { label: 'Mobile App', icon: 'Smartphone', href: '/projects/mobile-app' },\n];\nconst current = '/projects/website';\n\nconst row = (p: { label: string; icon: string; href: string }) => (\n <MenuItem\n key={p.href}\n size=\"small\"\n label={p.label}\n iconName={p.icon}\n href={p.href}\n isSelected={p.href === current}\n aria-current={p.href === current ? 'page' : undefined}\n // A real app lets the link go to its page.\n onClick={(event: { preventDefault: () => void }) => event.preventDefault()}\n />\n);\n\nconst sidebar = (\n <Navigation aria-label=\"Main\">\n <Paragraph size=\"body1\" measure=\"none\">Acme</Paragraph>\n {places.map(row)}\n <NavigationGroup label=\"Projects\">{projects.map(row)}</NavigationGroup>\n </Navigation>\n);\n\nexport default function NotFoundPageInShell() {\n // Below md the sidebar is a Drawer; this says whether it is open.\n const [navOpen, setNavOpen] = useState(false);\n return (\n <AppShell title=\"Website\" navOpen={navOpen} onNavOpenChange={setNavOpen} sidebar={sidebar}>\n <Surface minHeight=\"tall\" align=\"center\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">Page not found</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">The link may be wrong, or the page was moved or removed.</Paragraph>\n </Stack>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Go Home\" href=\"/\" />\n </Cluster>\n </Stack>\n </Surface>\n </AppShell>\n );\n}\n",
|
|
2484
2997
|
"uses": [
|
|
2998
|
+
"AppShell",
|
|
2485
2999
|
"Button",
|
|
2486
3000
|
"Cluster",
|
|
2487
3001
|
"Heading",
|
|
2488
|
-
"
|
|
3002
|
+
"MenuItem",
|
|
3003
|
+
"Navigation",
|
|
3004
|
+
"NavigationGroup",
|
|
2489
3005
|
"Paragraph",
|
|
2490
3006
|
"Stack",
|
|
2491
|
-
"Surface"
|
|
2492
|
-
|
|
2493
|
-
|
|
3007
|
+
"Surface"
|
|
3008
|
+
]
|
|
3009
|
+
}
|
|
3010
|
+
]
|
|
3011
|
+
},
|
|
3012
|
+
{
|
|
3013
|
+
"id": "notification-menu",
|
|
3014
|
+
"title": "Notification setting",
|
|
3015
|
+
"kind": "design",
|
|
3016
|
+
"level": "organism",
|
|
3017
|
+
"area": "menu",
|
|
3018
|
+
"situation": "A person chooses how much a channel or a thread notifies them.",
|
|
3019
|
+
"do": [
|
|
3020
|
+
"Use an `IconButton` with `iconName=\"Bell\"`, and `BellOff` when the channel is muted.",
|
|
3021
|
+
"Say the current value in the button's `ariaLabel`: 'Notifications: All messages'. Show it in a `Tooltip` too.",
|
|
3022
|
+
"Open a navigable menu of three choices: `<Popover returnFocus>` around `<Menu navigable aria-label=\"Notifications\">`.",
|
|
3023
|
+
"Give each choice a `secondLabel` of one line: 'All Messages', then 'Every message in this channel.'",
|
|
3024
|
+
"Give each item `role=\"menuitemradio\"` and mark the current choice with `isSelected`, which sets `aria-checked`.",
|
|
3025
|
+
"Save as soon as a choice is made, as the rule 'A setting saves in place, or with one Save Button' says. Close the menu and show nothing when it works.",
|
|
3026
|
+
"Set `aria-busy` on the bell while the request runs.",
|
|
3027
|
+
"Put the bell back to its old value when the save fails, and show an error toast: 'Could not save your notification setting. Try again.' This is the exception in the rule 'A setting saves in place, or with one Save Button': a setting chosen from a menu shows a failed save in a toast, because the menu closes.",
|
|
3028
|
+
"Dismiss the toast when the example goes away."
|
|
3029
|
+
],
|
|
3030
|
+
"dont": [
|
|
3031
|
+
"Do not add a Save Button to the menu.",
|
|
3032
|
+
"Do not show a toast when the save works.",
|
|
3033
|
+
"Do not leave the bell on the new value when the save failed.",
|
|
3034
|
+
"Do not show a failure inside the menu. It has already closed.",
|
|
3035
|
+
"Do not use only the icon to say muted. The button's name says it too."
|
|
3036
|
+
],
|
|
3037
|
+
"native": "On Apple use a toolbar `Menu` with a `Picker` inside it, with the bell symbol changing to `bell.slash`. On Android use a dropdown menu with radio items.",
|
|
3038
|
+
"options": [
|
|
3039
|
+
{
|
|
3040
|
+
"id": "menu",
|
|
3041
|
+
"title": "Bell with a menu",
|
|
3042
|
+
"useWhen": "There are three or four choices and each one needs a line to explain it.",
|
|
3043
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Pref = 'all' | 'mentions' | 'none';\n\nconst choices: { value: Pref; label: string; line: string; current: string }[] = [\n { value: 'all', label: 'All Messages', line: 'Every message in this channel.', current: 'All messages' },\n { value: 'mentions', label: 'Mentions Only', line: 'Only when someone mentions you.', current: 'Mentions only' },\n { value: 'none', label: 'Muted', line: 'No notifications from this channel.', current: 'Muted' },\n];\n\nexport default function NotificationMenuExample() {\n const [pref, setPref] = useState<Pref>('all');\n const [saving, setSaving] = useState(false);\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const current = choices.find((c) => c.value === pref) ?? choices[0];\n\n // On unmount it stops the request and closes the toast it opened.\n useEffect(() => () => {\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n function toggle(anchorEl: HTMLElement) {\n if (saving) return;\n setAnchor(anchorEl);\n setOpen((o) => !o);\n }\n\n // Saves at once and shows nothing when it works: the bell already shows the new value.\n // The menu is gone by now, so a failure says so in a toast, and the bell goes back.\n function choose(next: Pref) {\n const previous = pref;\n setOpen(false);\n if (next === previous) return;\n setPref(next);\n setSaving(true);\n // Stands in for the request to the server. 'Muted' never saves, as if the connection were down.\n timer.current = setTimeout(() => {\n setSaving(false);\n if (next === 'none') {\n setPref(previous);\n toastIds.current.push(toast({ type: 'error', message: 'Could not save your notification setting. Try again.' }));\n }\n }, 900);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Design team</Heading>\n <Tooltip title={current.current}>\n <IconButton\n color={pref === 'none' ? 'secondary' : 'iconOnly'}\n state={open ? 'selected' : 'enabled'}\n size=\"small\"\n iconName={pref === 'none' ? 'BellOff' : 'Bell'}\n ariaLabel={`Notifications: ${current.current}`}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n aria-busy={saving}\n onClick={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Ben Carter: The press kit is in the shared folder.</Paragraph>\n </Stack>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Notifications\" width={260}>\n {choices.map((c) => (\n <MenuItem\n key={c.value}\n size=\"small\"\n label={c.label}\n secondLabel={c.line}\n isSelected={c.value === pref}\n role=\"menuitemradio\"\n onClick={() => choose(c.value)}\n />\n ))}\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
|
|
3044
|
+
"uses": [
|
|
3045
|
+
"Center",
|
|
3046
|
+
"Cluster",
|
|
3047
|
+
"Heading",
|
|
3048
|
+
"IconButton",
|
|
3049
|
+
"Menu",
|
|
3050
|
+
"MenuItem",
|
|
3051
|
+
"Paragraph",
|
|
3052
|
+
"Popover",
|
|
3053
|
+
"Stack",
|
|
3054
|
+
"Toaster",
|
|
3055
|
+
"Tooltip",
|
|
3056
|
+
"dismissToast",
|
|
3057
|
+
"toast"
|
|
2494
3058
|
]
|
|
2495
3059
|
}
|
|
2496
3060
|
]
|
|
@@ -2521,11 +3085,6 @@
|
|
|
2521
3085
|
"Do not name the access by its scope id, such as 'tasks:write'.",
|
|
2522
3086
|
"Do not label Cancel 'Deny' or 'No'."
|
|
2523
3087
|
],
|
|
2524
|
-
"notBuiltYet": "Scindo on the web turns on access to every workspace for the person, and shows its spinner on neither Button while the request runs. Commentify puts 'Allow' before 'Deny', writes its error in a red caption by hand, and says nothing about how to remove the access.",
|
|
2525
|
-
"seenIn": [
|
|
2526
|
-
"Commentify",
|
|
2527
|
-
"Scindo"
|
|
2528
|
-
],
|
|
2529
3088
|
"options": [
|
|
2530
3089
|
{
|
|
2531
3090
|
"id": "simple",
|
|
@@ -2570,70 +3129,465 @@
|
|
|
2570
3129
|
]
|
|
2571
3130
|
},
|
|
2572
3131
|
{
|
|
2573
|
-
"id": "
|
|
2574
|
-
"title": "
|
|
3132
|
+
"id": "on-off-settings",
|
|
3133
|
+
"title": "On and off settings",
|
|
2575
3134
|
"kind": "design",
|
|
2576
3135
|
"level": "organism",
|
|
2577
|
-
"area": "
|
|
2578
|
-
"situation": "A person
|
|
3136
|
+
"area": "settings",
|
|
3137
|
+
"situation": "A person turns things on and off, such as which notifications they get.",
|
|
2579
3138
|
"do": [
|
|
2580
|
-
"
|
|
2581
|
-
"
|
|
2582
|
-
"
|
|
2583
|
-
"
|
|
2584
|
-
"
|
|
2585
|
-
"
|
|
3139
|
+
"Follow the rule 'A setting saves in place, or with one Save Button'. Every `Switch` saves as soon as it changes, and the page has no Save Button.",
|
|
3140
|
+
"Give each `Switch` a visible `label` and a `description` that says what happens when it is on.",
|
|
3141
|
+
"Group the switches in `SettingsSection`s with a title and one line under it.",
|
|
3142
|
+
"Set `busy` on the switch while its request runs. It keeps its position and ignores presses. Show nothing when the save works.",
|
|
3143
|
+
"Put the switch back to its old value when the save fails, and set `error` to a short line: 'Could not save. Try again.'",
|
|
3144
|
+
"Clear the `error` when the person presses the switch again.",
|
|
3145
|
+
"Use a `Checkbox` for an on/off choice only inside a form that has a Save Button, such as a consent line above a Submit Button.",
|
|
3146
|
+
"Give each switch a unique `id`."
|
|
2586
3147
|
],
|
|
2587
3148
|
"dont": [
|
|
2588
|
-
"Do not
|
|
2589
|
-
"Do not
|
|
2590
|
-
"Do not
|
|
2591
|
-
"Do not
|
|
2592
|
-
|
|
2593
|
-
"native": "On Apple rename in place in a list with a `TextField` and `.onSubmit`. Use an `.alert` with a `TextField` when the name is not on screen.",
|
|
2594
|
-
"notBuiltYet": "Commentify's two renames disagree on what leaving the field does: a project name cancels, a tag name saves. Scindo on the web labels its rename Modals' action 'Save', shows 'Saving...' while it runs, and writes a taken name as a red caption by hand.",
|
|
2595
|
-
"seenIn": [
|
|
2596
|
-
"Commentify",
|
|
2597
|
-
"Scindo"
|
|
3149
|
+
"Do not use a `Checkbox` for an on/off setting that saves on change. Use a `Switch`.",
|
|
3150
|
+
"Do not add a Save Button to a list of switches.",
|
|
3151
|
+
"Do not show a toast when a switch saves.",
|
|
3152
|
+
"Do not leave a switch in its new position when the save failed.",
|
|
3153
|
+
"Do not put 'On' or 'Off' in the label. The switch shows it."
|
|
2598
3154
|
],
|
|
3155
|
+
"native": "On Apple use a `Toggle` in a grouped `Form`, and on Android a `Switch`. Both save as they change.",
|
|
2599
3156
|
"options": [
|
|
2600
3157
|
{
|
|
2601
|
-
"id": "
|
|
2602
|
-
"title": "
|
|
2603
|
-
"useWhen": "
|
|
2604
|
-
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport
|
|
3158
|
+
"id": "list",
|
|
3159
|
+
"title": "A list of switches",
|
|
3160
|
+
"useWhen": "Each setting is on or off and stands alone. Every switch saves as soon as it changes.",
|
|
3161
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Switch from 'oneslash-design-system/components/switch';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\ntype Setting = { id: string; label: string; description: string; on: boolean; fails?: boolean };\n\nconst failedMessage = 'Could not save. Try again.';\n\nconst emailSettings: Setting[] = [\n { id: 'mentions', label: 'Mentions', description: 'An email when someone mentions you.', on: true },\n { id: 'replies', label: 'Replies', description: 'An email when someone replies to your message.', on: true },\n { id: 'digest', label: 'Weekly digest', description: 'A summary of last week, every Monday.', on: false },\n];\n\n// Stands in for a connection that is down: this one never saves.\nconst appSettings: Setting[] = [\n { id: 'slack', label: 'Slack digest', description: 'Post the weekly digest in #general.', on: false, fails: true },\n { id: 'push', label: 'Push on your phone', description: 'Mentions and replies, while the app is closed.', on: true },\n];\n\nconst everySetting = [...emailSettings, ...appSettings];\n\nexport default function OnOffSettingsList() {\n const [values, setValues] = useState<Record<string, boolean>>(() => Object.fromEntries(everySetting.map((s) => [s.id, s.on])));\n const [busy, setBusy] = useState<Record<string, boolean>>({});\n // Opens on a failed save, as if the person just turned Slack digest on.\n const [errors, setErrors] = useState<Record<string, string>>({ slack: failedMessage });\n const timers = useRef<Record<string, ReturnType<typeof setTimeout>>>({});\n\n // Stops every request if the example goes away before they end.\n useEffect(() => () => Object.values(timers.current).forEach(clearTimeout), []);\n\n // Saves as soon as it changes. Nothing shows when it works. When it fails, the switch goes back and says why.\n function handleChange(setting: Setting, next: boolean) {\n setErrors((current) => ({ ...current, [setting.id]: '' }));\n setBusy((current) => ({ ...current, [setting.id]: true }));\n setValues((current) => ({ ...current, [setting.id]: next }));\n // Stands in for the request to the server.\n timers.current[setting.id] = setTimeout(() => {\n setBusy((current) => ({ ...current, [setting.id]: false }));\n if (setting.fails) {\n setValues((current) => ({ ...current, [setting.id]: !next }));\n setErrors((current) => ({ ...current, [setting.id]: failedMessage }));\n }\n }, 900);\n }\n\n function renderSwitch(setting: Setting) {\n return (\n <Switch\n key={setting.id}\n id={`on-off-settings-${setting.id}`}\n label={setting.label}\n description={setting.description}\n checked={values[setting.id]}\n busy={Boolean(busy[setting.id])}\n error={errors[setting.id] || undefined}\n onChange={(next) => handleChange(setting, next)}\n />\n );\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Heading level={1} size=\"h5\">Notifications</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Each switch saves as soon as you change it.</Paragraph>\n </Stack>\n <SettingsSection title=\"Email\" description=\"Sent to dana@acme.example.\">\n {emailSettings.map(renderSwitch)}\n </SettingsSection>\n <SettingsSection title=\"Apps\" description=\"Where else Acme tells you.\">\n {appSettings.map(renderSwitch)}\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
|
|
2605
3162
|
"uses": [
|
|
2606
|
-
"Button",
|
|
2607
3163
|
"Center",
|
|
2608
|
-
"Cluster",
|
|
2609
|
-
"Form",
|
|
2610
3164
|
"Heading",
|
|
2611
|
-
"Modal",
|
|
2612
3165
|
"Paragraph",
|
|
3166
|
+
"SettingsSection",
|
|
2613
3167
|
"Stack",
|
|
2614
|
-
"
|
|
3168
|
+
"Switch"
|
|
2615
3169
|
]
|
|
2616
|
-
}
|
|
3170
|
+
}
|
|
3171
|
+
]
|
|
3172
|
+
},
|
|
3173
|
+
{
|
|
3174
|
+
"id": "on-this-page",
|
|
3175
|
+
"title": "On this page",
|
|
3176
|
+
"kind": "design",
|
|
3177
|
+
"level": "organism",
|
|
3178
|
+
"area": "shell",
|
|
3179
|
+
"situation": "A person reads a long page and wants to see its sections, jump to one and know which one they are in.",
|
|
3180
|
+
"do": [
|
|
3181
|
+
"Put `OnThisPage` in the `aside` of `PageShell`. It sticks below a `SiteHeader` and shows from `xl`. `PageShell` gives each level 2 and 3 heading with an `id` a scroll margin, so `#sharing` lands below the header.",
|
|
3182
|
+
"Build `items` from the headings of the page, in page order: the level 2 headings and the level 3 headings under them. Give each heading an `id`.",
|
|
3183
|
+
"Use it when the page has two items or more. With fewer it renders nothing.",
|
|
3184
|
+
"Keep the labels the same as the headings, in the same case.",
|
|
3185
|
+
"Name the nav 'On this page', which is the default, or pass an `aria-label` that fits the page.",
|
|
3186
|
+
"Let a click scroll the heading to just under the header and keep its item current until the scroll ends. With reduced motion it jumps.",
|
|
3187
|
+
"Keep the aside to the list. A phone does not show it, so the page must read in order without it. The sections are not places: on a phone the person scrolls to them."
|
|
3188
|
+
],
|
|
3189
|
+
"dont": [
|
|
3190
|
+
"Do not take the arrow keys to jump between sections. They scroll the page and move the cursor in a field.",
|
|
3191
|
+
"Do not list a page with one section.",
|
|
3192
|
+
"Do not add the items by hand for a page whose headings change. Build them from the headings.",
|
|
3193
|
+
"Do not mark the current item with color only. The bar beside it moves too.",
|
|
3194
|
+
"Do not put a second contents list in the page."
|
|
3195
|
+
],
|
|
3196
|
+
"native": "On Apple use a `ScrollViewReader` with a `Menu` or `List` of sections that scrolls to an id. On Android use a `LazyColumn` with a `scrollToItem` list.",
|
|
3197
|
+
"options": [
|
|
2617
3198
|
{
|
|
2618
|
-
"id": "
|
|
2619
|
-
"title": "
|
|
2620
|
-
"useWhen": "The
|
|
2621
|
-
"source": "'use client';\nimport
|
|
3199
|
+
"id": "aside",
|
|
3200
|
+
"title": "List of sections beside the page",
|
|
3201
|
+
"useWhen": "The page has two or more level 2 or 3 headings, and people jump between them.",
|
|
3202
|
+
"source": "'use client';\nimport SiteHeader from 'oneslash-design-system/components/siteHeader';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport OnThisPage from 'oneslash-design-system/components/onThisPage';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\n// The page's level 2 and 3 headings, in page order. A real site builds this from the page.\nconst sections = [\n { id: 'on-this-page-overview', label: 'Overview', level: 2 as const, text: 'Acme keeps your files in folders that the whole team can open. Everyone sees the same files.' },\n { id: 'on-this-page-sharing', label: 'Sharing', level: 2 as const, text: 'Share a folder with a person or a team. Dana Lee can share any folder she owns.' },\n { id: 'on-this-page-links', label: 'Share by link', level: 3 as const, text: 'A link opens the folder for anyone who has it. Turn the link off to stop it.' },\n { id: 'on-this-page-people', label: 'Share with people', level: 3 as const, text: 'Choose people by name. Ben Carter and Omar Reyes can view or edit.' },\n { id: 'on-this-page-roles', label: 'Roles and access', level: 2 as const, text: 'Owners change who has access. Editors change files. Viewers read them.' },\n { id: 'on-this-page-limits', label: 'Limits', level: 2 as const, text: 'A free team holds up to 5 GB. Paid teams hold as much as they need.' },\n];\n\n// Filler for the example, so each section is long enough to scroll.\nconst more = 'A change shows for everyone at once, so there is one copy of each file to look after. Older versions stay for 30 days, and an owner can bring one back.';\n\nconst items = sections.map(({ id, label, level }) => ({ id, label, level }));\n\nexport default function OnThisPageAside() {\n return (\n <>\n <SiteHeader\n brand={{ href: '#top', name: 'Acme Docs' }}\n links={[{ label: 'Guides', href: '#guides', current: true }, { label: 'Reference', href: '#reference' }]}\n mainId=\"on-this-page-main\"\n />\n {/* The list sticks below the header from xl. Below xl the page reads in order without it. */}\n <PageShell id=\"on-this-page-main\" tabIndex={-1} aside={<OnThisPage items={items} />}>\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Share a folder</Heading>\n {sections.map((s) => (\n <Stack key={s.id} gap=\"medium\">\n <Heading level={s.level} size={s.level === 2 ? 'h6' : 'subtitle1'} id={s.id}>{s.label}</Heading>\n <Paragraph measure=\"none\">{s.text}</Paragraph>\n <Paragraph tone=\"secondary\" measure=\"none\">{more}</Paragraph>\n <Paragraph tone=\"secondary\" measure=\"none\">{more}</Paragraph>\n </Stack>\n ))}\n </Stack>\n </PageShell>\n </>\n );\n}\n",
|
|
2622
3203
|
"uses": [
|
|
2623
|
-
"Center",
|
|
2624
|
-
"Cluster",
|
|
2625
3204
|
"Heading",
|
|
2626
|
-
"
|
|
3205
|
+
"OnThisPage",
|
|
3206
|
+
"PageShell",
|
|
2627
3207
|
"Paragraph",
|
|
2628
|
-
"
|
|
2629
|
-
"
|
|
2630
|
-
"Tooltip"
|
|
3208
|
+
"SiteHeader",
|
|
3209
|
+
"Stack"
|
|
2631
3210
|
]
|
|
2632
3211
|
}
|
|
2633
3212
|
]
|
|
2634
3213
|
},
|
|
2635
3214
|
{
|
|
2636
|
-
"id": "
|
|
3215
|
+
"id": "overflow-menu",
|
|
3216
|
+
"title": "More menu",
|
|
3217
|
+
"kind": "design",
|
|
3218
|
+
"level": "organism",
|
|
3219
|
+
"area": "menu",
|
|
3220
|
+
"situation": "A person opens a menu of less common actions, behind one button, for a thing or for the page.",
|
|
3221
|
+
"do": [
|
|
3222
|
+
"Use an `IconButton` with `iconName=\"Ellipsis\"` and a `Tooltip` of 'More'.",
|
|
3223
|
+
"Name the thing in the button's `ariaLabel`, in sentence case: 'More actions for Q3 report'. In a list, each row names its own item.",
|
|
3224
|
+
"Open `<Popover returnFocus>` around `<Menu navigable aria-label=\"Actions for Q3 report\">` with `onClick` items, from the button the person pressed: pass `event.currentTarget` as `anchorEl`.",
|
|
3225
|
+
"Set `aria-haspopup=\"menu\"` and `aria-expanded` on the button, and `state=\"selected\"` while the menu is open.",
|
|
3226
|
+
"Order the items by how often they are used. Put a destructive item last, after a `Line`, as a `MenuItem` with `color=\"danger\"`.",
|
|
3227
|
+
"Show a toast when an item has no other sign, such as 'Link copied.', since the menu is gone.",
|
|
3228
|
+
"Show no toast for Duplicate on a row: the copy shows under it. Move focus to the copy's More button.",
|
|
3229
|
+
"Confirm a delete on a row in the row, as the case 'Delete confirm' says: 'Cancel' and a danger 'Delete' take the place of the button, and focus goes to 'Cancel'.",
|
|
3230
|
+
"Move focus after a row is deleted to the next row's More button, or the one before it when it was the last.",
|
|
3231
|
+
"Confirm a delete from a header in a small Modal: 'Delete Report', 'Cancel' first, then a danger 'Delete'. 'Cancel' puts focus back on the More button.",
|
|
3232
|
+
"Go back to the list the thing was in after a delete from a header, and show a toast that names it.",
|
|
3233
|
+
"Show an error toast when Copy Link fails, because the clipboard is missing or refuses: 'Copying is blocked here. Select the link and copy it:' and the link. It stays until the person closes it.",
|
|
3234
|
+
"Check that the example is still mounted before the clipboard promise starts a toast, for success and failure."
|
|
3235
|
+
],
|
|
3236
|
+
"dont": [
|
|
3237
|
+
"Do not name the button only 'More'. Say what it acts on.",
|
|
3238
|
+
"Do not put a frequent action only in the menu. A person needs it in one press.",
|
|
3239
|
+
"Do not put a destructive item first, or color it by hand. It is last, with `color=\"danger\"`.",
|
|
3240
|
+
"Do not delete on the first click.",
|
|
3241
|
+
"Do not open a Modal to confirm a delete on a row in a dense list. The row keeps the place."
|
|
3242
|
+
],
|
|
3243
|
+
"native": "On Apple use a toolbar `Menu` with an `ellipsis.circle` label, or a row's `contextMenu`, with Delete last in the `.destructive` role. Delete asks in a `confirmationDialog`. On Android use an `IconButton` with a `DropdownMenu`.",
|
|
3244
|
+
"options": [
|
|
3245
|
+
{
|
|
3246
|
+
"id": "on-a-row",
|
|
3247
|
+
"title": "More button on a row",
|
|
3248
|
+
"useWhen": "The actions are for one item in a list, and each row has its own button.",
|
|
3249
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Report = { id: string; name: string; updated: string };\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\n\n// A real app reads these from the server.\nconst firstReports: Report[] = [\n { id: 'q3', name: 'Q3 report', updated: 'Updated 2 days ago' },\n { id: 'budget', name: 'Budget review', updated: 'Updated last week' },\n { id: 'hiring', name: 'Hiring plan', updated: 'Updated 3 weeks ago' },\n { id: 'roadmap', name: 'Roadmap', updated: 'Updated last month' },\n];\n\nexport default function OverflowMenuOnARow() {\n const [reports, setReports] = useState(firstReports);\n // The row whose menu is open, and the More button it opens from. Both stay set while the menu fades out.\n const [menuRow, setMenuRow] = useState<Report | null>(null);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n // The row that asks to confirm the delete. One row at a time.\n const [confirmingId, setConfirmingId] = useState<string | null>(null);\n const [deleting, setDeleting] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const cancelDelete = useRef<Focusable>(null);\n // Each row's More button by row id, so focus can move to one when the thing that had it is gone.\n const moreButtons = useRef<Record<string, Focusable>>({});\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n // Gives each copy its own id, so no two rows share a key.\n const copies = useRef(0);\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n function openMenu(r: Report, anchor: HTMLElement) {\n if (menuOpen && menuRow?.id === r.id) {\n setMenuOpen(false);\n return;\n }\n setMenuRow(r);\n setMenuAnchor(anchor);\n setMenuOpen(true);\n }\n\n // Every item closes the menu, and Escape and a click outside do too. The Popover gives focus back to More.\n function choose(action: (r: Report) => void) {\n if (!menuRow) return;\n const r = menuRow;\n setMenuOpen(false);\n action(r);\n }\n\n // The copy shows under the row, so it needs no toast. Focus goes to the copy's More button.\n function duplicate(r: Report) {\n copies.current += 1;\n const copy = { id: `${r.id}-copy-${copies.current}`, name: `${r.name} copy`, updated: 'Updated just now' };\n setReports((list) => {\n const at = list.findIndex((x) => x.id === r.id);\n return [...list.slice(0, at + 1), copy, ...list.slice(at + 1)];\n });\n focusNext.current = () => moreButtons.current[copy.id]?.focus();\n }\n\n // The menu is gone, so the result shows in a toast. A clipboard that is missing or refuses says to copy by hand,\n // in an error toast that stays until the person closes it.\n function copyLink(r: Report) {\n const link = `https://example.com/reports/${r.id}`;\n const failed = () => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'error', message: `Copying is blocked here. Select the link and copy it: ${link}` }));\n };\n if (!navigator.clipboard) return failed();\n navigator.clipboard.writeText(link).then(() => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'success', message: 'Link copied.' }));\n }, failed);\n }\n\n // The confirm opens in the row, with focus on 'Cancel'.\n function askToDelete(r: Report) {\n setConfirmingId(r.id);\n focusNext.current = () => cancelDelete.current?.focus();\n }\n\n // 'Cancel' goes away with the confirm, so focus goes back to the row's More button.\n function keepReport() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n setConfirmingId(null);\n focusNext.current = () => moreButtons.current[id]?.focus();\n }\n\n function confirmDelete() {\n if (deleting || !confirmingId) return;\n const id = confirmingId;\n const at = reports.findIndex((r) => r.id === id);\n const gone = reports[at];\n const neighbor = reports[at + 1] ?? reports[at - 1];\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n setConfirmingId(null);\n setReports((list) => list.filter((r) => r.id !== id));\n toastIds.current.push(toast({ type: 'success', message: `${gone.name} deleted.` }));\n // The row is gone: focus goes to the next row's More button, or the one before it when it was the last.\n focusNext.current = () => (neighbor ? moreButtons.current[neighbor.id] : null)?.focus();\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Reports</Heading>\n {reports.length > 0 ? (\n <TableContainer>\n {reports.map((r) => {\n const confirming = r.id === confirmingId;\n return (\n <TableRow key={r.id}>\n <TableCell>\n <Stack gap=\"small\">\n {r.name}\n {confirming && <Paragraph size=\"body2\" tone=\"secondary\" measure=\"none\">Delete this report?</Paragraph>}\n </Stack>\n </TableCell>\n <TableCell width=\"160px\">{r.updated}</TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"168px\" align=\"right\">\n {confirming ? (\n <Cluster gap=\"small\" justify=\"end\">\n <Button ref={cancelDelete} size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel deleting ${r.name}`} onClickButton={keepReport} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" aria-label={`Delete ${r.name}`} loading={deleting} onClickButton={confirmDelete} />\n </Cluster>\n ) : (\n <Cluster justify=\"end\">\n <Tooltip title=\"More\">\n <IconButton\n ref={(el) => { moreButtons.current[r.id] = el; }}\n color=\"iconOnly\"\n state={menuOpen && menuRow?.id === r.id ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for ${r.name}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen && menuRow?.id === r.id}\n onClick={(e: { currentTarget: HTMLElement }) => openMenu(r, e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n )}\n </TableCell>\n </TableRow>\n );\n })}\n </TableContainer>\n ) : (\n <EmptyBox size=\"small\" text=\"No reports yet\" secondText=\"Reports you create appear here.\" />\n )}\n </Stack>\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={() => setMenuOpen(false)} returnFocus>\n <Menu navigable aria-label={menuRow ? `Actions for ${menuRow.name}` : 'Report actions'} width={200}>\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Duplicate\" onClick={() => choose(duplicate)} />\n <MenuItem size=\"small\" iconName=\"Link\" label=\"Copy Link\" onClick={() => choose(copyLink)} />\n <Line />\n {/* Delete is last, and danger. */}\n <MenuItem size=\"small\" color=\"danger\" iconName=\"Trash2\" label=\"Delete\" onClick={() => choose(askToDelete)} />\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
|
|
3250
|
+
"uses": [
|
|
3251
|
+
"Button",
|
|
3252
|
+
"Center",
|
|
3253
|
+
"Cluster",
|
|
3254
|
+
"EmptyBox",
|
|
3255
|
+
"Heading",
|
|
3256
|
+
"IconButton",
|
|
3257
|
+
"Line",
|
|
3258
|
+
"Menu",
|
|
3259
|
+
"MenuItem",
|
|
3260
|
+
"Paragraph",
|
|
3261
|
+
"Popover",
|
|
3262
|
+
"Stack",
|
|
3263
|
+
"TableCell",
|
|
3264
|
+
"TableContainer",
|
|
3265
|
+
"TableRow",
|
|
3266
|
+
"Toaster",
|
|
3267
|
+
"Tooltip",
|
|
3268
|
+
"dismissToast",
|
|
3269
|
+
"toast"
|
|
3270
|
+
]
|
|
3271
|
+
},
|
|
3272
|
+
{
|
|
3273
|
+
"id": "in-a-header",
|
|
3274
|
+
"title": "More button in a header",
|
|
3275
|
+
"useWhen": "The actions are for the whole page, and the header has one button.",
|
|
3276
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst otherReports = ['Budget review', 'Hiring plan', 'Roadmap'];\n\nexport default function OverflowMenuInAHeader() {\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [deleting, setDeleting] = useState(false);\n const [deleted, setDeleted] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const moreButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n // The clipboard answers later; by then the example may be gone.\n const mounted = useRef(true);\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n mounted.current = false;\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n function toggle(anchorEl: HTMLElement) {\n setAnchor(anchorEl);\n setOpen((o) => !o);\n }\n\n // Every item closes the menu, and Escape and a click outside do too. The Popover gives focus back to More.\n function duplicate() {\n setOpen(false);\n toastIds.current.push(toast({ type: 'success', message: 'Q3 report duplicated.' }));\n }\n\n // The menu is gone, so the result shows in a toast. A clipboard that is missing or refuses says to copy by hand.\n function copyLink() {\n setOpen(false);\n const link = 'https://example.com/reports/q3';\n const failed = () => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'error', message: `Copying is blocked here. Select the link and copy it: ${link}` }));\n };\n if (!navigator.clipboard) return failed();\n navigator.clipboard.writeText(link).then(() => {\n if (!mounted.current) return;\n toastIds.current.push(toast({ type: 'success', message: 'Link copied.' }));\n }, failed);\n }\n\n function askToDelete() {\n setOpen(false);\n setConfirming(true);\n }\n\n // The Modal opens while the menu fades, so it cannot take focus back from the menu item: 'Cancel' sends it to More.\n function keepReport() {\n if (deleting) return;\n setConfirming(false);\n focusNext.current = () => moreButton.current?.focus();\n }\n\n function confirmDelete() {\n if (deleting) return;\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n setConfirming(false);\n setDeleted(true);\n toastIds.current.push(toast({ type: 'success', message: 'Q3 report deleted.' }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n {deleted ? (\n // A real app goes back to the list of reports here.\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Reports</Heading>\n <Surface padding=\"large\">\n <List items={otherReports} size=\"body1\" />\n </Surface>\n </Stack>\n ) : (\n <Stack gap=\"medium\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Q3 report</Heading>\n <Tooltip title=\"More\">\n <IconButton\n ref={moreButton}\n color=\"iconOnly\"\n state={open ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel=\"More actions for Q3 report\"\n aria-haspopup=\"menu\"\n aria-expanded={open}\n onClick={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}\n />\n </Tooltip>\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>\n </Stack>\n )}\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Actions for Q3 report\" width={200}>\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Duplicate\" onClick={duplicate} />\n <MenuItem size=\"small\" iconName=\"Link\" label=\"Copy Link\" onClick={copyLink} />\n <Line />\n {/* Delete is last, and danger. */}\n <MenuItem size=\"small\" color=\"danger\" iconName=\"Trash2\" label=\"Delete\" onClick={askToDelete} />\n </Menu>\n </Popover>\n {/* The page is not a row in a list, so the confirm is a small Modal, as the case 'Delete confirm' says. */}\n <Modal\n isOpen={confirming}\n size=\"small\"\n title=\"Delete Report\"\n onClose={keepReport}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={keepReport} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" loading={deleting} onClickButton={confirmDelete} />\n </>\n }\n >\n <Paragraph measure=\"none\">This deletes 'Q3 report' and its 12 tasks.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
|
|
3277
|
+
"uses": [
|
|
3278
|
+
"Button",
|
|
3279
|
+
"Center",
|
|
3280
|
+
"Cluster",
|
|
3281
|
+
"Heading",
|
|
3282
|
+
"IconButton",
|
|
3283
|
+
"Line",
|
|
3284
|
+
"List",
|
|
3285
|
+
"Menu",
|
|
3286
|
+
"MenuItem",
|
|
3287
|
+
"Modal",
|
|
3288
|
+
"Paragraph",
|
|
3289
|
+
"Popover",
|
|
3290
|
+
"Stack",
|
|
3291
|
+
"Surface",
|
|
3292
|
+
"Toaster",
|
|
3293
|
+
"Tooltip",
|
|
3294
|
+
"dismissToast",
|
|
3295
|
+
"toast"
|
|
3296
|
+
]
|
|
3297
|
+
}
|
|
3298
|
+
]
|
|
3299
|
+
},
|
|
3300
|
+
{
|
|
3301
|
+
"id": "page-header",
|
|
3302
|
+
"title": "Page header with actions",
|
|
3303
|
+
"kind": "design",
|
|
3304
|
+
"level": "organism",
|
|
3305
|
+
"area": "shell",
|
|
3306
|
+
"situation": "A page names itself at the top and offers what the person can do with it.",
|
|
3307
|
+
"do": [
|
|
3308
|
+
"Follow the rule 'On a phone, a sidebar opens as a drawer and a list opens its detail'.",
|
|
3309
|
+
"Use `TitleBar` with the page's name as the level 1 heading. Inside `AppShell` the top bar names the place on a phone. When the page is the place, the two are the same.",
|
|
3310
|
+
"Give the page one primary Button, first in `actions`.",
|
|
3311
|
+
"Put icon buttons after it, each in a `Tooltip` and named for what they act on: 'Search Home page'.",
|
|
3312
|
+
"Put a More menu last, as the case 'More menu' says: an `IconButton` with `iconName=\"Ellipsis\"`, `aria-haspopup=\"menu\"` and a name such as 'More actions for Home page'.",
|
|
3313
|
+
"Pass `phoneActions` with the primary Button and More. Below `md` they replace `actions`.",
|
|
3314
|
+
"Fold the icon buttons you leave out into the More menu, in the same order, so every action is still there. Put them first, before a `Line`. Keep a frequent action, such as Search, as an icon button in `phoneActions`.",
|
|
3315
|
+
"Pass `back` on a sub-page, a tertiary Button named for the page it goes to: 'Back to Website'. Below `md` it takes its own line.",
|
|
3316
|
+
"Let a long title wrap. Never cut it short."
|
|
3317
|
+
],
|
|
3318
|
+
"dont": [
|
|
3319
|
+
"Do not add a breadcrumb. Back goes one step up, and the title says where the person is.",
|
|
3320
|
+
"Do not show two primary Buttons.",
|
|
3321
|
+
"Do not name an icon button only by its icon, or More only by the word.",
|
|
3322
|
+
"Do not leave an action out on a phone without a way to reach it.",
|
|
3323
|
+
"Do not name the Back Button 'Back'. Name the page."
|
|
3324
|
+
],
|
|
3325
|
+
"native": "On Apple use a navigation title with `.toolbar` items: the primary action as a `ToolbarItem`, the rest in a `Menu`. The system back button names the page before it. On Android use a top app bar with an overflow menu.",
|
|
3326
|
+
"options": [
|
|
3327
|
+
{
|
|
3328
|
+
"id": "actions",
|
|
3329
|
+
"title": "The page's own actions",
|
|
3330
|
+
"useWhen": "The page is a place of its own, and the person can add to it, search it or change it.",
|
|
3331
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\nexport default function PageHeaderActions() {\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n // Which More button opened the menu: on a phone the menu also holds Search and Filter.\n const [from, setFrom] = useState<'wide' | 'phone'>('wide');\n const [open, setOpen] = useState(false);\n const [chosen, setChosen] = useState('');\n\n function openMore(kind: 'wide' | 'phone', el: HTMLElement) {\n setFrom(kind);\n setAnchor(el);\n setOpen((o) => !o);\n }\n\n // Every item closes the menu. Its Popover gives focus back to the More button.\n function choose(label: string) {\n setOpen(false);\n setChosen(label);\n }\n\n const newTask = <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"New Task\" decoIcon=\"Plus\" onClickButton={() => setChosen('New Task')} />;\n\n const more = (kind: 'wide' | 'phone') => (\n <Tooltip title=\"More\">\n <IconButton\n color=\"iconOnly\"\n state={open && from === kind ? 'selected' : 'enabled'}\n size=\"medium\"\n iconName=\"Ellipsis\"\n ariaLabel=\"More actions for Home page\"\n aria-haspopup=\"menu\"\n aria-expanded={open && from === kind}\n onClick={(e: { currentTarget: HTMLElement }) => openMore(kind, e.currentTarget)}\n />\n </Tooltip>\n );\n\n return (\n <PageShell>\n <Stack gap=\"large\">\n {/* The title is the page's level 1 heading. One primary Button, then icon buttons, then More last. Below md only the primary and More stay. */}\n <TitleBar\n title=\"Home page\"\n actions={\n <>\n {newTask}\n <Tooltip title=\"Search\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"medium\" iconName=\"Search\" ariaLabel=\"Search Home page\" onClick={() => setChosen('Search')} />\n </Tooltip>\n <Tooltip title=\"Filter\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"medium\" iconName=\"Filter\" ariaLabel=\"Filter Home page\" onClick={() => setChosen('Filter')} />\n </Tooltip>\n {more('wide')}\n </>\n }\n phoneActions={\n <>\n {newTask}\n {more('phone')}\n </>\n }\n />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{chosen ? `You chose ${chosen}.` : '12 tasks are open. Updated 2 days ago by Dana Lee.'}</Paragraph>\n </Stack>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Actions for Home page\" width={200}>\n {from === 'phone' && (\n <>\n <MenuItem size=\"small\" iconName=\"Search\" label=\"Search\" onClick={() => choose('Search')} />\n <MenuItem size=\"small\" iconName=\"Filter\" label=\"Filter\" onClick={() => choose('Filter')} />\n <Line />\n </>\n )}\n <MenuItem size=\"small\" iconName=\"Pencil\" label=\"Rename\" onClick={() => choose('Rename')} />\n <MenuItem size=\"small\" iconName=\"Copy\" label=\"Duplicate\" onClick={() => choose('Duplicate')} />\n <MenuItem size=\"small\" iconName=\"Archive\" label=\"Archive\" onClick={() => choose('Archive')} />\n </Menu>\n </Popover>\n </PageShell>\n );\n}\n",
|
|
3332
|
+
"uses": [
|
|
3333
|
+
"Button",
|
|
3334
|
+
"IconButton",
|
|
3335
|
+
"Line",
|
|
3336
|
+
"Menu",
|
|
3337
|
+
"MenuItem",
|
|
3338
|
+
"PageShell",
|
|
3339
|
+
"Paragraph",
|
|
3340
|
+
"Popover",
|
|
3341
|
+
"Stack",
|
|
3342
|
+
"TitleBar",
|
|
3343
|
+
"Tooltip"
|
|
3344
|
+
]
|
|
3345
|
+
},
|
|
3346
|
+
{
|
|
3347
|
+
"id": "sub-page",
|
|
3348
|
+
"title": "A page one step down, with Back",
|
|
3349
|
+
"useWhen": "The page opens from another page, such as a task from its project.",
|
|
3350
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Button from 'oneslash-design-system/components/button';\nimport Navigation from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\nconst taskTitle = 'Move the sign-up form above the pricing table on the home page';\n\nexport default function PageHeaderSubPage() {\n // The task is a page one step down from the project's page.\n const [view, setView] = useState<'task' | 'project'>('task');\n const [done, setDone] = useState(false);\n\n if (view === 'project') {\n return (\n <PageShell>\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Website</Heading>\n <Navigation aria-label=\"Tasks\">\n <MenuItem\n size=\"medium\"\n label={taskTitle}\n secondLabel={done ? 'Done' : 'Open'}\n iconRight=\"ChevronRight\"\n href=\"/website/tasks/sign-up-form\"\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to the task's page. The example keeps the choice in state.\n event.preventDefault();\n setView('task');\n }}\n />\n </Navigation>\n </Stack>\n </PageShell>\n );\n }\n\n return (\n <PageShell>\n <Stack gap=\"large\">\n {/* Back names the page it goes to. Below md it takes its own line above the title, and a long title wraps. */}\n <TitleBar\n title={taskTitle}\n back={<Button size=\"small\" type=\"tertiary\" state=\"enabled\" decoIcon=\"ChevronLeft\" label=\"Back to Website\" onClickButton={() => setView('project')} />}\n actions={<Button size=\"medium\" type=\"primary\" state={done ? 'disabled' : 'enabled'} label=\"Mark Done\" onClickButton={() => setDone(true)} />}\n />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{done ? 'Done. Marked by Dana Lee.' : 'Assigned to Ben Carter. Due on Friday.'}</Paragraph>\n </Stack>\n </PageShell>\n );\n}\n",
|
|
3351
|
+
"uses": [
|
|
3352
|
+
"Button",
|
|
3353
|
+
"Heading",
|
|
3354
|
+
"MenuItem",
|
|
3355
|
+
"Navigation",
|
|
3356
|
+
"PageShell",
|
|
3357
|
+
"Paragraph",
|
|
3358
|
+
"Stack",
|
|
3359
|
+
"TitleBar"
|
|
3360
|
+
]
|
|
3361
|
+
}
|
|
3362
|
+
]
|
|
3363
|
+
},
|
|
3364
|
+
{
|
|
3365
|
+
"id": "phone-navigation",
|
|
3366
|
+
"title": "On a phone, a sidebar opens as a drawer and a list opens its detail",
|
|
3367
|
+
"kind": "rule",
|
|
3368
|
+
"level": "rule",
|
|
3369
|
+
"area": "shell",
|
|
3370
|
+
"situation": "A layout with a sidebar, a list beside its detail, or a side pane meets a phone screen.",
|
|
3371
|
+
"answer": "An app's sidebar opens in a `Drawer` from the start side, from a 'Menu' `IconButton` at the start of a top bar that names the place. `AppShell` does this. The Drawer closes on a choice, on Close, on Escape, on the scrim and when the window widens. A list beside its detail becomes two screens: the list, then the detail with a Back Button named for the list, as `SettingsLayout` does. A settings nav is such a list. A side pane takes the whole content area and has Close. It is never squeezed beside the content. A site's links go into the same kind of menu, and one main action may stay in the bar. Nothing is hidden on a phone without a way to reach it. There is no bottom tab bar on the web.",
|
|
3372
|
+
"why": "A drawer opens over the page, so the person still sees where they are, and closing it puts them back on the same page. One drawer, built into `AppShell`, works the same way in every app.",
|
|
3373
|
+
"do": [
|
|
3374
|
+
"Open the sidebar in a `Drawer` from the start side, from a 'Menu' `IconButton` at the start of a top bar that names the place. Use `AppShell`.",
|
|
3375
|
+
"Close the drawer on a choice, Close, Escape, the scrim and when the window widens past `md`.",
|
|
3376
|
+
"Turn a list beside its detail into two screens on a phone: the list first, then the detail with a Back Button named for the list.",
|
|
3377
|
+
"Let a side pane take the whole content area on a phone, with a Close button.",
|
|
3378
|
+
"Put a site's links in the same kind of menu, and keep at most one main action in the bar.",
|
|
3379
|
+
"Give every place a way to be reached on a phone, even one that is only a link."
|
|
3380
|
+
],
|
|
3381
|
+
"dont": [
|
|
3382
|
+
"Do not hide a link on a phone without a menu that holds it.",
|
|
3383
|
+
"Do not show a sidebar beside the page on a phone, or squeeze a side pane beside the content.",
|
|
3384
|
+
"Do not replace the page with the app's sidebar. Open the drawer over it. A settings nav is a list beside its detail, so it is the first screen on a phone.",
|
|
3385
|
+
"Do not add a bottom tab bar on the web.",
|
|
3386
|
+
"Do not leave a drawer that Escape and a tap outside cannot close."
|
|
3387
|
+
],
|
|
3388
|
+
"native": "On iPhone use a `TabView` or a `NavigationStack` that pushes the detail with the system back button, and a `.sheet` for a short task. On Android use a navigation drawer or a bottom bar, and push the detail with the system back."
|
|
3389
|
+
},
|
|
3390
|
+
{
|
|
3391
|
+
"id": "profile-form",
|
|
3392
|
+
"title": "Profile",
|
|
3393
|
+
"kind": "design",
|
|
3394
|
+
"level": "organism",
|
|
3395
|
+
"area": "settings",
|
|
3396
|
+
"situation": "A person changes how they appear and how they sign in: their picture, their name and their password.",
|
|
3397
|
+
"do": [
|
|
3398
|
+
"Follow the rule 'A setting saves in place, or with one Save Button'.",
|
|
3399
|
+
"Put the picture, the name and the password in their own `SettingsSection`s. Do not mix a control that saves on change and a Save Button in one section.",
|
|
3400
|
+
"Save the picture as soon as the person chooses it, with 'Change Picture' and 'Remove'. Show `loading` on the Button that was pressed while it saves, and nothing when it works.",
|
|
3401
|
+
"When the picture fails to save, keep the old one and say why under the Buttons: 'Could not save. Try again.'",
|
|
3402
|
+
"Give 'Remove' an `aria-label` that names the thing: 'Remove picture'. Show it only when there is a picture to remove.",
|
|
3403
|
+
"Give the name one Save Button inside a `Form`. It is `state=\"disabled\"` while the name has not changed, shows `loading` while it saves, and reads 'Saved' for 2 seconds.",
|
|
3404
|
+
"Give the password one 'Update Password' Button. Ask for the current password and the new one. It is disabled while either field is empty, and reads 'Saved' for 2 seconds. Then clear both fields.",
|
|
3405
|
+
"Show a wrong current password under that field, and keep what the person typed in both.",
|
|
3406
|
+
"Use `<TextField type=\"password\">` for both, with `autoComplete=\"current-password\"` and `autoComplete=\"new-password\"`.",
|
|
3407
|
+
"Wrap each field in a `FormField` and pass `id` and `aria-describedby` to the control, and `aria-invalid` to a `TextField` or `Textarea`. This ties its label, help and error to it.",
|
|
3408
|
+
"Show a problem with a field under it, as the rule 'A form error shows next to the problem' says: 'Enter your name.' and 'Use at least 8 characters.'",
|
|
3409
|
+
"Disable the field while its request runs, and keep what the person typed when the save fails.",
|
|
3410
|
+
"Use `UserImage` with the person's name as `userHandle`, so a person with no picture sees their initial."
|
|
3411
|
+
],
|
|
3412
|
+
"dont": [
|
|
3413
|
+
"Do not add one Save Button for the whole page. Each group saves by itself.",
|
|
3414
|
+
"Do not label the Button 'Saving…' while it runs. It keeps its label.",
|
|
3415
|
+
"Do not show a toast when the name or the password is saved. The Button says it.",
|
|
3416
|
+
"Do not keep the passwords in the fields after they are saved.",
|
|
3417
|
+
"Do not ask for the new password twice. Show one field and the length rule."
|
|
3418
|
+
],
|
|
3419
|
+
"native": "On Apple use a grouped `Form` with the name in a `TextField` and a `SecureField` for the password, and a `PhotosPicker` for the picture. The picture saves when it is chosen.",
|
|
3420
|
+
"options": [
|
|
3421
|
+
{
|
|
3422
|
+
"id": "form",
|
|
3423
|
+
"title": "Picture, name and password",
|
|
3424
|
+
"useWhen": "People sign in with a password and can change their own picture and name.",
|
|
3425
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport Alert from 'oneslash-design-system/components/alert';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A picture the person chose. A real app uploads the file and gets a URL back.\nconst chosenPicture =\n \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' fill='%232f6b4f'/%3E%3Ccircle cx='32' cy='25' r='11' fill='%23fff'/%3E%3Cpath d='M10 64c2-15 11-22 22-22s20 7 22 22z' fill='%23fff'/%3E%3C/svg%3E\";\n\nconst minPasswordLength = 8;\n// Stands in for the server's check. In this example every current password is right except this one.\nconst wrongCurrentPassword = 'incorrect';\n\nexport default function ProfileForm() {\n const [picture, setPicture] = useState<string | undefined>(undefined);\n // Which picture Button was pressed, so only that one shows `loading`.\n const [savingPicture, setSavingPicture] = useState<'change' | 'remove' | null>(null);\n const [pictureError, setPictureError] = useState('');\n\n const [savedName, setSavedName] = useState('Dana Lee');\n const [name, setName] = useState('Dana Lee');\n const [nameError, setNameError] = useState('');\n const [savingName, setSavingName] = useState(false);\n const [nameSaved, setNameSaved] = useState(false);\n\n const [currentPassword, setCurrentPassword] = useState('');\n const [currentPasswordError, setCurrentPasswordError] = useState('');\n const [password, setPassword] = useState('');\n const [passwordError, setPasswordError] = useState('');\n const [savingPassword, setSavingPassword] = useState(false);\n const [passwordSaved, setPasswordSaved] = useState(false);\n\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // One 'Saved' timer per group, cleared before a new one starts, so an old one cannot end a new 'Saved' early.\n const nameSavedTimer = useRef<ReturnType<typeof setTimeout>>();\n const passwordSavedTimer = useRef<ReturnType<typeof setTimeout>>();\n // The first picture save fails, as if the upload dropped, so the example shows both paths.\n const pictureFails = useRef(true);\n\n // Stops every request and every 'Saved' if the example goes away before they end.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n clearTimeout(nameSavedTimer.current);\n clearTimeout(passwordSavedTimer.current);\n }, []);\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // The picture is one control on its own, so it saves as soon as it is chosen or removed. Nothing shows when it works.\n // When it fails, the old picture stays and a line under the Buttons says why.\n function savePicture(next: string | undefined, pressed: 'change' | 'remove') {\n if (savingPicture) return;\n setPictureError('');\n setSavingPicture(pressed);\n later(() => {\n setSavingPicture(null);\n if (pictureFails.current) {\n pictureFails.current = false;\n setPictureError('Could not save. Try again.');\n return;\n }\n setPicture(next);\n }, 900);\n }\n\n // The name is a group with one Save Button: 'Saved' shows for 2 seconds, and the Button is disabled while nothing changed.\n function handleSaveName() {\n if (savingName) return;\n if (!name.trim()) {\n setNameError('Enter your name.');\n return;\n }\n setNameError('');\n setSavingName(true);\n later(() => {\n setSavedName(name.trim());\n setName(name.trim());\n setSavingName(false);\n setNameSaved(true);\n clearTimeout(nameSavedTimer.current);\n nameSavedTimer.current = setTimeout(() => setNameSaved(false), 2000);\n }, 1200);\n }\n\n function handleUpdatePassword() {\n if (savingPassword || !currentPassword || !password) return;\n setCurrentPasswordError('');\n if (password.length < minPasswordLength) {\n setPasswordError(`Use at least ${minPasswordLength} characters.`);\n return;\n }\n setPasswordError('');\n setSavingPassword(true);\n later(() => {\n setSavingPassword(false);\n // A wrong current password shows under that field, and both fields keep what the person typed.\n if (currentPassword === wrongCurrentPassword) {\n setCurrentPasswordError('This is not your current password. Enter it again.');\n return;\n }\n setCurrentPassword('');\n setPassword('');\n setPasswordSaved(true);\n clearTimeout(passwordSavedTimer.current);\n passwordSavedTimer.current = setTimeout(() => setPasswordSaved(false), 2000);\n }, 1200);\n }\n\n const nameChanged = name !== savedName;\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Heading level={1} size=\"h5\">Profile</Heading>\n\n <SettingsSection title=\"Picture\" description=\"Shown beside your name in Acme.\">\n <Cluster gap=\"large\">\n <UserImage userHandle={savedName} userImgUrl={picture} size={64} />\n <Stack gap=\"small\">\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"secondary\" state={savingPicture === 'remove' ? 'disabled' : 'enabled'} label=\"Change Picture\" loading={savingPicture === 'change'} onClickButton={() => savePicture(chosenPicture, 'change')} />\n {picture && <Button size=\"small\" type=\"tertiary\" state={savingPicture === 'change' ? 'disabled' : 'enabled'} label=\"Remove\" aria-label=\"Remove picture\" loading={savingPicture === 'remove'} onClickButton={() => savePicture(undefined, 'remove')} />}\n </Cluster>\n {pictureError && <Alert type=\"error\" variant=\"inline\" autoDismiss={false} message={pictureError} />}\n </Stack>\n </Cluster>\n </SettingsSection>\n\n <SettingsSection title=\"Name\" description=\"How people see you in messages and on tasks.\">\n <Form aria-label=\"Name\" gap=\"medium\" onSubmit={handleSaveName}>\n <FormField id=\"profile-form-name\" label=\"Name\" error={nameError}>\n {(f) => (\n <TextField\n id={f.id}\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={name}\n disabled={savingName}\n autoComplete=\"name\"\n onChange={(e) => { setName(e.target.value); setNameError(''); setNameSaved(false); }}\n />\n )}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={nameChanged || savingName ? 'enabled' : 'disabled'} label={nameSaved ? 'Saved' : 'Save'} htmlType=\"submit\" loading={savingName} />\n </Cluster>\n </Form>\n </SettingsSection>\n\n <SettingsSection title=\"Password\" description=\"Sign in with dana@acme.example and a password.\">\n <Form aria-label=\"Password\" gap=\"medium\" onSubmit={handleUpdatePassword}>\n <FormField id=\"profile-form-current-password\" label=\"Current password\" error={currentPasswordError}>\n {(f) => (\n <TextField\n id={f.id}\n type=\"password\"\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={currentPassword}\n disabled={savingPassword}\n autoComplete=\"current-password\"\n onChange={(e) => { setCurrentPassword(e.target.value); setCurrentPasswordError(''); setPasswordSaved(false); }}\n />\n )}\n </FormField>\n <FormField id=\"profile-form-password\" label=\"New password\" help={`Use at least ${minPasswordLength} characters.`} error={passwordError}>\n {(f) => (\n <TextField\n id={f.id}\n type=\"password\"\n aria-describedby={f['aria-describedby']}\n aria-invalid={f['aria-invalid']}\n value={password}\n disabled={savingPassword}\n autoComplete=\"new-password\"\n onChange={(e) => { setPassword(e.target.value); setPasswordError(''); setPasswordSaved(false); }}\n />\n )}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={(currentPassword && password) || savingPassword ? 'enabled' : 'disabled'} label={passwordSaved ? 'Saved' : 'Update Password'} htmlType=\"submit\" loading={savingPassword} />\n </Cluster>\n </Form>\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
|
|
3426
|
+
"uses": [
|
|
3427
|
+
"Alert",
|
|
3428
|
+
"Button",
|
|
3429
|
+
"Center",
|
|
3430
|
+
"Cluster",
|
|
3431
|
+
"Form",
|
|
3432
|
+
"FormField",
|
|
3433
|
+
"Heading",
|
|
3434
|
+
"SettingsSection",
|
|
3435
|
+
"Stack",
|
|
3436
|
+
"TextField",
|
|
3437
|
+
"UserImage"
|
|
3438
|
+
]
|
|
3439
|
+
}
|
|
3440
|
+
]
|
|
3441
|
+
},
|
|
3442
|
+
{
|
|
3443
|
+
"id": "quick-switcher",
|
|
3444
|
+
"title": "Quick switcher",
|
|
3445
|
+
"kind": "design",
|
|
3446
|
+
"level": "organism",
|
|
3447
|
+
"area": "menu",
|
|
3448
|
+
"situation": "A person jumps to a channel, task or document by typing part of its name, from anywhere in the product.",
|
|
3449
|
+
"do": [
|
|
3450
|
+
"Open it with Cmd+K, or Ctrl+K on Windows, and with a visible 'Go to' Button. A shortcut alone is not found.",
|
|
3451
|
+
"Add the shortcut with `useHotkey('k', …)`. It is removed when the page goes away, and it does nothing while the person types in a field.",
|
|
3452
|
+
"Open a small `Modal` with `initialFocus=\"body\"`, so focus lands in the search field. Closing gives focus back to where it was.",
|
|
3453
|
+
"Build it as a combobox, as the case 'Mention list' says. The field gets `role=\"combobox\"`, `aria-expanded`, `aria-controls` and `aria-activedescendant`.",
|
|
3454
|
+
"Make the list a `Menu role=\"listbox\"` of `MenuItem role=\"option\"` rows, with `isActive` and `aria-selected` on the highlighted one.",
|
|
3455
|
+
"Name the field with `aria-label=\"Go to\"`, since it has no visible label.",
|
|
3456
|
+
"Show the most recent places, at most 6, before the person types.",
|
|
3457
|
+
"Show each place with its icon and name, and where it lives in `secondLabel`.",
|
|
3458
|
+
"Move the highlight with the arrow keys. Enter opens the highlighted place and closes the Modal. Escape closes it.",
|
|
3459
|
+
"Leave Enter and the arrow keys to an input method while it is still composing.",
|
|
3460
|
+
"Follow the case 'Empty search' when nothing matches: the words searched for and a 'Clear Search' Button, which puts focus back in the field."
|
|
3461
|
+
],
|
|
3462
|
+
"dont": [
|
|
3463
|
+
"Do not use the shortcut as the only way in.",
|
|
3464
|
+
"Do not take Cmd+K while the person types in a field. Some fields use it for their own commands.",
|
|
3465
|
+
"Do not move focus into the list. The person keeps typing in the field.",
|
|
3466
|
+
"Do not keep the last search. It opens empty.",
|
|
3467
|
+
"Do not show a toast after going to a place. The page changing says it."
|
|
3468
|
+
],
|
|
3469
|
+
"native": "On Apple use a sheet with a `TextField` over a `List`, opened with `.keyboardShortcut(\"k\")`, and `ContentUnavailableView.search(text:)` when nothing matches. A phone needs no switcher: use the search tab.",
|
|
3470
|
+
"options": [
|
|
3471
|
+
{
|
|
3472
|
+
"id": "modal",
|
|
3473
|
+
"title": "Small Modal with a search field and a list",
|
|
3474
|
+
"useWhen": "The product has many places to go to, and people work with a keyboard.",
|
|
3475
|
+
"source": "'use client';\nimport { useState, type KeyboardEvent } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport useHotkey from 'oneslash-design-system/components/useHotkey';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server. The most recent place comes first.\ntype Place = { id: string; title: string; kind: 'channel' | 'task' | 'doc'; workspace: string };\nconst places: Place[] = [\n { id: 'launch-plan', title: 'launch-plan', kind: 'channel', workspace: 'Acme Design' },\n { id: 'press-kit', title: 'Update the press kit', kind: 'task', workspace: 'Acme Design' },\n { id: 'pricing-notes', title: 'Pricing notes', kind: 'doc', workspace: 'Acme Marketing' },\n { id: 'launch-checklist', title: 'Launch checklist', kind: 'doc', workspace: 'Acme Design' },\n { id: 'design-review', title: 'design-review', kind: 'channel', workspace: 'Acme Design' },\n { id: 'hiring-plan', title: 'Hiring plan', kind: 'doc', workspace: 'Acme Engineering' },\n];\nconst icons = { channel: 'Hash', task: 'SquareCheck', doc: 'FileText' } as const;\n\n// At most this many rows show, so the list never needs to scroll; typing more letters narrows it.\nconst MAX_RESULTS = 6;\nconst listId = 'quick-switcher-results';\nconst optionId = (p: Place) => `quick-switcher-option-${p.id}`;\n\n// Places with a word that starts with what was typed. With nothing typed it shows the most recent.\nfunction matches(query: string) {\n const q = query.trim().toLowerCase();\n if (!q) return places.slice(0, MAX_RESULTS);\n return places.filter((p) => p.title.toLowerCase().split(/[\\s-]+/).some((w) => w.startsWith(q))).slice(0, MAX_RESULTS);\n}\n\nexport default function QuickSwitcherModal() {\n // Opens with the switcher showing, as if the person just pressed Cmd+K.\n const [open, setOpen] = useState(true);\n const [query, setQuery] = useState('la');\n const [active, setActive] = useState(0);\n const [here, setHere] = useState<Place>(places[0]);\n // Bumped by 'Clear Search'. It remounts the search field with `autoFocus`, so focus goes back to the field\n // instead of being lost with the Button that the list replaces.\n const [fieldKey, setFieldKey] = useState(0);\n\n const results = matches(query);\n const listOpen = results.length > 0;\n\n function openSwitcher() {\n setQuery('');\n setActive(0);\n setOpen(true);\n }\n\n // The shortcut works from anywhere on the page except a text field. Cmd+K inside the switcher's own field does nothing.\n useHotkey('k', () => {\n if (!open) openSwitcher();\n });\n\n function change(value: string) {\n setQuery(value);\n setActive(0);\n }\n\n // A real app goes to the place here. Closing hands focus back to what had it before the switcher opened.\n function go(place: Place) {\n setHere(place);\n setOpen(false);\n }\n\n function clearSearch() {\n setQuery('');\n setActive(0);\n setFieldKey((k) => k + 1);\n }\n\n // Focus stays in the field; the arrows move the highlight and Enter opens it. Escape is the Modal's.\n function keyDown(e: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) {\n // An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.\n if (e.nativeEvent.isComposing || e.keyCode === 229) return;\n if (!listOpen) return;\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setActive((i) => Math.min(i + 1, results.length - 1));\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setActive((i) => Math.max(i - 1, 0));\n } else if (e.key === 'Enter') {\n e.preventDefault();\n go(results[active]);\n }\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">{here.title}</Heading>\n {/* A shortcut alone is not found by most people, so a Button opens it too. */}\n <Button\n size=\"small\"\n type=\"secondary\"\n state=\"enabled\"\n label=\"Go to\"\n decoIcon=\"Search\"\n aria-haspopup=\"dialog\"\n aria-keyshortcuts=\"Meta+K Control+K\"\n onClickButton={openSwitcher}\n />\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {here.workspace}. Press Cmd+K, or Ctrl+K on Windows, to go to a channel, task or document.\n </Paragraph>\n </Stack>\n <Modal isOpen={open} size=\"small\" title=\"Go to\" initialFocus=\"body\" onClose={() => setOpen(false)}>\n <Stack gap=\"medium\">\n <TextField\n key={fieldKey}\n id=\"quick-switcher-query\"\n type=\"search\"\n // The Modal focuses the field when it opens. `autoFocus` only after 'Clear Search', which remounts the field.\n autoFocus={fieldKey > 0}\n aria-label=\"Go to\"\n placeholder=\"Search channels, tasks and documents\"\n value={query}\n onChange={(e) => change(e.target.value)}\n onKeyDown={keyDown}\n // Focus stays in the field; the field points at the list and at the highlighted row.\n role=\"combobox\"\n aria-autocomplete=\"list\"\n aria-expanded={listOpen}\n aria-controls={listOpen ? listId : undefined}\n aria-activedescendant={listOpen ? optionId(results[active]) : undefined}\n />\n {listOpen ? (\n <Menu role=\"listbox\" id={listId} aria-label=\"Places\" width=\"100%\">\n {results.map((p, i) => (\n <MenuItem\n key={p.id}\n id={optionId(p)}\n role=\"option\"\n tabIndex={-1}\n isActive={i === active}\n aria-selected={i === active}\n size=\"small\"\n iconName={icons[p.kind]}\n label={p.title}\n secondLabel={p.workspace}\n onClick={() => go(p)}\n />\n ))}\n </Menu>\n ) : (\n // The case 'Empty search' says what to show: the words searched for, and a way to clear them.\n <EmptyBox\n size=\"small\"\n icon=\"Search\"\n text={`No places match \"${query.trim()}\"`}\n secondText=\"Check the spelling, or search for fewer words.\"\n action={<Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Clear Search\" onClickButton={clearSearch} />}\n />\n )}\n </Stack>\n </Modal>\n </Center>\n );\n}\n",
|
|
3476
|
+
"uses": [
|
|
3477
|
+
"Button",
|
|
3478
|
+
"Center",
|
|
3479
|
+
"Cluster",
|
|
3480
|
+
"EmptyBox",
|
|
3481
|
+
"Heading",
|
|
3482
|
+
"Menu",
|
|
3483
|
+
"MenuItem",
|
|
3484
|
+
"Modal",
|
|
3485
|
+
"Paragraph",
|
|
3486
|
+
"Stack",
|
|
3487
|
+
"TextField",
|
|
3488
|
+
"useHotkey"
|
|
3489
|
+
]
|
|
3490
|
+
}
|
|
3491
|
+
]
|
|
3492
|
+
},
|
|
3493
|
+
{
|
|
3494
|
+
"id": "range-switch",
|
|
3495
|
+
"title": "Range switch",
|
|
3496
|
+
"kind": "design",
|
|
3497
|
+
"level": "organism",
|
|
3498
|
+
"area": "menu",
|
|
3499
|
+
"situation": "A person changes the time range of a chart or a list on the same page, such as Week, Month or Quarter.",
|
|
3500
|
+
"do": [
|
|
3501
|
+
"Use `SegmentedControl` with `size=\"small\"` and `aria-label=\"Range\"`: 'Week', 'Month', 'Quarter'.",
|
|
3502
|
+
"Put it beside the heading of the chart or list it changes, with `width=\"fit\"` so it is as wide as its options.",
|
|
3503
|
+
"Keep one option on at all times. Start on 'Week', the newest numbers, unless the page is about a longer period.",
|
|
3504
|
+
"Change the numbers in place and keep the page, the heading and the scroll position.",
|
|
3505
|
+
"Move between options with the arrow keys. They select as they move."
|
|
3506
|
+
],
|
|
3507
|
+
"dont": [
|
|
3508
|
+
"Do not use tabs. Tabs switch panels, and this changes one value on the same page.",
|
|
3509
|
+
"Do not use more than four options. Use a menu, as the case 'Filter menu' says.",
|
|
3510
|
+
"Do not let the person turn every option off.",
|
|
3511
|
+
"Do not hide a range of three choices behind a menu."
|
|
3512
|
+
],
|
|
3513
|
+
"native": "On Apple use a `Picker` with the `.segmented` style, and on Android a `SingleChoiceSegmentedButtonRow`.",
|
|
3514
|
+
"options": [
|
|
3515
|
+
{
|
|
3516
|
+
"id": "segmented",
|
|
3517
|
+
"title": "Segmented control",
|
|
3518
|
+
"useWhen": "Two to four short choices change the numbers on one page, and one is always on.",
|
|
3519
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport SegmentedControl from 'oneslash-design-system/components/segmentedControl';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app counts these on the server.\nconst ranges = [\n { value: 'week', label: 'Week', count: 18 },\n { value: 'month', label: 'Month', count: 64 },\n { value: 'quarter', label: 'Quarter', count: 171 },\n];\n\nexport default function RangeSwitchSegmented() {\n const [range, setRange] = useState('week');\n const current = ranges.find((r) => r.value === range) ?? ranges[0];\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Heading level={1} size=\"h5\">Overview</Heading>\n <SegmentedControl\n size=\"small\"\n width=\"fit\"\n aria-label=\"Range\"\n options={ranges.map(({ value, label }) => ({ value, label }))}\n value={range}\n onChange={setRange}\n />\n </Cluster>\n {/* The chart or list below changes with the range. This page stays the same. */}\n <Paragraph size=\"body2\" measure=\"none\">{current.count} comments this {current.label.toLowerCase()}.</Paragraph>\n </Stack>\n </Center>\n );\n}\n",
|
|
3520
|
+
"uses": [
|
|
3521
|
+
"Center",
|
|
3522
|
+
"Cluster",
|
|
3523
|
+
"Heading",
|
|
3524
|
+
"Paragraph",
|
|
3525
|
+
"SegmentedControl",
|
|
3526
|
+
"Stack"
|
|
3527
|
+
]
|
|
3528
|
+
}
|
|
3529
|
+
]
|
|
3530
|
+
},
|
|
3531
|
+
{
|
|
3532
|
+
"id": "rename",
|
|
3533
|
+
"title": "Rename",
|
|
3534
|
+
"kind": "design",
|
|
3535
|
+
"level": "organism",
|
|
3536
|
+
"area": "confirm",
|
|
3537
|
+
"situation": "A person renames something, such as a project or a channel.",
|
|
3538
|
+
"do": [
|
|
3539
|
+
"Title the Modal 'Rename' and the thing, such as 'Rename Project', and give its action the same verb: 'Rename'.",
|
|
3540
|
+
"Keep 'Rename' `state=\"disabled\"` while the name is empty or unchanged.",
|
|
3541
|
+
"Save on Enter too: put the field in a `Form`.",
|
|
3542
|
+
"Show a name that is taken under the field, with `error` and `errorText`, and keep the Modal open.",
|
|
3543
|
+
"Focus the field with `autoFocus` when the name becomes a field in place.",
|
|
3544
|
+
"Save on Enter and when the person leaves the field. Cancel on Escape, and when the name is empty."
|
|
3545
|
+
],
|
|
3546
|
+
"dont": [
|
|
3547
|
+
"Do not label the Modal's action 'Save' or 'OK'.",
|
|
3548
|
+
"Do not show a toast after a rename. The new name shows where the old one was.",
|
|
3549
|
+
"Do not save an empty name.",
|
|
3550
|
+
"Do not drop what the person typed when they leave the field."
|
|
3551
|
+
],
|
|
3552
|
+
"native": "On Apple rename in place in a list with a `TextField` and `.onSubmit`. Use an `.alert` with a `TextField` when the name is not on screen.",
|
|
3553
|
+
"options": [
|
|
3554
|
+
{
|
|
3555
|
+
"id": "modal",
|
|
3556
|
+
"title": "Rename in a Modal",
|
|
3557
|
+
"useWhen": "Rename is opened from a menu or from far away from the name.",
|
|
3558
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Form from 'oneslash-design-system/components/form';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// Names the server already has. Type one to see the request fail.\nconst takenNames = ['website refresh', 'hiring plan', 'office move'];\n\nexport default function RenameModal() {\n const [name, setName] = useState('Q3 plan');\n // Opens on the Modal, as if the person just chose Rename Project.\n const [open, setOpen] = useState(true);\n const [draft, setDraft] = useState('Q3 plan');\n const [nameError, setNameError] = useState('');\n const [saving, setSaving] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n const next = draft.trim();\n const canRename = next !== '' && next !== name;\n\n function handleOpen() {\n setDraft(name);\n setNameError('');\n setOpen(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleClose() {\n if (saving) return;\n setOpen(false);\n }\n\n function handleRename() {\n if (saving || !canRename) return;\n setNameError('');\n setSaving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setSaving(false);\n if (takenNames.includes(next.toLowerCase())) {\n setNameError(`A project named '${next}' already exists. Choose another name.`);\n return;\n }\n setName(next);\n setOpen(false);\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n <Heading level={1} size=\"h5\">{name}</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>\n {/* A real app often opens Rename from a menu on the project. */}\n <Cluster>\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Rename Project\" onClickButton={handleOpen} />\n </Cluster>\n </Stack>\n <Modal\n isOpen={open}\n size=\"small\"\n initialFocus=\"body\"\n title=\"Rename Project\"\n onClose={handleClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={saving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleClose} />\n <Button size=\"small\" type=\"primary\" state={canRename ? 'enabled' : 'disabled'} label=\"Rename\" loading={saving} onClickButton={handleRename} />\n </>\n }\n >\n {/* The Form lets Enter in the field rename too. */}\n <Form aria-label=\"Rename project\" onSubmit={handleRename}>\n <TextField id=\"rename-name\" label=\"Project name\" value={draft} disabled={saving} error={Boolean(nameError)} errorText={nameError} onChange={(e) => { setDraft(e.target.value); setNameError(''); }} />\n </Form>\n </Modal>\n </Center>\n );\n}\n",
|
|
3559
|
+
"uses": [
|
|
3560
|
+
"Button",
|
|
3561
|
+
"Center",
|
|
3562
|
+
"Cluster",
|
|
3563
|
+
"Form",
|
|
3564
|
+
"Heading",
|
|
3565
|
+
"Modal",
|
|
3566
|
+
"Paragraph",
|
|
3567
|
+
"Stack",
|
|
3568
|
+
"TextField"
|
|
3569
|
+
]
|
|
3570
|
+
},
|
|
3571
|
+
{
|
|
3572
|
+
"id": "inline",
|
|
3573
|
+
"title": "Rename in place",
|
|
3574
|
+
"useWhen": "The name is on screen, and it becomes a field.",
|
|
3575
|
+
"source": "'use client';\nimport { useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nexport default function RenameInline() {\n const [name, setName] = useState('Q3 plan');\n // Opens with the name as a field, as if the person just chose Rename.\n const [editing, setEditing] = useState(true);\n const [draft, setDraft] = useState('Q3 plan');\n // Enter and Escape end the edit before the field goes away, so its blur must not save again.\n const ended = useRef(false);\n\n function startEditing() {\n ended.current = false;\n setDraft(name);\n setEditing(true);\n }\n\n function save() {\n if (ended.current) return;\n ended.current = true;\n const next = draft.trim();\n // An empty or unchanged name cancels: there is nothing to send.\n // Otherwise a real app sends the new name to the server here and shows it at once.\n if (next && next !== name) setName(next);\n setEditing(false);\n }\n\n function cancel() {\n if (ended.current) return;\n ended.current = true;\n setEditing(false);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"medium\">\n {editing ? (\n <TextField\n id=\"rename-inline-name\"\n label=\"Project name\"\n value={draft}\n autoFocus\n onChange={(e) => setDraft(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n save();\n } else if (e.key === 'Escape') {\n e.preventDefault();\n cancel();\n }\n }}\n onBlur={save}\n />\n ) : (\n <Cluster gap=\"small\">\n <Heading level={1} size=\"h5\">{name}</Heading>\n <Tooltip title=\"Rename\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"small\" iconName=\"Pencil\" ariaLabel=\"Rename project\" onClick={startEditing} />\n </Tooltip>\n </Cluster>\n )}\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">12 tasks. Updated 2 days ago by Dana Lee.</Paragraph>\n </Stack>\n </Center>\n );\n}\n",
|
|
3576
|
+
"uses": [
|
|
3577
|
+
"Center",
|
|
3578
|
+
"Cluster",
|
|
3579
|
+
"Heading",
|
|
3580
|
+
"IconButton",
|
|
3581
|
+
"Paragraph",
|
|
3582
|
+
"Stack",
|
|
3583
|
+
"TextField",
|
|
3584
|
+
"Tooltip"
|
|
3585
|
+
]
|
|
3586
|
+
}
|
|
3587
|
+
]
|
|
3588
|
+
},
|
|
3589
|
+
{
|
|
3590
|
+
"id": "reply-feedback",
|
|
2637
3591
|
"title": "Reply feedback",
|
|
2638
3592
|
"kind": "design",
|
|
2639
3593
|
"level": "organism",
|
|
@@ -2666,10 +3620,6 @@
|
|
|
2666
3620
|
"Do not show feedback buttons on a person's message.",
|
|
2667
3621
|
"Do not show Regenerate on an older reply."
|
|
2668
3622
|
],
|
|
2669
|
-
"notBuiltYet": "Scindo on the web shows thumbs down only, with no thumbs up and no Copy, and the button goes away once pressed. Its thanks reads 'Noted, we'll improve.' Its reasons are Buttons, Skip is a cross, and Regenerate sits in the hover toolbar. Scindo's Apple app has no feedback buttons and no Regenerate.",
|
|
2670
|
-
"seenIn": [
|
|
2671
|
-
"Scindo"
|
|
2672
|
-
],
|
|
2673
3623
|
"options": [
|
|
2674
3624
|
{
|
|
2675
3625
|
"id": "thumbs",
|
|
@@ -2744,10 +3694,6 @@
|
|
|
2744
3694
|
"Do not show more than six cards before the person asks for the rest."
|
|
2745
3695
|
],
|
|
2746
3696
|
"native": "On Apple the cards fill as many columns as fit. A card with a link opens it in the browser, and a card with nothing to open cannot be tapped.",
|
|
2747
|
-
"notBuiltYet": "Scindo cannot hide the sources again once they are all shown, and its button reads 'Show N more', in sentence case. The meta of a card that cannot be opened does not say why.",
|
|
2748
|
-
"seenIn": [
|
|
2749
|
-
"Scindo"
|
|
2750
|
-
],
|
|
2751
3697
|
"options": [
|
|
2752
3698
|
{
|
|
2753
3699
|
"id": "cards",
|
|
@@ -2808,10 +3754,6 @@
|
|
|
2808
3754
|
"Do not show the empty text while the list is still loading."
|
|
2809
3755
|
],
|
|
2810
3756
|
"native": "On Apple use `ProgressView()` with no label, centered in the pane.",
|
|
2811
|
-
"seenIn": [
|
|
2812
|
-
"Commentify",
|
|
2813
|
-
"Scindo"
|
|
2814
|
-
],
|
|
2815
3757
|
"options": [
|
|
2816
3758
|
{
|
|
2817
3759
|
"id": "full-screen",
|
|
@@ -2827,15 +3769,59 @@
|
|
|
2827
3769
|
"id": "region",
|
|
2828
3770
|
"title": "In one pane",
|
|
2829
3771
|
"useWhen": "The shell shows and one pane loads.",
|
|
2830
|
-
"source": "'use client';\nimport
|
|
3772
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport AppShell from 'oneslash-design-system/components/appShell';\nimport Navigation, { NavigationGroup } from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Surface from 'oneslash-design-system/components/surface';\nimport LoadingScreen from 'oneslash-design-system/components/loadingScreen';\n\n// The places, and the projects the person made. The page that failed or loads is the current one.\nconst places = [\n { label: 'Home', icon: 'House', href: '/' },\n { label: 'Settings', icon: 'Settings', href: '/settings' },\n];\nconst projects = [\n { label: 'Website', icon: 'Globe', href: '/projects/website' },\n { label: 'Mobile App', icon: 'Smartphone', href: '/projects/mobile-app' },\n];\nconst current = '/projects/website';\n\nconst row = (p: { label: string; icon: string; href: string }) => (\n <MenuItem\n key={p.href}\n size=\"small\"\n label={p.label}\n iconName={p.icon}\n href={p.href}\n isSelected={p.href === current}\n aria-current={p.href === current ? 'page' : undefined}\n // A real app lets the link go to its page.\n onClick={(event: { preventDefault: () => void }) => event.preventDefault()}\n />\n);\n\nconst sidebar = (\n <Navigation aria-label=\"Main\">\n <Paragraph size=\"body1\" measure=\"none\">Acme</Paragraph>\n {places.map(row)}\n <NavigationGroup label=\"Projects\">{projects.map(row)}</NavigationGroup>\n </Navigation>\n);\n\nexport default function RouteLoadingRegion() {\n // Below md the sidebar is a Drawer; this says whether it is open.\n const [navOpen, setNavOpen] = useState(false);\n return (\n <AppShell title=\"Website\" navOpen={navOpen} onNavOpenChange={setNavOpen} sidebar={sidebar}>\n <Surface minHeight=\"tall\" align=\"center\">\n <LoadingScreen />\n </Surface>\n </AppShell>\n );\n}\n",
|
|
2831
3773
|
"uses": [
|
|
2832
|
-
"
|
|
2833
|
-
"Image",
|
|
3774
|
+
"AppShell",
|
|
2834
3775
|
"LoadingScreen",
|
|
2835
|
-
"
|
|
2836
|
-
"
|
|
2837
|
-
"
|
|
2838
|
-
"
|
|
3776
|
+
"MenuItem",
|
|
3777
|
+
"Navigation",
|
|
3778
|
+
"NavigationGroup",
|
|
3779
|
+
"Paragraph",
|
|
3780
|
+
"Surface"
|
|
3781
|
+
]
|
|
3782
|
+
}
|
|
3783
|
+
]
|
|
3784
|
+
},
|
|
3785
|
+
{
|
|
3786
|
+
"id": "scope-picker",
|
|
3787
|
+
"title": "Scope picker",
|
|
3788
|
+
"kind": "design",
|
|
3789
|
+
"level": "organism",
|
|
3790
|
+
"area": "menu",
|
|
3791
|
+
"situation": "A person chooses where a search or a question looks, such as one workspace or all of them.",
|
|
3792
|
+
"do": [
|
|
3793
|
+
"Use a small tertiary `Button` whose label is the current scope, with `actionIcon=\"ChevronDown\"` so it looks like it opens a menu.",
|
|
3794
|
+
"Open a navigable menu from it: `<Popover returnFocus>` around `<Menu navigable aria-label=\"Where to search\">` with `onClick` items.",
|
|
3795
|
+
"Put 'All Workspaces' first, then a `Line`, then one item for each workspace.",
|
|
3796
|
+
"Give each item `role=\"menuitemradio\"` and mark the current scope with `isSelected`, which sets `aria-checked`.",
|
|
3797
|
+
"Give the Button an `aria-label` that starts with its label and says what it does: 'Acme Design, change where to search'.",
|
|
3798
|
+
"Set `aria-haspopup=\"menu\"` and `aria-expanded` on the Button, and `state=\"selected\"` while the menu is open.",
|
|
3799
|
+
"Say what the scope means under the control, such as which workspaces the answers use."
|
|
3800
|
+
],
|
|
3801
|
+
"dont": [
|
|
3802
|
+
"Do not use a `Select` for a scope that sits in a toolbar.",
|
|
3803
|
+
"Do not put the scope in the Button without a chevron.",
|
|
3804
|
+
"Do not open the menu when the page loads.",
|
|
3805
|
+
"Do not keep the menu open after a choice."
|
|
3806
|
+
],
|
|
3807
|
+
"native": "On Apple use a toolbar `Menu` with a `Picker` inside it, and on Android a dropdown menu.",
|
|
3808
|
+
"options": [
|
|
3809
|
+
{
|
|
3810
|
+
"id": "menu",
|
|
3811
|
+
"title": "Button with a menu",
|
|
3812
|
+
"useWhen": "There are a few places to choose from, and one choice means everything.",
|
|
3813
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Line from 'oneslash-design-system/components/line';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst workspaces = ['Acme Design', 'Acme Engineering', 'Acme Marketing'];\nconst all = 'All Workspaces';\n\nexport default function ScopePickerMenu() {\n // null means every workspace.\n const [scope, setScope] = useState<string | null>(null);\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const label = scope ?? all;\n\n function toggle(anchorEl: HTMLElement) {\n setAnchor(anchorEl);\n setOpen((o) => !o);\n }\n\n function choose(next: string | null) {\n setScope(next);\n setOpen(false);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Ask Acme</Heading>\n <Cluster gap=\"small\">\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Searching in</Paragraph>\n {/* The label is the scope. The chevron says it opens a menu. */}\n <Button\n size=\"small\"\n type=\"tertiary\"\n state={open ? 'selected' : 'enabled'}\n label={label}\n actionIcon=\"ChevronDown\"\n aria-label={`${label}, change where to search`}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n onClickButton={(e: { currentTarget: HTMLElement }) => toggle(e.currentTarget)}\n />\n </Cluster>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {scope ? `Answers use only ${scope}.` : `Answers use all ${workspaces.length} of your workspaces.`}\n </Paragraph>\n </Stack>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Where to search\" width={220}>\n <MenuItem size=\"small\" label={all} isSelected={scope === null} role=\"menuitemradio\" onClick={() => choose(null)} />\n <Line />\n {workspaces.map((w) => (\n <MenuItem key={w} size=\"small\" label={w} isSelected={scope === w} role=\"menuitemradio\" onClick={() => choose(w)} />\n ))}\n </Menu>\n </Popover>\n </Center>\n );\n}\n",
|
|
3814
|
+
"uses": [
|
|
3815
|
+
"Button",
|
|
3816
|
+
"Center",
|
|
3817
|
+
"Cluster",
|
|
3818
|
+
"Heading",
|
|
3819
|
+
"Line",
|
|
3820
|
+
"Menu",
|
|
3821
|
+
"MenuItem",
|
|
3822
|
+
"Paragraph",
|
|
3823
|
+
"Popover",
|
|
3824
|
+
"Stack"
|
|
2839
3825
|
]
|
|
2840
3826
|
}
|
|
2841
3827
|
]
|
|
@@ -2864,11 +3850,6 @@
|
|
|
2864
3850
|
"Do not replace the form with a spinner while updating.",
|
|
2865
3851
|
"Do not show the form when the link is invalid or expired."
|
|
2866
3852
|
],
|
|
2867
|
-
"notBuiltYet": "Commentify and Scindo on the web replace the form with a spinner while updating, and show field problems in an Alert above the fields. Both accept 6 characters, and say 'Password must be at least 6 characters.' only after it is broken. Scindo's reset page has no invalid-link state.",
|
|
2868
|
-
"seenIn": [
|
|
2869
|
-
"Commentify",
|
|
2870
|
-
"Scindo"
|
|
2871
|
-
],
|
|
2872
3853
|
"options": [
|
|
2873
3854
|
{
|
|
2874
3855
|
"id": "form",
|
|
@@ -2908,6 +3889,241 @@
|
|
|
2908
3889
|
}
|
|
2909
3890
|
]
|
|
2910
3891
|
},
|
|
3892
|
+
{
|
|
3893
|
+
"id": "settings-page",
|
|
3894
|
+
"title": "Settings page",
|
|
3895
|
+
"kind": "design",
|
|
3896
|
+
"level": "page",
|
|
3897
|
+
"area": "settings",
|
|
3898
|
+
"situation": "A person opens the settings of the product and looks for one area, such as Profile or Billing.",
|
|
3899
|
+
"do": [
|
|
3900
|
+
"Title the page 'Settings' with a level 1 `Heading`.",
|
|
3901
|
+
"Follow the rule 'A setting saves in place, or with one Save Button' in every area.",
|
|
3902
|
+
"Put each area's controls in `SettingsSection`s. Put them in `SettingsColumns` when an area has several: one column on a phone, two from `md`.",
|
|
3903
|
+
"Give each `Tab` an `href` and the app's `router`, so the selected Tab follows the page.",
|
|
3904
|
+
"Keep the tabs to four areas or fewer, each named with one short word, such as 'Profile' or 'Billing', so the tabs fit on a phone without scrolling.",
|
|
3905
|
+
"Group the areas in a `Navigation` with `aria-label=\"Settings\"` when there are more. Give each `NavigationGroup` a `label`, such as 'Account' and 'Workspace'.",
|
|
3906
|
+
"Make each nav item a `MenuItem` with an `href`. Mark the open one with `isSelected` and `aria-current=\"page\"`.",
|
|
3907
|
+
"Put 'Log Out' last in the nav, and ask first as the case 'Log-out confirm' says.",
|
|
3908
|
+
"Use `SettingsLayout` for the side nav. From `md` the nav sits beside the area. On a phone the nav is the page, and choosing an item opens that area alone.",
|
|
3909
|
+
"Show a 'Back to Settings' Button above the area on a phone, and nothing at `md` and up. It goes back to the nav.",
|
|
3910
|
+
"Show a setting a person cannot change as read-only, with one line that says who can: 'Only owners can change this.'"
|
|
3911
|
+
],
|
|
3912
|
+
"dont": [
|
|
3913
|
+
"Do not use tabs for more than four areas. They run off a phone screen.",
|
|
3914
|
+
"Do not show the nav and the area together on a phone.",
|
|
3915
|
+
"Do not leave a phone with no way back to the nav.",
|
|
3916
|
+
"Do not put a Save Button for the whole page. Each group saves by itself.",
|
|
3917
|
+
"Do not call it 'Preferences' in one place and 'Settings' in another."
|
|
3918
|
+
],
|
|
3919
|
+
"native": "On macOS use a `Settings` scene with one tab per area, or a `NavigationSplitView` with a sidebar `List` in `Section`s. On iPhone the list is the first screen and an item pushes its area. On Android use a list of areas that opens each one on its own screen.",
|
|
3920
|
+
"options": [
|
|
3921
|
+
{
|
|
3922
|
+
"id": "top-tabs",
|
|
3923
|
+
"title": "Tabs across the top",
|
|
3924
|
+
"useWhen": "Four areas or fewer, with short names that fit on a phone.",
|
|
3925
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport List from 'oneslash-design-system/components/list';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Switch from 'oneslash-design-system/components/switch';\nimport Button from 'oneslash-design-system/components/button';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport SettingsSection, { SettingsColumns } from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Area = 'profile' | 'notifications' | 'billing';\n\n// Four areas or fewer, each named with one short word, so the tabs fit on a phone. Each tab is a page of its own in a real app, so it has an `href`.\nconst areas: { id: Area; label: string }[] = [\n { id: 'profile', label: 'Profile' },\n { id: 'notifications', label: 'Notifications' },\n { id: 'billing', label: 'Billing' },\n];\n\nconst invoices = ['January 2025, $40.00', 'December 2024, $40.00', 'November 2024, $40.00'];\n\nexport default function SettingsPageTopTabs() {\n const [area, setArea] = useState<Area>('profile');\n const [savedName, setSavedName] = useState('Dana Lee');\n const [name, setName] = useState('Dana Lee');\n const [nameError, setNameError] = useState('');\n const [saving, setSaving] = useState(false);\n const [saved, setSaved] = useState(false);\n const [values, setValues] = useState({ mentions: true, digest: false });\n const [busy, setBusy] = useState({ mentions: false, digest: false });\n // A real app passes the router from its framework, such as Next's useRouter(). Here it sets the open area.\n const router = { push: (url: string) => setArea(url.split('/').pop() as Area) };\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // Cleared before a new 'Saved' starts, so an old timer cannot end it early.\n const savedTimer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops every request and the 'Saved' if the example goes away before they end.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n clearTimeout(savedTimer.current);\n }, []);\n\n // A group of fields has one Save Button: `loading`, then 'Saved' for 2 seconds.\n function handleSave() {\n if (saving) return;\n if (!name.trim()) {\n setNameError('Enter your name.');\n return;\n }\n setNameError('');\n setSaving(true);\n // Stands in for the request to the server.\n timers.current.push(setTimeout(() => {\n setSavedName(name.trim());\n setName(name.trim());\n setSaving(false);\n setSaved(true);\n clearTimeout(savedTimer.current);\n savedTimer.current = setTimeout(() => setSaved(false), 2000);\n }, 1200));\n }\n\n // A switch on its own saves as soon as it changes, and shows nothing when it works.\n function handleSwitch(key: 'mentions' | 'digest', next: boolean) {\n setBusy((current) => ({ ...current, [key]: true }));\n setValues((current) => ({ ...current, [key]: next }));\n timers.current.push(setTimeout(() => setBusy((current) => ({ ...current, [key]: false })), 900));\n }\n\n const profile = (\n <SettingsColumns>\n <SettingsSection id=\"settings-page-tabs-name\" title=\"Name\" description=\"How people see you in messages and on tasks.\">\n <Form aria-label=\"Name\" gap=\"medium\" onSubmit={handleSave}>\n <FormField id=\"settings-page-tabs-name-field\" label=\"Name\" error={nameError}>\n {(f) => <TextField id={f.id} aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} value={name} disabled={saving} onChange={(e) => { setName(e.target.value); setNameError(''); setSaved(false); }} />}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={name !== savedName || saving ? 'enabled' : 'disabled'} label={saved ? 'Saved' : 'Save'} htmlType=\"submit\" loading={saving} />\n </Cluster>\n </Form>\n </SettingsSection>\n <SettingsSection id=\"settings-page-tabs-email\" title=\"Email\" description=\"Where Acme writes to you.\">\n <FormField id=\"settings-page-tabs-email-field\" label=\"Email\" help=\"Only support can change this. Write to help@acme.example.\">\n {(f) => <TextField id={f.id} aria-describedby={f['aria-describedby']} value=\"dana@acme.example\" readOnly onChange={() => {}} />}\n </FormField>\n </SettingsSection>\n </SettingsColumns>\n );\n\n const notifications = (\n <SettingsColumns>\n <SettingsSection id=\"settings-page-tabs-email-alerts\" title=\"Email\" description=\"Sent to dana@acme.example.\">\n <Switch id=\"settings-page-tabs-mentions\" label=\"Mentions\" description=\"An email when someone mentions you.\" checked={values.mentions} busy={busy.mentions} onChange={(next) => handleSwitch('mentions', next)} />\n <Switch id=\"settings-page-tabs-digest\" label=\"Weekly digest\" description=\"A summary of last week, every Monday.\" checked={values.digest} busy={busy.digest} onChange={(next) => handleSwitch('digest', next)} />\n </SettingsSection>\n </SettingsColumns>\n );\n\n const billing = (\n <SettingsColumns>\n <SettingsSection id=\"settings-page-tabs-plan\" title=\"Plan\" description=\"Team plan, 5 seats.\">\n <Paragraph size=\"body2\" measure=\"none\">Renews on January 15. Only owners can change the plan.</Paragraph>\n </SettingsSection>\n <SettingsSection id=\"settings-page-tabs-invoices\" title=\"Invoices\" description=\"The last three months.\">\n <List items={invoices} size=\"body2\" />\n </SettingsSection>\n </SettingsColumns>\n );\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Heading level={1} size=\"h5\">Settings</Heading>\n <TabsContainer>\n {areas.map((a) => (\n <Tab key={a.id} label={a.label} href={`/settings/${a.id}`} router={router} isSelected={area === a.id} onClickTab={() => setArea(a.id)} />\n ))}\n </TabsContainer>\n {area === 'profile' && profile}\n {area === 'notifications' && notifications}\n {area === 'billing' && billing}\n </Stack>\n </Center>\n );\n}\n",
|
|
3926
|
+
"uses": [
|
|
3927
|
+
"Button",
|
|
3928
|
+
"Center",
|
|
3929
|
+
"Cluster",
|
|
3930
|
+
"Form",
|
|
3931
|
+
"FormField",
|
|
3932
|
+
"Heading",
|
|
3933
|
+
"List",
|
|
3934
|
+
"Paragraph",
|
|
3935
|
+
"SettingsColumns",
|
|
3936
|
+
"SettingsSection",
|
|
3937
|
+
"Stack",
|
|
3938
|
+
"Switch",
|
|
3939
|
+
"Tab",
|
|
3940
|
+
"TabsContainer",
|
|
3941
|
+
"TextField"
|
|
3942
|
+
]
|
|
3943
|
+
},
|
|
3944
|
+
{
|
|
3945
|
+
"id": "side-nav",
|
|
3946
|
+
"title": "Side navigation in groups",
|
|
3947
|
+
"useWhen": "There are more areas, and they fall into groups.",
|
|
3948
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Form from 'oneslash-design-system/components/form';\nimport FormField from 'oneslash-design-system/components/formField';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Switch from 'oneslash-design-system/components/switch';\nimport Button from 'oneslash-design-system/components/button';\nimport Navigation, { NavigationGroup } from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport SettingsSection, { SettingsLayout } from 'oneslash-design-system/components/settingsSection';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Area = { id: string; label: string; icon: string; group: string; description: string };\n\n// Areas in groups, as the side nav lists them. Each is a page of its own in a real app, so it has an `href`.\nconst areas: Area[] = [\n { id: 'profile', label: 'Profile', icon: 'User', group: 'Account', description: 'How people see you in Acme.' },\n { id: 'notifications', label: 'Notifications', icon: 'Bell', group: 'Account', description: 'Choose what reaches you.' },\n { id: 'general', label: 'General', icon: 'Settings', group: 'Workspace', description: 'The name and defaults of the Acme workspace.' },\n { id: 'members', label: 'Members', icon: 'Users', group: 'Workspace', description: 'Who is in Acme, and what they can do.' },\n { id: 'billing', label: 'Billing', icon: 'CreditCard', group: 'Workspace', description: 'Your plan and invoices.' },\n { id: 'api-keys', label: 'API Keys', icon: 'Key', group: 'Developers', description: 'Keys for tools that use Acme.' },\n { id: 'webhooks', label: 'Webhooks', icon: 'Webhook', group: 'Developers', description: 'Send Acme events to other tools.' },\n];\n\nconst groups = ['Account', 'Workspace', 'Developers'];\n\nexport default function SettingsPageSideNav() {\n const [areaId, setAreaId] = useState('profile');\n // On a phone the nav is the page: it shows until the person opens an area, and 'Back to Settings' returns to it.\n const [opened, setOpened] = useState(false);\n const [savedName, setSavedName] = useState('Dana Lee');\n const [name, setName] = useState('Dana Lee');\n const [nameError, setNameError] = useState('');\n const [saving, setSaving] = useState(false);\n const [saved, setSaved] = useState(false);\n const [values, setValues] = useState({ mentions: true, digest: false });\n const [busy, setBusy] = useState({ mentions: false, digest: false });\n const [confirmingLogOut, setConfirmingLogOut] = useState(false);\n const [loggingOut, setLoggingOut] = useState(false);\n const [loggedOut, setLoggedOut] = useState(false);\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n // Cleared before a new 'Saved' starts, so an old timer cannot end it early.\n const savedTimer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops every request and the 'Saved' if the example goes away before they end.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n clearTimeout(savedTimer.current);\n }, []);\n\n const area = areas.find((a) => a.id === areaId) ?? areas[0];\n\n function handleOpen(id: string) {\n setAreaId(id);\n setOpened(true);\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function handleLogOutClose() {\n if (loggingOut) return;\n setConfirmingLogOut(false);\n }\n\n function handleLogOut() {\n if (loggingOut) return;\n setLoggingOut(true);\n timers.current.push(setTimeout(() => {\n setLoggingOut(false);\n setConfirmingLogOut(false);\n setLoggedOut(true);\n }, 1200));\n }\n\n // A group of fields has one Save Button: `loading`, then 'Saved' for 2 seconds.\n function handleSave() {\n if (saving) return;\n if (!name.trim()) {\n setNameError('Enter your name.');\n return;\n }\n setNameError('');\n setSaving(true);\n // Stands in for the request to the server.\n timers.current.push(setTimeout(() => {\n setSavedName(name.trim());\n setName(name.trim());\n setSaving(false);\n setSaved(true);\n clearTimeout(savedTimer.current);\n savedTimer.current = setTimeout(() => setSaved(false), 2000);\n }, 1200));\n }\n\n // A switch on its own saves as soon as it changes, and shows nothing when it works.\n function handleSwitch(key: 'mentions' | 'digest', next: boolean) {\n setBusy((current) => ({ ...current, [key]: true }));\n setValues((current) => ({ ...current, [key]: next }));\n timers.current.push(setTimeout(() => setBusy((current) => ({ ...current, [key]: false })), 900));\n }\n\n const profile = (\n <SettingsSection id=\"settings-page-nav-name\" title=\"Name\" description=\"How people see you in messages and on tasks.\">\n <Form aria-label=\"Name\" gap=\"medium\" onSubmit={handleSave}>\n <FormField id=\"settings-page-nav-name-field\" label=\"Name\" error={nameError}>\n {(f) => <TextField id={f.id} aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} value={name} disabled={saving} onChange={(e) => { setName(e.target.value); setNameError(''); setSaved(false); }} />}\n </FormField>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state={name !== savedName || saving ? 'enabled' : 'disabled'} label={saved ? 'Saved' : 'Save'} htmlType=\"submit\" loading={saving} />\n </Cluster>\n </Form>\n </SettingsSection>\n );\n\n const notifications = (\n <SettingsSection id=\"settings-page-nav-email\" title=\"Email\" description=\"Sent to dana@acme.example.\">\n <Switch id=\"settings-page-nav-mentions\" label=\"Mentions\" description=\"An email when someone mentions you.\" checked={values.mentions} busy={busy.mentions} onChange={(next) => handleSwitch('mentions', next)} />\n <Switch id=\"settings-page-nav-digest\" label=\"Weekly digest\" description=\"A summary of last week, every Monday.\" checked={values.digest} busy={busy.digest} onChange={(next) => handleSwitch('digest', next)} />\n </SettingsSection>\n );\n\n // A real app goes to its login page here. The example shows a short logged-out page instead.\n if (loggedOut) {\n return (\n <Center fill>\n <Heading level={1} size=\"h5\">You are logged out</Heading>\n <Cluster>\n <Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Log In\" onClickButton={() => setLoggedOut(false)} />\n </Cluster>\n </Center>\n );\n }\n\n const nav = (\n <Navigation aria-label=\"Settings\">\n {groups.map((group) => (\n <NavigationGroup key={group} label={group}>\n {areas.filter((a) => a.group === group).map((a) => (\n <MenuItem\n key={a.id}\n size=\"small\"\n label={a.label}\n iconName={a.icon}\n href={`/settings/${a.id}`}\n isSelected={a.id === area.id}\n aria-current={a.id === area.id ? 'page' : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example keeps the choice in state.\n event.preventDefault();\n handleOpen(a.id);\n }}\n />\n ))}\n </NavigationGroup>\n ))}\n <NavigationGroup label=\"Session\">\n <MenuItem size=\"small\" label=\"Log Out\" iconName=\"LogOut\" role=\"button\" onClick={() => setConfirmingLogOut(true)} />\n </NavigationGroup>\n </Navigation>\n );\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Heading level={1} size=\"h5\">Settings</Heading>\n <SettingsLayout\n nav={nav}\n showContent={opened}\n back={<Button size=\"small\" type=\"tertiary\" state=\"enabled\" decoIcon=\"ChevronLeft\" label=\"Back to Settings\" onClickButton={() => setOpened(false)} />}\n >\n <Stack gap=\"small\">\n <Heading level={2} size=\"h6\">{area.label}</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{area.description}</Paragraph>\n </Stack>\n {area.id === 'profile' && profile}\n {area.id === 'notifications' && notifications}\n {area.id !== 'profile' && area.id !== 'notifications' && (\n <Paragraph size=\"body2\" measure=\"none\">Nothing to show for {area.label} in this example.</Paragraph>\n )}\n </SettingsLayout>\n </Stack>\n <Modal\n isOpen={confirmingLogOut}\n size=\"small\"\n title=\"Log Out\"\n onClose={handleLogOutClose}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={loggingOut ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={handleLogOutClose} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Log Out\" loading={loggingOut} onClickButton={handleLogOut} />\n </>\n }\n >\n <Paragraph measure=\"none\">You will need to log in again to use Acme on this device.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
|
|
3949
|
+
"uses": [
|
|
3950
|
+
"Button",
|
|
3951
|
+
"Center",
|
|
3952
|
+
"Cluster",
|
|
3953
|
+
"Form",
|
|
3954
|
+
"FormField",
|
|
3955
|
+
"Heading",
|
|
3956
|
+
"MenuItem",
|
|
3957
|
+
"Modal",
|
|
3958
|
+
"Navigation",
|
|
3959
|
+
"NavigationGroup",
|
|
3960
|
+
"Paragraph",
|
|
3961
|
+
"SettingsLayout",
|
|
3962
|
+
"SettingsSection",
|
|
3963
|
+
"Stack",
|
|
3964
|
+
"Switch",
|
|
3965
|
+
"TextField"
|
|
3966
|
+
]
|
|
3967
|
+
}
|
|
3968
|
+
]
|
|
3969
|
+
},
|
|
3970
|
+
{
|
|
3971
|
+
"id": "settings-save",
|
|
3972
|
+
"title": "A setting saves in place, or with one Save Button",
|
|
3973
|
+
"kind": "rule",
|
|
3974
|
+
"level": "rule",
|
|
3975
|
+
"area": "settings",
|
|
3976
|
+
"situation": "A person changes a setting.",
|
|
3977
|
+
"answer": "A control that stands alone saves as soon as it changes: a `Switch`, a choice in a `RadioGroup` or a `Select`, or a picture the person chooses. It shows nothing on success, because the control already shows the new value. While the request runs it is busy: a `Switch` takes `busy`, and a `RadioGroup` or `Select` is disabled. If the save fails, the control goes back to its old value and says why next to itself: in a Switch's `error`, in the error line of its `FormField`, or in an inline error `Alert` under a control with no visible label, such as a role in a row. A group of fields that belong together, such as a name, a profile, instructions or a budget, has one Save Button for the whole group. The Button is `loading` while it saves, keeps its label, then reads 'Saved' for 2 seconds. It is disabled while nothing has changed. A group that fails to save follows the rule 'A form error shows next to the problem'. Leaving with unsaved changes follows the case 'Unsaved changes'. Never mix both in one group: a Switch beside a Save Button leaves the person unsure which one is saved. Never show a toast for a setting saved in place. The one exception is a setting chosen from a menu: the menu closes, so a failed save shows in a toast and the control goes back to its old value. A person who cannot change a setting sees it read-only, with one line that says who can change it.",
|
|
3978
|
+
"why": "A control that saves by itself needs no button, and a group needs one place to say it is saved. Mixing the two makes people guess what is saved and what is not.",
|
|
3979
|
+
"do": [
|
|
3980
|
+
"Save a `Switch`, a `RadioGroup` or a `Select` that stands alone as soon as it changes.",
|
|
3981
|
+
"Set the Switch `busy`, or disable the `RadioGroup` or `Select`, while the request runs, and show nothing when it works.",
|
|
3982
|
+
"Put the old value back when a save fails, and say why next to the control: 'Could not save. Try again.'",
|
|
3983
|
+
"Give a group of fields that belong together one Save Button.",
|
|
3984
|
+
"Show `loading` on the Save Button while it saves, keep its label, then show 'Saved' for 2 seconds.",
|
|
3985
|
+
"Keep the Save Button `state=\"disabled\"` while nothing has changed.",
|
|
3986
|
+
"Show a failed group save as the rule 'A form error shows next to the problem' says.",
|
|
3987
|
+
"Follow the case 'Unsaved changes' when the person leaves a group with changes.",
|
|
3988
|
+
"Show a setting the person cannot change as read-only, with one line that says who can: 'Only owners can change this.'"
|
|
3989
|
+
],
|
|
3990
|
+
"dont": [
|
|
3991
|
+
"Do not mix a control that saves on change and a Save Button in one group.",
|
|
3992
|
+
"Do not show a toast for a setting saved in place, except a failed save of a setting chosen from a menu.",
|
|
3993
|
+
"Do not change the Button's label while it is loading, such as to 'Saving…'.",
|
|
3994
|
+
"Do not leave a failed save without a message.",
|
|
3995
|
+
"Do not use a `Checkbox` for an on/off setting that saves on change. Use a `Switch`."
|
|
3996
|
+
],
|
|
3997
|
+
"native": "On Apple use the system `Toggle` and `Picker` that save as they change, and a `Form` with one Save Button for a group of fields. On Android use a `Switch`."
|
|
3998
|
+
},
|
|
3999
|
+
{
|
|
4000
|
+
"id": "side-pane",
|
|
4001
|
+
"title": "Side pane",
|
|
4002
|
+
"kind": "design",
|
|
4003
|
+
"level": "organism",
|
|
4004
|
+
"area": "shell",
|
|
4005
|
+
"situation": "A person opens more about the page, such as its members, its history or a document, without leaving the page.",
|
|
4006
|
+
"do": [
|
|
4007
|
+
"Follow the rule 'On a phone, a sidebar opens as a drawer and a list opens its detail': on a phone a pane takes the whole content area.",
|
|
4008
|
+
"Put the pane in the `pane` of `AppShell`, as a `SidePane` with a `title` and `onClose`. Render it only while it is open.",
|
|
4009
|
+
"Open it from an `IconButton` with a name and `aria-expanded`, and give it `state=\"selected\"` while the pane is open.",
|
|
4010
|
+
"Show one pane at a time. Opening another replaces the first. Pressing the opener of the open pane calls `focus()` on the pane's ref instead of opening a second one.",
|
|
4011
|
+
"Let Close and Escape close the pane. Focus goes back to the opener.",
|
|
4012
|
+
"Open a pane only from the person's own action. It takes focus when it mounts.",
|
|
4013
|
+
"Make a pane resizable only when it holds a document: pass `width` and `onWidthChange`. The start edge then moves with the pointer and with the arrow keys.",
|
|
4014
|
+
"Use `Drawer side=\"end\"` with a `title` for a short task. On a phone it is a sheet from the bottom.",
|
|
4015
|
+
"Give a Drawer `initialFocus=\"body\"` when it holds a control, so focus lands on the control. Keep the Drawer open while its request runs.",
|
|
4016
|
+
"Show the result of a task in the page behind the Drawer, such as 'Assigned to Ben Carter.' Show no toast.",
|
|
4017
|
+
"Title a Drawer for its action in Title Case, as a Modal: 'Assign Task'. Title a pane that shows one thing with its name.",
|
|
4018
|
+
"Put 'Cancel' first and the action last, named with the title's verb: 'Assign Task' has an 'Assign' Button. If the request fails, keep the Drawer open and show an inline error Alert at its top, as the rule 'A form error shows next to the problem' says."
|
|
4019
|
+
],
|
|
4020
|
+
"dont": [
|
|
4021
|
+
"Do not squeeze a pane beside the page on a phone.",
|
|
4022
|
+
"Do not open two panes at once.",
|
|
4023
|
+
"Do not open a pane when the page loads, or from a timer. It takes focus away from the person.",
|
|
4024
|
+
"Do not make a list of members resizable. Only a document needs room.",
|
|
4025
|
+
"Do not use a Drawer for something the person reads together with the page."
|
|
4026
|
+
],
|
|
4027
|
+
"native": "On Apple use an inspector (`.inspector`) for a pane beside the page, and a `.sheet` with `presentationDetents` for a short task. On Android use a `ModalBottomSheet` for a short task.",
|
|
4028
|
+
"options": [
|
|
4029
|
+
{
|
|
4030
|
+
"id": "beside",
|
|
4031
|
+
"title": "Pane beside the page",
|
|
4032
|
+
"useWhen": "The person reads the pane and the page together, such as members, history or a document.",
|
|
4033
|
+
"source": "'use client';\nimport { useRef, useState } from 'react';\nimport AppShell from 'oneslash-design-system/components/appShell';\nimport SidePane, { type SidePaneHandle } from 'oneslash-design-system/components/sidePane';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport Navigation, { NavigationGroup } from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype PaneId = 'members' | 'brief';\n\nconst members = [\n { name: 'Dana Lee', role: 'Owner' },\n { name: 'Ben Carter', role: 'Editor' },\n { name: 'Omar Reyes', role: 'Editor' },\n];\n\nconst places = [\n { id: 'inbox', label: 'Inbox', icon: 'Inbox' },\n { id: 'tasks', label: 'Tasks', icon: 'ListChecks' },\n { id: 'files', label: 'Files', icon: 'Files' },\n];\n// The projects the person made\nconst projects = [\n { id: 'website', label: 'Website', icon: 'Globe' },\n { id: 'mobile-app', label: 'Mobile App', icon: 'Smartphone' },\n];\n\nexport default function SidePaneBeside() {\n const [navOpen, setNavOpen] = useState(false);\n const [placeId, setPlaceId] = useState('tasks');\n // One pane at a time. Opening another replaces it.\n const [open, setOpen] = useState<PaneId | null>(null);\n // Only the pane that holds a document can be resized.\n const [briefWidth, setBriefWidth] = useState(448);\n const pane = useRef<SidePaneHandle>(null);\n\n const place = [...places, ...projects].find((p) => p.id === placeId) ?? places[0];\n\n // Pressed again while its pane is open, the opener brings the pane forward instead of opening a second one.\n function opener(id: PaneId, label: string, icon: 'Users' | 'FileText') {\n return (\n <Tooltip title={label}>\n <IconButton\n color=\"iconOnly\"\n state={open === id ? 'selected' : 'enabled'}\n size=\"medium\"\n iconName={icon}\n ariaLabel={label}\n aria-expanded={open === id}\n onClick={() => (open === id ? pane.current?.focus() : setOpen(id))}\n />\n </Tooltip>\n );\n }\n\n const row = (p: { id: string; label: string; icon: string }) => (\n <MenuItem\n key={p.id}\n size=\"small\"\n label={p.label}\n iconName={p.icon}\n href={`/${p.id}`}\n isSelected={p.id === place.id}\n aria-current={p.id === place.id ? 'page' : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example keeps the choice in state.\n event.preventDefault();\n setPlaceId(p.id);\n }}\n />\n );\n\n const sidebar = (\n <Navigation aria-label=\"Main\">\n {places.map(row)}\n <NavigationGroup label=\"Projects\">{projects.map(row)}</NavigationGroup>\n </Navigation>\n );\n\n return (\n <AppShell\n title={place.label}\n navOpen={navOpen}\n onNavOpenChange={setNavOpen}\n sidebar={sidebar}\n pane={\n open && (\n <SidePane\n key={open}\n ref={pane}\n title={open === 'members' ? 'Members' : 'Brief'}\n onClose={() => setOpen(null)}\n width={open === 'brief' ? briefWidth : undefined}\n onWidthChange={open === 'brief' ? setBriefWidth : undefined}\n >\n {open === 'members' ? (\n <Stack gap=\"medium\">\n {members.map((m) => (\n <Cluster key={m.name}>\n <UserImage userHandle={m.name} decorative />\n <Paragraph size=\"body1\" measure=\"none\">{m.name}</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{m.role}</Paragraph>\n </Cluster>\n ))}\n </Stack>\n ) : (\n <Stack gap=\"medium\">\n <Paragraph measure=\"none\">Acme ships the new home page on Friday. Omar Reyes owns the copy and Dana Lee the screens.</Paragraph>\n <Paragraph tone=\"secondary\" measure=\"none\">The pane stays beside the page, so the task and the brief are read together. Drag its edge, or use the arrow keys on it, to make it wider.</Paragraph>\n </Stack>\n )}\n </SidePane>\n )\n }\n >\n <Stack gap=\"large\">\n <TitleBar title=\"Launch plan\" actions={<>{opener('members', 'Members', 'Users')}{opener('brief', 'Brief', 'FileText')}</>} />\n <Paragraph tone=\"secondary\" measure=\"none\">Ben Carter is writing the announcement. Omar Reyes is waiting for the new screens.</Paragraph>\n </Stack>\n </AppShell>\n );\n}\n",
|
|
4034
|
+
"uses": [
|
|
4035
|
+
"AppShell",
|
|
4036
|
+
"Cluster",
|
|
4037
|
+
"IconButton",
|
|
4038
|
+
"MenuItem",
|
|
4039
|
+
"Navigation",
|
|
4040
|
+
"NavigationGroup",
|
|
4041
|
+
"Paragraph",
|
|
4042
|
+
"SidePane",
|
|
4043
|
+
"Stack",
|
|
4044
|
+
"TitleBar",
|
|
4045
|
+
"Tooltip",
|
|
4046
|
+
"UserImage"
|
|
4047
|
+
]
|
|
4048
|
+
},
|
|
4049
|
+
{
|
|
4050
|
+
"id": "over",
|
|
4051
|
+
"title": "Drawer over the page",
|
|
4052
|
+
"useWhen": "The task is short and the page can be hidden for a moment, such as picking a person.",
|
|
4053
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Drawer from 'oneslash-design-system/components/drawer';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport RadioGroup from 'oneslash-design-system/components/radioGroup';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst people = [\n { label: 'Dana Lee', value: 'dana' },\n { label: 'Ben Carter', value: 'ben' },\n { label: 'Omar Reyes', value: 'omar' },\n];\n\nexport default function SidePaneOver() {\n const [open, setOpen] = useState(false);\n // The person on the task, and the one picked in the sheet before Assign.\n const [assigned, setAssigned] = useState('');\n const [picked, setPicked] = useState('dana');\n const [saving, setSaving] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // Escape, the scrim, Close and Cancel all close it, except while the request runs.\n function close() {\n if (saving) return;\n setOpen(false);\n }\n\n function assign() {\n if (saving) return;\n setSaving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setSaving(false);\n setAssigned(people.find((p) => p.value === picked)?.label ?? '');\n setOpen(false);\n }, 1200);\n }\n\n return (\n <PageShell>\n <Stack gap=\"large\">\n <TitleBar title=\"Launch plan\" actions={<Button size=\"medium\" type=\"secondary\" state=\"enabled\" label=\"Assign\" decoIcon=\"UserPlus\" onClickButton={() => setOpen(true)} />} />\n {/* The result shows here, where the person is looking, so there is no toast. */}\n <Paragraph tone=\"secondary\" measure=\"none\">{assigned ? `Assigned to ${assigned}.` : 'Nobody is assigned yet.'}</Paragraph>\n </Stack>\n <Drawer isOpen={open} onClose={close} side=\"end\" size=\"small\" title=\"Assign Task\" initialFocus=\"body\">\n <Stack gap=\"large\">\n <RadioGroup aria-label=\"Person\" options={people} selectedValue={picked} disabled={saving} onChange={setPicked} />\n <Cluster justify=\"end\">\n <Button size=\"small\" type=\"tertiary\" state={saving ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={close} />\n <Button size=\"small\" type=\"primary\" state=\"enabled\" label=\"Assign\" loading={saving} onClickButton={assign} />\n </Cluster>\n </Stack>\n </Drawer>\n </PageShell>\n );\n}\n",
|
|
4054
|
+
"uses": [
|
|
4055
|
+
"Button",
|
|
4056
|
+
"Cluster",
|
|
4057
|
+
"Drawer",
|
|
4058
|
+
"PageShell",
|
|
4059
|
+
"Paragraph",
|
|
4060
|
+
"RadioGroup",
|
|
4061
|
+
"Stack",
|
|
4062
|
+
"TitleBar"
|
|
4063
|
+
]
|
|
4064
|
+
}
|
|
4065
|
+
]
|
|
4066
|
+
},
|
|
4067
|
+
{
|
|
4068
|
+
"id": "sidebar-nav",
|
|
4069
|
+
"title": "Sidebar with sections and counts",
|
|
4070
|
+
"kind": "design",
|
|
4071
|
+
"level": "organism",
|
|
4072
|
+
"area": "shell",
|
|
4073
|
+
"situation": "A person looks down the sidebar for a place, and for what has something new in it.",
|
|
4074
|
+
"do": [
|
|
4075
|
+
"Follow the rule 'On a phone, a sidebar opens as a drawer and a list opens its detail'.",
|
|
4076
|
+
"Build it as a `Navigation` with `aria-label=\"Main\"`, and put the places in `NavigationGroup`s with a short `label`, such as 'Mail' and 'Tasks'.",
|
|
4077
|
+
"Make each place a `MenuItem` with an `href`. Mark the open one with `isSelected` and `aria-current=\"page\"`.",
|
|
4078
|
+
"Show the count of what has not been read, never a total, as a `tag` with `variant=\"textOnly\"`.",
|
|
4079
|
+
"Put the count in the row's name too: `aria-label=\"Inbox, 3 unread\"`. Start the name with the visible label.",
|
|
4080
|
+
"Show nothing at zero. Opening a place reads it, so its count goes away.",
|
|
4081
|
+
"Put 'New Task' at the top of its group, as a `MenuItem` with `role=\"button\"`. The new task opens at the top of the group.",
|
|
4082
|
+
"Make the row that holds the others a `MenuItem` with `role=\"button\"`, `aria-expanded` and a chevron in `iconRight`. Name it for the place: 'Acme'.",
|
|
4083
|
+
"Keep a place the person closed closed when they return. Save it for the person, such as in local storage or their profile.",
|
|
4084
|
+
"Show the sum of what is unread under a closed place on its own row, so nothing unread is out of sight.",
|
|
4085
|
+
"Show a place inside another with `level={2}` on its `MenuItem`, and keep its own icon.",
|
|
4086
|
+
"Give each 'New Task' a name that says where it goes: `aria-label=\"New task in Acme\"`. In a phone menu, close the menu in its `onClick`, since a button row does not close it."
|
|
4087
|
+
],
|
|
4088
|
+
"dont": [
|
|
4089
|
+
"Do not show a total of everything, such as every task. A count is what needs the person.",
|
|
4090
|
+
"Do not show '0'. Leave the count out.",
|
|
4091
|
+
"Do not color a count red, even for a mention. A count is quiet text.",
|
|
4092
|
+
"Do not close a place with no sign of what is inside it. A closed place keeps its count.",
|
|
4093
|
+
"Do not close a place without `aria-expanded` on its row."
|
|
4094
|
+
],
|
|
4095
|
+
"native": "On Apple use a sidebar `List` with `Section`s, a `.badge(count)` on each row, and a `DisclosureGroup` for places that hold places. On Android use a navigation drawer with a `Badge`.",
|
|
4096
|
+
"options": [
|
|
4097
|
+
{
|
|
4098
|
+
"id": "flat",
|
|
4099
|
+
"title": "One list in a few groups",
|
|
4100
|
+
"useWhen": "Each place is one row, and the places fall into a few groups.",
|
|
4101
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport Navigation, { NavigationGroup } from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\ntype Place = { id: string; label: string; icon: string; group: string };\n\nconst initialPlaces: Place[] = [\n { id: 'inbox', label: 'Inbox', icon: 'Inbox', group: 'Mail' },\n { id: 'mentions', label: 'Mentions', icon: 'AtSign', group: 'Mail' },\n { id: 'sent', label: 'Sent', icon: 'Send', group: 'Mail' },\n { id: 'launch', label: 'Launch plan', icon: 'ListChecks', group: 'Tasks' },\n { id: 'review', label: 'Design review', icon: 'ListChecks', group: 'Tasks' },\n { id: 'pricing', label: 'Pricing page', icon: 'ListChecks', group: 'Tasks' },\n];\n\nconst groups = ['Mail', 'Tasks'];\n\n// What has not been read, by place. A place with none has no entry, and shows no count.\nconst initialUnread: Record<string, number> = { inbox: 3, mentions: 1, launch: 2 };\n\nexport default function SidebarNavFlat() {\n const [places, setPlaces] = useState(initialPlaces);\n const [currentId, setCurrentId] = useState('sent');\n const [unread, setUnread] = useState(initialUnread);\n const [created, setCreated] = useState(0);\n\n const current = places.find((p) => p.id === currentId) ?? places[0];\n\n // Opening a place reads it, so its count goes away.\n function open(id: string) {\n setCurrentId(id);\n setUnread((u) => ({ ...u, [id]: 0 }));\n }\n\n // The new task goes to the top of its group, and opens.\n function newTask() {\n const id = `new-${created + 1}`;\n setCreated(created + 1);\n setPlaces((all) => [{ id, label: `New task ${created + 1}`, icon: 'ListChecks', group: 'Tasks' }, ...all]);\n setCurrentId(id);\n }\n\n return (\n <Center>\n <Stack gap=\"large\">\n <Navigation aria-label=\"Main\">\n {groups.map((group) => (\n <NavigationGroup key={group} label={group}>\n {group === 'Tasks' && <MenuItem size=\"small\" iconName=\"Plus\" label=\"New Task\" role=\"button\" onClick={newTask} />}\n {places.filter((p) => p.group === group).map((p) => {\n const count = unread[p.id] ?? 0;\n return (\n <MenuItem\n key={p.id}\n size=\"small\"\n label={p.label}\n iconName={p.icon}\n href={`/${p.id}`}\n isSelected={p.id === current.id}\n aria-current={p.id === current.id ? 'page' : undefined}\n // A count is what has not been read, as quiet text. Nothing shows at zero, and the name says the count.\n tag={count > 0 ? { label: String(count), variant: 'textOnly' } : undefined}\n aria-label={count > 0 ? `${p.label}, ${count} unread` : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n // A real app lets the link go to its page. The example keeps the choice in state.\n event.preventDefault();\n open(p.id);\n }}\n />\n );\n })}\n </NavigationGroup>\n ))}\n </Navigation>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">You are in {current.label}.</Paragraph>\n </Stack>\n </Center>\n );\n}\n",
|
|
4102
|
+
"uses": [
|
|
4103
|
+
"Center",
|
|
4104
|
+
"MenuItem",
|
|
4105
|
+
"Navigation",
|
|
4106
|
+
"NavigationGroup",
|
|
4107
|
+
"Paragraph",
|
|
4108
|
+
"Stack"
|
|
4109
|
+
]
|
|
4110
|
+
},
|
|
4111
|
+
{
|
|
4112
|
+
"id": "nested",
|
|
4113
|
+
"title": "Places that hold places",
|
|
4114
|
+
"useWhen": "A place holds others, such as a workspace and its tasks, and the person wants to hide what they do not use.",
|
|
4115
|
+
"source": "'use client';\nimport { useEffect, useState } from 'react';\nimport Navigation, { NavigationGroup } from 'oneslash-design-system/components/navigation';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\ntype Task = { id: string; label: string };\ntype Workspace = { id: string; name: string; tasks: Task[] };\n\nconst initialWorkspaces: Workspace[] = [\n {\n id: 'acme',\n name: 'Acme',\n tasks: [\n { id: 'launch', label: 'Launch plan' },\n { id: 'pricing', label: 'Pricing page' },\n ],\n },\n {\n id: 'studio',\n name: 'Side Studio',\n tasks: [\n { id: 'logo', label: 'New logo' },\n { id: 'site', label: 'Landing page' },\n ],\n },\n];\n\n// What has not been read, by place. A place with none has no entry, and shows no count.\nconst initialUnread: Record<string, number> = { pricing: 2, site: 1 };\n\nconst STORAGE_KEY = 'sidebar-nav-hidden-groups';\n\nexport default function SidebarNavNested() {\n const [workspaces, setWorkspaces] = useState(initialWorkspaces);\n const [currentId, setCurrentId] = useState('launch');\n const [unread, setUnread] = useState(initialUnread);\n const [created, setCreated] = useState(0);\n // The groups the person hid. They stay hidden when the person comes back, so a real app saves them per person.\n const [hiddenGroups, setHiddenGroups] = useState<string[]>([]);\n\n // Read after the first render, so the server and the browser start from the same page.\n useEffect(() => {\n try {\n const saved = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? '[]');\n if (Array.isArray(saved)) setHiddenGroups(saved.filter((id) => typeof id === 'string'));\n } catch {\n // Storage can be blocked. The groups then start shown.\n }\n }, []);\n\n function toggleGroup(id: string) {\n const next = hiddenGroups.includes(id) ? hiddenGroups.filter((g) => g !== id) : [...hiddenGroups, id];\n setHiddenGroups(next);\n try {\n localStorage.setItem(STORAGE_KEY, JSON.stringify(next));\n } catch {\n // Storage can be blocked. The choice then lasts until the page closes.\n }\n }\n\n function open(id: string) {\n setCurrentId(id);\n setUnread((u) => ({ ...u, [id]: 0 }));\n }\n\n // The new task goes to the top of its group, and opens.\n function newTask(workspaceId: string) {\n const id = `new-${created + 1}`;\n setCreated(created + 1);\n setWorkspaces((all) => all.map((w) => (w.id === workspaceId ? { ...w, tasks: [{ id, label: `New task ${created + 1}` }, ...w.tasks] } : w)));\n setCurrentId(id);\n }\n\n const currentName = workspaces.flatMap((w) => w.tasks).find((t) => t.id === currentId)?.label ?? '';\n\n return (\n <Center>\n <Stack gap=\"large\">\n <Navigation aria-label=\"Main\">\n <NavigationGroup label=\"Workspaces\">\n {workspaces.map((w) => {\n const hidden = hiddenGroups.includes(w.id);\n // A closed place keeps its count, on its own row, so nothing unread is out of sight.\n const hiddenUnread = hidden ? w.tasks.reduce((sum, t) => sum + (unread[t.id] ?? 0), 0) : 0;\n return (\n <Stack key={w.id} gap=\"small\">\n {/* The row that holds the others shows or hides them. It keeps its name; aria-expanded says which. */}\n <MenuItem\n size=\"small\"\n label={w.name}\n iconName=\"Building2\"\n iconRight={hidden ? 'ChevronRight' : 'ChevronDown'}\n role=\"button\"\n aria-expanded={!hidden}\n // A closed place keeps its count here, and the name says it.\n tag={hiddenUnread > 0 ? { label: String(hiddenUnread), variant: 'textOnly' } : undefined}\n aria-label={hiddenUnread > 0 ? `${w.name}, ${hiddenUnread} unread` : undefined}\n onClick={() => toggleGroup(w.id)}\n />\n {/* Each workspace has its own New Task, so its name says which. In a phone menu, close the menu in this onClick. */}\n {!hidden && <MenuItem size=\"small\" level={2} iconName=\"Plus\" label=\"New Task\" aria-label={`New task in ${w.name}`} role=\"button\" onClick={() => newTask(w.id)} />}\n {!hidden && w.tasks.map((t) => (\n <MenuItem\n key={t.id}\n size=\"small\"\n label={t.label}\n level={2}\n iconName=\"ListChecks\"\n href={`/${w.id}/${t.id}`}\n isSelected={t.id === currentId}\n aria-current={t.id === currentId ? 'page' : undefined}\n tag={(unread[t.id] ?? 0) > 0 ? { label: String(unread[t.id]), variant: 'textOnly' } : undefined}\n aria-label={(unread[t.id] ?? 0) > 0 ? `${t.label}, ${unread[t.id]} unread` : undefined}\n onClick={(event: { preventDefault: () => void }) => {\n event.preventDefault();\n open(t.id);\n }}\n />\n ))}\n </Stack>\n );\n })}\n </NavigationGroup>\n </Navigation>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">You are in {currentName}.</Paragraph>\n </Stack>\n </Center>\n );\n}\n",
|
|
4116
|
+
"uses": [
|
|
4117
|
+
"Center",
|
|
4118
|
+
"MenuItem",
|
|
4119
|
+
"Navigation",
|
|
4120
|
+
"NavigationGroup",
|
|
4121
|
+
"Paragraph",
|
|
4122
|
+
"Stack"
|
|
4123
|
+
]
|
|
4124
|
+
}
|
|
4125
|
+
]
|
|
4126
|
+
},
|
|
2911
4127
|
{
|
|
2912
4128
|
"id": "sign-up-page",
|
|
2913
4129
|
"title": "Sign-up page",
|
|
@@ -2934,12 +4150,7 @@
|
|
|
2934
4150
|
"Do not replace the form with a spinner while creating the account.",
|
|
2935
4151
|
"Do not say on the page whether an address already has an account."
|
|
2936
4152
|
],
|
|
2937
|
-
"native": "On Apple,
|
|
2938
|
-
"notBuiltYet": "Commentify and Scindo on the web replace the form with a spinner while creating the account. Neither says a password rule on its sign-up page. Their reset pages accept 6 characters and say 'Password must be at least 6 characters.' only after it is broken. Commentify asks for the first and last name in two fields.",
|
|
2939
|
-
"seenIn": [
|
|
2940
|
-
"Commentify",
|
|
2941
|
-
"Scindo"
|
|
2942
|
-
],
|
|
4153
|
+
"native": "On Apple, the app opens the web sign-up page with a `Link`. A sign-up built in the app uses `SignInWithAppleButton` for Apple, a grouped form for the fields, and system buttons.",
|
|
2943
4154
|
"options": [
|
|
2944
4155
|
{
|
|
2945
4156
|
"id": "centered",
|
|
@@ -3009,6 +4220,121 @@
|
|
|
3009
4220
|
}
|
|
3010
4221
|
]
|
|
3011
4222
|
},
|
|
4223
|
+
{
|
|
4224
|
+
"id": "site-footer",
|
|
4225
|
+
"title": "Site footer",
|
|
4226
|
+
"kind": "design",
|
|
4227
|
+
"level": "organism",
|
|
4228
|
+
"area": "shell",
|
|
4229
|
+
"situation": "A person reaches the end of a site's page and looks for the pages that are not in the header, and who runs the site.",
|
|
4230
|
+
"do": [
|
|
4231
|
+
"Use `SiteFooter` at the end of the page, after `PageShell`. It is a `<footer>` with a `<nav aria-label=\"Footer\">`.",
|
|
4232
|
+
"Pass the brand, so the person can go home, and the links. Use `links` for a few and `columns` for many.",
|
|
4233
|
+
"Give each column a short `title`, such as 'Product', 'Company' and 'Legal'. A phone shows two columns across and a wide window up to four.",
|
|
4234
|
+
"Put the legal line last, in `legal`: the year and the name, and the license if there is one, such as '© 2026 Acme. Released under the MIT License.'",
|
|
4235
|
+
"Mark a link to another site with `external`. It opens in a new tab and the icon and the hidden words '(opens in a new tab)' say so.",
|
|
4236
|
+
"Keep the footer to links and the legal line. It holds every page the header leaves out, in plain words."
|
|
4237
|
+
],
|
|
4238
|
+
"dont": [
|
|
4239
|
+
"Do not put a sales pitch, a heading or a Button in the footer. Use a call to action band above it.",
|
|
4240
|
+
"Do not open an external link in a new tab without saying so.",
|
|
4241
|
+
"Do not repeat a long sentence of the page in the footer.",
|
|
4242
|
+
"Do not hide a link on a phone. The columns sit two across.",
|
|
4243
|
+
"Do not put the legal line before the links."
|
|
4244
|
+
],
|
|
4245
|
+
"native": "On Apple and Android an app has no footer. Put the links in a settings or an About screen, as a `List` of rows.",
|
|
4246
|
+
"options": [
|
|
4247
|
+
{
|
|
4248
|
+
"id": "simple",
|
|
4249
|
+
"title": "A row of links",
|
|
4250
|
+
"useWhen": "The site has a few links to show.",
|
|
4251
|
+
"source": "'use client';\nimport SiteFooter from 'oneslash-design-system/components/siteFooter';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\nconst links = [\n { label: 'Pricing', href: '#pricing' },\n { label: 'Changelog', href: '#changelog' },\n { label: 'Privacy', href: '#privacy' },\n { label: 'GitHub', href: 'https://github.com/acme/acme', external: true },\n];\n\nexport default function SiteFooterSimple() {\n return (\n <>\n {/* A real page puts its content in PageShell, then SiteFooter. Center keeps the footer in view here. */}\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Changelog</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">Version 2.4 adds shared folders. Ben Carter wrote the notes.</Paragraph>\n </Stack>\n </Center>\n {/* A few links in one row that wraps, then the legal line last. */}\n <SiteFooter\n brand={{ href: '#top', name: 'Acme' }}\n links={links}\n legal=\"© 2026 Acme. Released under the MIT License.\"\n />\n </>\n );\n}\n",
|
|
4252
|
+
"uses": [
|
|
4253
|
+
"Center",
|
|
4254
|
+
"Heading",
|
|
4255
|
+
"Paragraph",
|
|
4256
|
+
"SiteFooter",
|
|
4257
|
+
"Stack"
|
|
4258
|
+
]
|
|
4259
|
+
},
|
|
4260
|
+
{
|
|
4261
|
+
"id": "columns",
|
|
4262
|
+
"title": "Links in groups",
|
|
4263
|
+
"useWhen": "The site has many links that fall into groups, such as product, company and legal.",
|
|
4264
|
+
"source": "'use client';\nimport SiteFooter from 'oneslash-design-system/components/siteFooter';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\nconst columns = [\n {\n title: 'Product',\n links: [\n { label: 'Features', href: '#features' },\n { label: 'Pricing', href: '#pricing' },\n { label: 'Changelog', href: '#changelog' },\n { label: 'Docs', href: '#docs' },\n ],\n },\n {\n title: 'Company',\n links: [\n { label: 'About', href: '#about' },\n { label: 'Blog', href: '#blog' },\n { label: 'Contact', href: '#contact' },\n ],\n },\n {\n title: 'Follow',\n links: [\n { label: 'GitHub', href: 'https://github.com/acme/acme', external: true },\n { label: 'Newsletter', href: 'https://acme.example/newsletter', external: true },\n ],\n },\n {\n title: 'Legal',\n links: [\n { label: 'Terms', href: '#terms' },\n { label: 'Privacy', href: '#privacy' },\n ],\n },\n];\n\nexport default function SiteFooterColumns() {\n return (\n <>\n {/* A real page puts its content in PageShell, then SiteFooter. Center keeps the footer in view here. */}\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">About Acme</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">Acme helps small teams share files and decide together.</Paragraph>\n </Stack>\n </Center>\n {/* Groups of links, two across on a phone and four across from md. The legal line is last. */}\n <SiteFooter\n brand={{ href: '#top', name: 'Acme' }}\n columns={columns}\n legal=\"© 2026 Acme. All rights reserved.\"\n />\n </>\n );\n}\n",
|
|
4265
|
+
"uses": [
|
|
4266
|
+
"Center",
|
|
4267
|
+
"Heading",
|
|
4268
|
+
"Paragraph",
|
|
4269
|
+
"SiteFooter",
|
|
4270
|
+
"Stack"
|
|
4271
|
+
]
|
|
4272
|
+
}
|
|
4273
|
+
]
|
|
4274
|
+
},
|
|
4275
|
+
{
|
|
4276
|
+
"id": "site-header",
|
|
4277
|
+
"title": "Site header",
|
|
4278
|
+
"kind": "design",
|
|
4279
|
+
"level": "organism",
|
|
4280
|
+
"area": "shell",
|
|
4281
|
+
"situation": "A site's pages name the site at the top and show the person where to go and what to do next.",
|
|
4282
|
+
"do": [
|
|
4283
|
+
"Follow the rule 'On a phone, a sidebar opens as a drawer and a list opens its detail': below `md` the links go into a menu and one main action stays in the bar.",
|
|
4284
|
+
"Use `SiteHeader` for a few pages. Pass the brand, at most five `links`, and mark the page the person is on with `current`.",
|
|
4285
|
+
"Pass what must stay in the bar on a phone as `phoneAction`. On a product site that is the main action, named 'Open App' or 'Sign Up'. It is last at every width. Do not repeat it in `actions`.",
|
|
4286
|
+
"Pass the secondary Buttons, such as 'Log In', as `actions`. They go into the menu on a phone.",
|
|
4287
|
+
"Give `PageShell` `id` and `tabIndex={-1}` to match `mainId`, so the 'Skip to content' link moves focus into the page.",
|
|
4288
|
+
"Give a site with sections one `TabsContainer` of `Tab`s with `href`, four sections or fewer and one short word each. Pass it as `nav` to `SiteHeader` with `links` empty: it is a second row of the bar at every width.",
|
|
4289
|
+
"Pass search and the theme menu as `phoneAction`, so they stay at the end of the bar on a phone. With no `links` and no `actions` there is no menu.",
|
|
4290
|
+
"Keep the section tabs in the bar, so no section is hidden. On a phone, put the pages of the open section in a menu, as the case 'Menu on a phone' shows in 'Sections with their pages'.",
|
|
4291
|
+
"Open the theme menu as the case 'Theme switcher' says, and name the search `IconButton` 'Search'."
|
|
4292
|
+
],
|
|
4293
|
+
"dont": [
|
|
4294
|
+
"Do not show more than five links in the bar.",
|
|
4295
|
+
"Do not show two primary Buttons in the bar.",
|
|
4296
|
+
"Do not hide a link on a phone without a menu that holds it.",
|
|
4297
|
+
"Do not put a Button that opens a Modal in `actions`. On a phone the menu closes when it is chosen, so the Modal has no Button to give focus back to. Link to a page instead.",
|
|
4298
|
+
"Do not turn a product site's few pages into tabs. Use `links`. Tabs are for sections that each hold many pages."
|
|
4299
|
+
],
|
|
4300
|
+
"native": "On Apple a site header has no counterpart: an app uses a `NavigationStack` with a navigation bar. On Android use a top app bar.",
|
|
4301
|
+
"options": [
|
|
4302
|
+
{
|
|
4303
|
+
"id": "links",
|
|
4304
|
+
"title": "Links and one main action",
|
|
4305
|
+
"useWhen": "A product site has a few pages and one main action, such as 'Sign Up'.",
|
|
4306
|
+
"source": "'use client';\nimport SiteHeader from 'oneslash-design-system/components/siteHeader';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport Button from 'oneslash-design-system/components/button';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\nconst links = [\n { label: 'Features', href: '#features' },\n { label: 'Pricing', href: '#pricing', current: true },\n { label: 'Changelog', href: '#changelog' },\n { label: 'Docs', href: '#docs' },\n];\n\nexport default function SiteHeaderLinks() {\n return (\n <>\n {/* From md the links are a row in the bar. Below md they and 'Log In' are in the Menu; Sign Up stays beside it. */}\n <SiteHeader\n brand={{ href: '#top', name: 'Acme' }}\n links={links}\n actions={<Button size=\"medium\" type=\"tertiary\" state=\"enabled\" label=\"Log In\" href=\"#log-in\" />}\n phoneAction={<Button size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Sign Up\" href=\"#sign-up\" />}\n mainId=\"site-header-main\"\n />\n {/* The skip link goes here: the id matches mainId, and tabIndex -1 lets focus move in. */}\n <PageShell id=\"site-header-main\" tabIndex={-1}>\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Pricing</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">Acme is free for up to three people. Add more people when your team grows.</Paragraph>\n </Stack>\n </PageShell>\n </>\n );\n}\n",
|
|
4307
|
+
"uses": [
|
|
4308
|
+
"Button",
|
|
4309
|
+
"Heading",
|
|
4310
|
+
"PageShell",
|
|
4311
|
+
"Paragraph",
|
|
4312
|
+
"SiteHeader",
|
|
4313
|
+
"Stack"
|
|
4314
|
+
]
|
|
4315
|
+
},
|
|
4316
|
+
{
|
|
4317
|
+
"id": "sections",
|
|
4318
|
+
"title": "Sections with their own tabs",
|
|
4319
|
+
"useWhen": "A docs site has sections that each hold many pages.",
|
|
4320
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport SiteHeader from 'oneslash-design-system/components/siteHeader';\nimport TabsContainer from 'oneslash-design-system/components/tabsContainer';\nimport Tab from 'oneslash-design-system/components/tab';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport { Stack } from 'oneslash-design-system/components/layout';\n\ntype Mode = 'light' | 'dark' | 'system';\n\n// Four sections, one short word each. Each holds many pages.\nconst sections = [\n { id: 'start', label: 'Start', page: 'Start here' },\n { id: 'guides', label: 'Guides', page: 'Guides' },\n { id: 'reference', label: 'API', page: 'API reference' },\n { id: 'updates', label: 'News', page: 'News' },\n];\n\nconst modes: { value: Mode; label: string; icon: 'Sun' | 'Moon' | 'Monitor' }[] = [\n { value: 'light', label: 'Light', icon: 'Sun' },\n { value: 'dark', label: 'Dark', icon: 'Moon' },\n { value: 'system', label: 'System', icon: 'Monitor' },\n];\n\nexport default function SiteHeaderSections() {\n const [sectionId, setSectionId] = useState('guides');\n const [mode, setMode] = useState<Mode>('system');\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const section = sections.find((s) => s.id === sectionId) ?? sections[0];\n const current = modes.find((m) => m.value === mode) ?? modes[2];\n // A real app passes the router from its framework, such as Next's useRouter(). Here it sets the open section.\n const router = { push: (url: string) => setSectionId(url.split('/').pop() ?? 'start') };\n\n return (\n <>\n {/* The brand, then search and the theme menu as `phoneAction`, so they stay in the bar at every width. The section Tabs are `nav`, a second row of the bar. */}\n <SiteHeader\n brand={{ href: '#top', name: 'Acme Docs' }}\n links={[]}\n phoneAction={\n <>\n <Tooltip title=\"Search\">\n <IconButton color=\"iconOnly\" state=\"enabled\" size=\"medium\" iconName=\"Search\" ariaLabel=\"Search\" />\n </Tooltip>\n <Tooltip title={`Theme: ${current.label}`}>\n <IconButton\n color=\"iconOnly\"\n state={open ? 'selected' : 'enabled'}\n size=\"medium\"\n iconName={current.icon}\n ariaLabel={`Theme: ${current.label}`}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n onClick={(e: { currentTarget: HTMLElement }) => {\n setAnchor(e.currentTarget);\n setOpen((o) => !o);\n }}\n />\n </Tooltip>\n </>\n }\n nav={\n <TabsContainer fill>\n {sections.map((s) => (\n <Tab key={s.id} label={s.label} href={`/${s.id}`} router={router} isSelected={s.id === section.id} onClickTab={() => setSectionId(s.id)} />\n ))}\n </TabsContainer>\n }\n mainId=\"site-header-sections-main\"\n />\n <PageShell id=\"site-header-sections-main\" tabIndex={-1}>\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">{section.page}</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">The pages in {section.label} are listed beside this page on a wide screen, and in the menu on a phone.</Paragraph>\n </Stack>\n </PageShell>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Theme\" width={180}>\n {modes.map((m) => (\n <MenuItem\n key={m.value}\n size=\"small\"\n iconName={m.icon}\n label={m.label}\n isSelected={m.value === mode}\n role=\"menuitemradio\"\n onClick={() => { setMode(m.value); setOpen(false); }}\n />\n ))}\n </Menu>\n </Popover>\n </>\n );\n}\n",
|
|
4321
|
+
"uses": [
|
|
4322
|
+
"Heading",
|
|
4323
|
+
"IconButton",
|
|
4324
|
+
"Menu",
|
|
4325
|
+
"MenuItem",
|
|
4326
|
+
"PageShell",
|
|
4327
|
+
"Paragraph",
|
|
4328
|
+
"Popover",
|
|
4329
|
+
"SiteHeader",
|
|
4330
|
+
"Stack",
|
|
4331
|
+
"Tab",
|
|
4332
|
+
"TabsContainer",
|
|
4333
|
+
"Tooltip"
|
|
4334
|
+
]
|
|
4335
|
+
}
|
|
4336
|
+
]
|
|
4337
|
+
},
|
|
3012
4338
|
{
|
|
3013
4339
|
"id": "slash-command-list",
|
|
3014
4340
|
"title": "Command list",
|
|
@@ -3038,10 +4364,6 @@
|
|
|
3038
4364
|
"Do not open the list for a / in the middle of the text."
|
|
3039
4365
|
],
|
|
3040
4366
|
"native": "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.",
|
|
3041
|
-
"notBuiltYet": "Scindo on the web builds its list from buttons, so a screen reader in the field does not hear which command is highlighted. Both Scindo apps run a command with no argument as soon as it is picked.",
|
|
3042
|
-
"seenIn": [
|
|
3043
|
-
"Scindo"
|
|
3044
|
-
],
|
|
3045
4367
|
"options": [
|
|
3046
4368
|
{
|
|
3047
4369
|
"id": "in-composer",
|
|
@@ -3086,11 +4408,129 @@
|
|
|
3086
4408
|
"Do not build a toast from `Alert`. Use `toast()`.",
|
|
3087
4409
|
"Do not make the person close a success message."
|
|
3088
4410
|
],
|
|
3089
|
-
"native": "On Apple there is no toast. Show the result in place."
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
4411
|
+
"native": "On Apple there is no toast. Show the result in place."
|
|
4412
|
+
},
|
|
4413
|
+
{
|
|
4414
|
+
"id": "tag-filter",
|
|
4415
|
+
"title": "Tag filter",
|
|
4416
|
+
"kind": "design",
|
|
4417
|
+
"level": "organism",
|
|
4418
|
+
"area": "menu",
|
|
4419
|
+
"situation": "A person filters a list by a tag, and adds, renames and deletes the tags themselves.",
|
|
4420
|
+
"do": [
|
|
4421
|
+
"Use a row of `Tag` with `variant=\"contained\"` and `size=\"medium\"` in a `Cluster`. Put 'All' first, then each tag. The row wraps.",
|
|
4422
|
+
"Mark the chosen one with `state=\"selected\"`. A clickable `Tag` is a toggle and reports `aria-pressed`.",
|
|
4423
|
+
"Choose Tags over a `SegmentedControl`. A `SegmentedControl` is for a fixed set of two to four, as in the case 'Range switch'. It cannot grow, wrap or hold a field.",
|
|
4424
|
+
"Show one More `IconButton` after the selected tag: `ariaLabel=\"More actions for tag Design\"`. The row gets one extra stop, not one for each tag.",
|
|
4425
|
+
"Open a navigable menu from it: `<Popover returnFocus>` around `<Menu navigable aria-label=\"Tag actions\">` with 'Rename', then a danger 'Delete'.",
|
|
4426
|
+
"Rename in place, as the case 'Rename' says. The row becomes a field with `aria-label=\"Rename tag Design\"`. Enter and a click away save, and Escape cancels.",
|
|
4427
|
+
"Add a tag with an 'Add Tag' Button that turns the row into the same field, with `aria-label=\"New tag name\"`. The new tag is chosen once it is added.",
|
|
4428
|
+
"Show a name that is taken under the field with `error` and `errorText`, and keep what the person typed.",
|
|
4429
|
+
"Confirm Delete in a small Modal, as the case 'Delete confirm' says: 'Cancel' first, then a danger 'Delete'.",
|
|
4430
|
+
"Say where the items go: 'Its 3 items stay in All, with no tag.' Name the tag in a toast when it is gone.",
|
|
4431
|
+
"Put focus on the More button after Rename or Cancel, and on 'Add Tag' after a delete, since the tag and its More button are gone."
|
|
4432
|
+
],
|
|
4433
|
+
"dont": [
|
|
4434
|
+
"Do not use a `SegmentedControl` for tags that people add and delete.",
|
|
4435
|
+
"Do not delete the items with their tag.",
|
|
4436
|
+
"Do not say 'Are you sure?' in the confirm. Say what is deleted and where the items go.",
|
|
4437
|
+
"Do not add a 'Delete' that has no confirm. A tag may be on many items.",
|
|
4438
|
+
"Do not leave the row on a tag that was just deleted. It goes back to All."
|
|
4439
|
+
],
|
|
4440
|
+
"native": "On Apple use a horizontal `ScrollView` of toggle `Button`s, with a `.contextMenu` on each tag: Rename, then Delete in the `.destructive` role, which asks in a `confirmationDialog`. On Android use `FilterChip`s in a `LazyRow`.",
|
|
4441
|
+
"options": [
|
|
4442
|
+
{
|
|
4443
|
+
"id": "tags",
|
|
4444
|
+
"title": "Row of toggle Tags",
|
|
4445
|
+
"useWhen": "The tags are made by the person, so the set is not fixed or short.",
|
|
4446
|
+
"source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport TextField from 'oneslash-design-system/components/textField';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\n// A real app reads these from the server. 'All' is not a tag: it shows every item.\ntype Item = { id: string; title: string; tagId: string | null };\nconst firstTags = [\n { id: 'design', name: 'Design' },\n { id: 'research', name: 'Research' },\n { id: 'ideas', name: 'Ideas' },\n];\nconst firstItems: Item[] = [\n { id: 'i1', title: 'Pricing page teardown', tagId: 'research' },\n { id: 'i2', title: 'Color tokens for dark mode', tagId: 'design' },\n { id: 'i3', title: 'Onboarding checklist patterns', tagId: 'design' },\n { id: 'i4', title: 'Interview notes, March', tagId: 'research' },\n { id: 'i5', title: 'A weekly digest email', tagId: 'ideas' },\n { id: 'i6', title: 'Keyboard shortcut cheat sheet', tagId: null },\n];\n\n// What the field is for: a new tag, or the selected tag's new name.\ntype Editing = 'add' | 'rename' | null;\n\nexport default function TagFilterTags() {\n const [tags, setTags] = useState(firstTags);\n const [items, setItems] = useState(firstItems);\n // null is 'All'.\n const [selected, setSelected] = useState<string | null>('design');\n const [editing, setEditing] = useState<Editing>(null);\n const [draft, setDraft] = useState('');\n const [taken, setTaken] = useState(false);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n const [confirming, setConfirming] = useState(false);\n const [deleting, setDeleting] = useState(false);\n // The tag the confirm is about, kept until the Modal is closed, so its text stays while it fades out.\n const [doomed, setDoomed] = useState<{ name: string; count: number }>({ name: '', count: 0 });\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const moreButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n const addButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);\n // Enter and Escape end the edit before the field goes away, so its blur must not save again.\n const ended = useRef(false);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n const tag = tags.find((t) => t.id === selected);\n const shown = selected === null ? items : items.filter((i) => i.tagId === selected);\n const nameOf = (tagId: string | null) => tags.find((t) => t.id === tagId)?.name ?? 'No tag';\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n function startEditing(kind: 'add' | 'rename') {\n ended.current = false;\n setDraft(kind === 'rename' && tag ? tag.name : '');\n setTaken(false);\n setEditing(kind);\n }\n\n // Enter and a click away save. An empty or unchanged name cancels. A name that is taken stays in the field with\n // the error, so what the person typed is not lost. `byKey` is true for Enter, where focus goes back to where it was.\n function finish(byKey: boolean) {\n if (ended.current || !editing) return;\n const name = draft.trim();\n const unchanged = editing === 'rename' && name === tag?.name;\n if (!name || unchanged) return cancel(byKey);\n if (tags.some((t) => !(editing === 'rename' && t.id === selected) && t.name.toLowerCase() === name.toLowerCase())) {\n setTaken(true);\n return;\n }\n ended.current = true;\n // A real app sends the name to the server here and shows it at once.\n if (editing === 'rename') {\n setTags((list) => list.map((t) => (t.id === selected ? { ...t, name } : t)));\n } else {\n const id = `tag-${name.toLowerCase().replace(/\\s+/g, '-')}`;\n setTags((list) => [...list, { id, name }]);\n setSelected(id);\n }\n leave(byKey);\n }\n\n function cancel(byKey: boolean) {\n if (ended.current) return;\n ended.current = true;\n leave(byKey);\n }\n\n function leave(byKey: boolean) {\n const kind = editing;\n setEditing(null);\n setTaken(false);\n if (byKey) focusNext.current = () => (kind === 'rename' ? moreButton.current : addButton.current)?.focus();\n }\n\n function openMenu(anchorEl: HTMLElement) {\n setMenuAnchor(anchorEl);\n setMenuOpen((o) => !o);\n }\n\n // The menu closes on any choice. Its Popover gives focus back to the More button.\n function rename() {\n setMenuOpen(false);\n startEditing('rename');\n }\n\n function askToDelete() {\n setMenuOpen(false);\n if (tag) setDoomed({ name: tag.name, count: items.filter((i) => i.tagId === tag.id).length });\n setConfirming(true);\n }\n\n // 'Cancel' ends the confirm; the More button is still there, so focus goes back to it.\n function keepTag() {\n if (deleting) return;\n setConfirming(false);\n focusNext.current = () => moreButton.current?.focus();\n }\n\n // 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'.\n function confirmDelete() {\n if (deleting || !tag) return;\n const gone = tag;\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n setConfirming(false);\n setTags((list) => list.filter((t) => t.id !== gone.id));\n setItems((list) => list.map((i) => (i.tagId === gone.id ? { ...i, tagId: null } : i)));\n setSelected(null);\n toastIds.current.push(toast({ type: 'success', message: `${gone.name} tag deleted.` }));\n focusNext.current = () => addButton.current?.focus();\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Reading list</Heading>\n {editing ? (\n // 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.\n <TextField\n key={editing}\n id=\"tag-filter-name\"\n size=\"small\"\n autoFocus\n aria-label={editing === 'rename' ? `Rename tag ${tag?.name}` : 'New tag name'}\n placeholder={editing === 'add' ? 'Tag name' : undefined}\n value={draft}\n error={taken}\n errorText=\"A tag with this name already exists.\"\n onChange={(e) => {\n setDraft(e.target.value);\n setTaken(false);\n }}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n e.preventDefault();\n finish(true);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n cancel(true);\n }\n }}\n onBlur={() => finish(false)}\n />\n ) : (\n // Tags that people add, rename and delete are not a fixed short set, so they are toggle Tags in a row that wraps.\n <Cluster gap=\"small\">\n <Tag variant=\"contained\" size=\"medium\" label=\"All\" state={selected === null ? 'selected' : 'enabled'} onClick={() => setSelected(null)} />\n {tags.map((t) => (\n <Tag key={t.id} variant=\"contained\" size=\"medium\" label={t.name} state={t.id === selected ? 'selected' : 'enabled'} onClick={() => setSelected(t.id)} />\n ))}\n {/* One More button, for the tag that is selected, so the row has one extra stop and not one per tag. */}\n {tag && (\n <Tooltip title=\"More\">\n <IconButton\n ref={moreButton}\n color=\"iconOnly\"\n state={menuOpen ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for tag ${tag.name}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen}\n onClick={(e: { currentTarget: HTMLElement }) => openMenu(e.currentTarget)}\n />\n </Tooltip>\n )}\n <Button ref={addButton} size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Add Tag\" decoIcon=\"Plus\" onClickButton={() => startEditing('add')} />\n </Cluster>\n )}\n {shown.length > 0 ? (\n <TableContainer>\n {shown.map((i) => (\n <TableRow key={i.id}>\n <TableCell>{i.title}</TableCell>\n <TableCell width=\"120px\">{nameOf(i.tagId)}</TableCell>\n </TableRow>\n ))}\n </TableContainer>\n ) : (\n <EmptyBox size=\"small\" icon=\"Tag\" text={`No items tagged '${tag?.name}'`} secondText=\"Items you tag appear here.\" />\n )}\n </Stack>\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={() => setMenuOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Tag actions\" width={180}>\n <MenuItem size=\"small\" iconName=\"Pencil\" label=\"Rename\" onClick={rename} />\n {/* Delete is last, and danger. */}\n <MenuItem size=\"small\" color=\"danger\" iconName=\"Trash2\" label=\"Delete\" onClick={askToDelete} />\n </Menu>\n </Popover>\n <Modal\n isOpen={confirming}\n size=\"small\"\n title=\"Delete Tag\"\n onClose={keepTag}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={keepTag} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" loading={deleting} onClickButton={confirmDelete} />\n </>\n }\n >\n <Paragraph measure=\"none\">{`This deletes the tag '${doomed.name}'.`}</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">\n {doomed.count === 1 ? 'Its 1 item stays in All, with no tag.' : `Its ${doomed.count} items stay in All, with no tag.`}\n </Paragraph>\n </Modal>\n </Center>\n );\n}\n",
|
|
4447
|
+
"uses": [
|
|
4448
|
+
"Button",
|
|
4449
|
+
"Center",
|
|
4450
|
+
"Cluster",
|
|
4451
|
+
"EmptyBox",
|
|
4452
|
+
"Heading",
|
|
4453
|
+
"IconButton",
|
|
4454
|
+
"Menu",
|
|
4455
|
+
"MenuItem",
|
|
4456
|
+
"Modal",
|
|
4457
|
+
"Paragraph",
|
|
4458
|
+
"Popover",
|
|
4459
|
+
"Stack",
|
|
4460
|
+
"TableCell",
|
|
4461
|
+
"TableContainer",
|
|
4462
|
+
"TableRow",
|
|
4463
|
+
"Tag",
|
|
4464
|
+
"TextField",
|
|
4465
|
+
"Toaster",
|
|
4466
|
+
"Tooltip",
|
|
4467
|
+
"dismissToast",
|
|
4468
|
+
"toast"
|
|
4469
|
+
]
|
|
4470
|
+
}
|
|
4471
|
+
]
|
|
4472
|
+
},
|
|
4473
|
+
{
|
|
4474
|
+
"id": "theme-switcher",
|
|
4475
|
+
"title": "Theme switcher",
|
|
4476
|
+
"kind": "design",
|
|
4477
|
+
"level": "organism",
|
|
4478
|
+
"area": "shell",
|
|
4479
|
+
"situation": "A person chooses between a light page, a dark page, or the one their device uses.",
|
|
4480
|
+
"do": [
|
|
4481
|
+
"Offer three choices, in this order: 'Light', 'Dark' and 'System'. 'System' follows the device and is the default.",
|
|
4482
|
+
"Name the menu's `IconButton` for the current choice, in sentence case: 'Theme: Dark'. Show the icon of the current choice: a sun, a moon or a monitor.",
|
|
4483
|
+
"Open a navigable menu: `<Popover returnFocus>` around `<Menu navigable aria-label=\"Theme\">`. Set `aria-haspopup=\"menu\"` and `aria-expanded` on the button, and `state=\"selected\"` while the menu is open.",
|
|
4484
|
+
"Give each item `role=\"menuitemradio\"` and `isSelected` on the current one, and close the menu on a choice.",
|
|
4485
|
+
"Use a `SegmentedControl` named 'Theme' with `width=\"fit\"` in a `SettingsSection` on a settings page. It saves in place and shows nothing, as the rule 'A setting saves in place, or with one Save Button' says.",
|
|
4486
|
+
"Change the page as soon as a choice is made. A choice kept on the device cannot fail, so show no message and no toast.",
|
|
4487
|
+
"Keep the choice on the device, such as in a cookie or local storage, and read it before the page paints, so the page never flashes the wrong theme.",
|
|
4488
|
+
"For 'System', set no class and follow `prefers-color-scheme`, and change the page when the device changes.",
|
|
4489
|
+
"Set the choice's class on `<html>`. The example keeps the choice in state, because it must not touch the document."
|
|
4490
|
+
],
|
|
4491
|
+
"dont": [
|
|
4492
|
+
"Do not add a brand theme as a fourth choice. A brand theme is another setting.",
|
|
4493
|
+
"Do not name the button for the action, such as 'Dark mode'. Name it for what is on.",
|
|
4494
|
+
"Do not use a toggle that only flips between light and dark. It hides System.",
|
|
4495
|
+
"Do not mark the current choice with color only.",
|
|
4496
|
+
"Do not show both the menu and the segmented control on the same page.",
|
|
4497
|
+
"Do not save the theme to the person's account with this case. A save that can fail follows the rule 'A setting saves in place, or with one Save Button'."
|
|
4498
|
+
],
|
|
4499
|
+
"native": "On Apple and Android follow the system appearance and offer no switcher. If the app has one, use a `Picker` of Light, Dark and System in settings.",
|
|
4500
|
+
"options": [
|
|
4501
|
+
{
|
|
4502
|
+
"id": "menu",
|
|
4503
|
+
"title": "Menu in the header",
|
|
4504
|
+
"useWhen": "The site has no settings page, or the person should reach the theme from every page.",
|
|
4505
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Link from 'oneslash-design-system/components/link';\nimport { Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Mode = 'light' | 'dark' | 'system';\n\nconst modes: { value: Mode; label: string; icon: 'Sun' | 'Moon' | 'Monitor' }[] = [\n { value: 'light', label: 'Light', icon: 'Sun' },\n { value: 'dark', label: 'Dark', icon: 'Moon' },\n { value: 'system', label: 'System', icon: 'Monitor' },\n];\n\nexport default function ThemeSwitcherMenu() {\n // The example keeps the choice in state. A real app keeps it for the person and sets the `dark` class on <html>.\n const [mode, setMode] = useState<Mode>('system');\n const [anchor, setAnchor] = useState<HTMLElement | null>(null);\n const [open, setOpen] = useState(false);\n const current = modes.find((m) => m.value === mode) ?? modes[2];\n\n return (\n <PageShell>\n <Stack gap=\"large\">\n <Cluster justify=\"between\">\n <Link href=\"#top\" size=\"subtitle1\">Acme</Link>\n <Tooltip title={`Theme: ${current.label}`}>\n <IconButton\n color=\"iconOnly\"\n state={open ? 'selected' : 'enabled'}\n size=\"medium\"\n iconName={current.icon}\n ariaLabel={`Theme: ${current.label}`}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n onClick={(e: { currentTarget: HTMLElement }) => {\n setAnchor(e.currentTarget);\n setOpen((o) => !o);\n }}\n />\n </Tooltip>\n </Cluster>\n <Heading level={1} size=\"h5\">Welcome back, Dana</Heading>\n <Paragraph tone=\"secondary\" measure=\"none\">\n {mode === 'system' ? 'Acme follows your device.' : `Acme is set to ${mode}.`} In a real app the page changes now.\n </Paragraph>\n </Stack>\n <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>\n <Menu navigable aria-label=\"Theme\" width={180}>\n {modes.map((m) => (\n <MenuItem\n key={m.value}\n size=\"small\"\n iconName={m.icon}\n label={m.label}\n isSelected={m.value === mode}\n role=\"menuitemradio\"\n onClick={() => { setMode(m.value); setOpen(false); }}\n />\n ))}\n </Menu>\n </Popover>\n </PageShell>\n );\n}\n",
|
|
4506
|
+
"uses": [
|
|
4507
|
+
"Cluster",
|
|
4508
|
+
"Heading",
|
|
4509
|
+
"IconButton",
|
|
4510
|
+
"Link",
|
|
4511
|
+
"Menu",
|
|
4512
|
+
"MenuItem",
|
|
4513
|
+
"PageShell",
|
|
4514
|
+
"Paragraph",
|
|
4515
|
+
"Popover",
|
|
4516
|
+
"Stack",
|
|
4517
|
+
"Tooltip"
|
|
4518
|
+
]
|
|
4519
|
+
},
|
|
4520
|
+
{
|
|
4521
|
+
"id": "segmented",
|
|
4522
|
+
"title": "Segmented control on a settings page",
|
|
4523
|
+
"useWhen": "The choice is a setting among others, on a settings page.",
|
|
4524
|
+
"source": "'use client';\nimport { useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport SegmentedControl from 'oneslash-design-system/components/segmentedControl';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\nconst options = [\n { value: 'light', label: 'Light' },\n { value: 'dark', label: 'Dark' },\n { value: 'system', label: 'System' },\n];\n\nexport default function ThemeSwitcherSegmented() {\n // The example keeps the choice in state. A real app keeps it for the person and sets the `dark` class on <html>.\n const [mode, setMode] = useState('system');\n\n return (\n <Center width=\"page\">\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Settings</Heading>\n <SettingsSection title=\"Appearance\" description=\"System follows your device.\">\n {/* Kept on the device, so it saves in place and shows nothing: the page changes at once. */}\n <Cluster>\n <SegmentedControl size=\"small\" width=\"fit\" aria-label=\"Theme\" options={options} value={mode} onChange={setMode} />\n </Cluster>\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
|
|
4525
|
+
"uses": [
|
|
4526
|
+
"Center",
|
|
4527
|
+
"Cluster",
|
|
4528
|
+
"Heading",
|
|
4529
|
+
"SegmentedControl",
|
|
4530
|
+
"SettingsSection",
|
|
4531
|
+
"Stack"
|
|
4532
|
+
]
|
|
4533
|
+
}
|
|
3094
4534
|
]
|
|
3095
4535
|
},
|
|
3096
4536
|
{
|
|
@@ -3115,11 +4555,6 @@
|
|
|
3115
4555
|
"Do not show a failed request as a red caption written by hand. Use an inline error Alert."
|
|
3116
4556
|
],
|
|
3117
4557
|
"native": "On Apple use an `.alert` with a `TextField` in it. Put the action in the `.destructive` role and disable it until the text matches.",
|
|
3118
|
-
"notBuiltYet": "Commentify matches its phrase with any case and ignores spaces around it, and labels its Button 'Deleting…' while it runs. Scindo labels its Button 'Deleting...' on the web and on Apple. On the web its Delete Workspace Modal shows a failed request as a red caption written by hand.",
|
|
3119
|
-
"seenIn": [
|
|
3120
|
-
"Commentify",
|
|
3121
|
-
"Scindo"
|
|
3122
|
-
],
|
|
3123
4558
|
"options": [
|
|
3124
4559
|
{
|
|
3125
4560
|
"id": "modal",
|
|
@@ -3182,10 +4617,6 @@
|
|
|
3182
4617
|
"Do not say an agent is typing.",
|
|
3183
4618
|
"Do not list every name when three or more people type."
|
|
3184
4619
|
],
|
|
3185
|
-
"notBuiltYet": "Scindo on the web names people by their full name and ends the line with three dots.",
|
|
3186
|
-
"seenIn": [
|
|
3187
|
-
"Scindo"
|
|
3188
|
-
],
|
|
3189
4620
|
"options": [
|
|
3190
4621
|
{
|
|
3191
4622
|
"id": "line",
|
|
@@ -3227,10 +4658,6 @@
|
|
|
3227
4658
|
"Do not title the Modal 'Are you sure?'."
|
|
3228
4659
|
],
|
|
3229
4660
|
"native": "On macOS a document window that closes with changes asks with the system alert: 'Save', 'Don't Save' and 'Cancel'. When the product cannot save, use a `confirmationDialog` with 'Discard' in the `.destructive` role and 'Keep Editing' in the `.cancel` role.",
|
|
3230
|
-
"notBuiltYet": "Scindo on the web guards no unsaved changes. It drops the changes to a document when the person chooses Cancel, with no question.",
|
|
3231
|
-
"seenIn": [
|
|
3232
|
-
"Scindo"
|
|
3233
|
-
],
|
|
3234
4661
|
"options": [
|
|
3235
4662
|
{
|
|
3236
4663
|
"id": "save-or-discard",
|
|
@@ -3292,11 +4719,6 @@
|
|
|
3292
4719
|
"Do not build the overlay by hand. Use `Modal`, which closes on Escape."
|
|
3293
4720
|
],
|
|
3294
4721
|
"native": "On Apple show the notice in place, with an Upgrade Button only for admins. It opens the plan sheet in the app, never a link to a web page.",
|
|
3295
|
-
"notBuiltYet": "Scindo's upgrade prompt on the web is an overlay built by hand that does not close on Escape, is titled 'Upgrade Required' and shows Upgrade to everyone. Commentify's upgrade Modal labels its Buttons 'Maybe Later' and 'Upgrade'.",
|
|
3296
|
-
"seenIn": [
|
|
3297
|
-
"Commentify",
|
|
3298
|
-
"Scindo"
|
|
3299
|
-
],
|
|
3300
4722
|
"options": [
|
|
3301
4723
|
{
|
|
3302
4724
|
"id": "modal",
|