@dt-dds/react-select 1.0.0-beta.58 → 1.0.0-beta.60
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 +258 -270
- package/dist/index.mjs +259 -274
- 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 { Typography } from "@dt-dds/react-typography";
|
|
40
40
|
import { useSelect } 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,196 @@ 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
|
-
return {
|
|
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 helperTextId = "helper-text-id";
|
|
280
242
|
var Select = ({
|
|
281
243
|
dataTestId,
|
|
282
244
|
style,
|
|
283
|
-
|
|
284
|
-
hasError = false,
|
|
285
|
-
initialValue = "",
|
|
245
|
+
value,
|
|
286
246
|
label,
|
|
287
|
-
isMulti
|
|
247
|
+
isMulti,
|
|
288
248
|
isRequired,
|
|
289
|
-
errorMessage,
|
|
290
249
|
children,
|
|
291
250
|
isDisabled,
|
|
251
|
+
labelIcon,
|
|
252
|
+
hasError = false,
|
|
253
|
+
helperText = "",
|
|
292
254
|
variant = "outlined",
|
|
293
255
|
fill = "default",
|
|
256
|
+
isFloatingLabel = true,
|
|
257
|
+
scale = "standard",
|
|
294
258
|
onChange
|
|
295
259
|
}) => {
|
|
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([]);
|
|
260
|
+
var _a;
|
|
261
|
+
const anchorRef = useRef(null);
|
|
262
|
+
const handleClearKeyDown = (e) => {
|
|
263
|
+
if (e.code === "Enter" || e.code === "Space") {
|
|
264
|
+
handleClearSelection(e);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
const handleClearSelection = (e) => {
|
|
268
|
+
e.stopPropagation();
|
|
269
|
+
isMulti && onChange([]);
|
|
317
270
|
};
|
|
318
|
-
const helperMessage = hasError && errorMessage ? errorMessage : helperText;
|
|
319
271
|
const options = useMemo(() => {
|
|
272
|
+
var _a2;
|
|
320
273
|
const tempOptions = Children.map(children, (child) => {
|
|
321
274
|
if (isValidElement(child) && child.props.value != void 0) {
|
|
322
|
-
return
|
|
275
|
+
return {
|
|
276
|
+
value: child.props.value,
|
|
277
|
+
isDisabled: child.props.isDisabled,
|
|
278
|
+
label: child.props.children
|
|
279
|
+
};
|
|
323
280
|
}
|
|
324
281
|
return null;
|
|
325
282
|
});
|
|
326
|
-
return tempOptions ? tempOptions.filter(Boolean) : [];
|
|
283
|
+
return (_a2 = tempOptions == null ? void 0 : tempOptions.filter(Boolean)) != null ? _a2 : [];
|
|
327
284
|
}, [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]);
|
|
285
|
+
const selectedOptionsSet = useMemo(
|
|
286
|
+
() => new Set(value ? [value].flat() : []),
|
|
287
|
+
[value]
|
|
288
|
+
);
|
|
289
|
+
const selectedItems = useMemo(
|
|
290
|
+
() => options.filter((o) => selectedOptionsSet.has(o.value)),
|
|
291
|
+
[options, selectedOptionsSet]
|
|
292
|
+
);
|
|
293
|
+
const hasSelectedItems = !!(selectedItems == null ? void 0 : selectedItems.length);
|
|
294
|
+
const selectedValueContainerText = () => {
|
|
295
|
+
var _a2;
|
|
296
|
+
return selectedItems.length > 1 ? `${selectedItems.length} options selected` : (_a2 = selectedItems[0]) == null ? void 0 : _a2.label;
|
|
297
|
+
};
|
|
363
298
|
const {
|
|
364
299
|
isOpen,
|
|
365
300
|
closeMenu,
|
|
@@ -371,109 +306,159 @@ var Select = ({
|
|
|
371
306
|
} = useSelect({
|
|
372
307
|
items: options,
|
|
373
308
|
isItemDisabled(item) {
|
|
374
|
-
return !!item.
|
|
309
|
+
return !!item.isDisabled;
|
|
375
310
|
},
|
|
376
|
-
|
|
377
|
-
|
|
311
|
+
defaultHighlightedIndex: isMulti || !(selectedItems == null ? void 0 : selectedItems[0]) ? 0 : void 0,
|
|
312
|
+
selectedItem: !isMulti ? (_a = selectedItems == null ? void 0 : selectedItems[0]) != null ? _a : null : null,
|
|
313
|
+
stateReducer(state, actionAndChanges) {
|
|
378
314
|
const { changes, type } = actionAndChanges;
|
|
379
315
|
switch (type) {
|
|
380
|
-
case useSelect.stateChangeTypes.ToggleButtonKeyDownEnter:
|
|
381
|
-
case useSelect.stateChangeTypes.ToggleButtonKeyDownSpaceButton:
|
|
382
|
-
case useSelect.stateChangeTypes.ItemClick:
|
|
383
316
|
case useSelect.stateChangeTypes.ToggleButtonBlur:
|
|
384
317
|
return __spreadProps(__spreadValues({}, changes), {
|
|
385
|
-
isOpen:
|
|
318
|
+
isOpen: false,
|
|
319
|
+
selectedItem: state.selectedItem,
|
|
386
320
|
highlightedIndex: state.highlightedIndex
|
|
387
321
|
});
|
|
322
|
+
case useSelect.stateChangeTypes.ItemClick:
|
|
323
|
+
case useSelect.stateChangeTypes.ToggleButtonKeyDownEnter:
|
|
324
|
+
case useSelect.stateChangeTypes.ToggleButtonKeyDownSpaceButton:
|
|
325
|
+
return isMulti ? __spreadProps(__spreadValues({}, changes), {
|
|
326
|
+
isOpen: true,
|
|
327
|
+
highlightedIndex: state.highlightedIndex
|
|
328
|
+
}) : changes;
|
|
388
329
|
default:
|
|
389
330
|
return changes;
|
|
390
331
|
}
|
|
391
332
|
},
|
|
392
|
-
selectedItem: null,
|
|
393
333
|
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
|
-
}
|
|
334
|
+
if (!selectedItem) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (isMulti) {
|
|
338
|
+
const currentValue = Array.isArray(value) ? value : [];
|
|
339
|
+
const isSelectedItem = selectedOptionsSet.has(selectedItem.value);
|
|
340
|
+
const nextValue = isSelectedItem ? currentValue.filter((v) => v !== selectedItem.value) : [...currentValue, selectedItem.value];
|
|
341
|
+
onChange(nextValue);
|
|
342
|
+
return;
|
|
411
343
|
}
|
|
412
|
-
|
|
344
|
+
onChange(selectedItem.value);
|
|
413
345
|
}
|
|
414
346
|
});
|
|
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
347
|
const disabled = isDisabled || options.length === 1;
|
|
348
|
+
const toggleProps = getToggleButtonProps({
|
|
349
|
+
disabled,
|
|
350
|
+
tabIndex: disabled ? -1 : 0,
|
|
351
|
+
ref: anchorRef
|
|
352
|
+
});
|
|
421
353
|
return /* @__PURE__ */ jsx3(
|
|
422
354
|
SelectProvider,
|
|
423
355
|
{
|
|
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
|
-
|
|
356
|
+
value: {
|
|
357
|
+
highlightedIndex,
|
|
358
|
+
getItemProps,
|
|
359
|
+
selectedItems,
|
|
360
|
+
isMulti: !!isMulti
|
|
361
|
+
},
|
|
362
|
+
children: /* @__PURE__ */ jsxs(
|
|
363
|
+
Box,
|
|
364
|
+
{
|
|
365
|
+
dataTestId: dataTestId != null ? dataTestId : "select",
|
|
366
|
+
style: { alignItems: "start", gap: 4 },
|
|
367
|
+
children: [
|
|
368
|
+
/* @__PURE__ */ jsxs(SelectStyled, { style, children: [
|
|
369
|
+
/* @__PURE__ */ jsx3(
|
|
370
|
+
LabelField,
|
|
371
|
+
__spreadProps(__spreadValues(__spreadProps(__spreadValues({}, getLabelProps()), {
|
|
372
|
+
hasError,
|
|
373
|
+
icon: labelIcon,
|
|
374
|
+
isActive: isFloatingLabel ? hasSelectedItems : isOpen,
|
|
375
|
+
isCentered: true,
|
|
376
|
+
isDisabled: disabled,
|
|
377
|
+
isFloating: isFloatingLabel,
|
|
378
|
+
isRequired,
|
|
379
|
+
scale
|
|
380
|
+
}), isFloatingLabel && {
|
|
381
|
+
style: { pointerEvents: "none" }
|
|
382
|
+
}), {
|
|
383
|
+
children: label
|
|
384
|
+
})
|
|
385
|
+
),
|
|
386
|
+
/* @__PURE__ */ jsxs(
|
|
387
|
+
SelectContainerStyled,
|
|
388
|
+
__spreadProps(__spreadValues(__spreadValues(__spreadValues({}, toggleProps), !!helperText && { "aria-describedby": helperTextId }), hasError && { "aria-invalid": hasError }), {
|
|
389
|
+
"data-testid": "select-container",
|
|
390
|
+
fill,
|
|
391
|
+
isOpen,
|
|
392
|
+
scale,
|
|
393
|
+
variant,
|
|
394
|
+
children: [
|
|
395
|
+
/* @__PURE__ */ jsx3(
|
|
396
|
+
TypographyValueStyled,
|
|
397
|
+
__spreadProps(__spreadValues({
|
|
398
|
+
color: "content.default",
|
|
399
|
+
dataTestId: "select-value",
|
|
400
|
+
element: "span",
|
|
401
|
+
fontStyles: "bodyMdRegular",
|
|
402
|
+
isFloatingLabel,
|
|
403
|
+
scale
|
|
404
|
+
}, disabled && { color: "content.light" }), {
|
|
405
|
+
children: selectedValueContainerText()
|
|
406
|
+
})
|
|
407
|
+
),
|
|
408
|
+
/* @__PURE__ */ jsxs(
|
|
409
|
+
SelectActionContainerStyled,
|
|
410
|
+
{
|
|
411
|
+
hasItems: hasSelectedItems,
|
|
412
|
+
isFloatingLabel,
|
|
413
|
+
scale,
|
|
414
|
+
children: [
|
|
415
|
+
isMulti && hasSelectedItems ? /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
416
|
+
/* @__PURE__ */ jsx3(
|
|
417
|
+
IconButton,
|
|
418
|
+
{
|
|
419
|
+
dataTestId: "clear-selection",
|
|
420
|
+
onClick: handleClearSelection,
|
|
421
|
+
onKeyDown: handleClearKeyDown,
|
|
422
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
423
|
+
children: /* @__PURE__ */ jsx3(Icon, { code: "close_small" })
|
|
424
|
+
}
|
|
425
|
+
),
|
|
426
|
+
/* @__PURE__ */ jsx3(Tooltip.Content, { children: "Clear all" })
|
|
427
|
+
] }) : null,
|
|
428
|
+
/* @__PURE__ */ jsx3(Icon, { code: isOpen ? "expand_less" : "expand_more" })
|
|
429
|
+
]
|
|
430
|
+
}
|
|
431
|
+
)
|
|
432
|
+
]
|
|
433
|
+
})
|
|
434
|
+
)
|
|
435
|
+
] }),
|
|
436
|
+
helperText ? /* @__PURE__ */ jsx3(
|
|
437
|
+
TypographyHelperTextStyled,
|
|
438
|
+
{
|
|
439
|
+
color: isDisabled ? "content.light" : hasError ? "error.default" : "content.medium",
|
|
440
|
+
dataTestId: "select-helper-text",
|
|
441
|
+
element: "span",
|
|
442
|
+
fontStyles: "bodySmRegular",
|
|
443
|
+
id: helperTextId,
|
|
444
|
+
children: helperText
|
|
445
|
+
}
|
|
446
|
+
) : null,
|
|
447
|
+
/* @__PURE__ */ jsx3(
|
|
448
|
+
Dropdown2,
|
|
449
|
+
__spreadProps(__spreadValues({}, getMenuProps()), {
|
|
450
|
+
anchorRef,
|
|
451
|
+
"aria-multiselectable": isMulti,
|
|
452
|
+
as: "ul",
|
|
453
|
+
isOpen,
|
|
454
|
+
onClose: closeMenu,
|
|
455
|
+
style: { maxHeight: 200 },
|
|
456
|
+
children
|
|
457
|
+
})
|
|
458
|
+
)
|
|
459
|
+
]
|
|
460
|
+
}
|
|
461
|
+
)
|
|
477
462
|
}
|
|
478
463
|
);
|
|
479
464
|
};
|