oneslash-design-system 2.17.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.
Files changed (185) hide show
  1. package/README.md +2 -2
  2. package/dist/DESIGN.md +30 -14
  3. package/dist/cases/accept-invite.md +1 -5
  4. package/dist/cases/account-menu/menu.d.ts +1 -0
  5. package/dist/cases/account-menu/menu.jsx +99 -0
  6. package/dist/cases/account-menu.md +164 -0
  7. package/dist/cases/agent-asks-before-risky-action.md +0 -4
  8. package/dist/cases/agent-cancels-when-unanswered.md +0 -4
  9. package/dist/cases/agent-options.md +0 -4
  10. package/dist/cases/agent-pending-reply.md +0 -4
  11. package/dist/cases/agent-plan-proposal.md +0 -4
  12. package/dist/cases/agent-question.md +0 -4
  13. package/dist/cases/agent-refuses-clearly.md +0 -4
  14. package/dist/cases/agent-says-what-it-is.md +0 -2
  15. package/dist/cases/agent-settings/form.d.ts +1 -0
  16. package/dist/cases/agent-settings/form.jsx +164 -0
  17. package/dist/cases/agent-settings.md +259 -0
  18. package/dist/cases/agent-shows-progress.md +0 -2
  19. package/dist/cases/agent-shows-sources.md +0 -2
  20. package/dist/cases/api-keys/list.d.ts +1 -0
  21. package/dist/cases/api-keys/list.jsx +162 -0
  22. package/dist/cases/api-keys.md +229 -0
  23. package/dist/cases/artifact-card.md +0 -4
  24. package/dist/cases/auth-gate-loading.md +0 -4
  25. package/dist/cases/check-your-email.md +0 -4
  26. package/dist/cases/collapsible-search/popover.d.ts +1 -0
  27. package/dist/cases/collapsible-search/popover.jsx +74 -0
  28. package/dist/cases/collapsible-search.md +143 -0
  29. package/dist/cases/composer-limit.md +0 -4
  30. package/dist/cases/confirm-destructive-action.md +0 -4
  31. package/dist/cases/confirm-dialogs.md +0 -4
  32. package/dist/cases/conversation-starters.md +0 -4
  33. package/dist/cases/create-modal.md +0 -4
  34. package/dist/cases/danger-zone/collapsed.d.ts +1 -0
  35. package/dist/cases/danger-zone/collapsed.jsx +75 -0
  36. package/dist/cases/danger-zone/shown.d.ts +1 -0
  37. package/dist/cases/danger-zone/shown.jsx +95 -0
  38. package/dist/cases/danger-zone.md +263 -0
  39. package/dist/cases/device-login.md +0 -4
  40. package/dist/cases/email-confirmed.md +0 -4
  41. package/dist/cases/empty-list.md +0 -4
  42. package/dist/cases/empty-lists.md +0 -4
  43. package/dist/cases/empty-not-set-up.md +0 -4
  44. package/dist/cases/empty-search.md +0 -4
  45. package/dist/cases/error-page.md +0 -4
  46. package/dist/cases/feedback-form.md +0 -4
  47. package/dist/cases/filter-menu/presets.d.ts +1 -0
  48. package/dist/cases/filter-menu/presets.jsx +53 -0
  49. package/dist/cases/filter-menu/with-clear.d.ts +1 -0
  50. package/dist/cases/filter-menu/with-clear.jsx +56 -0
  51. package/dist/cases/filter-menu.md +204 -0
  52. package/dist/cases/forgot-password.md +0 -4
  53. package/dist/cases/form-errors.md +0 -4
  54. package/dist/cases/import-checklist.md +0 -4
  55. package/dist/cases/inline-form-feedback.md +0 -4
  56. package/dist/cases/integrations-list/nested.d.ts +1 -0
  57. package/dist/cases/integrations-list/nested.jsx +164 -0
  58. package/dist/cases/integrations-list/rows.d.ts +1 -0
  59. package/dist/cases/integrations-list/rows.jsx +134 -0
  60. package/dist/cases/integrations-list.md +379 -0
  61. package/dist/cases/invite-member.md +0 -4
  62. package/dist/cases/load-failure.md +0 -4
  63. package/dist/cases/log-out-confirm.md +0 -4
  64. package/dist/cases/login-page.md +0 -4
  65. package/dist/cases/members-list/rows.d.ts +1 -0
  66. package/dist/cases/members-list/rows.jsx +318 -0
  67. package/dist/cases/members-list/table.d.ts +1 -0
  68. package/dist/cases/members-list/table.jsx +351 -0
  69. package/dist/cases/members-list.md +799 -0
  70. package/dist/cases/mention-list.md +0 -4
  71. package/dist/cases/message-actions.md +0 -4
  72. package/dist/cases/message-attachments.md +0 -4
  73. package/dist/cases/message-composer.md +0 -4
  74. package/dist/cases/message-edit.md +0 -4
  75. package/dist/cases/message-reactions.md +0 -4
  76. package/dist/cases/message-row.md +0 -4
  77. package/dist/cases/not-found-page.md +0 -4
  78. package/dist/cases/notification-menu/menu.d.ts +1 -0
  79. package/dist/cases/notification-menu/menu.jsx +74 -0
  80. package/dist/cases/notification-menu.md +135 -0
  81. package/dist/cases/oauth-consent.md +0 -4
  82. package/dist/cases/on-off-settings/list.d.ts +1 -0
  83. package/dist/cases/on-off-settings/list.jsx +97 -0
  84. package/dist/cases/on-off-settings.md +116 -0
  85. package/dist/cases/overflow-menu/in-a-header.d.ts +1 -0
  86. package/dist/cases/overflow-menu/in-a-header.jsx +128 -0
  87. package/dist/cases/overflow-menu/on-a-row.d.ts +1 -0
  88. package/dist/cases/overflow-menu/on-a-row.jsx +183 -0
  89. package/dist/cases/overflow-menu.md +410 -0
  90. package/dist/cases/profile-form/form.d.ts +1 -0
  91. package/dist/cases/profile-form/form.jsx +153 -0
  92. package/dist/cases/profile-form.md +236 -0
  93. package/dist/cases/quick-switcher/modal.d.ts +1 -0
  94. package/dist/cases/quick-switcher/modal.jsx +114 -0
  95. package/dist/cases/quick-switcher.md +205 -0
  96. package/dist/cases/range-switch/segmented.d.ts +1 -0
  97. package/dist/cases/range-switch/segmented.jsx +30 -0
  98. package/dist/cases/range-switch.md +67 -0
  99. package/dist/cases/rename.md +0 -4
  100. package/dist/cases/reply-feedback.md +0 -4
  101. package/dist/cases/reply-sources.md +0 -4
  102. package/dist/cases/route-loading.md +0 -2
  103. package/dist/cases/scope-picker/menu.d.ts +1 -0
  104. package/dist/cases/scope-picker/menu.jsx +47 -0
  105. package/dist/cases/scope-picker.md +97 -0
  106. package/dist/cases/set-new-password.md +0 -4
  107. package/dist/cases/settings-page/side-nav.d.ts +1 -0
  108. package/dist/cases/settings-page/side-nav.jsx +171 -0
  109. package/dist/cases/settings-page/top-tabs.d.ts +1 -0
  110. package/dist/cases/settings-page/top-tabs.jsx +129 -0
  111. package/dist/cases/settings-page.md +378 -0
  112. package/dist/cases/settings-save.md +35 -0
  113. package/dist/cases/sign-up-page.md +1 -5
  114. package/dist/cases/slash-command-list.md +0 -4
  115. package/dist/cases/success-feedback.md +0 -4
  116. package/dist/cases/tag-filter/tags.d.ts +1 -0
  117. package/dist/cases/tag-filter/tags.jsx +226 -0
  118. package/dist/cases/tag-filter.md +298 -0
  119. package/dist/cases/type-to-confirm.md +0 -4
  120. package/dist/cases/typing-and-status.md +0 -4
  121. package/dist/cases/unsaved-changes-guard.md +0 -4
  122. package/dist/cases/upgrade-prompt.md +0 -4
  123. package/dist/cases.json +1038 -263
  124. package/dist/components/alert.d.ts +3 -1
  125. package/dist/components/alert.jsx +2 -2
  126. package/dist/components/button.jsx +5 -2
  127. package/dist/components/checkBox.d.ts +5 -1
  128. package/dist/components/checkBox.jsx +2 -2
  129. package/dist/components/copyField.d.ts +20 -0
  130. package/dist/components/copyField.jsx +99 -0
  131. package/dist/components/formField.d.ts +34 -0
  132. package/dist/components/formField.jsx +28 -0
  133. package/dist/components/heading.d.ts +3 -1
  134. package/dist/components/heading.jsx +2 -2
  135. package/dist/components/menu.jsx +2 -2
  136. package/dist/components/menuItem.d.ts +4 -2
  137. package/dist/components/menuItem.jsx +3 -3
  138. package/dist/components/navigation.d.ts +9 -1
  139. package/dist/components/navigation.jsx +15 -3
  140. package/dist/components/radioGroup.d.ts +5 -1
  141. package/dist/components/radioGroup.jsx +2 -2
  142. package/dist/components/segmentedControl.d.ts +22 -0
  143. package/dist/components/segmentedControl.jsx +54 -0
  144. package/dist/components/select.d.ts +5 -1
  145. package/dist/components/select.jsx +2 -2
  146. package/dist/components/settingsSection.d.ts +31 -0
  147. package/dist/components/settingsSection.jsx +58 -0
  148. package/dist/components/slidingIndicator.d.ts +50 -0
  149. package/dist/components/slidingIndicator.jsx +102 -0
  150. package/dist/components/switch.d.ts +25 -0
  151. package/dist/components/switch.jsx +55 -0
  152. package/dist/components/tab.jsx +5 -11
  153. package/dist/components/tabsContainer.jsx +5 -67
  154. package/dist/components/textField.d.ts +12 -2
  155. package/dist/components/textField.jsx +11 -4
  156. package/dist/components/textarea.d.ts +5 -1
  157. package/dist/components/textarea.jsx +3 -3
  158. package/dist/components/useHotkey.d.ts +7 -0
  159. package/dist/components/useHotkey.js +24 -0
  160. package/dist/index.d.ts +6 -0
  161. package/dist/index.js +6 -0
  162. package/dist/internal/copyField.d.ts +5 -0
  163. package/dist/internal/copyField.js +61 -0
  164. package/dist/internal/hotkey.d.ts +16 -0
  165. package/dist/internal/hotkey.js +20 -0
  166. package/dist/internal/switch.d.ts +5 -0
  167. package/dist/internal/switch.js +9 -0
  168. package/dist/native-mapping.json +30 -0
  169. package/dist/stories/Cases.generated.stories.d.ts +23 -0
  170. package/dist/stories/Cases.generated.stories.jsx +46 -0
  171. package/dist/stories/CopyField.stories.d.ts +11 -0
  172. package/dist/stories/CopyField.stories.jsx +65 -0
  173. package/dist/stories/FormField.stories.d.ts +6 -0
  174. package/dist/stories/FormField.stories.jsx +44 -0
  175. package/dist/stories/Navigation.stories.d.ts +1 -0
  176. package/dist/stories/Navigation.stories.jsx +17 -1
  177. package/dist/stories/SegmentedControl.stories.d.ts +8 -0
  178. package/dist/stories/SegmentedControl.stories.jsx +33 -0
  179. package/dist/stories/SettingsSection.stories.d.ts +11 -0
  180. package/dist/stories/SettingsSection.stories.jsx +64 -0
  181. package/dist/stories/Switch.stories.d.ts +14 -0
  182. package/dist/stories/Switch.stories.jsx +87 -0
  183. package/dist/stories/TextField.stories.d.ts +1 -0
  184. package/dist/stories/TextField.stories.jsx +13 -0
  185. package/package.json +5 -1
@@ -0,0 +1,58 @@
1
+ 'use client';
2
+ import React, { useEffect, useId, useRef } from 'react';
3
+ import Heading from './heading';
4
+ // A hairline, a title, a description and then the controls. Reads as one block, so it never splits.
5
+ export default function SettingsSection(_a) {
6
+ var title = _a.title, description = _a.description, children = _a.children, _b = _a.tone, tone = _b === void 0 ? 'default' : _b, id = _a.id, _c = _a.level, level = _c === void 0 ? 2 : _c;
7
+ var generated = useId();
8
+ var titleId = id ? "".concat(id, "-title") : generated;
9
+ var danger = tone === 'danger';
10
+ return (<section id={id} aria-labelledby={titleId} className={"flex flex-col gap-large border-t pt-large ".concat(danger ? 'border-error-main' : 'border-misc-divider')}>
11
+ <div className="flex flex-col gap-small">
12
+ <Heading level={level} id={titleId} color={danger ? 'danger' : 'default'}>
13
+ {title}
14
+ </Heading>
15
+ {description && <p className="text-body2 text-fg-secondary">{description}</p>}
16
+ </div>
17
+ <div className="flex flex-col gap-medium">{children}</div>
18
+ </section>);
19
+ }
20
+ // Sections in one column, two from md up. A grid, so a section is never cut across columns.
21
+ export function SettingsColumns(_a) {
22
+ var children = _a.children;
23
+ return <div className="grid grid-cols-1 items-start gap-xlarge md:grid-cols-2">{children}</div>;
24
+ }
25
+ // A side nav beside its content from md up. On a phone the nav is the page and an item opens its content, so only one shows at a time.
26
+ var FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
27
+ var isHidden = function (el) { return !el || getComputedStyle(el).display === 'none'; };
28
+ export function SettingsLayout(_a) {
29
+ var nav = _a.nav, children = _a.children, showContent = _a.showContent, back = _a.back;
30
+ var navRef = useRef(null);
31
+ var contentRef = useRef(null);
32
+ var prev = useRef(showContent);
33
+ // On a phone one side hides the other, and the focused control goes with it. Move focus to the side that shows:
34
+ // the back Button (or the first control) when the content opens, the open item when the nav returns.
35
+ // From md up both sides show, so focus stays where it is.
36
+ useEffect(function () {
37
+ var _a, _b, _c, _d;
38
+ // Compare with the last value, not a first-run flag: StrictMode runs the effect twice on mount.
39
+ if (prev.current === showContent)
40
+ return;
41
+ prev.current = showContent;
42
+ if (showContent && isHidden(navRef.current)) {
43
+ (_b = (_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(FOCUSABLE)) === null || _b === void 0 ? void 0 : _b.focus();
44
+ }
45
+ else if (!showContent && isHidden(contentRef.current)) {
46
+ var items = navRef.current;
47
+ (_d = ((_c = items === null || items === void 0 ? void 0 : items.querySelector('[aria-current]')) !== null && _c !== void 0 ? _c : items === null || items === void 0 ? void 0 : items.querySelector(FOCUSABLE))) === null || _d === void 0 ? void 0 : _d.focus();
48
+ }
49
+ }, [showContent]);
50
+ return (<div className="grid grid-cols-1 items-start gap-xlarge md:grid-cols-[16rem_minmax(0,1fr)]">
51
+ <div ref={navRef} className={showContent ? 'hidden md:block' : 'block'}>{nav}</div>
52
+ <div ref={contentRef} className={"flex-col gap-large ".concat(showContent ? 'flex' : 'hidden md:flex')}>
53
+ {back && <div className="md:hidden">{back}</div>}
54
+ {children}
55
+ </div>
56
+ </div>);
57
+ }
58
+ export { SettingsSection };
@@ -0,0 +1,50 @@
1
+ import React from 'react';
2
+ type IndicatorRect = {
3
+ x: number;
4
+ y: number;
5
+ width: number;
6
+ height: number;
7
+ animate: boolean;
8
+ };
9
+ /** The track around the items. `filled` is false for an empty track, which stays transparent. */
10
+ export declare function segmentTrackClasses(fill: boolean, filled: boolean): string;
11
+ export declare const segmentTrackStyle: React.CSSProperties;
12
+ /** The classes every item has, selected or not */
13
+ export declare function segmentItemClasses(fill: boolean, sizeClass: string, selectedClasses: string): string;
14
+ /** Item text and icon sizes. Items use `data-tab-selected="true"` on the selected one. */
15
+ export declare const segmentSizes: {
16
+ medium: {
17
+ tab: string;
18
+ label: string;
19
+ secondLabel: string;
20
+ icon: string;
21
+ };
22
+ small: {
23
+ tab: string;
24
+ label: string;
25
+ secondLabel: string;
26
+ icon: string;
27
+ };
28
+ tiny: {
29
+ tab: string;
30
+ label: string;
31
+ secondLabel: string;
32
+ icon: string;
33
+ };
34
+ };
35
+ export declare const segmentSelectedClasses = "text-primary-contrast";
36
+ export declare const segmentIdleClasses = "text-fg-primary hover:bg-background-accent200";
37
+ /**
38
+ * Places a pill behind the item marked `data-tab-selected="true"` inside the container, keeps it
39
+ * there as items resize, and scrolls a newly selected item into view. Pass the container's `ref`
40
+ * and `children` (the effect runs again when they change).
41
+ */
42
+ export declare function useSlidingIndicator(children: unknown): {
43
+ containerRef: React.RefObject<HTMLDivElement>;
44
+ indicator: IndicatorRect | null;
45
+ };
46
+ /** The pill itself. Render it first inside the track. */
47
+ export declare function SlidingPill({ indicator }: {
48
+ indicator: IndicatorRect | null;
49
+ }): React.JSX.Element | null;
50
+ export {};
@@ -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 };
@@ -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 { focusRing, pressFeedbackAny, stateTransition } from './sharedStyles';
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
- ? 'text-primary-contrast'
24
- : 'bg-primary-dark text-primary-contrast';
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={"\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(sizeClasses.tab, "\n ").concat(isSelected
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, useEffect, useLayoutEffect, useRef, useState } from 'react';
3
- // useLayoutEffect warns on a server render, where it cannot run; useEffect is the same there and silent
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 containerRef = useRef(null);
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={"\n relative flex gap-0.5 p-1 rounded-container overflow-x-auto".concat(fill ? ' w-full' : '', "\n ").concat(tabCount > 0 ? 'bg-background-accent100' : 'bg-transparent', "\n ")} style={{
86
- scrollbarWidth: 'none',
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': error ? errorId : helperText ? helperId : undefined,
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,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
@@ -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,5 @@
1
+ type ClipboardLike = {
2
+ writeText?: (text: string) => Promise<void>;
3
+ } | null | undefined;
4
+ export declare function copyText(clipboard: ClipboardLike, text: string): Promise<boolean>;
5
+ export {};