@xsolla/xui-dropdown 0.64.0-pr56.1768440195

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.
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+
3
+ interface DropdownProps {
4
+ trigger: React.ReactNode;
5
+ children: React.ReactNode;
6
+ isOpen?: boolean;
7
+ onOpenChange?: (open: boolean) => void;
8
+ width?: string | number;
9
+ }
10
+ declare const Dropdown: React.FC<DropdownProps>;
11
+ interface DropdownItemProps {
12
+ children: React.ReactNode;
13
+ onPress?: () => void;
14
+ active?: boolean;
15
+ disabled?: boolean;
16
+ icon?: React.ReactNode;
17
+ }
18
+ declare const DropdownItem: React.FC<DropdownItemProps>;
19
+
20
+ export { Dropdown, DropdownItem, type DropdownItemProps, type DropdownProps };
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+
3
+ interface DropdownProps {
4
+ trigger: React.ReactNode;
5
+ children: React.ReactNode;
6
+ isOpen?: boolean;
7
+ onOpenChange?: (open: boolean) => void;
8
+ width?: string | number;
9
+ }
10
+ declare const Dropdown: React.FC<DropdownProps>;
11
+ interface DropdownItemProps {
12
+ children: React.ReactNode;
13
+ onPress?: () => void;
14
+ active?: boolean;
15
+ disabled?: boolean;
16
+ icon?: React.ReactNode;
17
+ }
18
+ declare const DropdownItem: React.FC<DropdownItemProps>;
19
+
20
+ export { Dropdown, DropdownItem, type DropdownItemProps, type DropdownProps };
@@ -0,0 +1,618 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.tsx
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ Dropdown: () => Dropdown,
34
+ DropdownItem: () => DropdownItem
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+
38
+ // src/Dropdown.tsx
39
+ var import_react4 = require("react");
40
+
41
+ // ../primitives-native/src/Box.tsx
42
+ var import_react_native = require("react-native");
43
+ var import_jsx_runtime = require("react/jsx-runtime");
44
+ var Box = ({
45
+ children,
46
+ onPress,
47
+ onLayout,
48
+ onMoveShouldSetResponder,
49
+ onResponderGrant,
50
+ onResponderMove,
51
+ onResponderRelease,
52
+ onResponderTerminate,
53
+ backgroundColor,
54
+ borderColor,
55
+ borderWidth,
56
+ borderBottomWidth,
57
+ borderBottomColor,
58
+ borderTopWidth,
59
+ borderTopColor,
60
+ borderLeftWidth,
61
+ borderLeftColor,
62
+ borderRightWidth,
63
+ borderRightColor,
64
+ borderRadius,
65
+ borderStyle,
66
+ height,
67
+ padding,
68
+ paddingHorizontal,
69
+ paddingVertical,
70
+ margin,
71
+ marginTop,
72
+ marginBottom,
73
+ marginLeft,
74
+ marginRight,
75
+ flexDirection,
76
+ alignItems,
77
+ justifyContent,
78
+ position,
79
+ top,
80
+ bottom,
81
+ left,
82
+ right,
83
+ width,
84
+ flex,
85
+ overflow,
86
+ zIndex,
87
+ hoverStyle,
88
+ pressStyle,
89
+ style,
90
+ "data-testid": dataTestId,
91
+ testID,
92
+ as,
93
+ src,
94
+ alt,
95
+ ...rest
96
+ }) => {
97
+ const getContainerStyle = (pressed) => ({
98
+ backgroundColor: pressed && pressStyle?.backgroundColor ? pressStyle.backgroundColor : backgroundColor,
99
+ borderColor,
100
+ borderWidth,
101
+ borderBottomWidth,
102
+ borderBottomColor,
103
+ borderTopWidth,
104
+ borderTopColor,
105
+ borderLeftWidth,
106
+ borderLeftColor,
107
+ borderRightWidth,
108
+ borderRightColor,
109
+ borderRadius,
110
+ borderStyle,
111
+ overflow,
112
+ zIndex,
113
+ height,
114
+ width,
115
+ padding,
116
+ paddingHorizontal,
117
+ paddingVertical,
118
+ margin,
119
+ marginTop,
120
+ marginBottom,
121
+ marginLeft,
122
+ marginRight,
123
+ flexDirection,
124
+ alignItems,
125
+ justifyContent,
126
+ position,
127
+ top,
128
+ bottom,
129
+ left,
130
+ right,
131
+ flex,
132
+ ...style
133
+ });
134
+ const finalTestID = dataTestId || testID;
135
+ const {
136
+ role,
137
+ tabIndex,
138
+ onKeyDown,
139
+ onKeyUp,
140
+ "aria-label": _ariaLabel,
141
+ "aria-labelledby": _ariaLabelledBy,
142
+ "aria-current": _ariaCurrent,
143
+ "aria-disabled": _ariaDisabled,
144
+ "aria-live": _ariaLive,
145
+ className,
146
+ "data-testid": _dataTestId,
147
+ ...nativeRest
148
+ } = rest;
149
+ if (as === "img" && src) {
150
+ const imageStyle = {
151
+ width,
152
+ height,
153
+ borderRadius,
154
+ position,
155
+ top,
156
+ bottom,
157
+ left,
158
+ right,
159
+ ...style
160
+ };
161
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
162
+ import_react_native.Image,
163
+ {
164
+ source: { uri: src },
165
+ style: imageStyle,
166
+ testID: finalTestID,
167
+ resizeMode: "cover",
168
+ ...nativeRest
169
+ }
170
+ );
171
+ }
172
+ if (onPress) {
173
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
174
+ import_react_native.Pressable,
175
+ {
176
+ onPress,
177
+ onLayout,
178
+ onMoveShouldSetResponder,
179
+ onResponderGrant,
180
+ onResponderMove,
181
+ onResponderRelease,
182
+ onResponderTerminate,
183
+ style: ({ pressed }) => getContainerStyle(pressed),
184
+ testID: finalTestID,
185
+ ...nativeRest,
186
+ children
187
+ }
188
+ );
189
+ }
190
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
191
+ import_react_native.View,
192
+ {
193
+ style: getContainerStyle(),
194
+ testID: finalTestID,
195
+ onLayout,
196
+ onMoveShouldSetResponder,
197
+ onResponderGrant,
198
+ onResponderMove,
199
+ onResponderRelease,
200
+ onResponderTerminate,
201
+ ...nativeRest,
202
+ children
203
+ }
204
+ );
205
+ };
206
+
207
+ // ../primitives-native/src/Text.tsx
208
+ var import_react_native2 = require("react-native");
209
+ var import_jsx_runtime2 = require("react/jsx-runtime");
210
+ var roleMap = {
211
+ alert: "alert",
212
+ heading: "header",
213
+ button: "button",
214
+ link: "link",
215
+ text: "text"
216
+ };
217
+ var Text = ({
218
+ children,
219
+ color,
220
+ fontSize,
221
+ fontWeight,
222
+ fontFamily,
223
+ id,
224
+ role,
225
+ ...props
226
+ }) => {
227
+ let resolvedFontFamily = fontFamily ? fontFamily.split(",")[0].replace(/['"]/g, "").trim() : void 0;
228
+ if (resolvedFontFamily === "Pilat Wide Bold") {
229
+ resolvedFontFamily = void 0;
230
+ }
231
+ const style = {
232
+ color,
233
+ fontSize: typeof fontSize === "number" ? fontSize : void 0,
234
+ fontWeight,
235
+ fontFamily: resolvedFontFamily,
236
+ textDecorationLine: props.textDecoration
237
+ };
238
+ const accessibilityRole = role ? roleMap[role] : void 0;
239
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Text, { style, testID: id, accessibilityRole, children });
240
+ };
241
+
242
+ // ../primitives-native/src/Spinner.tsx
243
+ var import_react_native3 = require("react-native");
244
+ var import_jsx_runtime3 = require("react/jsx-runtime");
245
+ var Spinner = ({
246
+ color,
247
+ size,
248
+ role,
249
+ "aria-label": ariaLabel,
250
+ "aria-live": ariaLive,
251
+ "aria-describedby": ariaDescribedBy,
252
+ testID
253
+ }) => {
254
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
255
+ import_react_native3.View,
256
+ {
257
+ accessible: true,
258
+ accessibilityRole: role === "status" ? "none" : void 0,
259
+ accessibilityLabel: ariaLabel,
260
+ accessibilityLiveRegion: ariaLive === "polite" ? "polite" : ariaLive === "assertive" ? "assertive" : "none",
261
+ testID,
262
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
263
+ import_react_native3.ActivityIndicator,
264
+ {
265
+ color,
266
+ size: typeof size === "number" ? size : "small"
267
+ }
268
+ )
269
+ }
270
+ );
271
+ };
272
+ Spinner.displayName = "Spinner";
273
+
274
+ // ../primitives-native/src/Icon.tsx
275
+ var import_react = __toESM(require("react"));
276
+ var import_react_native4 = require("react-native");
277
+ var import_jsx_runtime4 = require("react/jsx-runtime");
278
+
279
+ // ../primitives-native/src/Divider.tsx
280
+ var import_react_native5 = require("react-native");
281
+ var import_jsx_runtime5 = require("react/jsx-runtime");
282
+
283
+ // ../primitives-native/src/Input.tsx
284
+ var import_react2 = require("react");
285
+ var import_react_native6 = require("react-native");
286
+ var import_jsx_runtime6 = require("react/jsx-runtime");
287
+ var keyboardTypeMap = {
288
+ text: "default",
289
+ number: "numeric",
290
+ email: "email-address",
291
+ tel: "phone-pad",
292
+ url: "url",
293
+ decimal: "decimal-pad"
294
+ };
295
+ var inputModeToKeyboardType = {
296
+ none: "default",
297
+ text: "default",
298
+ decimal: "decimal-pad",
299
+ numeric: "number-pad",
300
+ tel: "phone-pad",
301
+ search: "default",
302
+ email: "email-address",
303
+ url: "url"
304
+ };
305
+ var autoCompleteToTextContentType = {
306
+ "one-time-code": "oneTimeCode",
307
+ email: "emailAddress",
308
+ username: "username",
309
+ password: "password",
310
+ "new-password": "newPassword",
311
+ tel: "telephoneNumber",
312
+ "postal-code": "postalCode",
313
+ name: "name"
314
+ };
315
+ var InputPrimitive = (0, import_react2.forwardRef)(
316
+ ({
317
+ value,
318
+ placeholder,
319
+ onChange,
320
+ onChangeText,
321
+ onFocus,
322
+ onBlur,
323
+ onKeyDown,
324
+ disabled,
325
+ secureTextEntry,
326
+ style,
327
+ color,
328
+ fontSize,
329
+ placeholderTextColor,
330
+ maxLength,
331
+ name,
332
+ type,
333
+ inputMode,
334
+ autoComplete,
335
+ id,
336
+ "aria-invalid": ariaInvalid,
337
+ "aria-describedby": ariaDescribedBy,
338
+ "aria-labelledby": ariaLabelledBy,
339
+ "aria-label": ariaLabel,
340
+ "aria-disabled": ariaDisabled,
341
+ "data-testid": dataTestId
342
+ }, ref) => {
343
+ const handleChangeText = (text) => {
344
+ onChangeText?.(text);
345
+ if (onChange) {
346
+ const syntheticEvent = {
347
+ target: { value: text },
348
+ currentTarget: { value: text },
349
+ type: "change",
350
+ nativeEvent: { text },
351
+ preventDefault: () => {
352
+ },
353
+ stopPropagation: () => {
354
+ },
355
+ isTrusted: false
356
+ };
357
+ onChange(syntheticEvent);
358
+ }
359
+ };
360
+ const keyboardType = inputMode ? inputModeToKeyboardType[inputMode] || "default" : type ? keyboardTypeMap[type] || "default" : "default";
361
+ const textContentType = autoComplete ? autoCompleteToTextContentType[autoComplete] : void 0;
362
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
363
+ import_react_native6.TextInput,
364
+ {
365
+ ref,
366
+ value,
367
+ placeholder,
368
+ onChangeText: handleChangeText,
369
+ onFocus,
370
+ onBlur,
371
+ onKeyPress: (e) => {
372
+ if (onKeyDown) {
373
+ onKeyDown({
374
+ key: e.nativeEvent.key,
375
+ preventDefault: () => {
376
+ }
377
+ });
378
+ }
379
+ },
380
+ editable: !disabled,
381
+ secureTextEntry: secureTextEntry || type === "password",
382
+ keyboardType,
383
+ textContentType,
384
+ style: [
385
+ {
386
+ color,
387
+ fontSize: typeof fontSize === "number" ? fontSize : void 0,
388
+ flex: 1,
389
+ padding: 0,
390
+ textAlign: style?.textAlign || "left"
391
+ },
392
+ style
393
+ ],
394
+ placeholderTextColor,
395
+ maxLength,
396
+ testID: dataTestId || id,
397
+ accessibilityLabel: ariaLabel,
398
+ accessibilityHint: ariaDescribedBy,
399
+ accessibilityState: {
400
+ disabled: disabled || ariaDisabled
401
+ },
402
+ accessible: true
403
+ }
404
+ );
405
+ }
406
+ );
407
+ InputPrimitive.displayName = "InputPrimitive";
408
+
409
+ // ../primitives-native/src/TextArea.tsx
410
+ var import_react3 = require("react");
411
+ var import_react_native7 = require("react-native");
412
+ var import_jsx_runtime7 = require("react/jsx-runtime");
413
+ var TextAreaPrimitive = (0, import_react3.forwardRef)(
414
+ ({
415
+ value,
416
+ placeholder,
417
+ onChange,
418
+ onChangeText,
419
+ onFocus,
420
+ onBlur,
421
+ onKeyDown,
422
+ disabled,
423
+ style,
424
+ color,
425
+ fontSize,
426
+ placeholderTextColor,
427
+ maxLength,
428
+ rows,
429
+ id,
430
+ "aria-invalid": ariaInvalid,
431
+ "aria-describedby": ariaDescribedBy,
432
+ "aria-labelledby": ariaLabelledBy,
433
+ "aria-label": ariaLabel,
434
+ "aria-disabled": ariaDisabled,
435
+ "data-testid": dataTestId
436
+ }, ref) => {
437
+ const handleChangeText = (text) => {
438
+ onChangeText?.(text);
439
+ if (onChange) {
440
+ const syntheticEvent = {
441
+ target: { value: text },
442
+ currentTarget: { value: text },
443
+ type: "change",
444
+ nativeEvent: { text },
445
+ preventDefault: () => {
446
+ },
447
+ stopPropagation: () => {
448
+ },
449
+ isTrusted: false
450
+ };
451
+ onChange(syntheticEvent);
452
+ }
453
+ };
454
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
455
+ import_react_native7.TextInput,
456
+ {
457
+ ref,
458
+ value,
459
+ placeholder,
460
+ onChangeText: handleChangeText,
461
+ onFocus,
462
+ onBlur,
463
+ onKeyPress: (e) => {
464
+ if (onKeyDown) {
465
+ onKeyDown({
466
+ key: e.nativeEvent.key,
467
+ preventDefault: () => {
468
+ }
469
+ });
470
+ }
471
+ },
472
+ editable: !disabled,
473
+ multiline: true,
474
+ numberOfLines: rows || 4,
475
+ style: [
476
+ {
477
+ color,
478
+ fontSize: typeof fontSize === "number" ? fontSize : void 0,
479
+ flex: 1,
480
+ padding: 0,
481
+ textAlignVertical: "top",
482
+ textAlign: style?.textAlign || "left"
483
+ },
484
+ style
485
+ ],
486
+ placeholderTextColor,
487
+ maxLength,
488
+ testID: dataTestId || id,
489
+ accessibilityLabel: ariaLabel,
490
+ accessibilityHint: ariaDescribedBy,
491
+ accessibilityState: {
492
+ disabled: disabled || ariaDisabled
493
+ },
494
+ accessible: true
495
+ }
496
+ );
497
+ }
498
+ );
499
+ TextAreaPrimitive.displayName = "TextAreaPrimitive";
500
+
501
+ // src/Dropdown.tsx
502
+ var import_xui_core = require("@xsolla/xui-core");
503
+ var import_jsx_runtime8 = require("react/jsx-runtime");
504
+ var Dropdown = ({
505
+ trigger,
506
+ children,
507
+ isOpen: propIsOpen,
508
+ onOpenChange,
509
+ width = "auto"
510
+ }) => {
511
+ const [internalIsOpen, setInternalIsOpen] = (0, import_react4.useState)(false);
512
+ const isOpen = propIsOpen !== void 0 ? propIsOpen : internalIsOpen;
513
+ const containerRef = (0, import_react4.useRef)(null);
514
+ const { theme } = (0, import_xui_core.useDesignSystem)();
515
+ const toggleOpen = () => {
516
+ const nextOpen = !isOpen;
517
+ if (propIsOpen === void 0) {
518
+ setInternalIsOpen(nextOpen);
519
+ }
520
+ if (onOpenChange) onOpenChange(nextOpen);
521
+ };
522
+ (0, import_react4.useEffect)(() => {
523
+ const handleClickOutside = (event) => {
524
+ if (containerRef.current && !containerRef.current.contains(event.target)) {
525
+ if (propIsOpen === void 0) {
526
+ setInternalIsOpen(false);
527
+ }
528
+ if (onOpenChange) onOpenChange(false);
529
+ }
530
+ };
531
+ if (isOpen) {
532
+ document.addEventListener("mousedown", handleClickOutside);
533
+ }
534
+ return () => {
535
+ document.removeEventListener("mousedown", handleClickOutside);
536
+ };
537
+ }, [isOpen, propIsOpen, onOpenChange]);
538
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
539
+ "div",
540
+ {
541
+ ref: containerRef,
542
+ style: {
543
+ position: "relative",
544
+ width: width === "auto" ? "fit-content" : width,
545
+ alignSelf: "flex-start",
546
+ height: "fit-content"
547
+ },
548
+ children: [
549
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { onClick: toggleOpen, style: { cursor: "pointer" }, children: trigger }),
550
+ isOpen && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
551
+ Box,
552
+ {
553
+ position: "absolute",
554
+ top: "100%",
555
+ left: 0,
556
+ marginTop: 4,
557
+ backgroundColor: theme.colors.background.secondary,
558
+ borderColor: theme.colors.border.secondary,
559
+ borderWidth: 1,
560
+ borderRadius: theme.radius.button,
561
+ paddingVertical: 4,
562
+ style: {
563
+ zIndex: 1e3,
564
+ boxShadow: "0 4px 12px rgba(0,0,0,0.1)",
565
+ minWidth: "100%"
566
+ },
567
+ children
568
+ }
569
+ )
570
+ ]
571
+ }
572
+ );
573
+ };
574
+ var DropdownItem = ({
575
+ children,
576
+ onPress,
577
+ active,
578
+ disabled,
579
+ icon
580
+ }) => {
581
+ const { theme } = (0, import_xui_core.useDesignSystem)();
582
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
583
+ Box,
584
+ {
585
+ onPress: !disabled ? onPress : void 0,
586
+ paddingHorizontal: 16,
587
+ paddingVertical: 8,
588
+ flexDirection: "row",
589
+ alignItems: "center",
590
+ backgroundColor: active ? theme.colors.control.input.bgHover : "transparent",
591
+ hoverStyle: !disabled ? {
592
+ backgroundColor: theme.colors.control.input.bgHover
593
+ } : void 0,
594
+ style: {
595
+ opacity: disabled ? 0.5 : 1,
596
+ cursor: disabled ? "not-allowed" : "pointer"
597
+ },
598
+ children: [
599
+ icon && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Box, { marginRight: 12, alignItems: "center", justifyContent: "center", children: icon }),
600
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
601
+ Text,
602
+ {
603
+ color: active ? theme.colors.content.primary : theme.colors.content.secondary,
604
+ fontSize: 14,
605
+ fontWeight: active ? "600" : "400",
606
+ children
607
+ }
608
+ )
609
+ ]
610
+ }
611
+ );
612
+ };
613
+ // Annotate the CommonJS export names for ESM import in node:
614
+ 0 && (module.exports = {
615
+ Dropdown,
616
+ DropdownItem
617
+ });
618
+ //# sourceMappingURL=index.js.map