oneslash-design-system 2.17.0 → 2.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/DESIGN.md +55 -14
- package/dist/cases/accept-invite.md +1 -5
- package/dist/cases/account-menu/menu.d.ts +1 -0
- package/dist/cases/account-menu/menu.jsx +99 -0
- package/dist/cases/account-menu.md +164 -0
- package/dist/cases/agent-asks-before-risky-action.md +0 -4
- package/dist/cases/agent-cancels-when-unanswered.md +0 -4
- package/dist/cases/agent-options.md +0 -4
- package/dist/cases/agent-pending-reply.md +0 -4
- package/dist/cases/agent-plan-proposal.md +0 -4
- package/dist/cases/agent-question.md +0 -4
- package/dist/cases/agent-refuses-clearly.md +0 -4
- package/dist/cases/agent-says-what-it-is.md +0 -2
- package/dist/cases/agent-settings/form.d.ts +1 -0
- package/dist/cases/agent-settings/form.jsx +164 -0
- package/dist/cases/agent-settings.md +259 -0
- package/dist/cases/agent-shows-progress.md +0 -2
- package/dist/cases/agent-shows-sources.md +0 -2
- package/dist/cases/api-keys/list.d.ts +1 -0
- package/dist/cases/api-keys/list.jsx +162 -0
- package/dist/cases/api-keys.md +229 -0
- package/dist/cases/app-shell/sidebar.d.ts +1 -0
- package/dist/cases/app-shell/sidebar.jsx +124 -0
- package/dist/cases/app-shell/top-tabs.d.ts +1 -0
- package/dist/cases/app-shell/top-tabs.jsx +106 -0
- package/dist/cases/app-shell.md +364 -0
- package/dist/cases/artifact-card/card.jsx +32 -6
- package/dist/cases/artifact-card.md +55 -11
- package/dist/cases/auth-gate-loading.md +0 -4
- package/dist/cases/check-your-email.md +0 -4
- package/dist/cases/collapsible-search/popover.d.ts +1 -0
- package/dist/cases/collapsible-search/popover.jsx +74 -0
- package/dist/cases/collapsible-search.md +143 -0
- package/dist/cases/composer-limit.md +0 -4
- package/dist/cases/confirm-destructive-action.md +0 -4
- package/dist/cases/confirm-dialogs.md +0 -4
- package/dist/cases/conversation-starters.md +0 -4
- package/dist/cases/create-modal.md +0 -4
- package/dist/cases/danger-zone/collapsed.d.ts +1 -0
- package/dist/cases/danger-zone/collapsed.jsx +75 -0
- package/dist/cases/danger-zone/shown.d.ts +1 -0
- package/dist/cases/danger-zone/shown.jsx +95 -0
- package/dist/cases/danger-zone.md +263 -0
- package/dist/cases/device-login.md +0 -4
- package/dist/cases/email-confirmed.md +0 -4
- package/dist/cases/empty-list.md +0 -4
- package/dist/cases/empty-lists.md +0 -4
- package/dist/cases/empty-not-set-up.md +0 -4
- package/dist/cases/empty-search.md +0 -4
- package/dist/cases/error-page/in-shell.jsx +26 -17
- package/dist/cases/error-page.md +42 -25
- package/dist/cases/feedback-form.md +0 -4
- package/dist/cases/filter-menu/presets.d.ts +1 -0
- package/dist/cases/filter-menu/presets.jsx +53 -0
- package/dist/cases/filter-menu/with-clear.d.ts +1 -0
- package/dist/cases/filter-menu/with-clear.jsx +56 -0
- package/dist/cases/filter-menu.md +204 -0
- package/dist/cases/forgot-password.md +0 -4
- package/dist/cases/form-errors.md +0 -4
- package/dist/cases/import-checklist.md +0 -4
- package/dist/cases/inline-form-feedback.md +0 -4
- package/dist/cases/integrations-list/nested.d.ts +1 -0
- package/dist/cases/integrations-list/nested.jsx +164 -0
- package/dist/cases/integrations-list/rows.d.ts +1 -0
- package/dist/cases/integrations-list/rows.jsx +134 -0
- package/dist/cases/integrations-list.md +379 -0
- package/dist/cases/invite-member.md +0 -4
- package/dist/cases/load-failure.md +0 -4
- package/dist/cases/log-out-confirm.md +0 -4
- package/dist/cases/login-page.md +0 -4
- package/dist/cases/master-detail/list-then-page.d.ts +1 -0
- package/dist/cases/master-detail/list-then-page.jsx +65 -0
- package/dist/cases/master-detail/split.d.ts +1 -0
- package/dist/cases/master-detail/split.jsx +49 -0
- package/dist/cases/master-detail.md +213 -0
- package/dist/cases/members-list/rows.d.ts +1 -0
- package/dist/cases/members-list/rows.jsx +318 -0
- package/dist/cases/members-list/table.d.ts +1 -0
- package/dist/cases/members-list/table.jsx +351 -0
- package/dist/cases/members-list.md +799 -0
- package/dist/cases/mention-list.md +0 -4
- package/dist/cases/message-actions.md +0 -4
- package/dist/cases/message-attachments.md +0 -4
- package/dist/cases/message-composer.md +0 -4
- package/dist/cases/message-edit.md +0 -4
- package/dist/cases/message-reactions.md +0 -4
- package/dist/cases/message-row.md +0 -4
- package/dist/cases/mobile-menu/links.d.ts +1 -0
- package/dist/cases/mobile-menu/links.jsx +24 -0
- package/dist/cases/mobile-menu/sections.d.ts +1 -0
- package/dist/cases/mobile-menu/sections.jsx +61 -0
- package/dist/cases/mobile-menu.md +170 -0
- package/dist/cases/not-found-page/in-shell.jsx +26 -17
- package/dist/cases/not-found-page.md +41 -24
- package/dist/cases/notification-menu/menu.d.ts +1 -0
- package/dist/cases/notification-menu/menu.jsx +74 -0
- package/dist/cases/notification-menu.md +135 -0
- package/dist/cases/oauth-consent.md +0 -4
- package/dist/cases/on-off-settings/list.d.ts +1 -0
- package/dist/cases/on-off-settings/list.jsx +97 -0
- package/dist/cases/on-off-settings.md +116 -0
- package/dist/cases/on-this-page/aside.d.ts +1 -0
- package/dist/cases/on-this-page/aside.jsx +39 -0
- package/dist/cases/on-this-page.md +80 -0
- package/dist/cases/overflow-menu/in-a-header.d.ts +1 -0
- package/dist/cases/overflow-menu/in-a-header.jsx +128 -0
- package/dist/cases/overflow-menu/on-a-row.d.ts +1 -0
- package/dist/cases/overflow-menu/on-a-row.jsx +183 -0
- package/dist/cases/overflow-menu.md +410 -0
- package/dist/cases/page-header/actions.d.ts +1 -0
- package/dist/cases/page-header/actions.jsx +65 -0
- package/dist/cases/page-header/sub-page.d.ts +1 -0
- package/dist/cases/page-header/sub-page.jsx +37 -0
- package/dist/cases/page-header.md +195 -0
- package/dist/cases/phone-navigation.md +32 -0
- package/dist/cases/profile-form/form.d.ts +1 -0
- package/dist/cases/profile-form/form.jsx +153 -0
- package/dist/cases/profile-form.md +236 -0
- package/dist/cases/quick-switcher/modal.d.ts +1 -0
- package/dist/cases/quick-switcher/modal.jsx +114 -0
- package/dist/cases/quick-switcher.md +205 -0
- package/dist/cases/range-switch/segmented.d.ts +1 -0
- package/dist/cases/range-switch/segmented.jsx +30 -0
- package/dist/cases/range-switch.md +67 -0
- package/dist/cases/rename.md +0 -4
- package/dist/cases/reply-feedback.md +0 -4
- package/dist/cases/reply-sources.md +0 -4
- package/dist/cases/route-loading/region.jsx +27 -18
- package/dist/cases/route-loading.md +42 -23
- package/dist/cases/scope-picker/menu.d.ts +1 -0
- package/dist/cases/scope-picker/menu.jsx +47 -0
- package/dist/cases/scope-picker.md +97 -0
- package/dist/cases/set-new-password.md +0 -4
- package/dist/cases/settings-page/side-nav.d.ts +1 -0
- package/dist/cases/settings-page/side-nav.jsx +171 -0
- package/dist/cases/settings-page/top-tabs.d.ts +1 -0
- package/dist/cases/settings-page/top-tabs.jsx +129 -0
- package/dist/cases/settings-page.md +378 -0
- package/dist/cases/settings-save.md +35 -0
- package/dist/cases/side-pane/beside.d.ts +1 -0
- package/dist/cases/side-pane/beside.jsx +79 -0
- package/dist/cases/side-pane/over.d.ts +1 -0
- package/dist/cases/side-pane/over.jsx +58 -0
- package/dist/cases/side-pane.md +238 -0
- package/dist/cases/sidebar-nav/flat.d.ts +1 -0
- package/dist/cases/sidebar-nav/flat.jsx +81 -0
- package/dist/cases/sidebar-nav/nested.d.ts +1 -0
- package/dist/cases/sidebar-nav/nested.jsx +122 -0
- package/dist/cases/sidebar-nav.md +261 -0
- package/dist/cases/sign-up-page.md +1 -5
- package/dist/cases/site-footer/columns.d.ts +1 -0
- package/dist/cases/site-footer/columns.jsx +51 -0
- package/dist/cases/site-footer/simple.d.ts +1 -0
- package/dist/cases/site-footer/simple.jsx +24 -0
- package/dist/cases/site-footer.md +133 -0
- package/dist/cases/site-header/links.d.ts +1 -0
- package/dist/cases/site-header/links.jsx +26 -0
- package/dist/cases/site-header/sections.d.ts +1 -0
- package/dist/cases/site-header/sections.jsx +64 -0
- package/dist/cases/site-header.md +183 -0
- package/dist/cases/slash-command-list.md +0 -4
- package/dist/cases/success-feedback.md +0 -4
- package/dist/cases/tag-filter/tags.d.ts +1 -0
- package/dist/cases/tag-filter/tags.jsx +226 -0
- package/dist/cases/tag-filter.md +298 -0
- package/dist/cases/theme-switcher/menu.d.ts +1 -0
- package/dist/cases/theme-switcher/menu.jsx +47 -0
- package/dist/cases/theme-switcher/segmented.d.ts +1 -0
- package/dist/cases/theme-switcher/segmented.jsx +26 -0
- package/dist/cases/theme-switcher.md +149 -0
- package/dist/cases/type-to-confirm.md +0 -4
- package/dist/cases/typing-and-status.md +0 -4
- package/dist/cases/unsaved-changes-guard.md +0 -4
- package/dist/cases/upgrade-prompt.md +0 -4
- package/dist/cases.json +1737 -315
- package/dist/components/alert.d.ts +3 -1
- package/dist/components/alert.jsx +2 -2
- package/dist/components/appShell.d.ts +44 -0
- package/dist/components/appShell.jsx +121 -0
- package/dist/components/button.jsx +5 -2
- package/dist/components/checkBox.d.ts +5 -1
- package/dist/components/checkBox.jsx +2 -2
- package/dist/components/copyField.d.ts +20 -0
- package/dist/components/copyField.jsx +99 -0
- package/dist/components/drawer.d.ts +31 -0
- package/dist/components/drawer.jsx +121 -0
- package/dist/components/formField.d.ts +34 -0
- package/dist/components/formField.jsx +28 -0
- package/dist/components/heading.d.ts +5 -1
- package/dist/components/heading.jsx +2 -2
- package/dist/components/link.d.ts +6 -1
- package/dist/components/link.jsx +11 -3
- package/dist/components/menu.jsx +2 -2
- package/dist/components/menuItem.d.ts +10 -2
- package/dist/components/menuItem.jsx +4 -3
- package/dist/components/modal.jsx +12 -23
- package/dist/components/navigation.d.ts +9 -1
- package/dist/components/navigation.jsx +15 -3
- package/dist/components/onThisPage.d.ts +29 -0
- package/dist/components/onThisPage.jsx +151 -0
- package/dist/components/pageShell.d.ts +7 -1
- package/dist/components/pageShell.jsx +14 -1
- package/dist/components/popover.jsx +4 -0
- package/dist/components/radioGroup.d.ts +5 -1
- package/dist/components/radioGroup.jsx +2 -2
- package/dist/components/segmentedControl.d.ts +22 -0
- package/dist/components/segmentedControl.jsx +54 -0
- package/dist/components/select.d.ts +5 -1
- package/dist/components/select.jsx +2 -2
- package/dist/components/settingsSection.d.ts +36 -0
- package/dist/components/settingsSection.jsx +65 -0
- package/dist/components/sidePane.d.ts +32 -0
- package/dist/components/sidePane.jsx +128 -0
- package/dist/components/siteFooter.d.ts +24 -0
- package/dist/components/siteFooter.jsx +48 -0
- package/dist/components/siteHeader.d.ts +55 -0
- package/dist/components/siteHeader.jsx +125 -0
- package/dist/components/slidingIndicator.d.ts +50 -0
- package/dist/components/slidingIndicator.jsx +102 -0
- package/dist/components/switch.d.ts +25 -0
- package/dist/components/switch.jsx +55 -0
- package/dist/components/tab.jsx +5 -11
- package/dist/components/tabsContainer.jsx +5 -67
- package/dist/components/textField.d.ts +12 -2
- package/dist/components/textField.jsx +11 -4
- package/dist/components/textarea.d.ts +5 -1
- package/dist/components/textarea.jsx +3 -3
- package/dist/components/titleBar.d.ts +17 -0
- package/dist/components/titleBar.jsx +17 -0
- package/dist/components/useHotkey.d.ts +7 -0
- package/dist/components/useHotkey.js +24 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/internal/copyField.d.ts +5 -0
- package/dist/internal/copyField.js +61 -0
- package/dist/internal/hotkey.d.ts +16 -0
- package/dist/internal/hotkey.js +20 -0
- package/dist/internal/overlayStack.d.ts +24 -0
- package/dist/internal/overlayStack.js +71 -0
- package/dist/internal/resize.d.ts +9 -0
- package/dist/internal/resize.js +31 -0
- package/dist/internal/scrollSpy.d.ts +24 -0
- package/dist/internal/scrollSpy.js +53 -0
- package/dist/internal/siteBrand.d.ts +6 -0
- package/dist/internal/siteBrand.jsx +11 -0
- package/dist/internal/switch.d.ts +5 -0
- package/dist/internal/switch.js +9 -0
- package/dist/native-mapping.json +72 -0
- package/dist/stories/AppShell.stories.d.ts +15 -0
- package/dist/stories/AppShell.stories.jsx +137 -0
- package/dist/stories/Cases.generated.stories.d.ts +42 -0
- package/dist/stories/Cases.generated.stories.jsx +84 -0
- package/dist/stories/CopyField.stories.d.ts +11 -0
- package/dist/stories/CopyField.stories.jsx +65 -0
- package/dist/stories/Drawer.stories.d.ts +10 -0
- package/dist/stories/Drawer.stories.jsx +123 -0
- package/dist/stories/FormField.stories.d.ts +6 -0
- package/dist/stories/FormField.stories.jsx +44 -0
- package/dist/stories/Link.stories.d.ts +1 -0
- package/dist/stories/Link.stories.jsx +8 -0
- package/dist/stories/Navigation.stories.d.ts +1 -0
- package/dist/stories/Navigation.stories.jsx +17 -1
- package/dist/stories/OnThisPage.stories.d.ts +10 -0
- package/dist/stories/OnThisPage.stories.jsx +105 -0
- package/dist/stories/SegmentedControl.stories.d.ts +8 -0
- package/dist/stories/SegmentedControl.stories.jsx +33 -0
- package/dist/stories/SettingsSection.stories.d.ts +12 -0
- package/dist/stories/SettingsSection.stories.jsx +91 -0
- package/dist/stories/SidePane.stories.d.ts +6 -0
- package/dist/stories/SidePane.stories.jsx +37 -0
- package/dist/stories/SiteFooter.stories.d.ts +7 -0
- package/dist/stories/SiteFooter.stories.jsx +63 -0
- package/dist/stories/SiteHeader.stories.d.ts +10 -0
- package/dist/stories/SiteHeader.stories.jsx +94 -0
- package/dist/stories/Switch.stories.d.ts +14 -0
- package/dist/stories/Switch.stories.jsx +87 -0
- package/dist/stories/TextField.stories.d.ts +1 -0
- package/dist/stories/TextField.stories.jsx +13 -0
- package/dist/stories/TitleBar.stories.d.ts +6 -0
- package/dist/stories/TitleBar.stories.jsx +34 -0
- package/package.json +5 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
// What TabsContainer and SegmentedControl share: the track classes, the sliding pill behind the
|
|
3
|
+
// selected item, and the item classes and sizes. Not exported from the package index. It lives in
|
|
4
|
+
// components/ like sharedStyles, so the class names in it are found by the Tailwind scan.
|
|
5
|
+
import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
6
|
+
import { focusRing, pressFeedbackAny, stateTransition } from './sharedStyles';
|
|
7
|
+
// useLayoutEffect warns on a server render, where it cannot run; useEffect is the same there and silent
|
|
8
|
+
var useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
|
|
9
|
+
/** The track around the items. `filled` is false for an empty track, which stays transparent. */
|
|
10
|
+
export function segmentTrackClasses(fill, filled) {
|
|
11
|
+
return "\n relative flex gap-0.5 p-1 rounded-container overflow-x-auto".concat(fill ? ' w-full' : '', "\n ").concat(filled ? 'bg-background-accent100' : 'bg-transparent', "\n ");
|
|
12
|
+
}
|
|
13
|
+
export var segmentTrackStyle = {
|
|
14
|
+
scrollbarWidth: 'none',
|
|
15
|
+
msOverflowStyle: 'none',
|
|
16
|
+
};
|
|
17
|
+
/** The classes every item has, selected or not */
|
|
18
|
+
export function segmentItemClasses(fill, sizeClass, selectedClasses) {
|
|
19
|
+
return "\n relative flex items-center space-x-1 rounded-control cursor-pointer ".concat(fill ? 'flex-1 justify-center' : 'justify-start', " ").concat(stateTransition, " ").concat(pressFeedbackAny, " ").concat(focusRing, "\n ").concat(sizeClass, "\n ").concat(selectedClasses, "\n ");
|
|
20
|
+
}
|
|
21
|
+
/** Item text and icon sizes. Items use `data-tab-selected="true"` on the selected one. */
|
|
22
|
+
export var segmentSizes = {
|
|
23
|
+
medium: { tab: 'py-1 px-[6px]', label: 'px-[6px] text-body1', secondLabel: 'text-body2', icon: 'w-6 h-6' },
|
|
24
|
+
small: { tab: 'py-1 px-[6px]', label: 'px-1 text-body2', secondLabel: 'text-caption', icon: 'w-5 h-5' },
|
|
25
|
+
tiny: { tab: 'py-0.5 px-1', label: 'px-1 text-caption', secondLabel: 'text-caption', icon: 'w-4 h-4' },
|
|
26
|
+
};
|
|
27
|
+
export var segmentSelectedClasses = 'text-primary-contrast';
|
|
28
|
+
export var segmentIdleClasses = 'text-fg-primary hover:bg-background-accent200';
|
|
29
|
+
/**
|
|
30
|
+
* Places a pill behind the item marked `data-tab-selected="true"` inside the container, keeps it
|
|
31
|
+
* there as items resize, and scrolls a newly selected item into view. Pass the container's `ref`
|
|
32
|
+
* and `children` (the effect runs again when they change).
|
|
33
|
+
*/
|
|
34
|
+
export function useSlidingIndicator(children) {
|
|
35
|
+
var containerRef = useRef(null);
|
|
36
|
+
var selectedRef = useRef(null);
|
|
37
|
+
var _a = useState(null), indicator = _a[0], setIndicator = _a[1];
|
|
38
|
+
useIsomorphicLayoutEffect(function () {
|
|
39
|
+
var _a;
|
|
40
|
+
var container = containerRef.current;
|
|
41
|
+
if (!container)
|
|
42
|
+
return;
|
|
43
|
+
var update = function () {
|
|
44
|
+
var selected = container.querySelector('[data-tab-selected="true"]');
|
|
45
|
+
if (!selected) {
|
|
46
|
+
selectedRef.current = null;
|
|
47
|
+
setIndicator(null);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
setIndicator(function (prev) { return ({
|
|
51
|
+
animate: prev !== null,
|
|
52
|
+
x: selected.offsetLeft,
|
|
53
|
+
y: selected.offsetTop,
|
|
54
|
+
width: selected.offsetWidth,
|
|
55
|
+
height: selected.offsetHeight,
|
|
56
|
+
}); });
|
|
57
|
+
// Items scroll horizontally instead of wrapping; keep a newly selected item in view
|
|
58
|
+
if (selected !== selectedRef.current) {
|
|
59
|
+
selectedRef.current = selected;
|
|
60
|
+
var left = selected.offsetLeft;
|
|
61
|
+
var right = left + selected.offsetWidth;
|
|
62
|
+
if (left < container.scrollLeft) {
|
|
63
|
+
container.scrollTo({ left: left - 4, behavior: 'smooth' });
|
|
64
|
+
}
|
|
65
|
+
else if (right > container.scrollLeft + container.clientWidth) {
|
|
66
|
+
container.scrollTo({ left: right - container.clientWidth + 4, behavior: 'smooth' });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
update();
|
|
71
|
+
// Item widths change once web fonts load
|
|
72
|
+
(_a = document.fonts) === null || _a === void 0 ? void 0 : _a.ready.then(update);
|
|
73
|
+
var resizeObserver = new ResizeObserver(update);
|
|
74
|
+
resizeObserver.observe(container);
|
|
75
|
+
Array.from(container.children).forEach(function (child) { return resizeObserver.observe(child); });
|
|
76
|
+
var mutationObserver = new MutationObserver(update);
|
|
77
|
+
mutationObserver.observe(container, {
|
|
78
|
+
subtree: true,
|
|
79
|
+
childList: true,
|
|
80
|
+
attributes: true,
|
|
81
|
+
attributeFilter: ['data-tab-selected'],
|
|
82
|
+
});
|
|
83
|
+
return function () {
|
|
84
|
+
resizeObserver.disconnect();
|
|
85
|
+
mutationObserver.disconnect();
|
|
86
|
+
};
|
|
87
|
+
}, [children]);
|
|
88
|
+
return { containerRef: containerRef, indicator: indicator };
|
|
89
|
+
}
|
|
90
|
+
/** The pill itself. Render it first inside the track. */
|
|
91
|
+
export function SlidingPill(_a) {
|
|
92
|
+
var indicator = _a.indicator;
|
|
93
|
+
if (!indicator)
|
|
94
|
+
return null;
|
|
95
|
+
return (<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={{
|
|
96
|
+
top: 0,
|
|
97
|
+
left: 0,
|
|
98
|
+
transform: "translate(".concat(indicator.x, "px, ").concat(indicator.y, "px)"),
|
|
99
|
+
width: indicator.width,
|
|
100
|
+
height: indicator.height,
|
|
101
|
+
}}/>);
|
|
102
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface SwitchBaseProps {
|
|
3
|
+
/** On the `<button>`. Defaults to a generated id. */
|
|
4
|
+
id?: string;
|
|
5
|
+
checked: boolean;
|
|
6
|
+
/** Called with the value the press asks for. The Switch stays controlled: it shows `checked` until the parent changes it. */
|
|
7
|
+
onChange: (next: boolean) => void;
|
|
8
|
+
/** A line under the label. Tied to the switch with `aria-describedby`. */
|
|
9
|
+
description?: string;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/** A change is being saved: the switch keeps its position, shows a spinner in the thumb and ignores presses. Set it from the parent while its request runs. */
|
|
12
|
+
busy?: boolean;
|
|
13
|
+
/** Shown under the row and tied to the switch. The parent sets it and puts `checked` back when a change fails. */
|
|
14
|
+
error?: string;
|
|
15
|
+
}
|
|
16
|
+
type SwitchProps = SwitchBaseProps & ({
|
|
17
|
+
label: string;
|
|
18
|
+
'aria-label'?: string;
|
|
19
|
+
} | {
|
|
20
|
+
label?: undefined;
|
|
21
|
+
'aria-label': string;
|
|
22
|
+
});
|
|
23
|
+
/** A settings row with an on/off switch at the right. Space and Enter toggle it. */
|
|
24
|
+
export default function Switch({ id, checked, onChange, label, description, disabled, busy, error, 'aria-label': ariaLabel, }: SwitchProps): React.JSX.Element;
|
|
25
|
+
export { Switch };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { useId } from 'react';
|
|
3
|
+
import { nextSwitchValue } from '../internal/switch';
|
|
4
|
+
import { focusRing, stateTransition } from './sharedStyles';
|
|
5
|
+
/** A settings row with an on/off switch at the right. Space and Enter toggle it. */
|
|
6
|
+
export default function Switch(_a) {
|
|
7
|
+
var id = _a.id, checked = _a.checked, onChange = _a.onChange, label = _a.label, description = _a.description, _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.busy, busy = _c === void 0 ? false : _c, error = _a.error, ariaLabel = _a["aria-label"];
|
|
8
|
+
var generatedId = useId();
|
|
9
|
+
var switchId = id !== null && id !== void 0 ? id : generatedId;
|
|
10
|
+
var descriptionId = "".concat(switchId, "-description");
|
|
11
|
+
var errorId = "".concat(switchId, "-error");
|
|
12
|
+
var describedBy = [description ? descriptionId : '', error ? errorId : ''].filter(Boolean).join(' ') || undefined;
|
|
13
|
+
var handleClick = function () {
|
|
14
|
+
var next = nextSwitchValue({ checked: checked, busy: busy, disabled: disabled });
|
|
15
|
+
if (next !== undefined)
|
|
16
|
+
onChange(next);
|
|
17
|
+
};
|
|
18
|
+
var track = disabled
|
|
19
|
+
? checked
|
|
20
|
+
? 'bg-fg-disabled border-transparent'
|
|
21
|
+
: 'border-fg-disabled'
|
|
22
|
+
: checked
|
|
23
|
+
? 'bg-accent-main border-transparent'
|
|
24
|
+
: 'border-fg-secondary';
|
|
25
|
+
var thumb = disabled
|
|
26
|
+
? checked
|
|
27
|
+
? 'bg-fg-contrast'
|
|
28
|
+
: 'bg-fg-disabled'
|
|
29
|
+
: checked
|
|
30
|
+
? 'bg-accent-contrast'
|
|
31
|
+
: 'bg-fg-secondary';
|
|
32
|
+
// The spinner takes the color of the track behind the thumb
|
|
33
|
+
var spinner = checked && !disabled ? 'text-accent-main' : 'text-background-default';
|
|
34
|
+
return (<div className="flex flex-col w-full">
|
|
35
|
+
<div className="flex items-start justify-between gap-3">
|
|
36
|
+
<div className="flex flex-col min-w-0">
|
|
37
|
+
{label && (<label htmlFor={switchId} className={"text-body1 ".concat(disabled ? 'text-fg-disabled cursor-not-allowed' : 'text-fg-primary cursor-pointer')}>
|
|
38
|
+
{label}
|
|
39
|
+
</label>)}
|
|
40
|
+
{description && (<p id={descriptionId} className={"text-body2 ".concat(disabled ? 'text-fg-disabled' : 'text-fg-secondary')}>
|
|
41
|
+
{description}
|
|
42
|
+
</p>)}
|
|
43
|
+
</div>
|
|
44
|
+
<button type="button" role="switch" id={switchId} aria-checked={checked} aria-label={ariaLabel} aria-describedby={describedBy} aria-invalid={error ? true : undefined} aria-busy={busy || undefined} disabled={disabled} onClick={handleClick} className={"relative flex flex-shrink-0 items-center w-10 h-6 px-0.5 rounded-full border-2 ".concat(stateTransition, " ").concat(focusRing, " ").concat(track, " ").concat(disabled ? 'cursor-not-allowed' : busy ? 'cursor-wait' : 'cursor-pointer')}>
|
|
45
|
+
<span aria-hidden="true" className={"flex items-center justify-center w-4 h-4 rounded-full ".concat(thumb, " transition-transform duration-[var(--os-duration-fast)] ease-out motion-reduce:transition-none ").concat(checked ? 'translate-x-4' : 'translate-x-0')}>
|
|
46
|
+
{busy && (<span className={"w-3 h-3 rounded-full border-2 border-current border-t-transparent animate-spin motion-reduce:animate-none ".concat(spinner)}/>)}
|
|
47
|
+
</span>
|
|
48
|
+
</button>
|
|
49
|
+
</div>
|
|
50
|
+
{error && (<p id={errorId} className="mt-1 text-error-text text-body2">
|
|
51
|
+
{error}
|
|
52
|
+
</p>)}
|
|
53
|
+
</div>);
|
|
54
|
+
}
|
|
55
|
+
export { Switch };
|
package/dist/components/tab.jsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import React, { useContext } from 'react';
|
|
3
3
|
import IconSlot from './iconSlot';
|
|
4
4
|
import { TabsContainerContext, TabsFillContext } from './tabsContainer';
|
|
5
|
-
import {
|
|
5
|
+
import { segmentIdleClasses, segmentItemClasses, segmentSelectedClasses, segmentSizes } from './slidingIndicator';
|
|
6
6
|
export default function Tab(_a) {
|
|
7
7
|
var label = _a.label, secondLabel = _a.secondLabel, href = _a.href, isSelected = _a.isSelected, onClickTab = _a.onClickTab, onClickActionIcon = _a.onClickActionIcon, decoIcon = _a.decoIcon, actionIcon = _a.actionIcon, router = _a.router, _b = _a.size, size = _b === void 0 ? 'medium' : _b;
|
|
8
8
|
var inContainer = useContext(TabsContainerContext);
|
|
@@ -13,15 +13,11 @@ export default function Tab(_a) {
|
|
|
13
13
|
router.push(href);
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
var sizeClasses =
|
|
17
|
-
medium: { tab: 'py-1 px-[6px]', label: 'px-[6px] text-body1', secondLabel: 'text-body2', icon: 'w-6 h-6' },
|
|
18
|
-
small: { tab: 'py-1 px-[6px]', label: 'px-1 text-body2', secondLabel: 'text-caption', icon: 'w-5 h-5' },
|
|
19
|
-
tiny: { tab: 'py-0.5 px-1', label: 'px-1 text-caption', secondLabel: 'text-caption', icon: 'w-4 h-4' },
|
|
20
|
-
}[size];
|
|
16
|
+
var sizeClasses = segmentSizes[size];
|
|
21
17
|
// Inside a TabsContainer the container's sliding pill is the selected background
|
|
22
18
|
var selectedClasses = inContainer
|
|
23
|
-
?
|
|
24
|
-
:
|
|
19
|
+
? segmentSelectedClasses
|
|
20
|
+
: "bg-primary-dark ".concat(segmentSelectedClasses);
|
|
25
21
|
return (<div data-tab-selected={isSelected} role="tab" aria-selected={isSelected}
|
|
26
22
|
// Inside a container only the selected tab is in the Tab order; arrow keys move between tabs
|
|
27
23
|
tabIndex={inContainer && !isSelected ? -1 : 0} onKeyDown={function (e) {
|
|
@@ -29,9 +25,7 @@ export default function Tab(_a) {
|
|
|
29
25
|
e.preventDefault();
|
|
30
26
|
handleClick();
|
|
31
27
|
}
|
|
32
|
-
}} className={
|
|
33
|
-
? selectedClasses
|
|
34
|
-
: 'text-fg-primary hover:bg-background-accent200', "\n ")} onClick={handleClick}>
|
|
28
|
+
}} className={segmentItemClasses(fill, sizeClasses.tab, isSelected ? selectedClasses : segmentIdleClasses)} onClick={handleClick}>
|
|
35
29
|
<IconSlot icon={decoIcon} className={sizeClasses.icon}/>
|
|
36
30
|
<div className={"flex flex-col text-center ".concat(sizeClasses.label)}>
|
|
37
31
|
<span className="whitespace-nowrap">
|
|
@@ -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>
|
|
@@ -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 {};
|
|
@@ -3,7 +3,7 @@ import React, { useCallback, useEffect, useRef } from 'react';
|
|
|
3
3
|
import { stateTransition } from './sharedStyles';
|
|
4
4
|
import { fitToContent } from '../internal/autoGrow';
|
|
5
5
|
export default function Textarea(_a) {
|
|
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;
|
|
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;
|
|
7
7
|
var textareaRef = useRef(null);
|
|
8
8
|
var handleKeyDown = function (e) {
|
|
9
9
|
// Ctrl+Enter or Cmd+Enter to submit
|
|
@@ -35,7 +35,7 @@ export default function Textarea(_a) {
|
|
|
35
35
|
: 'bg-background-default text-fg-primary';
|
|
36
36
|
// Border: error > focus (1px offset outline, the same weight as the border) > hover > default
|
|
37
37
|
var getBorderColor = function () {
|
|
38
|
-
if (error) {
|
|
38
|
+
if (error || ariaInvalid) {
|
|
39
39
|
return 'border-error-main focus:outline focus:outline-1 focus:outline-offset-2 focus:outline-error-main';
|
|
40
40
|
}
|
|
41
41
|
if (disabled) {
|
|
@@ -50,7 +50,7 @@ export default function Textarea(_a) {
|
|
|
50
50
|
{label}
|
|
51
51
|
</label>)}
|
|
52
52
|
<div className="relative">
|
|
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 || 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}/>
|
|
54
54
|
</div>
|
|
55
55
|
{error && (<p id={errorId} className="mt-1 text-error-text text-body2">
|
|
56
56
|
{errorText}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface TitleBarProps {
|
|
3
|
+
/** The page's or the pane's name */
|
|
4
|
+
title: string;
|
|
5
|
+
/** The heading's element. Default 1, for a page; a pane takes 2. */
|
|
6
|
+
level?: 1 | 2 | 3 | 4;
|
|
7
|
+
/** A Button before the title that goes one step up, e.g. 'Back to Inbox' */
|
|
8
|
+
back?: React.ReactNode;
|
|
9
|
+
/** Buttons at the end of the row. They never shrink; a long title wraps instead. */
|
|
10
|
+
actions?: React.ReactNode;
|
|
11
|
+
/** Below md these replace `actions`: the main action and a More menu holding the rest */
|
|
12
|
+
phoneActions?: React.ReactNode;
|
|
13
|
+
/** The heading's id */
|
|
14
|
+
id?: string;
|
|
15
|
+
}
|
|
16
|
+
export default function TitleBar({ title, level, back, actions, phoneActions, id }: TitleBarProps): React.JSX.Element;
|
|
17
|
+
export { TitleBar };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Heading from './heading';
|
|
3
|
+
// One row from md up: back, the title, then the actions. Below md Back takes its own line above the title.
|
|
4
|
+
// A row without Back is one row at every width. The heading takes tabIndex -1 so a page or a pane can
|
|
5
|
+
// move focus to it (a pane does on open) without adding it to the tab order.
|
|
6
|
+
export default function TitleBar(_a) {
|
|
7
|
+
var title = _a.title, _b = _a.level, level = _b === void 0 ? 1 : _b, back = _a.back, actions = _a.actions, phoneActions = _a.phoneActions, id = _a.id;
|
|
8
|
+
return (<div className={"flex min-w-0 items-center gap-2".concat(back ? ' flex-wrap md:flex-nowrap' : '')}>
|
|
9
|
+
{back && <div className="flex shrink-0 basis-full items-center md:basis-auto">{back}</div>}
|
|
10
|
+
<Heading level={level} size="h5" id={id} tabIndex={-1} className="min-w-0 flex-1 break-words outline-none">
|
|
11
|
+
{title}
|
|
12
|
+
</Heading>
|
|
13
|
+
{actions && <div className={"".concat(phoneActions ? 'hidden md:flex' : 'flex', " shrink-0 items-center gap-2")}>{actions}</div>}
|
|
14
|
+
{phoneActions && <div className="flex shrink-0 items-center gap-2 md:hidden">{phoneActions}</div>}
|
|
15
|
+
</div>);
|
|
16
|
+
}
|
|
17
|
+
export { TitleBar };
|
|
@@ -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
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import './designTokens';
|
|
2
2
|
export * from './components/alert';
|
|
3
|
+
export * from './components/appShell';
|
|
3
4
|
export * from './components/button';
|
|
4
5
|
export * from './components/checkBox';
|
|
6
|
+
export * from './components/copyField';
|
|
7
|
+
export * from './components/drawer';
|
|
5
8
|
export * from './components/emptyBox';
|
|
9
|
+
export * from './components/formField';
|
|
6
10
|
export * from './components/iconButton';
|
|
7
11
|
export * from './components/layout';
|
|
8
12
|
export * from './components/loadingScreen';
|
|
@@ -10,10 +14,17 @@ export * from './components/menu';
|
|
|
10
14
|
export * from './components/menuItem';
|
|
11
15
|
export * from './components/modal';
|
|
12
16
|
export * from './components/navigation';
|
|
17
|
+
export * from './components/onThisPage';
|
|
13
18
|
export * from './components/popover';
|
|
14
19
|
export * from './components/radioGroup';
|
|
15
20
|
export * from './components/sectionIntro';
|
|
21
|
+
export * from './components/segmentedControl';
|
|
16
22
|
export * from './components/select';
|
|
23
|
+
export * from './components/settingsSection';
|
|
24
|
+
export * from './components/sidePane';
|
|
25
|
+
export * from './components/siteFooter';
|
|
26
|
+
export * from './components/siteHeader';
|
|
27
|
+
export * from './components/switch';
|
|
17
28
|
export * from './components/tab';
|
|
18
29
|
export * from './components/tableCell';
|
|
19
30
|
export * from './components/tableContainer';
|
|
@@ -25,6 +36,8 @@ export * from './components/tag';
|
|
|
25
36
|
export * from './components/textarea';
|
|
26
37
|
export * from './components/textField';
|
|
27
38
|
export * from './components/timeStamp';
|
|
39
|
+
export * from './components/titleBar';
|
|
28
40
|
export * from './components/tooltip';
|
|
29
41
|
export * from './components/userImage';
|
|
30
42
|
export { default as useDarkMode, resolveDarkMode } from './components/useDarkMode';
|
|
43
|
+
export { default as useHotkey } from './components/useHotkey';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import './designTokens';
|
|
2
2
|
export * from './components/alert';
|
|
3
|
+
export * from './components/appShell';
|
|
3
4
|
export * from './components/button';
|
|
4
5
|
export * from './components/checkBox';
|
|
6
|
+
export * from './components/copyField';
|
|
7
|
+
export * from './components/drawer';
|
|
5
8
|
export * from './components/emptyBox';
|
|
9
|
+
export * from './components/formField';
|
|
6
10
|
export * from './components/iconButton';
|
|
7
11
|
export * from './components/layout';
|
|
8
12
|
export * from './components/loadingScreen';
|
|
@@ -10,10 +14,17 @@ export * from './components/menu';
|
|
|
10
14
|
export * from './components/menuItem';
|
|
11
15
|
export * from './components/modal';
|
|
12
16
|
export * from './components/navigation';
|
|
17
|
+
export * from './components/onThisPage';
|
|
13
18
|
export * from './components/popover';
|
|
14
19
|
export * from './components/radioGroup';
|
|
15
20
|
export * from './components/sectionIntro';
|
|
21
|
+
export * from './components/segmentedControl';
|
|
16
22
|
export * from './components/select';
|
|
23
|
+
export * from './components/settingsSection';
|
|
24
|
+
export * from './components/sidePane';
|
|
25
|
+
export * from './components/siteFooter';
|
|
26
|
+
export * from './components/siteHeader';
|
|
27
|
+
export * from './components/switch';
|
|
17
28
|
export * from './components/tab';
|
|
18
29
|
export * from './components/tableCell';
|
|
19
30
|
export * from './components/tableContainer';
|
|
@@ -25,6 +36,8 @@ export * from './components/tag';
|
|
|
25
36
|
export * from './components/textarea';
|
|
26
37
|
export * from './components/textField';
|
|
27
38
|
export * from './components/timeStamp';
|
|
39
|
+
export * from './components/titleBar';
|
|
28
40
|
export * from './components/tooltip';
|
|
29
41
|
export * from './components/userImage';
|
|
30
42
|
export { default as useDarkMode, resolveDarkMode } from './components/useDarkMode';
|
|
43
|
+
export { default as useHotkey } from './components/useHotkey';
|