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.
- package/README.md +2 -2
- package/dist/DESIGN.md +30 -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/artifact-card.md +0 -4
- 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.md +0 -4
- package/dist/cases/feedback-form.md +0 -4
- package/dist/cases/filter-menu/presets.d.ts +1 -0
- package/dist/cases/filter-menu/presets.jsx +53 -0
- package/dist/cases/filter-menu/with-clear.d.ts +1 -0
- package/dist/cases/filter-menu/with-clear.jsx +56 -0
- package/dist/cases/filter-menu.md +204 -0
- package/dist/cases/forgot-password.md +0 -4
- package/dist/cases/form-errors.md +0 -4
- package/dist/cases/import-checklist.md +0 -4
- package/dist/cases/inline-form-feedback.md +0 -4
- package/dist/cases/integrations-list/nested.d.ts +1 -0
- package/dist/cases/integrations-list/nested.jsx +164 -0
- package/dist/cases/integrations-list/rows.d.ts +1 -0
- package/dist/cases/integrations-list/rows.jsx +134 -0
- package/dist/cases/integrations-list.md +379 -0
- package/dist/cases/invite-member.md +0 -4
- package/dist/cases/load-failure.md +0 -4
- package/dist/cases/log-out-confirm.md +0 -4
- package/dist/cases/login-page.md +0 -4
- package/dist/cases/members-list/rows.d.ts +1 -0
- package/dist/cases/members-list/rows.jsx +318 -0
- package/dist/cases/members-list/table.d.ts +1 -0
- package/dist/cases/members-list/table.jsx +351 -0
- package/dist/cases/members-list.md +799 -0
- package/dist/cases/mention-list.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/not-found-page.md +0 -4
- package/dist/cases/notification-menu/menu.d.ts +1 -0
- package/dist/cases/notification-menu/menu.jsx +74 -0
- package/dist/cases/notification-menu.md +135 -0
- package/dist/cases/oauth-consent.md +0 -4
- package/dist/cases/on-off-settings/list.d.ts +1 -0
- package/dist/cases/on-off-settings/list.jsx +97 -0
- package/dist/cases/on-off-settings.md +116 -0
- package/dist/cases/overflow-menu/in-a-header.d.ts +1 -0
- package/dist/cases/overflow-menu/in-a-header.jsx +128 -0
- package/dist/cases/overflow-menu/on-a-row.d.ts +1 -0
- package/dist/cases/overflow-menu/on-a-row.jsx +183 -0
- package/dist/cases/overflow-menu.md +410 -0
- package/dist/cases/profile-form/form.d.ts +1 -0
- package/dist/cases/profile-form/form.jsx +153 -0
- package/dist/cases/profile-form.md +236 -0
- package/dist/cases/quick-switcher/modal.d.ts +1 -0
- package/dist/cases/quick-switcher/modal.jsx +114 -0
- package/dist/cases/quick-switcher.md +205 -0
- package/dist/cases/range-switch/segmented.d.ts +1 -0
- package/dist/cases/range-switch/segmented.jsx +30 -0
- package/dist/cases/range-switch.md +67 -0
- package/dist/cases/rename.md +0 -4
- package/dist/cases/reply-feedback.md +0 -4
- package/dist/cases/reply-sources.md +0 -4
- package/dist/cases/route-loading.md +0 -2
- package/dist/cases/scope-picker/menu.d.ts +1 -0
- package/dist/cases/scope-picker/menu.jsx +47 -0
- package/dist/cases/scope-picker.md +97 -0
- package/dist/cases/set-new-password.md +0 -4
- package/dist/cases/settings-page/side-nav.d.ts +1 -0
- package/dist/cases/settings-page/side-nav.jsx +171 -0
- package/dist/cases/settings-page/top-tabs.d.ts +1 -0
- package/dist/cases/settings-page/top-tabs.jsx +129 -0
- package/dist/cases/settings-page.md +378 -0
- package/dist/cases/settings-save.md +35 -0
- package/dist/cases/sign-up-page.md +1 -5
- package/dist/cases/slash-command-list.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/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 +1038 -263
- package/dist/components/alert.d.ts +3 -1
- package/dist/components/alert.jsx +2 -2
- 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/formField.d.ts +34 -0
- package/dist/components/formField.jsx +28 -0
- package/dist/components/heading.d.ts +3 -1
- package/dist/components/heading.jsx +2 -2
- package/dist/components/menu.jsx +2 -2
- package/dist/components/menuItem.d.ts +4 -2
- package/dist/components/menuItem.jsx +3 -3
- package/dist/components/navigation.d.ts +9 -1
- package/dist/components/navigation.jsx +15 -3
- 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 +31 -0
- package/dist/components/settingsSection.jsx +58 -0
- package/dist/components/slidingIndicator.d.ts +50 -0
- package/dist/components/slidingIndicator.jsx +102 -0
- package/dist/components/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/useHotkey.d.ts +7 -0
- package/dist/components/useHotkey.js +24 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -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/switch.d.ts +5 -0
- package/dist/internal/switch.js +9 -0
- package/dist/native-mapping.json +30 -0
- package/dist/stories/Cases.generated.stories.d.ts +23 -0
- package/dist/stories/Cases.generated.stories.jsx +46 -0
- package/dist/stories/CopyField.stories.d.ts +11 -0
- package/dist/stories/CopyField.stories.jsx +65 -0
- package/dist/stories/FormField.stories.d.ts +6 -0
- package/dist/stories/FormField.stories.jsx +44 -0
- package/dist/stories/Navigation.stories.d.ts +1 -0
- package/dist/stories/Navigation.stories.jsx +17 -1
- package/dist/stories/SegmentedControl.stories.d.ts +8 -0
- package/dist/stories/SegmentedControl.stories.jsx +33 -0
- package/dist/stories/SettingsSection.stories.d.ts +11 -0
- package/dist/stories/SettingsSection.stories.jsx +64 -0
- package/dist/stories/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/package.json +5 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
interface AlertProps {
|
|
3
|
+
/** Lets a control point at the alert with `aria-describedby`, such as a Select whose save failed. */
|
|
4
|
+
id?: string;
|
|
3
5
|
open?: boolean;
|
|
4
6
|
type: 'success' | 'warning' | 'error' | 'info' | 'default';
|
|
5
7
|
message: string;
|
|
@@ -10,5 +12,5 @@ interface AlertProps {
|
|
|
10
12
|
/** Not set: the alert dismisses itself after 5 seconds unless it has a close button. `false` keeps it open; `true` dismisses it even with a close button. */
|
|
11
13
|
autoDismiss?: boolean;
|
|
12
14
|
}
|
|
13
|
-
export default function Alert({ open, type, message, secondMessage, onClose, showCloseButton, variant, autoDismiss, }: AlertProps): React.JSX.Element | null;
|
|
15
|
+
export default function Alert({ id, open, type, message, secondMessage, onClose, showCloseButton, variant, autoDismiss, }: AlertProps): React.JSX.Element | null;
|
|
14
16
|
export {};
|
|
@@ -18,7 +18,7 @@ var motionClasses = {
|
|
|
18
18
|
};
|
|
19
19
|
export default function Alert(_a) {
|
|
20
20
|
var _b;
|
|
21
|
-
var _c = _a.open, open = _c === void 0 ? true : _c, type = _a.type, message = _a.message, secondMessage = _a.secondMessage, onClose = _a.onClose, _d = _a.showCloseButton, showCloseButton = _d === void 0 ? false : _d, _e = _a.variant, variant = _e === void 0 ? 'toast' : _e, autoDismiss = _a.autoDismiss;
|
|
21
|
+
var id = _a.id, _c = _a.open, open = _c === void 0 ? true : _c, type = _a.type, message = _a.message, secondMessage = _a.secondMessage, onClose = _a.onClose, _d = _a.showCloseButton, showCloseButton = _d === void 0 ? false : _d, _e = _a.variant, variant = _e === void 0 ? 'toast' : _e, autoDismiss = _a.autoDismiss;
|
|
22
22
|
var _f = useState(false), isVisible = _f[0], setIsVisible = _f[1];
|
|
23
23
|
var _g = useState(false), shouldRender = _g[0], setShouldRender = _g[1];
|
|
24
24
|
// Auto-dismiss pauses while the toast is hovered or focused
|
|
@@ -66,7 +66,7 @@ export default function Alert(_a) {
|
|
|
66
66
|
var bgClasses = (_b = bgClassMap[type]) !== null && _b !== void 0 ? _b : bgClassMap.default;
|
|
67
67
|
// The default alert sits on secondary.main, whose label is secondary.contrast; the status backgrounds take text.primary
|
|
68
68
|
var textClasses = bgClasses === bgClassMap.default ? 'text-secondary-contrast' : 'text-fg-primary';
|
|
69
|
-
var alertContent = (<div
|
|
69
|
+
var alertContent = (<div id={id}
|
|
70
70
|
// Errors interrupt screen readers; everything else is announced politely
|
|
71
71
|
role={type === 'error' ? 'alert' : 'status'} onMouseEnter={function () { return setIsPaused(true); }} onMouseLeave={function () { return setIsPaused(false); }} onFocus={function () { return setIsPaused(true); }} onBlur={function () { return setIsPaused(false); }} className={"flex ".concat(secondMessage ? 'items-start' : 'items-center', " justify-between w-full p-2 rounded-control transition-[opacity,transform] ").concat(isVisible ? motionClasses.enter : motionClasses.exit, " motion-reduce:transition-none ").concat(bgClasses, " ").concat(isVisible ? 'opacity-100 translate-y-0' : variant === 'toast' ? 'opacity-0 -translate-y-[calc(100%+1rem)]' : 'opacity-0', " ").concat(variant === 'toast' ? 'max-w-md pointer-events-auto' : '')}>
|
|
72
72
|
<div className={"flex items-start gap-2 ".concat(textClasses)}>
|
|
@@ -105,11 +105,14 @@ var Button = forwardRef(function Button(_a, ref) {
|
|
|
105
105
|
</div>
|
|
106
106
|
</div>
|
|
107
107
|
{actionIcon && (<span onClick={function (e) {
|
|
108
|
+
// With no handler of its own, the icon is part of the button and the click goes through
|
|
109
|
+
if (!onClickActionIcon)
|
|
110
|
+
return;
|
|
108
111
|
// Don't also trigger the button's own click, or follow the link
|
|
109
112
|
e.stopPropagation();
|
|
110
|
-
if (isLink
|
|
113
|
+
if (isLink)
|
|
111
114
|
e.preventDefault();
|
|
112
|
-
onClickActionIcon
|
|
115
|
+
onClickActionIcon();
|
|
113
116
|
}} className="cursor-pointer">
|
|
114
117
|
<IconSlot icon={actionIcon} className={"".concat(sizeIcon, " flex-shrink-0")}/>
|
|
115
118
|
</span>)}
|
|
@@ -5,6 +5,10 @@ interface CheckboxProps {
|
|
|
5
5
|
checked?: boolean;
|
|
6
6
|
onChange?: (checked: boolean) => void;
|
|
7
7
|
disabled?: boolean;
|
|
8
|
+
/** On the `<input>`, so a `FormField` label can point at it */
|
|
9
|
+
id?: string;
|
|
10
|
+
/** Id of the element that describes the checkbox, e.g. help or error text */
|
|
11
|
+
'aria-describedby'?: string;
|
|
8
12
|
}
|
|
9
|
-
export default function Checkbox({ label, secondLabel, checked, onChange, disabled }: CheckboxProps): React.JSX.Element;
|
|
13
|
+
export default function Checkbox({ label, secondLabel, checked, onChange, disabled, id, 'aria-describedby': ariaDescribedBy, }: CheckboxProps): React.JSX.Element;
|
|
10
14
|
export {};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import React, { useEffect, useState } from 'react';
|
|
3
3
|
import { popTransition, stateTransition } from './sharedStyles';
|
|
4
4
|
export default function Checkbox(_a) {
|
|
5
|
-
var label = _a.label, secondLabel = _a.secondLabel, _b = _a.checked, checked = _b === void 0 ? false : _b, onChange = _a.onChange, _c = _a.disabled, disabled = _c === void 0 ? false : _c;
|
|
5
|
+
var label = _a.label, secondLabel = _a.secondLabel, _b = _a.checked, checked = _b === void 0 ? false : _b, onChange = _a.onChange, _c = _a.disabled, disabled = _c === void 0 ? false : _c, id = _a.id, ariaDescribedBy = _a["aria-describedby"];
|
|
6
6
|
var _d = useState(checked), isChecked = _d[0], setIsChecked = _d[1];
|
|
7
7
|
// Follow the parent when it changes `checked` (e.g. resetting a form)
|
|
8
8
|
useEffect(function () {
|
|
@@ -16,7 +16,7 @@ export default function Checkbox(_a) {
|
|
|
16
16
|
};
|
|
17
17
|
return (<label className={"group relative flex items-start ".concat(disabled ? 'cursor-not-allowed' : 'cursor-pointer')}>
|
|
18
18
|
{/* Native input keeps keyboard focus, Space to toggle and screen-reader semantics */}
|
|
19
|
-
<input type="checkbox" className="peer sr-only" checked={isChecked} disabled={disabled} onChange={handleChange}/>
|
|
19
|
+
<input type="checkbox" id={id} aria-describedby={ariaDescribedBy} className="peer sr-only" checked={isChecked} disabled={disabled} onChange={handleChange}/>
|
|
20
20
|
<span className={"relative flex flex-shrink-0 items-center justify-center w-6 h-6 rounded-full ".concat(stateTransition, "\n peer-focus-visible:outline peer-focus-visible:outline-2 peer-focus-visible:outline-offset-0 peer-focus-visible:outline-fg-primary\n ").concat(disabled ? '' : 'group-hover:bg-action-selected')}>
|
|
21
21
|
{/* Checkbox */}
|
|
22
22
|
<span className={"relative w-4 h-4 border-2 rounded ".concat(stateTransition, " ").concat(disabled
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface CopyFieldProps {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
value: string;
|
|
6
|
+
/** The button's words. Defaults to "Copy". */
|
|
7
|
+
copyLabel?: string;
|
|
8
|
+
/** The button's words for 2 seconds after the text is on the clipboard. Defaults to "Copied". */
|
|
9
|
+
copiedLabel?: string;
|
|
10
|
+
/** A monospace font, for keys and addresses */
|
|
11
|
+
mono?: boolean;
|
|
12
|
+
/** `once` adds the line "Copy it now. You will not see it again." under the field, for a secret shown a single time */
|
|
13
|
+
reveal?: 'once';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A read-only field with a button at its right that copies its text. "Copied" shows only after the
|
|
17
|
+
* browser accepted the text; when it refuses or has no clipboard, a line says to copy by hand.
|
|
18
|
+
*/
|
|
19
|
+
export default function CopyField({ id, label, value, copyLabel, copiedLabel, mono, reveal, }: CopyFieldProps): React.JSX.Element;
|
|
20
|
+
export { CopyField };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
39
|
+
import { copyText } from '../internal/copyField';
|
|
40
|
+
import Button from './button';
|
|
41
|
+
import TextField from './textField';
|
|
42
|
+
/**
|
|
43
|
+
* A read-only field with a button at its right that copies its text. "Copied" shows only after the
|
|
44
|
+
* browser accepted the text; when it refuses or has no clipboard, a line says to copy by hand.
|
|
45
|
+
*/
|
|
46
|
+
export default function CopyField(_a) {
|
|
47
|
+
var _this = this;
|
|
48
|
+
var id = _a.id, label = _a.label, value = _a.value, _b = _a.copyLabel, copyLabel = _b === void 0 ? 'Copy' : _b, _c = _a.copiedLabel, copiedLabel = _c === void 0 ? 'Copied' : _c, _d = _a.mono, mono = _d === void 0 ? false : _d, reveal = _a.reveal;
|
|
49
|
+
var _e = useState(false), copied = _e[0], setCopied = _e[1];
|
|
50
|
+
var _f = useState(false), blocked = _f[0], setBlocked = _f[1];
|
|
51
|
+
var timer = useRef(undefined);
|
|
52
|
+
var mounted = useRef(false);
|
|
53
|
+
useEffect(function () {
|
|
54
|
+
mounted.current = true;
|
|
55
|
+
return function () {
|
|
56
|
+
mounted.current = false;
|
|
57
|
+
clearTimeout(timer.current);
|
|
58
|
+
};
|
|
59
|
+
}, []);
|
|
60
|
+
var handleCopy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
61
|
+
var ok;
|
|
62
|
+
return __generator(this, function (_a) {
|
|
63
|
+
switch (_a.label) {
|
|
64
|
+
case 0: return [4 /*yield*/, copyText(typeof navigator === 'undefined' ? undefined : navigator.clipboard, value)];
|
|
65
|
+
case 1:
|
|
66
|
+
ok = _a.sent();
|
|
67
|
+
if (!mounted.current)
|
|
68
|
+
return [2 /*return*/];
|
|
69
|
+
clearTimeout(timer.current);
|
|
70
|
+
setBlocked(!ok);
|
|
71
|
+
setCopied(ok);
|
|
72
|
+
if (ok)
|
|
73
|
+
timer.current = setTimeout(function () { return setCopied(false); }, 2000);
|
|
74
|
+
return [2 /*return*/];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}); };
|
|
78
|
+
var revealId = "".concat(id, "-reveal");
|
|
79
|
+
var blockedId = "".concat(id, "-blocked");
|
|
80
|
+
var describedBy = [reveal ? revealId : '', blocked ? blockedId : ''].filter(Boolean).join(' ') || undefined;
|
|
81
|
+
return (<div className="flex flex-col w-full">
|
|
82
|
+
<div className={"flex items-end gap-2".concat(mono ? ' [&_input]:font-mono' : '')}>
|
|
83
|
+
<TextField id={id} label={label} value={value} readOnly onChange={function () { }} onFocus={function (e) { return e.target.select(); }} aria-describedby={describedBy}/>
|
|
84
|
+
<div className="flex-shrink-0">
|
|
85
|
+
<Button size="medium" type="secondary" state="enabled" label={copied ? copiedLabel : copyLabel} aria-label={"".concat(copied ? copiedLabel : copyLabel, " ").concat(label)} onClickButton={handleCopy}/>
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
{reveal && (<p id={revealId} className="mt-1 text-fg-secondary text-body2">
|
|
89
|
+
Copy it now. You will not see it again.
|
|
90
|
+
</p>)}
|
|
91
|
+
{blocked && (<p id={blockedId} role="alert" className="mt-1 text-error-text text-body2">
|
|
92
|
+
Copying is blocked here. Select the text and copy it.
|
|
93
|
+
</p>)}
|
|
94
|
+
<span role="status" className="sr-only">
|
|
95
|
+
{copied ? copiedLabel : ''}
|
|
96
|
+
</span>
|
|
97
|
+
</div>);
|
|
98
|
+
}
|
|
99
|
+
export { CopyField };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
/** What a FormField hands to its control */
|
|
3
|
+
export interface FormFieldControlProps {
|
|
4
|
+
id: string;
|
|
5
|
+
/** The help text's id, or the error text's id while there is an error. Absent when neither is shown. */
|
|
6
|
+
'aria-describedby'?: string;
|
|
7
|
+
/** `true` while there is an error. Absent otherwise. */
|
|
8
|
+
'aria-invalid'?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface FormFieldProps {
|
|
11
|
+
/** The control's id. The label points at it. */
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
/** A line under the control. The error replaces it while `error` is set. */
|
|
15
|
+
help?: string;
|
|
16
|
+
/** Shown under the control in place of the help text, and marks the control invalid */
|
|
17
|
+
error?: string;
|
|
18
|
+
/** Adds a required mark to the label that screen readers read as "required" */
|
|
19
|
+
required?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* A function that returns the control, e.g.
|
|
22
|
+
* `{(f) => <TextField id={f.id} aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} … />}`.
|
|
23
|
+
* A render prop, not a cloned child: the ids reach the control through props you can see, so
|
|
24
|
+
* nothing needs a `className`, a spread or a wrapper, and it works with any ODS control that
|
|
25
|
+
* takes `id` and `aria-describedby` (TextField, Textarea, Select, RadioGroup, Checkbox). Only
|
|
26
|
+
* TextField and Textarea take `aria-invalid`.
|
|
27
|
+
* The `<label for>` only names an input, textarea or button. Give a Select or RadioGroup the same
|
|
28
|
+
* text as its `aria-label`.
|
|
29
|
+
*/
|
|
30
|
+
children: (field: FormFieldControlProps) => ReactNode;
|
|
31
|
+
}
|
|
32
|
+
/** A label, a control and its help or error text, tied together for screen readers */
|
|
33
|
+
export default function FormField({ id, label, help, error, required, children }: FormFieldProps): React.JSX.Element;
|
|
34
|
+
export { FormField };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** A label, a control and its help or error text, tied together for screen readers */
|
|
3
|
+
export default function FormField(_a) {
|
|
4
|
+
var id = _a.id, label = _a.label, help = _a.help, error = _a.error, _b = _a.required, required = _b === void 0 ? false : _b, children = _a.children;
|
|
5
|
+
var helpId = "".concat(id, "-help");
|
|
6
|
+
var errorId = "".concat(id, "-error");
|
|
7
|
+
var describedBy = error ? errorId : help ? helpId : undefined;
|
|
8
|
+
return (<div className="flex flex-col w-full">
|
|
9
|
+
<label htmlFor={id} className="mb-1 text-body2 text-fg-secondary">
|
|
10
|
+
{label}
|
|
11
|
+
{required && (<>
|
|
12
|
+
<span aria-hidden="true" className="text-error-text ml-0.5">*</span>
|
|
13
|
+
<span className="sr-only"> required</span>
|
|
14
|
+
</>)}
|
|
15
|
+
</label>
|
|
16
|
+
{children({
|
|
17
|
+
id: id,
|
|
18
|
+
'aria-describedby': describedBy,
|
|
19
|
+
'aria-invalid': error ? true : undefined,
|
|
20
|
+
})}
|
|
21
|
+
{error ? (<p id={errorId} className="mt-1 text-error-text text-body2">
|
|
22
|
+
{error}
|
|
23
|
+
</p>) : (help && (<p id={helpId} className="mt-1 text-fg-secondary text-body2">
|
|
24
|
+
{help}
|
|
25
|
+
</p>))}
|
|
26
|
+
</div>);
|
|
27
|
+
}
|
|
28
|
+
export { FormField };
|
|
@@ -5,8 +5,10 @@ interface HeadingProps {
|
|
|
5
5
|
level?: 1 | 2 | 3 | 4;
|
|
6
6
|
/** How large it is set. */
|
|
7
7
|
size?: 'h4' | 'h5' | 'h6' | 'subtitle1';
|
|
8
|
+
/** `danger` gives the heading the error text color, for a danger zone. */
|
|
9
|
+
color?: 'default' | 'danger';
|
|
8
10
|
id?: string;
|
|
9
11
|
className?: string;
|
|
10
12
|
}
|
|
11
|
-
export default function Heading({ children, level, size, id, className }: HeadingProps): React.JSX.Element;
|
|
13
|
+
export default function Heading({ children, level, size, color, id, className }: HeadingProps): React.JSX.Element;
|
|
12
14
|
export {};
|
|
@@ -6,9 +6,9 @@ var sizes = {
|
|
|
6
6
|
subtitle1: 'text-subtitle1',
|
|
7
7
|
};
|
|
8
8
|
export default function Heading(_a) {
|
|
9
|
-
var children = _a.children, _b = _a.level, level = _b === void 0 ? 3 : _b, _c = _a.size, size = _c === void 0 ? 'h6' : _c, id = _a.id,
|
|
9
|
+
var children = _a.children, _b = _a.level, level = _b === void 0 ? 3 : _b, _c = _a.size, size = _c === void 0 ? 'h6' : _c, _d = _a.color, color = _d === void 0 ? 'default' : _d, id = _a.id, _e = _a.className, className = _e === void 0 ? '' : _e;
|
|
10
10
|
var Tag = "h".concat(level);
|
|
11
|
-
return (<Tag id={id} className={"".concat(sizes[size], " text-fg-primary ").concat(className)}>
|
|
11
|
+
return (<Tag id={id} className={"".concat(sizes[size], " ").concat(color === 'danger' ? 'text-error-text' : 'text-fg-primary', " ").concat(className)}>
|
|
12
12
|
{children}
|
|
13
13
|
</Tag>);
|
|
14
14
|
}
|
package/dist/components/menu.jsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import React, { forwardRef, useEffect, useRef } from 'react';
|
|
3
3
|
import { nextIndex } from '../internal/menu';
|
|
4
|
-
var ITEMS = '[role="menuitem"]:not([aria-disabled="true"])';
|
|
4
|
+
var ITEMS = '[role="menuitem"]:not([aria-disabled="true"]), [role="menuitemradio"]:not([aria-disabled="true"])';
|
|
5
5
|
var Menu = forwardRef(function (_a, ref) {
|
|
6
6
|
var children = _a.children, width = _a.width, _b = _a.className, className = _b === void 0 ? '' : _b, _c = _a.navigable, navigable = _c === void 0 ? false : _c, role = _a.role, id = _a.id, ariaLabel = _a["aria-label"];
|
|
7
7
|
var listRole = role !== null && role !== void 0 ? role : (navigable ? 'menu' : undefined);
|
|
@@ -17,7 +17,7 @@ var Menu = forwardRef(function (_a, ref) {
|
|
|
17
17
|
if (e.altKey || e.ctrlKey || e.metaKey)
|
|
18
18
|
return;
|
|
19
19
|
var list = items();
|
|
20
|
-
var item = e.target.closest('[role="menuitem"]');
|
|
20
|
+
var item = e.target.closest('[role="menuitem"], [role="menuitemradio"]');
|
|
21
21
|
var current = item ? list.indexOf(item) : -1;
|
|
22
22
|
var labels = list.map(function (el) { var _a; return (_a = el.textContent) !== null && _a !== void 0 ? _a : ''; });
|
|
23
23
|
var next = nextIndex({ key: e.key, current: current, count: list.length, labels: labels });
|
|
@@ -20,7 +20,7 @@ interface MenuItemProps {
|
|
|
20
20
|
};
|
|
21
21
|
iconRight?: string;
|
|
22
22
|
rightAction?: React.ReactNode;
|
|
23
|
-
/** ARIA role; Select passes 'option'. Defaults to 'menuitem'. */
|
|
23
|
+
/** ARIA role; Select passes 'option'. Defaults to 'menuitem'. Pass 'menuitemradio' for one current choice among several: `isSelected` then sets `aria-checked`. */
|
|
24
24
|
role?: string;
|
|
25
25
|
id?: string;
|
|
26
26
|
/** Keyboard highlight used by Select's listbox */
|
|
@@ -34,6 +34,8 @@ interface MenuItemProps {
|
|
|
34
34
|
tabIndex?: number;
|
|
35
35
|
/** `danger` gives the label and the left icon the error text color, for Delete and the like. `isSelected` wins over it. */
|
|
36
36
|
color?: 'default' | 'danger';
|
|
37
|
+
/** Marks the current page in a side nav so a screen reader announces it. On a link it goes on the `<a>`, otherwise on the row. */
|
|
38
|
+
'aria-current'?: 'page' | boolean;
|
|
37
39
|
}
|
|
38
|
-
export default function MenuItem({ href, iconName, icon, userHandle, userImgUrl, label, secondLabel, isSelected, onClick, className, size, tag, iconRight, rightAction, role, id, isActive, 'aria-selected': ariaSelected, tabIndex, color, }: MenuItemProps): React.JSX.Element;
|
|
40
|
+
export default function MenuItem({ href, iconName, icon, userHandle, userImgUrl, label, secondLabel, isSelected, onClick, className, size, tag, iconRight, rightAction, role, id, isActive, 'aria-selected': ariaSelected, tabIndex, color, 'aria-current': ariaCurrent, }: MenuItemProps): React.JSX.Element;
|
|
39
41
|
export {};
|
|
@@ -7,7 +7,7 @@ import Tag from './tag';
|
|
|
7
7
|
import { focusRing, pressFeedbackAny, stateTransition } from './sharedStyles';
|
|
8
8
|
export default function MenuItem(_a) {
|
|
9
9
|
var _b;
|
|
10
|
-
var href = _a.href, iconName = _a.iconName, icon = _a.icon, userHandle = _a.userHandle, userImgUrl = _a.userImgUrl, label = _a.label, secondLabel = _a.secondLabel, isSelected = _a.isSelected, onClick = _a.onClick, _c = _a.className, className = _c === void 0 ? '' : _c, _d = _a.size, size = _d === void 0 ? 'medium' : _d, tag = _a.tag, iconRight = _a.iconRight, rightAction = _a.rightAction, _e = _a.role, role = _e === void 0 ? 'menuitem' : _e, id = _a.id, _f = _a.isActive, isActive = _f === void 0 ? false : _f, ariaSelected = _a["aria-selected"], _g = _a.tabIndex, tabIndex = _g === void 0 ? 0 : _g, _h = _a.color, color = _h === void 0 ? 'default' : _h;
|
|
10
|
+
var href = _a.href, iconName = _a.iconName, icon = _a.icon, userHandle = _a.userHandle, userImgUrl = _a.userImgUrl, label = _a.label, secondLabel = _a.secondLabel, isSelected = _a.isSelected, onClick = _a.onClick, _c = _a.className, className = _c === void 0 ? '' : _c, _d = _a.size, size = _d === void 0 ? 'medium' : _d, tag = _a.tag, iconRight = _a.iconRight, rightAction = _a.rightAction, _e = _a.role, role = _e === void 0 ? 'menuitem' : _e, id = _a.id, _f = _a.isActive, isActive = _f === void 0 ? false : _f, ariaSelected = _a["aria-selected"], _g = _a.tabIndex, tabIndex = _g === void 0 ? 0 : _g, _h = _a.color, color = _h === void 0 ? 'default' : _h, ariaCurrent = _a["aria-current"];
|
|
11
11
|
// Size-based icon and text classes
|
|
12
12
|
var iconSize = { tiny: 'w-4 h-4', small: 'w-5 h-5', medium: 'w-6 h-6' }[size];
|
|
13
13
|
var labelClass = { tiny: 'text-caption', small: 'text-body2', medium: 'text-body1' }[size];
|
|
@@ -18,7 +18,7 @@ export default function MenuItem(_a) {
|
|
|
18
18
|
var danger = color === 'danger' && !isSelected;
|
|
19
19
|
var content = (<div id={id} role={href ? undefined : role}
|
|
20
20
|
// A link wrapper is already focusable; otherwise the row itself takes focus
|
|
21
|
-
tabIndex={href ? undefined : tabIndex} aria-selected={role === 'option' ? ariaSelected !== null && ariaSelected !== void 0 ? ariaSelected : !!isSelected : undefined} className={"\n flex items-center ".concat(paddingClass, " rounded-control cursor-pointer justify-between text-left ").concat(stateTransition, " ").concat(pressFeedbackAny, " ").concat(focusRing, "\n ").concat(isSelected
|
|
21
|
+
tabIndex={href ? undefined : tabIndex} aria-selected={role === 'option' ? ariaSelected !== null && ariaSelected !== void 0 ? ariaSelected : !!isSelected : undefined} aria-checked={!href && role === 'menuitemradio' ? !!isSelected : undefined} aria-current={href ? undefined : ariaCurrent} className={"\n flex items-center ".concat(paddingClass, " rounded-control cursor-pointer justify-between text-left ").concat(stateTransition, " ").concat(pressFeedbackAny, " ").concat(focusRing, "\n ").concat(isSelected
|
|
22
22
|
? 'bg-primary-dark text-primary-contrast'
|
|
23
23
|
: "hover:bg-background-accent200 ".concat(isActive ? 'bg-background-accent200' : ''), "\n ").concat(className, "\n ")} style={{ width: '100%' }} onClick={onClick} onKeyDown={function (e) {
|
|
24
24
|
if (!href && e.target === e.currentTarget && (e.key === 'Enter' || e.key === ' ')) {
|
|
@@ -50,5 +50,5 @@ export default function MenuItem(_a) {
|
|
|
50
50
|
</div>)}
|
|
51
51
|
</div>
|
|
52
52
|
</div>);
|
|
53
|
-
return href ? <NextLink href={href} className={"block rounded-control ".concat(focusRing)}>{content}</NextLink> : content;
|
|
53
|
+
return href ? <NextLink href={href} aria-current={ariaCurrent} className={"block rounded-control ".concat(focusRing)}>{content}</NextLink> : content;
|
|
54
54
|
}
|
|
@@ -2,6 +2,14 @@ import React from 'react';
|
|
|
2
2
|
interface NavigationProps {
|
|
3
3
|
children: React.ReactNode;
|
|
4
4
|
className?: string;
|
|
5
|
+
/** Names the landmark when a page has more than one nav, e.g. "Settings". */
|
|
6
|
+
'aria-label'?: string;
|
|
5
7
|
}
|
|
6
|
-
export default function Navigation({ children, className, }: NavigationProps): React.JSX.Element;
|
|
8
|
+
export default function Navigation({ children, className, 'aria-label': ariaLabel, }: NavigationProps): React.JSX.Element;
|
|
9
|
+
interface NavigationGroupProps {
|
|
10
|
+
/** The small label above the items. It names the group for a screen reader. */
|
|
11
|
+
label: string;
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
export declare function NavigationGroup({ label, children }: NavigationGroupProps): React.JSX.Element;
|
|
7
15
|
export { Navigation };
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useId } from 'react';
|
|
3
3
|
export default function Navigation(_a) {
|
|
4
|
-
var children = _a.children, _b = _a.className, className = _b === void 0 ? '' : _b;
|
|
5
|
-
return (<nav className={"\n bg-background-default\n border-r border-misc-divider\n p-2 flex flex-col gap-0.5\n ".concat(className, "\n ")}>
|
|
4
|
+
var children = _a.children, _b = _a.className, className = _b === void 0 ? '' : _b, ariaLabel = _a["aria-label"];
|
|
5
|
+
return (<nav aria-label={ariaLabel} className={"\n bg-background-default\n border-r border-misc-divider\n p-2 flex flex-col gap-0.5\n ".concat(className, "\n ")}>
|
|
6
6
|
{children}
|
|
7
7
|
</nav>);
|
|
8
8
|
}
|
|
9
|
+
// A labelled set of items inside a Navigation. A `role="group"` suits it because Navigation's
|
|
10
|
+
// items are rows, not a list: the group needs no list markup, and it keeps the label tied to them.
|
|
11
|
+
export function NavigationGroup(_a) {
|
|
12
|
+
var label = _a.label, children = _a.children;
|
|
13
|
+
var labelId = useId();
|
|
14
|
+
return (<div role="group" aria-labelledby={labelId} className="flex flex-col gap-0.5 mt-3 first:mt-0">
|
|
15
|
+
<div id={labelId} className="px-2 pb-1 text-caption text-fg-secondary">
|
|
16
|
+
{label}
|
|
17
|
+
</div>
|
|
18
|
+
{children}
|
|
19
|
+
</div>);
|
|
20
|
+
}
|
|
9
21
|
export { Navigation };
|
|
@@ -12,11 +12,15 @@ interface RadioGroupProps {
|
|
|
12
12
|
selectedValue: string;
|
|
13
13
|
onChange: (value: string) => void;
|
|
14
14
|
direction?: 'horizontal' | 'vertical';
|
|
15
|
+
/** On the `radiogroup` element, so a `FormField` label and help text can point at it */
|
|
16
|
+
id?: string;
|
|
15
17
|
'aria-label'?: string;
|
|
18
|
+
/** Id of the element that describes the group, e.g. help or error text */
|
|
19
|
+
'aria-describedby'?: string;
|
|
16
20
|
/** `card` draws each option as a bordered card that is the radio's label, with the selected one in the accent border */
|
|
17
21
|
variant?: 'default' | 'card';
|
|
18
22
|
/** Disables every option */
|
|
19
23
|
disabled?: boolean;
|
|
20
24
|
}
|
|
21
|
-
export default function RadioGroup({ options, selectedValue, onChange, direction, 'aria-label': ariaLabel, variant, disabled, }: RadioGroupProps): React.JSX.Element;
|
|
25
|
+
export default function RadioGroup({ options, selectedValue, onChange, direction, id, 'aria-label': ariaLabel, 'aria-describedby': ariaDescribedBy, variant, disabled, }: RadioGroupProps): React.JSX.Element;
|
|
22
26
|
export {};
|
|
@@ -3,10 +3,10 @@ import React, { useId } from 'react';
|
|
|
3
3
|
import { popTransition, stateTransition } from './sharedStyles';
|
|
4
4
|
import Tag from './tag';
|
|
5
5
|
export default function RadioGroup(_a) {
|
|
6
|
-
var options = _a.options, selectedValue = _a.selectedValue, onChange = _a.onChange, _b = _a.direction, direction = _b === void 0 ? 'vertical' : _b, ariaLabel = _a["aria-label"], _c = _a.variant, variant = _c === void 0 ? 'default' : _c, _d = _a.disabled, disabled = _d === void 0 ? false : _d;
|
|
6
|
+
var options = _a.options, selectedValue = _a.selectedValue, onChange = _a.onChange, _b = _a.direction, direction = _b === void 0 ? 'vertical' : _b, id = _a.id, ariaLabel = _a["aria-label"], ariaDescribedBy = _a["aria-describedby"], _c = _a.variant, variant = _c === void 0 ? 'default' : _c, _d = _a.disabled, disabled = _d === void 0 ? false : _d;
|
|
7
7
|
// One shared name gives native arrow-key movement between the options
|
|
8
8
|
var groupName = useId();
|
|
9
|
-
return (<div role="radiogroup" aria-label={ariaLabel} className={"flex ".concat(direction === 'horizontal' ? 'gap-4' : 'flex-col gap-2')}>
|
|
9
|
+
return (<div role="radiogroup" id={id} aria-label={ariaLabel} aria-describedby={ariaDescribedBy} className={"flex ".concat(direction === 'horizontal' ? 'gap-4' : 'flex-col gap-2')}>
|
|
10
10
|
{options.map(function (option) {
|
|
11
11
|
var isSelected = selectedValue === option.value;
|
|
12
12
|
var isDisabled = disabled || !!option.disabled;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface SegmentedControlProps {
|
|
3
|
+
options: {
|
|
4
|
+
value: string;
|
|
5
|
+
label: string;
|
|
6
|
+
}[];
|
|
7
|
+
/** The selected option's value. The control stays controlled: it shows `value` until the parent changes it. */
|
|
8
|
+
value: string;
|
|
9
|
+
onChange: (value: string) => void;
|
|
10
|
+
/** Names the group, e.g. "Range". Required: the options alone do not say what they choose. */
|
|
11
|
+
'aria-label': string;
|
|
12
|
+
size?: 'medium' | 'small' | 'tiny';
|
|
13
|
+
/** `fill` takes the width of its container. `fit` is as wide as its options, for a control that sits beside a heading. */
|
|
14
|
+
width?: 'fill' | 'fit';
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A row of options that sets one value on the same page, with the look of `TabsContainer fill`.
|
|
18
|
+
* Use tabs to switch panels and this to change a value. Arrow keys move and select; only the
|
|
19
|
+
* selected option is in the tab order.
|
|
20
|
+
*/
|
|
21
|
+
export default function SegmentedControl({ options, value, onChange, 'aria-label': ariaLabel, size, width, }: SegmentedControlProps): React.JSX.Element;
|
|
22
|
+
export { SegmentedControl };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { useRef } from 'react';
|
|
3
|
+
import { SlidingPill, segmentIdleClasses, segmentItemClasses, segmentSelectedClasses, segmentSizes, segmentTrackClasses, segmentTrackStyle, useSlidingIndicator, } from './slidingIndicator';
|
|
4
|
+
/**
|
|
5
|
+
* A row of options that sets one value on the same page, with the look of `TabsContainer fill`.
|
|
6
|
+
* Use tabs to switch panels and this to change a value. Arrow keys move and select; only the
|
|
7
|
+
* selected option is in the tab order.
|
|
8
|
+
*/
|
|
9
|
+
export default function SegmentedControl(_a) {
|
|
10
|
+
var options = _a.options, value = _a.value, onChange = _a.onChange, ariaLabel = _a["aria-label"], _b = _a.size, size = _b === void 0 ? 'medium' : _b, _c = _a.width, width = _c === void 0 ? 'fill' : _c;
|
|
11
|
+
var _d = useSlidingIndicator(options), containerRef = _d.containerRef, indicator = _d.indicator;
|
|
12
|
+
var refs = useRef([]);
|
|
13
|
+
var sizeClasses = segmentSizes[size];
|
|
14
|
+
var selectedIndex = options.findIndex(function (o) { return o.value === value; });
|
|
15
|
+
// With no match the first option is the way in
|
|
16
|
+
var tabStop = selectedIndex === -1 ? 0 : selectedIndex;
|
|
17
|
+
var move = function (to) {
|
|
18
|
+
var _a;
|
|
19
|
+
(_a = refs.current[to]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
20
|
+
onChange(options[to].value);
|
|
21
|
+
};
|
|
22
|
+
var handleKeyDown = function (e) {
|
|
23
|
+
var current = refs.current.findIndex(function (el) { return el === document.activeElement; });
|
|
24
|
+
if (current === -1 || options.length === 0)
|
|
25
|
+
return;
|
|
26
|
+
var last = options.length - 1;
|
|
27
|
+
var next = {
|
|
28
|
+
ArrowRight: current === last ? 0 : current + 1,
|
|
29
|
+
ArrowDown: current === last ? 0 : current + 1,
|
|
30
|
+
ArrowLeft: current === 0 ? last : current - 1,
|
|
31
|
+
ArrowUp: current === 0 ? last : current - 1,
|
|
32
|
+
Home: 0,
|
|
33
|
+
End: last,
|
|
34
|
+
}[e.key];
|
|
35
|
+
if (next === undefined)
|
|
36
|
+
return;
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
move(next);
|
|
39
|
+
};
|
|
40
|
+
return (<div ref={containerRef} role="radiogroup" aria-label={ariaLabel} onKeyDown={handleKeyDown} className={segmentTrackClasses(width === 'fill', options.length > 0)} style={segmentTrackStyle}>
|
|
41
|
+
<SlidingPill indicator={indicator}/>
|
|
42
|
+
{options.map(function (option, i) {
|
|
43
|
+
var selected = i === selectedIndex;
|
|
44
|
+
return (<button key={option.value} ref={function (el) {
|
|
45
|
+
refs.current[i] = el;
|
|
46
|
+
}} type="button" role="radio" aria-checked={selected} tabIndex={i === tabStop ? 0 : -1} data-tab-selected={selected} onClick={function () { return onChange(option.value); }} className={segmentItemClasses(width === 'fill', sizeClasses.tab, selected ? segmentSelectedClasses : segmentIdleClasses)}>
|
|
47
|
+
<div className={"flex flex-col text-center ".concat(sizeClasses.label)}>
|
|
48
|
+
<span className="whitespace-nowrap">{option.label}</span>
|
|
49
|
+
</div>
|
|
50
|
+
</button>);
|
|
51
|
+
})}
|
|
52
|
+
</div>);
|
|
53
|
+
}
|
|
54
|
+
export { SegmentedControl };
|
|
@@ -14,7 +14,11 @@ interface SelectProps {
|
|
|
14
14
|
width?: number | string;
|
|
15
15
|
multiple?: boolean;
|
|
16
16
|
className?: string;
|
|
17
|
+
/** On the combobox element, so a `FormField` label and help text can point at it */
|
|
18
|
+
id?: string;
|
|
17
19
|
'aria-label'?: string;
|
|
20
|
+
/** Id of the element that describes the select, e.g. help or error text */
|
|
21
|
+
'aria-describedby'?: string;
|
|
18
22
|
}
|
|
19
|
-
export default function Select({ value, options, onChange, disabled, placeholder, decoIconName, width, multiple, className, 'aria-label': ariaLabel, }: SelectProps): React.JSX.Element;
|
|
23
|
+
export default function Select({ value, options, onChange, disabled, placeholder, decoIconName, width, multiple, className, id, 'aria-label': ariaLabel, 'aria-describedby': ariaDescribedBy, }: SelectProps): React.JSX.Element;
|
|
20
24
|
export { Select };
|
|
@@ -42,7 +42,7 @@ var popperOptions = {
|
|
|
42
42
|
};
|
|
43
43
|
export default function Select(_a) {
|
|
44
44
|
var _b, _c;
|
|
45
|
-
var value = _a.value, options = _a.options, onChange = _a.onChange, _d = _a.disabled, disabled = _d === void 0 ? false : _d, _e = _a.placeholder, placeholder = _e === void 0 ? 'Label' : _e, decoIconName = _a.decoIconName, width = _a.width, _f = _a.multiple, multiple = _f === void 0 ? false : _f, _g = _a.className, className = _g === void 0 ? '' : _g, ariaLabel = _a["aria-label"];
|
|
45
|
+
var value = _a.value, options = _a.options, onChange = _a.onChange, _d = _a.disabled, disabled = _d === void 0 ? false : _d, _e = _a.placeholder, placeholder = _e === void 0 ? 'Label' : _e, decoIconName = _a.decoIconName, width = _a.width, _f = _a.multiple, multiple = _f === void 0 ? false : _f, _g = _a.className, className = _g === void 0 ? '' : _g, id = _a.id, ariaLabel = _a["aria-label"], ariaDescribedBy = _a["aria-describedby"];
|
|
46
46
|
var _h = useState(false), isOpen = _h[0], setIsOpen = _h[1];
|
|
47
47
|
// Option highlighted by the keyboard; focus itself stays on the trigger
|
|
48
48
|
var _j = useState(-1), activeIndex = _j[0], setActiveIndex = _j[1];
|
|
@@ -210,7 +210,7 @@ export default function Select(_a) {
|
|
|
210
210
|
};
|
|
211
211
|
return (<div className={"relative ".concat(className)} style={{ width: width || '100%' }}>
|
|
212
212
|
{/* Select Button */}
|
|
213
|
-
<div ref={setTrigger} role="combobox" aria-label={ariaLabel} aria-haspopup="listbox" aria-expanded={isOpen} aria-controls={listboxId} aria-activedescendant={isOpen && activeIndex >= 0 ? optionId(activeIndex) : undefined} aria-disabled={disabled || undefined} className={"\n rounded-control\n ".concat(getStateStyles(), "\n ").concat(disabled ? 'cursor-not-allowed' : 'cursor-pointer', "\n ").concat(stateTransition, "\n ").concat(focusRing, "\n ")} onClick={handleToggle} tabIndex={disabled ? -1 : 0} onKeyDown={handleKeyDown}>
|
|
213
|
+
<div ref={setTrigger} role="combobox" id={id} aria-label={ariaLabel} aria-describedby={ariaDescribedBy} aria-haspopup="listbox" aria-expanded={isOpen} aria-controls={listboxId} aria-activedescendant={isOpen && activeIndex >= 0 ? optionId(activeIndex) : undefined} aria-disabled={disabled || undefined} className={"\n rounded-control\n ".concat(getStateStyles(), "\n ").concat(disabled ? 'cursor-not-allowed' : 'cursor-pointer', "\n ").concat(stateTransition, "\n ").concat(focusRing, "\n ")} onClick={handleToggle} tabIndex={disabled ? -1 : 0} onKeyDown={handleKeyDown}>
|
|
214
214
|
{/* Inner Content Container; 7px vertical padding makes the control 40px like Button and TextField */}
|
|
215
215
|
<div className={"flex items-center justify-between px-2 py-[7px] ".concat(getTextColor())}>
|
|
216
216
|
{/* Content Container */}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface SettingsSectionProps {
|
|
3
|
+
title: string;
|
|
4
|
+
/** One line under the title, in secondary text. */
|
|
5
|
+
description?: string;
|
|
6
|
+
/** The section's controls, in one column. */
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
/** `danger` colors the title and the line above with the error colors, for a danger zone. */
|
|
9
|
+
tone?: 'default' | 'danger';
|
|
10
|
+
/** The section's id; the title gets `<id>-title`. Lets a nav link to the section. */
|
|
11
|
+
id?: string;
|
|
12
|
+
/** The title's element. Default 2. */
|
|
13
|
+
level?: 2 | 3 | 4;
|
|
14
|
+
}
|
|
15
|
+
export default function SettingsSection({ title, description, children, tone, id, level }: SettingsSectionProps): React.JSX.Element;
|
|
16
|
+
interface SettingsColumnsProps {
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
}
|
|
19
|
+
export declare function SettingsColumns({ children }: SettingsColumnsProps): React.JSX.Element;
|
|
20
|
+
interface SettingsLayoutProps {
|
|
21
|
+
/** The side navigation, a `Navigation`. */
|
|
22
|
+
nav: React.ReactNode;
|
|
23
|
+
/** The open area's content. */
|
|
24
|
+
children: React.ReactNode;
|
|
25
|
+
/** Below md, show the content (`true`) or the nav (`false`). From md up the nav and the content always sit side by side. */
|
|
26
|
+
showContent: boolean;
|
|
27
|
+
/** A Button that goes back to the nav. Shown only below md, above the content. */
|
|
28
|
+
back?: React.ReactNode;
|
|
29
|
+
}
|
|
30
|
+
export declare function SettingsLayout({ nav, children, showContent, back }: SettingsLayoutProps): React.JSX.Element;
|
|
31
|
+
export { SettingsSection };
|