@xsolla/xui-multi-select 0.171.2 → 0.171.3-pr330.1781564486
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/native/index.js +116 -84
- package/native/index.js.map +1 -1
- package/native/index.mjs +116 -84
- package/native/index.mjs.map +1 -1
- package/package.json +6 -5
- package/web/index.js +121 -83
- package/web/index.js.map +1 -1
- package/web/index.mjs +119 -81
- package/web/index.mjs.map +1 -1
package/web/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/MultiSelect.tsx
|
|
2
|
-
import { forwardRef as forwardRef4, useRef as useRef4, useEffect as
|
|
2
|
+
import { forwardRef as forwardRef4, useRef as useRef4, useEffect as useEffect4, useState as useState4, useCallback as useCallback2 } from "react";
|
|
3
3
|
|
|
4
4
|
// ../../foundation/primitives-web/src/Box.tsx
|
|
5
5
|
import React2 from "react";
|
|
@@ -317,8 +317,11 @@ var Icon = ({
|
|
|
317
317
|
return /* @__PURE__ */ jsx3(StyledIcon, { "data-testid": dataTestId || testID, ...props, children });
|
|
318
318
|
};
|
|
319
319
|
|
|
320
|
+
// ../../foundation/primitives-web/src/index.tsx
|
|
321
|
+
var isWeb = true;
|
|
322
|
+
|
|
320
323
|
// src/MultiSelect.tsx
|
|
321
|
-
import { useResolvedTheme as useResolvedTheme4 } from "@xsolla/xui-core";
|
|
324
|
+
import { useModalId, useResolvedTheme as useResolvedTheme4 } from "@xsolla/xui-core";
|
|
322
325
|
|
|
323
326
|
// src/MultiSelectControl.tsx
|
|
324
327
|
import { forwardRef as forwardRef3, useRef as useRef2 } from "react";
|
|
@@ -2190,6 +2193,16 @@ var useMultiSelect = ({
|
|
|
2190
2193
|
};
|
|
2191
2194
|
};
|
|
2192
2195
|
|
|
2196
|
+
// src/Portal.web.tsx
|
|
2197
|
+
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
2198
|
+
import { createPortal } from "react-dom";
|
|
2199
|
+
var Portal = ({ children }) => {
|
|
2200
|
+
const [mountNode, setMountNode] = useState3(null);
|
|
2201
|
+
useEffect3(() => setMountNode(document.body), []);
|
|
2202
|
+
if (!mountNode) return null;
|
|
2203
|
+
return createPortal(children, mountNode);
|
|
2204
|
+
};
|
|
2205
|
+
|
|
2193
2206
|
// src/MultiSelect.tsx
|
|
2194
2207
|
import { Fragment, jsx as jsx726, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
2195
2208
|
var EXTERNAL_MENU_MIN_WIDTH_DEFAULT = 540;
|
|
@@ -2220,8 +2233,10 @@ var MultiSelect = forwardRef4(
|
|
|
2220
2233
|
themeProductContext
|
|
2221
2234
|
}, ref) => {
|
|
2222
2235
|
const { theme } = useResolvedTheme4({ themeMode, themeProductContext });
|
|
2236
|
+
const modalId = useModalId();
|
|
2223
2237
|
const controlRef = useRef4(null);
|
|
2224
2238
|
const menuRef = useRef4(null);
|
|
2239
|
+
const [menuPosition, setMenuPosition] = useState4(null);
|
|
2225
2240
|
const sizeStyles = theme.sizing.input(size);
|
|
2226
2241
|
const state = externalState || (disabled ? "disable" : "default");
|
|
2227
2242
|
const isDisable = state === "disable" || disabled;
|
|
@@ -2242,7 +2257,7 @@ var MultiSelect = forwardRef4(
|
|
|
2242
2257
|
value,
|
|
2243
2258
|
onChange
|
|
2244
2259
|
});
|
|
2245
|
-
|
|
2260
|
+
useEffect4(() => {
|
|
2246
2261
|
if (isDisable || !dropdownMenu) {
|
|
2247
2262
|
onClose();
|
|
2248
2263
|
}
|
|
@@ -2265,11 +2280,111 @@ var MultiSelect = forwardRef4(
|
|
|
2265
2280
|
};
|
|
2266
2281
|
const controlMenuOpen = dropdownMenu ? isOpen : Boolean(menuOpen);
|
|
2267
2282
|
const controlOnClick = dropdownMenu ? onSelectClick : onTriggerPress;
|
|
2283
|
+
const updateMenuPosition = useCallback2(() => {
|
|
2284
|
+
if (!isWeb || !controlRef.current) return;
|
|
2285
|
+
const rect = controlRef.current.getBoundingClientRect();
|
|
2286
|
+
setMenuPosition({
|
|
2287
|
+
left: rect.left,
|
|
2288
|
+
top: rect.bottom + 4,
|
|
2289
|
+
width: rect.width
|
|
2290
|
+
});
|
|
2291
|
+
}, []);
|
|
2292
|
+
useEffect4(() => {
|
|
2293
|
+
if (!isWeb || !controlMenuOpen || isDisable || !dropdownMenu) return;
|
|
2294
|
+
updateMenuPosition();
|
|
2295
|
+
window.addEventListener("resize", updateMenuPosition);
|
|
2296
|
+
window.addEventListener("scroll", updateMenuPosition, true);
|
|
2297
|
+
return () => {
|
|
2298
|
+
window.removeEventListener("resize", updateMenuPosition);
|
|
2299
|
+
window.removeEventListener("scroll", updateMenuPosition, true);
|
|
2300
|
+
};
|
|
2301
|
+
}, [controlMenuOpen, dropdownMenu, isDisable, updateMenuPosition]);
|
|
2268
2302
|
const externalFieldLayout = !dropdownMenu ? {
|
|
2269
2303
|
width: "100%",
|
|
2270
2304
|
minWidth: menuMinWidth ?? EXTERNAL_MENU_MIN_WIDTH_DEFAULT,
|
|
2271
2305
|
boxSizing: "border-box"
|
|
2272
2306
|
} : void 0;
|
|
2307
|
+
const dropdown = dropdownMenu && isOpen && !isDisable && (!isWeb || menuPosition) && /* @__PURE__ */ jsxs4(Fragment, { children: [
|
|
2308
|
+
/* @__PURE__ */ jsx726(
|
|
2309
|
+
Box,
|
|
2310
|
+
{
|
|
2311
|
+
"data-modal-id": modalId,
|
|
2312
|
+
style: {
|
|
2313
|
+
position: "fixed",
|
|
2314
|
+
top: 0,
|
|
2315
|
+
left: 0,
|
|
2316
|
+
right: 0,
|
|
2317
|
+
bottom: 0,
|
|
2318
|
+
zIndex: 999,
|
|
2319
|
+
cursor: "default"
|
|
2320
|
+
},
|
|
2321
|
+
onPress: onClose
|
|
2322
|
+
}
|
|
2323
|
+
),
|
|
2324
|
+
/* @__PURE__ */ jsx726(
|
|
2325
|
+
Box,
|
|
2326
|
+
{
|
|
2327
|
+
ref: menuRef,
|
|
2328
|
+
"data-modal-id": modalId,
|
|
2329
|
+
backgroundColor: theme.colors.background.secondary,
|
|
2330
|
+
borderColor: theme.colors.border.secondary,
|
|
2331
|
+
borderWidth: 1,
|
|
2332
|
+
borderRadius: sizeStyles.radius,
|
|
2333
|
+
paddingVertical: 4,
|
|
2334
|
+
style: {
|
|
2335
|
+
position: isWeb ? "fixed" : "absolute",
|
|
2336
|
+
top: isWeb ? menuPosition?.top : "100%",
|
|
2337
|
+
left: isWeb ? menuPosition?.left : 0,
|
|
2338
|
+
right: isWeb ? void 0 : 0,
|
|
2339
|
+
width: isWeb ? menuPosition?.width : void 0,
|
|
2340
|
+
marginTop: isWeb ? void 0 : 4,
|
|
2341
|
+
zIndex: 1001,
|
|
2342
|
+
// Above control (1000) and backdrop (999)
|
|
2343
|
+
boxShadow: theme.shadow.popover,
|
|
2344
|
+
maxHeight,
|
|
2345
|
+
overflowY: "auto"
|
|
2346
|
+
},
|
|
2347
|
+
children: menuItems.map((item, _index) => {
|
|
2348
|
+
const brandColors = theme.colors.control.brand.primary;
|
|
2349
|
+
const contentColors = theme.colors.content;
|
|
2350
|
+
return /* @__PURE__ */ jsx726(
|
|
2351
|
+
Box,
|
|
2352
|
+
{
|
|
2353
|
+
testID,
|
|
2354
|
+
paddingHorizontal: sizeStyles.paddingHorizontal,
|
|
2355
|
+
paddingVertical: 8,
|
|
2356
|
+
onPress: () => {
|
|
2357
|
+
if (!item.disabled) {
|
|
2358
|
+
handleItemToggle(item.id, !item.checked);
|
|
2359
|
+
}
|
|
2360
|
+
},
|
|
2361
|
+
flexDirection: "row",
|
|
2362
|
+
alignItems: "center",
|
|
2363
|
+
justifyContent: "space-between",
|
|
2364
|
+
backgroundColor: item.checked ? brandColors.bg : "transparent",
|
|
2365
|
+
hoverStyle: !item.disabled && !item.checked ? {
|
|
2366
|
+
backgroundColor: theme.colors.control.input.bgHover
|
|
2367
|
+
} : void 0,
|
|
2368
|
+
style: {
|
|
2369
|
+
cursor: item.disabled ? "not-allowed" : "pointer",
|
|
2370
|
+
opacity: item.disabled ? 0.5 : 1
|
|
2371
|
+
},
|
|
2372
|
+
children: /* @__PURE__ */ jsx726(
|
|
2373
|
+
Text,
|
|
2374
|
+
{
|
|
2375
|
+
color: item.checked ? contentColors.on.brand : theme.colors.content.secondary,
|
|
2376
|
+
fontSize: sizeStyles.fontSize,
|
|
2377
|
+
fontWeight: "400",
|
|
2378
|
+
children: item.children
|
|
2379
|
+
}
|
|
2380
|
+
)
|
|
2381
|
+
},
|
|
2382
|
+
item.id
|
|
2383
|
+
);
|
|
2384
|
+
})
|
|
2385
|
+
}
|
|
2386
|
+
)
|
|
2387
|
+
] });
|
|
2273
2388
|
return /* @__PURE__ */ jsxs4(
|
|
2274
2389
|
Box,
|
|
2275
2390
|
{
|
|
@@ -2321,84 +2436,7 @@ var MultiSelect = forwardRef4(
|
|
|
2321
2436
|
extraClear
|
|
2322
2437
|
}
|
|
2323
2438
|
),
|
|
2324
|
-
|
|
2325
|
-
/* @__PURE__ */ jsx726(
|
|
2326
|
-
Box,
|
|
2327
|
-
{
|
|
2328
|
-
style: {
|
|
2329
|
-
position: "fixed",
|
|
2330
|
-
top: 0,
|
|
2331
|
-
left: 0,
|
|
2332
|
-
right: 0,
|
|
2333
|
-
bottom: 0,
|
|
2334
|
-
zIndex: 999,
|
|
2335
|
-
cursor: "default"
|
|
2336
|
-
},
|
|
2337
|
-
onPress: onClose
|
|
2338
|
-
}
|
|
2339
|
-
),
|
|
2340
|
-
/* @__PURE__ */ jsx726(
|
|
2341
|
-
Box,
|
|
2342
|
-
{
|
|
2343
|
-
ref: menuRef,
|
|
2344
|
-
backgroundColor: theme.colors.background.secondary,
|
|
2345
|
-
borderColor: theme.colors.border.secondary,
|
|
2346
|
-
borderWidth: 1,
|
|
2347
|
-
borderRadius: theme.shape.input[size].borderRadius,
|
|
2348
|
-
paddingVertical: 4,
|
|
2349
|
-
style: {
|
|
2350
|
-
position: "absolute",
|
|
2351
|
-
top: "100%",
|
|
2352
|
-
left: 0,
|
|
2353
|
-
right: 0,
|
|
2354
|
-
marginTop: 4,
|
|
2355
|
-
zIndex: 1001,
|
|
2356
|
-
// Above control (1000) and backdrop (999)
|
|
2357
|
-
boxShadow: theme.shadow.popover,
|
|
2358
|
-
maxHeight,
|
|
2359
|
-
overflowY: "auto"
|
|
2360
|
-
},
|
|
2361
|
-
children: menuItems.map((item, _index) => {
|
|
2362
|
-
const brandColors = theme.colors.control.brand.primary;
|
|
2363
|
-
const contentColors = theme.colors.content;
|
|
2364
|
-
return /* @__PURE__ */ jsx726(
|
|
2365
|
-
Box,
|
|
2366
|
-
{
|
|
2367
|
-
testID,
|
|
2368
|
-
paddingHorizontal: sizeStyles.paddingHorizontal,
|
|
2369
|
-
paddingVertical: 8,
|
|
2370
|
-
onPress: () => {
|
|
2371
|
-
if (!item.disabled) {
|
|
2372
|
-
handleItemToggle(item.id, !item.checked);
|
|
2373
|
-
}
|
|
2374
|
-
},
|
|
2375
|
-
flexDirection: "row",
|
|
2376
|
-
alignItems: "center",
|
|
2377
|
-
justifyContent: "space-between",
|
|
2378
|
-
backgroundColor: item.checked ? brandColors.bg : "transparent",
|
|
2379
|
-
hoverStyle: !item.disabled && !item.checked ? {
|
|
2380
|
-
backgroundColor: theme.colors.control.input.bgHover
|
|
2381
|
-
} : void 0,
|
|
2382
|
-
style: {
|
|
2383
|
-
cursor: item.disabled ? "not-allowed" : "pointer",
|
|
2384
|
-
opacity: item.disabled ? 0.5 : 1
|
|
2385
|
-
},
|
|
2386
|
-
children: /* @__PURE__ */ jsx726(
|
|
2387
|
-
Text,
|
|
2388
|
-
{
|
|
2389
|
-
color: item.checked ? contentColors.on.brand : theme.colors.content.secondary,
|
|
2390
|
-
fontSize: sizeStyles.fontSize,
|
|
2391
|
-
fontWeight: "400",
|
|
2392
|
-
children: item.children
|
|
2393
|
-
}
|
|
2394
|
-
)
|
|
2395
|
-
},
|
|
2396
|
-
item.id
|
|
2397
|
-
);
|
|
2398
|
-
})
|
|
2399
|
-
}
|
|
2400
|
-
)
|
|
2401
|
-
] })
|
|
2439
|
+
isWeb ? /* @__PURE__ */ jsx726(Portal, { children: dropdown }) : dropdown
|
|
2402
2440
|
]
|
|
2403
2441
|
}
|
|
2404
2442
|
),
|