@dt-dds/react-select 1.0.0-beta.46
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 +544 -0
- package/LICENSE.md +21 -0
- package/README.md +106 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +508 -0
- package/dist/index.mjs +482 -0
- package/package.json +61 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
37
|
+
var __export = (target, all) => {
|
|
38
|
+
for (var name in all)
|
|
39
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
+
};
|
|
41
|
+
var __copyProps = (to, from, except, desc) => {
|
|
42
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
+
for (let key of __getOwnPropNames(from))
|
|
44
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
+
}
|
|
47
|
+
return to;
|
|
48
|
+
};
|
|
49
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
+
mod
|
|
56
|
+
));
|
|
57
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
+
|
|
59
|
+
// index.ts
|
|
60
|
+
var select_exports = {};
|
|
61
|
+
__export(select_exports, {
|
|
62
|
+
Select: () => Select
|
|
63
|
+
});
|
|
64
|
+
module.exports = __toCommonJS(select_exports);
|
|
65
|
+
|
|
66
|
+
// src/Select.tsx
|
|
67
|
+
var import_react_core2 = require("@dt-dds/react-core");
|
|
68
|
+
var import_react_icon = require("@dt-dds/react-icon");
|
|
69
|
+
var import_react_icon_button = require("@dt-dds/react-icon-button");
|
|
70
|
+
var import_react_label_field = require("@dt-dds/react-label-field");
|
|
71
|
+
var import_react_tooltip = require("@dt-dds/react-tooltip");
|
|
72
|
+
var import_react_typography = require("@dt-dds/react-typography");
|
|
73
|
+
var import_downshift = require("downshift");
|
|
74
|
+
var import_react2 = require("react");
|
|
75
|
+
|
|
76
|
+
// src/components/SelectOption.tsx
|
|
77
|
+
var import_react_checkbox = require("@dt-dds/react-checkbox");
|
|
78
|
+
|
|
79
|
+
// src/context/SelectProvider.tsx
|
|
80
|
+
var import_react = require("react");
|
|
81
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
82
|
+
var SelectContext = (0, import_react.createContext)(void 0);
|
|
83
|
+
var useSelectContext = () => {
|
|
84
|
+
const context = (0, import_react.useContext)(SelectContext);
|
|
85
|
+
if (!context) {
|
|
86
|
+
throw new Error("useSelectContext must be used within a SelectProvider");
|
|
87
|
+
}
|
|
88
|
+
return context;
|
|
89
|
+
};
|
|
90
|
+
var SelectProvider = ({ children, value }) => {
|
|
91
|
+
const _a = value, { highlightedIndex, selectedItems } = _a, rest = __objRest(_a, ["highlightedIndex", "selectedItems"]);
|
|
92
|
+
const isItemHighlighted = (index) => index === highlightedIndex;
|
|
93
|
+
const isItemSelected = (item) => {
|
|
94
|
+
return !!selectedItems.find(
|
|
95
|
+
(selectedItem) => selectedItem.value === item.value
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
99
|
+
SelectContext.Provider,
|
|
100
|
+
{
|
|
101
|
+
value: __spreadValues({
|
|
102
|
+
isItemHighlighted,
|
|
103
|
+
isItemSelected
|
|
104
|
+
}, rest),
|
|
105
|
+
children
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// src/components/SelectOption.styled.ts
|
|
111
|
+
var import_styled = __toESM(require("@emotion/styled"));
|
|
112
|
+
var SelectOptionStyled = import_styled.default.li`
|
|
113
|
+
display: flex;
|
|
114
|
+
|
|
115
|
+
${({ theme, isMulti, isHighlighted }) => `
|
|
116
|
+
cursor:pointer;
|
|
117
|
+
align-items: center;
|
|
118
|
+
${!isMulti && `padding: ${theme.spacing["4xs"]} ${theme.spacing["2xs"]}`};
|
|
119
|
+
gap: ${isMulti ? theme.spacing["4xs"] : theme.spacing["5xs"]};
|
|
120
|
+
background-color: ${isHighlighted && !isMulti ? theme.palette.primary.light : theme.palette.surface.contrast};
|
|
121
|
+
|
|
122
|
+
color: ${theme.palette.content.default};
|
|
123
|
+
${theme.fontStyles.body2}
|
|
124
|
+
|
|
125
|
+
& > label {
|
|
126
|
+
${isMulti && `padding: ${theme.spacing["4xs"]} ${theme.spacing["2xs"]}`};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
&:hover,&:focus-within {
|
|
130
|
+
background-color: ${theme.palette.primary.light};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
&[aria-disabled="true"] {
|
|
134
|
+
cursor: not-allowed;
|
|
135
|
+
color: ${theme.palette.content.light};
|
|
136
|
+
&:hover {
|
|
137
|
+
background-color: ${theme.palette.surface.contrast};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
`}
|
|
141
|
+
`;
|
|
142
|
+
var SelectOptionContentStyled = import_styled.default.div`
|
|
143
|
+
text-overflow: ellipsis;
|
|
144
|
+
white-space: nowrap;
|
|
145
|
+
overflow: hidden;
|
|
146
|
+
width: 100%;
|
|
147
|
+
|
|
148
|
+
${({ theme, isSelected }) => `
|
|
149
|
+
${theme.fontStyles[isSelected ? "body2Bold" : "body2"]};
|
|
150
|
+
`}
|
|
151
|
+
`;
|
|
152
|
+
|
|
153
|
+
// src/components/SelectOption.tsx
|
|
154
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
155
|
+
var SelectOption = ({
|
|
156
|
+
dataTestId,
|
|
157
|
+
index,
|
|
158
|
+
children,
|
|
159
|
+
style,
|
|
160
|
+
value,
|
|
161
|
+
label,
|
|
162
|
+
disabled
|
|
163
|
+
}) => {
|
|
164
|
+
const { getItemProps, isItemHighlighted, isItemSelected, isMulti } = useSelectContext();
|
|
165
|
+
const item = { value, label, disabled: !!disabled };
|
|
166
|
+
const isSelected = isItemSelected(item);
|
|
167
|
+
const isHighlighted = isItemHighlighted(index);
|
|
168
|
+
const itemProps = getItemProps({ item, index });
|
|
169
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
170
|
+
SelectOptionStyled,
|
|
171
|
+
__spreadProps(__spreadValues({
|
|
172
|
+
"aria-disabled": itemProps["aria-disabled"],
|
|
173
|
+
"data-testid": dataTestId,
|
|
174
|
+
isHighlighted,
|
|
175
|
+
isMulti,
|
|
176
|
+
style
|
|
177
|
+
}, !isMulti && __spreadProps(__spreadValues({}, itemProps), {
|
|
178
|
+
"aria-selected": isSelected
|
|
179
|
+
})), {
|
|
180
|
+
children: isMulti ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
181
|
+
import_react_checkbox.Checkbox,
|
|
182
|
+
__spreadProps(__spreadValues({
|
|
183
|
+
isChecked: isSelected,
|
|
184
|
+
isDisabled: itemProps["aria-disabled"]
|
|
185
|
+
}, itemProps), {
|
|
186
|
+
children: children || label || value
|
|
187
|
+
})
|
|
188
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SelectOptionContentStyled, { isSelected, children: children || label || value })
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// src/Select.styled.ts
|
|
194
|
+
var import_react_core = require("@dt-dds/react-core");
|
|
195
|
+
var import_styled2 = __toESM(require("@emotion/styled"));
|
|
196
|
+
var SelectStyled = import_styled2.default.div`
|
|
197
|
+
position: relative;
|
|
198
|
+
width: 100%;
|
|
199
|
+
`;
|
|
200
|
+
var getThemedBackgroundFill = (fill, theme) => ({
|
|
201
|
+
default: theme.palette.surface.default,
|
|
202
|
+
contrast: theme.palette.surface.contrast,
|
|
203
|
+
light: theme.palette.surface.light
|
|
204
|
+
})[fill];
|
|
205
|
+
var SelectFieldStyled = import_styled2.default.div`
|
|
206
|
+
display: flex;
|
|
207
|
+
height: auto;
|
|
208
|
+
width: 100%;
|
|
209
|
+
position: relative;
|
|
210
|
+
flex-direction: column;
|
|
211
|
+
overflow: hidden;
|
|
212
|
+
`;
|
|
213
|
+
var SelectMenuStyled = import_styled2.default.ul`
|
|
214
|
+
list-style-type: none;
|
|
215
|
+
position: absolute;
|
|
216
|
+
z-index: ${import_react_core.DROPDOWN_MENU_Z_INDEX};
|
|
217
|
+
width: 100%;
|
|
218
|
+
max-height: 180px;
|
|
219
|
+
overflow: auto;
|
|
220
|
+
|
|
221
|
+
${({ isOpen, theme }) => `
|
|
222
|
+
margin-top:${theme.spacing["5xs"]};
|
|
223
|
+
padding: ${theme.spacing["2xs"]} ${theme.spacing.none};
|
|
224
|
+
background-color: ${theme.palette.surface.contrast};
|
|
225
|
+
display: ${isOpen ? "block" : "none"};
|
|
226
|
+
border-radius: ${theme.shape.formField};
|
|
227
|
+
box-shadow: ${theme.shadows.s};
|
|
228
|
+
`}
|
|
229
|
+
`;
|
|
230
|
+
var SelectValueContainerStyled = import_styled2.default.div`
|
|
231
|
+
display: flex;
|
|
232
|
+
flex: 1;
|
|
233
|
+
align-self: end;
|
|
234
|
+
overflow: hidden;
|
|
235
|
+
`;
|
|
236
|
+
var SelectValueStyled = import_styled2.default.div`
|
|
237
|
+
overflow: hidden;
|
|
238
|
+
text-overflow: ellipsis;
|
|
239
|
+
white-space: nowrap;
|
|
240
|
+
|
|
241
|
+
${({ theme }) => `
|
|
242
|
+
${theme.fontStyles.body2}
|
|
243
|
+
color: ${theme.palette.content.default};
|
|
244
|
+
`}
|
|
245
|
+
`;
|
|
246
|
+
var SelectContainerStyled = import_styled2.default.div`
|
|
247
|
+
transition: all 0.2s ease-in-out;
|
|
248
|
+
width: 100%;
|
|
249
|
+
height: 54px;
|
|
250
|
+
display: flex;
|
|
251
|
+
align-items: center;
|
|
252
|
+
justify-content: center;
|
|
253
|
+
|
|
254
|
+
${({
|
|
255
|
+
theme,
|
|
256
|
+
hasError,
|
|
257
|
+
disabled,
|
|
258
|
+
isOpen = false,
|
|
259
|
+
variant = "outlined",
|
|
260
|
+
fill = "default"
|
|
261
|
+
}) => `
|
|
262
|
+
${theme.fontStyles.body2}
|
|
263
|
+
color: ${disabled ? theme.palette.content.light : theme.palette.content.default};
|
|
264
|
+
padding: ${theme.spacing["4xs"]} ${theme.spacing["3xs"]};
|
|
265
|
+
gap: ${theme.spacing["4xs"]} ;
|
|
266
|
+
background-color: ${getThemedBackgroundFill(fill, theme)};
|
|
267
|
+
border-radius: ${theme.shape.formField};
|
|
268
|
+
cursor: ${disabled ? "not-allowed" : "pointer"};
|
|
269
|
+
|
|
270
|
+
border-width: ${variant === "outlined" ? "1px" : "0 0 1px"};
|
|
271
|
+
border-color: ${isOpen ? theme.palette.content.dark : theme.palette.border.medium};
|
|
272
|
+
border-style: solid;
|
|
273
|
+
|
|
274
|
+
&:focus, &:hover {
|
|
275
|
+
border-color: ${hasError ? theme.palette.error.default : theme.palette.content.dark};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
${hasError && `border-color: ${theme.palette.error.default}`};
|
|
279
|
+
`};
|
|
280
|
+
`;
|
|
281
|
+
var SelectActionContainerStyled = import_styled2.default.div`
|
|
282
|
+
display: flex;
|
|
283
|
+
`;
|
|
284
|
+
var HelperSelectFieldMessageStyled = import_styled2.default.div`
|
|
285
|
+
${({ theme }) => `
|
|
286
|
+
padding-left: ${theme.spacing["2xs"]};
|
|
287
|
+
`}
|
|
288
|
+
`;
|
|
289
|
+
|
|
290
|
+
// src/Select.tsx
|
|
291
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
292
|
+
var createOptionObject = (element) => {
|
|
293
|
+
return {
|
|
294
|
+
value: element.props.value,
|
|
295
|
+
label: element.props.label,
|
|
296
|
+
disabled: !!element.props.disabled
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
var itemToString = (item) => {
|
|
300
|
+
if (item) {
|
|
301
|
+
return item.label || item.value;
|
|
302
|
+
}
|
|
303
|
+
return "";
|
|
304
|
+
};
|
|
305
|
+
var Select = ({
|
|
306
|
+
dataTestId,
|
|
307
|
+
style,
|
|
308
|
+
helperText = "",
|
|
309
|
+
hasError = false,
|
|
310
|
+
initialValue = "",
|
|
311
|
+
label,
|
|
312
|
+
isMulti = false,
|
|
313
|
+
isRequired,
|
|
314
|
+
errorMessage,
|
|
315
|
+
children,
|
|
316
|
+
isDisabled,
|
|
317
|
+
variant = "outlined",
|
|
318
|
+
fill = "default",
|
|
319
|
+
onChange
|
|
320
|
+
}) => {
|
|
321
|
+
const [selectedItems, setSelectedItems] = (0, import_react2.useState)([]);
|
|
322
|
+
const ref = (0, import_react2.useRef)(null);
|
|
323
|
+
const changeSelectedItems = (0, import_react2.useCallback)(
|
|
324
|
+
(newItems, skipOnChangeTrigger = false) => {
|
|
325
|
+
var _a;
|
|
326
|
+
setSelectedItems(newItems);
|
|
327
|
+
if (onChange && !skipOnChangeTrigger) {
|
|
328
|
+
if (isMulti) {
|
|
329
|
+
const values = newItems.map((newSelectedItem) => newSelectedItem.value).filter((value) => Boolean(value));
|
|
330
|
+
onChange(values);
|
|
331
|
+
} else {
|
|
332
|
+
const value = ((_a = newItems[0]) == null ? void 0 : _a.value) || "";
|
|
333
|
+
onChange(value);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
[setSelectedItems, isMulti, onChange]
|
|
338
|
+
);
|
|
339
|
+
const clearSelection = (event) => {
|
|
340
|
+
event.stopPropagation();
|
|
341
|
+
changeSelectedItems([]);
|
|
342
|
+
};
|
|
343
|
+
const helperMessage = hasError && errorMessage ? errorMessage : helperText;
|
|
344
|
+
const options = (0, import_react2.useMemo)(() => {
|
|
345
|
+
const tempOptions = import_react2.Children.map(children, (child) => {
|
|
346
|
+
if ((0, import_react2.isValidElement)(child) && child.props.value != void 0) {
|
|
347
|
+
return createOptionObject(child);
|
|
348
|
+
}
|
|
349
|
+
return null;
|
|
350
|
+
});
|
|
351
|
+
return tempOptions ? tempOptions.filter(Boolean) : [];
|
|
352
|
+
}, [children]);
|
|
353
|
+
const validSelectedItems = (0, import_react2.useMemo)(() => {
|
|
354
|
+
const isSelectedItemValid = (selectedItem) => {
|
|
355
|
+
return !!options.find((option) => option.value === selectedItem.value);
|
|
356
|
+
};
|
|
357
|
+
return selectedItems.filter(isSelectedItemValid);
|
|
358
|
+
}, [options, selectedItems]);
|
|
359
|
+
(0, import_react2.useEffect)(() => {
|
|
360
|
+
const getInitialOptions = () => {
|
|
361
|
+
if (Array.isArray(initialValue)) {
|
|
362
|
+
return initialValue.map(
|
|
363
|
+
(value) => options.find((option) => option.value === value)
|
|
364
|
+
).filter((option) => Boolean(option));
|
|
365
|
+
} else {
|
|
366
|
+
return options.find((option) => option.value === initialValue);
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
const initalOptions = getInitialOptions();
|
|
370
|
+
if (!initialValue || !initalOptions || Array.isArray(initalOptions) && initalOptions.length === 0) {
|
|
371
|
+
changeSelectedItems([], true);
|
|
372
|
+
} else {
|
|
373
|
+
if (Array.isArray(initalOptions)) {
|
|
374
|
+
changeSelectedItems(isMulti ? initalOptions : [initalOptions[0]], true);
|
|
375
|
+
} else {
|
|
376
|
+
changeSelectedItems([initalOptions], true);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}, [isMulti, initialValue, options, changeSelectedItems]);
|
|
380
|
+
(0, import_react2.useEffect)(() => {
|
|
381
|
+
if (options.length === 1 && selectedItems.length === 0) {
|
|
382
|
+
changeSelectedItems([options[0]]);
|
|
383
|
+
}
|
|
384
|
+
if (validSelectedItems.length !== selectedItems.length) {
|
|
385
|
+
changeSelectedItems(validSelectedItems);
|
|
386
|
+
}
|
|
387
|
+
}, [options, selectedItems, validSelectedItems, changeSelectedItems]);
|
|
388
|
+
const {
|
|
389
|
+
isOpen,
|
|
390
|
+
closeMenu,
|
|
391
|
+
getToggleButtonProps,
|
|
392
|
+
getLabelProps,
|
|
393
|
+
getMenuProps,
|
|
394
|
+
highlightedIndex,
|
|
395
|
+
getItemProps
|
|
396
|
+
} = (0, import_downshift.useSelect)({
|
|
397
|
+
items: options,
|
|
398
|
+
isItemDisabled(item) {
|
|
399
|
+
return !!item.disabled;
|
|
400
|
+
},
|
|
401
|
+
itemToString,
|
|
402
|
+
stateReducer: (state, actionAndChanges) => {
|
|
403
|
+
const { changes, type } = actionAndChanges;
|
|
404
|
+
switch (type) {
|
|
405
|
+
case import_downshift.useSelect.stateChangeTypes.ToggleButtonKeyDownEnter:
|
|
406
|
+
case import_downshift.useSelect.stateChangeTypes.ToggleButtonKeyDownSpaceButton:
|
|
407
|
+
case import_downshift.useSelect.stateChangeTypes.ItemClick:
|
|
408
|
+
case import_downshift.useSelect.stateChangeTypes.ToggleButtonBlur:
|
|
409
|
+
return __spreadProps(__spreadValues({}, changes), {
|
|
410
|
+
isOpen: isMulti,
|
|
411
|
+
highlightedIndex: state.highlightedIndex
|
|
412
|
+
});
|
|
413
|
+
default:
|
|
414
|
+
return changes;
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
selectedItem: null,
|
|
418
|
+
onSelectedItemChange: ({ selectedItem }) => {
|
|
419
|
+
let newSelectedItems = [];
|
|
420
|
+
if (!isMulti) {
|
|
421
|
+
if (selectedItem) {
|
|
422
|
+
newSelectedItems = [selectedItem];
|
|
423
|
+
}
|
|
424
|
+
} else {
|
|
425
|
+
if (selectedItem) {
|
|
426
|
+
if (selectedItems.includes(selectedItem)) {
|
|
427
|
+
newSelectedItems = selectedItems.filter(
|
|
428
|
+
(item) => item !== selectedItem
|
|
429
|
+
);
|
|
430
|
+
} else {
|
|
431
|
+
newSelectedItems = [...selectedItems, selectedItem];
|
|
432
|
+
}
|
|
433
|
+
} else {
|
|
434
|
+
newSelectedItems = selectedItems;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
changeSelectedItems(newSelectedItems);
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
const hasSelectedItems = !!selectedItems && !!selectedItems.length;
|
|
441
|
+
const selectedValueContainerText = () => {
|
|
442
|
+
return selectedItems.length > 1 ? `${selectedItems.length} options selected` : selectedItems[0].label || selectedItems[0].value;
|
|
443
|
+
};
|
|
444
|
+
(0, import_react_core2.useClickOutside)({ ref, handler: () => closeMenu() });
|
|
445
|
+
const disabled = isDisabled || options.length === 1;
|
|
446
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
447
|
+
SelectProvider,
|
|
448
|
+
{
|
|
449
|
+
value: { highlightedIndex, getItemProps, selectedItems, isMulti },
|
|
450
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(SelectStyled, { "data-testid": dataTestId, ref, style, children: [
|
|
451
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SelectFieldStyled, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
452
|
+
SelectContainerStyled,
|
|
453
|
+
__spreadProps(__spreadValues({}, getToggleButtonProps({ disabled })), {
|
|
454
|
+
"data-testid": "select-container",
|
|
455
|
+
fill,
|
|
456
|
+
hasError,
|
|
457
|
+
isOpen,
|
|
458
|
+
variant,
|
|
459
|
+
children: [
|
|
460
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(SelectValueContainerStyled, { children: [
|
|
461
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
462
|
+
import_react_label_field.LabelField,
|
|
463
|
+
__spreadProps(__spreadValues({}, getLabelProps()), {
|
|
464
|
+
hasError,
|
|
465
|
+
isActive: hasSelectedItems,
|
|
466
|
+
isDisabled: disabled,
|
|
467
|
+
isRequired,
|
|
468
|
+
children: label
|
|
469
|
+
})
|
|
470
|
+
),
|
|
471
|
+
hasSelectedItems ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SelectValueStyled, { children: selectedValueContainerText() }) : null
|
|
472
|
+
] }),
|
|
473
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(SelectActionContainerStyled, { children: [
|
|
474
|
+
isMulti && hasSelectedItems ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react_tooltip.Tooltip, { children: [
|
|
475
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_icon_button.IconButton, { onClick: clearSelection, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_icon.Icon, { code: "close", dataTestId: "clear-selection", size: "s" }) }),
|
|
476
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_tooltip.Tooltip.Content, { children: "Clear all" })
|
|
477
|
+
] }) : null,
|
|
478
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_icon.Icon, { code: isOpen ? "expand_less" : "expand_more", size: "s" })
|
|
479
|
+
] })
|
|
480
|
+
]
|
|
481
|
+
})
|
|
482
|
+
) }),
|
|
483
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
484
|
+
SelectMenuStyled,
|
|
485
|
+
__spreadProps(__spreadValues({}, getMenuProps()), {
|
|
486
|
+
"aria-multiselectable": isMulti,
|
|
487
|
+
isOpen,
|
|
488
|
+
children: isOpen ? children : null
|
|
489
|
+
})
|
|
490
|
+
),
|
|
491
|
+
helperMessage ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(HelperSelectFieldMessageStyled, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
492
|
+
import_react_typography.Typography,
|
|
493
|
+
{
|
|
494
|
+
color: hasError ? "error.default" : "content.light",
|
|
495
|
+
element: "span",
|
|
496
|
+
fontStyles: "body3",
|
|
497
|
+
children: helperMessage
|
|
498
|
+
}
|
|
499
|
+
) }) : null
|
|
500
|
+
] })
|
|
501
|
+
}
|
|
502
|
+
);
|
|
503
|
+
};
|
|
504
|
+
Select.Option = SelectOption;
|
|
505
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
506
|
+
0 && (module.exports = {
|
|
507
|
+
Select
|
|
508
|
+
});
|