@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.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/MultiSelect.tsx
2
- import { forwardRef as forwardRef4, useRef as useRef4, useEffect as useEffect3 } from "react";
2
+ import { forwardRef as forwardRef4, useRef as useRef4, useEffect as useEffect3, useState as useState3, useCallback as useCallback2 } from "react";
3
3
 
4
4
  // ../../foundation/primitives-native/src/Box.tsx
5
5
  import {
@@ -277,8 +277,11 @@ var Icon = ({
277
277
  return /* @__PURE__ */ jsx3(View2, { style, testID: dataTestId || testID, children: childrenWithProps });
278
278
  };
279
279
 
280
+ // ../../foundation/primitives-native/src/index.tsx
281
+ var isWeb = false;
282
+
280
283
  // src/MultiSelect.tsx
281
- import { useResolvedTheme as useResolvedTheme4 } from "@xsolla/xui-core";
284
+ import { useModalId, useResolvedTheme as useResolvedTheme4 } from "@xsolla/xui-core";
282
285
 
283
286
  // src/MultiSelectControl.tsx
284
287
  import { forwardRef as forwardRef3, useRef as useRef2 } from "react";
@@ -2150,8 +2153,12 @@ var useMultiSelect = ({
2150
2153
  };
2151
2154
  };
2152
2155
 
2156
+ // src/Portal.native.tsx
2157
+ import { Fragment, jsx as jsx726 } from "react/jsx-runtime";
2158
+ var Portal = ({ children }) => /* @__PURE__ */ jsx726(Fragment, { children });
2159
+
2153
2160
  // src/MultiSelect.tsx
2154
- import { Fragment, jsx as jsx726, jsxs as jsxs4 } from "react/jsx-runtime";
2161
+ import { Fragment as Fragment2, jsx as jsx727, jsxs as jsxs4 } from "react/jsx-runtime";
2155
2162
  var EXTERNAL_MENU_MIN_WIDTH_DEFAULT = 540;
2156
2163
  var MultiSelect = forwardRef4(
2157
2164
  ({
@@ -2180,8 +2187,10 @@ var MultiSelect = forwardRef4(
2180
2187
  themeProductContext
2181
2188
  }, ref) => {
2182
2189
  const { theme } = useResolvedTheme4({ themeMode, themeProductContext });
2190
+ const modalId = useModalId();
2183
2191
  const controlRef = useRef4(null);
2184
2192
  const menuRef = useRef4(null);
2193
+ const [menuPosition, setMenuPosition] = useState3(null);
2185
2194
  const sizeStyles = theme.sizing.input(size);
2186
2195
  const state = externalState || (disabled ? "disable" : "default");
2187
2196
  const isDisable = state === "disable" || disabled;
@@ -2225,11 +2234,111 @@ var MultiSelect = forwardRef4(
2225
2234
  };
2226
2235
  const controlMenuOpen = dropdownMenu ? isOpen : Boolean(menuOpen);
2227
2236
  const controlOnClick = dropdownMenu ? onSelectClick : onTriggerPress;
2237
+ const updateMenuPosition = useCallback2(() => {
2238
+ if (!isWeb || !controlRef.current) return;
2239
+ const rect = controlRef.current.getBoundingClientRect();
2240
+ setMenuPosition({
2241
+ left: rect.left,
2242
+ top: rect.bottom + 4,
2243
+ width: rect.width
2244
+ });
2245
+ }, []);
2246
+ useEffect3(() => {
2247
+ if (!isWeb || !controlMenuOpen || isDisable || !dropdownMenu) return;
2248
+ updateMenuPosition();
2249
+ window.addEventListener("resize", updateMenuPosition);
2250
+ window.addEventListener("scroll", updateMenuPosition, true);
2251
+ return () => {
2252
+ window.removeEventListener("resize", updateMenuPosition);
2253
+ window.removeEventListener("scroll", updateMenuPosition, true);
2254
+ };
2255
+ }, [controlMenuOpen, dropdownMenu, isDisable, updateMenuPosition]);
2228
2256
  const externalFieldLayout = !dropdownMenu ? {
2229
2257
  width: "100%",
2230
2258
  minWidth: menuMinWidth ?? EXTERNAL_MENU_MIN_WIDTH_DEFAULT,
2231
2259
  boxSizing: "border-box"
2232
2260
  } : void 0;
2261
+ const dropdown = dropdownMenu && isOpen && !isDisable && (!isWeb || menuPosition) && /* @__PURE__ */ jsxs4(Fragment2, { children: [
2262
+ /* @__PURE__ */ jsx727(
2263
+ Box,
2264
+ {
2265
+ "data-modal-id": modalId,
2266
+ style: {
2267
+ position: "fixed",
2268
+ top: 0,
2269
+ left: 0,
2270
+ right: 0,
2271
+ bottom: 0,
2272
+ zIndex: 999,
2273
+ cursor: "default"
2274
+ },
2275
+ onPress: onClose
2276
+ }
2277
+ ),
2278
+ /* @__PURE__ */ jsx727(
2279
+ Box,
2280
+ {
2281
+ ref: menuRef,
2282
+ "data-modal-id": modalId,
2283
+ backgroundColor: theme.colors.background.secondary,
2284
+ borderColor: theme.colors.border.secondary,
2285
+ borderWidth: 1,
2286
+ borderRadius: sizeStyles.radius,
2287
+ paddingVertical: 4,
2288
+ style: {
2289
+ position: isWeb ? "fixed" : "absolute",
2290
+ top: isWeb ? menuPosition?.top : "100%",
2291
+ left: isWeb ? menuPosition?.left : 0,
2292
+ right: isWeb ? void 0 : 0,
2293
+ width: isWeb ? menuPosition?.width : void 0,
2294
+ marginTop: isWeb ? void 0 : 4,
2295
+ zIndex: 1001,
2296
+ // Above control (1000) and backdrop (999)
2297
+ boxShadow: theme.shadow.popover,
2298
+ maxHeight,
2299
+ overflowY: "auto"
2300
+ },
2301
+ children: menuItems.map((item, _index) => {
2302
+ const brandColors = theme.colors.control.brand.primary;
2303
+ const contentColors = theme.colors.content;
2304
+ return /* @__PURE__ */ jsx727(
2305
+ Box,
2306
+ {
2307
+ testID,
2308
+ paddingHorizontal: sizeStyles.paddingHorizontal,
2309
+ paddingVertical: 8,
2310
+ onPress: () => {
2311
+ if (!item.disabled) {
2312
+ handleItemToggle(item.id, !item.checked);
2313
+ }
2314
+ },
2315
+ flexDirection: "row",
2316
+ alignItems: "center",
2317
+ justifyContent: "space-between",
2318
+ backgroundColor: item.checked ? brandColors.bg : "transparent",
2319
+ hoverStyle: !item.disabled && !item.checked ? {
2320
+ backgroundColor: theme.colors.control.input.bgHover
2321
+ } : void 0,
2322
+ style: {
2323
+ cursor: item.disabled ? "not-allowed" : "pointer",
2324
+ opacity: item.disabled ? 0.5 : 1
2325
+ },
2326
+ children: /* @__PURE__ */ jsx727(
2327
+ Text,
2328
+ {
2329
+ color: item.checked ? contentColors.on.brand : theme.colors.content.secondary,
2330
+ fontSize: sizeStyles.fontSize,
2331
+ fontWeight: "400",
2332
+ children: item.children
2333
+ }
2334
+ )
2335
+ },
2336
+ item.id
2337
+ );
2338
+ })
2339
+ }
2340
+ )
2341
+ ] });
2233
2342
  return /* @__PURE__ */ jsxs4(
2234
2343
  Box,
2235
2344
  {
@@ -2238,7 +2347,7 @@ var MultiSelect = forwardRef4(
2238
2347
  gap: sizeStyles.fieldGap,
2239
2348
  style: externalFieldLayout,
2240
2349
  children: [
2241
- label && /* @__PURE__ */ jsx726(
2350
+ label && /* @__PURE__ */ jsx727(
2242
2351
  Text,
2243
2352
  {
2244
2353
  color: theme.colors.content.secondary,
@@ -2256,7 +2365,7 @@ var MultiSelect = forwardRef4(
2256
2365
  ...externalFieldLayout ? { width: "100%" } : {}
2257
2366
  },
2258
2367
  children: [
2259
- /* @__PURE__ */ jsx726(
2368
+ /* @__PURE__ */ jsx727(
2260
2369
  MultiSelectControl,
2261
2370
  {
2262
2371
  ref: controlRef,
@@ -2281,88 +2390,11 @@ var MultiSelect = forwardRef4(
2281
2390
  extraClear
2282
2391
  }
2283
2392
  ),
2284
- dropdownMenu && isOpen && !isDisable && /* @__PURE__ */ jsxs4(Fragment, { children: [
2285
- /* @__PURE__ */ jsx726(
2286
- Box,
2287
- {
2288
- style: {
2289
- position: "fixed",
2290
- top: 0,
2291
- left: 0,
2292
- right: 0,
2293
- bottom: 0,
2294
- zIndex: 999,
2295
- cursor: "default"
2296
- },
2297
- onPress: onClose
2298
- }
2299
- ),
2300
- /* @__PURE__ */ jsx726(
2301
- Box,
2302
- {
2303
- ref: menuRef,
2304
- backgroundColor: theme.colors.background.secondary,
2305
- borderColor: theme.colors.border.secondary,
2306
- borderWidth: 1,
2307
- borderRadius: theme.shape.input[size].borderRadius,
2308
- paddingVertical: 4,
2309
- style: {
2310
- position: "absolute",
2311
- top: "100%",
2312
- left: 0,
2313
- right: 0,
2314
- marginTop: 4,
2315
- zIndex: 1001,
2316
- // Above control (1000) and backdrop (999)
2317
- boxShadow: theme.shadow.popover,
2318
- maxHeight,
2319
- overflowY: "auto"
2320
- },
2321
- children: menuItems.map((item, _index) => {
2322
- const brandColors = theme.colors.control.brand.primary;
2323
- const contentColors = theme.colors.content;
2324
- return /* @__PURE__ */ jsx726(
2325
- Box,
2326
- {
2327
- testID,
2328
- paddingHorizontal: sizeStyles.paddingHorizontal,
2329
- paddingVertical: 8,
2330
- onPress: () => {
2331
- if (!item.disabled) {
2332
- handleItemToggle(item.id, !item.checked);
2333
- }
2334
- },
2335
- flexDirection: "row",
2336
- alignItems: "center",
2337
- justifyContent: "space-between",
2338
- backgroundColor: item.checked ? brandColors.bg : "transparent",
2339
- hoverStyle: !item.disabled && !item.checked ? {
2340
- backgroundColor: theme.colors.control.input.bgHover
2341
- } : void 0,
2342
- style: {
2343
- cursor: item.disabled ? "not-allowed" : "pointer",
2344
- opacity: item.disabled ? 0.5 : 1
2345
- },
2346
- children: /* @__PURE__ */ jsx726(
2347
- Text,
2348
- {
2349
- color: item.checked ? contentColors.on.brand : theme.colors.content.secondary,
2350
- fontSize: sizeStyles.fontSize,
2351
- fontWeight: "400",
2352
- children: item.children
2353
- }
2354
- )
2355
- },
2356
- item.id
2357
- );
2358
- })
2359
- }
2360
- )
2361
- ] })
2393
+ isWeb ? /* @__PURE__ */ jsx727(Portal, { children: dropdown }) : dropdown
2362
2394
  ]
2363
2395
  }
2364
2396
  ),
2365
- errorMessage && /* @__PURE__ */ jsx726(
2397
+ errorMessage && /* @__PURE__ */ jsx727(
2366
2398
  Text,
2367
2399
  {
2368
2400
  color: theme.colors.content.alert.primary,