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