@xsolla/xui-multi-select 0.149.1 → 0.150.0

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/web/index.mjs CHANGED
@@ -1941,6 +1941,7 @@ var MultiSelectControl = forwardRef3(
1941
1941
  iconRight,
1942
1942
  disabled = false,
1943
1943
  extraClear = false,
1944
+ width,
1944
1945
  themeMode,
1945
1946
  themeProductContext
1946
1947
  }, ref) => {
@@ -1989,6 +1990,7 @@ var MultiSelectControl = forwardRef3(
1989
1990
  Box,
1990
1991
  {
1991
1992
  ref,
1993
+ width,
1992
1994
  backgroundColor,
1993
1995
  borderColor,
1994
1996
  borderWidth: borderColor !== "transparent" ? 1 : 0,
@@ -2000,7 +2002,7 @@ var MultiSelectControl = forwardRef3(
2000
2002
  alignItems: "center",
2001
2003
  gap: 8,
2002
2004
  style: {
2003
- cursor: isDisable ? "not-allowed" : "pointer",
2005
+ cursor: isDisable ? "not-allowed" : onClick ? "pointer" : "default",
2004
2006
  boxSizing: "border-box",
2005
2007
  height: flexible ? "auto" : sizeStyles.height,
2006
2008
  position: "relative",
@@ -2008,7 +2010,7 @@ var MultiSelectControl = forwardRef3(
2008
2010
  // Above backdrop when open
2009
2011
  },
2010
2012
  onPress: isDisable ? void 0 : onClick,
2011
- hoverStyle: !isDisable && !isFocus && !isOpen && !isError ? {
2013
+ hoverStyle: !isDisable && onClick && !isFocus && !isOpen && !isError ? {
2012
2014
  backgroundColor: inputColors.bgHover,
2013
2015
  borderColor: inputColors.borderHover
2014
2016
  } : void 0,
@@ -2164,6 +2166,7 @@ var useMultiSelect = ({
2164
2166
 
2165
2167
  // src/MultiSelect.tsx
2166
2168
  import { Fragment, jsx as jsx726, jsxs as jsxs4 } from "react/jsx-runtime";
2169
+ var EXTERNAL_MENU_MIN_WIDTH_DEFAULT = 540;
2167
2170
  var MultiSelect = forwardRef4(
2168
2171
  ({
2169
2172
  options,
@@ -2182,6 +2185,10 @@ var MultiSelect = forwardRef4(
2182
2185
  iconLeft,
2183
2186
  iconRight,
2184
2187
  maxHeight = 300,
2188
+ dropdownMenu = true,
2189
+ onTriggerPress,
2190
+ menuOpen = false,
2191
+ menuMinWidth,
2185
2192
  themeMode,
2186
2193
  themeProductContext
2187
2194
  }, ref) => {
@@ -2209,10 +2216,10 @@ var MultiSelect = forwardRef4(
2209
2216
  onChange
2210
2217
  });
2211
2218
  useEffect3(() => {
2212
- if (isDisable) {
2219
+ if (isDisable || !dropdownMenu) {
2213
2220
  onClose();
2214
2221
  }
2215
- }, [isDisable, onClose]);
2222
+ }, [isDisable, dropdownMenu, onClose]);
2216
2223
  const menuItems = options.map((opt) => {
2217
2224
  const id = String(opt.value);
2218
2225
  const checked = values.map(String).includes(id);
@@ -2229,138 +2236,155 @@ var MultiSelect = forwardRef4(
2229
2236
  const newValues = checked ? [...values, value2] : values.filter((v) => v !== value2);
2230
2237
  onChoose(newValues.map(String));
2231
2238
  };
2232
- return /* @__PURE__ */ jsxs4(Box, { flexDirection: "column", gap: sizeStyles.fieldGap, children: [
2233
- label && /* @__PURE__ */ jsx726(
2234
- Text,
2235
- {
2236
- color: theme.colors.content.secondary,
2237
- fontSize: sizeStyles.fontSize - 2,
2238
- fontWeight: "500",
2239
- children: label
2240
- }
2241
- ),
2242
- /* @__PURE__ */ jsxs4(
2243
- Box,
2244
- {
2245
- ref,
2246
- style: {
2247
- position: "relative"
2248
- },
2249
- children: [
2250
- /* @__PURE__ */ jsx726(
2251
- MultiSelectControl,
2252
- {
2253
- ref: controlRef,
2254
- isOpen,
2255
- isFocus,
2256
- isError,
2257
- size,
2258
- state,
2259
- disabled: isDisable,
2260
- onClick: onSelectClick,
2261
- removeValue: onRemove,
2262
- removeAllValues: onRemoveAll,
2263
- stateList,
2264
- selectedItems,
2265
- variant,
2266
- flexible,
2267
- placeholder,
2268
- removeTagsButtons,
2269
- iconLeft,
2270
- iconRight,
2271
- extraClear
2272
- }
2273
- ),
2274
- isOpen && !isDisable && /* @__PURE__ */ jsxs4(Fragment, { children: [
2275
- /* @__PURE__ */ jsx726(
2276
- Box,
2277
- {
2278
- style: {
2279
- position: "fixed",
2280
- top: 0,
2281
- left: 0,
2282
- right: 0,
2283
- bottom: 0,
2284
- zIndex: 999,
2285
- cursor: "default"
2286
- },
2287
- onPress: onClose
2288
- }
2289
- ),
2290
- /* @__PURE__ */ jsx726(
2291
- Box,
2292
- {
2293
- ref: menuRef,
2294
- backgroundColor: theme.colors.background.secondary,
2295
- borderColor: theme.colors.border.secondary,
2296
- borderWidth: 1,
2297
- borderRadius: theme.radius.button,
2298
- paddingVertical: 4,
2299
- style: {
2300
- position: "absolute",
2301
- top: "100%",
2302
- left: 0,
2303
- right: 0,
2304
- marginTop: 4,
2305
- zIndex: 1001,
2306
- // Above control (1000) and backdrop (999)
2307
- boxShadow: theme.shadow.popover,
2308
- maxHeight,
2309
- overflowY: "auto"
2310
- },
2311
- children: menuItems.map((item, _index) => {
2312
- const brandColors = theme.colors.control.brand.primary;
2313
- const contentColors = theme.colors.content;
2314
- return /* @__PURE__ */ jsx726(
2315
- Box,
2316
- {
2317
- paddingHorizontal: sizeStyles.paddingHorizontal,
2318
- paddingVertical: 8,
2319
- onPress: () => {
2320
- if (!item.disabled) {
2321
- handleItemToggle(item.id, !item.checked);
2322
- }
2323
- },
2324
- flexDirection: "row",
2325
- alignItems: "center",
2326
- justifyContent: "space-between",
2327
- backgroundColor: item.checked ? brandColors.bg : "transparent",
2328
- hoverStyle: !item.disabled && !item.checked ? {
2329
- backgroundColor: theme.colors.control.input.bgHover
2330
- } : void 0,
2331
- style: {
2332
- cursor: item.disabled ? "not-allowed" : "pointer",
2333
- opacity: item.disabled ? 0.5 : 1
2334
- },
2335
- children: /* @__PURE__ */ jsx726(
2336
- Text,
2337
- {
2338
- color: item.checked ? contentColors.on.brand : theme.colors.content.secondary,
2339
- fontSize: sizeStyles.fontSize,
2340
- fontWeight: "400",
2341
- children: item.children
2342
- }
2343
- )
2239
+ const controlMenuOpen = dropdownMenu ? isOpen : Boolean(menuOpen);
2240
+ const controlOnClick = dropdownMenu ? onSelectClick : onTriggerPress;
2241
+ const externalFieldLayout = !dropdownMenu ? {
2242
+ width: "100%",
2243
+ minWidth: menuMinWidth ?? EXTERNAL_MENU_MIN_WIDTH_DEFAULT,
2244
+ boxSizing: "border-box"
2245
+ } : void 0;
2246
+ return /* @__PURE__ */ jsxs4(
2247
+ Box,
2248
+ {
2249
+ flexDirection: "column",
2250
+ gap: sizeStyles.fieldGap,
2251
+ style: externalFieldLayout,
2252
+ children: [
2253
+ label && /* @__PURE__ */ jsx726(
2254
+ Text,
2255
+ {
2256
+ color: theme.colors.content.secondary,
2257
+ fontSize: sizeStyles.fontSize - 2,
2258
+ fontWeight: "500",
2259
+ children: label
2260
+ }
2261
+ ),
2262
+ /* @__PURE__ */ jsxs4(
2263
+ Box,
2264
+ {
2265
+ ref,
2266
+ style: {
2267
+ position: "relative",
2268
+ ...externalFieldLayout ? { width: "100%" } : {}
2269
+ },
2270
+ children: [
2271
+ /* @__PURE__ */ jsx726(
2272
+ MultiSelectControl,
2273
+ {
2274
+ ref: controlRef,
2275
+ isOpen: controlMenuOpen,
2276
+ isFocus,
2277
+ isError,
2278
+ size,
2279
+ state,
2280
+ disabled: isDisable,
2281
+ onClick: controlOnClick,
2282
+ width: dropdownMenu ? void 0 : "100%",
2283
+ removeValue: onRemove,
2284
+ removeAllValues: onRemoveAll,
2285
+ stateList,
2286
+ selectedItems,
2287
+ variant,
2288
+ flexible,
2289
+ placeholder,
2290
+ removeTagsButtons,
2291
+ iconLeft,
2292
+ iconRight,
2293
+ extraClear
2294
+ }
2295
+ ),
2296
+ dropdownMenu && isOpen && !isDisable && /* @__PURE__ */ jsxs4(Fragment, { children: [
2297
+ /* @__PURE__ */ jsx726(
2298
+ Box,
2299
+ {
2300
+ style: {
2301
+ position: "fixed",
2302
+ top: 0,
2303
+ left: 0,
2304
+ right: 0,
2305
+ bottom: 0,
2306
+ zIndex: 999,
2307
+ cursor: "default"
2344
2308
  },
2345
- item.id
2346
- );
2347
- })
2348
- }
2349
- )
2350
- ] })
2351
- ]
2352
- }
2353
- ),
2354
- errorMessage && /* @__PURE__ */ jsx726(
2355
- Text,
2356
- {
2357
- color: theme.colors.content.alert.primary,
2358
- fontSize: sizeStyles.fontSize - 2,
2359
- style: { lineHeight: sizeStyles.lineHeight + "px" },
2360
- children: errorMessage
2361
- }
2362
- )
2363
- ] });
2309
+ onPress: onClose
2310
+ }
2311
+ ),
2312
+ /* @__PURE__ */ jsx726(
2313
+ Box,
2314
+ {
2315
+ ref: menuRef,
2316
+ backgroundColor: theme.colors.background.secondary,
2317
+ borderColor: theme.colors.border.secondary,
2318
+ borderWidth: 1,
2319
+ borderRadius: theme.radius.button,
2320
+ paddingVertical: 4,
2321
+ style: {
2322
+ position: "absolute",
2323
+ top: "100%",
2324
+ left: 0,
2325
+ right: 0,
2326
+ marginTop: 4,
2327
+ zIndex: 1001,
2328
+ // Above control (1000) and backdrop (999)
2329
+ boxShadow: theme.shadow.popover,
2330
+ maxHeight,
2331
+ overflowY: "auto"
2332
+ },
2333
+ children: menuItems.map((item, _index) => {
2334
+ const brandColors = theme.colors.control.brand.primary;
2335
+ const contentColors = theme.colors.content;
2336
+ return /* @__PURE__ */ jsx726(
2337
+ Box,
2338
+ {
2339
+ paddingHorizontal: sizeStyles.paddingHorizontal,
2340
+ paddingVertical: 8,
2341
+ onPress: () => {
2342
+ if (!item.disabled) {
2343
+ handleItemToggle(item.id, !item.checked);
2344
+ }
2345
+ },
2346
+ flexDirection: "row",
2347
+ alignItems: "center",
2348
+ justifyContent: "space-between",
2349
+ backgroundColor: item.checked ? brandColors.bg : "transparent",
2350
+ hoverStyle: !item.disabled && !item.checked ? {
2351
+ backgroundColor: theme.colors.control.input.bgHover
2352
+ } : void 0,
2353
+ style: {
2354
+ cursor: item.disabled ? "not-allowed" : "pointer",
2355
+ opacity: item.disabled ? 0.5 : 1
2356
+ },
2357
+ children: /* @__PURE__ */ jsx726(
2358
+ Text,
2359
+ {
2360
+ color: item.checked ? contentColors.on.brand : theme.colors.content.secondary,
2361
+ fontSize: sizeStyles.fontSize,
2362
+ fontWeight: "400",
2363
+ children: item.children
2364
+ }
2365
+ )
2366
+ },
2367
+ item.id
2368
+ );
2369
+ })
2370
+ }
2371
+ )
2372
+ ] })
2373
+ ]
2374
+ }
2375
+ ),
2376
+ errorMessage && /* @__PURE__ */ jsx726(
2377
+ Text,
2378
+ {
2379
+ color: theme.colors.content.alert.primary,
2380
+ fontSize: sizeStyles.fontSize - 2,
2381
+ style: { lineHeight: sizeStyles.lineHeight + "px" },
2382
+ children: errorMessage
2383
+ }
2384
+ )
2385
+ ]
2386
+ }
2387
+ );
2364
2388
  }
2365
2389
  );
2366
2390
  MultiSelect.displayName = "MultiSelect";