oneslash-design-system 2.14.2 → 2.16.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 +15 -0
- package/dist/DESIGN.md +138 -1
- package/dist/cases/accept-invite/signed-in.d.ts +1 -0
- package/dist/cases/accept-invite/signed-in.jsx +57 -0
- package/dist/cases/accept-invite/signed-out.d.ts +1 -0
- package/dist/cases/accept-invite/signed-out.jsx +33 -0
- package/dist/cases/accept-invite.md +161 -0
- package/dist/cases/agent-asks-before-risky-action.md +29 -0
- package/dist/cases/agent-cancels-when-unanswered.md +27 -0
- package/dist/cases/agent-refuses-clearly.md +31 -0
- package/dist/cases/agent-says-what-it-is.md +29 -0
- package/dist/cases/agent-shows-progress.md +30 -0
- package/dist/cases/agent-shows-sources.md +26 -0
- package/dist/cases/auth-gate-loading/spinner-with-line.d.ts +1 -0
- package/dist/cases/auth-gate-loading/spinner-with-line.jsx +10 -0
- package/dist/cases/auth-gate-loading/spinner.d.ts +1 -0
- package/dist/cases/auth-gate-loading/spinner.jsx +10 -0
- package/dist/cases/auth-gate-loading.md +70 -0
- package/dist/cases/check-your-email/alert-on-login.d.ts +1 -0
- package/dist/cases/check-your-email/alert-on-login.jsx +78 -0
- package/dist/cases/check-your-email/page.d.ts +1 -0
- package/dist/cases/check-your-email/page.jsx +49 -0
- package/dist/cases/check-your-email.md +184 -0
- package/dist/cases/confirm-destructive-action/inline.d.ts +1 -0
- package/dist/cases/confirm-destructive-action/inline.jsx +69 -0
- package/dist/cases/confirm-destructive-action/modal.d.ts +1 -0
- package/dist/cases/confirm-destructive-action/modal.jsx +66 -0
- package/dist/cases/confirm-destructive-action.md +211 -0
- package/dist/cases/confirm-dialogs.md +36 -0
- package/dist/cases/create-modal/quick.d.ts +1 -0
- package/dist/cases/create-modal/quick.jsx +80 -0
- package/dist/cases/create-modal/with-settings.d.ts +1 -0
- package/dist/cases/create-modal/with-settings.jsx +99 -0
- package/dist/cases/create-modal.md +244 -0
- package/dist/cases/device-login/popup.d.ts +1 -0
- package/dist/cases/device-login/popup.jsx +14 -0
- package/dist/cases/device-login/provider-first.d.ts +1 -0
- package/dist/cases/device-login/provider-first.jsx +98 -0
- package/dist/cases/device-login.md +171 -0
- package/dist/cases/email-confirmed/alert-on-login.d.ts +1 -0
- package/dist/cases/email-confirmed/alert-on-login.jsx +78 -0
- package/dist/cases/email-confirmed/page.d.ts +1 -0
- package/dist/cases/email-confirmed/page.jsx +21 -0
- package/dist/cases/email-confirmed.md +151 -0
- package/dist/cases/empty-list/region.d.ts +1 -0
- package/dist/cases/empty-list/region.jsx +13 -0
- package/dist/cases/empty-list/section.d.ts +1 -0
- package/dist/cases/empty-list/section.jsx +17 -0
- package/dist/cases/empty-list.md +77 -0
- package/dist/cases/empty-lists.md +35 -0
- package/dist/cases/empty-not-set-up/action.d.ts +1 -0
- package/dist/cases/empty-not-set-up/action.jsx +16 -0
- package/dist/cases/empty-not-set-up/pointer.d.ts +1 -0
- package/dist/cases/empty-not-set-up/pointer.jsx +13 -0
- package/dist/cases/empty-not-set-up.md +88 -0
- package/dist/cases/empty-search/clear-search.d.ts +1 -0
- package/dist/cases/empty-search/clear-search.jsx +29 -0
- package/dist/cases/empty-search.md +77 -0
- package/dist/cases/error-page/full-page.d.ts +1 -0
- package/dist/cases/error-page/full-page.jsx +19 -0
- package/dist/cases/error-page/in-shell.d.ts +1 -0
- package/dist/cases/error-page/in-shell.jsx +39 -0
- package/dist/cases/error-page.md +107 -0
- package/dist/cases/feedback-form/modal.d.ts +1 -0
- package/dist/cases/feedback-form/modal.jsx +89 -0
- package/dist/cases/feedback-form.md +139 -0
- package/dist/cases/forgot-password/in-place.d.ts +1 -0
- package/dist/cases/forgot-password/in-place.jsx +155 -0
- package/dist/cases/forgot-password/own-page.d.ts +1 -0
- package/dist/cases/forgot-password/own-page.jsx +99 -0
- package/dist/cases/forgot-password.md +328 -0
- package/dist/cases/form-errors.md +32 -0
- package/dist/cases/import-checklist/modal.d.ts +1 -0
- package/dist/cases/import-checklist/modal.jsx +125 -0
- package/dist/cases/import-checklist.md +188 -0
- package/dist/cases/inline-form-feedback/button-label.d.ts +1 -0
- package/dist/cases/inline-form-feedback/button-label.jsx +54 -0
- package/dist/cases/inline-form-feedback/inline-alert.d.ts +1 -0
- package/dist/cases/inline-form-feedback/inline-alert.jsx +49 -0
- package/dist/cases/inline-form-feedback/toast.d.ts +1 -0
- package/dist/cases/inline-form-feedback/toast.jsx +66 -0
- package/dist/cases/inline-form-feedback.md +237 -0
- package/dist/cases/invite-member/by-email.d.ts +1 -0
- package/dist/cases/invite-member/by-email.jsx +98 -0
- package/dist/cases/invite-member/by-link.d.ts +1 -0
- package/dist/cases/invite-member/by-link.jsx +122 -0
- package/dist/cases/invite-member.md +321 -0
- package/dist/cases/load-failure/inline.d.ts +1 -0
- package/dist/cases/load-failure/inline.jsx +52 -0
- package/dist/cases/load-failure/region.d.ts +1 -0
- package/dist/cases/load-failure/region.jsx +34 -0
- package/dist/cases/load-failure.md +155 -0
- package/dist/cases/log-out-confirm/modal.d.ts +1 -0
- package/dist/cases/log-out-confirm/modal.jsx +57 -0
- package/dist/cases/log-out-confirm.md +106 -0
- package/dist/cases/login-page/centered.d.ts +1 -0
- package/dist/cases/login-page/centered.jsx +72 -0
- package/dist/cases/login-page/email-only.d.ts +1 -0
- package/dist/cases/login-page/email-only.jsx +59 -0
- package/dist/cases/login-page/provider-first.d.ts +1 -0
- package/dist/cases/login-page/provider-first.jsx +66 -0
- package/dist/cases/login-page/split.d.ts +1 -0
- package/dist/cases/login-page/split.jsx +79 -0
- package/dist/cases/login-page.md +373 -0
- package/dist/cases/not-found-page/full-page.d.ts +1 -0
- package/dist/cases/not-found-page/full-page.jsx +16 -0
- package/dist/cases/not-found-page/in-shell.d.ts +1 -0
- package/dist/cases/not-found-page/in-shell.jsx +36 -0
- package/dist/cases/not-found-page.md +98 -0
- package/dist/cases/oauth-consent/simple.d.ts +1 -0
- package/dist/cases/oauth-consent/simple.jsx +73 -0
- package/dist/cases/oauth-consent/with-scope.d.ts +1 -0
- package/dist/cases/oauth-consent/with-scope.jsx +89 -0
- package/dist/cases/oauth-consent.md +233 -0
- package/dist/cases/rename/inline.d.ts +1 -0
- package/dist/cases/rename/inline.jsx +58 -0
- package/dist/cases/rename/modal.d.ts +1 -0
- package/dist/cases/rename/modal.jsx +70 -0
- package/dist/cases/rename.md +205 -0
- package/dist/cases/route-loading/full-screen.d.ts +1 -0
- package/dist/cases/route-loading/full-screen.jsx +8 -0
- package/dist/cases/route-loading/region.d.ts +1 -0
- package/dist/cases/route-loading/region.jsx +26 -0
- package/dist/cases/route-loading.md +84 -0
- package/dist/cases/set-new-password/form.d.ts +1 -0
- package/dist/cases/set-new-password/form.jsx +130 -0
- package/dist/cases/set-new-password/invalid-link.d.ts +1 -0
- package/dist/cases/set-new-password/invalid-link.jsx +50 -0
- package/dist/cases/set-new-password.md +247 -0
- package/dist/cases/sign-up-page/centered.d.ts +1 -0
- package/dist/cases/sign-up-page/centered.jsx +124 -0
- package/dist/cases/sign-up-page/provider-first.d.ts +1 -0
- package/dist/cases/sign-up-page/provider-first.jsx +124 -0
- package/dist/cases/sign-up-page/split.d.ts +1 -0
- package/dist/cases/sign-up-page/split.jsx +134 -0
- package/dist/cases/sign-up-page.md +478 -0
- package/dist/cases/success-feedback.md +35 -0
- package/dist/cases/type-to-confirm/inline.d.ts +1 -0
- package/dist/cases/type-to-confirm/inline.jsx +69 -0
- package/dist/cases/type-to-confirm/modal.d.ts +1 -0
- package/dist/cases/type-to-confirm/modal.jsx +73 -0
- package/dist/cases/type-to-confirm.md +222 -0
- package/dist/cases/unsaved-changes-guard/discard.d.ts +1 -0
- package/dist/cases/unsaved-changes-guard/discard.jsx +81 -0
- package/dist/cases/unsaved-changes-guard/save-or-discard.d.ts +1 -0
- package/dist/cases/unsaved-changes-guard/save-or-discard.jsx +85 -0
- package/dist/cases/unsaved-changes-guard.md +239 -0
- package/dist/cases/upgrade-prompt/inline.d.ts +1 -0
- package/dist/cases/upgrade-prompt/inline.jsx +52 -0
- package/dist/cases/upgrade-prompt/modal.d.ts +1 -0
- package/dist/cases/upgrade-prompt/modal.jsx +43 -0
- package/dist/cases/upgrade-prompt.md +174 -0
- package/dist/cases.json +2073 -0
- package/dist/components/alert.d.ts +3 -1
- package/dist/components/alert.jsx +6 -4
- package/dist/components/brandIcon.d.ts +12 -0
- package/dist/components/brandIcon.jsx +24 -0
- package/dist/components/emptyBox.d.ts +6 -1
- package/dist/components/emptyBox.jsx +4 -2
- package/dist/components/form.d.ts +11 -0
- package/dist/components/form.jsx +22 -0
- package/dist/components/heading.d.ts +2 -2
- package/dist/components/image.d.ts +14 -0
- package/dist/components/image.jsx +6 -0
- package/dist/components/layout.d.ts +18 -1
- package/dist/components/layout.jsx +16 -0
- package/dist/components/line.d.ts +3 -1
- package/dist/components/line.jsx +8 -1
- package/dist/components/loadingScreen.d.ts +5 -1
- package/dist/components/loadingScreen.jsx +4 -2
- package/dist/components/modal.d.ts +2 -1
- package/dist/components/modal.jsx +20 -8
- package/dist/components/radioGroup.d.ts +2 -1
- package/dist/components/radioGroup.jsx +2 -2
- package/dist/components/select.d.ts +2 -1
- package/dist/components/select.jsx +4 -2
- package/dist/components/tab.jsx +3 -2
- package/dist/components/tabsContainer.d.ts +4 -1
- package/dist/components/tabsContainer.jsx +11 -5
- package/dist/components/textField.d.ts +5 -1
- package/dist/components/textField.jsx +7 -3
- package/dist/components/toaster.d.ts +12 -0
- package/dist/components/toaster.jsx +103 -0
- package/dist/components/tooltip.jsx +3 -1
- package/dist/designTokens.d.ts +1 -0
- package/dist/designTokens.js +1 -0
- package/dist/internal/alert.d.ts +4 -0
- package/dist/internal/alert.js +6 -0
- package/dist/internal/modal.d.ts +2 -0
- package/dist/internal/modal.js +21 -0
- package/dist/internal/toaster.d.ts +19 -0
- package/dist/internal/toaster.js +50 -0
- package/dist/native-mapping.json +23 -1
- package/dist/stories/Alert.stories.d.ts +1 -0
- package/dist/stories/Alert.stories.jsx +16 -0
- package/dist/stories/BrandIcon.stories.d.ts +9 -0
- package/dist/stories/BrandIcon.stories.jsx +19 -0
- package/dist/stories/Cases.generated.stories.d.ts +60 -0
- package/dist/stories/Cases.generated.stories.jsx +116 -0
- package/dist/stories/EmptyBox.stories.d.ts +2 -0
- package/dist/stories/EmptyBox.stories.jsx +16 -0
- package/dist/stories/Form.stories.d.ts +6 -0
- package/dist/stories/Form.stories.jsx +26 -0
- package/dist/stories/Heading.stories.d.ts +6 -0
- package/dist/stories/Heading.stories.jsx +10 -0
- package/dist/stories/Image.stories.d.ts +7 -0
- package/dist/stories/Image.stories.jsx +18 -0
- package/dist/stories/Line.stories.d.ts +1 -0
- package/dist/stories/Line.stories.jsx +12 -0
- package/dist/stories/LoadingScreen.stories.d.ts +1 -0
- package/dist/stories/LoadingScreen.stories.jsx +8 -0
- package/dist/stories/Modal.stories.d.ts +2 -0
- package/dist/stories/Modal.stories.jsx +36 -0
- package/dist/stories/PageComponents.stories.d.ts +2 -0
- package/dist/stories/PageComponents.stories.jsx +15 -1
- package/dist/stories/RadioGroup.stories.d.ts +1 -0
- package/dist/stories/RadioGroup.stories.jsx +14 -0
- package/dist/stories/Select.stories.d.ts +1 -0
- package/dist/stories/Select.stories.jsx +14 -0
- package/dist/stories/TabsContainer.stories.d.ts +1 -0
- package/dist/stories/TabsContainer.stories.jsx +12 -0
- package/dist/stories/TextField.stories.d.ts +2 -0
- package/dist/stories/TextField.stories.jsx +22 -0
- package/dist/stories/Toaster.stories.d.ts +6 -0
- package/dist/stories/Toaster.stories.jsx +29 -0
- package/dist/tailwind-preset-auto.js +2 -1
- package/dist/tailwind-preset.js +2 -1
- package/dist/theme-auto.css +1 -0
- package/dist/theme.css +1 -0
- package/dist/tokens.css +1 -0
- package/dist/tokens.json +7 -0
- package/package.json +4 -2
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# Create modal
|
|
2
|
+
|
|
3
|
+
A person creates something new, such as a project or a task, and it needs a name before it exists.
|
|
4
|
+
|
|
5
|
+
**Not built yet:** 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.
|
|
6
|
+
|
|
7
|
+
## Do
|
|
8
|
+
|
|
9
|
+
- Title the Modal 'Create' and the thing, such as 'Create Project', and give its action the same verb: 'Create'.
|
|
10
|
+
- Put 'Cancel' first, a tertiary Button, then 'Create', a primary Button, in the Modal's `actions`.
|
|
11
|
+
- Create on Enter too: put the fields in a `Form`.
|
|
12
|
+
- Keep 'Create' `state="disabled"` while the name is empty.
|
|
13
|
+
- Show `loading` on 'Create' while it runs, and keep the fields on screen with what the person typed.
|
|
14
|
+
- Disable the fields while it runs, where the part allows it: the `TextField` and the `Checkbox`.
|
|
15
|
+
- Focus the name field when the Modal opens, with `initialFocus="body"`.
|
|
16
|
+
- Give a `RadioGroup` a line of text above it and an `aria-label` with the same words.
|
|
17
|
+
- Show a name that is taken under the field, with `error` and `errorText`, and keep the Modal open.
|
|
18
|
+
- Pick a safe default for every choice, so the person only has to type the name.
|
|
19
|
+
- Close the Modal when it works and show the new thing where it lives.
|
|
20
|
+
|
|
21
|
+
## Don't
|
|
22
|
+
|
|
23
|
+
- Do not replace the fields with a spinner while it creates.
|
|
24
|
+
- Do not change the label while it is loading, such as to 'Creating…'.
|
|
25
|
+
- Do not ask for more than the thing needs to exist. Everything else goes in its settings.
|
|
26
|
+
- Do not show a toast when the new thing is on screen. It shows where it lives.
|
|
27
|
+
|
|
28
|
+
## Option: Just a name
|
|
29
|
+
|
|
30
|
+
Use when: One name is enough. Everything else can be set later.
|
|
31
|
+
|
|
32
|
+
Uses: `Button`, `Center`, `Cluster`, `Form`, `Heading`, `List`, `Modal`, `Stack`, `Surface`, `TextField`
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
'use client';
|
|
36
|
+
import { useEffect, useRef, useState } from 'react';
|
|
37
|
+
import Modal from 'oneslash-design-system/components/modal';
|
|
38
|
+
import Surface from 'oneslash-design-system/components/surface';
|
|
39
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
40
|
+
import List from 'oneslash-design-system/components/list';
|
|
41
|
+
import Form from 'oneslash-design-system/components/form';
|
|
42
|
+
import TextField from 'oneslash-design-system/components/textField';
|
|
43
|
+
import Button from 'oneslash-design-system/components/button';
|
|
44
|
+
import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
|
|
45
|
+
|
|
46
|
+
export default function CreateModalQuick() {
|
|
47
|
+
const [projects, setProjects] = useState(['Website refresh', 'Hiring plan', 'Office move']);
|
|
48
|
+
// Opens on the Modal, as if the person just chose Create Project.
|
|
49
|
+
const [open, setOpen] = useState(true);
|
|
50
|
+
const [name, setName] = useState('Q4 budget');
|
|
51
|
+
const [nameError, setNameError] = useState('');
|
|
52
|
+
const [creating, setCreating] = useState(false);
|
|
53
|
+
const timer = useRef<ReturnType<typeof setTimeout>>();
|
|
54
|
+
|
|
55
|
+
// Stops the request if the example goes away before it ends.
|
|
56
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
57
|
+
|
|
58
|
+
const next = name.trim();
|
|
59
|
+
|
|
60
|
+
function handleOpen() {
|
|
61
|
+
setName('');
|
|
62
|
+
setNameError('');
|
|
63
|
+
setOpen(true);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Escape, a click outside and Cancel all close it, except while the request runs.
|
|
67
|
+
function handleClose() {
|
|
68
|
+
if (creating) return;
|
|
69
|
+
setOpen(false);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function handleCreate() {
|
|
73
|
+
if (creating || next === '') return;
|
|
74
|
+
setNameError('');
|
|
75
|
+
setCreating(true);
|
|
76
|
+
// Stands in for the request to the server.
|
|
77
|
+
timer.current = setTimeout(() => {
|
|
78
|
+
setCreating(false);
|
|
79
|
+
// The server already has these names. Type one to see the request fail.
|
|
80
|
+
if (projects.some((p) => p.toLowerCase() === next.toLowerCase())) {
|
|
81
|
+
setNameError(`A project named '${next}' already exists. Choose another name.`);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
setProjects((list) => [next, ...list]);
|
|
85
|
+
setOpen(false);
|
|
86
|
+
}, 1200);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<Center width="page">
|
|
91
|
+
<Stack gap="large">
|
|
92
|
+
<Cluster>
|
|
93
|
+
<Heading level={1} size="h5">Projects</Heading>
|
|
94
|
+
<Button size="small" type="primary" state="enabled" label="Create Project" decoIcon="Plus" onClickButton={handleOpen} />
|
|
95
|
+
</Cluster>
|
|
96
|
+
{/* The new project shows at the top of the list, so no toast is needed. */}
|
|
97
|
+
<Surface padding="large">
|
|
98
|
+
<List items={projects} size="body1" />
|
|
99
|
+
</Surface>
|
|
100
|
+
</Stack>
|
|
101
|
+
<Modal
|
|
102
|
+
isOpen={open}
|
|
103
|
+
size="small"
|
|
104
|
+
initialFocus="body"
|
|
105
|
+
title="Create Project"
|
|
106
|
+
onClose={handleClose}
|
|
107
|
+
actions={
|
|
108
|
+
<>
|
|
109
|
+
<Button size="small" type="tertiary" state={creating ? 'disabled' : 'enabled'} label="Cancel" onClickButton={handleClose} />
|
|
110
|
+
<Button size="small" type="primary" state={next === '' ? 'disabled' : 'enabled'} label="Create" loading={creating} onClickButton={handleCreate} />
|
|
111
|
+
</>
|
|
112
|
+
}
|
|
113
|
+
>
|
|
114
|
+
{/* The Form lets Enter in the field create too. */}
|
|
115
|
+
<Form aria-label="Create project" onSubmit={handleCreate}>
|
|
116
|
+
<TextField id="create-modal-name" label="Project name" placeholder="Q4 budget" value={name} disabled={creating} error={Boolean(nameError)} errorText={nameError} onChange={(e) => { setName(e.target.value); setNameError(''); }} />
|
|
117
|
+
</Form>
|
|
118
|
+
</Modal>
|
|
119
|
+
</Center>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Option: A name and a few choices
|
|
125
|
+
|
|
126
|
+
Use when: The thing needs two or three choices up front, such as who can see it.
|
|
127
|
+
|
|
128
|
+
Uses: `Button`, `Center`, `Checkbox`, `Cluster`, `Form`, `Heading`, `List`, `Modal`, `Paragraph`, `RadioGroup`, `Stack`, `Surface`, `TextField`
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
'use client';
|
|
132
|
+
import { useEffect, useRef, useState } from 'react';
|
|
133
|
+
import Modal from 'oneslash-design-system/components/modal';
|
|
134
|
+
import Surface from 'oneslash-design-system/components/surface';
|
|
135
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
136
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
137
|
+
import List from 'oneslash-design-system/components/list';
|
|
138
|
+
import Form from 'oneslash-design-system/components/form';
|
|
139
|
+
import TextField from 'oneslash-design-system/components/textField';
|
|
140
|
+
import RadioGroup from 'oneslash-design-system/components/radioGroup';
|
|
141
|
+
import Checkbox from 'oneslash-design-system/components/checkBox';
|
|
142
|
+
import Button from 'oneslash-design-system/components/button';
|
|
143
|
+
import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
|
|
144
|
+
|
|
145
|
+
const visibilityOptions = [
|
|
146
|
+
{ value: 'workspace', label: 'Everyone in Acme Design', secondLabel: 'Anyone in the workspace can find and open it.' },
|
|
147
|
+
{ value: 'private', label: 'Only people you invite', secondLabel: 'It stays hidden until you add people.' },
|
|
148
|
+
];
|
|
149
|
+
|
|
150
|
+
export default function CreateModalWithSettings() {
|
|
151
|
+
const [projects, setProjects] = useState(['Website refresh', 'Hiring plan', 'Office move']);
|
|
152
|
+
// Opens on the Modal, as if the person just chose Create Project.
|
|
153
|
+
const [open, setOpen] = useState(true);
|
|
154
|
+
const [name, setName] = useState('Q4 budget');
|
|
155
|
+
// Safe defaults, so the name is the only thing the person has to give.
|
|
156
|
+
const [visibility, setVisibility] = useState('workspace');
|
|
157
|
+
const [starterTasks, setStarterTasks] = useState(true);
|
|
158
|
+
const [nameError, setNameError] = useState('');
|
|
159
|
+
const [creating, setCreating] = useState(false);
|
|
160
|
+
const timer = useRef<ReturnType<typeof setTimeout>>();
|
|
161
|
+
|
|
162
|
+
// Stops the request if the example goes away before it ends.
|
|
163
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
164
|
+
|
|
165
|
+
const next = name.trim();
|
|
166
|
+
|
|
167
|
+
function handleOpen() {
|
|
168
|
+
setName('');
|
|
169
|
+
setVisibility('workspace');
|
|
170
|
+
setStarterTasks(true);
|
|
171
|
+
setNameError('');
|
|
172
|
+
setOpen(true);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Escape, a click outside and Cancel all close it, except while the request runs.
|
|
176
|
+
function handleClose() {
|
|
177
|
+
if (creating) return;
|
|
178
|
+
setOpen(false);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function handleCreate() {
|
|
182
|
+
if (creating || next === '') return;
|
|
183
|
+
setNameError('');
|
|
184
|
+
setCreating(true);
|
|
185
|
+
// Stands in for the request to the server.
|
|
186
|
+
timer.current = setTimeout(() => {
|
|
187
|
+
setCreating(false);
|
|
188
|
+
// The server already has these names. Type one to see the request fail.
|
|
189
|
+
if (projects.some((p) => p.toLowerCase() === next.toLowerCase())) {
|
|
190
|
+
setNameError(`A project named '${next}' already exists. Choose another name.`);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
setProjects((list) => [next, ...list]);
|
|
194
|
+
setOpen(false);
|
|
195
|
+
}, 1200);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<Center width="page">
|
|
200
|
+
<Stack gap="large">
|
|
201
|
+
<Cluster>
|
|
202
|
+
<Heading level={1} size="h5">Projects</Heading>
|
|
203
|
+
<Button size="small" type="primary" state="enabled" label="Create Project" decoIcon="Plus" onClickButton={handleOpen} />
|
|
204
|
+
</Cluster>
|
|
205
|
+
{/* The new project shows at the top of the list, so no toast is needed. */}
|
|
206
|
+
<Surface padding="large">
|
|
207
|
+
<List items={projects} size="body1" />
|
|
208
|
+
</Surface>
|
|
209
|
+
</Stack>
|
|
210
|
+
<Modal
|
|
211
|
+
isOpen={open}
|
|
212
|
+
size="small"
|
|
213
|
+
initialFocus="body"
|
|
214
|
+
title="Create Project"
|
|
215
|
+
onClose={handleClose}
|
|
216
|
+
actions={
|
|
217
|
+
<>
|
|
218
|
+
<Button size="small" type="tertiary" state={creating ? 'disabled' : 'enabled'} label="Cancel" onClickButton={handleClose} />
|
|
219
|
+
<Button size="small" type="primary" state={next === '' ? 'disabled' : 'enabled'} label="Create" loading={creating} onClickButton={handleCreate} />
|
|
220
|
+
</>
|
|
221
|
+
}
|
|
222
|
+
>
|
|
223
|
+
{/* The Form lets Enter in the name field create too. */}
|
|
224
|
+
<Form aria-label="Create project" onSubmit={handleCreate}>
|
|
225
|
+
<TextField id="create-modal-settings-name" label="Project name" placeholder="Q4 budget" value={name} disabled={creating} error={Boolean(nameError)} errorText={nameError} onChange={(e) => { setName(e.target.value); setNameError(''); }} />
|
|
226
|
+
<Stack gap="small">
|
|
227
|
+
{/* The line above names the choice on screen, and `aria-label` names it for a screen reader.
|
|
228
|
+
RadioGroup has no disabled state, so it stays live while the request runs. */}
|
|
229
|
+
<Paragraph tone="secondary" size="body2" measure="none">Who can see it</Paragraph>
|
|
230
|
+
<RadioGroup aria-label="Who can see it" options={visibilityOptions} selectedValue={visibility} onChange={setVisibility} />
|
|
231
|
+
</Stack>
|
|
232
|
+
<Checkbox label="Add starter tasks" secondLabel="A short list to plan the first week. You can delete them." checked={starterTasks} disabled={creating} onChange={setStarterTasks} />
|
|
233
|
+
</Form>
|
|
234
|
+
</Modal>
|
|
235
|
+
</Center>
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Native
|
|
241
|
+
|
|
242
|
+
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.
|
|
243
|
+
|
|
244
|
+
Seen in: Scindo.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function DeviceLoginPopup(): import("react").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import LoadingScreen from '../../components/loadingScreen';
|
|
3
|
+
import { Center } from '../../components/layout';
|
|
4
|
+
// The page the provider sends the popup back to. It finishes the login, tells the page
|
|
5
|
+
// that opened it, and closes itself with window.close() once that page answers.
|
|
6
|
+
// It stays on this state: the login does not finish by itself.
|
|
7
|
+
// If the browser keeps the popup open after window.close(), the page shows one line
|
|
8
|
+
// in place of the spinner: 'Done. You can close this window.'
|
|
9
|
+
// If no page answers after about 2 seconds, the login ran in this tab, so the page finishes it here.
|
|
10
|
+
export default function DeviceLoginPopup() {
|
|
11
|
+
return (<Center fill>
|
|
12
|
+
<LoadingScreen label="Finishing login…"/>
|
|
13
|
+
</Center>);
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function DeviceLoginProviderFirst(): import("react").JSX.Element;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import Image from '../../components/image';
|
|
4
|
+
import Heading from '../../components/heading';
|
|
5
|
+
import Paragraph from '../../components/paragraph';
|
|
6
|
+
import Form from '../../components/form';
|
|
7
|
+
import Alert from '../../components/alert';
|
|
8
|
+
import TextField from '../../components/textField';
|
|
9
|
+
import Button from '../../components/button';
|
|
10
|
+
import Line from '../../components/line';
|
|
11
|
+
import BrandIcon from '../../components/brandIcon';
|
|
12
|
+
import LoadingScreen from '../../components/loadingScreen';
|
|
13
|
+
import { Center, Stack } from '../../components/layout';
|
|
14
|
+
// The product's mark. A real app passes its own file.
|
|
15
|
+
var productMark = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E";
|
|
16
|
+
// A small check: some text, an @, then some text.
|
|
17
|
+
function looksLikeEmail(value) {
|
|
18
|
+
return /^[^@\s]+@[^@\s]+$/.test(value);
|
|
19
|
+
}
|
|
20
|
+
export default function DeviceLoginProviderFirst() {
|
|
21
|
+
var _a = useState('ada@example.com'), email = _a[0], setEmail = _a[1];
|
|
22
|
+
var _b = useState(''), password = _b[0], setPassword = _b[1];
|
|
23
|
+
var _c = useState(''), error = _c[0], setError = _c[1];
|
|
24
|
+
var _d = useState(''), emailError = _d[0], setEmailError = _d[1];
|
|
25
|
+
var _e = useState(''), passwordError = _e[0], setPasswordError = _e[1];
|
|
26
|
+
var _f = useState(false), loading = _f[0], setLoading = _f[1];
|
|
27
|
+
// 'form', then 'waiting' for the device to answer, then 'done'.
|
|
28
|
+
var _g = useState('form'), step = _g[0], setStep = _g[1];
|
|
29
|
+
var timer = useRef();
|
|
30
|
+
// Stops the requests if the example goes away before they end.
|
|
31
|
+
useEffect(function () { return function () { return clearTimeout(timer.current); }; }, []);
|
|
32
|
+
function handleSubmit() {
|
|
33
|
+
if (loading)
|
|
34
|
+
return;
|
|
35
|
+
setError('');
|
|
36
|
+
setEmailError('');
|
|
37
|
+
setPasswordError('');
|
|
38
|
+
if (!email.trim()) {
|
|
39
|
+
setEmailError('Enter your email.');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (!looksLikeEmail(email.trim())) {
|
|
43
|
+
setEmailError('Enter an email address, like name@example.com.');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (!password) {
|
|
47
|
+
setPasswordError('Enter your password.');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
setLoading(true);
|
|
51
|
+
// Stands in for the request to the server.
|
|
52
|
+
// A refused login calls setError instead: 'That email and password do not match.'
|
|
53
|
+
timer.current = setTimeout(function () {
|
|
54
|
+
setLoading(false);
|
|
55
|
+
setStep('waiting');
|
|
56
|
+
// Stands in for the request to the server.
|
|
57
|
+
// This one hands the login to Acme CLI and waits for it to answer that it has it.
|
|
58
|
+
// If it does not answer, go back to the form with setStep('form') and
|
|
59
|
+
// setError('Acme CLI did not answer. Make sure acme login is still running, then try again.').
|
|
60
|
+
timer.current = setTimeout(function () { return setStep('done'); }, 1200);
|
|
61
|
+
}, 1200);
|
|
62
|
+
}
|
|
63
|
+
// Success shows only after the device has answered.
|
|
64
|
+
if (step === 'done') {
|
|
65
|
+
return (<Center fill>
|
|
66
|
+
<Image src={productMark} alt="Acme" width={40} height={40}/>
|
|
67
|
+
<Stack gap="medium">
|
|
68
|
+
<Heading level={1} size="h5">You're logged in</Heading>
|
|
69
|
+
<Paragraph tone="secondary" measure="none">You can close this tab.</Paragraph>
|
|
70
|
+
</Stack>
|
|
71
|
+
</Center>);
|
|
72
|
+
}
|
|
73
|
+
if (step === 'waiting') {
|
|
74
|
+
return (<Center fill>
|
|
75
|
+
<LoadingScreen label="Waiting for Acme CLI…"/>
|
|
76
|
+
</Center>);
|
|
77
|
+
}
|
|
78
|
+
return (<Center fill>
|
|
79
|
+
<Image src={productMark} alt="Acme" width={40} height={40}/>
|
|
80
|
+
<Stack gap="medium">
|
|
81
|
+
<Heading level={1} size="h5">Log in to Acme</Heading>
|
|
82
|
+
<Paragraph tone="secondary" measure="none">This connects Acme CLI on your computer to your account.</Paragraph>
|
|
83
|
+
</Stack>
|
|
84
|
+
{/* A real app sends the person to the provider, which brings them back to this page to hand the login to Acme CLI. */}
|
|
85
|
+
<Stack gap="medium">
|
|
86
|
+
<Button size="medium" type="secondary" state={loading ? 'disabled' : 'enabled'} label="Continue with Google" decoIcon={<BrandIcon name="google"/>}/>
|
|
87
|
+
<Button size="medium" type="secondary" state={loading ? 'disabled' : 'enabled'} label="Continue with GitHub" decoIcon={<BrandIcon name="github"/>}/>
|
|
88
|
+
</Stack>
|
|
89
|
+
<Line label="or"/>
|
|
90
|
+
<Form aria-label="Log in with email" onSubmit={handleSubmit}>
|
|
91
|
+
{error && <Alert type="error" variant="inline" message={error} showCloseButton onClose={function () { return setError(''); }}/>}
|
|
92
|
+
<TextField id="device-login-provider-first-email" label="Email" type="email" autoComplete="username" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={function (e) { setEmail(e.target.value); setEmailError(''); }}/>
|
|
93
|
+
<TextField id="device-login-provider-first-password" label="Password" type="password" autoComplete="current-password" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} onChange={function (e) { setPassword(e.target.value); setPasswordError(''); }}/>
|
|
94
|
+
<Button size="medium" type="primary" state="enabled" label="Log In" htmlType="submit" loading={loading}/>
|
|
95
|
+
<Button size="medium" type="textOnly" state="enabled" label="Forgot Password?"/>
|
|
96
|
+
</Form>
|
|
97
|
+
</Center>);
|
|
98
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# Device login
|
|
2
|
+
|
|
3
|
+
A CLI, an editor or another app opened the browser so the person can log in, and the login must reach that app.
|
|
4
|
+
|
|
5
|
+
**Not built yet:** 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.
|
|
6
|
+
|
|
7
|
+
## Do
|
|
8
|
+
|
|
9
|
+
- Say in one line what the login connects: 'This connects Acme CLI on your computer to your account.'
|
|
10
|
+
- Put the providers on top, then a `Line` with `label="or"`, then email and password, as on the 'Login page' with providers first.
|
|
11
|
+
- Wait for the device to answer before showing success, with `LoadingScreen` and `label="Waiting for Acme CLI…"`.
|
|
12
|
+
- End on "You're logged in" and 'You can close this tab.' once the device has answered.
|
|
13
|
+
- Go back to the form with an inline error Alert when the device does not answer, and say what to check.
|
|
14
|
+
- Show `LoadingScreen` with `label="Finishing login…"` while a popup finishes, and close the popup when the page that opened it answers.
|
|
15
|
+
- Finish the login in this tab after about 2 seconds when no page that opened the popup answers.
|
|
16
|
+
- Show 'Done. You can close this window.' when the browser keeps the popup open.
|
|
17
|
+
|
|
18
|
+
## Don't
|
|
19
|
+
|
|
20
|
+
- Do not show success before the device answers.
|
|
21
|
+
- Do not leave a popup blank while it finishes.
|
|
22
|
+
- Do not label a provider Button with its name alone, such as 'Google'. Write 'Continue with Google'.
|
|
23
|
+
|
|
24
|
+
## Option: Login page for a device
|
|
25
|
+
|
|
26
|
+
Use when: A CLI or an editor opened a browser tab; most people log in with a provider and email is the fallback.
|
|
27
|
+
|
|
28
|
+
Uses: `Alert`, `BrandIcon`, `Button`, `Center`, `Form`, `Heading`, `Image`, `Line`, `LoadingScreen`, `Paragraph`, `Stack`, `TextField`
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
'use client';
|
|
32
|
+
import { useEffect, useRef, useState } from 'react';
|
|
33
|
+
import Image from 'oneslash-design-system/components/image';
|
|
34
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
35
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
36
|
+
import Form from 'oneslash-design-system/components/form';
|
|
37
|
+
import Alert from 'oneslash-design-system/components/alert';
|
|
38
|
+
import TextField from 'oneslash-design-system/components/textField';
|
|
39
|
+
import Button from 'oneslash-design-system/components/button';
|
|
40
|
+
import Line from 'oneslash-design-system/components/line';
|
|
41
|
+
import BrandIcon from 'oneslash-design-system/components/brandIcon';
|
|
42
|
+
import LoadingScreen from 'oneslash-design-system/components/loadingScreen';
|
|
43
|
+
import { Center, Stack } from 'oneslash-design-system/components/layout';
|
|
44
|
+
|
|
45
|
+
// The product's mark. A real app passes its own file.
|
|
46
|
+
const productMark =
|
|
47
|
+
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E";
|
|
48
|
+
|
|
49
|
+
// A small check: some text, an @, then some text.
|
|
50
|
+
function looksLikeEmail(value: string) {
|
|
51
|
+
return /^[^@\s]+@[^@\s]+$/.test(value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default function DeviceLoginProviderFirst() {
|
|
55
|
+
const [email, setEmail] = useState('ada@example.com');
|
|
56
|
+
const [password, setPassword] = useState('');
|
|
57
|
+
const [error, setError] = useState('');
|
|
58
|
+
const [emailError, setEmailError] = useState('');
|
|
59
|
+
const [passwordError, setPasswordError] = useState('');
|
|
60
|
+
const [loading, setLoading] = useState(false);
|
|
61
|
+
// 'form', then 'waiting' for the device to answer, then 'done'.
|
|
62
|
+
const [step, setStep] = useState<'form' | 'waiting' | 'done'>('form');
|
|
63
|
+
const timer = useRef<ReturnType<typeof setTimeout>>();
|
|
64
|
+
|
|
65
|
+
// Stops the requests if the example goes away before they end.
|
|
66
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
67
|
+
|
|
68
|
+
function handleSubmit() {
|
|
69
|
+
if (loading) return;
|
|
70
|
+
setError('');
|
|
71
|
+
setEmailError('');
|
|
72
|
+
setPasswordError('');
|
|
73
|
+
if (!email.trim()) {
|
|
74
|
+
setEmailError('Enter your email.');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (!looksLikeEmail(email.trim())) {
|
|
78
|
+
setEmailError('Enter an email address, like name@example.com.');
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (!password) {
|
|
82
|
+
setPasswordError('Enter your password.');
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
setLoading(true);
|
|
86
|
+
// Stands in for the request to the server.
|
|
87
|
+
// A refused login calls setError instead: 'That email and password do not match.'
|
|
88
|
+
timer.current = setTimeout(() => {
|
|
89
|
+
setLoading(false);
|
|
90
|
+
setStep('waiting');
|
|
91
|
+
// Stands in for the request to the server.
|
|
92
|
+
// This one hands the login to Acme CLI and waits for it to answer that it has it.
|
|
93
|
+
// If it does not answer, go back to the form with setStep('form') and
|
|
94
|
+
// setError('Acme CLI did not answer. Make sure acme login is still running, then try again.').
|
|
95
|
+
timer.current = setTimeout(() => setStep('done'), 1200);
|
|
96
|
+
}, 1200);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Success shows only after the device has answered.
|
|
100
|
+
if (step === 'done') {
|
|
101
|
+
return (
|
|
102
|
+
<Center fill>
|
|
103
|
+
<Image src={productMark} alt="Acme" width={40} height={40} />
|
|
104
|
+
<Stack gap="medium">
|
|
105
|
+
<Heading level={1} size="h5">You're logged in</Heading>
|
|
106
|
+
<Paragraph tone="secondary" measure="none">You can close this tab.</Paragraph>
|
|
107
|
+
</Stack>
|
|
108
|
+
</Center>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (step === 'waiting') {
|
|
113
|
+
return (
|
|
114
|
+
<Center fill>
|
|
115
|
+
<LoadingScreen label="Waiting for Acme CLI…" />
|
|
116
|
+
</Center>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<Center fill>
|
|
122
|
+
<Image src={productMark} alt="Acme" width={40} height={40} />
|
|
123
|
+
<Stack gap="medium">
|
|
124
|
+
<Heading level={1} size="h5">Log in to Acme</Heading>
|
|
125
|
+
<Paragraph tone="secondary" measure="none">This connects Acme CLI on your computer to your account.</Paragraph>
|
|
126
|
+
</Stack>
|
|
127
|
+
{/* A real app sends the person to the provider, which brings them back to this page to hand the login to Acme CLI. */}
|
|
128
|
+
<Stack gap="medium">
|
|
129
|
+
<Button size="medium" type="secondary" state={loading ? 'disabled' : 'enabled'} label="Continue with Google" decoIcon={<BrandIcon name="google" />} />
|
|
130
|
+
<Button size="medium" type="secondary" state={loading ? 'disabled' : 'enabled'} label="Continue with GitHub" decoIcon={<BrandIcon name="github" />} />
|
|
131
|
+
</Stack>
|
|
132
|
+
<Line label="or" />
|
|
133
|
+
<Form aria-label="Log in with email" onSubmit={handleSubmit}>
|
|
134
|
+
{error && <Alert type="error" variant="inline" message={error} showCloseButton onClose={() => setError('')} />}
|
|
135
|
+
<TextField id="device-login-provider-first-email" label="Email" type="email" autoComplete="username" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />
|
|
136
|
+
<TextField id="device-login-provider-first-password" label="Password" type="password" autoComplete="current-password" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />
|
|
137
|
+
<Button size="medium" type="primary" state="enabled" label="Log In" htmlType="submit" loading={loading} />
|
|
138
|
+
<Button size="medium" type="textOnly" state="enabled" label="Forgot Password?" />
|
|
139
|
+
</Form>
|
|
140
|
+
</Center>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Option: Popup that closes itself
|
|
146
|
+
|
|
147
|
+
Use when: A page opened a popup for the login, and the popup closes once the page has the login.
|
|
148
|
+
|
|
149
|
+
Uses: `Center`, `LoadingScreen`
|
|
150
|
+
|
|
151
|
+
```tsx
|
|
152
|
+
'use client';
|
|
153
|
+
import LoadingScreen from 'oneslash-design-system/components/loadingScreen';
|
|
154
|
+
import { Center } from 'oneslash-design-system/components/layout';
|
|
155
|
+
|
|
156
|
+
// The page the provider sends the popup back to. It finishes the login, tells the page
|
|
157
|
+
// that opened it, and closes itself with window.close() once that page answers.
|
|
158
|
+
// It stays on this state: the login does not finish by itself.
|
|
159
|
+
// If the browser keeps the popup open after window.close(), the page shows one line
|
|
160
|
+
// in place of the spinner: 'Done. You can close this window.'
|
|
161
|
+
// If no page answers after about 2 seconds, the login ran in this tab, so the page finishes it here.
|
|
162
|
+
export default function DeviceLoginPopup() {
|
|
163
|
+
return (
|
|
164
|
+
<Center fill>
|
|
165
|
+
<LoadingScreen label="Finishing login…" />
|
|
166
|
+
</Center>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Seen in: Commentify, Scindo.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function EmailConfirmedAlertOnLogin(): import("react").JSX.Element;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import Image from '../../components/image';
|
|
4
|
+
import TabsContainer from '../../components/tabsContainer';
|
|
5
|
+
import Tab from '../../components/tab';
|
|
6
|
+
import Form from '../../components/form';
|
|
7
|
+
import Alert from '../../components/alert';
|
|
8
|
+
import TextField from '../../components/textField';
|
|
9
|
+
import Button from '../../components/button';
|
|
10
|
+
import Line from '../../components/line';
|
|
11
|
+
import BrandIcon from '../../components/brandIcon';
|
|
12
|
+
import { Center } from '../../components/layout';
|
|
13
|
+
// The product's mark. A real app passes its own file.
|
|
14
|
+
var productMark = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E";
|
|
15
|
+
// A real app passes the router from its framework, such as Next's useRouter().
|
|
16
|
+
var router = { push: function (url) { return console.info("Go to ".concat(url)); } };
|
|
17
|
+
// A small check: some text, an @, then some text.
|
|
18
|
+
function looksLikeEmail(value) {
|
|
19
|
+
return /^[^@\s]+@[^@\s]+$/.test(value);
|
|
20
|
+
}
|
|
21
|
+
export default function EmailConfirmedAlertOnLogin() {
|
|
22
|
+
// Opens as the login page does when the link was opened in another browser.
|
|
23
|
+
var _a = useState('Your email is confirmed. Log in to continue.'), notice = _a[0], setNotice = _a[1];
|
|
24
|
+
// This browser does not know the address yet, so the field starts empty.
|
|
25
|
+
var _b = useState(''), email = _b[0], setEmail = _b[1];
|
|
26
|
+
var _c = useState(''), password = _c[0], setPassword = _c[1];
|
|
27
|
+
var _d = useState(''), error = _d[0], setError = _d[1];
|
|
28
|
+
var _e = useState(''), emailError = _e[0], setEmailError = _e[1];
|
|
29
|
+
var _f = useState(''), passwordError = _f[0], setPasswordError = _f[1];
|
|
30
|
+
var _g = useState(false), loading = _g[0], setLoading = _g[1];
|
|
31
|
+
var timer = useRef();
|
|
32
|
+
// Stops the request if the example goes away before it ends.
|
|
33
|
+
useEffect(function () { return function () { return clearTimeout(timer.current); }; }, []);
|
|
34
|
+
function handleSubmit() {
|
|
35
|
+
if (loading)
|
|
36
|
+
return;
|
|
37
|
+
setNotice('');
|
|
38
|
+
setError('');
|
|
39
|
+
setEmailError('');
|
|
40
|
+
setPasswordError('');
|
|
41
|
+
if (!email.trim()) {
|
|
42
|
+
setEmailError('Enter your email.');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (!looksLikeEmail(email.trim())) {
|
|
46
|
+
setEmailError('Enter an email address, like name@example.com.');
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!password) {
|
|
50
|
+
setPasswordError('Enter your password.');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
setLoading(true);
|
|
54
|
+
// Stands in for the request to the server.
|
|
55
|
+
timer.current = setTimeout(function () {
|
|
56
|
+
setLoading(false);
|
|
57
|
+
setError('That email and password do not match.');
|
|
58
|
+
}, 1200);
|
|
59
|
+
}
|
|
60
|
+
return (<Center fill>
|
|
61
|
+
<Image src={productMark} alt="Acme" width={40} height={40}/>
|
|
62
|
+
<TabsContainer fill>
|
|
63
|
+
<Tab label="Log In" isSelected onClickTab={function () { }}/>
|
|
64
|
+
<Tab label="Sign Up" isSelected={false} href="/sign-up" router={router} onClickTab={function () { }}/>
|
|
65
|
+
</TabsContainer>
|
|
66
|
+
<Form aria-label="Log in" onSubmit={handleSubmit}>
|
|
67
|
+
{/* It says what to do next, so it stays until the person submits the form: no close button, and it does not close on its own. */}
|
|
68
|
+
{notice && <Alert type="success" variant="inline" message={notice} autoDismiss={false}/>}
|
|
69
|
+
{error && <Alert type="error" variant="inline" message={error} showCloseButton onClose={function () { return setError(''); }}/>}
|
|
70
|
+
<TextField id="email-confirmed-login-email" label="Email" type="email" autoComplete="username" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={function (e) { setEmail(e.target.value); setEmailError(''); }}/>
|
|
71
|
+
<TextField id="email-confirmed-login-password" label="Password" type="password" autoComplete="current-password" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} onChange={function (e) { setPassword(e.target.value); setPasswordError(''); }}/>
|
|
72
|
+
<Button size="medium" type="primary" state="enabled" label="Log In" htmlType="submit" loading={loading}/>
|
|
73
|
+
<Button size="medium" type="textOnly" state="enabled" label="Forgot Password?"/>
|
|
74
|
+
</Form>
|
|
75
|
+
<Line label="or"/>
|
|
76
|
+
<Button size="medium" type="secondary" state="enabled" label="Continue with Google" decoIcon={<BrandIcon name="google"/>}/>
|
|
77
|
+
</Center>);
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function EmailConfirmedPage(): import("react").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import Image from '../../components/image';
|
|
3
|
+
import Heading from '../../components/heading';
|
|
4
|
+
import Paragraph from '../../components/paragraph';
|
|
5
|
+
import Button from '../../components/button';
|
|
6
|
+
import { Center, Stack } from '../../components/layout';
|
|
7
|
+
// The product's mark. A real app passes its own file.
|
|
8
|
+
var productMark = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E";
|
|
9
|
+
// A real app passes the router from its framework, such as Next's useRouter().
|
|
10
|
+
var router = { push: function (url) { return console.info("Go to ".concat(url)); } };
|
|
11
|
+
export default function EmailConfirmedPage() {
|
|
12
|
+
return (<Center fill>
|
|
13
|
+
<Image src={productMark} alt="Acme" width={40} height={40}/>
|
|
14
|
+
<Stack gap="medium">
|
|
15
|
+
<Heading level={1} size="h5">Email confirmed</Heading>
|
|
16
|
+
<Paragraph tone="secondary" measure="none">You can close this tab and go back to Acme, or continue here.</Paragraph>
|
|
17
|
+
</Stack>
|
|
18
|
+
{/* A real app sends the person on to where they were going, such as an invite they opened before signing up. */}
|
|
19
|
+
<Button size="medium" type="primary" state="enabled" label="Continue" onClickButton={function () { return router.push('/'); }}/>
|
|
20
|
+
</Center>);
|
|
21
|
+
}
|