oneslash-design-system 2.15.0 → 2.17.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 +6 -1
- package/dist/DESIGN.md +100 -73
- 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 +1 -1
- package/dist/cases/agent-cancels-when-unanswered.md +1 -1
- package/dist/cases/agent-options/cards.d.ts +1 -0
- package/dist/cases/agent-options/cards.jsx +91 -0
- package/dist/cases/agent-options.md +168 -0
- package/dist/cases/agent-pending-reply/steps.d.ts +1 -0
- package/dist/cases/agent-pending-reply/steps.jsx +149 -0
- package/dist/cases/agent-pending-reply/streaming.d.ts +1 -0
- package/dist/cases/agent-pending-reply/streaming.jsx +146 -0
- package/dist/cases/agent-pending-reply.md +432 -0
- package/dist/cases/agent-plan-proposal/changes.d.ts +1 -0
- package/dist/cases/agent-plan-proposal/changes.jsx +224 -0
- package/dist/cases/agent-plan-proposal/steps.d.ts +1 -0
- package/dist/cases/agent-plan-proposal/steps.jsx +211 -0
- package/dist/cases/agent-plan-proposal.md +656 -0
- package/dist/cases/agent-question/choices.d.ts +1 -0
- package/dist/cases/agent-question/choices.jsx +132 -0
- package/dist/cases/agent-question/free-text.d.ts +1 -0
- package/dist/cases/agent-question/free-text.jsx +81 -0
- package/dist/cases/agent-question.md +338 -0
- package/dist/cases/agent-shows-sources.md +2 -2
- package/dist/cases/artifact-card/card.d.ts +1 -0
- package/dist/cases/artifact-card/card.jsx +45 -0
- package/dist/cases/artifact-card.md +103 -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/composer-limit/notice-with-action.d.ts +1 -0
- package/dist/cases/composer-limit/notice-with-action.jsx +87 -0
- package/dist/cases/composer-limit/notice.d.ts +1 -0
- package/dist/cases/composer-limit/notice.jsx +84 -0
- package/dist/cases/composer-limit.md +286 -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/conversation-starters/chips.d.ts +1 -0
- package/dist/cases/conversation-starters/chips.jsx +69 -0
- package/dist/cases/conversation-starters/none.d.ts +1 -0
- package/dist/cases/conversation-starters/none.jsx +45 -0
- package/dist/cases/conversation-starters.md +208 -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.jsx +10 -7
- package/dist/cases/login-page/email-only.jsx +11 -8
- package/dist/cases/login-page/provider-first.jsx +12 -9
- package/dist/cases/login-page/split.jsx +11 -8
- package/dist/cases/login-page.md +58 -41
- package/dist/cases/mention-list/in-composer.d.ts +1 -0
- package/dist/cases/mention-list/in-composer.jsx +169 -0
- package/dist/cases/mention-list.md +252 -0
- package/dist/cases/message-actions/hover-toolbar.d.ts +1 -0
- package/dist/cases/message-actions/hover-toolbar.jsx +229 -0
- package/dist/cases/message-actions/menu.d.ts +1 -0
- package/dist/cases/message-actions/menu.jsx +258 -0
- package/dist/cases/message-actions.md +651 -0
- package/dist/cases/message-attachments/in-composer.d.ts +1 -0
- package/dist/cases/message-attachments/in-composer.jsx +134 -0
- package/dist/cases/message-attachments/in-message.d.ts +1 -0
- package/dist/cases/message-attachments/in-message.jsx +46 -0
- package/dist/cases/message-attachments.md +310 -0
- package/dist/cases/message-composer/plain.d.ts +1 -0
- package/dist/cases/message-composer/plain.jsx +57 -0
- package/dist/cases/message-composer/with-tools.d.ts +1 -0
- package/dist/cases/message-composer/with-tools.jsx +182 -0
- package/dist/cases/message-composer.md +356 -0
- package/dist/cases/message-edit/in-place.d.ts +1 -0
- package/dist/cases/message-edit/in-place.jsx +99 -0
- package/dist/cases/message-edit.md +179 -0
- package/dist/cases/message-reactions/chips.d.ts +1 -0
- package/dist/cases/message-reactions/chips.jsx +118 -0
- package/dist/cases/message-reactions/quick-pick.d.ts +1 -0
- package/dist/cases/message-reactions/quick-pick.jsx +155 -0
- package/dist/cases/message-reactions.md +371 -0
- package/dist/cases/message-row/grouped.d.ts +1 -0
- package/dist/cases/message-row/grouped.jsx +56 -0
- package/dist/cases/message-row/person-and-agent.d.ts +1 -0
- package/dist/cases/message-row/person-and-agent.jsx +41 -0
- package/dist/cases/message-row.md +189 -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/reply-feedback/thumbs.d.ts +1 -0
- package/dist/cases/reply-feedback/thumbs.jsx +191 -0
- package/dist/cases/reply-feedback/with-reason.d.ts +1 -0
- package/dist/cases/reply-feedback/with-reason.jsx +221 -0
- package/dist/cases/reply-feedback.md +552 -0
- package/dist/cases/reply-sources/cards.d.ts +1 -0
- package/dist/cases/reply-sources/cards.jsx +83 -0
- package/dist/cases/reply-sources/tag-only.d.ts +1 -0
- package/dist/cases/reply-sources/tag-only.jsx +45 -0
- package/dist/cases/reply-sources.md +247 -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/slash-command-list/in-composer.d.ts +1 -0
- package/dist/cases/slash-command-list/in-composer.jsx +162 -0
- package/dist/cases/slash-command-list.md +247 -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/typing-and-status/line.d.ts +1 -0
- package/dist/cases/typing-and-status/line.jsx +50 -0
- package/dist/cases/typing-and-status.md +96 -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 +3138 -59
- package/dist/components/alert.d.ts +3 -1
- package/dist/components/alert.jsx +6 -4
- package/dist/components/button.d.ts +3 -2
- package/dist/components/button.jsx +9 -7
- package/dist/components/composer.d.ts +74 -0
- package/dist/components/composer.jsx +122 -0
- package/dist/components/emptyBox.d.ts +6 -1
- package/dist/components/emptyBox.jsx +4 -2
- package/dist/components/fileChip.d.ts +33 -0
- package/dist/components/fileChip.jsx +61 -0
- package/dist/components/heading.d.ts +2 -2
- package/dist/components/iconButton.d.ts +3 -3
- package/dist/components/iconButton.jsx +9 -7
- package/dist/components/layout.d.ts +7 -1
- package/dist/components/layout.jsx +5 -2
- package/dist/components/loadingScreen.d.ts +5 -1
- package/dist/components/loadingScreen.jsx +4 -2
- package/dist/components/menu.d.ts +21 -0
- package/dist/components/menu.jsx +27 -3
- package/dist/components/menuItem.d.ts +9 -1
- package/dist/components/menuItem.jsx +5 -4
- package/dist/components/message.d.ts +28 -0
- package/dist/components/message.jsx +25 -0
- package/dist/components/modal.d.ts +2 -1
- package/dist/components/modal.jsx +20 -8
- package/dist/components/paragraph.d.ts +3 -1
- package/dist/components/paragraph.jsx +2 -2
- package/dist/components/popover.d.ts +7 -1
- package/dist/components/popover.jsx +35 -9
- package/dist/components/radioGroup.d.ts +9 -1
- package/dist/components/radioGroup.jsx +20 -9
- package/dist/components/select.d.ts +2 -1
- package/dist/components/select.jsx +4 -2
- package/dist/components/sourceCard.d.ts +23 -0
- package/dist/components/sourceCard.jsx +56 -0
- package/dist/components/stepList.d.ts +17 -0
- package/dist/components/stepList.jsx +79 -0
- package/dist/components/tab.jsx +3 -2
- package/dist/components/tabsContainer.d.ts +4 -1
- package/dist/components/tabsContainer.jsx +7 -3
- package/dist/components/tag.d.ts +9 -1
- package/dist/components/tag.jsx +6 -4
- package/dist/components/textField.d.ts +5 -1
- package/dist/components/textField.jsx +7 -3
- package/dist/components/textarea.jsx +3 -18
- package/dist/components/toaster.d.ts +12 -0
- package/dist/components/toaster.jsx +103 -0
- package/dist/components/userImage.d.ts +9 -1
- package/dist/components/userImage.jsx +10 -3
- package/dist/internal/alert.d.ts +4 -0
- package/dist/internal/alert.js +6 -0
- package/dist/internal/autoGrow.d.ts +11 -0
- package/dist/internal/autoGrow.js +28 -0
- package/dist/internal/composer.d.ts +16 -0
- package/dist/internal/composer.js +18 -0
- package/dist/internal/menu.d.ts +6 -0
- package/dist/internal/menu.js +31 -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 +38 -1
- package/dist/stories/Alert.stories.d.ts +1 -0
- package/dist/stories/Alert.stories.jsx +16 -0
- package/dist/stories/Button.stories.d.ts +1 -0
- package/dist/stories/Button.stories.jsx +17 -1
- package/dist/stories/Cases.generated.stories.d.ts +82 -0
- package/dist/stories/Cases.generated.stories.jsx +164 -0
- package/dist/stories/Composer.stories.d.ts +23 -0
- package/dist/stories/Composer.stories.jsx +121 -0
- package/dist/stories/EmptyBox.stories.d.ts +2 -0
- package/dist/stories/EmptyBox.stories.jsx +16 -0
- package/dist/stories/FileChip.stories.d.ts +7 -0
- package/dist/stories/FileChip.stories.jsx +35 -0
- package/dist/stories/Heading.stories.d.ts +6 -0
- package/dist/stories/Heading.stories.jsx +10 -0
- package/dist/stories/IconButton.stories.d.ts +1 -0
- package/dist/stories/IconButton.stories.jsx +18 -1
- package/dist/stories/LoadingScreen.stories.d.ts +1 -0
- package/dist/stories/LoadingScreen.stories.jsx +8 -0
- package/dist/stories/Menu.stories.d.ts +4 -0
- package/dist/stories/Menu.stories.jsx +46 -1
- package/dist/stories/MenuItem.stories.d.ts +1 -0
- package/dist/stories/MenuItem.stories.jsx +8 -0
- package/dist/stories/Message.stories.d.ts +10 -0
- package/dist/stories/Message.stories.jsx +77 -0
- package/dist/stories/Modal.stories.d.ts +2 -0
- package/dist/stories/Modal.stories.jsx +36 -0
- package/dist/stories/PageComponents.stories.d.ts +1 -0
- package/dist/stories/PageComponents.stories.jsx +21 -0
- package/dist/stories/RadioGroup.stories.d.ts +3 -0
- package/dist/stories/RadioGroup.stories.jsx +54 -1
- package/dist/stories/Select.stories.d.ts +1 -0
- package/dist/stories/Select.stories.jsx +14 -0
- package/dist/stories/SourceCard.stories.d.ts +8 -0
- package/dist/stories/SourceCard.stories.jsx +33 -0
- package/dist/stories/StepList.stories.d.ts +8 -0
- package/dist/stories/StepList.stories.jsx +35 -0
- package/dist/stories/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/stories/UserImage.stories.d.ts +2 -0
- package/dist/stories/UserImage.stories.jsx +19 -0
- package/package.json +4 -3
package/dist/cases/login-page.md
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
# Login page
|
|
2
2
|
|
|
3
|
-
A person who already has an account opens the product and is not
|
|
3
|
+
A person who already has an account opens the product and is not logged in.
|
|
4
4
|
|
|
5
|
-
**Not built yet:** Commentify and Scindo on the web replace the form with a spinner while
|
|
5
|
+
**Not built yet:** Commentify and Scindo on the web replace the form with a spinner while logging in. They do not use the Button's loading state yet.
|
|
6
6
|
|
|
7
7
|
## Do
|
|
8
8
|
|
|
9
9
|
- Show a problem with one field under that field.
|
|
10
|
-
- Show a refused
|
|
11
|
-
-
|
|
10
|
+
- Show a refused login or a failed request in an inline Alert above the fields.
|
|
11
|
+
- Put a text-only 'Forgot Password?' Button right under the submit Button when there is a password.
|
|
12
12
|
- Name the provider on its button: 'Continue with Google'.
|
|
13
|
-
-
|
|
13
|
+
- Show the loading state on the submit Button while logging in, and keep the form in place.
|
|
14
|
+
- Disable the fields while the request runs.
|
|
14
15
|
|
|
15
16
|
## Don't
|
|
16
17
|
|
|
17
18
|
- Do not clear the email field after a failed attempt.
|
|
18
19
|
- Do not show sign-up fields on the login page; link or tab to sign-up.
|
|
19
|
-
- Do not replace the form with a spinner while
|
|
20
|
+
- Do not replace the form with a spinner while logging in.
|
|
20
21
|
- Do not say which of the email or the password was wrong.
|
|
21
22
|
|
|
22
23
|
## Option: Centered column
|
|
23
24
|
|
|
24
|
-
Use when: The product has one way in, and most people
|
|
25
|
+
Use when: The product has one way in, and most people log in with email and a password.
|
|
25
26
|
|
|
26
27
|
Uses: `Alert`, `BrandIcon`, `Button`, `Center`, `Form`, `Image`, `Line`, `Tab`, `TabsContainer`, `TextField`
|
|
27
28
|
|
|
28
29
|
```tsx
|
|
29
30
|
'use client';
|
|
30
|
-
import { useState } from 'react';
|
|
31
|
+
import { useEffect, useRef, useState } from 'react';
|
|
31
32
|
import Image from 'oneslash-design-system/components/image';
|
|
32
33
|
import TabsContainer from 'oneslash-design-system/components/tabsContainer';
|
|
33
34
|
import Tab from 'oneslash-design-system/components/tab';
|
|
@@ -58,6 +59,10 @@ export default function LoginCentered() {
|
|
|
58
59
|
const [emailError, setEmailError] = useState('');
|
|
59
60
|
const [passwordError, setPasswordError] = useState('');
|
|
60
61
|
const [loading, setLoading] = useState(false);
|
|
62
|
+
const timer = useRef<ReturnType<typeof setTimeout>>();
|
|
63
|
+
|
|
64
|
+
// Stops the request if the example goes away before it ends.
|
|
65
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
61
66
|
|
|
62
67
|
function handleSubmit() {
|
|
63
68
|
if (loading) return;
|
|
@@ -69,7 +74,7 @@ export default function LoginCentered() {
|
|
|
69
74
|
return;
|
|
70
75
|
}
|
|
71
76
|
if (!looksLikeEmail(email.trim())) {
|
|
72
|
-
setEmailError('Enter
|
|
77
|
+
setEmailError('Enter an email address, like name@example.com.');
|
|
73
78
|
return;
|
|
74
79
|
}
|
|
75
80
|
if (!password) {
|
|
@@ -78,7 +83,7 @@ export default function LoginCentered() {
|
|
|
78
83
|
}
|
|
79
84
|
setLoading(true);
|
|
80
85
|
// Stands in for the request to the server.
|
|
81
|
-
setTimeout(() => {
|
|
86
|
+
timer.current = setTimeout(() => {
|
|
82
87
|
setLoading(false);
|
|
83
88
|
setError('That email and password do not match.');
|
|
84
89
|
}, 1200);
|
|
@@ -87,16 +92,16 @@ export default function LoginCentered() {
|
|
|
87
92
|
return (
|
|
88
93
|
<Center fill>
|
|
89
94
|
<Image src={productMark} alt="Acme" width={40} height={40} />
|
|
90
|
-
<TabsContainer>
|
|
95
|
+
<TabsContainer fill>
|
|
91
96
|
<Tab label="Log In" isSelected onClickTab={() => {}} />
|
|
92
97
|
<Tab label="Sign Up" isSelected={false} href="/sign-up" router={router} onClickTab={() => {}} />
|
|
93
98
|
</TabsContainer>
|
|
94
99
|
<Form aria-label="Log in" onSubmit={handleSubmit}>
|
|
95
100
|
{error && <Alert type="error" variant="inline" message={error} showCloseButton onClose={() => setError('')} />}
|
|
96
|
-
<TextField id="login-email" label="Email" type="email" autoComplete="username" value={email} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />
|
|
97
|
-
<TextField id="login-password" label="Password" type="password" autoComplete="current-password" value={password} error={Boolean(passwordError)} errorText={passwordError} onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />
|
|
101
|
+
<TextField id="login-email" label="Email" type="email" autoComplete="username" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />
|
|
102
|
+
<TextField id="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(''); }} />
|
|
98
103
|
<Button size="medium" type="primary" state="enabled" label="Log In" htmlType="submit" loading={loading} />
|
|
99
|
-
<Button size="medium" type="textOnly" state=
|
|
104
|
+
<Button size="medium" type="textOnly" state={loading ? 'disabled' : 'enabled'} label="Forgot Password?" />
|
|
100
105
|
</Form>
|
|
101
106
|
<Line label="or" />
|
|
102
107
|
<Button size="medium" type="secondary" state="enabled" label="Continue with Google" decoIcon={<BrandIcon name="google" />} />
|
|
@@ -113,7 +118,7 @@ Uses: `Alert`, `BrandIcon`, `Button`, `Center`, `Cluster`, `Form`, `Heading`, `I
|
|
|
113
118
|
|
|
114
119
|
```tsx
|
|
115
120
|
'use client';
|
|
116
|
-
import { useState } from 'react';
|
|
121
|
+
import { useEffect, useRef, useState } from 'react';
|
|
117
122
|
import Image from 'oneslash-design-system/components/image';
|
|
118
123
|
import Heading from 'oneslash-design-system/components/heading';
|
|
119
124
|
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
@@ -142,6 +147,10 @@ export default function LoginSplit() {
|
|
|
142
147
|
const [emailError, setEmailError] = useState('');
|
|
143
148
|
const [passwordError, setPasswordError] = useState('');
|
|
144
149
|
const [loading, setLoading] = useState(false);
|
|
150
|
+
const timer = useRef<ReturnType<typeof setTimeout>>();
|
|
151
|
+
|
|
152
|
+
// Stops the request if the example goes away before it ends.
|
|
153
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
145
154
|
|
|
146
155
|
function handleSubmit() {
|
|
147
156
|
if (loading) return;
|
|
@@ -153,7 +162,7 @@ export default function LoginSplit() {
|
|
|
153
162
|
return;
|
|
154
163
|
}
|
|
155
164
|
if (!looksLikeEmail(email.trim())) {
|
|
156
|
-
setEmailError('Enter
|
|
165
|
+
setEmailError('Enter an email address, like name@example.com.');
|
|
157
166
|
return;
|
|
158
167
|
}
|
|
159
168
|
if (!password) {
|
|
@@ -162,7 +171,7 @@ export default function LoginSplit() {
|
|
|
162
171
|
}
|
|
163
172
|
setLoading(true);
|
|
164
173
|
// Stands in for the request to the server.
|
|
165
|
-
setTimeout(() => {
|
|
174
|
+
timer.current = setTimeout(() => {
|
|
166
175
|
setLoading(false);
|
|
167
176
|
setError('That email and password do not match.');
|
|
168
177
|
}, 1200);
|
|
@@ -182,19 +191,19 @@ export default function LoginSplit() {
|
|
|
182
191
|
}
|
|
183
192
|
>
|
|
184
193
|
<Center fill>
|
|
185
|
-
<Heading level={
|
|
194
|
+
<Heading level={1} size="h5">Log in to Acme</Heading>
|
|
186
195
|
<Form aria-label="Log in" onSubmit={handleSubmit}>
|
|
187
196
|
{error && <Alert type="error" variant="inline" message={error} showCloseButton onClose={() => setError('')} />}
|
|
188
|
-
<TextField id="split-email" label="Email" type="email" autoComplete="username" value={email} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />
|
|
189
|
-
<TextField id="split-password" label="Password" type="password" autoComplete="current-password" value={password} error={Boolean(passwordError)} errorText={passwordError} onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />
|
|
197
|
+
<TextField id="split-email" label="Email" type="email" autoComplete="username" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />
|
|
198
|
+
<TextField id="split-password" label="Password" type="password" autoComplete="current-password" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />
|
|
190
199
|
<Button size="medium" type="primary" state="enabled" label="Log In" htmlType="submit" loading={loading} />
|
|
191
|
-
<Button size="medium" type="textOnly" state=
|
|
200
|
+
<Button size="medium" type="textOnly" state={loading ? 'disabled' : 'enabled'} label="Forgot Password?" />
|
|
192
201
|
</Form>
|
|
193
202
|
<Line label="or" />
|
|
194
203
|
<Button size="medium" type="secondary" state="enabled" label="Continue with Google" decoIcon={<BrandIcon name="google" />} />
|
|
195
204
|
<Cluster gap="small">
|
|
196
205
|
<Paragraph tone="secondary" size="body2" measure="none">New here?</Paragraph>
|
|
197
|
-
<Link href="/
|
|
206
|
+
<Link href="/sign-up" size="body2">Sign Up</Link>
|
|
198
207
|
</Cluster>
|
|
199
208
|
</Center>
|
|
200
209
|
</Split>
|
|
@@ -204,13 +213,13 @@ export default function LoginSplit() {
|
|
|
204
213
|
|
|
205
214
|
## Option: Provider first
|
|
206
215
|
|
|
207
|
-
Use when: Most people
|
|
216
|
+
Use when: Most people log in with Google, GitHub or Apple; email is the fallback.
|
|
208
217
|
|
|
209
218
|
Uses: `Alert`, `BrandIcon`, `Button`, `Center`, `Form`, `Heading`, `Line`, `Stack`, `TextField`
|
|
210
219
|
|
|
211
220
|
```tsx
|
|
212
221
|
'use client';
|
|
213
|
-
import { useState } from 'react';
|
|
222
|
+
import { useEffect, useRef, useState } from 'react';
|
|
214
223
|
import Heading from 'oneslash-design-system/components/heading';
|
|
215
224
|
import Form from 'oneslash-design-system/components/form';
|
|
216
225
|
import Alert from 'oneslash-design-system/components/alert';
|
|
@@ -232,6 +241,10 @@ export default function LoginProviderFirst() {
|
|
|
232
241
|
const [emailError, setEmailError] = useState('');
|
|
233
242
|
const [passwordError, setPasswordError] = useState('');
|
|
234
243
|
const [loading, setLoading] = 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), []);
|
|
235
248
|
|
|
236
249
|
function handleSubmit() {
|
|
237
250
|
if (loading) return;
|
|
@@ -243,7 +256,7 @@ export default function LoginProviderFirst() {
|
|
|
243
256
|
return;
|
|
244
257
|
}
|
|
245
258
|
if (!looksLikeEmail(email.trim())) {
|
|
246
|
-
setEmailError('Enter
|
|
259
|
+
setEmailError('Enter an email address, like name@example.com.');
|
|
247
260
|
return;
|
|
248
261
|
}
|
|
249
262
|
if (!password) {
|
|
@@ -252,7 +265,7 @@ export default function LoginProviderFirst() {
|
|
|
252
265
|
}
|
|
253
266
|
setLoading(true);
|
|
254
267
|
// Stands in for the request to the server.
|
|
255
|
-
setTimeout(() => {
|
|
268
|
+
timer.current = setTimeout(() => {
|
|
256
269
|
setLoading(false);
|
|
257
270
|
setError('That email and password do not match.');
|
|
258
271
|
}, 1200);
|
|
@@ -260,19 +273,19 @@ export default function LoginProviderFirst() {
|
|
|
260
273
|
|
|
261
274
|
return (
|
|
262
275
|
<Center fill>
|
|
263
|
-
<Heading level={
|
|
276
|
+
<Heading level={1} size="h5">Log in to Acme</Heading>
|
|
264
277
|
<Stack gap="medium">
|
|
265
278
|
<Button size="medium" type="secondary" state="enabled" label="Continue with Google" decoIcon={<BrandIcon name="google" />} />
|
|
266
279
|
<Button size="medium" type="secondary" state="enabled" label="Continue with GitHub" decoIcon={<BrandIcon name="github" />} />
|
|
267
280
|
<Button size="medium" type="secondary" state="enabled" label="Continue with Apple" decoIcon={<BrandIcon name="apple" />} />
|
|
268
281
|
</Stack>
|
|
269
282
|
<Line label="or" />
|
|
270
|
-
<Form aria-label="
|
|
283
|
+
<Form aria-label="Log in with email" onSubmit={handleSubmit}>
|
|
271
284
|
{error && <Alert type="error" variant="inline" message={error} showCloseButton onClose={() => setError('')} />}
|
|
272
|
-
<TextField id="provider-email" label="Email" type="email" autoComplete="username" value={email} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />
|
|
273
|
-
<TextField id="provider-password" label="Password" type="password" autoComplete="current-password" value={password} error={Boolean(passwordError)} errorText={passwordError} onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />
|
|
274
|
-
<Button size="medium" type="primary" state="enabled" label="
|
|
275
|
-
<Button size="medium" type="textOnly" state=
|
|
285
|
+
<TextField id="provider-email" label="Email" type="email" autoComplete="username" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />
|
|
286
|
+
<TextField id="provider-password" label="Password" type="password" autoComplete="current-password" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} onChange={(e) => { setPassword(e.target.value); setPasswordError(''); }} />
|
|
287
|
+
<Button size="medium" type="primary" state="enabled" label="Log In with Email" htmlType="submit" loading={loading} />
|
|
288
|
+
<Button size="medium" type="textOnly" state={loading ? 'disabled' : 'enabled'} label="Forgot Password?" />
|
|
276
289
|
</Form>
|
|
277
290
|
</Center>
|
|
278
291
|
);
|
|
@@ -281,13 +294,13 @@ export default function LoginProviderFirst() {
|
|
|
281
294
|
|
|
282
295
|
## Option: Email only
|
|
283
296
|
|
|
284
|
-
Use when: An internal tool with no passwords: the person gets a
|
|
297
|
+
Use when: An internal tool with no passwords: the person gets a login link by email.
|
|
285
298
|
|
|
286
299
|
Uses: `Alert`, `Button`, `Center`, `Form`, `Heading`, `Paragraph`, `Stack`, `Surface`, `TextField`
|
|
287
300
|
|
|
288
301
|
```tsx
|
|
289
302
|
'use client';
|
|
290
|
-
import { useState } from 'react';
|
|
303
|
+
import { useEffect, useRef, useState } from 'react';
|
|
291
304
|
import Surface from 'oneslash-design-system/components/surface';
|
|
292
305
|
import Heading from 'oneslash-design-system/components/heading';
|
|
293
306
|
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
@@ -307,6 +320,10 @@ export default function LoginEmailOnly() {
|
|
|
307
320
|
const [sentTo, setSentTo] = useState('');
|
|
308
321
|
const [emailError, setEmailError] = useState('');
|
|
309
322
|
const [loading, setLoading] = useState(false);
|
|
323
|
+
const timer = useRef<ReturnType<typeof setTimeout>>();
|
|
324
|
+
|
|
325
|
+
// Stops the request if the example goes away before it ends.
|
|
326
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
310
327
|
|
|
311
328
|
function handleSubmit() {
|
|
312
329
|
if (loading) return;
|
|
@@ -317,13 +334,13 @@ export default function LoginEmailOnly() {
|
|
|
317
334
|
return;
|
|
318
335
|
}
|
|
319
336
|
if (!looksLikeEmail(email.trim())) {
|
|
320
|
-
setEmailError('Enter
|
|
337
|
+
setEmailError('Enter an email address, like name@example.com.');
|
|
321
338
|
return;
|
|
322
339
|
}
|
|
323
340
|
setLoading(true);
|
|
324
341
|
const address = email.trim();
|
|
325
342
|
// Stands in for the request to the server.
|
|
326
|
-
setTimeout(() => {
|
|
343
|
+
timer.current = setTimeout(() => {
|
|
327
344
|
setLoading(false);
|
|
328
345
|
setSentTo(address);
|
|
329
346
|
}, 1200);
|
|
@@ -334,13 +351,13 @@ export default function LoginEmailOnly() {
|
|
|
334
351
|
<Surface padding="large">
|
|
335
352
|
<Stack gap="xlarge">
|
|
336
353
|
<Stack gap="small">
|
|
337
|
-
<Heading level={
|
|
338
|
-
<Paragraph tone="secondary" size="body2" measure="none">We will email you a link to
|
|
354
|
+
<Heading level={1} size="h5">Log in</Heading>
|
|
355
|
+
<Paragraph tone="secondary" size="body2" measure="none">We will email you a link to log in.</Paragraph>
|
|
339
356
|
</Stack>
|
|
340
357
|
<Form aria-label="Log in" onSubmit={handleSubmit}>
|
|
341
|
-
{sentTo && <Alert type="success" variant="inline" message={`We sent a
|
|
342
|
-
<TextField id="email-only-email" label="Email" type="email" autoComplete="username" value={email} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />
|
|
343
|
-
<Button size="medium" type="primary" state="enabled" label="Send
|
|
358
|
+
{sentTo && <Alert type="success" variant="inline" message={`We sent a login link to ${sentTo}.`} autoDismiss={false} />}
|
|
359
|
+
<TextField id="email-only-email" label="Email" type="email" autoComplete="username" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={(e) => { setEmail(e.target.value); setEmailError(''); }} />
|
|
360
|
+
<Button size="medium" type="primary" state="enabled" label="Send Login Link" htmlType="submit" loading={loading} />
|
|
344
361
|
</Form>
|
|
345
362
|
</Stack>
|
|
346
363
|
</Surface>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function MentionListInComposer(): import("react").JSX.Element;
|
|
@@ -0,0 +1,169 @@
|
|
|
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 { Bot } from 'lucide-react';
|
|
13
|
+
import Message from '../../components/message';
|
|
14
|
+
import UserImage from '../../components/userImage';
|
|
15
|
+
import TimeStamp from '../../components/timeStamp';
|
|
16
|
+
import Heading from '../../components/heading';
|
|
17
|
+
import Paragraph from '../../components/paragraph';
|
|
18
|
+
import Composer from '../../components/composer';
|
|
19
|
+
import Menu from '../../components/menu';
|
|
20
|
+
import MenuItem from '../../components/menuItem';
|
|
21
|
+
import { Center, Stack } from '../../components/layout';
|
|
22
|
+
// A real app reads these from the session and the workspace.
|
|
23
|
+
var me = 'Dana Lee';
|
|
24
|
+
// The agent comes first.
|
|
25
|
+
var members = [
|
|
26
|
+
{ id: 'acme-agent', name: 'Acme Agent', agent: true },
|
|
27
|
+
{ id: 'ben-carter', name: 'Ben Carter' },
|
|
28
|
+
{ id: 'dana-lee', name: 'Dana Lee' },
|
|
29
|
+
{ id: 'omar-reyes', name: 'Omar Reyes' },
|
|
30
|
+
];
|
|
31
|
+
var listId = 'mention-list-suggestions';
|
|
32
|
+
// The list shows at most this many names; typing more letters narrows it.
|
|
33
|
+
var MAX_MATCHES = 8;
|
|
34
|
+
var optionId = function (m) { return "mention-list-option-".concat(m.id); };
|
|
35
|
+
var firstThread = [
|
|
36
|
+
{ id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },
|
|
37
|
+
{ id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Who checks the links before we announce it?' },
|
|
38
|
+
];
|
|
39
|
+
// Opens with the person part-way through a mention, so the list shows.
|
|
40
|
+
var firstText = 'Can you check the links, @';
|
|
41
|
+
// The word after the @ that ends the text before the caret, or null when there is none. The @ starts
|
|
42
|
+
// the text or follows a space, so an email address such as dana@example.com opens nothing.
|
|
43
|
+
function mentionQuery(before) {
|
|
44
|
+
var match = before.match(/(?:^|\s)@(\w*)$/);
|
|
45
|
+
return match ? match[1] : null;
|
|
46
|
+
}
|
|
47
|
+
// The query for where the caret is now.
|
|
48
|
+
function queryAtCaret(field) {
|
|
49
|
+
var _a;
|
|
50
|
+
return mentionQuery(field.value.slice(0, (_a = field.selectionStart) !== null && _a !== void 0 ? _a : field.value.length));
|
|
51
|
+
}
|
|
52
|
+
// Names with a word that starts with what was typed, at most 8. The person typing is left out.
|
|
53
|
+
function matches(query) {
|
|
54
|
+
var q = query.toLowerCase();
|
|
55
|
+
return members.filter(function (m) { return m.name !== me && m.name.toLowerCase().split(' ').some(function (w) { return w.startsWith(q); }); }).slice(0, MAX_MATCHES);
|
|
56
|
+
}
|
|
57
|
+
export default function MentionListInComposer() {
|
|
58
|
+
var _a = useState(firstThread), thread = _a[0], setThread = _a[1];
|
|
59
|
+
var _b = useState(firstText), text = _b[0], setText = _b[1];
|
|
60
|
+
var _c = useState(mentionQuery(firstText)), query = _c[0], setQuery = _c[1];
|
|
61
|
+
var _d = useState(0), active = _d[0], setActive = _d[1];
|
|
62
|
+
// Where the caret goes after a pick; the effect below puts it there once the new text is in the field.
|
|
63
|
+
var _e = useState(null), caret = _e[0], setCaret = _e[1];
|
|
64
|
+
var field = useRef(null);
|
|
65
|
+
var results = query === null ? [] : matches(query);
|
|
66
|
+
// No match: the list closes.
|
|
67
|
+
var open = results.length > 0;
|
|
68
|
+
// The field opens with the caret at the end, after the @.
|
|
69
|
+
useEffect(function () {
|
|
70
|
+
var _a, _b, _c;
|
|
71
|
+
var end = (_b = (_a = field.current) === null || _a === void 0 ? void 0 : _a.value.length) !== null && _b !== void 0 ? _b : 0;
|
|
72
|
+
(_c = field.current) === null || _c === void 0 ? void 0 : _c.setSelectionRange(end, end);
|
|
73
|
+
}, []);
|
|
74
|
+
useEffect(function () {
|
|
75
|
+
if (caret === null || !field.current)
|
|
76
|
+
return;
|
|
77
|
+
field.current.focus();
|
|
78
|
+
field.current.setSelectionRange(caret, caret);
|
|
79
|
+
setCaret(null);
|
|
80
|
+
}, [caret]);
|
|
81
|
+
function change(value) {
|
|
82
|
+
var _a, _b;
|
|
83
|
+
setText(value);
|
|
84
|
+
var at = (_b = (_a = field.current) === null || _a === void 0 ? void 0 : _a.selectionStart) !== null && _b !== void 0 ? _b : value.length;
|
|
85
|
+
setQuery(mentionQuery(value.slice(0, at)));
|
|
86
|
+
setActive(0);
|
|
87
|
+
}
|
|
88
|
+
// The caret moved (an arrow key, a click, Home or End): the list follows the word at the caret, and
|
|
89
|
+
// closes when the caret leaves it.
|
|
90
|
+
function caretMoved(e) {
|
|
91
|
+
var next = queryAtCaret(e.currentTarget);
|
|
92
|
+
if (next === query)
|
|
93
|
+
return;
|
|
94
|
+
setQuery(next);
|
|
95
|
+
setActive(0);
|
|
96
|
+
}
|
|
97
|
+
// Puts '@Name ' in place of the @ and the word typed so far, and the caret after the space.
|
|
98
|
+
function pick(m) {
|
|
99
|
+
var _a, _b;
|
|
100
|
+
var at = (_b = (_a = field.current) === null || _a === void 0 ? void 0 : _a.selectionStart) !== null && _b !== void 0 ? _b : text.length;
|
|
101
|
+
var before = text.slice(0, at);
|
|
102
|
+
var start = before.lastIndexOf('@');
|
|
103
|
+
if (start < 0)
|
|
104
|
+
return;
|
|
105
|
+
var inserted = "@".concat(m.name, " ");
|
|
106
|
+
setText(before.slice(0, start) + inserted + text.slice(at));
|
|
107
|
+
setQuery(null);
|
|
108
|
+
setCaret(start + inserted.length);
|
|
109
|
+
}
|
|
110
|
+
// While the list is open it takes the arrows, Enter, Tab and Escape, so Enter picks instead of sending.
|
|
111
|
+
function keyDown(e) {
|
|
112
|
+
// An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.
|
|
113
|
+
if (e.nativeEvent.isComposing || e.keyCode === 229)
|
|
114
|
+
return;
|
|
115
|
+
if (!open)
|
|
116
|
+
return;
|
|
117
|
+
if (e.key === 'ArrowDown') {
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
setActive(function (i) { return Math.min(i + 1, results.length - 1); });
|
|
120
|
+
}
|
|
121
|
+
else if (e.key === 'ArrowUp') {
|
|
122
|
+
e.preventDefault();
|
|
123
|
+
setActive(function (i) { return Math.max(i - 1, 0); });
|
|
124
|
+
}
|
|
125
|
+
else if (e.key === 'Enter' || (e.key === 'Tab' && !e.shiftKey)) {
|
|
126
|
+
// Check the word at the caret again before taking the key. If nothing matches now, the list
|
|
127
|
+
// closes and the key does what it always does: Enter sends, Tab moves on. Shift+Tab is never a pick.
|
|
128
|
+
var now = queryAtCaret(e.currentTarget);
|
|
129
|
+
var found = now === null ? [] : matches(now);
|
|
130
|
+
if (found.length === 0) {
|
|
131
|
+
setQuery(null);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
e.preventDefault();
|
|
135
|
+
pick(found[now === query ? Math.min(active, found.length - 1) : 0]);
|
|
136
|
+
}
|
|
137
|
+
else if (e.key === 'Escape') {
|
|
138
|
+
e.preventDefault();
|
|
139
|
+
e.stopPropagation();
|
|
140
|
+
setQuery(null);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function send() {
|
|
144
|
+
// A real app sends the message to the server here and shows it at once.
|
|
145
|
+
setThread(function (rows) { return __spreadArray(__spreadArray([], rows, true), [{ id: "m".concat(rows.length + 1), from: me, at: new Date(), text: text.trim() }], false); });
|
|
146
|
+
setText('');
|
|
147
|
+
setQuery(null);
|
|
148
|
+
}
|
|
149
|
+
return (<Center width="page">
|
|
150
|
+
<Stack gap="large">
|
|
151
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
152
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
153
|
+
<Stack gap="small">
|
|
154
|
+
{thread.map(function (m) { return (<Message key={m.id} aria-label={m.from} avatar={<UserImage userHandle={m.from} decorative/>} name={m.from} meta={<TimeStamp createdAt={m.at} dateFormat="absolute" data="time"/>}>
|
|
155
|
+
<Paragraph measure="none">{m.text}</Paragraph>
|
|
156
|
+
</Message>); })}
|
|
157
|
+
</Stack>
|
|
158
|
+
<Composer ref={field} id="mention-list-message" aria-label="Message" placeholder="Message the team" value={text} onChange={change} onSubmit={send} onKeyDown={keyDown} onSelect={caretMoved}
|
|
159
|
+
// A press on a row keeps focus in the field, so this runs only when focus leaves for good.
|
|
160
|
+
onBlur={function () { return setQuery(null); }}
|
|
161
|
+
// Focus stays in the field; the field points at the list and at the highlighted row.
|
|
162
|
+
role="combobox" aria-autocomplete="list" aria-expanded={open} aria-controls={open ? listId : undefined} aria-activedescendant={open ? optionId(results[active]) : undefined} above={open ? (<Menu role="listbox" id={listId} aria-label="People and agents" width={280}>
|
|
163
|
+
{results.map(function (m, i) { return (<MenuItem key={m.id} id={optionId(m)} role="option" tabIndex={-1} isActive={i === active} aria-selected={i === active} size="small"
|
|
164
|
+
// A person may have no picture, so the avatar goes in icon: UserImage shows the initial.
|
|
165
|
+
icon={m.agent ? <UserImage userHandle={m.name} icon={Bot} size={20} decorative/> : <UserImage userHandle={m.name} size={20} decorative/>} label={m.name} tag={m.agent ? { label: 'Agent' } : undefined} onClick={function () { return pick(m); }}/>); })}
|
|
166
|
+
</Menu>) : undefined}/>
|
|
167
|
+
</Stack>
|
|
168
|
+
</Center>);
|
|
169
|
+
}
|