@dt-dds/react-dropdown 1.0.0-beta.67 → 1.0.0-beta.69
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 +30 -0
- package/README.md +28 -55
- package/dist/index.d.mts +18 -59
- package/dist/index.d.ts +18 -59
- package/dist/index.js +303 -384
- package/dist/index.mjs +303 -379
- package/package.json +11 -7
package/dist/index.mjs
CHANGED
|
@@ -1,413 +1,337 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
dataTestId,
|
|
17
|
-
isDisabled = false,
|
|
18
|
-
hasError = false,
|
|
19
|
-
children = ""
|
|
20
|
-
}) => {
|
|
21
|
-
const messageColor = isDisabled ? "content.light" : "content.medium";
|
|
22
|
-
return /* @__PURE__ */ jsx(DropdownDetailStyled, { "data-testid": dataTestId != null ? dataTestId : "dropdown-text", children: /* @__PURE__ */ jsx(
|
|
23
|
-
Typography,
|
|
24
|
-
{
|
|
25
|
-
color: hasError ? "error.default" : messageColor,
|
|
26
|
-
element: "span",
|
|
27
|
-
fontStyles: "bodySmRegular",
|
|
28
|
-
children
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
29
16
|
}
|
|
30
|
-
|
|
17
|
+
return a;
|
|
31
18
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
state: {
|
|
43
|
-
text: "",
|
|
44
|
-
value: ""
|
|
45
|
-
},
|
|
46
|
-
isOpen: false,
|
|
47
|
-
setState: () => null,
|
|
48
|
-
setIsOpen: () => null
|
|
49
|
-
};
|
|
50
|
-
var DropdownContext = createContext(DEFAULT_VALUE);
|
|
51
|
-
var DropdownContextProvider = ({
|
|
52
|
-
children,
|
|
53
|
-
defaultValue,
|
|
54
|
-
name
|
|
55
|
-
}) => {
|
|
56
|
-
const [state, setState] = useState(defaultValue != null ? defaultValue : DEFAULT_VALUE.state);
|
|
57
|
-
const [isOpen, setIsOpen] = useState(DEFAULT_VALUE.isOpen);
|
|
58
|
-
useEffect(() => defaultValue && setState(defaultValue), [defaultValue]);
|
|
59
|
-
return /* @__PURE__ */ jsx2(
|
|
60
|
-
DropdownContext.Provider,
|
|
61
|
-
{
|
|
62
|
-
value: {
|
|
63
|
-
state,
|
|
64
|
-
setState,
|
|
65
|
-
isOpen,
|
|
66
|
-
setIsOpen,
|
|
67
|
-
name
|
|
68
|
-
},
|
|
69
|
-
children
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
70
29
|
}
|
|
71
|
-
|
|
72
|
-
};
|
|
73
|
-
var useDropdownContext = () => {
|
|
74
|
-
const context = useContext(DropdownContext);
|
|
75
|
-
if (!context) {
|
|
76
|
-
throw new Error(
|
|
77
|
-
"Dropdown compound components cannot be rendered outside the Dropdown component"
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
return context;
|
|
30
|
+
return target;
|
|
81
31
|
};
|
|
82
32
|
|
|
33
|
+
// src/Dropdown.tsx
|
|
34
|
+
import { Portal, useClickOutside } from "@dt-dds/react-core";
|
|
35
|
+
import { forwardRef as forwardRef2, useCallback, useRef } from "react";
|
|
36
|
+
|
|
37
|
+
// src/components/option/DropdownOption.tsx
|
|
38
|
+
import { forwardRef } from "react";
|
|
39
|
+
|
|
83
40
|
// src/components/option/DropdownOption.styled.ts
|
|
84
|
-
import
|
|
85
|
-
var DropdownOptionStyled =
|
|
86
|
-
${({ theme
|
|
87
|
-
${theme.fontStyles
|
|
41
|
+
import styled from "@emotion/styled";
|
|
42
|
+
var DropdownOptionStyled = styled.li`
|
|
43
|
+
${({ theme }) => `
|
|
44
|
+
${theme.fontStyles.bodyMdRegular};
|
|
45
|
+
|
|
88
46
|
color: ${theme.palette.content.default};
|
|
47
|
+
padding: ${theme.spacing.spacing_40} ${theme.spacing.spacing_50};
|
|
89
48
|
list-style: none;
|
|
90
|
-
padding: ${theme.spacing.spacing_30} ${theme.spacing.spacing_50};
|
|
91
49
|
text-overflow: ellipsis;
|
|
92
50
|
overflow-x: hidden;
|
|
51
|
+
text-wrap: nowrap;
|
|
93
52
|
|
|
94
|
-
&:
|
|
95
|
-
|
|
96
|
-
|
|
53
|
+
&:not([aria-disabled="true"]) {
|
|
54
|
+
&[aria-selected="true"], &[aria-selected="true"] span {
|
|
55
|
+
${theme.fontStyles.bodyMdBold};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&:hover, &[data-highlighted="true"] {
|
|
59
|
+
background: ${theme.palette.accent.light};
|
|
60
|
+
cursor: pointer;
|
|
61
|
+
}
|
|
97
62
|
}
|
|
98
63
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
64
|
+
&[aria-disabled="true"] {
|
|
65
|
+
color: ${theme.palette.content.light};
|
|
66
|
+
cursor: not-allowed;
|
|
67
|
+
|
|
68
|
+
&[aria-selected="true"] {
|
|
69
|
+
background-color: ${theme.palette.surface.light};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
103
72
|
`}
|
|
104
73
|
`;
|
|
105
74
|
|
|
106
75
|
// src/components/option/DropdownOption.tsx
|
|
107
|
-
import { jsx
|
|
108
|
-
var DropdownOption = (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
isDisabled,
|
|
114
|
-
onClick
|
|
115
|
-
}) => {
|
|
116
|
-
var _a;
|
|
117
|
-
const { state, setState, setIsOpen, name } = useDropdownContext();
|
|
118
|
-
const testId = dataTestId != null ? dataTestId : `dropdown-option-${option.value}`;
|
|
119
|
-
const value = {
|
|
120
|
-
text: (_a = option.text) != null ? _a : option.value,
|
|
121
|
-
value: option.value
|
|
122
|
-
};
|
|
123
|
-
const handleClick = (event) => {
|
|
124
|
-
if (isDisabled) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
setIsOpen(false);
|
|
128
|
-
setState(value);
|
|
129
|
-
onClick && onClick(option.value, name, event);
|
|
130
|
-
};
|
|
131
|
-
return /* @__PURE__ */ jsx3(
|
|
132
|
-
DropdownOptionStyled,
|
|
133
|
-
{
|
|
134
|
-
"data-testid": testId,
|
|
135
|
-
disabled: isDisabled,
|
|
136
|
-
isSelected: state.value === option.value,
|
|
137
|
-
onClick: handleClick,
|
|
138
|
-
role: "option",
|
|
76
|
+
import { jsx } from "react/jsx-runtime";
|
|
77
|
+
var DropdownOption = forwardRef(
|
|
78
|
+
(_a, ref) => {
|
|
79
|
+
var _b = _a, {
|
|
80
|
+
dataTestId,
|
|
81
|
+
children,
|
|
139
82
|
style,
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
83
|
+
isDisabled,
|
|
84
|
+
isSelected = false,
|
|
85
|
+
isHighlighted = false,
|
|
86
|
+
onClick
|
|
87
|
+
} = _b, rest = __objRest(_b, [
|
|
88
|
+
"dataTestId",
|
|
89
|
+
"children",
|
|
90
|
+
"style",
|
|
91
|
+
"isDisabled",
|
|
92
|
+
"isSelected",
|
|
93
|
+
"isHighlighted",
|
|
94
|
+
"onClick"
|
|
95
|
+
]);
|
|
96
|
+
const testId = dataTestId != null ? dataTestId : "dropdown-option";
|
|
97
|
+
const handleClick = (e) => {
|
|
98
|
+
if (isDisabled) {
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
e.stopPropagation();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
onClick == null ? void 0 : onClick(e);
|
|
104
|
+
};
|
|
105
|
+
return /* @__PURE__ */ jsx(
|
|
106
|
+
DropdownOptionStyled,
|
|
107
|
+
__spreadProps(__spreadValues({}, rest), {
|
|
108
|
+
"aria-disabled": isDisabled,
|
|
109
|
+
"aria-selected": isSelected,
|
|
110
|
+
"data-highlighted": isHighlighted,
|
|
111
|
+
"data-testid": testId,
|
|
112
|
+
onClick: handleClick,
|
|
113
|
+
ref,
|
|
114
|
+
style,
|
|
115
|
+
children
|
|
116
|
+
})
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
);
|
|
145
120
|
|
|
146
|
-
// src/
|
|
147
|
-
import
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
import { Children, useEffect as useEffect2 } from "react";
|
|
121
|
+
// src/Dropdown.styled.ts
|
|
122
|
+
import styled2 from "@emotion/styled";
|
|
123
|
+
var DropdownStyled = styled2.div`
|
|
124
|
+
list-style-type: none;
|
|
125
|
+
width: 100%;
|
|
126
|
+
overflow: auto;
|
|
153
127
|
|
|
154
|
-
// src/components/menu/DropdownMenu.styled.ts
|
|
155
|
-
import { DROPDOWN_MENU_Z_INDEX } from "@dt-dds/react-core";
|
|
156
|
-
import styled3 from "@emotion/styled";
|
|
157
|
-
var DropdownMenuStyled = styled3.ul`
|
|
158
128
|
${({ theme }) => `
|
|
159
|
-
|
|
160
|
-
|
|
129
|
+
padding: ${theme.spacing.spacing_50} ${theme.spacing.spacing_0};
|
|
130
|
+
background-color: ${theme.palette.surface.contrast};
|
|
161
131
|
border-radius: ${theme.shape.dropdown};
|
|
162
|
-
|
|
163
|
-
padding:${theme.spacing.spacing_50} ${theme.spacing.spacing_0};
|
|
164
|
-
margin: ${theme.spacing.spacing_20} ${theme.spacing.spacing_0};
|
|
165
|
-
position: absolute;
|
|
166
|
-
right: 0;
|
|
167
|
-
z-index: ${DROPDOWN_MENU_Z_INDEX};
|
|
168
|
-
max-height: 180px;
|
|
169
|
-
overflow: auto;
|
|
132
|
+
border: 1px solid ${theme.palette.border.medium};
|
|
170
133
|
`}
|
|
171
134
|
`;
|
|
172
135
|
|
|
173
|
-
// src/
|
|
174
|
-
import {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
border-width: ${variant === "outlined" ? "1px" : "0 0 1px"};
|
|
221
|
-
border-color: ${isOpen ? activeBorderColor : borderColor};
|
|
222
|
-
border-style: solid;
|
|
223
|
-
|
|
224
|
-
&:focus, &:hover {
|
|
225
|
-
border-color: ${hasError ? errorBorderColor : activeBorderColor};
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
${hasError && `border-color: ${errorBorderColor}`};
|
|
229
|
-
${!hasBorder && "border: none"};
|
|
230
|
-
|
|
231
|
-
&:disabled {
|
|
232
|
-
pointer-events: none;
|
|
233
|
-
}
|
|
234
|
-
`;
|
|
235
|
-
}}
|
|
236
|
-
`;
|
|
237
|
-
|
|
238
|
-
// src/components/select/DropdownSelect.tsx
|
|
239
|
-
import { Fragment, jsx as jsx5, jsxs } from "react/jsx-runtime";
|
|
240
|
-
var DropdownSelect = ({
|
|
241
|
-
children,
|
|
242
|
-
label,
|
|
243
|
-
style,
|
|
244
|
-
dataTestId = "dropdown-select",
|
|
245
|
-
isDisabled = false,
|
|
246
|
-
isRequired,
|
|
247
|
-
hasBorder = true,
|
|
248
|
-
hasError = false,
|
|
249
|
-
hasDeselect = false,
|
|
250
|
-
variant = "outlined",
|
|
251
|
-
fill = "default"
|
|
252
|
-
}) => {
|
|
253
|
-
const { state, setState, isOpen, setIsOpen } = useDropdownContext();
|
|
254
|
-
const theme = useTheme();
|
|
255
|
-
const childCount = Children.count(children);
|
|
256
|
-
const hasOneChild = childCount === 1;
|
|
257
|
-
const disabled = isDisabled || hasOneChild;
|
|
258
|
-
const disabledIconColor = disabled ? theme.palette.content.light : theme.palette.content.default;
|
|
259
|
-
const handleClick = (event) => {
|
|
260
|
-
event.preventDefault();
|
|
261
|
-
setIsOpen((prev) => !prev);
|
|
262
|
-
};
|
|
263
|
-
const handleDeselectClick = (event) => {
|
|
264
|
-
event.stopPropagation();
|
|
265
|
-
setState({ text: "", value: "" });
|
|
266
|
-
};
|
|
267
|
-
useEffect2(() => {
|
|
268
|
-
const hasOption = Children.toArray(children).find(
|
|
269
|
-
(child) => child.props.option.value === state.value
|
|
270
|
-
);
|
|
271
|
-
if (!hasOption) {
|
|
272
|
-
setState({ text: "", value: "" });
|
|
136
|
+
// src/hooks/useFloatingPosition.ts
|
|
137
|
+
import { DROPDOWN_MENU_Z_INDEX } from "@dt-dds/react-core";
|
|
138
|
+
import { useLayoutEffect, useState } from "react";
|
|
139
|
+
function basePos({
|
|
140
|
+
placement,
|
|
141
|
+
anchor,
|
|
142
|
+
menuWidth,
|
|
143
|
+
menuHeight,
|
|
144
|
+
offsetX,
|
|
145
|
+
offsetY
|
|
146
|
+
}) {
|
|
147
|
+
switch (placement) {
|
|
148
|
+
case "bottom":
|
|
149
|
+
return { top: anchor.bottom + offsetY, left: anchor.left + offsetX };
|
|
150
|
+
case "top":
|
|
151
|
+
return {
|
|
152
|
+
top: anchor.top - offsetY - menuHeight,
|
|
153
|
+
left: anchor.left + offsetX
|
|
154
|
+
};
|
|
155
|
+
case "right":
|
|
156
|
+
return { top: anchor.top + offsetY, left: anchor.right + offsetX };
|
|
157
|
+
case "left":
|
|
158
|
+
return {
|
|
159
|
+
top: anchor.top + offsetY,
|
|
160
|
+
left: anchor.left - offsetX - menuWidth
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function useFloatingPosition(anchorEl, open, {
|
|
165
|
+
offsetX = 0,
|
|
166
|
+
offsetY = 4,
|
|
167
|
+
matchWidth = true,
|
|
168
|
+
minViewportPadding = 8,
|
|
169
|
+
placement = "bottom",
|
|
170
|
+
menuRef
|
|
171
|
+
} = {}) {
|
|
172
|
+
const [style, setStyle] = useState({
|
|
173
|
+
visibility: "hidden",
|
|
174
|
+
position: "fixed"
|
|
175
|
+
});
|
|
176
|
+
useLayoutEffect(() => {
|
|
177
|
+
if (!open || !(anchorEl == null ? void 0 : anchorEl.current)) {
|
|
178
|
+
setStyle({
|
|
179
|
+
visibility: "hidden",
|
|
180
|
+
position: "fixed"
|
|
181
|
+
});
|
|
182
|
+
return;
|
|
273
183
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
184
|
+
const anchorElement = anchorEl == null ? void 0 : anchorEl.current;
|
|
185
|
+
const menuElement = menuRef == null ? void 0 : menuRef.current;
|
|
186
|
+
const updatePosition = () => {
|
|
187
|
+
var _a, _b;
|
|
188
|
+
const vw = window.innerWidth;
|
|
189
|
+
const vh = window.innerHeight;
|
|
190
|
+
const anchor = anchorElement.getBoundingClientRect();
|
|
191
|
+
const menuRect = menuElement == null ? void 0 : menuElement.getBoundingClientRect();
|
|
192
|
+
const menuWidth = matchWidth ? anchor.width : (_a = menuRect == null ? void 0 : menuRect.width) != null ? _a : anchor.width;
|
|
193
|
+
const menuHeight = (_b = menuRect == null ? void 0 : menuRect.height) != null ? _b : 0;
|
|
194
|
+
let { top, left } = basePos({
|
|
195
|
+
placement,
|
|
196
|
+
anchor,
|
|
197
|
+
menuWidth,
|
|
198
|
+
menuHeight,
|
|
199
|
+
offsetX,
|
|
200
|
+
offsetY
|
|
201
|
+
});
|
|
202
|
+
const maxLeft = Math.max(
|
|
203
|
+
minViewportPadding,
|
|
204
|
+
vw - menuWidth - minViewportPadding
|
|
281
205
|
);
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
206
|
+
const maxTop = Math.max(
|
|
207
|
+
minViewportPadding,
|
|
208
|
+
vh - menuHeight - minViewportPadding
|
|
209
|
+
);
|
|
210
|
+
left = Math.max(minViewportPadding, Math.min(left, maxLeft));
|
|
211
|
+
top = Math.max(minViewportPadding, Math.min(top, maxTop));
|
|
212
|
+
setStyle({
|
|
213
|
+
position: "fixed",
|
|
214
|
+
top,
|
|
215
|
+
left,
|
|
216
|
+
width: matchWidth ? anchor.width : void 0,
|
|
217
|
+
maxWidth: matchWidth ? anchor.width : 300,
|
|
218
|
+
boxSizing: "border-box",
|
|
219
|
+
zIndex: DROPDOWN_MENU_Z_INDEX
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
updatePosition();
|
|
223
|
+
const ro = new ResizeObserver(updatePosition);
|
|
224
|
+
ro.observe(anchorElement);
|
|
225
|
+
if (anchorElement) {
|
|
226
|
+
ro.observe(anchorElement);
|
|
289
227
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
fontStyles: "bodySmRegular",
|
|
311
|
-
children: [
|
|
312
|
-
label,
|
|
313
|
-
isRequired ? /* @__PURE__ */ jsx5(
|
|
314
|
-
Typography2,
|
|
315
|
-
{
|
|
316
|
-
color: "error.default",
|
|
317
|
-
element: "span",
|
|
318
|
-
fontStyles: "bodySmRegular",
|
|
319
|
-
children: "*"
|
|
320
|
-
}
|
|
321
|
-
) : null
|
|
322
|
-
]
|
|
323
|
-
}
|
|
324
|
-
),
|
|
325
|
-
/* @__PURE__ */ jsx5(
|
|
326
|
-
Typography2,
|
|
327
|
-
{
|
|
328
|
-
color: disabled ? "content.light" : "content.default",
|
|
329
|
-
fontStyles: "bodyMdRegular",
|
|
330
|
-
style: { textOverflow: "ellipsis", overflow: "hidden" },
|
|
331
|
-
children: !state.value ? "Select an option" : state.text
|
|
332
|
-
}
|
|
333
|
-
)
|
|
334
|
-
] }),
|
|
335
|
-
/* @__PURE__ */ jsxs(Box, { style: { flexDirection: "row", gap: "0.5rem" }, children: [
|
|
336
|
-
hasDeselect && !!state.value ? /* @__PURE__ */ jsx5(IconButton, { onClick: handleDeselectClick, children: /* @__PURE__ */ jsx5(
|
|
337
|
-
Icon,
|
|
338
|
-
{
|
|
339
|
-
code: "close",
|
|
340
|
-
color: disabledIconColor,
|
|
341
|
-
dataTestId: "deselect-value",
|
|
342
|
-
size: "s"
|
|
343
|
-
}
|
|
344
|
-
) }) : null,
|
|
345
|
-
/* @__PURE__ */ jsx5(
|
|
346
|
-
Icon,
|
|
347
|
-
{
|
|
348
|
-
code: isOpen ? "expand_less" : "expand_more",
|
|
349
|
-
color: disabledIconColor,
|
|
350
|
-
size: "l"
|
|
351
|
-
}
|
|
352
|
-
)
|
|
353
|
-
] })
|
|
354
|
-
]
|
|
355
|
-
}
|
|
356
|
-
),
|
|
357
|
-
isOpen ? /* @__PURE__ */ jsx5(DropdownMenu, { dataTestId, children }) : null
|
|
358
|
-
] });
|
|
359
|
-
};
|
|
228
|
+
const opts = { passive: true };
|
|
229
|
+
window.addEventListener("scroll", updatePosition, opts);
|
|
230
|
+
window.addEventListener("resize", updatePosition, opts);
|
|
231
|
+
return () => {
|
|
232
|
+
ro.disconnect();
|
|
233
|
+
window.removeEventListener("scroll", updatePosition, opts);
|
|
234
|
+
window.removeEventListener("resize", updatePosition, opts);
|
|
235
|
+
};
|
|
236
|
+
}, [
|
|
237
|
+
menuRef,
|
|
238
|
+
anchorEl,
|
|
239
|
+
open,
|
|
240
|
+
placement,
|
|
241
|
+
offsetX,
|
|
242
|
+
offsetY,
|
|
243
|
+
matchWidth,
|
|
244
|
+
minViewportPadding
|
|
245
|
+
]);
|
|
246
|
+
return { style };
|
|
247
|
+
}
|
|
360
248
|
|
|
361
|
-
// src/
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
const ref = useRef(null);
|
|
372
|
-
useClickOutside({ ref, handler: () => setIsOpen(false) });
|
|
373
|
-
return /* @__PURE__ */ jsx6("div", { "data-testid": dataTestId, ref, style, children });
|
|
249
|
+
// src/utils/set-ref.ts
|
|
250
|
+
var setRef = (target, node) => {
|
|
251
|
+
if (!target) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
if (typeof target === "function") {
|
|
255
|
+
target(node);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
target.current = node;
|
|
374
259
|
};
|
|
375
260
|
|
|
376
|
-
// src/Dropdown.styled.ts
|
|
377
|
-
import styled5 from "@emotion/styled";
|
|
378
|
-
var DropdownStyled = styled5.div`
|
|
379
|
-
${({ theme, style }) => `
|
|
380
|
-
margin: ${theme.spacing.spacing_0};
|
|
381
|
-
display: inline-block;
|
|
382
|
-
position: relative;
|
|
383
|
-
width: 100%;
|
|
384
|
-
${style}
|
|
385
|
-
`}
|
|
386
|
-
`;
|
|
387
|
-
|
|
388
261
|
// src/Dropdown.tsx
|
|
389
|
-
import { jsx as
|
|
390
|
-
var Dropdown = (
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
262
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
263
|
+
var Dropdown = Object.assign(
|
|
264
|
+
forwardRef2(
|
|
265
|
+
(_a, forwardedRef) => {
|
|
266
|
+
var _b = _a, {
|
|
267
|
+
children,
|
|
268
|
+
style,
|
|
269
|
+
dataTestId = "dropdown",
|
|
270
|
+
isOpen = false,
|
|
271
|
+
anchorRef,
|
|
272
|
+
matchWidth = true,
|
|
273
|
+
offsetX,
|
|
274
|
+
offsetY,
|
|
275
|
+
as = "div",
|
|
276
|
+
onClose,
|
|
277
|
+
placement
|
|
278
|
+
} = _b, rest = __objRest(_b, [
|
|
279
|
+
"children",
|
|
280
|
+
"style",
|
|
281
|
+
"dataTestId",
|
|
282
|
+
"isOpen",
|
|
283
|
+
"anchorRef",
|
|
284
|
+
"matchWidth",
|
|
285
|
+
"offsetX",
|
|
286
|
+
"offsetY",
|
|
287
|
+
"as",
|
|
288
|
+
"onClose",
|
|
289
|
+
"placement"
|
|
290
|
+
]);
|
|
291
|
+
const localMenuRef = useRef(null);
|
|
292
|
+
const setMenuRef = useCallback(
|
|
293
|
+
(node) => {
|
|
294
|
+
localMenuRef.current = node;
|
|
295
|
+
setRef(forwardedRef, node);
|
|
296
|
+
},
|
|
297
|
+
[forwardedRef]
|
|
298
|
+
);
|
|
299
|
+
const { style: floatingStyle } = useFloatingPosition(
|
|
300
|
+
anchorRef,
|
|
301
|
+
isOpen,
|
|
302
|
+
{
|
|
303
|
+
matchWidth,
|
|
304
|
+
offsetX,
|
|
305
|
+
offsetY,
|
|
306
|
+
placement,
|
|
307
|
+
menuRef: localMenuRef
|
|
308
|
+
}
|
|
309
|
+
);
|
|
310
|
+
useClickOutside({
|
|
311
|
+
refs: [localMenuRef, anchorRef],
|
|
312
|
+
handler: () => onClose == null ? void 0 : onClose()
|
|
313
|
+
});
|
|
314
|
+
return /* @__PURE__ */ jsx2(Portal, { isOpen: true, children: /* @__PURE__ */ jsx2(
|
|
315
|
+
DropdownStyled,
|
|
316
|
+
__spreadProps(__spreadValues({
|
|
317
|
+
as,
|
|
318
|
+
"data-testid": dataTestId,
|
|
319
|
+
ref: setMenuRef,
|
|
320
|
+
role: "menu",
|
|
321
|
+
style: __spreadValues(__spreadValues({}, floatingStyle), style)
|
|
322
|
+
}, rest), {
|
|
323
|
+
"aria-hidden": !isOpen,
|
|
324
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
325
|
+
children
|
|
326
|
+
})
|
|
327
|
+
) });
|
|
328
|
+
}
|
|
329
|
+
),
|
|
330
|
+
{
|
|
331
|
+
Option: DropdownOption
|
|
332
|
+
}
|
|
333
|
+
);
|
|
403
334
|
export {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
DropdownContext,
|
|
407
|
-
DropdownContextProvider,
|
|
408
|
-
DropdownDetail,
|
|
409
|
-
DropdownMenu,
|
|
410
|
-
DropdownOption,
|
|
411
|
-
DropdownSelect,
|
|
412
|
-
useDropdownContext
|
|
335
|
+
Dropdown,
|
|
336
|
+
DropdownOption
|
|
413
337
|
};
|