@dt-dds/react-select 1.0.0-beta.59 → 1.0.0-beta.61
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 +36 -0
- package/README.md +44 -30
- package/dist/index.d.mts +14 -12
- package/dist/index.d.ts +14 -12
- package/dist/index.js +262 -286
- package/dist/index.mjs +261 -288
- package/package.json +16 -10
package/dist/index.mjs
CHANGED
|
@@ -31,25 +31,22 @@ var __objRest = (source, exclude) => {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
// src/Select.tsx
|
|
34
|
-
import {
|
|
34
|
+
import { Box } from "@dt-dds/react-box";
|
|
35
|
+
import { Dropdown as Dropdown2 } from "@dt-dds/react-dropdown";
|
|
35
36
|
import { Icon } from "@dt-dds/react-icon";
|
|
36
37
|
import { IconButton } from "@dt-dds/react-icon-button";
|
|
37
38
|
import { LabelField } from "@dt-dds/react-label-field";
|
|
38
39
|
import { Tooltip } from "@dt-dds/react-tooltip";
|
|
39
|
-
import
|
|
40
|
-
import { useSelect } from "downshift";
|
|
40
|
+
import * as Downshift from "downshift";
|
|
41
41
|
import {
|
|
42
|
-
useRef,
|
|
43
|
-
useState,
|
|
44
|
-
useEffect,
|
|
45
42
|
Children,
|
|
46
43
|
isValidElement,
|
|
47
44
|
useMemo,
|
|
48
|
-
|
|
45
|
+
useRef
|
|
49
46
|
} from "react";
|
|
50
47
|
|
|
51
48
|
// src/components/SelectOption.tsx
|
|
52
|
-
import {
|
|
49
|
+
import { Dropdown } from "@dt-dds/react-dropdown";
|
|
53
50
|
|
|
54
51
|
// src/context/SelectProvider.tsx
|
|
55
52
|
import { createContext, useContext } from "react";
|
|
@@ -83,47 +80,22 @@ var SelectProvider = ({ children, value }) => {
|
|
|
83
80
|
};
|
|
84
81
|
|
|
85
82
|
// src/components/SelectOption.styled.ts
|
|
83
|
+
import { Checkbox } from "@dt-dds/react-checkbox";
|
|
86
84
|
import styled from "@emotion/styled";
|
|
87
|
-
var
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
cursor:pointer;
|
|
92
|
-
align-items: center;
|
|
93
|
-
${!isMulti && `padding: ${theme.spacing.spacing_30} ${theme.spacing.spacing_50}`};
|
|
94
|
-
gap: ${isMulti ? theme.spacing.spacing_30 : theme.spacing.spacing_20};
|
|
95
|
-
background-color: ${isHighlighted && !isMulti ? theme.palette.primary.light : theme.palette.surface.contrast};
|
|
96
|
-
|
|
97
|
-
color: ${theme.palette.content.default};
|
|
98
|
-
${theme.fontStyles.bodyMdRegular}
|
|
85
|
+
var SelectCheckboxStyled = styled(Checkbox)`
|
|
86
|
+
${({ theme }) => `
|
|
87
|
+
pointer-events: none;
|
|
88
|
+
padding: ${theme.spacing.spacing_40} ${theme.spacing.spacing_50};
|
|
99
89
|
|
|
100
|
-
&
|
|
101
|
-
${
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
&:hover,&:focus-within {
|
|
105
|
-
background-color: ${theme.palette.primary.light};
|
|
90
|
+
&[data-selected="true"] span {
|
|
91
|
+
${theme.fontStyles.bodyMdBold};
|
|
106
92
|
}
|
|
107
93
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
color: ${theme.palette.content.light};
|
|
111
|
-
&:hover {
|
|
112
|
-
background-color: ${theme.palette.surface.contrast};
|
|
113
|
-
}
|
|
94
|
+
span {
|
|
95
|
+
color: inherit;
|
|
114
96
|
}
|
|
115
97
|
`}
|
|
116
98
|
`;
|
|
117
|
-
var SelectOptionContentStyled = styled.div`
|
|
118
|
-
text-overflow: ellipsis;
|
|
119
|
-
white-space: nowrap;
|
|
120
|
-
overflow: hidden;
|
|
121
|
-
width: 100%;
|
|
122
|
-
|
|
123
|
-
${({ theme, isSelected }) => `
|
|
124
|
-
${theme.fontStyles[isSelected ? "bodyMdBold" : "bodyMdRegular"]};
|
|
125
|
-
`}
|
|
126
|
-
`;
|
|
127
99
|
|
|
128
100
|
// src/components/SelectOption.tsx
|
|
129
101
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
@@ -133,233 +105,197 @@ var SelectOption = ({
|
|
|
133
105
|
children,
|
|
134
106
|
style,
|
|
135
107
|
value,
|
|
136
|
-
|
|
137
|
-
disabled
|
|
108
|
+
isDisabled = false
|
|
138
109
|
}) => {
|
|
139
110
|
const { getItemProps, isItemHighlighted, isItemSelected, isMulti } = useSelectContext();
|
|
140
|
-
const item = { value,
|
|
111
|
+
const item = { value, isDisabled };
|
|
141
112
|
const isSelected = isItemSelected(item);
|
|
142
113
|
const isHighlighted = isItemHighlighted(index);
|
|
143
|
-
const itemProps = getItemProps({ item, index });
|
|
144
114
|
return /* @__PURE__ */ jsx2(
|
|
145
|
-
|
|
115
|
+
Dropdown.Option,
|
|
146
116
|
__spreadProps(__spreadValues({
|
|
147
|
-
|
|
148
|
-
|
|
117
|
+
dataTestId,
|
|
118
|
+
isDisabled,
|
|
149
119
|
isHighlighted,
|
|
150
|
-
|
|
151
|
-
style
|
|
152
|
-
},
|
|
153
|
-
"aria-selected": isSelected
|
|
154
|
-
})), {
|
|
120
|
+
isSelected,
|
|
121
|
+
style: __spreadValues(__spreadValues({}, style), isMulti ? { padding: 0 } : {})
|
|
122
|
+
}, getItemProps({ item, index })), {
|
|
155
123
|
children: isMulti ? /* @__PURE__ */ jsx2(
|
|
156
|
-
|
|
157
|
-
|
|
124
|
+
SelectCheckboxStyled,
|
|
125
|
+
{
|
|
126
|
+
"aria-hidden": "true",
|
|
158
127
|
isChecked: isSelected,
|
|
159
|
-
isDisabled
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
128
|
+
isDisabled,
|
|
129
|
+
role: "presentation",
|
|
130
|
+
tabIndex: -1,
|
|
131
|
+
children
|
|
132
|
+
}
|
|
133
|
+
) : children
|
|
164
134
|
})
|
|
165
135
|
);
|
|
166
136
|
};
|
|
167
137
|
|
|
168
138
|
// src/Select.styled.ts
|
|
169
|
-
import {
|
|
139
|
+
import { Typography } from "@dt-dds/react-typography";
|
|
170
140
|
import styled2 from "@emotion/styled";
|
|
171
141
|
var SelectStyled = styled2.div`
|
|
172
142
|
position: relative;
|
|
173
143
|
width: 100%;
|
|
144
|
+
display: flex;
|
|
145
|
+
flex-direction: column;
|
|
146
|
+
gap: ${({ theme }) => theme.spacing.spacing_30};
|
|
174
147
|
`;
|
|
175
148
|
var getThemedBackgroundFill = (fill, theme) => ({
|
|
176
149
|
default: theme.palette.surface.default,
|
|
177
150
|
contrast: theme.palette.surface.contrast,
|
|
178
151
|
light: theme.palette.surface.light
|
|
179
152
|
})[fill];
|
|
180
|
-
var
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
width: 100%;
|
|
184
|
-
position: relative;
|
|
185
|
-
flex-direction: column;
|
|
186
|
-
overflow: hidden;
|
|
187
|
-
`;
|
|
188
|
-
var SelectMenuStyled = styled2.ul`
|
|
189
|
-
list-style-type: none;
|
|
190
|
-
position: absolute;
|
|
191
|
-
z-index: ${DROPDOWN_MENU_Z_INDEX};
|
|
192
|
-
width: 100%;
|
|
193
|
-
max-height: 180px;
|
|
194
|
-
overflow: auto;
|
|
195
|
-
|
|
196
|
-
${({ isOpen, theme }) => `
|
|
197
|
-
margin-top:${theme.spacing.spacing_20};
|
|
198
|
-
padding: ${theme.spacing.spacing_50} ${theme.spacing.spacing_0};
|
|
199
|
-
background-color: ${theme.palette.surface.contrast};
|
|
200
|
-
display: ${isOpen ? "block" : "none"};
|
|
201
|
-
border-radius: ${theme.shape.formField};
|
|
202
|
-
box-shadow: ${theme.shadows.elevation_200};
|
|
203
|
-
`}
|
|
204
|
-
`;
|
|
205
|
-
var SelectValueContainerStyled = styled2.div`
|
|
206
|
-
display: flex;
|
|
207
|
-
flex: 1;
|
|
208
|
-
align-self: end;
|
|
209
|
-
overflow: hidden;
|
|
210
|
-
`;
|
|
211
|
-
var SelectValueStyled = styled2.div`
|
|
153
|
+
var TypographyValueStyled = styled2(Typography, {
|
|
154
|
+
shouldForwardProp: (prop) => prop !== "scale" && prop !== "isFloatingLabel"
|
|
155
|
+
})`
|
|
212
156
|
overflow: hidden;
|
|
213
157
|
text-overflow: ellipsis;
|
|
214
158
|
white-space: nowrap;
|
|
215
159
|
|
|
216
|
-
${({ theme }) => `
|
|
217
|
-
${theme.
|
|
218
|
-
color: ${theme.palette.content.default};
|
|
160
|
+
${({ theme, scale, isFloatingLabel }) => `
|
|
161
|
+
${isFloatingLabel ? `padding-top: ${scale === "standard" ? theme.spacing.spacing_50 : theme.spacing.spacing_40};` : `padding-block: ${scale === "standard" ? theme.spacing.spacing_30 : theme.spacing.spacing_20};`}
|
|
219
162
|
`}
|
|
220
163
|
`;
|
|
221
164
|
var SelectContainerStyled = styled2.div`
|
|
222
|
-
transition:
|
|
165
|
+
transition: border 0.2s ease-in-out;
|
|
223
166
|
width: 100%;
|
|
224
|
-
height: 54px;
|
|
225
167
|
display: flex;
|
|
168
|
+
justify-content: space-between;
|
|
226
169
|
align-items: center;
|
|
227
|
-
justify-content: center;
|
|
228
170
|
|
|
229
171
|
${({
|
|
230
172
|
theme,
|
|
231
|
-
hasError,
|
|
232
|
-
disabled,
|
|
233
173
|
isOpen = false,
|
|
234
174
|
variant = "outlined",
|
|
235
|
-
fill = "default"
|
|
175
|
+
fill = "default",
|
|
176
|
+
scale
|
|
236
177
|
}) => `
|
|
237
178
|
${theme.fontStyles.bodyMdRegular}
|
|
238
|
-
color: ${
|
|
239
|
-
padding: ${theme.spacing.spacing_30} ${theme.spacing.spacing_40};
|
|
240
|
-
gap: ${theme.spacing.spacing_30}
|
|
179
|
+
color: ${theme.palette.content.default};
|
|
180
|
+
padding: ${scale === "standard" ? theme.spacing.spacing_40 : `${theme.spacing.spacing_30} ${theme.spacing.spacing_40}`};
|
|
181
|
+
gap: ${theme.spacing.spacing_30};
|
|
241
182
|
background-color: ${getThemedBackgroundFill(fill, theme)};
|
|
242
183
|
border-radius: ${theme.shape.formField};
|
|
243
|
-
cursor:
|
|
184
|
+
cursor: pointer;
|
|
185
|
+
user-select: none;
|
|
186
|
+
|
|
187
|
+
|
|
244
188
|
|
|
245
189
|
border-width: ${variant === "outlined" ? "1px" : "0 0 1px"};
|
|
246
|
-
|
|
247
|
-
|
|
190
|
+
border-color: ${isOpen ? theme.palette.informative.default : theme.palette.border.medium};
|
|
191
|
+
border-style: solid;
|
|
192
|
+
|
|
193
|
+
&:not([disabled]){
|
|
194
|
+
&:focus-visible {
|
|
195
|
+
outline: 2px solid ${theme.palette.primary.default};
|
|
196
|
+
outline-offset: 1px;
|
|
197
|
+
}
|
|
248
198
|
|
|
249
|
-
&:
|
|
250
|
-
|
|
199
|
+
&:not([aria-invalid="true"]){
|
|
200
|
+
&:focus-visible, &:hover {
|
|
201
|
+
border-color: ${theme.palette.informative.default};
|
|
202
|
+
}
|
|
251
203
|
}
|
|
252
204
|
|
|
253
|
-
|
|
205
|
+
&[aria-invalid="true"]{
|
|
206
|
+
border-color: ${theme.palette.error.default};
|
|
207
|
+
|
|
208
|
+
i {
|
|
209
|
+
color: ${theme.palette.error.default}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
&[disabled] {
|
|
215
|
+
color: ${theme.palette.content.light};
|
|
216
|
+
cursor: not-allowed;
|
|
217
|
+
|
|
218
|
+
i {
|
|
219
|
+
color: inherit;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
254
222
|
`};
|
|
255
223
|
`;
|
|
256
224
|
var SelectActionContainerStyled = styled2.div`
|
|
257
225
|
display: flex;
|
|
226
|
+
|
|
227
|
+
${({ scale, hasItems, isFloatingLabel, theme }) => `
|
|
228
|
+
gap: ${theme.spacing.spacing_30};
|
|
229
|
+
|
|
230
|
+
${(!hasItems || !isFloatingLabel) && `padding-block: ${scale === "standard" ? theme.spacing.spacing_20 : theme.spacing.spacing_10}`}
|
|
231
|
+
`}
|
|
258
232
|
`;
|
|
259
|
-
var
|
|
233
|
+
var TypographyHelperTextStyled = styled2(Typography)`
|
|
260
234
|
${({ theme }) => `
|
|
261
|
-
padding-left: ${theme.spacing.
|
|
235
|
+
padding-left: ${theme.spacing.spacing_40};
|
|
262
236
|
`}
|
|
263
237
|
`;
|
|
264
238
|
|
|
265
239
|
// src/Select.tsx
|
|
266
240
|
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
267
|
-
var
|
|
268
|
-
|
|
269
|
-
value: element.props.value,
|
|
270
|
-
label: element.props.label,
|
|
271
|
-
disabled: !!element.props.disabled
|
|
272
|
-
};
|
|
273
|
-
};
|
|
274
|
-
var itemToString = (item) => {
|
|
275
|
-
if (item) {
|
|
276
|
-
return item.label || item.value;
|
|
277
|
-
}
|
|
278
|
-
return "";
|
|
279
|
-
};
|
|
241
|
+
var { useSelect } = Downshift;
|
|
242
|
+
var helperTextId = "helper-text-id";
|
|
280
243
|
var Select = ({
|
|
281
244
|
dataTestId,
|
|
282
245
|
style,
|
|
283
|
-
|
|
284
|
-
hasError = false,
|
|
285
|
-
initialValue = "",
|
|
246
|
+
value,
|
|
286
247
|
label,
|
|
287
|
-
isMulti
|
|
248
|
+
isMulti,
|
|
288
249
|
isRequired,
|
|
289
|
-
errorMessage,
|
|
290
250
|
children,
|
|
291
251
|
isDisabled,
|
|
252
|
+
labelIcon,
|
|
253
|
+
hasError = false,
|
|
254
|
+
helperText = "",
|
|
292
255
|
variant = "outlined",
|
|
293
256
|
fill = "default",
|
|
257
|
+
isFloatingLabel = true,
|
|
258
|
+
scale = "standard",
|
|
294
259
|
onChange
|
|
295
260
|
}) => {
|
|
296
|
-
|
|
297
|
-
const
|
|
298
|
-
const
|
|
299
|
-
(
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
} else {
|
|
307
|
-
const value = ((_a = newItems[0]) == null ? void 0 : _a.value) || "";
|
|
308
|
-
onChange(value);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
},
|
|
312
|
-
[setSelectedItems, isMulti, onChange]
|
|
313
|
-
);
|
|
314
|
-
const clearSelection = (event) => {
|
|
315
|
-
event.stopPropagation();
|
|
316
|
-
changeSelectedItems([]);
|
|
261
|
+
var _a;
|
|
262
|
+
const anchorRef = useRef(null);
|
|
263
|
+
const handleClearKeyDown = (e) => {
|
|
264
|
+
if (e.code === "Enter" || e.code === "Space") {
|
|
265
|
+
handleClearSelection(e);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
const handleClearSelection = (e) => {
|
|
269
|
+
e.stopPropagation();
|
|
270
|
+
isMulti && onChange([]);
|
|
317
271
|
};
|
|
318
|
-
const helperMessage = hasError && errorMessage ? errorMessage : helperText;
|
|
319
272
|
const options = useMemo(() => {
|
|
273
|
+
var _a2;
|
|
320
274
|
const tempOptions = Children.map(children, (child) => {
|
|
321
275
|
if (isValidElement(child) && child.props.value != void 0) {
|
|
322
|
-
return
|
|
276
|
+
return {
|
|
277
|
+
value: child.props.value,
|
|
278
|
+
isDisabled: child.props.isDisabled,
|
|
279
|
+
label: child.props.children
|
|
280
|
+
};
|
|
323
281
|
}
|
|
324
282
|
return null;
|
|
325
283
|
});
|
|
326
|
-
return tempOptions ? tempOptions.filter(Boolean) : [];
|
|
284
|
+
return (_a2 = tempOptions == null ? void 0 : tempOptions.filter(Boolean)) != null ? _a2 : [];
|
|
327
285
|
}, [children]);
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
return options.find((option) => option.value === initialValue);
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
const initalOptions = getInitialOptions();
|
|
345
|
-
if (!initialValue || !initalOptions || Array.isArray(initalOptions) && initalOptions.length === 0) {
|
|
346
|
-
changeSelectedItems([], true);
|
|
347
|
-
} else {
|
|
348
|
-
if (Array.isArray(initalOptions)) {
|
|
349
|
-
changeSelectedItems(isMulti ? initalOptions : [initalOptions[0]], true);
|
|
350
|
-
} else {
|
|
351
|
-
changeSelectedItems([initalOptions], true);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}, [isMulti, initialValue, options, changeSelectedItems]);
|
|
355
|
-
useEffect(() => {
|
|
356
|
-
if (options.length === 1 && selectedItems.length === 0) {
|
|
357
|
-
changeSelectedItems([options[0]]);
|
|
358
|
-
}
|
|
359
|
-
if (validSelectedItems.length !== selectedItems.length) {
|
|
360
|
-
changeSelectedItems(validSelectedItems);
|
|
361
|
-
}
|
|
362
|
-
}, [options, selectedItems, validSelectedItems, changeSelectedItems]);
|
|
286
|
+
const selectedOptionsSet = useMemo(
|
|
287
|
+
() => new Set(value ? [value].flat() : []),
|
|
288
|
+
[value]
|
|
289
|
+
);
|
|
290
|
+
const selectedItems = useMemo(
|
|
291
|
+
() => options.filter((o) => selectedOptionsSet.has(o.value)),
|
|
292
|
+
[options, selectedOptionsSet]
|
|
293
|
+
);
|
|
294
|
+
const hasSelectedItems = !!(selectedItems == null ? void 0 : selectedItems.length);
|
|
295
|
+
const selectedValueContainerText = () => {
|
|
296
|
+
var _a2;
|
|
297
|
+
return selectedItems.length > 1 ? `${selectedItems.length} options selected` : (_a2 = selectedItems[0]) == null ? void 0 : _a2.label;
|
|
298
|
+
};
|
|
363
299
|
const {
|
|
364
300
|
isOpen,
|
|
365
301
|
closeMenu,
|
|
@@ -371,122 +307,159 @@ var Select = ({
|
|
|
371
307
|
} = useSelect({
|
|
372
308
|
items: options,
|
|
373
309
|
isItemDisabled(item) {
|
|
374
|
-
return !!item.
|
|
310
|
+
return !!item.isDisabled;
|
|
375
311
|
},
|
|
376
|
-
|
|
377
|
-
|
|
312
|
+
defaultHighlightedIndex: isMulti || !(selectedItems == null ? void 0 : selectedItems[0]) ? 0 : void 0,
|
|
313
|
+
selectedItem: !isMulti ? (_a = selectedItems == null ? void 0 : selectedItems[0]) != null ? _a : null : null,
|
|
314
|
+
stateReducer(state, actionAndChanges) {
|
|
378
315
|
const { changes, type } = actionAndChanges;
|
|
379
316
|
switch (type) {
|
|
380
|
-
case useSelect.stateChangeTypes.ToggleButtonKeyDownEnter:
|
|
381
|
-
case useSelect.stateChangeTypes.ToggleButtonKeyDownSpaceButton:
|
|
382
|
-
case useSelect.stateChangeTypes.ItemClick:
|
|
383
317
|
case useSelect.stateChangeTypes.ToggleButtonBlur:
|
|
384
318
|
return __spreadProps(__spreadValues({}, changes), {
|
|
385
|
-
isOpen:
|
|
319
|
+
isOpen: false,
|
|
320
|
+
selectedItem: state.selectedItem,
|
|
386
321
|
highlightedIndex: state.highlightedIndex
|
|
387
322
|
});
|
|
323
|
+
case useSelect.stateChangeTypes.ItemClick:
|
|
324
|
+
case useSelect.stateChangeTypes.ToggleButtonKeyDownEnter:
|
|
325
|
+
case useSelect.stateChangeTypes.ToggleButtonKeyDownSpaceButton:
|
|
326
|
+
return isMulti ? __spreadProps(__spreadValues({}, changes), {
|
|
327
|
+
isOpen: true,
|
|
328
|
+
highlightedIndex: state.highlightedIndex
|
|
329
|
+
}) : changes;
|
|
388
330
|
default:
|
|
389
331
|
return changes;
|
|
390
332
|
}
|
|
391
333
|
},
|
|
392
|
-
selectedItem: null,
|
|
393
334
|
onSelectedItemChange: ({ selectedItem }) => {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
(item) => item !== selectedItem
|
|
404
|
-
);
|
|
405
|
-
} else {
|
|
406
|
-
newSelectedItems = [...selectedItems, selectedItem];
|
|
407
|
-
}
|
|
408
|
-
} else {
|
|
409
|
-
newSelectedItems = selectedItems;
|
|
410
|
-
}
|
|
335
|
+
if (!selectedItem) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (isMulti) {
|
|
339
|
+
const currentValue = Array.isArray(value) ? value : [];
|
|
340
|
+
const isSelectedItem = selectedOptionsSet.has(selectedItem.value);
|
|
341
|
+
const nextValue = isSelectedItem ? currentValue.filter((v) => v !== selectedItem.value) : [...currentValue, selectedItem.value];
|
|
342
|
+
onChange(nextValue);
|
|
343
|
+
return;
|
|
411
344
|
}
|
|
412
|
-
|
|
345
|
+
onChange(selectedItem.value);
|
|
413
346
|
}
|
|
414
347
|
});
|
|
415
|
-
const hasSelectedItems = !!selectedItems && !!selectedItems.length;
|
|
416
|
-
const selectedValueContainerText = () => {
|
|
417
|
-
return selectedItems.length > 1 ? `${selectedItems.length} options selected` : selectedItems[0].label || selectedItems[0].value;
|
|
418
|
-
};
|
|
419
|
-
useClickOutside({ ref, handler: () => closeMenu() });
|
|
420
348
|
const disabled = isDisabled || options.length === 1;
|
|
349
|
+
const toggleProps = getToggleButtonProps({
|
|
350
|
+
disabled,
|
|
351
|
+
tabIndex: disabled ? -1 : 0,
|
|
352
|
+
ref: anchorRef
|
|
353
|
+
});
|
|
421
354
|
return /* @__PURE__ */ jsx3(
|
|
422
355
|
SelectProvider,
|
|
423
356
|
{
|
|
424
|
-
value: {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
357
|
+
value: {
|
|
358
|
+
highlightedIndex,
|
|
359
|
+
getItemProps,
|
|
360
|
+
selectedItems,
|
|
361
|
+
isMulti: !!isMulti
|
|
362
|
+
},
|
|
363
|
+
children: /* @__PURE__ */ jsxs(
|
|
364
|
+
Box,
|
|
365
|
+
{
|
|
366
|
+
dataTestId: dataTestId != null ? dataTestId : "select",
|
|
367
|
+
style: { alignItems: "start", gap: 4 },
|
|
368
|
+
children: [
|
|
369
|
+
/* @__PURE__ */ jsxs(SelectStyled, { style, children: [
|
|
370
|
+
/* @__PURE__ */ jsx3(
|
|
371
|
+
LabelField,
|
|
372
|
+
__spreadProps(__spreadValues(__spreadProps(__spreadValues({}, getLabelProps()), {
|
|
373
|
+
hasError,
|
|
374
|
+
icon: labelIcon,
|
|
375
|
+
isActive: isFloatingLabel ? hasSelectedItems : isOpen,
|
|
376
|
+
isCentered: true,
|
|
377
|
+
isDisabled: disabled,
|
|
378
|
+
isFloating: isFloatingLabel,
|
|
379
|
+
isRequired,
|
|
380
|
+
scale
|
|
381
|
+
}), isFloatingLabel && {
|
|
382
|
+
style: { pointerEvents: "none" }
|
|
383
|
+
}), {
|
|
384
|
+
children: label
|
|
385
|
+
})
|
|
386
|
+
),
|
|
387
|
+
/* @__PURE__ */ jsxs(
|
|
388
|
+
SelectContainerStyled,
|
|
389
|
+
__spreadProps(__spreadValues(__spreadValues(__spreadValues({}, toggleProps), !!helperText && { "aria-describedby": helperTextId }), hasError && { "aria-invalid": hasError }), {
|
|
390
|
+
"data-testid": "select-container",
|
|
391
|
+
fill,
|
|
392
|
+
isOpen,
|
|
393
|
+
scale,
|
|
394
|
+
variant,
|
|
395
|
+
children: [
|
|
396
|
+
/* @__PURE__ */ jsx3(
|
|
397
|
+
TypographyValueStyled,
|
|
398
|
+
__spreadProps(__spreadValues({
|
|
399
|
+
color: "content.default",
|
|
400
|
+
dataTestId: "select-value",
|
|
401
|
+
element: "span",
|
|
402
|
+
fontStyles: "bodyMdRegular",
|
|
403
|
+
isFloatingLabel,
|
|
404
|
+
scale
|
|
405
|
+
}, disabled && { color: "content.light" }), {
|
|
406
|
+
children: selectedValueContainerText()
|
|
407
|
+
})
|
|
408
|
+
),
|
|
409
|
+
/* @__PURE__ */ jsxs(
|
|
410
|
+
SelectActionContainerStyled,
|
|
411
|
+
{
|
|
412
|
+
hasItems: hasSelectedItems,
|
|
413
|
+
isFloatingLabel,
|
|
414
|
+
scale,
|
|
415
|
+
children: [
|
|
416
|
+
isMulti && hasSelectedItems ? /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
417
|
+
/* @__PURE__ */ jsx3(
|
|
418
|
+
IconButton,
|
|
419
|
+
{
|
|
420
|
+
dataTestId: "clear-selection",
|
|
421
|
+
onClick: handleClearSelection,
|
|
422
|
+
onKeyDown: handleClearKeyDown,
|
|
423
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
424
|
+
children: /* @__PURE__ */ jsx3(Icon, { code: "close_small" })
|
|
425
|
+
}
|
|
426
|
+
),
|
|
427
|
+
/* @__PURE__ */ jsx3(Tooltip.Content, { children: "Clear all" })
|
|
428
|
+
] }) : null,
|
|
429
|
+
/* @__PURE__ */ jsx3(Icon, { code: isOpen ? "expand_less" : "expand_more" })
|
|
430
|
+
]
|
|
431
|
+
}
|
|
432
|
+
)
|
|
433
|
+
]
|
|
434
|
+
})
|
|
435
|
+
)
|
|
436
|
+
] }),
|
|
437
|
+
helperText ? /* @__PURE__ */ jsx3(
|
|
438
|
+
TypographyHelperTextStyled,
|
|
439
|
+
{
|
|
440
|
+
color: isDisabled ? "content.light" : hasError ? "error.default" : "content.medium",
|
|
441
|
+
dataTestId: "select-helper-text",
|
|
442
|
+
element: "span",
|
|
443
|
+
fontStyles: "bodySmRegular",
|
|
444
|
+
id: helperTextId,
|
|
445
|
+
children: helperText
|
|
446
|
+
}
|
|
447
|
+
) : null,
|
|
448
|
+
/* @__PURE__ */ jsx3(
|
|
449
|
+
Dropdown2,
|
|
450
|
+
__spreadProps(__spreadValues({}, getMenuProps()), {
|
|
451
|
+
anchorRef,
|
|
452
|
+
"aria-multiselectable": isMulti,
|
|
453
|
+
as: "ul",
|
|
454
|
+
isOpen,
|
|
455
|
+
onClose: closeMenu,
|
|
456
|
+
style: { maxHeight: 200 },
|
|
457
|
+
children
|
|
458
|
+
})
|
|
459
|
+
)
|
|
460
|
+
]
|
|
461
|
+
}
|
|
462
|
+
)
|
|
490
463
|
}
|
|
491
464
|
);
|
|
492
465
|
};
|