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,328 @@
|
|
|
1
|
+
# Forgot password
|
|
2
|
+
|
|
3
|
+
A person cannot remember their password and asks for a link to set a new one.
|
|
4
|
+
|
|
5
|
+
**Not built yet:** Commentify and Scindo on the web replace the form with a spinner while sending the link. Both then say 'We sent a password reset link to' the address, even when it has no account.
|
|
6
|
+
|
|
7
|
+
## Do
|
|
8
|
+
|
|
9
|
+
- Name the page 'Reset password' in a `Heading` with `level={1}`, and say in one line what happens next.
|
|
10
|
+
- Ask only for the email, and send it with 'Send Reset Link'.
|
|
11
|
+
- Put a text-only 'Back to Login' Button under the form. In place, keep the email typed so far when it goes back.
|
|
12
|
+
- Keep the email out of the URL when the reset form has its own page.
|
|
13
|
+
- Offer 'Send Again' on the confirmation, as on 'Check your email': `loading` while it sends, then 'Sent' for 2 seconds.
|
|
14
|
+
- Answer every address the same way: 'If ada@example.com has an Acme account, we sent it a link to reset the password.'
|
|
15
|
+
- Show a problem with the email under the field, and a failed request in an inline Alert above it.
|
|
16
|
+
- Show the loading state on the submit Button while sending, and keep the form in place.
|
|
17
|
+
|
|
18
|
+
## Don't
|
|
19
|
+
|
|
20
|
+
- Do not say whether an address has an account.
|
|
21
|
+
- Do not clear the email the person typed on the login form.
|
|
22
|
+
- Do not replace the form with a spinner while sending the link.
|
|
23
|
+
|
|
24
|
+
## Option: In place of the login form
|
|
25
|
+
|
|
26
|
+
Use when: The person chose 'Forgot Password?' on the login page. The login form swaps to the reset form and keeps the email typed so far.
|
|
27
|
+
|
|
28
|
+
Uses: `Alert`, `BrandIcon`, `Button`, `Center`, `Form`, `Heading`, `Icon`, `Image`, `Line`, `Paragraph`, `Stack`, `Tab`, `TabsContainer`, `TextField`
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
'use client';
|
|
32
|
+
import { useEffect, useRef, useState } from 'react';
|
|
33
|
+
import { Mail } from 'lucide-react';
|
|
34
|
+
import Image from 'oneslash-design-system/components/image';
|
|
35
|
+
import TabsContainer from 'oneslash-design-system/components/tabsContainer';
|
|
36
|
+
import Tab from 'oneslash-design-system/components/tab';
|
|
37
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
38
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
39
|
+
import Icon from 'oneslash-design-system/components/icon';
|
|
40
|
+
import Form from 'oneslash-design-system/components/form';
|
|
41
|
+
import Alert from 'oneslash-design-system/components/alert';
|
|
42
|
+
import TextField from 'oneslash-design-system/components/textField';
|
|
43
|
+
import Button from 'oneslash-design-system/components/button';
|
|
44
|
+
import Line from 'oneslash-design-system/components/line';
|
|
45
|
+
import BrandIcon from 'oneslash-design-system/components/brandIcon';
|
|
46
|
+
import { Center, Stack } from 'oneslash-design-system/components/layout';
|
|
47
|
+
|
|
48
|
+
// The product's mark. A real app passes its own file.
|
|
49
|
+
const productMark =
|
|
50
|
+
"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";
|
|
51
|
+
|
|
52
|
+
// A real app passes the router from its framework, such as Next's useRouter().
|
|
53
|
+
const router = { push: (url: string) => console.info(`Go to ${url}`) };
|
|
54
|
+
|
|
55
|
+
// A small check: some text, an @, then some text.
|
|
56
|
+
function looksLikeEmail(value: string) {
|
|
57
|
+
return /^[^@\s]+@[^@\s]+$/.test(value);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default function ForgotPasswordInPlace() {
|
|
61
|
+
// Opens on the reset form, as if the person typed their email on the login form and then chose 'Forgot Password?'.
|
|
62
|
+
const [view, setView] = useState<'login' | 'reset' | 'sent'>('reset');
|
|
63
|
+
const [email, setEmail] = useState('ada@example.com');
|
|
64
|
+
const [password, setPassword] = useState('');
|
|
65
|
+
const [error, setError] = useState('');
|
|
66
|
+
const [emailError, setEmailError] = useState('');
|
|
67
|
+
const [passwordError, setPasswordError] = useState('');
|
|
68
|
+
const [loading, setLoading] = useState(false);
|
|
69
|
+
const [resending, setResending] = useState(false);
|
|
70
|
+
const [resent, setResent] = useState(false);
|
|
71
|
+
const timer = useRef<ReturnType<typeof setTimeout>>();
|
|
72
|
+
|
|
73
|
+
// Stops the request if the example goes away before it ends.
|
|
74
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
75
|
+
|
|
76
|
+
// 'Sent' shows for 2 seconds, then the Button reads 'Send Again'.
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (!resent) return;
|
|
79
|
+
const timer = setTimeout(() => setResent(false), 2000);
|
|
80
|
+
return () => clearTimeout(timer);
|
|
81
|
+
}, [resent]);
|
|
82
|
+
|
|
83
|
+
// Moves between the login form, the reset form and the confirmation. The email stays as typed.
|
|
84
|
+
function showView(next: 'login' | 'reset' | 'sent') {
|
|
85
|
+
setError('');
|
|
86
|
+
setEmailError('');
|
|
87
|
+
setPasswordError('');
|
|
88
|
+
setView(next);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function handleLogIn() {
|
|
92
|
+
if (loading) return;
|
|
93
|
+
setError('');
|
|
94
|
+
setEmailError('');
|
|
95
|
+
setPasswordError('');
|
|
96
|
+
if (!email.trim()) {
|
|
97
|
+
setEmailError('Enter your email.');
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (!looksLikeEmail(email.trim())) {
|
|
101
|
+
setEmailError('Enter an email address, like name@example.com.');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (!password) {
|
|
105
|
+
setPasswordError('Enter your password.');
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
setLoading(true);
|
|
109
|
+
// Stands in for the request to the server.
|
|
110
|
+
timer.current = setTimeout(() => {
|
|
111
|
+
setLoading(false);
|
|
112
|
+
setError('That email and password do not match.');
|
|
113
|
+
}, 1200);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function handleSendLink() {
|
|
117
|
+
if (loading) return;
|
|
118
|
+
setError('');
|
|
119
|
+
setEmailError('');
|
|
120
|
+
if (!email.trim()) {
|
|
121
|
+
setEmailError('Enter your email.');
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (!looksLikeEmail(email.trim())) {
|
|
125
|
+
setEmailError('Enter an email address, like name@example.com.');
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
setLoading(true);
|
|
129
|
+
// Stands in for the request to the server.
|
|
130
|
+
// A failed request calls setError with one sentence instead, such as 'The link was not sent. Try again.'
|
|
131
|
+
timer.current = setTimeout(() => {
|
|
132
|
+
setLoading(false);
|
|
133
|
+
// Every address gets the same confirmation, so the page never says whether it has an account.
|
|
134
|
+
showView('sent');
|
|
135
|
+
}, 1200);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function handleSendAgain() {
|
|
139
|
+
// One click sends one email: clicks while it sends or reads 'Sent' do nothing.
|
|
140
|
+
if (resending || resent) return;
|
|
141
|
+
setResending(true);
|
|
142
|
+
// Stands in for the request to the server.
|
|
143
|
+
timer.current = setTimeout(() => {
|
|
144
|
+
setResending(false);
|
|
145
|
+
setResent(true);
|
|
146
|
+
}, 1200);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (view === 'sent') {
|
|
150
|
+
return (
|
|
151
|
+
<Center fill>
|
|
152
|
+
<Icon icon={Mail} size="large" color="secondary" />
|
|
153
|
+
<Stack gap="medium">
|
|
154
|
+
<Heading level={1} size="h5">Check your email</Heading>
|
|
155
|
+
<Paragraph tone="secondary" measure="none">If {email.trim()} has an Acme account, we sent it a link to reset the password.</Paragraph>
|
|
156
|
+
</Stack>
|
|
157
|
+
<Stack gap="large">
|
|
158
|
+
<Button size="medium" type="secondary" state="enabled" label={resent ? 'Sent' : 'Send Again'} loading={resending} onClickButton={handleSendAgain} />
|
|
159
|
+
<Button size="medium" type="textOnly" state="enabled" label="Back to Login" onClickButton={() => showView('login')} />
|
|
160
|
+
</Stack>
|
|
161
|
+
</Center>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (view === 'reset') {
|
|
166
|
+
return (
|
|
167
|
+
<Center fill>
|
|
168
|
+
<Image src={productMark} alt="Acme" width={40} height={40} />
|
|
169
|
+
<Stack gap="medium">
|
|
170
|
+
<Heading level={1} size="h5">Reset password</Heading>
|
|
171
|
+
<Paragraph tone="secondary" measure="none">Enter your email and we will send you a link to set a new password.</Paragraph>
|
|
172
|
+
</Stack>
|
|
173
|
+
<Form aria-label="Reset password" onSubmit={handleSendLink}>
|
|
174
|
+
{error && <Alert type="error" variant="inline" message={error} showCloseButton onClose={() => setError('')} />}
|
|
175
|
+
<TextField id="forgot-password-in-place-reset-email" label="Email" type="email" autoComplete="username" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />
|
|
176
|
+
<Button size="medium" type="primary" state="enabled" label="Send Reset Link" htmlType="submit" loading={loading} />
|
|
177
|
+
<Button size="medium" type="textOnly" state={loading ? 'disabled' : 'enabled'} label="Back to Login" onClickButton={() => showView('login')} />
|
|
178
|
+
</Form>
|
|
179
|
+
</Center>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<Center fill>
|
|
185
|
+
<Image src={productMark} alt="Acme" width={40} height={40} />
|
|
186
|
+
<TabsContainer fill>
|
|
187
|
+
<Tab label="Log In" isSelected onClickTab={() => {}} />
|
|
188
|
+
<Tab label="Sign Up" isSelected={false} href="/sign-up" router={router} onClickTab={() => {}} />
|
|
189
|
+
</TabsContainer>
|
|
190
|
+
<Form aria-label="Log in" onSubmit={handleLogIn}>
|
|
191
|
+
{error && <Alert type="error" variant="inline" message={error} showCloseButton onClose={() => setError('')} />}
|
|
192
|
+
<TextField id="forgot-password-in-place-login-email" label="Email" type="email" autoComplete="username" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />
|
|
193
|
+
<TextField id="forgot-password-in-place-login-password" label="Password" type="password" autoComplete="current-password" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />
|
|
194
|
+
<Button size="medium" type="primary" state="enabled" label="Log In" htmlType="submit" loading={loading} />
|
|
195
|
+
<Button size="medium" type="textOnly" state={loading ? 'disabled' : 'enabled'} label="Forgot Password?" onClickButton={() => showView('reset')} />
|
|
196
|
+
</Form>
|
|
197
|
+
<Line label="or" />
|
|
198
|
+
<Button size="medium" type="secondary" state="enabled" label="Continue with Google" decoIcon={<BrandIcon name="google" />} />
|
|
199
|
+
</Center>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Option: Its own page
|
|
205
|
+
|
|
206
|
+
Use when: The person comes from a link in an email or another app.
|
|
207
|
+
|
|
208
|
+
Uses: `Alert`, `Button`, `Center`, `Form`, `Heading`, `Icon`, `Image`, `Paragraph`, `Stack`, `TextField`
|
|
209
|
+
|
|
210
|
+
```tsx
|
|
211
|
+
'use client';
|
|
212
|
+
import { useEffect, useRef, useState } from 'react';
|
|
213
|
+
import { Mail } from 'lucide-react';
|
|
214
|
+
import Image from 'oneslash-design-system/components/image';
|
|
215
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
216
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
217
|
+
import Icon from 'oneslash-design-system/components/icon';
|
|
218
|
+
import Form from 'oneslash-design-system/components/form';
|
|
219
|
+
import Alert from 'oneslash-design-system/components/alert';
|
|
220
|
+
import TextField from 'oneslash-design-system/components/textField';
|
|
221
|
+
import Button from 'oneslash-design-system/components/button';
|
|
222
|
+
import { Center, Stack } from 'oneslash-design-system/components/layout';
|
|
223
|
+
|
|
224
|
+
// The product's mark. A real app passes its own file.
|
|
225
|
+
const productMark =
|
|
226
|
+
"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";
|
|
227
|
+
|
|
228
|
+
// A real app passes the router from its framework, such as Next's useRouter().
|
|
229
|
+
const router = { push: (url: string) => console.info(`Go to ${url}`) };
|
|
230
|
+
|
|
231
|
+
// A small check: some text, an @, then some text.
|
|
232
|
+
function looksLikeEmail(value: string) {
|
|
233
|
+
return /^[^@\s]+@[^@\s]+$/.test(value);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export default function ForgotPasswordOwnPage() {
|
|
237
|
+
const [email, setEmail] = useState('');
|
|
238
|
+
const [sentTo, setSentTo] = useState('');
|
|
239
|
+
const [error, setError] = useState('');
|
|
240
|
+
const [emailError, setEmailError] = useState('');
|
|
241
|
+
const [loading, setLoading] = useState(false);
|
|
242
|
+
const [resending, setResending] = useState(false);
|
|
243
|
+
const [resent, setResent] = useState(false);
|
|
244
|
+
const timer = useRef<ReturnType<typeof setTimeout>>();
|
|
245
|
+
|
|
246
|
+
// Stops the request if the example goes away before it ends.
|
|
247
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
248
|
+
|
|
249
|
+
// 'Sent' shows for 2 seconds, then the Button reads 'Send Again'.
|
|
250
|
+
useEffect(() => {
|
|
251
|
+
if (!resent) return;
|
|
252
|
+
const timer = setTimeout(() => setResent(false), 2000);
|
|
253
|
+
return () => clearTimeout(timer);
|
|
254
|
+
}, [resent]);
|
|
255
|
+
|
|
256
|
+
function handleSubmit() {
|
|
257
|
+
if (loading) return;
|
|
258
|
+
setError('');
|
|
259
|
+
setEmailError('');
|
|
260
|
+
if (!email.trim()) {
|
|
261
|
+
setEmailError('Enter your email.');
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
if (!looksLikeEmail(email.trim())) {
|
|
265
|
+
setEmailError('Enter an email address, like name@example.com.');
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
setLoading(true);
|
|
269
|
+
const address = email.trim();
|
|
270
|
+
// Stands in for the request to the server.
|
|
271
|
+
// A failed request calls setError with one sentence instead, such as 'The link was not sent. Try again.'
|
|
272
|
+
timer.current = setTimeout(() => {
|
|
273
|
+
setLoading(false);
|
|
274
|
+
// Every address gets the same confirmation, so the page never says whether it has an account.
|
|
275
|
+
setSentTo(address);
|
|
276
|
+
}, 1200);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function handleSendAgain() {
|
|
280
|
+
// One click sends one email: clicks while it sends or reads 'Sent' do nothing.
|
|
281
|
+
if (resending || resent) return;
|
|
282
|
+
setResending(true);
|
|
283
|
+
// Stands in for the request to the server.
|
|
284
|
+
timer.current = setTimeout(() => {
|
|
285
|
+
setResending(false);
|
|
286
|
+
setResent(true);
|
|
287
|
+
}, 1200);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (sentTo) {
|
|
291
|
+
return (
|
|
292
|
+
<Center fill>
|
|
293
|
+
<Icon icon={Mail} size="large" color="secondary" />
|
|
294
|
+
<Stack gap="medium">
|
|
295
|
+
<Heading level={1} size="h5">Check your email</Heading>
|
|
296
|
+
<Paragraph tone="secondary" measure="none">If {sentTo} has an Acme account, we sent it a link to reset the password.</Paragraph>
|
|
297
|
+
</Stack>
|
|
298
|
+
<Stack gap="large">
|
|
299
|
+
<Button size="medium" type="secondary" state="enabled" label={resent ? 'Sent' : 'Send Again'} loading={resending} onClickButton={handleSendAgain} />
|
|
300
|
+
<Button size="medium" type="textOnly" state="enabled" label="Back to Login" onClickButton={() => router.push('/login')} />
|
|
301
|
+
</Stack>
|
|
302
|
+
</Center>
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return (
|
|
307
|
+
<Center fill>
|
|
308
|
+
<Image src={productMark} alt="Acme" width={40} height={40} />
|
|
309
|
+
<Stack gap="medium">
|
|
310
|
+
<Heading level={1} size="h5">Reset password</Heading>
|
|
311
|
+
<Paragraph tone="secondary" measure="none">Enter your email and we will send you a link to set a new password.</Paragraph>
|
|
312
|
+
</Stack>
|
|
313
|
+
<Form aria-label="Reset password" onSubmit={handleSubmit}>
|
|
314
|
+
{error && <Alert type="error" variant="inline" message={error} showCloseButton onClose={() => setError('')} />}
|
|
315
|
+
<TextField id="forgot-password-own-page-email" label="Email" type="email" autoComplete="username" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />
|
|
316
|
+
<Button size="medium" type="primary" state="enabled" label="Send Reset Link" htmlType="submit" loading={loading} />
|
|
317
|
+
<Button size="medium" type="textOnly" state={loading ? 'disabled' : 'enabled'} label="Back to Login" onClickButton={() => router.push('/login')} />
|
|
318
|
+
</Form>
|
|
319
|
+
</Center>
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## Native
|
|
325
|
+
|
|
326
|
+
On Apple, put 'Forgot Password?' under the 'Log In' Button and open the web reset form from it.
|
|
327
|
+
|
|
328
|
+
Seen in: Commentify, Scindo.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# A form error shows next to the problem
|
|
2
|
+
|
|
3
|
+
A form was submitted and something is wrong.
|
|
4
|
+
|
|
5
|
+
## Answer
|
|
6
|
+
|
|
7
|
+
A problem with one field shows under that field, through the field's `error` and `errorText`. A problem with the whole request shows above the fields in `<Alert type="error" variant="inline" showCloseButton>`, so it stays until the person closes it or submits again. Its `onClose` clears the message; if it does not, the Alert comes back. While the request runs, the submit Button is `loading` and keeps its label. The form keeps what the person typed. The next submit clears the old messages. Messages are in sentence case. It is never a colored caption written by hand, and never the browser's `alert()`.
|
|
8
|
+
|
|
9
|
+
**Not built yet:** Commentify writes red captions by hand on its consent screen and in its Figma import dialog. Scindo on the web does the same in its dialogs, such as renaming a workspace or a task. Commentify uses the browser's `alert()` in three files, and Scindo on the web in one.
|
|
10
|
+
|
|
11
|
+
## Why
|
|
12
|
+
|
|
13
|
+
A message next to the problem tells the person what to fix without searching for it. Keeping what they typed means they fix one thing instead of starting again.
|
|
14
|
+
|
|
15
|
+
## Do
|
|
16
|
+
|
|
17
|
+
- Show a problem with one field under that field, with `error` and `errorText`.
|
|
18
|
+
- Say what to do, not only what is wrong: 'Enter an email address, like name@example.com.'
|
|
19
|
+
- Show a problem with the whole request above the fields in `<Alert type="error" variant="inline" showCloseButton>`.
|
|
20
|
+
- Clear the message in the Alert's `onClose`.
|
|
21
|
+
- Keep everything the person typed after a failed submit.
|
|
22
|
+
- Clear the old messages when the person submits again.
|
|
23
|
+
|
|
24
|
+
## Don't
|
|
25
|
+
|
|
26
|
+
- Do not leave out `variant="inline"`: the default variant is a toast at the top of the screen, away from the form.
|
|
27
|
+
- Do not write a red caption by hand. Use `errorText` or an Alert.
|
|
28
|
+
- Do not use the browser's `alert()`.
|
|
29
|
+
- Do not clear the form after a failed submit.
|
|
30
|
+
- Do not change the submit Button's label while it is loading, such as to 'Saving…'.
|
|
31
|
+
|
|
32
|
+
Seen in: Commentify, Scindo, jinhwankim.com.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function ImportChecklistModal(): import("react").JSX.Element;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
import { useEffect, useRef, useState } from 'react';
|
|
12
|
+
import Modal from '../../components/modal';
|
|
13
|
+
import Surface from '../../components/surface';
|
|
14
|
+
import Heading from '../../components/heading';
|
|
15
|
+
import Paragraph from '../../components/paragraph';
|
|
16
|
+
import List from '../../components/list';
|
|
17
|
+
import TextField from '../../components/textField';
|
|
18
|
+
import Checkbox from '../../components/checkBox';
|
|
19
|
+
import EmptyBox from '../../components/emptyBox';
|
|
20
|
+
import Button from '../../components/button';
|
|
21
|
+
import { Center, Cluster, Stack } from '../../components/layout';
|
|
22
|
+
// Pages in the other place. A real app loads them when the Modal opens.
|
|
23
|
+
var wikiPages = [
|
|
24
|
+
{ id: 'p1', title: 'Launch checklist', edited: 'Edited 2 days ago' },
|
|
25
|
+
{ id: 'p2', title: 'Launch email draft', edited: 'Edited 3 days ago' },
|
|
26
|
+
{ id: 'p3', title: 'Brand voice', edited: 'Edited last week' },
|
|
27
|
+
{ id: 'p4', title: 'Pricing notes', edited: 'Edited last week' },
|
|
28
|
+
{ id: 'p5', title: 'Hiring plan', edited: 'Edited 2 weeks ago' },
|
|
29
|
+
{ id: 'p6', title: 'Office move', edited: 'Edited last month' },
|
|
30
|
+
{ id: 'p7', title: 'Onboarding guide', edited: 'Edited last month' },
|
|
31
|
+
{ id: 'p8', title: 'Team rituals', edited: 'Edited 2 months ago' },
|
|
32
|
+
];
|
|
33
|
+
var plural = function (n) { return (n === 1 ? 'Page' : 'Pages'); };
|
|
34
|
+
export default function ImportChecklistModal() {
|
|
35
|
+
var _a = useState(['Q3 plan', 'Meeting notes']), docs = _a[0], setDocs = _a[1];
|
|
36
|
+
var _b = useState([]), imported = _b[0], setImported = _b[1];
|
|
37
|
+
// Opens on the Modal with three pages picked, as if the person just chose Import Pages.
|
|
38
|
+
var _c = useState(true), open = _c[0], setOpen = _c[1];
|
|
39
|
+
var _d = useState(''), query = _d[0], setQuery = _d[1];
|
|
40
|
+
var _e = useState(['p1', 'p2', 'p4']), selected = _e[0], setSelected = _e[1];
|
|
41
|
+
var _f = useState(false), importing = _f[0], setImporting = _f[1];
|
|
42
|
+
// Bumped by 'Clear Search'. It remounts the search field with `autoFocus`, so focus goes
|
|
43
|
+
// back to the field instead of being lost with the Button that the list replaces.
|
|
44
|
+
var _g = useState(0), searchKey = _g[0], setSearchKey = _g[1];
|
|
45
|
+
var timer = useRef();
|
|
46
|
+
// Stops the request if the example goes away before it ends.
|
|
47
|
+
useEffect(function () { return function () { return clearTimeout(timer.current); }; }, []);
|
|
48
|
+
var available = wikiPages.filter(function (p) { return !imported.includes(p.id); });
|
|
49
|
+
var words = query.trim();
|
|
50
|
+
var shown = available.filter(function (p) { return p.title.toLowerCase().includes(words.toLowerCase()); });
|
|
51
|
+
var shownIds = shown.map(function (p) { return p.id; });
|
|
52
|
+
var count = selected.length;
|
|
53
|
+
// While a search is on, the labels say that they act only on the pages shown.
|
|
54
|
+
var searching = words !== '';
|
|
55
|
+
function toggle(id, checked) {
|
|
56
|
+
setSelected(function (list) { return (checked ? __spreadArray(__spreadArray([], list, true), [id], false) : list.filter(function (x) { return x !== id; })); });
|
|
57
|
+
}
|
|
58
|
+
// Both act on the pages shown. Pages the search hides keep their selection.
|
|
59
|
+
function selectShown() {
|
|
60
|
+
setSelected(function (list) { return __spreadArray(__spreadArray([], list, true), shownIds.filter(function (id) { return !list.includes(id); }), true); });
|
|
61
|
+
}
|
|
62
|
+
function clearShown() {
|
|
63
|
+
setSelected(function (list) { return list.filter(function (id) { return !shownIds.includes(id); }); });
|
|
64
|
+
}
|
|
65
|
+
function clearSearch() {
|
|
66
|
+
setQuery('');
|
|
67
|
+
setSearchKey(function (k) { return k + 1; });
|
|
68
|
+
}
|
|
69
|
+
function handleOpen() {
|
|
70
|
+
setQuery('');
|
|
71
|
+
setSelected([]);
|
|
72
|
+
setOpen(true);
|
|
73
|
+
}
|
|
74
|
+
// Escape, a click outside and Cancel all close it, except while the request runs.
|
|
75
|
+
function handleClose() {
|
|
76
|
+
if (importing)
|
|
77
|
+
return;
|
|
78
|
+
setOpen(false);
|
|
79
|
+
}
|
|
80
|
+
function handleImport() {
|
|
81
|
+
if (importing || count === 0)
|
|
82
|
+
return;
|
|
83
|
+
setImporting(true);
|
|
84
|
+
// Stands in for the request to the server.
|
|
85
|
+
timer.current = setTimeout(function () {
|
|
86
|
+
setImporting(false);
|
|
87
|
+
setDocs(function (list) { return __spreadArray(__spreadArray([], wikiPages.filter(function (p) { return selected.includes(p.id); }).map(function (p) { return p.title; }), true), list, true); });
|
|
88
|
+
setImported(function (list) { return __spreadArray(__spreadArray([], list, true), selected, true); });
|
|
89
|
+
setSelected([]);
|
|
90
|
+
setOpen(false);
|
|
91
|
+
}, 1200);
|
|
92
|
+
}
|
|
93
|
+
return (<Center width="page">
|
|
94
|
+
<Stack gap="large">
|
|
95
|
+
<Cluster>
|
|
96
|
+
<Heading level={1} size="h5">Docs</Heading>
|
|
97
|
+
<Button size="small" type="secondary" state="enabled" label="Import Pages" decoIcon="Download" onClickButton={handleOpen}/>
|
|
98
|
+
</Cluster>
|
|
99
|
+
{/* The imported pages show at the top of the list, so no toast is needed. */}
|
|
100
|
+
<Surface padding="large">
|
|
101
|
+
<List items={docs} size="body1"/>
|
|
102
|
+
</Surface>
|
|
103
|
+
</Stack>
|
|
104
|
+
<Modal isOpen={open} size="medium" initialFocus="body" title="Import Pages" secondTitle="From the Acme wiki" onClose={handleClose} actions={<>
|
|
105
|
+
<Button size="small" type="tertiary" state={importing ? 'disabled' : 'enabled'} label="Cancel" onClickButton={handleClose}/>
|
|
106
|
+
<Button size="small" type="primary" state={count === 0 ? 'disabled' : 'enabled'} label={count === 0 ? 'Import Pages' : "Import ".concat(count, " ").concat(plural(count))} loading={importing} onClickButton={handleImport}/>
|
|
107
|
+
</>}>
|
|
108
|
+
{available.length === 0 ? (<EmptyBox size="small" icon="FileCheck" text="No pages left to import" secondText="Every page in the Acme wiki is already in Docs."/>) : (<>
|
|
109
|
+
<TextField key={searchKey} autoFocus={searchKey > 0} id="import-checklist-search" label="Search pages" type="search" value={query} disabled={importing} onChange={function (e) { return setQuery(e.target.value); }}/>
|
|
110
|
+
<Stack gap="small">
|
|
111
|
+
<Paragraph tone="secondary" size="body2" measure="none">
|
|
112
|
+
{count} of {available.length} pages selected.{words && " ".concat(shown.length, " match \"").concat(words, "\".")}
|
|
113
|
+
</Paragraph>
|
|
114
|
+
<Cluster gap="small">
|
|
115
|
+
<Button size="small" type="tertiary" state={importing || shown.length === 0 ? 'disabled' : 'enabled'} label={searching ? 'Select Shown' : 'Select All'} onClickButton={selectShown}/>
|
|
116
|
+
<Button size="small" type="tertiary" state={importing || shown.length === 0 ? 'disabled' : 'enabled'} label={searching ? 'Clear Shown' : 'Clear'} onClickButton={clearShown}/>
|
|
117
|
+
</Cluster>
|
|
118
|
+
</Stack>
|
|
119
|
+
{shown.length > 0 ? (<Stack gap="medium">
|
|
120
|
+
{shown.map(function (p) { return (<Checkbox key={p.id} label={p.title} secondLabel={p.edited} checked={selected.includes(p.id)} disabled={importing} onChange={function (checked) { return toggle(p.id, checked); }}/>); })}
|
|
121
|
+
</Stack>) : (<EmptyBox size="small" icon="Search" text={"No pages match \"".concat(words, "\"")} secondText="Check the spelling, or search for fewer words." action={<Button size="small" type="secondary" state="enabled" label="Clear Search" onClickButton={clearSearch}/>}/>)}
|
|
122
|
+
</>)}
|
|
123
|
+
</Modal>
|
|
124
|
+
</Center>);
|
|
125
|
+
}
|