@auth0/quantum-product 2.10.4 → 2.10.5

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/esm/index.js CHANGED
@@ -66,6 +66,7 @@ export * from './radio';
66
66
  export * from './radio-field';
67
67
  export * from './region';
68
68
  export * from './row-layout';
69
+ export * from './segmented-control';
69
70
  export * from './select';
70
71
  export * from './select-dropdown';
71
72
  export * from './selectable-card';
@@ -0,0 +1,3 @@
1
+ export { SegmentedControl } from './segmented-control';
2
+ export { SegmentedControlContext, useSegmentedControlContext } from './segmented-control-context';
3
+ export * from './segment';
@@ -0,0 +1 @@
1
+ export { Segment } from './segment';
@@ -0,0 +1,78 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import * as React from 'react';
24
+ import { styled } from '../../styled';
25
+ import { useSegmentedControlContext } from '../segmented-control-context';
26
+ var SegmentRoot = styled('button')(function (_a) {
27
+ var theme = _a.theme, ownerState = _a.ownerState;
28
+ return (__assign(__assign(__assign(__assign(__assign(__assign({ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', position: 'relative', zIndex: 1, gap: theme.spacing(0.5), border: 'none', borderRadius: 4, cursor: ownerState.disabled ? 'not-allowed' : 'pointer', fontFamily: theme.typography.fontFamily, fontWeight: theme.typography.fontWeightSemibold, transition: theme.transitions.create(['color'], {
29
+ duration: theme.transitions.duration.shortest,
30
+ }), outline: 'none', userSelect: 'none', whiteSpace: 'nowrap' }, (ownerState.fullWidth && { flex: 1 })), (ownerState.size === 'medium' && {
31
+ minWidth: 80,
32
+ padding: '5px 16px',
33
+ fontSize: theme.typography.pxToRem(14),
34
+ lineHeight: '22px',
35
+ minHeight: 32,
36
+ })), (ownerState.size === 'small' && {
37
+ minWidth: 64,
38
+ padding: '3px 12px',
39
+ fontSize: theme.typography.pxToRem(12),
40
+ lineHeight: '18px',
41
+ minHeight: 24,
42
+ })), { backgroundColor: 'transparent', color: ownerState.disabled ? theme.tokens.color_fg_disabled : theme.tokens.color_fg_default }), (!ownerState.selected &&
43
+ !ownerState.disabled && {
44
+ '&:hover': {
45
+ backgroundColor: theme.tokens.color_bg_state_neutral_subtle,
46
+ color: theme.tokens.color_fg_default,
47
+ },
48
+ })), { '&:focus-visible': {
49
+ outline: "2px solid ".concat(theme.tokens.color_border_focus),
50
+ outlineOffset: 2,
51
+ } }));
52
+ });
53
+ var IconWrapper = styled('span')({
54
+ display: 'inline-flex',
55
+ alignItems: 'center',
56
+ flexShrink: 0,
57
+ fontSize: '1em',
58
+ });
59
+ export var Segment = React.forwardRef(function (_a, ref) {
60
+ var value = _a.value, label = _a.label, icon = _a.icon, _b = _a.disabled, disabled = _b === void 0 ? false : _b, analyticsId = _a.analyticsId, ariaLabel = _a["aria-label"], rest = __rest(_a, ["value", "label", "icon", "disabled", "analyticsId", 'aria-label']);
61
+ var _c = useSegmentedControlContext(), selectedValue = _c.value, onChange = _c.onChange, _d = _c.size, size = _d === void 0 ? 'medium' : _d, _e = _c.fullWidth, fullWidth = _e === void 0 ? false : _e;
62
+ var selected = selectedValue === value;
63
+ var ownerState = {
64
+ selected: selected,
65
+ size: size,
66
+ disabled: disabled,
67
+ fullWidth: fullWidth,
68
+ };
69
+ var handleClick = function () {
70
+ if (!disabled && onChange) {
71
+ onChange(value);
72
+ }
73
+ };
74
+ return (React.createElement(SegmentRoot, __assign({ ref: ref, type: "button", role: "radio", "aria-checked": selected, "aria-disabled": disabled, "aria-label": ariaLabel, disabled: disabled, tabIndex: !disabled && selected ? 0 : -1, onClick: handleClick, ownerState: ownerState }, (analyticsId && { 'data-analytics-id': analyticsId }), rest),
75
+ icon && React.createElement(IconWrapper, { "aria-hidden": "true" }, icon),
76
+ label));
77
+ });
78
+ Segment.displayName = 'Segment';
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ export var SegmentedControlContext = React.createContext({
3
+ value: undefined,
4
+ size: 'medium',
5
+ fullWidth: false,
6
+ onChange: function () { return undefined; },
7
+ });
8
+ export var useSegmentedControlContext = function () { return React.useContext(SegmentedControlContext); };
@@ -0,0 +1,124 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ var __read = (this && this.__read) || function (o, n) {
24
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
25
+ if (!m) return o;
26
+ var i = m.call(o), r, ar = [], e;
27
+ try {
28
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
29
+ }
30
+ catch (error) { e = { error: error }; }
31
+ finally {
32
+ try {
33
+ if (r && !r.done && (m = i["return"])) m.call(i);
34
+ }
35
+ finally { if (e) throw e.error; }
36
+ }
37
+ return ar;
38
+ };
39
+ import * as React from 'react';
40
+ import { styled } from '../styled';
41
+ import { SegmentedControlContext } from './segmented-control-context';
42
+ var Root = styled('div')(function (_a) {
43
+ var theme = _a.theme, fullWidth = _a.fullWidth;
44
+ return (__assign({ display: 'inline-flex', alignItems: 'center', position: 'relative', backgroundColor: theme.tokens.color_bg_layer_alternate, borderRadius: theme.shape.borderRadius * 2, padding: theme.spacing(0.5), gap: theme.spacing(0.5) }, (fullWidth && {
45
+ display: 'flex',
46
+ width: '100%',
47
+ })));
48
+ });
49
+ var Indicator = styled('div')(function (_a) {
50
+ var theme = _a.theme;
51
+ return ({
52
+ position: 'absolute',
53
+ borderRadius: 4,
54
+ backgroundColor: theme.palette.background.paper,
55
+ boxShadow: '0px 1px 2px -1px rgba(0, 0, 0, 0.1), 0px 2px 4px -2px rgba(0, 0, 0, 0.1), 0px 4px 8px -4px rgba(0, 0, 0, 0.1), 0px 0px 0px 1px rgba(0, 0, 0, 0.1), inset 0px -1px 2px -1px rgba(0, 0, 0, 0.1)',
56
+ transition: theme.transitions.create(['left', 'top', 'width', 'height'], {
57
+ duration: theme.transitions.duration.shortest,
58
+ easing: theme.transitions.easing.easeOut,
59
+ }),
60
+ zIndex: 0,
61
+ pointerEvents: 'none',
62
+ });
63
+ });
64
+ export var SegmentedControl = function (_a) {
65
+ var value = _a.value, onChange = _a.onChange, fullWidth = _a.fullWidth, _b = _a.size, size = _b === void 0 ? 'medium' : _b, children = _a.children, analyticsId = _a.analyticsId, ariaLabel = _a["aria-label"], ariaLabelledby = _a["aria-labelledby"], rest = __rest(_a, ["value", "onChange", "fullWidth", "size", "children", "analyticsId", 'aria-label', 'aria-labelledby']);
66
+ var containerRef = React.useRef(null);
67
+ var _c = __read(React.useState({}), 2), indicatorStyle = _c[0], setIndicatorStyle = _c[1];
68
+ var hasMounted = React.useRef(false);
69
+ var updateIndicator = React.useCallback(function () {
70
+ if (!containerRef.current)
71
+ return;
72
+ var selectedEl = containerRef.current.querySelector('[role="radio"][aria-checked="true"]');
73
+ if (!selectedEl)
74
+ return;
75
+ var containerRect = containerRef.current.getBoundingClientRect();
76
+ var selectedRect = selectedEl.getBoundingClientRect();
77
+ setIndicatorStyle(__assign({ left: selectedRect.left - containerRect.left, top: selectedRect.top - containerRect.top, width: selectedRect.width, height: selectedRect.height }, (hasMounted.current ? {} : { transition: 'none' })));
78
+ hasMounted.current = true;
79
+ }, []);
80
+ React.useLayoutEffect(function () {
81
+ updateIndicator();
82
+ }, [value, size, fullWidth, updateIndicator]);
83
+ React.useLayoutEffect(function () {
84
+ if (!containerRef.current || typeof ResizeObserver === 'undefined')
85
+ return;
86
+ var observer = new ResizeObserver(function () { return updateIndicator(); });
87
+ observer.observe(containerRef.current);
88
+ return function () { return observer.disconnect(); };
89
+ }, [updateIndicator]);
90
+ var handleKeyDown = function (e) {
91
+ if (!containerRef.current)
92
+ return;
93
+ var segments = Array.from(containerRef.current.querySelectorAll('[role="radio"]:not([disabled])'));
94
+ if (segments.length === 0)
95
+ return;
96
+ var currentIndex = segments.indexOf(document.activeElement);
97
+ var nextIndex = null;
98
+ if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
99
+ e.preventDefault();
100
+ nextIndex = currentIndex < segments.length - 1 ? currentIndex + 1 : 0;
101
+ }
102
+ else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
103
+ e.preventDefault();
104
+ nextIndex = currentIndex > 0 ? currentIndex - 1 : segments.length - 1;
105
+ }
106
+ else if (e.key === 'Home') {
107
+ e.preventDefault();
108
+ nextIndex = 0;
109
+ }
110
+ else if (e.key === 'End') {
111
+ e.preventDefault();
112
+ nextIndex = segments.length - 1;
113
+ }
114
+ if (nextIndex !== null) {
115
+ segments[nextIndex].focus();
116
+ segments[nextIndex].click();
117
+ }
118
+ };
119
+ var ctx = React.useMemo(function () { return ({ value: value, onChange: onChange, size: size, fullWidth: fullWidth }); }, [value, onChange, size, fullWidth]);
120
+ return (React.createElement(SegmentedControlContext.Provider, { value: ctx },
121
+ React.createElement(Root, __assign({ ref: containerRef, fullWidth: fullWidth, role: "radiogroup", onKeyDown: handleKeyDown, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby }, (analyticsId && { 'data-analytics-id': analyticsId }), rest),
122
+ React.createElement(Indicator, { "aria-hidden": "true", style: indicatorStyle }),
123
+ children)));
124
+ };
package/index.d.ts CHANGED
@@ -66,6 +66,7 @@ export * from './radio';
66
66
  export * from './radio-field';
67
67
  export * from './region';
68
68
  export * from './row-layout';
69
+ export * from './segmented-control';
69
70
  export * from './select';
70
71
  export * from './select-dropdown';
71
72
  export * from './selectable-card';
package/index.js CHANGED
@@ -82,6 +82,7 @@ __exportStar(require("./radio"), exports);
82
82
  __exportStar(require("./radio-field"), exports);
83
83
  __exportStar(require("./region"), exports);
84
84
  __exportStar(require("./row-layout"), exports);
85
+ __exportStar(require("./segmented-control"), exports);
85
86
  __exportStar(require("./select"), exports);
86
87
  __exportStar(require("./select-dropdown"), exports);
87
88
  __exportStar(require("./selectable-card"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auth0/quantum-product",
3
- "version": "2.10.4",
3
+ "version": "2.10.5",
4
4
  "sideEffects": false,
5
5
  "license": "Apache-2.0",
6
6
  "publishConfig": {
@@ -0,0 +1,5 @@
1
+ export { SegmentedControl } from './segmented-control';
2
+ export type { ISegmentedControlProps } from './segmented-control';
3
+ export { SegmentedControlContext, useSegmentedControlContext } from './segmented-control-context';
4
+ export type { ISegmentedControlContextValue } from './segmented-control-context';
5
+ export * from './segment';
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.useSegmentedControlContext = exports.SegmentedControlContext = exports.SegmentedControl = void 0;
18
+ var segmented_control_1 = require("./segmented-control");
19
+ Object.defineProperty(exports, "SegmentedControl", { enumerable: true, get: function () { return segmented_control_1.SegmentedControl; } });
20
+ var segmented_control_context_1 = require("./segmented-control-context");
21
+ Object.defineProperty(exports, "SegmentedControlContext", { enumerable: true, get: function () { return segmented_control_context_1.SegmentedControlContext; } });
22
+ Object.defineProperty(exports, "useSegmentedControlContext", { enumerable: true, get: function () { return segmented_control_context_1.useSegmentedControlContext; } });
23
+ __exportStar(require("./segment"), exports);
@@ -0,0 +1,2 @@
1
+ export { Segment } from './segment';
2
+ export type { ISegmentProps } from './segment';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Segment = void 0;
4
+ var segment_1 = require("./segment");
5
+ Object.defineProperty(exports, "Segment", { enumerable: true, get: function () { return segment_1.Segment; } });
@@ -0,0 +1,38 @@
1
+ import * as React from 'react';
2
+ import { OverrideProps } from '../../overridable-component';
3
+ export interface ISegmentTypeMap<P = {}, D extends React.ElementType = 'button'> {
4
+ props: P & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'type' | 'onClick'> & {
5
+ /** The value represented by this segment */
6
+ value: string | number;
7
+ /** Text label for the segment */
8
+ label?: string;
9
+ /** Icon to display inside the segment */
10
+ icon?: React.ReactNode;
11
+ /** If true, the segment cannot be selected */
12
+ disabled?: boolean;
13
+ analyticsId?: string;
14
+ /**
15
+ * Accessible label — required when the segment contains only an icon and no visible label.
16
+ * Screen readers will announce this instead of the icon content.
17
+ */
18
+ 'aria-label'?: string;
19
+ };
20
+ defaultComponent: D;
21
+ }
22
+ export type ISegmentProps<D extends React.ElementType = ISegmentTypeMap['defaultComponent'], P = {}> = OverrideProps<ISegmentTypeMap<P, D>, D>;
23
+ export declare const Segment: React.ForwardRefExoticComponent<Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "type" | "onClick"> & {
24
+ /** The value represented by this segment */
25
+ value: string | number;
26
+ /** Text label for the segment */
27
+ label?: string;
28
+ /** Icon to display inside the segment */
29
+ icon?: React.ReactNode;
30
+ /** If true, the segment cannot be selected */
31
+ disabled?: boolean;
32
+ analyticsId?: string;
33
+ /**
34
+ * Accessible label — required when the segment contains only an icon and no visible label.
35
+ * Screen readers will announce this instead of the icon content.
36
+ */
37
+ 'aria-label'?: string;
38
+ } & Omit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "form" | "label" | "slot" | "style" | "title" | "ref" | "disabled" | "color" | "hidden" | "content" | "icon" | "translate" | "suppressHydrationWarning" | "className" | "id" | "lang" | "name" | "role" | "tabIndex" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-braillelabel" | "aria-brailleroledescription" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colindextext" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-description" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowindextext" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerLeave" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "accessKey" | "autoCapitalize" | "autoFocus" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "enterKeyHint" | "nonce" | "spellCheck" | "radioGroup" | "about" | "datatype" | "inlist" | "prefix" | "property" | "rel" | "resource" | "rev" | "typeof" | "vocab" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "exportparts" | "part" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "value" | "analyticsId"> & React.RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || (function () {
30
+ var ownKeys = function(o) {
31
+ ownKeys = Object.getOwnPropertyNames || function (o) {
32
+ var ar = [];
33
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
+ return ar;
35
+ };
36
+ return ownKeys(o);
37
+ };
38
+ return function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ })();
46
+ var __rest = (this && this.__rest) || function (s, e) {
47
+ var t = {};
48
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
49
+ t[p] = s[p];
50
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
51
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
52
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
53
+ t[p[i]] = s[p[i]];
54
+ }
55
+ return t;
56
+ };
57
+ Object.defineProperty(exports, "__esModule", { value: true });
58
+ exports.Segment = void 0;
59
+ var React = __importStar(require("react"));
60
+ var styled_1 = require("../../styled");
61
+ var segmented_control_context_1 = require("../segmented-control-context");
62
+ var SegmentRoot = (0, styled_1.styled)('button')(function (_a) {
63
+ var theme = _a.theme, ownerState = _a.ownerState;
64
+ return (__assign(__assign(__assign(__assign(__assign(__assign({ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', position: 'relative', zIndex: 1, gap: theme.spacing(0.5), border: 'none', borderRadius: 4, cursor: ownerState.disabled ? 'not-allowed' : 'pointer', fontFamily: theme.typography.fontFamily, fontWeight: theme.typography.fontWeightSemibold, transition: theme.transitions.create(['color'], {
65
+ duration: theme.transitions.duration.shortest,
66
+ }), outline: 'none', userSelect: 'none', whiteSpace: 'nowrap' }, (ownerState.fullWidth && { flex: 1 })), (ownerState.size === 'medium' && {
67
+ minWidth: 80,
68
+ padding: '5px 16px',
69
+ fontSize: theme.typography.pxToRem(14),
70
+ lineHeight: '22px',
71
+ minHeight: 32,
72
+ })), (ownerState.size === 'small' && {
73
+ minWidth: 64,
74
+ padding: '3px 12px',
75
+ fontSize: theme.typography.pxToRem(12),
76
+ lineHeight: '18px',
77
+ minHeight: 24,
78
+ })), { backgroundColor: 'transparent', color: ownerState.disabled ? theme.tokens.color_fg_disabled : theme.tokens.color_fg_default }), (!ownerState.selected &&
79
+ !ownerState.disabled && {
80
+ '&:hover': {
81
+ backgroundColor: theme.tokens.color_bg_state_neutral_subtle,
82
+ color: theme.tokens.color_fg_default,
83
+ },
84
+ })), { '&:focus-visible': {
85
+ outline: "2px solid ".concat(theme.tokens.color_border_focus),
86
+ outlineOffset: 2,
87
+ } }));
88
+ });
89
+ var IconWrapper = (0, styled_1.styled)('span')({
90
+ display: 'inline-flex',
91
+ alignItems: 'center',
92
+ flexShrink: 0,
93
+ fontSize: '1em',
94
+ });
95
+ exports.Segment = React.forwardRef(function (_a, ref) {
96
+ var value = _a.value, label = _a.label, icon = _a.icon, _b = _a.disabled, disabled = _b === void 0 ? false : _b, analyticsId = _a.analyticsId, ariaLabel = _a["aria-label"], rest = __rest(_a, ["value", "label", "icon", "disabled", "analyticsId", 'aria-label']);
97
+ var _c = (0, segmented_control_context_1.useSegmentedControlContext)(), selectedValue = _c.value, onChange = _c.onChange, _d = _c.size, size = _d === void 0 ? 'medium' : _d, _e = _c.fullWidth, fullWidth = _e === void 0 ? false : _e;
98
+ var selected = selectedValue === value;
99
+ var ownerState = {
100
+ selected: selected,
101
+ size: size,
102
+ disabled: disabled,
103
+ fullWidth: fullWidth,
104
+ };
105
+ var handleClick = function () {
106
+ if (!disabled && onChange) {
107
+ onChange(value);
108
+ }
109
+ };
110
+ return (React.createElement(SegmentRoot, __assign({ ref: ref, type: "button", role: "radio", "aria-checked": selected, "aria-disabled": disabled, "aria-label": ariaLabel, disabled: disabled, tabIndex: !disabled && selected ? 0 : -1, onClick: handleClick, ownerState: ownerState }, (analyticsId && { 'data-analytics-id': analyticsId }), rest),
111
+ icon && React.createElement(IconWrapper, { "aria-hidden": "true" }, icon),
112
+ label));
113
+ });
114
+ exports.Segment.displayName = 'Segment';
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ export interface ISegmentedControlContextValue {
3
+ value?: string | number;
4
+ size?: 'small' | 'medium';
5
+ fullWidth?: boolean;
6
+ onChange?(value: string | number): void;
7
+ }
8
+ export declare const SegmentedControlContext: React.Context<ISegmentedControlContextValue>;
9
+ export declare const useSegmentedControlContext: () => ISegmentedControlContextValue;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.useSegmentedControlContext = exports.SegmentedControlContext = void 0;
37
+ var React = __importStar(require("react"));
38
+ exports.SegmentedControlContext = React.createContext({
39
+ value: undefined,
40
+ size: 'medium',
41
+ fullWidth: false,
42
+ onChange: function () { return undefined; },
43
+ });
44
+ var useSegmentedControlContext = function () { return React.useContext(exports.SegmentedControlContext); };
45
+ exports.useSegmentedControlContext = useSegmentedControlContext;
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
2
+ export interface ISegmentedControlProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {
3
+ /** The currently selected value */
4
+ value: string | number;
5
+ onChange?: (value: string | number) => void;
6
+ /** If true, the component stretches to fill its container */
7
+ fullWidth?: boolean;
8
+ size?: 'small' | 'medium';
9
+ children: React.ReactNode;
10
+ analyticsId?: string;
11
+ /** Accessible label for the radiogroup — required when no visible label is associated */
12
+ 'aria-label'?: string;
13
+ /** ID of an element that labels this radiogroup */
14
+ 'aria-labelledby'?: string;
15
+ }
16
+ export declare const SegmentedControl: React.FC<ISegmentedControlProps>;
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || (function () {
30
+ var ownKeys = function(o) {
31
+ ownKeys = Object.getOwnPropertyNames || function (o) {
32
+ var ar = [];
33
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
+ return ar;
35
+ };
36
+ return ownKeys(o);
37
+ };
38
+ return function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ })();
46
+ var __rest = (this && this.__rest) || function (s, e) {
47
+ var t = {};
48
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
49
+ t[p] = s[p];
50
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
51
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
52
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
53
+ t[p[i]] = s[p[i]];
54
+ }
55
+ return t;
56
+ };
57
+ var __read = (this && this.__read) || function (o, n) {
58
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
59
+ if (!m) return o;
60
+ var i = m.call(o), r, ar = [], e;
61
+ try {
62
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
63
+ }
64
+ catch (error) { e = { error: error }; }
65
+ finally {
66
+ try {
67
+ if (r && !r.done && (m = i["return"])) m.call(i);
68
+ }
69
+ finally { if (e) throw e.error; }
70
+ }
71
+ return ar;
72
+ };
73
+ Object.defineProperty(exports, "__esModule", { value: true });
74
+ exports.SegmentedControl = void 0;
75
+ var React = __importStar(require("react"));
76
+ var styled_1 = require("../styled");
77
+ var segmented_control_context_1 = require("./segmented-control-context");
78
+ var Root = (0, styled_1.styled)('div')(function (_a) {
79
+ var theme = _a.theme, fullWidth = _a.fullWidth;
80
+ return (__assign({ display: 'inline-flex', alignItems: 'center', position: 'relative', backgroundColor: theme.tokens.color_bg_layer_alternate, borderRadius: theme.shape.borderRadius * 2, padding: theme.spacing(0.5), gap: theme.spacing(0.5) }, (fullWidth && {
81
+ display: 'flex',
82
+ width: '100%',
83
+ })));
84
+ });
85
+ var Indicator = (0, styled_1.styled)('div')(function (_a) {
86
+ var theme = _a.theme;
87
+ return ({
88
+ position: 'absolute',
89
+ borderRadius: 4,
90
+ backgroundColor: theme.palette.background.paper,
91
+ boxShadow: '0px 1px 2px -1px rgba(0, 0, 0, 0.1), 0px 2px 4px -2px rgba(0, 0, 0, 0.1), 0px 4px 8px -4px rgba(0, 0, 0, 0.1), 0px 0px 0px 1px rgba(0, 0, 0, 0.1), inset 0px -1px 2px -1px rgba(0, 0, 0, 0.1)',
92
+ transition: theme.transitions.create(['left', 'top', 'width', 'height'], {
93
+ duration: theme.transitions.duration.shortest,
94
+ easing: theme.transitions.easing.easeOut,
95
+ }),
96
+ zIndex: 0,
97
+ pointerEvents: 'none',
98
+ });
99
+ });
100
+ var SegmentedControl = function (_a) {
101
+ var value = _a.value, onChange = _a.onChange, fullWidth = _a.fullWidth, _b = _a.size, size = _b === void 0 ? 'medium' : _b, children = _a.children, analyticsId = _a.analyticsId, ariaLabel = _a["aria-label"], ariaLabelledby = _a["aria-labelledby"], rest = __rest(_a, ["value", "onChange", "fullWidth", "size", "children", "analyticsId", 'aria-label', 'aria-labelledby']);
102
+ var containerRef = React.useRef(null);
103
+ var _c = __read(React.useState({}), 2), indicatorStyle = _c[0], setIndicatorStyle = _c[1];
104
+ var hasMounted = React.useRef(false);
105
+ var updateIndicator = React.useCallback(function () {
106
+ if (!containerRef.current)
107
+ return;
108
+ var selectedEl = containerRef.current.querySelector('[role="radio"][aria-checked="true"]');
109
+ if (!selectedEl)
110
+ return;
111
+ var containerRect = containerRef.current.getBoundingClientRect();
112
+ var selectedRect = selectedEl.getBoundingClientRect();
113
+ setIndicatorStyle(__assign({ left: selectedRect.left - containerRect.left, top: selectedRect.top - containerRect.top, width: selectedRect.width, height: selectedRect.height }, (hasMounted.current ? {} : { transition: 'none' })));
114
+ hasMounted.current = true;
115
+ }, []);
116
+ React.useLayoutEffect(function () {
117
+ updateIndicator();
118
+ }, [value, size, fullWidth, updateIndicator]);
119
+ React.useLayoutEffect(function () {
120
+ if (!containerRef.current || typeof ResizeObserver === 'undefined')
121
+ return;
122
+ var observer = new ResizeObserver(function () { return updateIndicator(); });
123
+ observer.observe(containerRef.current);
124
+ return function () { return observer.disconnect(); };
125
+ }, [updateIndicator]);
126
+ var handleKeyDown = function (e) {
127
+ if (!containerRef.current)
128
+ return;
129
+ var segments = Array.from(containerRef.current.querySelectorAll('[role="radio"]:not([disabled])'));
130
+ if (segments.length === 0)
131
+ return;
132
+ var currentIndex = segments.indexOf(document.activeElement);
133
+ var nextIndex = null;
134
+ if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
135
+ e.preventDefault();
136
+ nextIndex = currentIndex < segments.length - 1 ? currentIndex + 1 : 0;
137
+ }
138
+ else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
139
+ e.preventDefault();
140
+ nextIndex = currentIndex > 0 ? currentIndex - 1 : segments.length - 1;
141
+ }
142
+ else if (e.key === 'Home') {
143
+ e.preventDefault();
144
+ nextIndex = 0;
145
+ }
146
+ else if (e.key === 'End') {
147
+ e.preventDefault();
148
+ nextIndex = segments.length - 1;
149
+ }
150
+ if (nextIndex !== null) {
151
+ segments[nextIndex].focus();
152
+ segments[nextIndex].click();
153
+ }
154
+ };
155
+ var ctx = React.useMemo(function () { return ({ value: value, onChange: onChange, size: size, fullWidth: fullWidth }); }, [value, onChange, size, fullWidth]);
156
+ return (React.createElement(segmented_control_context_1.SegmentedControlContext.Provider, { value: ctx },
157
+ React.createElement(Root, __assign({ ref: containerRef, fullWidth: fullWidth, role: "radiogroup", onKeyDown: handleKeyDown, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby }, (analyticsId && { 'data-analytics-id': analyticsId }), rest),
158
+ React.createElement(Indicator, { "aria-hidden": "true", style: indicatorStyle }),
159
+ children)));
160
+ };
161
+ exports.SegmentedControl = SegmentedControl;