@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/native/index.mjs CHANGED
@@ -1902,6 +1902,7 @@ var MultiSelectControl = forwardRef3(
1902
1902
  iconRight,
1903
1903
  disabled = false,
1904
1904
  extraClear = false,
1905
+ width,
1905
1906
  themeMode,
1906
1907
  themeProductContext
1907
1908
  }, ref) => {
@@ -1950,6 +1951,7 @@ var MultiSelectControl = forwardRef3(
1950
1951
  Box,
1951
1952
  {
1952
1953
  ref,
1954
+ width,
1953
1955
  backgroundColor,
1954
1956
  borderColor,
1955
1957
  borderWidth: borderColor !== "transparent" ? 1 : 0,
@@ -1961,7 +1963,7 @@ var MultiSelectControl = forwardRef3(
1961
1963
  alignItems: "center",
1962
1964
  gap: 8,
1963
1965
  style: {
1964
- cursor: isDisable ? "not-allowed" : "pointer",
1966
+ cursor: isDisable ? "not-allowed" : onClick ? "pointer" : "default",
1965
1967
  boxSizing: "border-box",
1966
1968
  height: flexible ? "auto" : sizeStyles.height,
1967
1969
  position: "relative",
@@ -1969,7 +1971,7 @@ var MultiSelectControl = forwardRef3(
1969
1971
  // Above backdrop when open
1970
1972
  },
1971
1973
  onPress: isDisable ? void 0 : onClick,
1972
- hoverStyle: !isDisable && !isFocus && !isOpen && !isError ? {
1974
+ hoverStyle: !isDisable && onClick && !isFocus && !isOpen && !isError ? {
1973
1975
  backgroundColor: inputColors.bgHover,
1974
1976
  borderColor: inputColors.borderHover
1975
1977
  } : void 0,
@@ -2125,6 +2127,7 @@ var useMultiSelect = ({
2125
2127
 
2126
2128
  // src/MultiSelect.tsx
2127
2129
  import { Fragment, jsx as jsx726, jsxs as jsxs4 } from "react/jsx-runtime";
2130
+ var EXTERNAL_MENU_MIN_WIDTH_DEFAULT = 540;
2128
2131
  var MultiSelect = forwardRef4(
2129
2132
  ({
2130
2133
  options,
@@ -2143,6 +2146,10 @@ var MultiSelect = forwardRef4(
2143
2146
  iconLeft,
2144
2147
  iconRight,
2145
2148
  maxHeight = 300,
2149
+ dropdownMenu = true,
2150
+ onTriggerPress,
2151
+ menuOpen = false,
2152
+ menuMinWidth,
2146
2153
  themeMode,
2147
2154
  themeProductContext
2148
2155
  }, ref) => {
@@ -2170,10 +2177,10 @@ var MultiSelect = forwardRef4(
2170
2177
  onChange
2171
2178
  });
2172
2179
  useEffect3(() => {
2173
- if (isDisable) {
2180
+ if (isDisable || !dropdownMenu) {
2174
2181
  onClose();
2175
2182
  }
2176
- }, [isDisable, onClose]);
2183
+ }, [isDisable, dropdownMenu, onClose]);
2177
2184
  const menuItems = options.map((opt) => {
2178
2185
  const id = String(opt.value);
2179
2186
  const checked = values.map(String).includes(id);
@@ -2190,138 +2197,155 @@ var MultiSelect = forwardRef4(
2190
2197
  const newValues = checked ? [...values, value2] : values.filter((v) => v !== value2);
2191
2198
  onChoose(newValues.map(String));
2192
2199
  };
2193
- return /* @__PURE__ */ jsxs4(Box, { flexDirection: "column", gap: sizeStyles.fieldGap, children: [
2194
- label && /* @__PURE__ */ jsx726(
2195
- Text,
2196
- {
2197
- color: theme.colors.content.secondary,
2198
- fontSize: sizeStyles.fontSize - 2,
2199
- fontWeight: "500",
2200
- children: label
2201
- }
2202
- ),
2203
- /* @__PURE__ */ jsxs4(
2204
- Box,
2205
- {
2206
- ref,
2207
- style: {
2208
- position: "relative"
2209
- },
2210
- children: [
2211
- /* @__PURE__ */ jsx726(
2212
- MultiSelectControl,
2213
- {
2214
- ref: controlRef,
2215
- isOpen,
2216
- isFocus,
2217
- isError,
2218
- size,
2219
- state,
2220
- disabled: isDisable,
2221
- onClick: onSelectClick,
2222
- removeValue: onRemove,
2223
- removeAllValues: onRemoveAll,
2224
- stateList,
2225
- selectedItems,
2226
- variant,
2227
- flexible,
2228
- placeholder,
2229
- removeTagsButtons,
2230
- iconLeft,
2231
- iconRight,
2232
- extraClear
2233
- }
2234
- ),
2235
- isOpen && !isDisable && /* @__PURE__ */ jsxs4(Fragment, { children: [
2236
- /* @__PURE__ */ jsx726(
2237
- Box,
2238
- {
2239
- style: {
2240
- position: "fixed",
2241
- top: 0,
2242
- left: 0,
2243
- right: 0,
2244
- bottom: 0,
2245
- zIndex: 999,
2246
- cursor: "default"
2247
- },
2248
- onPress: onClose
2249
- }
2250
- ),
2251
- /* @__PURE__ */ jsx726(
2252
- Box,
2253
- {
2254
- ref: menuRef,
2255
- backgroundColor: theme.colors.background.secondary,
2256
- borderColor: theme.colors.border.secondary,
2257
- borderWidth: 1,
2258
- borderRadius: theme.radius.button,
2259
- paddingVertical: 4,
2260
- style: {
2261
- position: "absolute",
2262
- top: "100%",
2263
- left: 0,
2264
- right: 0,
2265
- marginTop: 4,
2266
- zIndex: 1001,
2267
- // Above control (1000) and backdrop (999)
2268
- boxShadow: theme.shadow.popover,
2269
- maxHeight,
2270
- overflowY: "auto"
2271
- },
2272
- children: menuItems.map((item, _index) => {
2273
- const brandColors = theme.colors.control.brand.primary;
2274
- const contentColors = theme.colors.content;
2275
- return /* @__PURE__ */ jsx726(
2276
- Box,
2277
- {
2278
- paddingHorizontal: sizeStyles.paddingHorizontal,
2279
- paddingVertical: 8,
2280
- onPress: () => {
2281
- if (!item.disabled) {
2282
- handleItemToggle(item.id, !item.checked);
2283
- }
2284
- },
2285
- flexDirection: "row",
2286
- alignItems: "center",
2287
- justifyContent: "space-between",
2288
- backgroundColor: item.checked ? brandColors.bg : "transparent",
2289
- hoverStyle: !item.disabled && !item.checked ? {
2290
- backgroundColor: theme.colors.control.input.bgHover
2291
- } : void 0,
2292
- style: {
2293
- cursor: item.disabled ? "not-allowed" : "pointer",
2294
- opacity: item.disabled ? 0.5 : 1
2295
- },
2296
- children: /* @__PURE__ */ jsx726(
2297
- Text,
2298
- {
2299
- color: item.checked ? contentColors.on.brand : theme.colors.content.secondary,
2300
- fontSize: sizeStyles.fontSize,
2301
- fontWeight: "400",
2302
- children: item.children
2303
- }
2304
- )
2200
+ const controlMenuOpen = dropdownMenu ? isOpen : Boolean(menuOpen);
2201
+ const controlOnClick = dropdownMenu ? onSelectClick : onTriggerPress;
2202
+ const externalFieldLayout = !dropdownMenu ? {
2203
+ width: "100%",
2204
+ minWidth: menuMinWidth ?? EXTERNAL_MENU_MIN_WIDTH_DEFAULT,
2205
+ boxSizing: "border-box"
2206
+ } : void 0;
2207
+ return /* @__PURE__ */ jsxs4(
2208
+ Box,
2209
+ {
2210
+ flexDirection: "column",
2211
+ gap: sizeStyles.fieldGap,
2212
+ style: externalFieldLayout,
2213
+ children: [
2214
+ label && /* @__PURE__ */ jsx726(
2215
+ Text,
2216
+ {
2217
+ color: theme.colors.content.secondary,
2218
+ fontSize: sizeStyles.fontSize - 2,
2219
+ fontWeight: "500",
2220
+ children: label
2221
+ }
2222
+ ),
2223
+ /* @__PURE__ */ jsxs4(
2224
+ Box,
2225
+ {
2226
+ ref,
2227
+ style: {
2228
+ position: "relative",
2229
+ ...externalFieldLayout ? { width: "100%" } : {}
2230
+ },
2231
+ children: [
2232
+ /* @__PURE__ */ jsx726(
2233
+ MultiSelectControl,
2234
+ {
2235
+ ref: controlRef,
2236
+ isOpen: controlMenuOpen,
2237
+ isFocus,
2238
+ isError,
2239
+ size,
2240
+ state,
2241
+ disabled: isDisable,
2242
+ onClick: controlOnClick,
2243
+ width: dropdownMenu ? void 0 : "100%",
2244
+ removeValue: onRemove,
2245
+ removeAllValues: onRemoveAll,
2246
+ stateList,
2247
+ selectedItems,
2248
+ variant,
2249
+ flexible,
2250
+ placeholder,
2251
+ removeTagsButtons,
2252
+ iconLeft,
2253
+ iconRight,
2254
+ extraClear
2255
+ }
2256
+ ),
2257
+ dropdownMenu && isOpen && !isDisable && /* @__PURE__ */ jsxs4(Fragment, { children: [
2258
+ /* @__PURE__ */ jsx726(
2259
+ Box,
2260
+ {
2261
+ style: {
2262
+ position: "fixed",
2263
+ top: 0,
2264
+ left: 0,
2265
+ right: 0,
2266
+ bottom: 0,
2267
+ zIndex: 999,
2268
+ cursor: "default"
2305
2269
  },
2306
- item.id
2307
- );
2308
- })
2309
- }
2310
- )
2311
- ] })
2312
- ]
2313
- }
2314
- ),
2315
- errorMessage && /* @__PURE__ */ jsx726(
2316
- Text,
2317
- {
2318
- color: theme.colors.content.alert.primary,
2319
- fontSize: sizeStyles.fontSize - 2,
2320
- style: { lineHeight: sizeStyles.lineHeight + "px" },
2321
- children: errorMessage
2322
- }
2323
- )
2324
- ] });
2270
+ onPress: onClose
2271
+ }
2272
+ ),
2273
+ /* @__PURE__ */ jsx726(
2274
+ Box,
2275
+ {
2276
+ ref: menuRef,
2277
+ backgroundColor: theme.colors.background.secondary,
2278
+ borderColor: theme.colors.border.secondary,
2279
+ borderWidth: 1,
2280
+ borderRadius: theme.radius.button,
2281
+ paddingVertical: 4,
2282
+ style: {
2283
+ position: "absolute",
2284
+ top: "100%",
2285
+ left: 0,
2286
+ right: 0,
2287
+ marginTop: 4,
2288
+ zIndex: 1001,
2289
+ // Above control (1000) and backdrop (999)
2290
+ boxShadow: theme.shadow.popover,
2291
+ maxHeight,
2292
+ overflowY: "auto"
2293
+ },
2294
+ children: menuItems.map((item, _index) => {
2295
+ const brandColors = theme.colors.control.brand.primary;
2296
+ const contentColors = theme.colors.content;
2297
+ return /* @__PURE__ */ jsx726(
2298
+ Box,
2299
+ {
2300
+ paddingHorizontal: sizeStyles.paddingHorizontal,
2301
+ paddingVertical: 8,
2302
+ onPress: () => {
2303
+ if (!item.disabled) {
2304
+ handleItemToggle(item.id, !item.checked);
2305
+ }
2306
+ },
2307
+ flexDirection: "row",
2308
+ alignItems: "center",
2309
+ justifyContent: "space-between",
2310
+ backgroundColor: item.checked ? brandColors.bg : "transparent",
2311
+ hoverStyle: !item.disabled && !item.checked ? {
2312
+ backgroundColor: theme.colors.control.input.bgHover
2313
+ } : void 0,
2314
+ style: {
2315
+ cursor: item.disabled ? "not-allowed" : "pointer",
2316
+ opacity: item.disabled ? 0.5 : 1
2317
+ },
2318
+ children: /* @__PURE__ */ jsx726(
2319
+ Text,
2320
+ {
2321
+ color: item.checked ? contentColors.on.brand : theme.colors.content.secondary,
2322
+ fontSize: sizeStyles.fontSize,
2323
+ fontWeight: "400",
2324
+ children: item.children
2325
+ }
2326
+ )
2327
+ },
2328
+ item.id
2329
+ );
2330
+ })
2331
+ }
2332
+ )
2333
+ ] })
2334
+ ]
2335
+ }
2336
+ ),
2337
+ errorMessage && /* @__PURE__ */ jsx726(
2338
+ Text,
2339
+ {
2340
+ color: theme.colors.content.alert.primary,
2341
+ fontSize: sizeStyles.fontSize - 2,
2342
+ style: { lineHeight: sizeStyles.lineHeight + "px" },
2343
+ children: errorMessage
2344
+ }
2345
+ )
2346
+ ]
2347
+ }
2348
+ );
2325
2349
  }
2326
2350
  );
2327
2351
  MultiSelect.displayName = "MultiSelect";