@coinbase/cds-web 8.19.0 → 8.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dts/alpha/select/DefaultSelectAllOption.d.ts +12 -0
- package/dts/alpha/select/DefaultSelectAllOption.d.ts.map +1 -0
- package/dts/alpha/select/DefaultSelectControl.d.ts +13 -0
- package/dts/alpha/select/DefaultSelectControl.d.ts.map +1 -0
- package/dts/alpha/select/DefaultSelectDropdown.d.ts +12 -0
- package/dts/alpha/select/DefaultSelectDropdown.d.ts.map +1 -0
- package/dts/alpha/select/DefaultSelectEmptyDropdownContents.d.ts +3 -0
- package/dts/alpha/select/DefaultSelectEmptyDropdownContents.d.ts.map +1 -0
- package/dts/alpha/select/DefaultSelectOption.d.ts +9 -0
- package/dts/alpha/select/DefaultSelectOption.d.ts.map +1 -0
- package/dts/alpha/select/Select.d.ts +470 -0
- package/dts/alpha/select/Select.d.ts.map +1 -0
- package/dts/alpha/select/index.d.ts +7 -0
- package/dts/alpha/select/index.d.ts.map +1 -0
- package/dts/cells/Cell.d.ts.map +1 -1
- package/dts/chips/Chip.d.ts.map +1 -1
- package/dts/chips/ChipProps.d.ts +15 -4
- package/dts/chips/ChipProps.d.ts.map +1 -1
- package/dts/chips/InputChip.d.ts.map +1 -1
- package/dts/controls/InputStack.d.ts +65 -63
- package/dts/controls/InputStack.d.ts.map +1 -1
- package/dts/controls/SearchInput.d.ts +1 -1
- package/dts/controls/Select.d.ts +1 -1
- package/dts/controls/SelectStack.d.ts +1 -1
- package/dts/controls/TextInput.d.ts +1 -1
- package/dts/hooks/useClickOutside.d.ts +22 -0
- package/dts/hooks/useClickOutside.d.ts.map +1 -0
- package/dts/overlays/FocusTrap.d.ts +4 -0
- package/dts/overlays/FocusTrap.d.ts.map +1 -1
- package/dts/overlays/modal/FullscreenModalLayout.d.ts +1 -1
- package/dts/system/Interactable.d.ts +45 -38
- package/dts/system/Interactable.d.ts.map +1 -1
- package/dts/utils/findClosestNonDisabledNodeIndex.d.ts +11 -0
- package/dts/utils/findClosestNonDisabledNodeIndex.d.ts.map +1 -0
- package/esm/alpha/select/DefaultSelectAllOption.js +47 -0
- package/esm/alpha/select/DefaultSelectControl.css +1 -0
- package/esm/alpha/select/DefaultSelectControl.js +234 -0
- package/esm/alpha/select/DefaultSelectDropdown.js +233 -0
- package/esm/alpha/select/DefaultSelectEmptyDropdownContents.js +23 -0
- package/esm/alpha/select/DefaultSelectOption.css +2 -0
- package/esm/alpha/select/DefaultSelectOption.js +103 -0
- package/esm/alpha/select/Select.js +222 -0
- package/esm/alpha/select/index.js +6 -0
- package/esm/cells/Cell.js +5 -4
- package/esm/chips/Chip.js +3 -2
- package/esm/chips/InputChip.js +7 -5
- package/esm/chips/__figma__/InputChip.figma.js +1 -1
- package/esm/controls/InputStack.js +4 -2
- package/esm/hooks/useClickOutside.js +37 -0
- package/esm/overlays/FocusTrap.js +23 -14
- package/esm/system/Interactable.js +34 -11
- package/esm/utils/findClosestNonDisabledNodeIndex.js +24 -0
- package/package.json +6 -6
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
const _excluded = ["value", "type", "options", "onChange", "open", "setOpen", "disabled", "disableClickOutsideClose", "placeholder", "helperText", "compact", "label", "labelVariant", "accessibilityLabel", "accessibilityRoles", "controlAccessibilityLabel", "selectAllLabel", "emptyOptionsLabel", "clearAllLabel", "hideSelectAll", "defaultOpen", "startNode", "endNode", "variant", "maxSelectedOptionsToShow", "hiddenSelectedOptionsLabel", "removeSelectedOptionAccessibilityLabel", "accessory", "media", "end", "SelectOptionComponent", "SelectAllOptionComponent", "SelectDropdownComponent", "SelectControlComponent", "SelectEmptyDropdownContentsComponent", "style", "styles", "className", "classNames", "testID"];
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
8
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
9
|
+
import { forwardRef, memo, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
10
|
+
import { flip, useFloating } from '@floating-ui/react-dom';
|
|
11
|
+
import { cx } from '../../cx';
|
|
12
|
+
import { useClickOutside } from '../../hooks/useClickOutside';
|
|
13
|
+
import { useHasMounted } from '../../hooks/useHasMounted';
|
|
14
|
+
import { Box } from '../../layout/Box';
|
|
15
|
+
import { Portal } from '../../overlays/Portal';
|
|
16
|
+
import { modalContainerId } from '../../overlays/PortalProvider';
|
|
17
|
+
import { DefaultSelectAllOption } from './DefaultSelectAllOption';
|
|
18
|
+
import { DefaultSelectControl } from './DefaultSelectControl';
|
|
19
|
+
import { DefaultSelectDropdown } from './DefaultSelectDropdown';
|
|
20
|
+
import { DefaultSelectEmptyDropdownContents } from './DefaultSelectEmptyDropdownContents';
|
|
21
|
+
import { DefaultSelectOption } from './DefaultSelectOption';
|
|
22
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
23
|
+
export const defaultAccessibilityRoles = {
|
|
24
|
+
dropdown: 'listbox',
|
|
25
|
+
option: 'option'
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Configuration for a single option in the Select component
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Props for individual option components within the Select dropdown
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Custom UI to render for an option in the Select component options array
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Props for the select control component (the clickable input that opens the dropdown)
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Props for the dropdown component that contains the list of options
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Props for the Select component
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
const SelectBase = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
53
|
+
let {
|
|
54
|
+
value,
|
|
55
|
+
type = 'single',
|
|
56
|
+
options,
|
|
57
|
+
onChange,
|
|
58
|
+
open: openProp,
|
|
59
|
+
setOpen: setOpenProp,
|
|
60
|
+
disabled,
|
|
61
|
+
disableClickOutsideClose,
|
|
62
|
+
placeholder,
|
|
63
|
+
helperText,
|
|
64
|
+
compact,
|
|
65
|
+
label,
|
|
66
|
+
labelVariant,
|
|
67
|
+
accessibilityLabel = 'Select control',
|
|
68
|
+
accessibilityRoles = defaultAccessibilityRoles,
|
|
69
|
+
controlAccessibilityLabel,
|
|
70
|
+
selectAllLabel,
|
|
71
|
+
emptyOptionsLabel,
|
|
72
|
+
clearAllLabel,
|
|
73
|
+
hideSelectAll,
|
|
74
|
+
defaultOpen,
|
|
75
|
+
startNode,
|
|
76
|
+
endNode,
|
|
77
|
+
variant,
|
|
78
|
+
maxSelectedOptionsToShow,
|
|
79
|
+
hiddenSelectedOptionsLabel,
|
|
80
|
+
removeSelectedOptionAccessibilityLabel,
|
|
81
|
+
accessory,
|
|
82
|
+
media,
|
|
83
|
+
end,
|
|
84
|
+
SelectOptionComponent = DefaultSelectOption,
|
|
85
|
+
SelectAllOptionComponent = DefaultSelectAllOption,
|
|
86
|
+
SelectDropdownComponent = DefaultSelectDropdown,
|
|
87
|
+
SelectControlComponent = DefaultSelectControl,
|
|
88
|
+
SelectEmptyDropdownContentsComponent = DefaultSelectEmptyDropdownContents,
|
|
89
|
+
style,
|
|
90
|
+
styles,
|
|
91
|
+
className,
|
|
92
|
+
classNames,
|
|
93
|
+
testID
|
|
94
|
+
} = _ref,
|
|
95
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
96
|
+
const hasMounted = useHasMounted();
|
|
97
|
+
const [openInternal, setOpenInternal] = useState(defaultOpen !== null && defaultOpen !== void 0 ? defaultOpen : false);
|
|
98
|
+
const open = openProp !== null && openProp !== void 0 ? openProp : openInternal;
|
|
99
|
+
const setOpen = setOpenProp !== null && setOpenProp !== void 0 ? setOpenProp : setOpenInternal;
|
|
100
|
+
if (typeof openProp === 'undefined' && typeof setOpenProp !== 'undefined' || typeof openProp !== 'undefined' && typeof setOpenProp === 'undefined') throw Error('Select component must be fully controlled or uncontrolled: "open" and "setOpen" props must be provided together or not at all');
|
|
101
|
+
const {
|
|
102
|
+
refs,
|
|
103
|
+
floatingStyles
|
|
104
|
+
} = useFloating({
|
|
105
|
+
open,
|
|
106
|
+
middleware: [flip()]
|
|
107
|
+
});
|
|
108
|
+
useClickOutside(() => !disableClickOutsideClose && setOpen(false), {
|
|
109
|
+
ref: refs.floating,
|
|
110
|
+
excludeRefs: [refs.reference]
|
|
111
|
+
});
|
|
112
|
+
const rootStyles = useMemo(() => _objectSpread(_objectSpread({}, style), styles === null || styles === void 0 ? void 0 : styles.root), [style, styles === null || styles === void 0 ? void 0 : styles.root]);
|
|
113
|
+
const controlStyles = useMemo(() => ({
|
|
114
|
+
controlStartNode: styles === null || styles === void 0 ? void 0 : styles.controlStartNode,
|
|
115
|
+
controlInputNode: styles === null || styles === void 0 ? void 0 : styles.controlInputNode,
|
|
116
|
+
controlValueNode: styles === null || styles === void 0 ? void 0 : styles.controlValueNode,
|
|
117
|
+
controlLabelNode: styles === null || styles === void 0 ? void 0 : styles.controlLabelNode,
|
|
118
|
+
controlHelperTextNode: styles === null || styles === void 0 ? void 0 : styles.controlHelperTextNode,
|
|
119
|
+
controlEndNode: styles === null || styles === void 0 ? void 0 : styles.controlEndNode
|
|
120
|
+
}), [styles === null || styles === void 0 ? void 0 : styles.controlStartNode, styles === null || styles === void 0 ? void 0 : styles.controlInputNode, styles === null || styles === void 0 ? void 0 : styles.controlValueNode, styles === null || styles === void 0 ? void 0 : styles.controlLabelNode, styles === null || styles === void 0 ? void 0 : styles.controlHelperTextNode, styles === null || styles === void 0 ? void 0 : styles.controlEndNode]);
|
|
121
|
+
const controlClassNames = useMemo(() => ({
|
|
122
|
+
controlStartNode: classNames === null || classNames === void 0 ? void 0 : classNames.controlStartNode,
|
|
123
|
+
controlInputNode: classNames === null || classNames === void 0 ? void 0 : classNames.controlInputNode,
|
|
124
|
+
controlValueNode: classNames === null || classNames === void 0 ? void 0 : classNames.controlValueNode,
|
|
125
|
+
controlLabelNode: classNames === null || classNames === void 0 ? void 0 : classNames.controlLabelNode,
|
|
126
|
+
controlHelperTextNode: classNames === null || classNames === void 0 ? void 0 : classNames.controlHelperTextNode,
|
|
127
|
+
controlEndNode: classNames === null || classNames === void 0 ? void 0 : classNames.controlEndNode
|
|
128
|
+
}), [classNames === null || classNames === void 0 ? void 0 : classNames.controlStartNode, classNames === null || classNames === void 0 ? void 0 : classNames.controlInputNode, classNames === null || classNames === void 0 ? void 0 : classNames.controlValueNode, classNames === null || classNames === void 0 ? void 0 : classNames.controlLabelNode, classNames === null || classNames === void 0 ? void 0 : classNames.controlHelperTextNode, classNames === null || classNames === void 0 ? void 0 : classNames.controlEndNode]);
|
|
129
|
+
const dropdownStyles = useMemo(() => ({
|
|
130
|
+
root: _objectSpread(_objectSpread({}, floatingStyles), styles === null || styles === void 0 ? void 0 : styles.dropdown),
|
|
131
|
+
option: styles === null || styles === void 0 ? void 0 : styles.option,
|
|
132
|
+
optionBlendStyles: styles === null || styles === void 0 ? void 0 : styles.optionBlendStyles,
|
|
133
|
+
optionCell: styles === null || styles === void 0 ? void 0 : styles.optionCell,
|
|
134
|
+
optionContent: styles === null || styles === void 0 ? void 0 : styles.optionContent,
|
|
135
|
+
optionLabel: styles === null || styles === void 0 ? void 0 : styles.optionLabel,
|
|
136
|
+
optionDescription: styles === null || styles === void 0 ? void 0 : styles.optionDescription,
|
|
137
|
+
selectAllDivider: styles === null || styles === void 0 ? void 0 : styles.selectAllDivider,
|
|
138
|
+
emptyContentsContainer: styles === null || styles === void 0 ? void 0 : styles.emptyContentsContainer,
|
|
139
|
+
emptyContentsText: styles === null || styles === void 0 ? void 0 : styles.emptyContentsText
|
|
140
|
+
}), [floatingStyles, styles === null || styles === void 0 ? void 0 : styles.dropdown, styles === null || styles === void 0 ? void 0 : styles.option, styles === null || styles === void 0 ? void 0 : styles.optionBlendStyles, styles === null || styles === void 0 ? void 0 : styles.optionCell, styles === null || styles === void 0 ? void 0 : styles.optionContent, styles === null || styles === void 0 ? void 0 : styles.optionLabel, styles === null || styles === void 0 ? void 0 : styles.optionDescription, styles === null || styles === void 0 ? void 0 : styles.selectAllDivider, styles === null || styles === void 0 ? void 0 : styles.emptyContentsContainer, styles === null || styles === void 0 ? void 0 : styles.emptyContentsText]);
|
|
141
|
+
const dropdownClassNames = useMemo(() => ({
|
|
142
|
+
root: classNames === null || classNames === void 0 ? void 0 : classNames.dropdown,
|
|
143
|
+
option: classNames === null || classNames === void 0 ? void 0 : classNames.option,
|
|
144
|
+
optionCell: classNames === null || classNames === void 0 ? void 0 : classNames.optionCell,
|
|
145
|
+
optionContent: classNames === null || classNames === void 0 ? void 0 : classNames.optionContent,
|
|
146
|
+
optionLabel: classNames === null || classNames === void 0 ? void 0 : classNames.optionLabel,
|
|
147
|
+
optionDescription: classNames === null || classNames === void 0 ? void 0 : classNames.optionDescription,
|
|
148
|
+
selectAllDivider: classNames === null || classNames === void 0 ? void 0 : classNames.selectAllDivider,
|
|
149
|
+
emptyContentsContainer: classNames === null || classNames === void 0 ? void 0 : classNames.emptyContentsContainer,
|
|
150
|
+
emptyContentsText: classNames === null || classNames === void 0 ? void 0 : classNames.emptyContentsText
|
|
151
|
+
}), [classNames === null || classNames === void 0 ? void 0 : classNames.dropdown, classNames === null || classNames === void 0 ? void 0 : classNames.option, classNames === null || classNames === void 0 ? void 0 : classNames.optionCell, classNames === null || classNames === void 0 ? void 0 : classNames.optionContent, classNames === null || classNames === void 0 ? void 0 : classNames.optionLabel, classNames === null || classNames === void 0 ? void 0 : classNames.optionDescription, classNames === null || classNames === void 0 ? void 0 : classNames.selectAllDivider, classNames === null || classNames === void 0 ? void 0 : classNames.emptyContentsContainer, classNames === null || classNames === void 0 ? void 0 : classNames.emptyContentsText]);
|
|
152
|
+
const containerRef = useRef(null);
|
|
153
|
+
useImperativeHandle(ref, () => Object.assign(containerRef.current, {
|
|
154
|
+
open,
|
|
155
|
+
setOpen,
|
|
156
|
+
refs
|
|
157
|
+
}));
|
|
158
|
+
return /*#__PURE__*/_jsxs(Box, {
|
|
159
|
+
ref: containerRef,
|
|
160
|
+
className: cx(classNames === null || classNames === void 0 ? void 0 : classNames.root, className),
|
|
161
|
+
"data-testid": testID,
|
|
162
|
+
style: rootStyles,
|
|
163
|
+
children: [/*#__PURE__*/_jsx(SelectControlComponent, {
|
|
164
|
+
ref: refs.setReference,
|
|
165
|
+
accessibilityLabel: controlAccessibilityLabel,
|
|
166
|
+
ariaHaspopup: accessibilityRoles === null || accessibilityRoles === void 0 ? void 0 : accessibilityRoles.dropdown,
|
|
167
|
+
blendStyles: styles === null || styles === void 0 ? void 0 : styles.controlBlendStyles,
|
|
168
|
+
className: classNames === null || classNames === void 0 ? void 0 : classNames.control,
|
|
169
|
+
classNames: controlClassNames,
|
|
170
|
+
compact: compact,
|
|
171
|
+
disabled: disabled,
|
|
172
|
+
endNode: endNode,
|
|
173
|
+
helperText: helperText,
|
|
174
|
+
hiddenSelectedOptionsLabel: hiddenSelectedOptionsLabel,
|
|
175
|
+
label: label,
|
|
176
|
+
labelVariant: labelVariant,
|
|
177
|
+
maxSelectedOptionsToShow: maxSelectedOptionsToShow,
|
|
178
|
+
onChange: onChange,
|
|
179
|
+
open: open,
|
|
180
|
+
options: options,
|
|
181
|
+
placeholder: placeholder,
|
|
182
|
+
removeSelectedOptionAccessibilityLabel: removeSelectedOptionAccessibilityLabel,
|
|
183
|
+
setOpen: setOpen,
|
|
184
|
+
startNode: startNode,
|
|
185
|
+
style: styles === null || styles === void 0 ? void 0 : styles.control,
|
|
186
|
+
styles: controlStyles,
|
|
187
|
+
type: type,
|
|
188
|
+
value: value,
|
|
189
|
+
variant: variant
|
|
190
|
+
}), /*#__PURE__*/_jsx(Portal, {
|
|
191
|
+
containerId: modalContainerId,
|
|
192
|
+
children: /*#__PURE__*/_jsx(SelectDropdownComponent, {
|
|
193
|
+
ref: refs.setFloating,
|
|
194
|
+
SelectAllOptionComponent: SelectAllOptionComponent,
|
|
195
|
+
SelectEmptyDropdownContentsComponent: SelectEmptyDropdownContentsComponent,
|
|
196
|
+
SelectOptionComponent: SelectOptionComponent,
|
|
197
|
+
accessibilityLabel: accessibilityLabel,
|
|
198
|
+
accessibilityRoles: accessibilityRoles,
|
|
199
|
+
accessory: accessory,
|
|
200
|
+
classNames: dropdownClassNames,
|
|
201
|
+
clearAllLabel: clearAllLabel,
|
|
202
|
+
compact: compact,
|
|
203
|
+
controlRef: refs.reference,
|
|
204
|
+
disabled: disabled,
|
|
205
|
+
emptyOptionsLabel: emptyOptionsLabel,
|
|
206
|
+
end: end,
|
|
207
|
+
hideSelectAll: hideSelectAll,
|
|
208
|
+
label: label,
|
|
209
|
+
media: media,
|
|
210
|
+
onChange: onChange,
|
|
211
|
+
open: hasMounted && open,
|
|
212
|
+
options: options,
|
|
213
|
+
selectAllLabel: selectAllLabel,
|
|
214
|
+
setOpen: setOpen,
|
|
215
|
+
styles: dropdownStyles,
|
|
216
|
+
type: type,
|
|
217
|
+
value: value
|
|
218
|
+
})
|
|
219
|
+
})]
|
|
220
|
+
});
|
|
221
|
+
}));
|
|
222
|
+
export const Select = SelectBase;
|
package/esm/cells/Cell.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _excluded = ["as", "accessory", "accessoryNode", "alignItems", "borderRadius", "children", "style", "styles", "classNames", "className", "contentClassName", "end", "detail", "detailWidth", "disabled", "gap", "columnGap", "rowGap", "intermediary", "media", "minHeight", "maxHeight", "onClick", "onKeyDown", "onKeyUp", "priority", "selected", "testID", "target", "href", "tabIndex", "shouldOverflow", "shouldTruncate", "accessibilityLabel", "accessibilityLabelledBy", "accessibilityHint", "innerSpacing", "outerSpacing", "bottomContent"],
|
|
1
|
+
const _excluded = ["as", "accessory", "accessoryNode", "alignItems", "borderRadius", "children", "style", "styles", "classNames", "className", "contentClassName", "end", "detail", "detailWidth", "disabled", "gap", "columnGap", "rowGap", "intermediary", "media", "minHeight", "maxHeight", "onClick", "onKeyDown", "onKeyUp", "priority", "selected", "testID", "target", "href", "tabIndex", "shouldOverflow", "shouldTruncate", "accessibilityLabel", "accessibilityLabelledBy", "accessibilityHint", "innerSpacing", "outerSpacing", "bottomContent", "background"],
|
|
2
2
|
_excluded2 = ["marginX"];
|
|
3
3
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
4
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -71,7 +71,8 @@ export const Cell = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
71
71
|
accessibilityHint,
|
|
72
72
|
innerSpacing: innerSpacingProp,
|
|
73
73
|
outerSpacing: outerSpacingProp,
|
|
74
|
-
bottomContent: bottom
|
|
74
|
+
bottomContent: bottom,
|
|
75
|
+
background = 'bgAlternate'
|
|
75
76
|
} = _ref,
|
|
76
77
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
77
78
|
const Component = as !== null && as !== void 0 ? as : cellDefaultElement;
|
|
@@ -99,7 +100,7 @@ export const Cell = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
99
100
|
className: cx(contentClassName, classNames === null || classNames === void 0 ? void 0 : classNames.contentContainer),
|
|
100
101
|
testID
|
|
101
102
|
}, selected ? {
|
|
102
|
-
background
|
|
103
|
+
background
|
|
103
104
|
} : {}), linkable ? innerSpacingWithoutMarginX : innerSpacing), {}, {
|
|
104
105
|
style: styles === null || styles === void 0 ? void 0 : styles.contentContainer
|
|
105
106
|
});
|
|
@@ -173,7 +174,7 @@ export const Cell = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
173
174
|
children: bottom
|
|
174
175
|
})]
|
|
175
176
|
}));
|
|
176
|
-
}, [borderRadius, contentClassName, classNames === null || classNames === void 0 ? void 0 : classNames.contentContainer, classNames === null || classNames === void 0 ? void 0 : classNames.topContent, classNames === null || classNames === void 0 ? void 0 : classNames.media, classNames === null || classNames === void 0 ? void 0 : classNames.intermediary, classNames === null || classNames === void 0 ? void 0 : classNames.end, classNames === null || classNames === void 0 ? void 0 : classNames.accessory, classNames === null || classNames === void 0 ? void 0 : classNames.bottomContent, testID, selected, linkable, innerSpacingWithoutMarginX, innerSpacing, styles === null || styles === void 0 ? void 0 : styles.contentContainer, styles === null || styles === void 0 ? void 0 : styles.topContent, styles === null || styles === void 0 ? void 0 : styles.media, styles === null || styles === void 0 ? void 0 : styles.intermediary, styles === null || styles === void 0 ? void 0 : styles.end, styles === null || styles === void 0 ? void 0 : styles.accessory, styles === null || styles === void 0 ? void 0 : styles.bottomContent, alignItems, columnGap, gap, media, contentTruncationStyle, priority, children, intermediary, end, detail, detailWidth, accessory, accessoryNode, bottom, rowGap]);
|
|
177
|
+
}, [borderRadius, contentClassName, classNames === null || classNames === void 0 ? void 0 : classNames.contentContainer, classNames === null || classNames === void 0 ? void 0 : classNames.topContent, classNames === null || classNames === void 0 ? void 0 : classNames.media, classNames === null || classNames === void 0 ? void 0 : classNames.intermediary, classNames === null || classNames === void 0 ? void 0 : classNames.end, classNames === null || classNames === void 0 ? void 0 : classNames.accessory, classNames === null || classNames === void 0 ? void 0 : classNames.bottomContent, testID, selected, background, linkable, innerSpacingWithoutMarginX, innerSpacing, styles === null || styles === void 0 ? void 0 : styles.contentContainer, styles === null || styles === void 0 ? void 0 : styles.topContent, styles === null || styles === void 0 ? void 0 : styles.media, styles === null || styles === void 0 ? void 0 : styles.intermediary, styles === null || styles === void 0 ? void 0 : styles.end, styles === null || styles === void 0 ? void 0 : styles.accessory, styles === null || styles === void 0 ? void 0 : styles.bottomContent, alignItems, columnGap, gap, media, contentTruncationStyle, priority, children, intermediary, end, detail, detailWidth, accessory, accessoryNode, bottom, rowGap]);
|
|
177
178
|
const pressableWrappedContent = useMemo(() => {
|
|
178
179
|
const pressableSharedProps = {
|
|
179
180
|
noScaleOnPress: true,
|
package/esm/chips/Chip.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _excluded = ["as", "alignItems", "width", "height", "compact", "gap", "start", "end", "paddingX", "paddingY", "padding", "paddingTop", "paddingBottom", "paddingStart", "paddingEnd", "justifyContent", "children", "maxWidth", "inverted", "numberOfLines", "testID", "contentStyle", "borderRadius", "background", "style", "className", "styles", "classNames", "font", "onClick"];
|
|
1
|
+
const _excluded = ["as", "alignItems", "width", "height", "compact", "gap", "start", "end", "paddingX", "paddingY", "padding", "paddingTop", "paddingBottom", "paddingStart", "paddingEnd", "justifyContent", "children", "maxWidth", "invertColorScheme", "inverted", "numberOfLines", "testID", "contentStyle", "borderRadius", "background", "style", "className", "styles", "classNames", "font", "onClick"];
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
4
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
@@ -41,6 +41,7 @@ export const Chip = /*#__PURE__*/memo(/*#__PURE__*/forwardRef(function Chip(_ref
|
|
|
41
41
|
justifyContent,
|
|
42
42
|
children,
|
|
43
43
|
maxWidth = chipMaxWidth,
|
|
44
|
+
invertColorScheme,
|
|
44
45
|
inverted,
|
|
45
46
|
numberOfLines = 1,
|
|
46
47
|
testID,
|
|
@@ -55,7 +56,7 @@ export const Chip = /*#__PURE__*/memo(/*#__PURE__*/forwardRef(function Chip(_ref
|
|
|
55
56
|
onClick
|
|
56
57
|
} = _ref,
|
|
57
58
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
58
|
-
const WrapperComponent = inverted ? InvertedThemeProvider : Fragment;
|
|
59
|
+
const WrapperComponent = (invertColorScheme !== null && invertColorScheme !== void 0 ? invertColorScheme : inverted) ? InvertedThemeProvider : Fragment;
|
|
59
60
|
const containerProps = {
|
|
60
61
|
background,
|
|
61
62
|
borderRadius,
|
package/esm/chips/InputChip.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _excluded = ["value", "accessibilityLabel", "testID"];
|
|
1
|
+
const _excluded = ["value", "children", "accessibilityLabel", "invertColorScheme", "testID"];
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
4
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
@@ -13,13 +13,14 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
13
13
|
export const InputChip = /*#__PURE__*/memo(/*#__PURE__*/forwardRef(function InputChip(_ref, ref) {
|
|
14
14
|
let {
|
|
15
15
|
value,
|
|
16
|
-
|
|
16
|
+
children = value,
|
|
17
|
+
accessibilityLabel = typeof children === 'string' ? "Remove ".concat(children) : 'Remove option',
|
|
18
|
+
invertColorScheme = true,
|
|
17
19
|
testID = 'input-chip'
|
|
18
20
|
} = _ref,
|
|
19
21
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
20
22
|
return /*#__PURE__*/_jsx(MediaChip, _objectSpread(_objectSpread({
|
|
21
23
|
ref: ref,
|
|
22
|
-
inverted: true,
|
|
23
24
|
accessibilityLabel: accessibilityLabel,
|
|
24
25
|
end: /*#__PURE__*/_jsx(Icon, {
|
|
25
26
|
active: true,
|
|
@@ -27,8 +28,9 @@ export const InputChip = /*#__PURE__*/memo(/*#__PURE__*/forwardRef(function Inpu
|
|
|
27
28
|
name: "close",
|
|
28
29
|
size: "xs",
|
|
29
30
|
testID: testID ? "".concat(testID, "-close-icon") : 'input-chip-close-icon'
|
|
30
|
-
})
|
|
31
|
+
}),
|
|
32
|
+
invertColorScheme: invertColorScheme
|
|
31
33
|
}, props), {}, {
|
|
32
|
-
children:
|
|
34
|
+
children: children
|
|
33
35
|
}));
|
|
34
36
|
}));
|
|
@@ -9,7 +9,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
9
9
|
figma.connect(InputChip, 'https://www.figma.com/design/k5CtyJccNQUGMI5bI4lJ2g/✨-CDS-Components?node-id=10177-5161&m=dev', {
|
|
10
10
|
imports: ["import { InputChip } from '@coinbase/cds-web/chips/InputChip'"],
|
|
11
11
|
props: {
|
|
12
|
-
|
|
12
|
+
children: figma.string('value'),
|
|
13
13
|
start: figma.boolean('show start', {
|
|
14
14
|
true: figma.instance('start'),
|
|
15
15
|
false: undefined
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _excluded = ["width", "prependNode", "endNode", "appendNode", "startNode", "disabled", "inputNode", "helperTextNode", "borderWidth", "variant", "labelNode", "testID", "focused", "borderRadius", "height", "disableFocusedStyle", "enableColorSurge", "labelVariant"];
|
|
1
|
+
const _excluded = ["width", "prependNode", "endNode", "appendNode", "startNode", "disabled", "inputNode", "helperTextNode", "borderWidth", "variant", "labelNode", "testID", "focused", "borderRadius", "height", "disableFocusedStyle", "enableColorSurge", "labelVariant", "blendStyles"];
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
4
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
@@ -54,7 +54,8 @@ export const InputStack = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref)
|
|
|
54
54
|
height,
|
|
55
55
|
disableFocusedStyle = false,
|
|
56
56
|
enableColorSurge,
|
|
57
|
-
labelVariant = 'outside'
|
|
57
|
+
labelVariant = 'outside',
|
|
58
|
+
blendStyles
|
|
58
59
|
} = _ref,
|
|
59
60
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
60
61
|
const focusedVariant = useMemo(() => focused && variant !== 'positive' && variant !== 'negative' ? 'primary' : variant, [focused, variant]);
|
|
@@ -108,6 +109,7 @@ export const InputStack = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref)
|
|
|
108
109
|
ref: ref,
|
|
109
110
|
as: "span",
|
|
110
111
|
background: variant === 'secondary' ? 'bgSecondary' : 'bg',
|
|
112
|
+
blendStyles: blendStyles,
|
|
111
113
|
borderRadius: borderRadius,
|
|
112
114
|
borderWidth: borderWidth,
|
|
113
115
|
className: cx(baseCss, focused && persistedFocusCss),
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options for configuring the useClickOutside hook
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Hook that detects clicks outside of a specified element and triggers a callback
|
|
9
|
+
* @param callback - Function to call when a click outside is detected
|
|
10
|
+
* @param options - Configuration options for the hook
|
|
11
|
+
* @returns A ref to attach to the element you want to detect clicks outside of
|
|
12
|
+
*/
|
|
13
|
+
export const useClickOutside = function (callback) {
|
|
14
|
+
let {
|
|
15
|
+
ref,
|
|
16
|
+
excludeRefs
|
|
17
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
18
|
+
const internalRef = useRef(null);
|
|
19
|
+
const containerRef = ref !== null && ref !== void 0 ? ref : internalRef;
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const handleClickOutside = event => {
|
|
22
|
+
const target = event.target;
|
|
23
|
+
if (!containerRef.current) return;
|
|
24
|
+
if (containerRef.current && containerRef.current.contains(target)) return;
|
|
25
|
+
if (excludeRefs && excludeRefs.some(ref => {
|
|
26
|
+
var _ref$current;
|
|
27
|
+
return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.contains(target);
|
|
28
|
+
})) return;
|
|
29
|
+
callback();
|
|
30
|
+
};
|
|
31
|
+
window.addEventListener('mousedown', handleClickOutside);
|
|
32
|
+
return () => {
|
|
33
|
+
window.removeEventListener('mousedown', handleClickOutside);
|
|
34
|
+
};
|
|
35
|
+
}, [callback, containerRef, excludeRefs]);
|
|
36
|
+
return containerRef;
|
|
37
|
+
};
|
|
@@ -14,6 +14,7 @@ export const FocusTrap = /*#__PURE__*/memo(function FocusTrap(_ref) {
|
|
|
14
14
|
onEscPress,
|
|
15
15
|
disableTypeFocus,
|
|
16
16
|
disableFocusTrap,
|
|
17
|
+
includeTriggerInFocusTrap,
|
|
17
18
|
disableAutoFocus,
|
|
18
19
|
respectNegativeTabIndex,
|
|
19
20
|
focusTabIndexElements,
|
|
@@ -55,32 +56,40 @@ export const FocusTrap = /*#__PURE__*/memo(function FocusTrap(_ref) {
|
|
|
55
56
|
const activeElement = document === null || document === void 0 ? void 0 : document.activeElement;
|
|
56
57
|
if (!element || !document) return;
|
|
57
58
|
let focusableElements = Array.from(element.querySelectorAll(focusTabIndexElements ? FOCUSABLE_ELEMENTS_INCLUDING_TABINDEX : FOCUSABLE_ELEMENTS));
|
|
59
|
+
if (includeTriggerInFocusTrap && previouslyFocusedElement.current) {
|
|
60
|
+
focusableElements = [previouslyFocusedElement.current, ...focusableElements];
|
|
61
|
+
}
|
|
58
62
|
if (respectNegativeTabIndex) {
|
|
59
63
|
focusableElements = focusableElements.filter(element => !((element === null || element === void 0 ? void 0 : element.tabIndex) < 0));
|
|
60
64
|
}
|
|
61
65
|
const menuItems = element.querySelectorAll('[role="menuitem"]');
|
|
62
|
-
const
|
|
66
|
+
const optionItems = element.querySelectorAll('[role="option"]');
|
|
67
|
+
const activeElementIsMenuItem = activeElement && Array.from(menuItems).includes(activeElement);
|
|
68
|
+
const activeElementIsOption = activeElement && Array.from(optionItems).includes(activeElement);
|
|
69
|
+
const activeElementIsMenuItemOrOption = activeElementIsMenuItem || activeElementIsOption;
|
|
63
70
|
if (focusableElements.length === 0) return;
|
|
64
71
|
const firstElement = focusableElements[0];
|
|
72
|
+
const secondElement = focusableElements[1];
|
|
65
73
|
const lastElement = focusableElements[focusableElements.length - 1];
|
|
66
74
|
const activeElementIndex = activeElement ? focusableElements.indexOf(activeElement) : undefined;
|
|
75
|
+
const secondElementIsMenuItemOrOption = secondElement.role === 'menuitem' || secondElement.role === 'option';
|
|
67
76
|
|
|
68
77
|
// bring focus inside modal
|
|
69
78
|
if (!isFocused.current &&
|
|
70
79
|
// check if focus is inside modal
|
|
71
80
|
!focusableElements.includes(activeElement)) {
|
|
72
81
|
// don't focus if arrow keys are used, instead allow scroll via keyboard
|
|
73
|
-
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
82
|
+
if ((event.key === 'ArrowDown' || event.key === 'ArrowUp') && !includeTriggerInFocusTrap) {
|
|
74
83
|
return;
|
|
75
84
|
}
|
|
85
|
+
event.preventDefault();
|
|
76
86
|
firstElement.focus();
|
|
77
87
|
isFocused.current = true;
|
|
78
|
-
event.preventDefault();
|
|
79
88
|
}
|
|
80
89
|
if (event.key === 'Tab') {
|
|
81
90
|
event.preventDefault();
|
|
82
91
|
}
|
|
83
|
-
if (
|
|
92
|
+
if (activeElementIsMenuItemOrOption || secondElementIsMenuItemOrOption || event.key === 'ArrowUp' || event.key === 'ArrowDown') {
|
|
84
93
|
event.preventDefault();
|
|
85
94
|
}
|
|
86
95
|
const focusPrevElement = () => {
|
|
@@ -92,22 +101,22 @@ export const FocusTrap = /*#__PURE__*/memo(function FocusTrap(_ref) {
|
|
|
92
101
|
|
|
93
102
|
// force active element to loop back to beginning of list
|
|
94
103
|
const handleLastElement = () => {
|
|
95
|
-
if (!event.shiftKey && event.key === 'Tab' || event.key === 'ArrowDown' &&
|
|
104
|
+
if (!event.shiftKey && event.key === 'Tab' || event.key === 'ArrowDown' && activeElementIsMenuItemOrOption) {
|
|
96
105
|
firstElement.focus();
|
|
97
106
|
return;
|
|
98
107
|
}
|
|
99
|
-
if (event.key === '
|
|
108
|
+
if (event.shiftKey && event.key === 'Tab' || event.key === 'ArrowUp' && activeElementIsMenuItemOrOption) {
|
|
100
109
|
focusPrevElement();
|
|
101
110
|
}
|
|
102
111
|
};
|
|
103
112
|
const handleFirstElement = () => {
|
|
104
113
|
// force active element to loop back to end of list
|
|
105
|
-
if (event.shiftKey && event.key === 'Tab' || event.key === 'ArrowUp' &&
|
|
114
|
+
if (event.shiftKey && event.key === 'Tab' || event.key === 'ArrowUp' && (activeElementIsMenuItemOrOption || secondElementIsMenuItemOrOption)) {
|
|
106
115
|
lastElement.focus();
|
|
107
116
|
return;
|
|
108
117
|
}
|
|
109
|
-
if (event.key === '
|
|
110
|
-
|
|
118
|
+
if (event.key === 'Tab' || event.key === 'ArrowDown' && (activeElementIsMenuItemOrOption || secondElementIsMenuItemOrOption)) {
|
|
119
|
+
secondElement.focus();
|
|
111
120
|
}
|
|
112
121
|
};
|
|
113
122
|
if (event.key === 'Home') {
|
|
@@ -120,7 +129,7 @@ export const FocusTrap = /*#__PURE__*/memo(function FocusTrap(_ref) {
|
|
|
120
129
|
lastElement.focus();
|
|
121
130
|
return;
|
|
122
131
|
}
|
|
123
|
-
if (!disableTypeFocus &&
|
|
132
|
+
if (!disableTypeFocus && activeElementIsMenuItemOrOption && ALPHABET_KEYS.includes(event.key)) {
|
|
124
133
|
event.preventDefault();
|
|
125
134
|
const elementWithMatchingFirstLetter = focusableElements.find(el => {
|
|
126
135
|
var _el$textContent;
|
|
@@ -140,14 +149,14 @@ export const FocusTrap = /*#__PURE__*/memo(function FocusTrap(_ref) {
|
|
|
140
149
|
handleFirstElement();
|
|
141
150
|
return;
|
|
142
151
|
}
|
|
143
|
-
if ((event.key === 'ArrowDown' &&
|
|
152
|
+
if ((event.key === 'ArrowDown' && activeElementIsMenuItemOrOption || event.key === 'Tab') && activeElementIndex) {
|
|
144
153
|
const nextElement = focusableElements[activeElementIndex + 1];
|
|
145
154
|
nextElement.focus();
|
|
146
155
|
}
|
|
147
|
-
if ((event.key === 'ArrowUp' &&
|
|
156
|
+
if ((event.key === 'ArrowUp' && activeElementIsMenuItemOrOption || event.key === 'Tab' && event.shiftKey) && activeElementIndex) {
|
|
148
157
|
focusPrevElement();
|
|
149
158
|
}
|
|
150
|
-
}, [focusTabIndexElements, disableTypeFocus, respectNegativeTabIndex]);
|
|
159
|
+
}, [focusTabIndexElements, disableTypeFocus, respectNegativeTabIndex, includeTriggerInFocusTrap]);
|
|
151
160
|
const handleKeyDown = useCallback(event => {
|
|
152
161
|
// Update the keystroke history
|
|
153
162
|
updateKeystrokeHistory(event.key);
|
|
@@ -186,7 +195,7 @@ export const FocusTrap = /*#__PURE__*/memo(function FocusTrap(_ref) {
|
|
|
186
195
|
const elementToAutoFocus = focusableElements[0];
|
|
187
196
|
if (typeof autoFocusDelay !== 'number') elementToAutoFocus.focus();else setTimeout(() => elementToAutoFocus.focus(), autoFocusDelay);
|
|
188
197
|
}
|
|
189
|
-
}, [disableAutoFocus, autoFocusDelay]);
|
|
198
|
+
}, [disableAutoFocus, autoFocusDelay, includeTriggerInFocusTrap]);
|
|
190
199
|
|
|
191
200
|
// only works for single child
|
|
192
201
|
const onlyChild = React.Children.only(children);
|
|
@@ -19,6 +19,26 @@ const blockCss = "blockCss-b1ytinjt";
|
|
|
19
19
|
const transparentActiveCss = "transparentActiveCss-t10ei5ro";
|
|
20
20
|
const transparentWhileInactiveCss = "transparentWhileInactiveCss-te5q23s";
|
|
21
21
|
export const interactableDefaultElement = 'button';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Custom color overrides for different interaction states.
|
|
25
|
+
* Base colors (background, borderColor) are used directly, while interaction
|
|
26
|
+
* state colors (hovered, pressed, disabled) are used as alternative base colors
|
|
27
|
+
* for blending calculations with blend strength and color scheme considerations.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* <Interactable
|
|
32
|
+
* blendStyles={{
|
|
33
|
+
* background: '#ffffff',
|
|
34
|
+
* hoveredBackground: '#f5f5f5',
|
|
35
|
+
* pressedBackground: '#e0e0e0',
|
|
36
|
+
* borderColor: '#cccccc'
|
|
37
|
+
* }}
|
|
38
|
+
* />
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
|
|
22
42
|
export const Interactable = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
23
43
|
let {
|
|
24
44
|
as,
|
|
@@ -57,7 +77,7 @@ export const Interactable = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
57
77
|
}, props));
|
|
58
78
|
});
|
|
59
79
|
export const getInteractableStyles = _ref2 => {
|
|
60
|
-
var _blendStyles$backgrou, _blendStyles$borderCo, _blendStyles$backgrou2, _blendStyles$borderCo2, _blendStyles$hoveredB, _blendStyles$hoveredB2, _blendStyles$pressedB, _blendStyles$pressedB2, _blendStyles$
|
|
80
|
+
var _blendStyles$backgrou, _blendStyles$borderCo, _blendStyles$hoveredO, _blendStyles$pressedO, _blendStyles$disabled, _blendStyles$backgrou2, _blendStyles$borderCo2, _blendStyles$hoveredB, _blendStyles$hoveredB2, _blendStyles$pressedB, _blendStyles$pressedB2, _blendStyles$disabled2, _blendStyles$disabled3;
|
|
61
81
|
let {
|
|
62
82
|
theme,
|
|
63
83
|
background = 'transparent',
|
|
@@ -66,6 +86,9 @@ export const getInteractableStyles = _ref2 => {
|
|
|
66
86
|
} = _ref2;
|
|
67
87
|
const backgroundColor = (_blendStyles$backgrou = blendStyles === null || blendStyles === void 0 ? void 0 : blendStyles.background) !== null && _blendStyles$backgrou !== void 0 ? _blendStyles$backgrou : theme.color[background];
|
|
68
88
|
const borderColorValue = (_blendStyles$borderCo = blendStyles === null || blendStyles === void 0 ? void 0 : blendStyles.borderColor) !== null && _blendStyles$borderCo !== void 0 ? _blendStyles$borderCo : theme.color[borderColor];
|
|
89
|
+
const hoveredOpacity = (_blendStyles$hoveredO = blendStyles === null || blendStyles === void 0 ? void 0 : blendStyles.hoveredOpacity) !== null && _blendStyles$hoveredO !== void 0 ? _blendStyles$hoveredO : opacityHovered;
|
|
90
|
+
const pressedOpacity = (_blendStyles$pressedO = blendStyles === null || blendStyles === void 0 ? void 0 : blendStyles.pressedOpacity) !== null && _blendStyles$pressedO !== void 0 ? _blendStyles$pressedO : opacityPressed;
|
|
91
|
+
const disabledOpacity = (_blendStyles$disabled = blendStyles === null || blendStyles === void 0 ? void 0 : blendStyles.disabledOpacity) !== null && _blendStyles$disabled !== void 0 ? _blendStyles$disabled : opacityDisabled;
|
|
69
92
|
return {
|
|
70
93
|
[interactableBackground]: (_blendStyles$backgrou2 = blendStyles === null || blendStyles === void 0 ? void 0 : blendStyles.background) !== null && _blendStyles$backgrou2 !== void 0 ? _blendStyles$backgrou2 : "var(--color-".concat(background, ")"),
|
|
71
94
|
[interactableBorderColor]: (_blendStyles$borderCo2 = blendStyles === null || blendStyles === void 0 ? void 0 : blendStyles.borderColor) !== null && _blendStyles$borderCo2 !== void 0 ? _blendStyles$borderCo2 : "var(--color-".concat(borderColor, ")"),
|
|
@@ -75,37 +98,37 @@ export const getInteractableStyles = _ref2 => {
|
|
|
75
98
|
// Hover:
|
|
76
99
|
[interactableHoveredBackground]: getBlendedColor({
|
|
77
100
|
overlayColor: (_blendStyles$hoveredB = blendStyles === null || blendStyles === void 0 ? void 0 : blendStyles.hoveredBackground) !== null && _blendStyles$hoveredB !== void 0 ? _blendStyles$hoveredB : backgroundColor,
|
|
78
|
-
blendOpacity:
|
|
101
|
+
blendOpacity: hoveredOpacity,
|
|
79
102
|
colorScheme: theme.activeColorScheme
|
|
80
103
|
}),
|
|
81
104
|
[interactableHoveredBorderColor]: getBlendedColor({
|
|
82
105
|
overlayColor: (_blendStyles$hoveredB2 = blendStyles === null || blendStyles === void 0 ? void 0 : blendStyles.hoveredBorderColor) !== null && _blendStyles$hoveredB2 !== void 0 ? _blendStyles$hoveredB2 : borderColorValue,
|
|
83
|
-
blendOpacity:
|
|
106
|
+
blendOpacity: hoveredOpacity,
|
|
84
107
|
colorScheme: theme.activeColorScheme
|
|
85
108
|
}),
|
|
86
|
-
[interactableHoveredOpacity]:
|
|
109
|
+
[interactableHoveredOpacity]: hoveredOpacity,
|
|
87
110
|
// Pressed:
|
|
88
111
|
[interactablePressedBackground]: getBlendedColor({
|
|
89
112
|
overlayColor: (_blendStyles$pressedB = blendStyles === null || blendStyles === void 0 ? void 0 : blendStyles.pressedBackground) !== null && _blendStyles$pressedB !== void 0 ? _blendStyles$pressedB : backgroundColor,
|
|
90
|
-
blendOpacity:
|
|
113
|
+
blendOpacity: pressedOpacity,
|
|
91
114
|
colorScheme: theme.activeColorScheme
|
|
92
115
|
}),
|
|
93
116
|
[interactablePressedBorderColor]: getBlendedColor({
|
|
94
117
|
overlayColor: (_blendStyles$pressedB2 = blendStyles === null || blendStyles === void 0 ? void 0 : blendStyles.pressedBorderColor) !== null && _blendStyles$pressedB2 !== void 0 ? _blendStyles$pressedB2 : borderColorValue,
|
|
95
|
-
blendOpacity:
|
|
118
|
+
blendOpacity: pressedOpacity,
|
|
96
119
|
colorScheme: theme.activeColorScheme
|
|
97
120
|
}),
|
|
98
|
-
[interactablePressedOpacity]:
|
|
121
|
+
[interactablePressedOpacity]: pressedOpacity,
|
|
99
122
|
// Disabled:
|
|
100
123
|
[interactableDisabledBackground]: getBlendedColor({
|
|
101
|
-
overlayColor: (_blendStyles$
|
|
102
|
-
blendOpacity:
|
|
124
|
+
overlayColor: (_blendStyles$disabled2 = blendStyles === null || blendStyles === void 0 ? void 0 : blendStyles.disabledBackground) !== null && _blendStyles$disabled2 !== void 0 ? _blendStyles$disabled2 : backgroundColor,
|
|
125
|
+
blendOpacity: disabledOpacity,
|
|
103
126
|
colorScheme: theme.activeColorScheme,
|
|
104
127
|
skipContrastOptimization: true
|
|
105
128
|
}),
|
|
106
129
|
[interactableDisabledBorderColor]: getBlendedColor({
|
|
107
|
-
overlayColor: (_blendStyles$
|
|
108
|
-
blendOpacity:
|
|
130
|
+
overlayColor: (_blendStyles$disabled3 = blendStyles === null || blendStyles === void 0 ? void 0 : blendStyles.disabledBorderColor) !== null && _blendStyles$disabled3 !== void 0 ? _blendStyles$disabled3 : borderColorValue,
|
|
131
|
+
blendOpacity: disabledOpacity,
|
|
109
132
|
colorScheme: theme.activeColorScheme,
|
|
110
133
|
skipContrastOptimization: true
|
|
111
134
|
})
|