oneslash-design-system 2.17.0 → 2.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/DESIGN.md +55 -14
- package/dist/cases/accept-invite.md +1 -5
- package/dist/cases/account-menu/menu.d.ts +1 -0
- package/dist/cases/account-menu/menu.jsx +99 -0
- package/dist/cases/account-menu.md +164 -0
- package/dist/cases/agent-asks-before-risky-action.md +0 -4
- package/dist/cases/agent-cancels-when-unanswered.md +0 -4
- package/dist/cases/agent-options.md +0 -4
- package/dist/cases/agent-pending-reply.md +0 -4
- package/dist/cases/agent-plan-proposal.md +0 -4
- package/dist/cases/agent-question.md +0 -4
- package/dist/cases/agent-refuses-clearly.md +0 -4
- package/dist/cases/agent-says-what-it-is.md +0 -2
- package/dist/cases/agent-settings/form.d.ts +1 -0
- package/dist/cases/agent-settings/form.jsx +164 -0
- package/dist/cases/agent-settings.md +259 -0
- package/dist/cases/agent-shows-progress.md +0 -2
- package/dist/cases/agent-shows-sources.md +0 -2
- package/dist/cases/api-keys/list.d.ts +1 -0
- package/dist/cases/api-keys/list.jsx +162 -0
- package/dist/cases/api-keys.md +229 -0
- package/dist/cases/app-shell/sidebar.d.ts +1 -0
- package/dist/cases/app-shell/sidebar.jsx +124 -0
- package/dist/cases/app-shell/top-tabs.d.ts +1 -0
- package/dist/cases/app-shell/top-tabs.jsx +106 -0
- package/dist/cases/app-shell.md +364 -0
- package/dist/cases/artifact-card/card.jsx +32 -6
- package/dist/cases/artifact-card.md +55 -11
- package/dist/cases/auth-gate-loading.md +0 -4
- package/dist/cases/check-your-email.md +0 -4
- package/dist/cases/collapsible-search/popover.d.ts +1 -0
- package/dist/cases/collapsible-search/popover.jsx +74 -0
- package/dist/cases/collapsible-search.md +143 -0
- package/dist/cases/composer-limit.md +0 -4
- package/dist/cases/confirm-destructive-action.md +0 -4
- package/dist/cases/confirm-dialogs.md +0 -4
- package/dist/cases/conversation-starters.md +0 -4
- package/dist/cases/create-modal.md +0 -4
- package/dist/cases/danger-zone/collapsed.d.ts +1 -0
- package/dist/cases/danger-zone/collapsed.jsx +75 -0
- package/dist/cases/danger-zone/shown.d.ts +1 -0
- package/dist/cases/danger-zone/shown.jsx +95 -0
- package/dist/cases/danger-zone.md +263 -0
- package/dist/cases/device-login.md +0 -4
- package/dist/cases/email-confirmed.md +0 -4
- package/dist/cases/empty-list.md +0 -4
- package/dist/cases/empty-lists.md +0 -4
- package/dist/cases/empty-not-set-up.md +0 -4
- package/dist/cases/empty-search.md +0 -4
- package/dist/cases/error-page/in-shell.jsx +26 -17
- package/dist/cases/error-page.md +42 -25
- package/dist/cases/feedback-form.md +0 -4
- package/dist/cases/filter-menu/presets.d.ts +1 -0
- package/dist/cases/filter-menu/presets.jsx +53 -0
- package/dist/cases/filter-menu/with-clear.d.ts +1 -0
- package/dist/cases/filter-menu/with-clear.jsx +56 -0
- package/dist/cases/filter-menu.md +204 -0
- package/dist/cases/forgot-password.md +0 -4
- package/dist/cases/form-errors.md +0 -4
- package/dist/cases/import-checklist.md +0 -4
- package/dist/cases/inline-form-feedback.md +0 -4
- package/dist/cases/integrations-list/nested.d.ts +1 -0
- package/dist/cases/integrations-list/nested.jsx +164 -0
- package/dist/cases/integrations-list/rows.d.ts +1 -0
- package/dist/cases/integrations-list/rows.jsx +134 -0
- package/dist/cases/integrations-list.md +379 -0
- package/dist/cases/invite-member.md +0 -4
- package/dist/cases/load-failure.md +0 -4
- package/dist/cases/log-out-confirm.md +0 -4
- package/dist/cases/login-page.md +0 -4
- package/dist/cases/master-detail/list-then-page.d.ts +1 -0
- package/dist/cases/master-detail/list-then-page.jsx +65 -0
- package/dist/cases/master-detail/split.d.ts +1 -0
- package/dist/cases/master-detail/split.jsx +49 -0
- package/dist/cases/master-detail.md +213 -0
- package/dist/cases/members-list/rows.d.ts +1 -0
- package/dist/cases/members-list/rows.jsx +318 -0
- package/dist/cases/members-list/table.d.ts +1 -0
- package/dist/cases/members-list/table.jsx +351 -0
- package/dist/cases/members-list.md +799 -0
- package/dist/cases/mention-list.md +0 -4
- package/dist/cases/message-actions.md +0 -4
- package/dist/cases/message-attachments.md +0 -4
- package/dist/cases/message-composer.md +0 -4
- package/dist/cases/message-edit.md +0 -4
- package/dist/cases/message-reactions.md +0 -4
- package/dist/cases/message-row.md +0 -4
- package/dist/cases/mobile-menu/links.d.ts +1 -0
- package/dist/cases/mobile-menu/links.jsx +24 -0
- package/dist/cases/mobile-menu/sections.d.ts +1 -0
- package/dist/cases/mobile-menu/sections.jsx +61 -0
- package/dist/cases/mobile-menu.md +170 -0
- package/dist/cases/not-found-page/in-shell.jsx +26 -17
- package/dist/cases/not-found-page.md +41 -24
- package/dist/cases/notification-menu/menu.d.ts +1 -0
- package/dist/cases/notification-menu/menu.jsx +74 -0
- package/dist/cases/notification-menu.md +135 -0
- package/dist/cases/oauth-consent.md +0 -4
- package/dist/cases/on-off-settings/list.d.ts +1 -0
- package/dist/cases/on-off-settings/list.jsx +97 -0
- package/dist/cases/on-off-settings.md +116 -0
- package/dist/cases/on-this-page/aside.d.ts +1 -0
- package/dist/cases/on-this-page/aside.jsx +39 -0
- package/dist/cases/on-this-page.md +80 -0
- package/dist/cases/overflow-menu/in-a-header.d.ts +1 -0
- package/dist/cases/overflow-menu/in-a-header.jsx +128 -0
- package/dist/cases/overflow-menu/on-a-row.d.ts +1 -0
- package/dist/cases/overflow-menu/on-a-row.jsx +183 -0
- package/dist/cases/overflow-menu.md +410 -0
- package/dist/cases/page-header/actions.d.ts +1 -0
- package/dist/cases/page-header/actions.jsx +65 -0
- package/dist/cases/page-header/sub-page.d.ts +1 -0
- package/dist/cases/page-header/sub-page.jsx +37 -0
- package/dist/cases/page-header.md +195 -0
- package/dist/cases/phone-navigation.md +32 -0
- package/dist/cases/profile-form/form.d.ts +1 -0
- package/dist/cases/profile-form/form.jsx +153 -0
- package/dist/cases/profile-form.md +236 -0
- package/dist/cases/quick-switcher/modal.d.ts +1 -0
- package/dist/cases/quick-switcher/modal.jsx +114 -0
- package/dist/cases/quick-switcher.md +205 -0
- package/dist/cases/range-switch/segmented.d.ts +1 -0
- package/dist/cases/range-switch/segmented.jsx +30 -0
- package/dist/cases/range-switch.md +67 -0
- package/dist/cases/rename.md +0 -4
- package/dist/cases/reply-feedback.md +0 -4
- package/dist/cases/reply-sources.md +0 -4
- package/dist/cases/route-loading/region.jsx +27 -18
- package/dist/cases/route-loading.md +42 -23
- package/dist/cases/scope-picker/menu.d.ts +1 -0
- package/dist/cases/scope-picker/menu.jsx +47 -0
- package/dist/cases/scope-picker.md +97 -0
- package/dist/cases/set-new-password.md +0 -4
- package/dist/cases/settings-page/side-nav.d.ts +1 -0
- package/dist/cases/settings-page/side-nav.jsx +171 -0
- package/dist/cases/settings-page/top-tabs.d.ts +1 -0
- package/dist/cases/settings-page/top-tabs.jsx +129 -0
- package/dist/cases/settings-page.md +378 -0
- package/dist/cases/settings-save.md +35 -0
- package/dist/cases/side-pane/beside.d.ts +1 -0
- package/dist/cases/side-pane/beside.jsx +79 -0
- package/dist/cases/side-pane/over.d.ts +1 -0
- package/dist/cases/side-pane/over.jsx +58 -0
- package/dist/cases/side-pane.md +238 -0
- package/dist/cases/sidebar-nav/flat.d.ts +1 -0
- package/dist/cases/sidebar-nav/flat.jsx +81 -0
- package/dist/cases/sidebar-nav/nested.d.ts +1 -0
- package/dist/cases/sidebar-nav/nested.jsx +122 -0
- package/dist/cases/sidebar-nav.md +261 -0
- package/dist/cases/sign-up-page.md +1 -5
- package/dist/cases/site-footer/columns.d.ts +1 -0
- package/dist/cases/site-footer/columns.jsx +51 -0
- package/dist/cases/site-footer/simple.d.ts +1 -0
- package/dist/cases/site-footer/simple.jsx +24 -0
- package/dist/cases/site-footer.md +133 -0
- package/dist/cases/site-header/links.d.ts +1 -0
- package/dist/cases/site-header/links.jsx +26 -0
- package/dist/cases/site-header/sections.d.ts +1 -0
- package/dist/cases/site-header/sections.jsx +64 -0
- package/dist/cases/site-header.md +183 -0
- package/dist/cases/slash-command-list.md +0 -4
- package/dist/cases/success-feedback.md +0 -4
- package/dist/cases/tag-filter/tags.d.ts +1 -0
- package/dist/cases/tag-filter/tags.jsx +226 -0
- package/dist/cases/tag-filter.md +298 -0
- package/dist/cases/theme-switcher/menu.d.ts +1 -0
- package/dist/cases/theme-switcher/menu.jsx +47 -0
- package/dist/cases/theme-switcher/segmented.d.ts +1 -0
- package/dist/cases/theme-switcher/segmented.jsx +26 -0
- package/dist/cases/theme-switcher.md +149 -0
- package/dist/cases/type-to-confirm.md +0 -4
- package/dist/cases/typing-and-status.md +0 -4
- package/dist/cases/unsaved-changes-guard.md +0 -4
- package/dist/cases/upgrade-prompt.md +0 -4
- package/dist/cases.json +1737 -315
- package/dist/components/alert.d.ts +3 -1
- package/dist/components/alert.jsx +2 -2
- package/dist/components/appShell.d.ts +44 -0
- package/dist/components/appShell.jsx +121 -0
- package/dist/components/button.jsx +5 -2
- package/dist/components/checkBox.d.ts +5 -1
- package/dist/components/checkBox.jsx +2 -2
- package/dist/components/copyField.d.ts +20 -0
- package/dist/components/copyField.jsx +99 -0
- package/dist/components/drawer.d.ts +31 -0
- package/dist/components/drawer.jsx +121 -0
- package/dist/components/formField.d.ts +34 -0
- package/dist/components/formField.jsx +28 -0
- package/dist/components/heading.d.ts +5 -1
- package/dist/components/heading.jsx +2 -2
- package/dist/components/link.d.ts +6 -1
- package/dist/components/link.jsx +11 -3
- package/dist/components/menu.jsx +2 -2
- package/dist/components/menuItem.d.ts +10 -2
- package/dist/components/menuItem.jsx +4 -3
- package/dist/components/modal.jsx +12 -23
- package/dist/components/navigation.d.ts +9 -1
- package/dist/components/navigation.jsx +15 -3
- package/dist/components/onThisPage.d.ts +29 -0
- package/dist/components/onThisPage.jsx +151 -0
- package/dist/components/pageShell.d.ts +7 -1
- package/dist/components/pageShell.jsx +14 -1
- package/dist/components/popover.jsx +4 -0
- package/dist/components/radioGroup.d.ts +5 -1
- package/dist/components/radioGroup.jsx +2 -2
- package/dist/components/segmentedControl.d.ts +22 -0
- package/dist/components/segmentedControl.jsx +54 -0
- package/dist/components/select.d.ts +5 -1
- package/dist/components/select.jsx +2 -2
- package/dist/components/settingsSection.d.ts +36 -0
- package/dist/components/settingsSection.jsx +65 -0
- package/dist/components/sidePane.d.ts +32 -0
- package/dist/components/sidePane.jsx +128 -0
- package/dist/components/siteFooter.d.ts +24 -0
- package/dist/components/siteFooter.jsx +48 -0
- package/dist/components/siteHeader.d.ts +55 -0
- package/dist/components/siteHeader.jsx +125 -0
- package/dist/components/slidingIndicator.d.ts +50 -0
- package/dist/components/slidingIndicator.jsx +102 -0
- package/dist/components/switch.d.ts +25 -0
- package/dist/components/switch.jsx +55 -0
- package/dist/components/tab.jsx +5 -11
- package/dist/components/tabsContainer.jsx +5 -67
- package/dist/components/textField.d.ts +12 -2
- package/dist/components/textField.jsx +11 -4
- package/dist/components/textarea.d.ts +5 -1
- package/dist/components/textarea.jsx +3 -3
- package/dist/components/titleBar.d.ts +17 -0
- package/dist/components/titleBar.jsx +17 -0
- package/dist/components/useHotkey.d.ts +7 -0
- package/dist/components/useHotkey.js +24 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/internal/copyField.d.ts +5 -0
- package/dist/internal/copyField.js +61 -0
- package/dist/internal/hotkey.d.ts +16 -0
- package/dist/internal/hotkey.js +20 -0
- package/dist/internal/overlayStack.d.ts +24 -0
- package/dist/internal/overlayStack.js +71 -0
- package/dist/internal/resize.d.ts +9 -0
- package/dist/internal/resize.js +31 -0
- package/dist/internal/scrollSpy.d.ts +24 -0
- package/dist/internal/scrollSpy.js +53 -0
- package/dist/internal/siteBrand.d.ts +6 -0
- package/dist/internal/siteBrand.jsx +11 -0
- package/dist/internal/switch.d.ts +5 -0
- package/dist/internal/switch.js +9 -0
- package/dist/native-mapping.json +72 -0
- package/dist/stories/AppShell.stories.d.ts +15 -0
- package/dist/stories/AppShell.stories.jsx +137 -0
- package/dist/stories/Cases.generated.stories.d.ts +42 -0
- package/dist/stories/Cases.generated.stories.jsx +84 -0
- package/dist/stories/CopyField.stories.d.ts +11 -0
- package/dist/stories/CopyField.stories.jsx +65 -0
- package/dist/stories/Drawer.stories.d.ts +10 -0
- package/dist/stories/Drawer.stories.jsx +123 -0
- package/dist/stories/FormField.stories.d.ts +6 -0
- package/dist/stories/FormField.stories.jsx +44 -0
- package/dist/stories/Link.stories.d.ts +1 -0
- package/dist/stories/Link.stories.jsx +8 -0
- package/dist/stories/Navigation.stories.d.ts +1 -0
- package/dist/stories/Navigation.stories.jsx +17 -1
- package/dist/stories/OnThisPage.stories.d.ts +10 -0
- package/dist/stories/OnThisPage.stories.jsx +105 -0
- package/dist/stories/SegmentedControl.stories.d.ts +8 -0
- package/dist/stories/SegmentedControl.stories.jsx +33 -0
- package/dist/stories/SettingsSection.stories.d.ts +12 -0
- package/dist/stories/SettingsSection.stories.jsx +91 -0
- package/dist/stories/SidePane.stories.d.ts +6 -0
- package/dist/stories/SidePane.stories.jsx +37 -0
- package/dist/stories/SiteFooter.stories.d.ts +7 -0
- package/dist/stories/SiteFooter.stories.jsx +63 -0
- package/dist/stories/SiteHeader.stories.d.ts +10 -0
- package/dist/stories/SiteHeader.stories.jsx +94 -0
- package/dist/stories/Switch.stories.d.ts +14 -0
- package/dist/stories/Switch.stories.jsx +87 -0
- package/dist/stories/TextField.stories.d.ts +1 -0
- package/dist/stories/TextField.stories.jsx +13 -0
- package/dist/stories/TitleBar.stories.d.ts +6 -0
- package/dist/stories/TitleBar.stories.jsx +34 -0
- package/package.json +5 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import PageShell from '../../components/pageShell';
|
|
4
|
+
import TitleBar from '../../components/titleBar';
|
|
5
|
+
import Heading from '../../components/heading';
|
|
6
|
+
import Button from '../../components/button';
|
|
7
|
+
import Navigation from '../../components/navigation';
|
|
8
|
+
import MenuItem from '../../components/menuItem';
|
|
9
|
+
import Paragraph from '../../components/paragraph';
|
|
10
|
+
import { Stack } from '../../components/layout';
|
|
11
|
+
var taskTitle = 'Move the sign-up form above the pricing table on the home page';
|
|
12
|
+
export default function PageHeaderSubPage() {
|
|
13
|
+
// The task is a page one step down from the project's page.
|
|
14
|
+
var _a = useState('task'), view = _a[0], setView = _a[1];
|
|
15
|
+
var _b = useState(false), done = _b[0], setDone = _b[1];
|
|
16
|
+
if (view === 'project') {
|
|
17
|
+
return (<PageShell>
|
|
18
|
+
<Stack gap="large">
|
|
19
|
+
<Heading level={1} size="h5">Website</Heading>
|
|
20
|
+
<Navigation aria-label="Tasks">
|
|
21
|
+
<MenuItem size="medium" label={taskTitle} secondLabel={done ? 'Done' : 'Open'} iconRight="ChevronRight" href="/website/tasks/sign-up-form" onClick={function (event) {
|
|
22
|
+
// A real app lets the link go to the task's page. The example keeps the choice in state.
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
setView('task');
|
|
25
|
+
}}/>
|
|
26
|
+
</Navigation>
|
|
27
|
+
</Stack>
|
|
28
|
+
</PageShell>);
|
|
29
|
+
}
|
|
30
|
+
return (<PageShell>
|
|
31
|
+
<Stack gap="large">
|
|
32
|
+
{/* Back names the page it goes to. Below md it takes its own line above the title, and a long title wraps. */}
|
|
33
|
+
<TitleBar title={taskTitle} back={<Button size="small" type="tertiary" state="enabled" decoIcon="ChevronLeft" label="Back to Website" onClickButton={function () { return setView('project'); }}/>} actions={<Button size="medium" type="primary" state={done ? 'disabled' : 'enabled'} label="Mark Done" onClickButton={function () { return setDone(true); }}/>}/>
|
|
34
|
+
<Paragraph tone="secondary" size="body2" measure="none">{done ? 'Done. Marked by Dana Lee.' : 'Assigned to Ben Carter. Due on Friday.'}</Paragraph>
|
|
35
|
+
</Stack>
|
|
36
|
+
</PageShell>);
|
|
37
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# Page header with actions
|
|
2
|
+
|
|
3
|
+
A page names itself at the top and offers what the person can do with it.
|
|
4
|
+
|
|
5
|
+
## Do
|
|
6
|
+
|
|
7
|
+
- Follow the rule 'On a phone, a sidebar opens as a drawer and a list opens its detail'.
|
|
8
|
+
- 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.
|
|
9
|
+
- Give the page one primary Button, first in `actions`.
|
|
10
|
+
- Put icon buttons after it, each in a `Tooltip` and named for what they act on: 'Search Home page'.
|
|
11
|
+
- 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'.
|
|
12
|
+
- Pass `phoneActions` with the primary Button and More. Below `md` they replace `actions`.
|
|
13
|
+
- 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`.
|
|
14
|
+
- 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.
|
|
15
|
+
- Let a long title wrap. Never cut it short.
|
|
16
|
+
|
|
17
|
+
## Don't
|
|
18
|
+
|
|
19
|
+
- Do not add a breadcrumb. Back goes one step up, and the title says where the person is.
|
|
20
|
+
- Do not show two primary Buttons.
|
|
21
|
+
- Do not name an icon button only by its icon, or More only by the word.
|
|
22
|
+
- Do not leave an action out on a phone without a way to reach it.
|
|
23
|
+
- Do not name the Back Button 'Back'. Name the page.
|
|
24
|
+
|
|
25
|
+
## Option: The page's own actions
|
|
26
|
+
|
|
27
|
+
Use when: The page is a place of its own, and the person can add to it, search it or change it.
|
|
28
|
+
|
|
29
|
+
Uses: `Button`, `IconButton`, `Line`, `Menu`, `MenuItem`, `PageShell`, `Paragraph`, `Popover`, `Stack`, `TitleBar`, `Tooltip`
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
'use client';
|
|
33
|
+
import { useState } from 'react';
|
|
34
|
+
import PageShell from 'oneslash-design-system/components/pageShell';
|
|
35
|
+
import TitleBar from 'oneslash-design-system/components/titleBar';
|
|
36
|
+
import Button from 'oneslash-design-system/components/button';
|
|
37
|
+
import IconButton from 'oneslash-design-system/components/iconButton';
|
|
38
|
+
import Tooltip from 'oneslash-design-system/components/tooltip';
|
|
39
|
+
import Popover from 'oneslash-design-system/components/popover';
|
|
40
|
+
import Menu from 'oneslash-design-system/components/menu';
|
|
41
|
+
import MenuItem from 'oneslash-design-system/components/menuItem';
|
|
42
|
+
import Line from 'oneslash-design-system/components/line';
|
|
43
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
44
|
+
import { Stack } from 'oneslash-design-system/components/layout';
|
|
45
|
+
|
|
46
|
+
export default function PageHeaderActions() {
|
|
47
|
+
const [anchor, setAnchor] = useState<HTMLElement | null>(null);
|
|
48
|
+
// Which More button opened the menu: on a phone the menu also holds Search and Filter.
|
|
49
|
+
const [from, setFrom] = useState<'wide' | 'phone'>('wide');
|
|
50
|
+
const [open, setOpen] = useState(false);
|
|
51
|
+
const [chosen, setChosen] = useState('');
|
|
52
|
+
|
|
53
|
+
function openMore(kind: 'wide' | 'phone', el: HTMLElement) {
|
|
54
|
+
setFrom(kind);
|
|
55
|
+
setAnchor(el);
|
|
56
|
+
setOpen((o) => !o);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Every item closes the menu. Its Popover gives focus back to the More button.
|
|
60
|
+
function choose(label: string) {
|
|
61
|
+
setOpen(false);
|
|
62
|
+
setChosen(label);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const newTask = <Button size="medium" type="primary" state="enabled" label="New Task" decoIcon="Plus" onClickButton={() => setChosen('New Task')} />;
|
|
66
|
+
|
|
67
|
+
const more = (kind: 'wide' | 'phone') => (
|
|
68
|
+
<Tooltip title="More">
|
|
69
|
+
<IconButton
|
|
70
|
+
color="iconOnly"
|
|
71
|
+
state={open && from === kind ? 'selected' : 'enabled'}
|
|
72
|
+
size="medium"
|
|
73
|
+
iconName="Ellipsis"
|
|
74
|
+
ariaLabel="More actions for Home page"
|
|
75
|
+
aria-haspopup="menu"
|
|
76
|
+
aria-expanded={open && from === kind}
|
|
77
|
+
onClick={(e: { currentTarget: HTMLElement }) => openMore(kind, e.currentTarget)}
|
|
78
|
+
/>
|
|
79
|
+
</Tooltip>
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<PageShell>
|
|
84
|
+
<Stack gap="large">
|
|
85
|
+
{/* 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. */}
|
|
86
|
+
<TitleBar
|
|
87
|
+
title="Home page"
|
|
88
|
+
actions={
|
|
89
|
+
<>
|
|
90
|
+
{newTask}
|
|
91
|
+
<Tooltip title="Search">
|
|
92
|
+
<IconButton color="iconOnly" state="enabled" size="medium" iconName="Search" ariaLabel="Search Home page" onClick={() => setChosen('Search')} />
|
|
93
|
+
</Tooltip>
|
|
94
|
+
<Tooltip title="Filter">
|
|
95
|
+
<IconButton color="iconOnly" state="enabled" size="medium" iconName="Filter" ariaLabel="Filter Home page" onClick={() => setChosen('Filter')} />
|
|
96
|
+
</Tooltip>
|
|
97
|
+
{more('wide')}
|
|
98
|
+
</>
|
|
99
|
+
}
|
|
100
|
+
phoneActions={
|
|
101
|
+
<>
|
|
102
|
+
{newTask}
|
|
103
|
+
{more('phone')}
|
|
104
|
+
</>
|
|
105
|
+
}
|
|
106
|
+
/>
|
|
107
|
+
<Paragraph tone="secondary" size="body2" measure="none">{chosen ? `You chose ${chosen}.` : '12 tasks are open. Updated 2 days ago by Dana Lee.'}</Paragraph>
|
|
108
|
+
</Stack>
|
|
109
|
+
<Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>
|
|
110
|
+
<Menu navigable aria-label="Actions for Home page" width={200}>
|
|
111
|
+
{from === 'phone' && (
|
|
112
|
+
<>
|
|
113
|
+
<MenuItem size="small" iconName="Search" label="Search" onClick={() => choose('Search')} />
|
|
114
|
+
<MenuItem size="small" iconName="Filter" label="Filter" onClick={() => choose('Filter')} />
|
|
115
|
+
<Line />
|
|
116
|
+
</>
|
|
117
|
+
)}
|
|
118
|
+
<MenuItem size="small" iconName="Pencil" label="Rename" onClick={() => choose('Rename')} />
|
|
119
|
+
<MenuItem size="small" iconName="Copy" label="Duplicate" onClick={() => choose('Duplicate')} />
|
|
120
|
+
<MenuItem size="small" iconName="Archive" label="Archive" onClick={() => choose('Archive')} />
|
|
121
|
+
</Menu>
|
|
122
|
+
</Popover>
|
|
123
|
+
</PageShell>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Option: A page one step down, with Back
|
|
129
|
+
|
|
130
|
+
Use when: The page opens from another page, such as a task from its project.
|
|
131
|
+
|
|
132
|
+
Uses: `Button`, `Heading`, `MenuItem`, `Navigation`, `PageShell`, `Paragraph`, `Stack`, `TitleBar`
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
'use client';
|
|
136
|
+
import { useState } from 'react';
|
|
137
|
+
import PageShell from 'oneslash-design-system/components/pageShell';
|
|
138
|
+
import TitleBar from 'oneslash-design-system/components/titleBar';
|
|
139
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
140
|
+
import Button from 'oneslash-design-system/components/button';
|
|
141
|
+
import Navigation from 'oneslash-design-system/components/navigation';
|
|
142
|
+
import MenuItem from 'oneslash-design-system/components/menuItem';
|
|
143
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
144
|
+
import { Stack } from 'oneslash-design-system/components/layout';
|
|
145
|
+
|
|
146
|
+
const taskTitle = 'Move the sign-up form above the pricing table on the home page';
|
|
147
|
+
|
|
148
|
+
export default function PageHeaderSubPage() {
|
|
149
|
+
// The task is a page one step down from the project's page.
|
|
150
|
+
const [view, setView] = useState<'task' | 'project'>('task');
|
|
151
|
+
const [done, setDone] = useState(false);
|
|
152
|
+
|
|
153
|
+
if (view === 'project') {
|
|
154
|
+
return (
|
|
155
|
+
<PageShell>
|
|
156
|
+
<Stack gap="large">
|
|
157
|
+
<Heading level={1} size="h5">Website</Heading>
|
|
158
|
+
<Navigation aria-label="Tasks">
|
|
159
|
+
<MenuItem
|
|
160
|
+
size="medium"
|
|
161
|
+
label={taskTitle}
|
|
162
|
+
secondLabel={done ? 'Done' : 'Open'}
|
|
163
|
+
iconRight="ChevronRight"
|
|
164
|
+
href="/website/tasks/sign-up-form"
|
|
165
|
+
onClick={(event: { preventDefault: () => void }) => {
|
|
166
|
+
// A real app lets the link go to the task's page. The example keeps the choice in state.
|
|
167
|
+
event.preventDefault();
|
|
168
|
+
setView('task');
|
|
169
|
+
}}
|
|
170
|
+
/>
|
|
171
|
+
</Navigation>
|
|
172
|
+
</Stack>
|
|
173
|
+
</PageShell>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<PageShell>
|
|
179
|
+
<Stack gap="large">
|
|
180
|
+
{/* Back names the page it goes to. Below md it takes its own line above the title, and a long title wraps. */}
|
|
181
|
+
<TitleBar
|
|
182
|
+
title={taskTitle}
|
|
183
|
+
back={<Button size="small" type="tertiary" state="enabled" decoIcon="ChevronLeft" label="Back to Website" onClickButton={() => setView('project')} />}
|
|
184
|
+
actions={<Button size="medium" type="primary" state={done ? 'disabled' : 'enabled'} label="Mark Done" onClickButton={() => setDone(true)} />}
|
|
185
|
+
/>
|
|
186
|
+
<Paragraph tone="secondary" size="body2" measure="none">{done ? 'Done. Marked by Dana Lee.' : 'Assigned to Ben Carter. Due on Friday.'}</Paragraph>
|
|
187
|
+
</Stack>
|
|
188
|
+
</PageShell>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Native
|
|
194
|
+
|
|
195
|
+
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.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# On a phone, a sidebar opens as a drawer and a list opens its detail
|
|
2
|
+
|
|
3
|
+
A layout with a sidebar, a list beside its detail, or a side pane meets a phone screen.
|
|
4
|
+
|
|
5
|
+
## Answer
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
## Why
|
|
10
|
+
|
|
11
|
+
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.
|
|
12
|
+
|
|
13
|
+
## Do
|
|
14
|
+
|
|
15
|
+
- 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`.
|
|
16
|
+
- Close the drawer on a choice, Close, Escape, the scrim and when the window widens past `md`.
|
|
17
|
+
- 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.
|
|
18
|
+
- Let a side pane take the whole content area on a phone, with a Close button.
|
|
19
|
+
- Put a site's links in the same kind of menu, and keep at most one main action in the bar.
|
|
20
|
+
- Give every place a way to be reached on a phone, even one that is only a link.
|
|
21
|
+
|
|
22
|
+
## Don't
|
|
23
|
+
|
|
24
|
+
- Do not hide a link on a phone without a menu that holds it.
|
|
25
|
+
- Do not show a sidebar beside the page on a phone, or squeeze a side pane beside the content.
|
|
26
|
+
- 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.
|
|
27
|
+
- Do not add a bottom tab bar on the web.
|
|
28
|
+
- Do not leave a drawer that Escape and a tap outside cannot close.
|
|
29
|
+
|
|
30
|
+
## Native
|
|
31
|
+
|
|
32
|
+
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function ProfileForm(): import("react").JSX.Element;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import Heading from '../../components/heading';
|
|
4
|
+
import Form from '../../components/form';
|
|
5
|
+
import FormField from '../../components/formField';
|
|
6
|
+
import TextField from '../../components/textField';
|
|
7
|
+
import Button from '../../components/button';
|
|
8
|
+
import Alert from '../../components/alert';
|
|
9
|
+
import UserImage from '../../components/userImage';
|
|
10
|
+
import SettingsSection from '../../components/settingsSection';
|
|
11
|
+
import { Center, Cluster, Stack } from '../../components/layout';
|
|
12
|
+
// A picture the person chose. A real app uploads the file and gets a URL back.
|
|
13
|
+
var chosenPicture = "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";
|
|
14
|
+
var minPasswordLength = 8;
|
|
15
|
+
// Stands in for the server's check. In this example every current password is right except this one.
|
|
16
|
+
var wrongCurrentPassword = 'incorrect';
|
|
17
|
+
export default function ProfileForm() {
|
|
18
|
+
var _a = useState(undefined), picture = _a[0], setPicture = _a[1];
|
|
19
|
+
// Which picture Button was pressed, so only that one shows `loading`.
|
|
20
|
+
var _b = useState(null), savingPicture = _b[0], setSavingPicture = _b[1];
|
|
21
|
+
var _c = useState(''), pictureError = _c[0], setPictureError = _c[1];
|
|
22
|
+
var _d = useState('Dana Lee'), savedName = _d[0], setSavedName = _d[1];
|
|
23
|
+
var _e = useState('Dana Lee'), name = _e[0], setName = _e[1];
|
|
24
|
+
var _f = useState(''), nameError = _f[0], setNameError = _f[1];
|
|
25
|
+
var _g = useState(false), savingName = _g[0], setSavingName = _g[1];
|
|
26
|
+
var _h = useState(false), nameSaved = _h[0], setNameSaved = _h[1];
|
|
27
|
+
var _j = useState(''), currentPassword = _j[0], setCurrentPassword = _j[1];
|
|
28
|
+
var _k = useState(''), currentPasswordError = _k[0], setCurrentPasswordError = _k[1];
|
|
29
|
+
var _l = useState(''), password = _l[0], setPassword = _l[1];
|
|
30
|
+
var _m = useState(''), passwordError = _m[0], setPasswordError = _m[1];
|
|
31
|
+
var _o = useState(false), savingPassword = _o[0], setSavingPassword = _o[1];
|
|
32
|
+
var _p = useState(false), passwordSaved = _p[0], setPasswordSaved = _p[1];
|
|
33
|
+
var timers = useRef([]);
|
|
34
|
+
// One 'Saved' timer per group, cleared before a new one starts, so an old one cannot end a new 'Saved' early.
|
|
35
|
+
var nameSavedTimer = useRef();
|
|
36
|
+
var passwordSavedTimer = useRef();
|
|
37
|
+
// The first picture save fails, as if the upload dropped, so the example shows both paths.
|
|
38
|
+
var pictureFails = useRef(true);
|
|
39
|
+
// Stops every request and every 'Saved' if the example goes away before they end.
|
|
40
|
+
useEffect(function () { return function () {
|
|
41
|
+
timers.current.forEach(clearTimeout);
|
|
42
|
+
clearTimeout(nameSavedTimer.current);
|
|
43
|
+
clearTimeout(passwordSavedTimer.current);
|
|
44
|
+
}; }, []);
|
|
45
|
+
// Stands in for the request to the server.
|
|
46
|
+
function later(callback, ms) {
|
|
47
|
+
timers.current.push(setTimeout(callback, ms));
|
|
48
|
+
}
|
|
49
|
+
// The picture is one control on its own, so it saves as soon as it is chosen or removed. Nothing shows when it works.
|
|
50
|
+
// When it fails, the old picture stays and a line under the Buttons says why.
|
|
51
|
+
function savePicture(next, pressed) {
|
|
52
|
+
if (savingPicture)
|
|
53
|
+
return;
|
|
54
|
+
setPictureError('');
|
|
55
|
+
setSavingPicture(pressed);
|
|
56
|
+
later(function () {
|
|
57
|
+
setSavingPicture(null);
|
|
58
|
+
if (pictureFails.current) {
|
|
59
|
+
pictureFails.current = false;
|
|
60
|
+
setPictureError('Could not save. Try again.');
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
setPicture(next);
|
|
64
|
+
}, 900);
|
|
65
|
+
}
|
|
66
|
+
// The name is a group with one Save Button: 'Saved' shows for 2 seconds, and the Button is disabled while nothing changed.
|
|
67
|
+
function handleSaveName() {
|
|
68
|
+
if (savingName)
|
|
69
|
+
return;
|
|
70
|
+
if (!name.trim()) {
|
|
71
|
+
setNameError('Enter your name.');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
setNameError('');
|
|
75
|
+
setSavingName(true);
|
|
76
|
+
later(function () {
|
|
77
|
+
setSavedName(name.trim());
|
|
78
|
+
setName(name.trim());
|
|
79
|
+
setSavingName(false);
|
|
80
|
+
setNameSaved(true);
|
|
81
|
+
clearTimeout(nameSavedTimer.current);
|
|
82
|
+
nameSavedTimer.current = setTimeout(function () { return setNameSaved(false); }, 2000);
|
|
83
|
+
}, 1200);
|
|
84
|
+
}
|
|
85
|
+
function handleUpdatePassword() {
|
|
86
|
+
if (savingPassword || !currentPassword || !password)
|
|
87
|
+
return;
|
|
88
|
+
setCurrentPasswordError('');
|
|
89
|
+
if (password.length < minPasswordLength) {
|
|
90
|
+
setPasswordError("Use at least ".concat(minPasswordLength, " characters."));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
setPasswordError('');
|
|
94
|
+
setSavingPassword(true);
|
|
95
|
+
later(function () {
|
|
96
|
+
setSavingPassword(false);
|
|
97
|
+
// A wrong current password shows under that field, and both fields keep what the person typed.
|
|
98
|
+
if (currentPassword === wrongCurrentPassword) {
|
|
99
|
+
setCurrentPasswordError('This is not your current password. Enter it again.');
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
setCurrentPassword('');
|
|
103
|
+
setPassword('');
|
|
104
|
+
setPasswordSaved(true);
|
|
105
|
+
clearTimeout(passwordSavedTimer.current);
|
|
106
|
+
passwordSavedTimer.current = setTimeout(function () { return setPasswordSaved(false); }, 2000);
|
|
107
|
+
}, 1200);
|
|
108
|
+
}
|
|
109
|
+
var nameChanged = name !== savedName;
|
|
110
|
+
return (<Center width="page">
|
|
111
|
+
<Stack gap="xlarge">
|
|
112
|
+
<Heading level={1} size="h5">Profile</Heading>
|
|
113
|
+
|
|
114
|
+
<SettingsSection title="Picture" description="Shown beside your name in Acme.">
|
|
115
|
+
<Cluster gap="large">
|
|
116
|
+
<UserImage userHandle={savedName} userImgUrl={picture} size={64}/>
|
|
117
|
+
<Stack gap="small">
|
|
118
|
+
<Cluster gap="small">
|
|
119
|
+
<Button size="small" type="secondary" state={savingPicture === 'remove' ? 'disabled' : 'enabled'} label="Change Picture" loading={savingPicture === 'change'} onClickButton={function () { return savePicture(chosenPicture, 'change'); }}/>
|
|
120
|
+
{picture && <Button size="small" type="tertiary" state={savingPicture === 'change' ? 'disabled' : 'enabled'} label="Remove" aria-label="Remove picture" loading={savingPicture === 'remove'} onClickButton={function () { return savePicture(undefined, 'remove'); }}/>}
|
|
121
|
+
</Cluster>
|
|
122
|
+
{pictureError && <Alert type="error" variant="inline" autoDismiss={false} message={pictureError}/>}
|
|
123
|
+
</Stack>
|
|
124
|
+
</Cluster>
|
|
125
|
+
</SettingsSection>
|
|
126
|
+
|
|
127
|
+
<SettingsSection title="Name" description="How people see you in messages and on tasks.">
|
|
128
|
+
<Form aria-label="Name" gap="medium" onSubmit={handleSaveName}>
|
|
129
|
+
<FormField id="profile-form-name" label="Name" error={nameError}>
|
|
130
|
+
{function (f) { return (<TextField id={f.id} aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} value={name} disabled={savingName} autoComplete="name" onChange={function (e) { setName(e.target.value); setNameError(''); setNameSaved(false); }}/>); }}
|
|
131
|
+
</FormField>
|
|
132
|
+
<Cluster>
|
|
133
|
+
<Button size="medium" type="primary" state={nameChanged || savingName ? 'enabled' : 'disabled'} label={nameSaved ? 'Saved' : 'Save'} htmlType="submit" loading={savingName}/>
|
|
134
|
+
</Cluster>
|
|
135
|
+
</Form>
|
|
136
|
+
</SettingsSection>
|
|
137
|
+
|
|
138
|
+
<SettingsSection title="Password" description="Sign in with dana@acme.example and a password.">
|
|
139
|
+
<Form aria-label="Password" gap="medium" onSubmit={handleUpdatePassword}>
|
|
140
|
+
<FormField id="profile-form-current-password" label="Current password" error={currentPasswordError}>
|
|
141
|
+
{function (f) { return (<TextField id={f.id} type="password" aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} value={currentPassword} disabled={savingPassword} autoComplete="current-password" onChange={function (e) { setCurrentPassword(e.target.value); setCurrentPasswordError(''); setPasswordSaved(false); }}/>); }}
|
|
142
|
+
</FormField>
|
|
143
|
+
<FormField id="profile-form-password" label="New password" help={"Use at least ".concat(minPasswordLength, " characters.")} error={passwordError}>
|
|
144
|
+
{function (f) { return (<TextField id={f.id} type="password" aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} value={password} disabled={savingPassword} autoComplete="new-password" onChange={function (e) { setPassword(e.target.value); setPasswordError(''); setPasswordSaved(false); }}/>); }}
|
|
145
|
+
</FormField>
|
|
146
|
+
<Cluster>
|
|
147
|
+
<Button size="medium" type="primary" state={(currentPassword && password) || savingPassword ? 'enabled' : 'disabled'} label={passwordSaved ? 'Saved' : 'Update Password'} htmlType="submit" loading={savingPassword}/>
|
|
148
|
+
</Cluster>
|
|
149
|
+
</Form>
|
|
150
|
+
</SettingsSection>
|
|
151
|
+
</Stack>
|
|
152
|
+
</Center>);
|
|
153
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# Profile
|
|
2
|
+
|
|
3
|
+
A person changes how they appear and how they sign in: their picture, their name and their password.
|
|
4
|
+
|
|
5
|
+
## Do
|
|
6
|
+
|
|
7
|
+
- Follow the rule 'A setting saves in place, or with one Save Button'.
|
|
8
|
+
- 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.
|
|
9
|
+
- 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.
|
|
10
|
+
- When the picture fails to save, keep the old one and say why under the Buttons: 'Could not save. Try again.'
|
|
11
|
+
- Give 'Remove' an `aria-label` that names the thing: 'Remove picture'. Show it only when there is a picture to remove.
|
|
12
|
+
- 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.
|
|
13
|
+
- 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.
|
|
14
|
+
- Show a wrong current password under that field, and keep what the person typed in both.
|
|
15
|
+
- Use `<TextField type="password">` for both, with `autoComplete="current-password"` and `autoComplete="new-password"`.
|
|
16
|
+
- 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.
|
|
17
|
+
- 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.'
|
|
18
|
+
- Disable the field while its request runs, and keep what the person typed when the save fails.
|
|
19
|
+
- Use `UserImage` with the person's name as `userHandle`, so a person with no picture sees their initial.
|
|
20
|
+
|
|
21
|
+
## Don't
|
|
22
|
+
|
|
23
|
+
- Do not add one Save Button for the whole page. Each group saves by itself.
|
|
24
|
+
- Do not label the Button 'Saving…' while it runs. It keeps its label.
|
|
25
|
+
- Do not show a toast when the name or the password is saved. The Button says it.
|
|
26
|
+
- Do not keep the passwords in the fields after they are saved.
|
|
27
|
+
- Do not ask for the new password twice. Show one field and the length rule.
|
|
28
|
+
|
|
29
|
+
## Example: Picture, name and password
|
|
30
|
+
|
|
31
|
+
Uses: `Alert`, `Button`, `Center`, `Cluster`, `Form`, `FormField`, `Heading`, `SettingsSection`, `Stack`, `TextField`, `UserImage`
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
'use client';
|
|
35
|
+
import { useEffect, useRef, useState } from 'react';
|
|
36
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
37
|
+
import Form from 'oneslash-design-system/components/form';
|
|
38
|
+
import FormField from 'oneslash-design-system/components/formField';
|
|
39
|
+
import TextField from 'oneslash-design-system/components/textField';
|
|
40
|
+
import Button from 'oneslash-design-system/components/button';
|
|
41
|
+
import Alert from 'oneslash-design-system/components/alert';
|
|
42
|
+
import UserImage from 'oneslash-design-system/components/userImage';
|
|
43
|
+
import SettingsSection from 'oneslash-design-system/components/settingsSection';
|
|
44
|
+
import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
|
|
45
|
+
|
|
46
|
+
// A picture the person chose. A real app uploads the file and gets a URL back.
|
|
47
|
+
const chosenPicture =
|
|
48
|
+
"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";
|
|
49
|
+
|
|
50
|
+
const minPasswordLength = 8;
|
|
51
|
+
// Stands in for the server's check. In this example every current password is right except this one.
|
|
52
|
+
const wrongCurrentPassword = 'incorrect';
|
|
53
|
+
|
|
54
|
+
export default function ProfileForm() {
|
|
55
|
+
const [picture, setPicture] = useState<string | undefined>(undefined);
|
|
56
|
+
// Which picture Button was pressed, so only that one shows `loading`.
|
|
57
|
+
const [savingPicture, setSavingPicture] = useState<'change' | 'remove' | null>(null);
|
|
58
|
+
const [pictureError, setPictureError] = useState('');
|
|
59
|
+
|
|
60
|
+
const [savedName, setSavedName] = useState('Dana Lee');
|
|
61
|
+
const [name, setName] = useState('Dana Lee');
|
|
62
|
+
const [nameError, setNameError] = useState('');
|
|
63
|
+
const [savingName, setSavingName] = useState(false);
|
|
64
|
+
const [nameSaved, setNameSaved] = useState(false);
|
|
65
|
+
|
|
66
|
+
const [currentPassword, setCurrentPassword] = useState('');
|
|
67
|
+
const [currentPasswordError, setCurrentPasswordError] = useState('');
|
|
68
|
+
const [password, setPassword] = useState('');
|
|
69
|
+
const [passwordError, setPasswordError] = useState('');
|
|
70
|
+
const [savingPassword, setSavingPassword] = useState(false);
|
|
71
|
+
const [passwordSaved, setPasswordSaved] = useState(false);
|
|
72
|
+
|
|
73
|
+
const timers = useRef<ReturnType<typeof setTimeout>[]>([]);
|
|
74
|
+
// One 'Saved' timer per group, cleared before a new one starts, so an old one cannot end a new 'Saved' early.
|
|
75
|
+
const nameSavedTimer = useRef<ReturnType<typeof setTimeout>>();
|
|
76
|
+
const passwordSavedTimer = useRef<ReturnType<typeof setTimeout>>();
|
|
77
|
+
// The first picture save fails, as if the upload dropped, so the example shows both paths.
|
|
78
|
+
const pictureFails = useRef(true);
|
|
79
|
+
|
|
80
|
+
// Stops every request and every 'Saved' if the example goes away before they end.
|
|
81
|
+
useEffect(() => () => {
|
|
82
|
+
timers.current.forEach(clearTimeout);
|
|
83
|
+
clearTimeout(nameSavedTimer.current);
|
|
84
|
+
clearTimeout(passwordSavedTimer.current);
|
|
85
|
+
}, []);
|
|
86
|
+
|
|
87
|
+
// Stands in for the request to the server.
|
|
88
|
+
function later(callback: () => void, ms: number) {
|
|
89
|
+
timers.current.push(setTimeout(callback, ms));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// The picture is one control on its own, so it saves as soon as it is chosen or removed. Nothing shows when it works.
|
|
93
|
+
// When it fails, the old picture stays and a line under the Buttons says why.
|
|
94
|
+
function savePicture(next: string | undefined, pressed: 'change' | 'remove') {
|
|
95
|
+
if (savingPicture) return;
|
|
96
|
+
setPictureError('');
|
|
97
|
+
setSavingPicture(pressed);
|
|
98
|
+
later(() => {
|
|
99
|
+
setSavingPicture(null);
|
|
100
|
+
if (pictureFails.current) {
|
|
101
|
+
pictureFails.current = false;
|
|
102
|
+
setPictureError('Could not save. Try again.');
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
setPicture(next);
|
|
106
|
+
}, 900);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// The name is a group with one Save Button: 'Saved' shows for 2 seconds, and the Button is disabled while nothing changed.
|
|
110
|
+
function handleSaveName() {
|
|
111
|
+
if (savingName) return;
|
|
112
|
+
if (!name.trim()) {
|
|
113
|
+
setNameError('Enter your name.');
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
setNameError('');
|
|
117
|
+
setSavingName(true);
|
|
118
|
+
later(() => {
|
|
119
|
+
setSavedName(name.trim());
|
|
120
|
+
setName(name.trim());
|
|
121
|
+
setSavingName(false);
|
|
122
|
+
setNameSaved(true);
|
|
123
|
+
clearTimeout(nameSavedTimer.current);
|
|
124
|
+
nameSavedTimer.current = setTimeout(() => setNameSaved(false), 2000);
|
|
125
|
+
}, 1200);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function handleUpdatePassword() {
|
|
129
|
+
if (savingPassword || !currentPassword || !password) return;
|
|
130
|
+
setCurrentPasswordError('');
|
|
131
|
+
if (password.length < minPasswordLength) {
|
|
132
|
+
setPasswordError(`Use at least ${minPasswordLength} characters.`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
setPasswordError('');
|
|
136
|
+
setSavingPassword(true);
|
|
137
|
+
later(() => {
|
|
138
|
+
setSavingPassword(false);
|
|
139
|
+
// A wrong current password shows under that field, and both fields keep what the person typed.
|
|
140
|
+
if (currentPassword === wrongCurrentPassword) {
|
|
141
|
+
setCurrentPasswordError('This is not your current password. Enter it again.');
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
setCurrentPassword('');
|
|
145
|
+
setPassword('');
|
|
146
|
+
setPasswordSaved(true);
|
|
147
|
+
clearTimeout(passwordSavedTimer.current);
|
|
148
|
+
passwordSavedTimer.current = setTimeout(() => setPasswordSaved(false), 2000);
|
|
149
|
+
}, 1200);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const nameChanged = name !== savedName;
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<Center width="page">
|
|
156
|
+
<Stack gap="xlarge">
|
|
157
|
+
<Heading level={1} size="h5">Profile</Heading>
|
|
158
|
+
|
|
159
|
+
<SettingsSection title="Picture" description="Shown beside your name in Acme.">
|
|
160
|
+
<Cluster gap="large">
|
|
161
|
+
<UserImage userHandle={savedName} userImgUrl={picture} size={64} />
|
|
162
|
+
<Stack gap="small">
|
|
163
|
+
<Cluster gap="small">
|
|
164
|
+
<Button size="small" type="secondary" state={savingPicture === 'remove' ? 'disabled' : 'enabled'} label="Change Picture" loading={savingPicture === 'change'} onClickButton={() => savePicture(chosenPicture, 'change')} />
|
|
165
|
+
{picture && <Button size="small" type="tertiary" state={savingPicture === 'change' ? 'disabled' : 'enabled'} label="Remove" aria-label="Remove picture" loading={savingPicture === 'remove'} onClickButton={() => savePicture(undefined, 'remove')} />}
|
|
166
|
+
</Cluster>
|
|
167
|
+
{pictureError && <Alert type="error" variant="inline" autoDismiss={false} message={pictureError} />}
|
|
168
|
+
</Stack>
|
|
169
|
+
</Cluster>
|
|
170
|
+
</SettingsSection>
|
|
171
|
+
|
|
172
|
+
<SettingsSection title="Name" description="How people see you in messages and on tasks.">
|
|
173
|
+
<Form aria-label="Name" gap="medium" onSubmit={handleSaveName}>
|
|
174
|
+
<FormField id="profile-form-name" label="Name" error={nameError}>
|
|
175
|
+
{(f) => (
|
|
176
|
+
<TextField
|
|
177
|
+
id={f.id}
|
|
178
|
+
aria-describedby={f['aria-describedby']}
|
|
179
|
+
aria-invalid={f['aria-invalid']}
|
|
180
|
+
value={name}
|
|
181
|
+
disabled={savingName}
|
|
182
|
+
autoComplete="name"
|
|
183
|
+
onChange={(e) => { setName(e.target.value); setNameError(''); setNameSaved(false); }}
|
|
184
|
+
/>
|
|
185
|
+
)}
|
|
186
|
+
</FormField>
|
|
187
|
+
<Cluster>
|
|
188
|
+
<Button size="medium" type="primary" state={nameChanged || savingName ? 'enabled' : 'disabled'} label={nameSaved ? 'Saved' : 'Save'} htmlType="submit" loading={savingName} />
|
|
189
|
+
</Cluster>
|
|
190
|
+
</Form>
|
|
191
|
+
</SettingsSection>
|
|
192
|
+
|
|
193
|
+
<SettingsSection title="Password" description="Sign in with dana@acme.example and a password.">
|
|
194
|
+
<Form aria-label="Password" gap="medium" onSubmit={handleUpdatePassword}>
|
|
195
|
+
<FormField id="profile-form-current-password" label="Current password" error={currentPasswordError}>
|
|
196
|
+
{(f) => (
|
|
197
|
+
<TextField
|
|
198
|
+
id={f.id}
|
|
199
|
+
type="password"
|
|
200
|
+
aria-describedby={f['aria-describedby']}
|
|
201
|
+
aria-invalid={f['aria-invalid']}
|
|
202
|
+
value={currentPassword}
|
|
203
|
+
disabled={savingPassword}
|
|
204
|
+
autoComplete="current-password"
|
|
205
|
+
onChange={(e) => { setCurrentPassword(e.target.value); setCurrentPasswordError(''); setPasswordSaved(false); }}
|
|
206
|
+
/>
|
|
207
|
+
)}
|
|
208
|
+
</FormField>
|
|
209
|
+
<FormField id="profile-form-password" label="New password" help={`Use at least ${minPasswordLength} characters.`} error={passwordError}>
|
|
210
|
+
{(f) => (
|
|
211
|
+
<TextField
|
|
212
|
+
id={f.id}
|
|
213
|
+
type="password"
|
|
214
|
+
aria-describedby={f['aria-describedby']}
|
|
215
|
+
aria-invalid={f['aria-invalid']}
|
|
216
|
+
value={password}
|
|
217
|
+
disabled={savingPassword}
|
|
218
|
+
autoComplete="new-password"
|
|
219
|
+
onChange={(e) => { setPassword(e.target.value); setPasswordError(''); setPasswordSaved(false); }}
|
|
220
|
+
/>
|
|
221
|
+
)}
|
|
222
|
+
</FormField>
|
|
223
|
+
<Cluster>
|
|
224
|
+
<Button size="medium" type="primary" state={(currentPassword && password) || savingPassword ? 'enabled' : 'disabled'} label={passwordSaved ? 'Saved' : 'Update Password'} htmlType="submit" loading={savingPassword} />
|
|
225
|
+
</Cluster>
|
|
226
|
+
</Form>
|
|
227
|
+
</SettingsSection>
|
|
228
|
+
</Stack>
|
|
229
|
+
</Center>
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Native
|
|
235
|
+
|
|
236
|
+
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.
|