@auth0/quantum-product 2.10.3 → 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.
@@ -32,6 +32,22 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __read = (this && this.__read) || function (o, n) {
36
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
37
+ if (!m) return o;
38
+ var i = m.call(o), r, ar = [], e;
39
+ try {
40
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
41
+ }
42
+ catch (error) { e = { error: error }; }
43
+ finally {
44
+ try {
45
+ if (r && !r.done && (m = i["return"])) m.call(i);
46
+ }
47
+ finally { if (e) throw e.error; }
48
+ }
49
+ return ar;
50
+ };
35
51
  Object.defineProperty(exports, "__esModule", { value: true });
36
52
  exports.CommandPaletteGroupContext = exports.CommandPaletteStoreContext = exports.CommandPaletteContext = void 0;
37
53
  exports.useCommandPaletteContext = useCommandPaletteContext;
@@ -57,5 +73,21 @@ function useCommandPaletteStore() {
57
73
  }
58
74
  function useCommandPaletteState(selector) {
59
75
  var store = useCommandPaletteStore();
60
- return React.useSyncExternalStore(store.subscribe, function () { return selector(store.snapshot()); }, function () { return selector(store.snapshot()); });
76
+ var selectorRef = React.useRef(selector);
77
+ var _a = __read(React.useState(function () { return selector(store.snapshot()); }), 2), state = _a[0], setState = _a[1];
78
+ React.useEffect(function () {
79
+ selectorRef.current = selector;
80
+ setState(selector(store.snapshot()));
81
+ }, [selector, store]);
82
+ React.useLayoutEffect(function () {
83
+ var unsubscribe = store.subscribe(function () {
84
+ setState(function (prevSelected) {
85
+ var nextSelected = selectorRef.current(store.snapshot());
86
+ return Object.is(prevSelected, nextSelected) ? prevSelected : nextSelected;
87
+ });
88
+ });
89
+ return unsubscribe;
90
+ // eslint-disable-next-line react-hooks/exhaustive-deps
91
+ }, [store]);
92
+ return state;
61
93
  }
@@ -62,6 +62,7 @@ exports.CommandPaletteGroup = void 0;
62
62
  var React = __importStar(require("react"));
63
63
  var styled_1 = require("../styled");
64
64
  var clsx_1 = __importDefault(require("../utils/clsx"));
65
+ var use_id_1 = require("../utils/use-id");
65
66
  var command_palette_classes_1 = require("./command-palette-classes");
66
67
  var command_palette_context_1 = require("./command-palette-context");
67
68
  var Root = (0, styled_1.styled)('div', {
@@ -97,7 +98,7 @@ var Items = (0, styled_1.styled)('div', {
97
98
  }); });
98
99
  exports.CommandPaletteGroup = React.forwardRef(function (props, ref) {
99
100
  var heading = props.heading, _a = props.forceMount, forceMount = _a === void 0 ? false : _a, children = props.children, className = props.className, groupProps = __rest(props, ["heading", "forceMount", "children", "className"]);
100
- var id = React.useId();
101
+ var id = (0, use_id_1.useId)() || '';
101
102
  var headingId = "".concat(id, "-heading");
102
103
  var context = (0, command_palette_context_1.useCommandPaletteContext)();
103
104
  React.useLayoutEffect(function () {
@@ -88,6 +88,7 @@ var React = __importStar(require("react"));
88
88
  var useForkRef_1 = __importDefault(require("@mui/utils/useForkRef"));
89
89
  var styled_1 = require("../styled");
90
90
  var clsx_1 = __importDefault(require("../utils/clsx"));
91
+ var use_id_1 = require("../utils/use-id");
91
92
  var command_palette_1 = require("./command-palette");
92
93
  var command_palette_classes_1 = require("./command-palette-classes");
93
94
  var command_palette_context_1 = require("./command-palette-context");
@@ -197,8 +198,15 @@ function useValue(id, ref, deps) {
197
198
  }
198
199
  exports.CommandPaletteItem = React.forwardRef(function (props, ref) {
199
200
  var _a;
200
- var valueProp = props.value, keywords = props.keywords, _b = props.disabled, disabled = _b === void 0 ? false : _b, onSelect = props.onSelect, _c = props.forceMount, forceMount = _c === void 0 ? false : _c, icon = props.icon, shortcut = props.shortcut, children = props.children, className = props.className, itemProps = __rest(props, ["value", "keywords", "disabled", "onSelect", "forceMount", "icon", "shortcut", "children", "className"]);
201
- var id = React.useId();
201
+ var _b, _c;
202
+ var valueProp = props.value, keywords = props.keywords, _d = props.disabled, disabled = _d === void 0 ? false : _d, onSelect = props.onSelect, _e = props.forceMount, forceMount = _e === void 0 ? false : _e, icon = props.icon, shortcut = props.shortcut, children = props.children, className = props.className, itemProps = __rest(props, ["value", "keywords", "disabled", "onSelect", "forceMount", "icon", "shortcut", "children", "className"]);
203
+ var generatedId = (0, use_id_1.useId)();
204
+ var idRef = React.useRef();
205
+ if (!idRef.current) {
206
+ idRef.current =
207
+ (_c = (_b = itemProps.id) !== null && _b !== void 0 ? _b : generatedId) !== null && _c !== void 0 ? _c : "command-palette-item-".concat(Math.random().toString(36).slice(2));
208
+ }
209
+ var id = idRef.current;
202
210
  var itemRef = React.useRef(null);
203
211
  var context = (0, command_palette_context_1.useCommandPaletteContext)();
204
212
  var store = (0, command_palette_context_1.useCommandPaletteStore)();
@@ -79,6 +79,7 @@ var React = __importStar(require("react"));
79
79
  var styled_1 = require("../styled");
80
80
  var classes_1 = require("../styles/classes");
81
81
  var clsx_1 = __importDefault(require("../utils/clsx"));
82
+ var use_id_1 = require("../utils/use-id");
82
83
  var command_palette_classes_1 = require("./command-palette-classes");
83
84
  var command_palette_context_1 = require("./command-palette-context");
84
85
  var command_palette_score_1 = require("./command-palette-score");
@@ -218,10 +219,12 @@ function useScheduleLayoutEffect() {
218
219
  }, []);
219
220
  }
220
221
  exports.CommandPalette = React.forwardRef(function (props, ref) {
221
- var _a = props.label, label = _a === void 0 ? 'Command palette' : _a, searchProp = props.search, _onSearchChange = props.onSearchChange, valueProp = props.value, _onValueChange = props.onValueChange, filterProp = props.filter, _b = props.shouldFilter, shouldFilter = _b === void 0 ? true : _b, _c = props.loop, loop = _c === void 0 ? false : _c, _onSelect = props.onSelect, children = props.children, className = props.className, rootProps = __rest(props, ["label", "search", "onSearchChange", "value", "onValueChange", "filter", "shouldFilter", "loop", "onSelect", "children", "className"]);
222
- var id = React.useId();
223
- var listId = "".concat(id, "-list");
224
- var inputId = "".concat(id, "-input");
222
+ var _a;
223
+ var _b = props.label, label = _b === void 0 ? 'Command palette' : _b, searchProp = props.search, _onSearchChange = props.onSearchChange, valueProp = props.value, _onValueChange = props.onValueChange, filterProp = props.filter, _c = props.shouldFilter, shouldFilter = _c === void 0 ? true : _c, _d = props.loop, loop = _d === void 0 ? false : _d, _onSelect = props.onSelect, children = props.children, className = props.className, rootProps = __rest(props, ["label", "search", "onSearchChange", "value", "onValueChange", "filter", "shouldFilter", "loop", "onSelect", "children", "className"]);
224
+ var generatedId = (0, use_id_1.useId)();
225
+ var id = (_a = rootProps.id) !== null && _a !== void 0 ? _a : generatedId;
226
+ var listId = id ? "".concat(id, "-list") : undefined;
227
+ var inputId = id ? "".concat(id, "-input") : undefined;
225
228
  var listInnerRef = React.useRef(null);
226
229
  var allItems = React.useRef(new Map());
227
230
  var allGroups = React.useRef(new Map());
@@ -367,9 +370,9 @@ exports.CommandPalette = React.forwardRef(function (props, ref) {
367
370
  };
368
371
  },
369
372
  filter: filter,
370
- label: label,
371
- listId: listId,
372
- inputId: inputId,
373
+ label: label !== null && label !== void 0 ? label : '',
374
+ listId: listId !== null && listId !== void 0 ? listId : '',
375
+ inputId: inputId !== null && inputId !== void 0 ? inputId : '',
373
376
  listInnerRef: listInnerRef,
374
377
  }); },
375
378
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -1,3 +1,19 @@
1
+ var __read = (this && this.__read) || function (o, n) {
2
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
3
+ if (!m) return o;
4
+ var i = m.call(o), r, ar = [], e;
5
+ try {
6
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
+ }
8
+ catch (error) { e = { error: error }; }
9
+ finally {
10
+ try {
11
+ if (r && !r.done && (m = i["return"])) m.call(i);
12
+ }
13
+ finally { if (e) throw e.error; }
14
+ }
15
+ return ar;
16
+ };
1
17
  import * as React from 'react';
2
18
  export var CommandPaletteContext = React.createContext(undefined);
3
19
  export var CommandPaletteStoreContext = React.createContext(undefined);
@@ -18,5 +34,21 @@ export function useCommandPaletteStore() {
18
34
  }
19
35
  export function useCommandPaletteState(selector) {
20
36
  var store = useCommandPaletteStore();
21
- return React.useSyncExternalStore(store.subscribe, function () { return selector(store.snapshot()); }, function () { return selector(store.snapshot()); });
37
+ var selectorRef = React.useRef(selector);
38
+ var _a = __read(React.useState(function () { return selector(store.snapshot()); }), 2), state = _a[0], setState = _a[1];
39
+ React.useEffect(function () {
40
+ selectorRef.current = selector;
41
+ setState(selector(store.snapshot()));
42
+ }, [selector, store]);
43
+ React.useLayoutEffect(function () {
44
+ var unsubscribe = store.subscribe(function () {
45
+ setState(function (prevSelected) {
46
+ var nextSelected = selectorRef.current(store.snapshot());
47
+ return Object.is(prevSelected, nextSelected) ? prevSelected : nextSelected;
48
+ });
49
+ });
50
+ return unsubscribe;
51
+ // eslint-disable-next-line react-hooks/exhaustive-deps
52
+ }, [store]);
53
+ return state;
22
54
  }
@@ -23,6 +23,7 @@ var __rest = (this && this.__rest) || function (s, e) {
23
23
  import * as React from 'react';
24
24
  import { styled } from '../styled';
25
25
  import clsx from '../utils/clsx';
26
+ import { useId } from '../utils/use-id';
26
27
  import { commandPaletteClasses, commandPaletteComponentName } from './command-palette-classes';
27
28
  import { CommandPaletteGroupContext, useCommandPaletteContext, useCommandPaletteState, } from './command-palette-context';
28
29
  var Root = styled('div', {
@@ -58,7 +59,7 @@ var Items = styled('div', {
58
59
  }); });
59
60
  export var CommandPaletteGroup = React.forwardRef(function (props, ref) {
60
61
  var heading = props.heading, _a = props.forceMount, forceMount = _a === void 0 ? false : _a, children = props.children, className = props.className, groupProps = __rest(props, ["heading", "forceMount", "children", "className"]);
61
- var id = React.useId();
62
+ var id = useId() || '';
62
63
  var headingId = "".concat(id, "-heading");
63
64
  var context = useCommandPaletteContext();
64
65
  React.useLayoutEffect(function () {
@@ -49,6 +49,7 @@ import * as React from 'react';
49
49
  import useForkRef from '@mui/utils/useForkRef';
50
50
  import { styled } from '../styled';
51
51
  import clsx from '../utils/clsx';
52
+ import { useId } from '../utils/use-id';
52
53
  import { VALUE_ATTR } from './command-palette';
53
54
  import { commandPaletteClasses, commandPaletteComponentName } from './command-palette-classes';
54
55
  import { CommandPaletteGroupContext, useCommandPaletteContext, useCommandPaletteState, useCommandPaletteStore, } from './command-palette-context';
@@ -158,8 +159,15 @@ function useValue(id, ref, deps) {
158
159
  }
159
160
  export var CommandPaletteItem = React.forwardRef(function (props, ref) {
160
161
  var _a;
161
- var valueProp = props.value, keywords = props.keywords, _b = props.disabled, disabled = _b === void 0 ? false : _b, onSelect = props.onSelect, _c = props.forceMount, forceMount = _c === void 0 ? false : _c, icon = props.icon, shortcut = props.shortcut, children = props.children, className = props.className, itemProps = __rest(props, ["value", "keywords", "disabled", "onSelect", "forceMount", "icon", "shortcut", "children", "className"]);
162
- var id = React.useId();
162
+ var _b, _c;
163
+ var valueProp = props.value, keywords = props.keywords, _d = props.disabled, disabled = _d === void 0 ? false : _d, onSelect = props.onSelect, _e = props.forceMount, forceMount = _e === void 0 ? false : _e, icon = props.icon, shortcut = props.shortcut, children = props.children, className = props.className, itemProps = __rest(props, ["value", "keywords", "disabled", "onSelect", "forceMount", "icon", "shortcut", "children", "className"]);
164
+ var generatedId = useId();
165
+ var idRef = React.useRef();
166
+ if (!idRef.current) {
167
+ idRef.current =
168
+ (_c = (_b = itemProps.id) !== null && _b !== void 0 ? _b : generatedId) !== null && _c !== void 0 ? _c : "command-palette-item-".concat(Math.random().toString(36).slice(2));
169
+ }
170
+ var id = idRef.current;
163
171
  var itemRef = React.useRef(null);
164
172
  var context = useCommandPaletteContext();
165
173
  var store = useCommandPaletteStore();
@@ -40,6 +40,7 @@ import * as React from 'react';
40
40
  import { styled } from '../styled';
41
41
  import { useMergedClasses } from '../styles/classes';
42
42
  import clsx from '../utils/clsx';
43
+ import { useId } from '../utils/use-id';
43
44
  import { commandPaletteClasses, commandPaletteComponentName, getCommandPaletteUtilityClass, } from './command-palette-classes';
44
45
  import { CommandPaletteContext, CommandPaletteStoreContext } from './command-palette-context';
45
46
  import { commandScore } from './command-palette-score';
@@ -178,10 +179,12 @@ function useScheduleLayoutEffect() {
178
179
  }, []);
179
180
  }
180
181
  export var CommandPalette = React.forwardRef(function (props, ref) {
181
- var _a = props.label, label = _a === void 0 ? 'Command palette' : _a, searchProp = props.search, _onSearchChange = props.onSearchChange, valueProp = props.value, _onValueChange = props.onValueChange, filterProp = props.filter, _b = props.shouldFilter, shouldFilter = _b === void 0 ? true : _b, _c = props.loop, loop = _c === void 0 ? false : _c, _onSelect = props.onSelect, children = props.children, className = props.className, rootProps = __rest(props, ["label", "search", "onSearchChange", "value", "onValueChange", "filter", "shouldFilter", "loop", "onSelect", "children", "className"]);
182
- var id = React.useId();
183
- var listId = "".concat(id, "-list");
184
- var inputId = "".concat(id, "-input");
182
+ var _a;
183
+ var _b = props.label, label = _b === void 0 ? 'Command palette' : _b, searchProp = props.search, _onSearchChange = props.onSearchChange, valueProp = props.value, _onValueChange = props.onValueChange, filterProp = props.filter, _c = props.shouldFilter, shouldFilter = _c === void 0 ? true : _c, _d = props.loop, loop = _d === void 0 ? false : _d, _onSelect = props.onSelect, children = props.children, className = props.className, rootProps = __rest(props, ["label", "search", "onSearchChange", "value", "onValueChange", "filter", "shouldFilter", "loop", "onSelect", "children", "className"]);
184
+ var generatedId = useId();
185
+ var id = (_a = rootProps.id) !== null && _a !== void 0 ? _a : generatedId;
186
+ var listId = id ? "".concat(id, "-list") : undefined;
187
+ var inputId = id ? "".concat(id, "-input") : undefined;
185
188
  var listInnerRef = React.useRef(null);
186
189
  var allItems = React.useRef(new Map());
187
190
  var allGroups = React.useRef(new Map());
@@ -327,9 +330,9 @@ export var CommandPalette = React.forwardRef(function (props, ref) {
327
330
  };
328
331
  },
329
332
  filter: filter,
330
- label: label,
331
- listId: listId,
332
- inputId: inputId,
333
+ label: label !== null && label !== void 0 ? label : '',
334
+ listId: listId !== null && listId !== void 0 ? listId : '',
335
+ inputId: inputId !== null && inputId !== void 0 ? inputId : '',
333
336
  listInnerRef: listInnerRef,
334
337
  }); },
335
338
  // eslint-disable-next-line react-hooks/exhaustive-deps
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.3",
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;