@auth0/quantum-product 2.10.4 → 2.10.6
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 +1 -0
- package/esm/segmented-control/index.js +3 -0
- package/esm/segmented-control/segment/index.js +1 -0
- package/esm/segmented-control/segment/segment.js +78 -0
- package/esm/segmented-control/segmented-control-context.js +8 -0
- package/esm/segmented-control/segmented-control.js +155 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/segmented-control/index.d.ts +5 -0
- package/segmented-control/index.js +23 -0
- package/segmented-control/segment/index.d.ts +2 -0
- package/segmented-control/segment/index.js +5 -0
- package/segmented-control/segment/segment.d.ts +38 -0
- package/segmented-control/segment/segment.js +114 -0
- package/segmented-control/segmented-control-context.d.ts +10 -0
- package/segmented-control/segmented-control-context.js +45 -0
- package/segmented-control/segmented-control.d.ts +16 -0
- package/segmented-control/segmented-control.js +192 -0
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 @@
|
|
|
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, tabFocusValue = _c.tabFocusValue, 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, "data-value": value }, (typeof value === 'number' && { 'data-numeric-value': '' }), { disabled: disabled, tabIndex: !disabled && value === tabFocusValue ? 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,155 @@
|
|
|
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 _d = __read(React.useState(null), 2), focusedValue = _d[0], setFocusedValue = _d[1];
|
|
91
|
+
var tabFocusValue = React.useMemo(function () {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
if (focusedValue != null)
|
|
94
|
+
return focusedValue;
|
|
95
|
+
var segments = React.Children.toArray(children).filter(function (child) {
|
|
96
|
+
return React.isValidElement(child);
|
|
97
|
+
});
|
|
98
|
+
var selected = segments.find(function (child) { return child.props.value === value; });
|
|
99
|
+
if (selected && !selected.props.disabled)
|
|
100
|
+
return value;
|
|
101
|
+
return (_b = (_a = segments.find(function (child) { return !child.props.disabled; })) === null || _a === void 0 ? void 0 : _a.props.value) !== null && _b !== void 0 ? _b : value;
|
|
102
|
+
}, [focusedValue, children, value]);
|
|
103
|
+
var handleKeyDown = function (e) {
|
|
104
|
+
if (!containerRef.current)
|
|
105
|
+
return;
|
|
106
|
+
var segments = Array.from(containerRef.current.querySelectorAll('[role="radio"]:not([disabled])'));
|
|
107
|
+
if (segments.length === 0)
|
|
108
|
+
return;
|
|
109
|
+
var currentIndex = segments.indexOf(document.activeElement);
|
|
110
|
+
var nextIndex = null;
|
|
111
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
|
|
112
|
+
e.preventDefault();
|
|
113
|
+
nextIndex = currentIndex < segments.length - 1 ? currentIndex + 1 : 0;
|
|
114
|
+
}
|
|
115
|
+
else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
|
|
116
|
+
e.preventDefault();
|
|
117
|
+
nextIndex = currentIndex > 0 ? currentIndex - 1 : segments.length - 1;
|
|
118
|
+
}
|
|
119
|
+
else if (e.key === 'Home') {
|
|
120
|
+
e.preventDefault();
|
|
121
|
+
nextIndex = 0;
|
|
122
|
+
}
|
|
123
|
+
else if (e.key === 'End') {
|
|
124
|
+
e.preventDefault();
|
|
125
|
+
nextIndex = segments.length - 1;
|
|
126
|
+
}
|
|
127
|
+
else if (e.key === 'Enter' || e.key === ' ') {
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
var focused = document.activeElement;
|
|
130
|
+
if (focused && focused.dataset.value != null) {
|
|
131
|
+
var val = focused.dataset.numericValue != null ? Number(focused.dataset.value) : focused.dataset.value;
|
|
132
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(val);
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (nextIndex !== null) {
|
|
137
|
+
var nextEl = segments[nextIndex];
|
|
138
|
+
nextEl.focus();
|
|
139
|
+
var val = nextEl.dataset.numericValue != null ? Number(nextEl.dataset.value) : nextEl.dataset.value;
|
|
140
|
+
if (val != null)
|
|
141
|
+
setFocusedValue(val);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
var handleBlur = function (e) {
|
|
145
|
+
var _a;
|
|
146
|
+
if (!((_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.relatedTarget))) {
|
|
147
|
+
setFocusedValue(null);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
var ctx = React.useMemo(function () { return ({ value: value, tabFocusValue: tabFocusValue, onChange: onChange, size: size, fullWidth: fullWidth }); }, [value, tabFocusValue, onChange, size, fullWidth]);
|
|
151
|
+
return (React.createElement(SegmentedControlContext.Provider, { value: ctx },
|
|
152
|
+
React.createElement(Root, __assign({ ref: containerRef, fullWidth: fullWidth, role: "radiogroup", onKeyDown: handleKeyDown, onBlur: handleBlur, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby }, (analyticsId && { 'data-analytics-id': analyticsId }), rest),
|
|
153
|
+
React.createElement(Indicator, { "aria-hidden": "true", style: indicatorStyle }),
|
|
154
|
+
children)));
|
|
155
|
+
};
|
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
|
@@ -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,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, tabFocusValue = _c.tabFocusValue, 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, "data-value": value }, (typeof value === 'number' && { 'data-numeric-value': '' }), { disabled: disabled, tabIndex: !disabled && value === tabFocusValue ? 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,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export interface ISegmentedControlContextValue {
|
|
3
|
+
value?: string | number;
|
|
4
|
+
tabFocusValue?: string | number;
|
|
5
|
+
size?: 'small' | 'medium';
|
|
6
|
+
fullWidth?: boolean;
|
|
7
|
+
onChange?(value: string | number): void;
|
|
8
|
+
}
|
|
9
|
+
export declare const SegmentedControlContext: React.Context<ISegmentedControlContextValue>;
|
|
10
|
+
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,192 @@
|
|
|
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 _d = __read(React.useState(null), 2), focusedValue = _d[0], setFocusedValue = _d[1];
|
|
127
|
+
var tabFocusValue = React.useMemo(function () {
|
|
128
|
+
var _a, _b;
|
|
129
|
+
if (focusedValue != null)
|
|
130
|
+
return focusedValue;
|
|
131
|
+
var segments = React.Children.toArray(children).filter(function (child) {
|
|
132
|
+
return React.isValidElement(child);
|
|
133
|
+
});
|
|
134
|
+
var selected = segments.find(function (child) { return child.props.value === value; });
|
|
135
|
+
if (selected && !selected.props.disabled)
|
|
136
|
+
return value;
|
|
137
|
+
return (_b = (_a = segments.find(function (child) { return !child.props.disabled; })) === null || _a === void 0 ? void 0 : _a.props.value) !== null && _b !== void 0 ? _b : value;
|
|
138
|
+
}, [focusedValue, children, value]);
|
|
139
|
+
var handleKeyDown = function (e) {
|
|
140
|
+
if (!containerRef.current)
|
|
141
|
+
return;
|
|
142
|
+
var segments = Array.from(containerRef.current.querySelectorAll('[role="radio"]:not([disabled])'));
|
|
143
|
+
if (segments.length === 0)
|
|
144
|
+
return;
|
|
145
|
+
var currentIndex = segments.indexOf(document.activeElement);
|
|
146
|
+
var nextIndex = null;
|
|
147
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
nextIndex = currentIndex < segments.length - 1 ? currentIndex + 1 : 0;
|
|
150
|
+
}
|
|
151
|
+
else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
|
|
152
|
+
e.preventDefault();
|
|
153
|
+
nextIndex = currentIndex > 0 ? currentIndex - 1 : segments.length - 1;
|
|
154
|
+
}
|
|
155
|
+
else if (e.key === 'Home') {
|
|
156
|
+
e.preventDefault();
|
|
157
|
+
nextIndex = 0;
|
|
158
|
+
}
|
|
159
|
+
else if (e.key === 'End') {
|
|
160
|
+
e.preventDefault();
|
|
161
|
+
nextIndex = segments.length - 1;
|
|
162
|
+
}
|
|
163
|
+
else if (e.key === 'Enter' || e.key === ' ') {
|
|
164
|
+
e.preventDefault();
|
|
165
|
+
var focused = document.activeElement;
|
|
166
|
+
if (focused && focused.dataset.value != null) {
|
|
167
|
+
var val = focused.dataset.numericValue != null ? Number(focused.dataset.value) : focused.dataset.value;
|
|
168
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(val);
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (nextIndex !== null) {
|
|
173
|
+
var nextEl = segments[nextIndex];
|
|
174
|
+
nextEl.focus();
|
|
175
|
+
var val = nextEl.dataset.numericValue != null ? Number(nextEl.dataset.value) : nextEl.dataset.value;
|
|
176
|
+
if (val != null)
|
|
177
|
+
setFocusedValue(val);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
var handleBlur = function (e) {
|
|
181
|
+
var _a;
|
|
182
|
+
if (!((_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.relatedTarget))) {
|
|
183
|
+
setFocusedValue(null);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
var ctx = React.useMemo(function () { return ({ value: value, tabFocusValue: tabFocusValue, onChange: onChange, size: size, fullWidth: fullWidth }); }, [value, tabFocusValue, onChange, size, fullWidth]);
|
|
187
|
+
return (React.createElement(segmented_control_context_1.SegmentedControlContext.Provider, { value: ctx },
|
|
188
|
+
React.createElement(Root, __assign({ ref: containerRef, fullWidth: fullWidth, role: "radiogroup", onKeyDown: handleKeyDown, onBlur: handleBlur, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledby }, (analyticsId && { 'data-analytics-id': analyticsId }), rest),
|
|
189
|
+
React.createElement(Indicator, { "aria-hidden": "true", style: indicatorStyle }),
|
|
190
|
+
children)));
|
|
191
|
+
};
|
|
192
|
+
exports.SegmentedControl = SegmentedControl;
|