oneslash-design-system 2.16.0 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/DESIGN.md +56 -17
- package/dist/cases/accept-invite/signed-in.jsx +1 -1
- package/dist/cases/accept-invite/signed-out.jsx +1 -1
- package/dist/cases/accept-invite.md +3 -7
- package/dist/cases/account-menu/menu.d.ts +1 -0
- package/dist/cases/account-menu/menu.jsx +99 -0
- package/dist/cases/account-menu.md +164 -0
- package/dist/cases/agent-asks-before-risky-action.md +0 -4
- package/dist/cases/agent-cancels-when-unanswered.md +0 -4
- package/dist/cases/agent-options/cards.d.ts +1 -0
- package/dist/cases/agent-options/cards.jsx +91 -0
- package/dist/cases/agent-options.md +164 -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 +428 -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 +652 -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 +334 -0
- package/dist/cases/agent-refuses-clearly.md +0 -4
- package/dist/cases/agent-says-what-it-is.md +0 -2
- package/dist/cases/agent-settings/form.d.ts +1 -0
- package/dist/cases/agent-settings/form.jsx +164 -0
- package/dist/cases/agent-settings.md +259 -0
- package/dist/cases/agent-shows-progress.md +0 -2
- package/dist/cases/agent-shows-sources.md +2 -4
- package/dist/cases/api-keys/list.d.ts +1 -0
- package/dist/cases/api-keys/list.jsx +162 -0
- package/dist/cases/api-keys.md +229 -0
- package/dist/cases/artifact-card/card.d.ts +1 -0
- package/dist/cases/artifact-card/card.jsx +45 -0
- package/dist/cases/artifact-card.md +99 -0
- package/dist/cases/auth-gate-loading.md +0 -4
- package/dist/cases/check-your-email.md +0 -4
- package/dist/cases/collapsible-search/popover.d.ts +1 -0
- package/dist/cases/collapsible-search/popover.jsx +74 -0
- package/dist/cases/collapsible-search.md +143 -0
- package/dist/cases/composer-limit/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 +282 -0
- package/dist/cases/confirm-destructive-action.md +0 -4
- package/dist/cases/confirm-dialogs.md +0 -4
- 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 +204 -0
- package/dist/cases/create-modal.md +0 -4
- package/dist/cases/danger-zone/collapsed.d.ts +1 -0
- package/dist/cases/danger-zone/collapsed.jsx +75 -0
- package/dist/cases/danger-zone/shown.d.ts +1 -0
- package/dist/cases/danger-zone/shown.jsx +95 -0
- package/dist/cases/danger-zone.md +263 -0
- package/dist/cases/device-login.md +0 -4
- package/dist/cases/email-confirmed.md +0 -4
- package/dist/cases/empty-list.md +0 -4
- package/dist/cases/empty-lists.md +0 -4
- package/dist/cases/empty-not-set-up.md +0 -4
- package/dist/cases/empty-search.md +0 -4
- package/dist/cases/error-page.md +0 -4
- package/dist/cases/feedback-form.md +0 -4
- package/dist/cases/filter-menu/presets.d.ts +1 -0
- package/dist/cases/filter-menu/presets.jsx +53 -0
- package/dist/cases/filter-menu/with-clear.d.ts +1 -0
- package/dist/cases/filter-menu/with-clear.jsx +56 -0
- package/dist/cases/filter-menu.md +204 -0
- package/dist/cases/forgot-password.md +0 -4
- package/dist/cases/form-errors.md +0 -4
- package/dist/cases/import-checklist.md +0 -4
- package/dist/cases/inline-form-feedback.md +0 -4
- package/dist/cases/integrations-list/nested.d.ts +1 -0
- package/dist/cases/integrations-list/nested.jsx +164 -0
- package/dist/cases/integrations-list/rows.d.ts +1 -0
- package/dist/cases/integrations-list/rows.jsx +134 -0
- package/dist/cases/integrations-list.md +379 -0
- package/dist/cases/invite-member.md +0 -4
- package/dist/cases/load-failure.md +0 -4
- package/dist/cases/log-out-confirm.md +0 -4
- package/dist/cases/login-page.md +0 -4
- package/dist/cases/members-list/rows.d.ts +1 -0
- package/dist/cases/members-list/rows.jsx +318 -0
- package/dist/cases/members-list/table.d.ts +1 -0
- package/dist/cases/members-list/table.jsx +351 -0
- package/dist/cases/members-list.md +799 -0
- package/dist/cases/mention-list/in-composer.d.ts +1 -0
- package/dist/cases/mention-list/in-composer.jsx +169 -0
- package/dist/cases/mention-list.md +248 -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 +647 -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 +306 -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 +352 -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 +175 -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 +367 -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 +185 -0
- package/dist/cases/not-found-page.md +0 -4
- package/dist/cases/notification-menu/menu.d.ts +1 -0
- package/dist/cases/notification-menu/menu.jsx +74 -0
- package/dist/cases/notification-menu.md +135 -0
- package/dist/cases/oauth-consent.md +0 -4
- package/dist/cases/on-off-settings/list.d.ts +1 -0
- package/dist/cases/on-off-settings/list.jsx +97 -0
- package/dist/cases/on-off-settings.md +116 -0
- package/dist/cases/overflow-menu/in-a-header.d.ts +1 -0
- package/dist/cases/overflow-menu/in-a-header.jsx +128 -0
- package/dist/cases/overflow-menu/on-a-row.d.ts +1 -0
- package/dist/cases/overflow-menu/on-a-row.jsx +183 -0
- package/dist/cases/overflow-menu.md +410 -0
- package/dist/cases/profile-form/form.d.ts +1 -0
- package/dist/cases/profile-form/form.jsx +153 -0
- package/dist/cases/profile-form.md +236 -0
- package/dist/cases/quick-switcher/modal.d.ts +1 -0
- package/dist/cases/quick-switcher/modal.jsx +114 -0
- package/dist/cases/quick-switcher.md +205 -0
- package/dist/cases/range-switch/segmented.d.ts +1 -0
- package/dist/cases/range-switch/segmented.jsx +30 -0
- package/dist/cases/range-switch.md +67 -0
- package/dist/cases/rename.md +0 -4
- package/dist/cases/reply-feedback/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 +548 -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 +243 -0
- package/dist/cases/route-loading.md +0 -2
- package/dist/cases/scope-picker/menu.d.ts +1 -0
- package/dist/cases/scope-picker/menu.jsx +47 -0
- package/dist/cases/scope-picker.md +97 -0
- package/dist/cases/set-new-password.md +0 -4
- package/dist/cases/settings-page/side-nav.d.ts +1 -0
- package/dist/cases/settings-page/side-nav.jsx +171 -0
- package/dist/cases/settings-page/top-tabs.d.ts +1 -0
- package/dist/cases/settings-page/top-tabs.jsx +129 -0
- package/dist/cases/settings-page.md +378 -0
- package/dist/cases/settings-save.md +35 -0
- package/dist/cases/sign-up-page.md +1 -5
- 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 +243 -0
- package/dist/cases/success-feedback.md +1 -5
- package/dist/cases/tag-filter/tags.d.ts +1 -0
- package/dist/cases/tag-filter/tags.jsx +226 -0
- package/dist/cases/tag-filter.md +298 -0
- package/dist/cases/type-to-confirm.md +0 -4
- 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 +92 -0
- package/dist/cases/unsaved-changes-guard.md +0 -4
- package/dist/cases/upgrade-prompt.md +0 -4
- package/dist/cases.json +2331 -294
- package/dist/components/alert.d.ts +3 -1
- package/dist/components/alert.jsx +2 -2
- package/dist/components/button.d.ts +3 -2
- package/dist/components/button.jsx +14 -9
- package/dist/components/checkBox.d.ts +5 -1
- package/dist/components/checkBox.jsx +2 -2
- package/dist/components/composer.d.ts +74 -0
- package/dist/components/composer.jsx +122 -0
- package/dist/components/copyField.d.ts +20 -0
- package/dist/components/copyField.jsx +99 -0
- package/dist/components/fileChip.d.ts +33 -0
- package/dist/components/fileChip.jsx +61 -0
- package/dist/components/formField.d.ts +34 -0
- package/dist/components/formField.jsx +28 -0
- package/dist/components/heading.d.ts +3 -1
- package/dist/components/heading.jsx +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/menu.d.ts +21 -0
- package/dist/components/menu.jsx +27 -3
- package/dist/components/menuItem.d.ts +12 -2
- package/dist/components/menuItem.jsx +6 -5
- package/dist/components/message.d.ts +28 -0
- package/dist/components/message.jsx +25 -0
- package/dist/components/navigation.d.ts +9 -1
- package/dist/components/navigation.jsx +15 -3
- 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 +12 -1
- package/dist/components/radioGroup.jsx +20 -9
- package/dist/components/segmentedControl.d.ts +22 -0
- package/dist/components/segmentedControl.jsx +54 -0
- package/dist/components/select.d.ts +5 -1
- package/dist/components/select.jsx +2 -2
- package/dist/components/settingsSection.d.ts +31 -0
- package/dist/components/settingsSection.jsx +58 -0
- package/dist/components/slidingIndicator.d.ts +50 -0
- package/dist/components/slidingIndicator.jsx +102 -0
- 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/switch.d.ts +25 -0
- package/dist/components/switch.jsx +55 -0
- package/dist/components/tab.jsx +5 -11
- package/dist/components/tabsContainer.jsx +5 -67
- package/dist/components/tag.d.ts +9 -1
- package/dist/components/tag.jsx +6 -4
- package/dist/components/textField.d.ts +12 -2
- package/dist/components/textField.jsx +11 -4
- package/dist/components/textarea.d.ts +5 -1
- package/dist/components/textarea.jsx +6 -21
- package/dist/components/useHotkey.d.ts +7 -0
- package/dist/components/useHotkey.js +24 -0
- package/dist/components/userImage.d.ts +9 -1
- package/dist/components/userImage.jsx +10 -3
- package/dist/index.d.ts +6 -0
- package/dist/index.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/copyField.d.ts +5 -0
- package/dist/internal/copyField.js +61 -0
- package/dist/internal/hotkey.d.ts +16 -0
- package/dist/internal/hotkey.js +20 -0
- package/dist/internal/menu.d.ts +6 -0
- package/dist/internal/menu.js +31 -0
- package/dist/internal/switch.d.ts +5 -0
- package/dist/internal/switch.js +9 -0
- package/dist/native-mapping.json +62 -1
- 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 +53 -0
- package/dist/stories/Cases.generated.stories.jsx +106 -0
- package/dist/stories/Composer.stories.d.ts +23 -0
- package/dist/stories/Composer.stories.jsx +121 -0
- package/dist/stories/CopyField.stories.d.ts +11 -0
- package/dist/stories/CopyField.stories.jsx +65 -0
- package/dist/stories/FileChip.stories.d.ts +7 -0
- package/dist/stories/FileChip.stories.jsx +35 -0
- package/dist/stories/FormField.stories.d.ts +6 -0
- package/dist/stories/FormField.stories.jsx +44 -0
- package/dist/stories/IconButton.stories.d.ts +1 -0
- package/dist/stories/IconButton.stories.jsx +18 -1
- 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/Navigation.stories.d.ts +1 -0
- package/dist/stories/Navigation.stories.jsx +17 -1
- package/dist/stories/PageComponents.stories.d.ts +1 -0
- package/dist/stories/PageComponents.stories.jsx +21 -0
- package/dist/stories/RadioGroup.stories.d.ts +2 -0
- package/dist/stories/RadioGroup.stories.jsx +40 -1
- package/dist/stories/SegmentedControl.stories.d.ts +8 -0
- package/dist/stories/SegmentedControl.stories.jsx +33 -0
- package/dist/stories/SettingsSection.stories.d.ts +11 -0
- package/dist/stories/SettingsSection.stories.jsx +64 -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/Switch.stories.d.ts +14 -0
- package/dist/stories/Switch.stories.jsx +87 -0
- package/dist/stories/TextField.stories.d.ts +1 -0
- package/dist/stories/TextField.stories.jsx +13 -0
- package/dist/stories/UserImage.stories.d.ts +2 -0
- package/dist/stories/UserImage.stories.jsx +19 -0
- package/package.json +8 -3
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import React, { createContext
|
|
3
|
-
|
|
4
|
-
var useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
|
|
2
|
+
import React, { createContext } from 'react';
|
|
3
|
+
import { SlidingPill, segmentTrackClasses, segmentTrackStyle, useSlidingIndicator } from './slidingIndicator';
|
|
5
4
|
// Lets a Tab know a container draws its selected background (the sliding pill)
|
|
6
5
|
export var TabsContainerContext = createContext(false);
|
|
7
6
|
// Lets a Tab know every tab in the container takes an equal share of the width
|
|
@@ -9,59 +8,7 @@ export var TabsFillContext = createContext(false);
|
|
|
9
8
|
export default function TabsContainer(_a) {
|
|
10
9
|
var children = _a.children, _b = _a.fill, fill = _b === void 0 ? false : _b;
|
|
11
10
|
var tabCount = React.Children.count(children);
|
|
12
|
-
var
|
|
13
|
-
var selectedRef = useRef(null);
|
|
14
|
-
var _c = useState(null), indicator = _c[0], setIndicator = _c[1];
|
|
15
|
-
useIsomorphicLayoutEffect(function () {
|
|
16
|
-
var _a;
|
|
17
|
-
var container = containerRef.current;
|
|
18
|
-
if (!container)
|
|
19
|
-
return;
|
|
20
|
-
var update = function () {
|
|
21
|
-
var selected = container.querySelector('[data-tab-selected="true"]');
|
|
22
|
-
if (!selected) {
|
|
23
|
-
selectedRef.current = null;
|
|
24
|
-
setIndicator(null);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
setIndicator(function (prev) { return ({
|
|
28
|
-
animate: prev !== null,
|
|
29
|
-
x: selected.offsetLeft,
|
|
30
|
-
y: selected.offsetTop,
|
|
31
|
-
width: selected.offsetWidth,
|
|
32
|
-
height: selected.offsetHeight,
|
|
33
|
-
}); });
|
|
34
|
-
// Tabs scroll horizontally instead of wrapping; keep a newly selected tab in view
|
|
35
|
-
if (selected !== selectedRef.current) {
|
|
36
|
-
selectedRef.current = selected;
|
|
37
|
-
var left = selected.offsetLeft;
|
|
38
|
-
var right = left + selected.offsetWidth;
|
|
39
|
-
if (left < container.scrollLeft) {
|
|
40
|
-
container.scrollTo({ left: left - 4, behavior: 'smooth' });
|
|
41
|
-
}
|
|
42
|
-
else if (right > container.scrollLeft + container.clientWidth) {
|
|
43
|
-
container.scrollTo({ left: right - container.clientWidth + 4, behavior: 'smooth' });
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
update();
|
|
48
|
-
// Tab widths change once web fonts load
|
|
49
|
-
(_a = document.fonts) === null || _a === void 0 ? void 0 : _a.ready.then(update);
|
|
50
|
-
var resizeObserver = new ResizeObserver(update);
|
|
51
|
-
resizeObserver.observe(container);
|
|
52
|
-
Array.from(container.children).forEach(function (child) { return resizeObserver.observe(child); });
|
|
53
|
-
var mutationObserver = new MutationObserver(update);
|
|
54
|
-
mutationObserver.observe(container, {
|
|
55
|
-
subtree: true,
|
|
56
|
-
childList: true,
|
|
57
|
-
attributes: true,
|
|
58
|
-
attributeFilter: ['data-tab-selected'],
|
|
59
|
-
});
|
|
60
|
-
return function () {
|
|
61
|
-
resizeObserver.disconnect();
|
|
62
|
-
mutationObserver.disconnect();
|
|
63
|
-
};
|
|
64
|
-
}, [children]);
|
|
11
|
+
var _c = useSlidingIndicator(children), containerRef = _c.containerRef, indicator = _c.indicator;
|
|
65
12
|
return (<TabsContainerContext.Provider value={true}>
|
|
66
13
|
<TabsFillContext.Provider value={fill}>
|
|
67
14
|
<div ref={containerRef} role="tablist" onKeyDown={function (e) {
|
|
@@ -82,17 +29,8 @@ export default function TabsContainer(_a) {
|
|
|
82
29
|
e.preventDefault();
|
|
83
30
|
tabs[next].focus();
|
|
84
31
|
tabs[next].click();
|
|
85
|
-
}} className={
|
|
86
|
-
|
|
87
|
-
msOverflowStyle: 'none',
|
|
88
|
-
}}>
|
|
89
|
-
{indicator && (<span aria-hidden className={"absolute rounded-control pointer-events-none bg-primary-dark\n ".concat(indicator.animate ? 'transition-[transform,width,height] duration-[var(--os-duration-slide)] ease-emphasized motion-reduce:transition-none' : '')} style={{
|
|
90
|
-
top: 0,
|
|
91
|
-
left: 0,
|
|
92
|
-
transform: "translate(".concat(indicator.x, "px, ").concat(indicator.y, "px)"),
|
|
93
|
-
width: indicator.width,
|
|
94
|
-
height: indicator.height,
|
|
95
|
-
}}/>)}
|
|
32
|
+
}} className={segmentTrackClasses(fill, tabCount > 0)} style={segmentTrackStyle}>
|
|
33
|
+
<SlidingPill indicator={indicator}/>
|
|
96
34
|
{children}
|
|
97
35
|
</div>
|
|
98
36
|
</TabsFillContext.Provider>
|
package/dist/components/tag.d.ts
CHANGED
|
@@ -15,6 +15,14 @@ interface TagProps {
|
|
|
15
15
|
onClick?: React.MouseEventHandler<HTMLDivElement>;
|
|
16
16
|
/** Only applies to a clickable tag: dims it, drops it from the tab order and ignores clicks */
|
|
17
17
|
disabled?: boolean;
|
|
18
|
+
/** The tag's name, when the label alone does not say it (a reaction: 'Thumbs up, 3 reactions'). On the button when clickable; a static tag with a name gets `role="img"`. */
|
|
19
|
+
'aria-label'?: string;
|
|
20
|
+
/**
|
|
21
|
+
* A clickable tag is a toggle by default and reports `aria-pressed`: right for a filter or a reaction.
|
|
22
|
+
* `false` makes it a plain button with no `aria-pressed`, for an action such as a conversation starter.
|
|
23
|
+
* `state="selected"` still gives the selected look then, but it is only a look. No effect without `onClick`.
|
|
24
|
+
*/
|
|
25
|
+
toggle?: boolean;
|
|
18
26
|
}
|
|
19
|
-
export default function Tag({ variant, size, state, color, label, secondLabel, iconName, icon, onClick, disabled, }: TagProps): JSX.Element;
|
|
27
|
+
export default function Tag({ variant, size, state, color, label, secondLabel, iconName, icon, onClick, disabled, 'aria-label': ariaLabel, toggle, }: TagProps): React.JSX.Element;
|
|
20
28
|
export {};
|
package/dist/components/tag.jsx
CHANGED
|
@@ -48,7 +48,7 @@ var colorConfig = {
|
|
|
48
48
|
},
|
|
49
49
|
};
|
|
50
50
|
export default function Tag(_a) {
|
|
51
|
-
var variant = _a.variant, size = _a.size, _b = _a.state, state = _b === void 0 ? 'enabled' : _b, color = _a.color, label = _a.label, secondLabel = _a.secondLabel, iconName = _a.iconName, icon = _a.icon, onClick = _a.onClick, _c = _a.disabled, disabled = _c === void 0 ? false : _c;
|
|
51
|
+
var variant = _a.variant, size = _a.size, _b = _a.state, state = _b === void 0 ? 'enabled' : _b, color = _a.color, label = _a.label, secondLabel = _a.secondLabel, iconName = _a.iconName, icon = _a.icon, onClick = _a.onClick, _c = _a.disabled, disabled = _c === void 0 ? false : _c, ariaLabel = _a["aria-label"], _d = _a.toggle, toggle = _d === void 0 ? true : _d;
|
|
52
52
|
// Size and padding
|
|
53
53
|
var sizeClasses = {
|
|
54
54
|
medium: 'text-body2 px-2 py-1',
|
|
@@ -121,12 +121,12 @@ export default function Tag(_a) {
|
|
|
121
121
|
var cursorClass = isDisabled ? 'cursor-not-allowed opacity-50' : onClick && !isSelected ? 'cursor-pointer' : '';
|
|
122
122
|
// inline-flex so a tag wraps its content instead of stretching to its container
|
|
123
123
|
var baseClasses = "inline-flex items-center gap-1 rounded-full whitespace-nowrap ".concat(stateTransition);
|
|
124
|
-
// A clickable tag is a keyboard-reachable toggle
|
|
124
|
+
// A clickable tag is a keyboard-reachable button, a toggle unless `toggle` is false
|
|
125
125
|
var interactiveProps = onClick
|
|
126
126
|
? {
|
|
127
127
|
role: 'button',
|
|
128
128
|
tabIndex: isDisabled ? -1 : 0,
|
|
129
|
-
'aria-pressed': isSelected,
|
|
129
|
+
'aria-pressed': toggle ? isSelected : undefined,
|
|
130
130
|
'aria-disabled': isDisabled || undefined,
|
|
131
131
|
onClick: isDisabled ? undefined : onClick,
|
|
132
132
|
onKeyDown: function (e) {
|
|
@@ -137,7 +137,9 @@ export default function Tag(_a) {
|
|
|
137
137
|
},
|
|
138
138
|
}
|
|
139
139
|
: {};
|
|
140
|
-
return (<div className={"".concat(baseClasses, " ").concat(sizeClasses, " ").concat(bgClasses, " ").concat(fontClasses, " ").concat(borderClasses, " ").concat(hoverClasses, " ").concat(cursorClass, " ").concat(onClick ? focusRing : '', " ").concat(onClick && !isDisabled ? pressFeedbackAny : '')} {
|
|
140
|
+
return (<div className={"".concat(baseClasses, " ").concat(sizeClasses, " ").concat(bgClasses, " ").concat(fontClasses, " ").concat(borderClasses, " ").concat(hoverClasses, " ").concat(cursorClass, " ").concat(onClick ? focusRing : '', " ").concat(onClick && !isDisabled ? pressFeedbackAny : '')} aria-label={ariaLabel}
|
|
141
|
+
// A name on a plain div is not valid; a static tag with a name is an image of its label
|
|
142
|
+
role={!onClick && ariaLabel ? 'img' : undefined} {...interactiveProps}>
|
|
141
143
|
{variant === 'dot' && (<span className={"w-3 h-3 rounded-full flex-shrink-0 ".concat(dotColor)}/>)}
|
|
142
144
|
{variant !== 'dot' && <IconSlot icon={icon !== null && icon !== void 0 ? icon : iconName} className={"".concat(size === 'tiny' ? 'w-3 h-3' : 'w-4 h-4', " flex-shrink-0")}/>}
|
|
143
145
|
<div className="flex flex-col text-center">
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
interface TextFieldProps {
|
|
2
|
+
interface TextFieldProps extends Pick<React.AriaAttributes, 'aria-label' | 'aria-expanded' | 'aria-controls' | 'aria-activedescendant' | 'aria-autocomplete'> {
|
|
3
3
|
id: string;
|
|
4
4
|
label?: string;
|
|
5
5
|
value: string;
|
|
@@ -33,6 +33,16 @@ interface TextFieldProps {
|
|
|
33
33
|
minLength?: number;
|
|
34
34
|
/** Passed to the `<input>` or `<textarea>`. Left to the browser's default when not set. */
|
|
35
35
|
spellCheck?: boolean;
|
|
36
|
+
/** Id of the element that describes the field, e.g. a `FormField`'s help or error text. Read after the field's own helper text. */
|
|
37
|
+
'aria-describedby'?: string;
|
|
38
|
+
/** Marks the field invalid and draws the error border without the built-in error text, for a `FormField` that shows its own */
|
|
39
|
+
'aria-invalid'?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Passed to the `<input>` or `<textarea>`. `role="combobox"` with `aria-expanded`, `aria-controls`,
|
|
42
|
+
* `aria-activedescendant` and `aria-autocomplete` makes a search field that drives a list below it, as in a quick
|
|
43
|
+
* switcher. `aria-label` names a field that has no visible `label`, such as a search field.
|
|
44
|
+
*/
|
|
45
|
+
role?: React.AriaRole;
|
|
36
46
|
}
|
|
37
|
-
export default function TextField({ id, label, value, type, onChange, onBlur, onFocus, onKeyDown, onSubmit, autoFocus, multiline, maxRows, disabled, readOnly, error, errorText, helperText, required, size, placeholder, name, autoComplete, tabIndex, maxLength, minLength, spellCheck, }: TextFieldProps): React.JSX.Element;
|
|
47
|
+
export default function TextField({ id, label, value, type, onChange, onBlur, onFocus, onKeyDown, onSubmit, autoFocus, multiline, maxRows, disabled, readOnly, error, errorText, helperText, required, size, placeholder, name, autoComplete, tabIndex, maxLength, minLength, spellCheck, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, role, 'aria-label': ariaLabel, 'aria-expanded': ariaExpanded, 'aria-controls': ariaControls, 'aria-activedescendant': ariaActiveDescendant, 'aria-autocomplete': ariaAutocomplete, }: TextFieldProps): React.JSX.Element;
|
|
38
48
|
export {};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { stateTransition } from './sharedStyles';
|
|
4
4
|
export default function TextField(_a) {
|
|
5
|
-
var id = _a.id, label = _a.label, value = _a.value, _b = _a.type, type = _b === void 0 ? 'text' : _b, onChange = _a.onChange, onBlur = _a.onBlur, onFocus = _a.onFocus, onKeyDown = _a.onKeyDown, onSubmit = _a.onSubmit, _c = _a.autoFocus, autoFocus = _c === void 0 ? false : _c, _d = _a.multiline, multiline = _d === void 0 ? false : _d, _e = _a.maxRows, maxRows = _e === void 0 ? 6 : _e, _f = _a.disabled, disabled = _f === void 0 ? false : _f, _g = _a.readOnly, readOnly = _g === void 0 ? false : _g, _h = _a.error, error = _h === void 0 ? false : _h, _j = _a.errorText, errorText = _j === void 0 ? 'This field is required' : _j, helperText = _a.helperText, _k = _a.required, required = _k === void 0 ? false : _k, _l = _a.size, size = _l === void 0 ? 'medium' : _l, placeholder = _a.placeholder, name = _a.name, _m = _a.autoComplete, autoComplete = _m === void 0 ? 'off' : _m, tabIndex = _a.tabIndex, maxLength = _a.maxLength, minLength = _a.minLength, spellCheck = _a.spellCheck;
|
|
5
|
+
var id = _a.id, label = _a.label, value = _a.value, _b = _a.type, type = _b === void 0 ? 'text' : _b, onChange = _a.onChange, onBlur = _a.onBlur, onFocus = _a.onFocus, onKeyDown = _a.onKeyDown, onSubmit = _a.onSubmit, _c = _a.autoFocus, autoFocus = _c === void 0 ? false : _c, _d = _a.multiline, multiline = _d === void 0 ? false : _d, _e = _a.maxRows, maxRows = _e === void 0 ? 6 : _e, _f = _a.disabled, disabled = _f === void 0 ? false : _f, _g = _a.readOnly, readOnly = _g === void 0 ? false : _g, _h = _a.error, error = _h === void 0 ? false : _h, _j = _a.errorText, errorText = _j === void 0 ? 'This field is required' : _j, helperText = _a.helperText, _k = _a.required, required = _k === void 0 ? false : _k, _l = _a.size, size = _l === void 0 ? 'medium' : _l, placeholder = _a.placeholder, name = _a.name, _m = _a.autoComplete, autoComplete = _m === void 0 ? 'off' : _m, tabIndex = _a.tabIndex, maxLength = _a.maxLength, minLength = _a.minLength, spellCheck = _a.spellCheck, ariaDescribedBy = _a["aria-describedby"], _o = _a["aria-invalid"], ariaInvalid = _o === void 0 ? false : _o, role = _a.role, ariaLabel = _a["aria-label"], ariaExpanded = _a["aria-expanded"], ariaControls = _a["aria-controls"], ariaActiveDescendant = _a["aria-activedescendant"], ariaAutocomplete = _a["aria-autocomplete"];
|
|
6
6
|
var handleKeyDown = function (e) {
|
|
7
7
|
// Ctrl+Enter or Cmd+Enter to submit
|
|
8
8
|
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter' && onSubmit) {
|
|
@@ -26,7 +26,7 @@ export default function TextField(_a) {
|
|
|
26
26
|
: 'bg-background-default text-fg-primary';
|
|
27
27
|
// Border: error > focus (1px offset outline, the same weight as the border) > hover > default
|
|
28
28
|
var getBorderColor = function () {
|
|
29
|
-
if (error) {
|
|
29
|
+
if (error || ariaInvalid) {
|
|
30
30
|
return 'border-error-main focus:outline focus:outline-1 focus:outline-offset-2 focus:outline-error-main';
|
|
31
31
|
}
|
|
32
32
|
if (disabled) {
|
|
@@ -54,9 +54,16 @@ export default function TextField(_a) {
|
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
var containerClasses = "\n ".concat(colorClasses, "\n ").concat(baseClasses, "\n ").concat(sizeClasses, "\n ").concat(getBorderColor(), "\n ");
|
|
57
|
+
var ownDescription = error ? errorId : helperText ? helperId : undefined;
|
|
57
58
|
var errorProps = {
|
|
58
|
-
'aria-invalid': error || undefined,
|
|
59
|
-
'aria-describedby':
|
|
59
|
+
'aria-invalid': error || ariaInvalid || undefined,
|
|
60
|
+
'aria-describedby': [ownDescription, ariaDescribedBy].filter(Boolean).join(' ') || undefined,
|
|
61
|
+
role: role,
|
|
62
|
+
'aria-label': ariaLabel,
|
|
63
|
+
'aria-expanded': ariaExpanded,
|
|
64
|
+
'aria-controls': ariaControls,
|
|
65
|
+
'aria-activedescendant': ariaActiveDescendant,
|
|
66
|
+
'aria-autocomplete': ariaAutocomplete,
|
|
60
67
|
};
|
|
61
68
|
return (<div className="flex flex-col w-full">
|
|
62
69
|
{label && (<label htmlFor={id} className="mb-1 text-body2 text-fg-secondary">
|
|
@@ -26,6 +26,10 @@ interface TextareaProps {
|
|
|
26
26
|
maxLength?: number;
|
|
27
27
|
/** Passed to the `<textarea>`. Left to the browser's default when not set. */
|
|
28
28
|
spellCheck?: boolean;
|
|
29
|
+
/** Id of the element that describes the field, e.g. a `FormField`'s help or error text. Read after the field's own error text. */
|
|
30
|
+
'aria-describedby'?: string;
|
|
31
|
+
/** Marks the field invalid and draws the error border without the built-in error text, for a `FormField` that shows its own */
|
|
32
|
+
'aria-invalid'?: boolean;
|
|
29
33
|
}
|
|
30
|
-
export default function Textarea({ id, label, value, onChange, onBlur, onFocus, onKeyDown, onCompositionStart, onCompositionEnd, onSubmit, autoFocus, maxRows, disabled, error, errorText, size, placeholder, name, autoComplete, tabIndex, maxLength, spellCheck, }: TextareaProps): React.JSX.Element;
|
|
34
|
+
export default function Textarea({ id, label, value, onChange, onBlur, onFocus, onKeyDown, onCompositionStart, onCompositionEnd, onSubmit, autoFocus, maxRows, disabled, error, errorText, size, placeholder, name, autoComplete, tabIndex, maxLength, spellCheck, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, }: TextareaProps): React.JSX.Element;
|
|
31
35
|
export {};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import React, { useCallback, useEffect, useRef } from 'react';
|
|
3
3
|
import { stateTransition } from './sharedStyles';
|
|
4
|
+
import { fitToContent } from '../internal/autoGrow';
|
|
4
5
|
export default function Textarea(_a) {
|
|
5
|
-
var id = _a.id, label = _a.label, value = _a.value, onChange = _a.onChange, onBlur = _a.onBlur, onFocus = _a.onFocus, onKeyDown = _a.onKeyDown, onCompositionStart = _a.onCompositionStart, onCompositionEnd = _a.onCompositionEnd, onSubmit = _a.onSubmit, _b = _a.autoFocus, autoFocus = _b === void 0 ? false : _b, _c = _a.maxRows, maxRows = _c === void 0 ? 6 : _c, _d = _a.disabled, disabled = _d === void 0 ? false : _d, _e = _a.error, error = _e === void 0 ? false : _e, _f = _a.errorText, errorText = _f === void 0 ? 'This field is required' : _f, _g = _a.size, size = _g === void 0 ? 'medium' : _g, placeholder = _a.placeholder, name = _a.name, _h = _a.autoComplete, autoComplete = _h === void 0 ? 'off' : _h, tabIndex = _a.tabIndex, maxLength = _a.maxLength, spellCheck = _a.spellCheck;
|
|
6
|
+
var id = _a.id, label = _a.label, value = _a.value, onChange = _a.onChange, onBlur = _a.onBlur, onFocus = _a.onFocus, onKeyDown = _a.onKeyDown, onCompositionStart = _a.onCompositionStart, onCompositionEnd = _a.onCompositionEnd, onSubmit = _a.onSubmit, _b = _a.autoFocus, autoFocus = _b === void 0 ? false : _b, _c = _a.maxRows, maxRows = _c === void 0 ? 6 : _c, _d = _a.disabled, disabled = _d === void 0 ? false : _d, _e = _a.error, error = _e === void 0 ? false : _e, _f = _a.errorText, errorText = _f === void 0 ? 'This field is required' : _f, _g = _a.size, size = _g === void 0 ? 'medium' : _g, placeholder = _a.placeholder, name = _a.name, _h = _a.autoComplete, autoComplete = _h === void 0 ? 'off' : _h, tabIndex = _a.tabIndex, maxLength = _a.maxLength, spellCheck = _a.spellCheck, ariaDescribedBy = _a["aria-describedby"], _j = _a["aria-invalid"], ariaInvalid = _j === void 0 ? false : _j;
|
|
6
7
|
var textareaRef = useRef(null);
|
|
7
8
|
var handleKeyDown = function (e) {
|
|
8
9
|
// Ctrl+Enter or Cmd+Enter to submit
|
|
@@ -14,24 +15,8 @@ export default function Textarea(_a) {
|
|
|
14
15
|
onKeyDown(e);
|
|
15
16
|
};
|
|
16
17
|
var adjustHeight = useCallback(function () {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return;
|
|
20
|
-
textarea.style.height = 'auto'; // Reset height to calculate scrollHeight
|
|
21
|
-
var style = getComputedStyle(textarea);
|
|
22
|
-
var lineHeight = parseFloat(style.lineHeight);
|
|
23
|
-
// style.height is border-box, scrollHeight includes padding but not border
|
|
24
|
-
var paddingY = parseFloat(style.paddingTop) + parseFloat(style.paddingBottom);
|
|
25
|
-
var borderY = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);
|
|
26
|
-
var maxContentHeight = lineHeight * maxRows + paddingY;
|
|
27
|
-
var scrollHeight = textarea.scrollHeight;
|
|
28
|
-
// Fit the content, capped at maxRows, but at least 1 line
|
|
29
|
-
var contentHeight = Math.max(Math.min(scrollHeight, maxContentHeight), lineHeight + paddingY);
|
|
30
|
-
textarea.style.height = "".concat(contentHeight + borderY, "px");
|
|
31
|
-
// Enable vertical scroll if content exceeds maxRows (hide scrollbar)
|
|
32
|
-
textarea.style.overflowY = scrollHeight > maxContentHeight ? 'scroll' : 'hidden';
|
|
33
|
-
textarea.style.scrollbarWidth = 'none'; // Firefox
|
|
34
|
-
textarea.style.msOverflowStyle = 'none'; // IE/Edge
|
|
18
|
+
if (textareaRef.current)
|
|
19
|
+
fitToContent(textareaRef.current, maxRows);
|
|
35
20
|
}, [maxRows]);
|
|
36
21
|
// Also re-measure when the value changes from outside (e.g. cleared after submit)
|
|
37
22
|
useEffect(function () {
|
|
@@ -50,7 +35,7 @@ export default function Textarea(_a) {
|
|
|
50
35
|
: 'bg-background-default text-fg-primary';
|
|
51
36
|
// Border: error > focus (1px offset outline, the same weight as the border) > hover > default
|
|
52
37
|
var getBorderColor = function () {
|
|
53
|
-
if (error) {
|
|
38
|
+
if (error || ariaInvalid) {
|
|
54
39
|
return 'border-error-main focus:outline focus:outline-1 focus:outline-offset-2 focus:outline-error-main';
|
|
55
40
|
}
|
|
56
41
|
if (disabled) {
|
|
@@ -65,7 +50,7 @@ export default function Textarea(_a) {
|
|
|
65
50
|
{label}
|
|
66
51
|
</label>)}
|
|
67
52
|
<div className="relative">
|
|
68
|
-
<textarea ref={textareaRef} id={id} rows={1} className={containerClasses} value={value} onChange={onChange} onInput={adjustHeight} placeholder={placeholder} onFocus={onFocus} onBlur={onBlur} onKeyDown={handleKeyDown} onCompositionStart={onCompositionStart} onCompositionEnd={onCompositionEnd} autoFocus={autoFocus} disabled={disabled} name={name} autoComplete={autoComplete} tabIndex={tabIndex} maxLength={maxLength} spellCheck={spellCheck} aria-invalid={error || undefined} aria-describedby={error ? errorId : undefined}/>
|
|
53
|
+
<textarea ref={textareaRef} id={id} rows={1} className={containerClasses} value={value} onChange={onChange} onInput={adjustHeight} placeholder={placeholder} onFocus={onFocus} onBlur={onBlur} onKeyDown={handleKeyDown} onCompositionStart={onCompositionStart} onCompositionEnd={onCompositionEnd} autoFocus={autoFocus} disabled={disabled} name={name} autoComplete={autoComplete} tabIndex={tabIndex} maxLength={maxLength} spellCheck={spellCheck} aria-invalid={error || ariaInvalid || undefined} aria-describedby={[error ? errorId : undefined, ariaDescribedBy].filter(Boolean).join(' ') || undefined}/>
|
|
69
54
|
</div>
|
|
70
55
|
{error && (<p id={errorId} className="mt-1 text-error-text text-body2">
|
|
71
56
|
{errorText}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calls `onPress` when the person presses Cmd+`key` or Ctrl+`key` anywhere on the page, and stops when
|
|
3
|
+
* the component goes away. The browser's own action for the key (Ctrl+K focuses the address bar in some
|
|
4
|
+
* browsers) is stopped. It does nothing while the person is typing in a field, so a shortcut never
|
|
5
|
+
* steals a key from text editing; a field that wants it says so by handling the key itself.
|
|
6
|
+
*/
|
|
7
|
+
export default function useHotkey(key: string, onPress: () => void): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { isHotkey, isTypingTarget } from '../internal/hotkey';
|
|
4
|
+
/**
|
|
5
|
+
* Calls `onPress` when the person presses Cmd+`key` or Ctrl+`key` anywhere on the page, and stops when
|
|
6
|
+
* the component goes away. The browser's own action for the key (Ctrl+K focuses the address bar in some
|
|
7
|
+
* browsers) is stopped. It does nothing while the person is typing in a field, so a shortcut never
|
|
8
|
+
* steals a key from text editing; a field that wants it says so by handling the key itself.
|
|
9
|
+
*/
|
|
10
|
+
export default function useHotkey(key, onPress) {
|
|
11
|
+
// The newest callback is read at press time, so the listener is added once
|
|
12
|
+
var latest = useRef(onPress);
|
|
13
|
+
latest.current = onPress;
|
|
14
|
+
useEffect(function () {
|
|
15
|
+
var handle = function (e) {
|
|
16
|
+
if (!isHotkey(e, key) || isTypingTarget(e.target))
|
|
17
|
+
return;
|
|
18
|
+
e.preventDefault();
|
|
19
|
+
latest.current();
|
|
20
|
+
};
|
|
21
|
+
window.addEventListener('keydown', handle);
|
|
22
|
+
return function () { return window.removeEventListener('keydown', handle); };
|
|
23
|
+
}, [key]);
|
|
24
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { type IconSource } from './iconSlot';
|
|
2
3
|
interface UserImageProps {
|
|
3
4
|
userHandle: string;
|
|
4
5
|
userImgUrl?: string;
|
|
@@ -7,6 +8,13 @@ interface UserImageProps {
|
|
|
7
8
|
size?: number;
|
|
8
9
|
/** Passed to the `<img>`, e.g. `no-referrer` for hosts that refuse requests carrying a referrer */
|
|
9
10
|
referrerPolicy?: React.HTMLAttributeReferrerPolicy;
|
|
11
|
+
/** Shows this icon on the panel background in place of a picture or an initial: an agent's avatar. `userHandle` stays its accessible name. A Lucide name, an icon component or an element. */
|
|
12
|
+
icon?: IconSource;
|
|
13
|
+
/**
|
|
14
|
+
* Hides the avatar from assistive tech (`aria-hidden`, no name, an empty `alt` on a picture), for an
|
|
15
|
+
* avatar that sits beside the same name in text, so the name is not read twice. All three forms.
|
|
16
|
+
*/
|
|
17
|
+
decorative?: boolean;
|
|
10
18
|
}
|
|
11
|
-
export default function UserImage({ userHandle, userImgUrl, grayscale, size, referrerPolicy, }: UserImageProps): React.JSX.Element;
|
|
19
|
+
export default function UserImage({ userHandle, userImgUrl, grayscale, size, referrerPolicy, icon, decorative, }: UserImageProps): React.JSX.Element;
|
|
12
20
|
export {};
|
|
@@ -11,6 +11,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
import React from 'react';
|
|
14
|
+
import IconSlot from './iconSlot';
|
|
14
15
|
function getColorSeed(userHandle) {
|
|
15
16
|
var words = userHandle.trim().split(/\s+/);
|
|
16
17
|
var letters = words.map(function (word) { return word.charAt(0).toLowerCase(); });
|
|
@@ -33,7 +34,13 @@ function getHash(str) {
|
|
|
33
34
|
return hash;
|
|
34
35
|
}
|
|
35
36
|
export default function UserImage(_a) {
|
|
36
|
-
var userHandle = _a.userHandle, userImgUrl = _a.userImgUrl, _b = _a.grayscale, grayscale = _b === void 0 ? false : _b, size = _a.size, referrerPolicy = _a.referrerPolicy;
|
|
37
|
+
var userHandle = _a.userHandle, userImgUrl = _a.userImgUrl, _b = _a.grayscale, grayscale = _b === void 0 ? false : _b, size = _a.size, referrerPolicy = _a.referrerPolicy, icon = _a.icon, _c = _a.decorative, decorative = _c === void 0 ? false : _c;
|
|
38
|
+
if (icon) {
|
|
39
|
+
var diameter = size !== null && size !== void 0 ? size : 24;
|
|
40
|
+
return (<div role={decorative ? undefined : 'img'} aria-label={decorative ? undefined : userHandle} aria-hidden={decorative || undefined} style={size !== undefined ? { width: size, height: size } : undefined} className="flex items-center justify-center flex-shrink-0 w-6 h-6 rounded-full overflow-hidden bg-secondary-main text-secondary-contrast">
|
|
41
|
+
<IconSlot icon={icon} size={Math.round(diameter / 2)}/>
|
|
42
|
+
</div>);
|
|
43
|
+
}
|
|
37
44
|
var displayInitial = userHandle.charAt(0).toUpperCase() || 'A';
|
|
38
45
|
var seed = getColorSeed(userHandle);
|
|
39
46
|
var hue = Math.abs(getHash(seed)) % 360;
|
|
@@ -47,8 +54,8 @@ export default function UserImage(_a) {
|
|
|
47
54
|
return (
|
|
48
55
|
// Per-user hue computed in JS, not a theme token, so the dark: variant stays here (one of the two documented
|
|
49
56
|
// `dark:` exemptions, see the overlay rings in Menu/Popover/Modal). The dark: variant follows whatever dark variant the app's preset/@theme defines (class-only or OS-aware).
|
|
50
|
-
<div style={__assign({ '--light-bg': lightBg, '--dark-bg': darkBg }, (size !== undefined && { width: size, height: size, fontSize: (size * 2) / 3 }))} className="flex items-center justify-center w-6 h-6 rounded-full overflow-hidden bg-[var(--light-bg)] dark:bg-[var(--dark-bg)] text-fg-primary">
|
|
51
|
-
{userImgUrl ? (<img src={userImgUrl} alt={userHandle} referrerPolicy={referrerPolicy} className="w-full h-full object-cover rounded-full"/>) : (<span className={"".concat(size === undefined ? 'text-body1' : 'leading-none', " text-fg-primary")}>
|
|
57
|
+
<div aria-hidden={decorative || undefined} style={__assign({ '--light-bg': lightBg, '--dark-bg': darkBg }, (size !== undefined && { width: size, height: size, fontSize: (size * 2) / 3 }))} className="flex items-center justify-center w-6 h-6 rounded-full overflow-hidden bg-[var(--light-bg)] dark:bg-[var(--dark-bg)] text-fg-primary">
|
|
58
|
+
{userImgUrl ? (<img src={userImgUrl} alt={decorative ? '' : userHandle} referrerPolicy={referrerPolicy} className="w-full h-full object-cover rounded-full"/>) : (<span className={"".concat(size === undefined ? 'text-body1' : 'leading-none', " text-fg-primary")}>
|
|
52
59
|
{displayInitial}
|
|
53
60
|
</span>)}
|
|
54
61
|
</div>);
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ import './designTokens';
|
|
|
2
2
|
export * from './components/alert';
|
|
3
3
|
export * from './components/button';
|
|
4
4
|
export * from './components/checkBox';
|
|
5
|
+
export * from './components/copyField';
|
|
5
6
|
export * from './components/emptyBox';
|
|
7
|
+
export * from './components/formField';
|
|
6
8
|
export * from './components/iconButton';
|
|
7
9
|
export * from './components/layout';
|
|
8
10
|
export * from './components/loadingScreen';
|
|
@@ -13,7 +15,10 @@ export * from './components/navigation';
|
|
|
13
15
|
export * from './components/popover';
|
|
14
16
|
export * from './components/radioGroup';
|
|
15
17
|
export * from './components/sectionIntro';
|
|
18
|
+
export * from './components/segmentedControl';
|
|
16
19
|
export * from './components/select';
|
|
20
|
+
export * from './components/settingsSection';
|
|
21
|
+
export * from './components/switch';
|
|
17
22
|
export * from './components/tab';
|
|
18
23
|
export * from './components/tableCell';
|
|
19
24
|
export * from './components/tableContainer';
|
|
@@ -28,3 +33,4 @@ export * from './components/timeStamp';
|
|
|
28
33
|
export * from './components/tooltip';
|
|
29
34
|
export * from './components/userImage';
|
|
30
35
|
export { default as useDarkMode, resolveDarkMode } from './components/useDarkMode';
|
|
36
|
+
export { default as useHotkey } from './components/useHotkey';
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,9 @@ import './designTokens';
|
|
|
2
2
|
export * from './components/alert';
|
|
3
3
|
export * from './components/button';
|
|
4
4
|
export * from './components/checkBox';
|
|
5
|
+
export * from './components/copyField';
|
|
5
6
|
export * from './components/emptyBox';
|
|
7
|
+
export * from './components/formField';
|
|
6
8
|
export * from './components/iconButton';
|
|
7
9
|
export * from './components/layout';
|
|
8
10
|
export * from './components/loadingScreen';
|
|
@@ -13,7 +15,10 @@ export * from './components/navigation';
|
|
|
13
15
|
export * from './components/popover';
|
|
14
16
|
export * from './components/radioGroup';
|
|
15
17
|
export * from './components/sectionIntro';
|
|
18
|
+
export * from './components/segmentedControl';
|
|
16
19
|
export * from './components/select';
|
|
20
|
+
export * from './components/settingsSection';
|
|
21
|
+
export * from './components/switch';
|
|
17
22
|
export * from './components/tab';
|
|
18
23
|
export * from './components/tableCell';
|
|
19
24
|
export * from './components/tableContainer';
|
|
@@ -28,3 +33,4 @@ export * from './components/timeStamp';
|
|
|
28
33
|
export * from './components/tooltip';
|
|
29
34
|
export * from './components/userImage';
|
|
30
35
|
export { default as useDarkMode, resolveDarkMode } from './components/useDarkMode';
|
|
36
|
+
export { default as useHotkey } from './components/useHotkey';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function fitHeight({ scrollHeight, lineHeight, paddingY, borderY, maxRows, }: {
|
|
2
|
+
scrollHeight: number;
|
|
3
|
+
lineHeight: number;
|
|
4
|
+
paddingY: number;
|
|
5
|
+
borderY: number;
|
|
6
|
+
maxRows: number;
|
|
7
|
+
}): {
|
|
8
|
+
height: number;
|
|
9
|
+
scroll: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function fitToContent(textarea: HTMLTextAreaElement, maxRows: number): void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// The auto-grow Textarea and Composer share: the text area fits its content, at least one line
|
|
2
|
+
// and at most maxRows, and scrolls past that. Kept out of the public API.
|
|
3
|
+
// The height to set (border-box) and whether the content needs to scroll
|
|
4
|
+
export function fitHeight(_a) {
|
|
5
|
+
var scrollHeight = _a.scrollHeight, lineHeight = _a.lineHeight, paddingY = _a.paddingY, borderY = _a.borderY, maxRows = _a.maxRows;
|
|
6
|
+
var maxContentHeight = lineHeight * maxRows + paddingY;
|
|
7
|
+
// Fit the content, capped at maxRows, but at least 1 line
|
|
8
|
+
var contentHeight = Math.max(Math.min(scrollHeight, maxContentHeight), lineHeight + paddingY);
|
|
9
|
+
return { height: contentHeight + borderY, scroll: scrollHeight > maxContentHeight };
|
|
10
|
+
}
|
|
11
|
+
// Measures the text area and sets its height. Call it from an effect or an event, never at module scope.
|
|
12
|
+
export function fitToContent(textarea, maxRows) {
|
|
13
|
+
textarea.style.height = 'auto'; // Reset height to calculate scrollHeight
|
|
14
|
+
var style = getComputedStyle(textarea);
|
|
15
|
+
// style.height is border-box, scrollHeight includes padding but not border
|
|
16
|
+
var _a = fitHeight({
|
|
17
|
+
scrollHeight: textarea.scrollHeight,
|
|
18
|
+
lineHeight: parseFloat(style.lineHeight),
|
|
19
|
+
paddingY: parseFloat(style.paddingTop) + parseFloat(style.paddingBottom),
|
|
20
|
+
borderY: parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth),
|
|
21
|
+
maxRows: maxRows,
|
|
22
|
+
}), height = _a.height, scroll = _a.scroll;
|
|
23
|
+
textarea.style.height = "".concat(height, "px");
|
|
24
|
+
// Enable vertical scroll if content exceeds maxRows (hide scrollbar)
|
|
25
|
+
textarea.style.overflowY = scroll ? 'scroll' : 'hidden';
|
|
26
|
+
textarea.style.scrollbarWidth = 'none'; // Firefox
|
|
27
|
+
textarea.style.msOverflowStyle = 'none'; // IE/Edge
|
|
28
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function isComposing({ composing, nativeIsComposing, keyCode }: {
|
|
2
|
+
composing: boolean;
|
|
3
|
+
nativeIsComposing: boolean;
|
|
4
|
+
keyCode: number;
|
|
5
|
+
}): boolean;
|
|
6
|
+
export declare function shouldSubmit({ key, shiftKey, metaKey, ctrlKey, isComposing, canSubmit, disabled, sending, submitOnEnter, }: {
|
|
7
|
+
key: string;
|
|
8
|
+
shiftKey: boolean;
|
|
9
|
+
metaKey: boolean;
|
|
10
|
+
ctrlKey: boolean;
|
|
11
|
+
isComposing: boolean;
|
|
12
|
+
canSubmit: boolean;
|
|
13
|
+
disabled: boolean;
|
|
14
|
+
sending: boolean;
|
|
15
|
+
submitOnEnter: boolean;
|
|
16
|
+
}): boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Composer's pure helpers, kept out of the public API (index.ts and the package exports do not reach internal/)
|
|
2
|
+
// Whether an input method (Korean, Japanese, Chinese) is composing text, so Enter confirms the
|
|
3
|
+
// text and must not send. Any one sign is enough: the composition events, the event's own flag,
|
|
4
|
+
// and keyCode 229, which Safari gives the Enter that ends a composition after compositionend
|
|
5
|
+
// has fired and while isComposing is already false.
|
|
6
|
+
export function isComposing(_a) {
|
|
7
|
+
var composing = _a.composing, nativeIsComposing = _a.nativeIsComposing, keyCode = _a.keyCode;
|
|
8
|
+
return composing || nativeIsComposing || keyCode === 229;
|
|
9
|
+
}
|
|
10
|
+
// Whether this key press sends the message. Cmd+Enter and Ctrl+Enter always do; plain Enter does
|
|
11
|
+
// when `submitOnEnter` is on and Shift is not held. Never while an input method is composing, when
|
|
12
|
+
// there is nothing to send (`canSubmit` false), or while the Composer is disabled or sending.
|
|
13
|
+
export function shouldSubmit(_a) {
|
|
14
|
+
var key = _a.key, shiftKey = _a.shiftKey, metaKey = _a.metaKey, ctrlKey = _a.ctrlKey, isComposing = _a.isComposing, canSubmit = _a.canSubmit, disabled = _a.disabled, sending = _a.sending, submitOnEnter = _a.submitOnEnter;
|
|
15
|
+
if (key !== 'Enter' || isComposing || !canSubmit || disabled || sending)
|
|
16
|
+
return false;
|
|
17
|
+
return metaKey || ctrlKey || (submitOnEnter && !shiftKey);
|
|
18
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// CopyField's clipboard write, kept out of the public API.
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
// True only after the clipboard accepted the text. A missing clipboard, a refusal and a throw all give false.
|
|
39
|
+
export function copyText(clipboard, text) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
41
|
+
var _a;
|
|
42
|
+
return __generator(this, function (_b) {
|
|
43
|
+
switch (_b.label) {
|
|
44
|
+
case 0:
|
|
45
|
+
if (!clipboard || typeof clipboard.writeText !== 'function')
|
|
46
|
+
return [2 /*return*/, false];
|
|
47
|
+
_b.label = 1;
|
|
48
|
+
case 1:
|
|
49
|
+
_b.trys.push([1, 3, , 4]);
|
|
50
|
+
return [4 /*yield*/, clipboard.writeText(text)];
|
|
51
|
+
case 2:
|
|
52
|
+
_b.sent();
|
|
53
|
+
return [2 /*return*/, true];
|
|
54
|
+
case 3:
|
|
55
|
+
_a = _b.sent();
|
|
56
|
+
return [2 /*return*/, false];
|
|
57
|
+
case 4: return [2 /*return*/];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface HotkeyEvent {
|
|
2
|
+
key: string;
|
|
3
|
+
code?: string;
|
|
4
|
+
metaKey: boolean;
|
|
5
|
+
ctrlKey: boolean;
|
|
6
|
+
altKey: boolean;
|
|
7
|
+
shiftKey: boolean;
|
|
8
|
+
isComposing: boolean;
|
|
9
|
+
repeat: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function isHotkey(e: HotkeyEvent, key: string): boolean;
|
|
12
|
+
export declare function isTypingTarget(target: {
|
|
13
|
+
tagName: string;
|
|
14
|
+
isContentEditable: boolean;
|
|
15
|
+
} | null): boolean;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// useHotkey's pure helpers, kept out of the public API (index.ts and the package exports do not reach internal/)
|
|
2
|
+
// True for Cmd+key or Ctrl+key and nothing more: not with Shift or Alt, not while an input method
|
|
3
|
+
// composes, and not for a key held down. When e.key is not a Latin letter (a non-Latin layout, where it is
|
|
4
|
+
// 'л' or 'ㅏ'), a single letter also matches its physical key (e.code 'KeyK'). A Latin e.key always wins, so
|
|
5
|
+
// Dvorak's Cmd+T (physical KeyK) and AZERTY's Cmd+A (physical KeyQ) do not fire the K or Q shortcut.
|
|
6
|
+
export function isHotkey(e, key) {
|
|
7
|
+
if (e.altKey || e.shiftKey || e.isComposing || e.repeat)
|
|
8
|
+
return false;
|
|
9
|
+
if (!(e.metaKey || e.ctrlKey))
|
|
10
|
+
return false;
|
|
11
|
+
if (e.key.toLowerCase() === key.toLowerCase())
|
|
12
|
+
return true;
|
|
13
|
+
return !/^[a-z]$/i.test(e.key) && /^[a-z]$/i.test(key) && e.code === "Key".concat(key.toUpperCase());
|
|
14
|
+
}
|
|
15
|
+
// True when the target takes typed text, where a shortcut could be meant as text editing.
|
|
16
|
+
export function isTypingTarget(target) {
|
|
17
|
+
if (!target)
|
|
18
|
+
return false;
|
|
19
|
+
return target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName);
|
|
20
|
+
}
|