@xsolla/xui-segmented-native 0.64.0-pr56.1768348754

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/index.js ADDED
@@ -0,0 +1,661 @@
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
+ Segmented: () => Segmented
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // src/Segmented.tsx
38
+ var import_react4 = require("react");
39
+
40
+ // ../primitives-native/src/Box.tsx
41
+ var import_react_native = require("react-native");
42
+ var import_jsx_runtime = require("react/jsx-runtime");
43
+ var Box = ({
44
+ children,
45
+ onPress,
46
+ onLayout,
47
+ onMoveShouldSetResponder,
48
+ onResponderGrant,
49
+ onResponderMove,
50
+ onResponderRelease,
51
+ onResponderTerminate,
52
+ backgroundColor,
53
+ borderColor,
54
+ borderWidth,
55
+ borderBottomWidth,
56
+ borderBottomColor,
57
+ borderTopWidth,
58
+ borderTopColor,
59
+ borderLeftWidth,
60
+ borderLeftColor,
61
+ borderRightWidth,
62
+ borderRightColor,
63
+ borderRadius,
64
+ borderStyle,
65
+ height,
66
+ padding,
67
+ paddingHorizontal,
68
+ paddingVertical,
69
+ margin,
70
+ marginTop,
71
+ marginBottom,
72
+ marginLeft,
73
+ marginRight,
74
+ flexDirection,
75
+ alignItems,
76
+ justifyContent,
77
+ position,
78
+ top,
79
+ bottom,
80
+ left,
81
+ right,
82
+ width,
83
+ flex,
84
+ overflow,
85
+ zIndex,
86
+ hoverStyle,
87
+ pressStyle,
88
+ style,
89
+ "data-testid": dataTestId,
90
+ testID,
91
+ as,
92
+ src,
93
+ alt,
94
+ ...rest
95
+ }) => {
96
+ const getContainerStyle = (pressed) => ({
97
+ backgroundColor: pressed && pressStyle?.backgroundColor ? pressStyle.backgroundColor : backgroundColor,
98
+ borderColor,
99
+ borderWidth,
100
+ borderBottomWidth,
101
+ borderBottomColor,
102
+ borderTopWidth,
103
+ borderTopColor,
104
+ borderLeftWidth,
105
+ borderLeftColor,
106
+ borderRightWidth,
107
+ borderRightColor,
108
+ borderRadius,
109
+ borderStyle,
110
+ overflow,
111
+ zIndex,
112
+ height,
113
+ width,
114
+ padding,
115
+ paddingHorizontal,
116
+ paddingVertical,
117
+ margin,
118
+ marginTop,
119
+ marginBottom,
120
+ marginLeft,
121
+ marginRight,
122
+ flexDirection,
123
+ alignItems,
124
+ justifyContent,
125
+ position,
126
+ top,
127
+ bottom,
128
+ left,
129
+ right,
130
+ flex,
131
+ ...style
132
+ });
133
+ const finalTestID = dataTestId || testID;
134
+ const {
135
+ role,
136
+ tabIndex,
137
+ onKeyDown,
138
+ onKeyUp,
139
+ "aria-label": _ariaLabel,
140
+ "aria-labelledby": _ariaLabelledBy,
141
+ "aria-current": _ariaCurrent,
142
+ "aria-disabled": _ariaDisabled,
143
+ "aria-live": _ariaLive,
144
+ className,
145
+ "data-testid": _dataTestId,
146
+ ...nativeRest
147
+ } = rest;
148
+ if (as === "img" && src) {
149
+ const imageStyle = {
150
+ width,
151
+ height,
152
+ borderRadius,
153
+ position,
154
+ top,
155
+ bottom,
156
+ left,
157
+ right,
158
+ ...style
159
+ };
160
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
161
+ import_react_native.Image,
162
+ {
163
+ source: { uri: src },
164
+ style: imageStyle,
165
+ testID: finalTestID,
166
+ resizeMode: "cover",
167
+ ...nativeRest
168
+ }
169
+ );
170
+ }
171
+ if (onPress) {
172
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
173
+ import_react_native.Pressable,
174
+ {
175
+ onPress,
176
+ onLayout,
177
+ onMoveShouldSetResponder,
178
+ onResponderGrant,
179
+ onResponderMove,
180
+ onResponderRelease,
181
+ onResponderTerminate,
182
+ style: ({ pressed }) => getContainerStyle(pressed),
183
+ testID: finalTestID,
184
+ ...nativeRest,
185
+ children
186
+ }
187
+ );
188
+ }
189
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
190
+ import_react_native.View,
191
+ {
192
+ style: getContainerStyle(),
193
+ testID: finalTestID,
194
+ onLayout,
195
+ onMoveShouldSetResponder,
196
+ onResponderGrant,
197
+ onResponderMove,
198
+ onResponderRelease,
199
+ onResponderTerminate,
200
+ ...nativeRest,
201
+ children
202
+ }
203
+ );
204
+ };
205
+
206
+ // ../primitives-native/src/Text.tsx
207
+ var import_react_native2 = require("react-native");
208
+ var import_jsx_runtime2 = require("react/jsx-runtime");
209
+ var roleMap = {
210
+ alert: "alert",
211
+ heading: "header",
212
+ button: "button",
213
+ link: "link",
214
+ text: "text"
215
+ };
216
+ var Text = ({
217
+ children,
218
+ color,
219
+ fontSize,
220
+ fontWeight,
221
+ fontFamily,
222
+ id,
223
+ role,
224
+ ...props
225
+ }) => {
226
+ let resolvedFontFamily = fontFamily ? fontFamily.split(",")[0].replace(/['"]/g, "").trim() : void 0;
227
+ if (resolvedFontFamily === "Pilat Wide Bold") {
228
+ resolvedFontFamily = void 0;
229
+ }
230
+ const style = {
231
+ color,
232
+ fontSize: typeof fontSize === "number" ? fontSize : void 0,
233
+ fontWeight,
234
+ fontFamily: resolvedFontFamily,
235
+ textDecorationLine: props.textDecoration
236
+ };
237
+ const accessibilityRole = role ? roleMap[role] : void 0;
238
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Text, { style, testID: id, accessibilityRole, children });
239
+ };
240
+
241
+ // ../primitives-native/src/Spinner.tsx
242
+ var import_react_native3 = require("react-native");
243
+ var import_jsx_runtime3 = require("react/jsx-runtime");
244
+ var Spinner = ({
245
+ color,
246
+ size,
247
+ role,
248
+ "aria-label": ariaLabel,
249
+ "aria-live": ariaLive,
250
+ "aria-describedby": ariaDescribedBy,
251
+ testID
252
+ }) => {
253
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
254
+ import_react_native3.View,
255
+ {
256
+ accessible: true,
257
+ accessibilityRole: role === "status" ? "none" : void 0,
258
+ accessibilityLabel: ariaLabel,
259
+ accessibilityLiveRegion: ariaLive === "polite" ? "polite" : ariaLive === "assertive" ? "assertive" : "none",
260
+ testID,
261
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
262
+ import_react_native3.ActivityIndicator,
263
+ {
264
+ color,
265
+ size: typeof size === "number" ? size : "small"
266
+ }
267
+ )
268
+ }
269
+ );
270
+ };
271
+ Spinner.displayName = "Spinner";
272
+
273
+ // ../primitives-native/src/Icon.tsx
274
+ var import_react = __toESM(require("react"));
275
+ var import_react_native4 = require("react-native");
276
+ var import_jsx_runtime4 = require("react/jsx-runtime");
277
+ var Icon = ({ children, color, size }) => {
278
+ const style = {
279
+ width: typeof size === "number" ? size : void 0,
280
+ height: typeof size === "number" ? size : void 0,
281
+ alignItems: "center",
282
+ justifyContent: "center"
283
+ };
284
+ const childrenWithProps = import_react.default.Children.map(children, (child) => {
285
+ if (import_react.default.isValidElement(child)) {
286
+ return import_react.default.cloneElement(child, {
287
+ color: child.props.color || color,
288
+ // Also pass size if child seems to be an icon that needs it
289
+ size: child.props.size || size
290
+ });
291
+ }
292
+ return child;
293
+ });
294
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native4.View, { style, children: childrenWithProps });
295
+ };
296
+
297
+ // ../primitives-native/src/Divider.tsx
298
+ var import_react_native5 = require("react-native");
299
+ var import_jsx_runtime5 = require("react/jsx-runtime");
300
+
301
+ // ../primitives-native/src/Input.tsx
302
+ var import_react2 = require("react");
303
+ var import_react_native6 = require("react-native");
304
+ var import_jsx_runtime6 = require("react/jsx-runtime");
305
+ var keyboardTypeMap = {
306
+ text: "default",
307
+ number: "numeric",
308
+ email: "email-address",
309
+ tel: "phone-pad",
310
+ url: "url",
311
+ decimal: "decimal-pad"
312
+ };
313
+ var inputModeToKeyboardType = {
314
+ none: "default",
315
+ text: "default",
316
+ decimal: "decimal-pad",
317
+ numeric: "number-pad",
318
+ tel: "phone-pad",
319
+ search: "default",
320
+ email: "email-address",
321
+ url: "url"
322
+ };
323
+ var autoCompleteToTextContentType = {
324
+ "one-time-code": "oneTimeCode",
325
+ email: "emailAddress",
326
+ username: "username",
327
+ password: "password",
328
+ "new-password": "newPassword",
329
+ tel: "telephoneNumber",
330
+ "postal-code": "postalCode",
331
+ name: "name"
332
+ };
333
+ var InputPrimitive = (0, import_react2.forwardRef)(
334
+ ({
335
+ value,
336
+ placeholder,
337
+ onChange,
338
+ onChangeText,
339
+ onFocus,
340
+ onBlur,
341
+ onKeyDown,
342
+ disabled,
343
+ secureTextEntry,
344
+ style,
345
+ color,
346
+ fontSize,
347
+ placeholderTextColor,
348
+ maxLength,
349
+ name,
350
+ type,
351
+ inputMode,
352
+ autoComplete,
353
+ id,
354
+ "aria-invalid": ariaInvalid,
355
+ "aria-describedby": ariaDescribedBy,
356
+ "aria-labelledby": ariaLabelledBy,
357
+ "aria-label": ariaLabel,
358
+ "aria-disabled": ariaDisabled,
359
+ "data-testid": dataTestId
360
+ }, ref) => {
361
+ const handleChangeText = (text) => {
362
+ onChangeText?.(text);
363
+ if (onChange) {
364
+ const syntheticEvent = {
365
+ target: { value: text },
366
+ currentTarget: { value: text },
367
+ type: "change",
368
+ nativeEvent: { text },
369
+ preventDefault: () => {
370
+ },
371
+ stopPropagation: () => {
372
+ },
373
+ isTrusted: false
374
+ };
375
+ onChange(syntheticEvent);
376
+ }
377
+ };
378
+ const keyboardType = inputMode ? inputModeToKeyboardType[inputMode] || "default" : type ? keyboardTypeMap[type] || "default" : "default";
379
+ const textContentType = autoComplete ? autoCompleteToTextContentType[autoComplete] : void 0;
380
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
381
+ import_react_native6.TextInput,
382
+ {
383
+ ref,
384
+ value,
385
+ placeholder,
386
+ onChangeText: handleChangeText,
387
+ onFocus,
388
+ onBlur,
389
+ onKeyPress: (e) => {
390
+ if (onKeyDown) {
391
+ onKeyDown({
392
+ key: e.nativeEvent.key,
393
+ preventDefault: () => {
394
+ }
395
+ });
396
+ }
397
+ },
398
+ editable: !disabled,
399
+ secureTextEntry: secureTextEntry || type === "password",
400
+ keyboardType,
401
+ textContentType,
402
+ style: [
403
+ {
404
+ color,
405
+ fontSize: typeof fontSize === "number" ? fontSize : void 0,
406
+ flex: 1,
407
+ padding: 0,
408
+ textAlign: style?.textAlign || "left"
409
+ },
410
+ style
411
+ ],
412
+ placeholderTextColor,
413
+ maxLength,
414
+ testID: dataTestId || id,
415
+ accessibilityLabel: ariaLabel,
416
+ accessibilityHint: ariaDescribedBy,
417
+ accessibilityState: {
418
+ disabled: disabled || ariaDisabled
419
+ },
420
+ accessible: true
421
+ }
422
+ );
423
+ }
424
+ );
425
+ InputPrimitive.displayName = "InputPrimitive";
426
+
427
+ // ../primitives-native/src/TextArea.tsx
428
+ var import_react3 = require("react");
429
+ var import_react_native7 = require("react-native");
430
+ var import_jsx_runtime7 = require("react/jsx-runtime");
431
+ var TextAreaPrimitive = (0, import_react3.forwardRef)(
432
+ ({
433
+ value,
434
+ placeholder,
435
+ onChange,
436
+ onChangeText,
437
+ onFocus,
438
+ onBlur,
439
+ onKeyDown,
440
+ disabled,
441
+ style,
442
+ color,
443
+ fontSize,
444
+ placeholderTextColor,
445
+ maxLength,
446
+ rows,
447
+ id,
448
+ "aria-invalid": ariaInvalid,
449
+ "aria-describedby": ariaDescribedBy,
450
+ "aria-labelledby": ariaLabelledBy,
451
+ "aria-label": ariaLabel,
452
+ "aria-disabled": ariaDisabled,
453
+ "data-testid": dataTestId
454
+ }, ref) => {
455
+ const handleChangeText = (text) => {
456
+ onChangeText?.(text);
457
+ if (onChange) {
458
+ const syntheticEvent = {
459
+ target: { value: text },
460
+ currentTarget: { value: text },
461
+ type: "change",
462
+ nativeEvent: { text },
463
+ preventDefault: () => {
464
+ },
465
+ stopPropagation: () => {
466
+ },
467
+ isTrusted: false
468
+ };
469
+ onChange(syntheticEvent);
470
+ }
471
+ };
472
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
473
+ import_react_native7.TextInput,
474
+ {
475
+ ref,
476
+ value,
477
+ placeholder,
478
+ onChangeText: handleChangeText,
479
+ onFocus,
480
+ onBlur,
481
+ onKeyPress: (e) => {
482
+ if (onKeyDown) {
483
+ onKeyDown({
484
+ key: e.nativeEvent.key,
485
+ preventDefault: () => {
486
+ }
487
+ });
488
+ }
489
+ },
490
+ editable: !disabled,
491
+ multiline: true,
492
+ numberOfLines: rows || 4,
493
+ style: [
494
+ {
495
+ color,
496
+ fontSize: typeof fontSize === "number" ? fontSize : void 0,
497
+ flex: 1,
498
+ padding: 0,
499
+ textAlignVertical: "top",
500
+ textAlign: style?.textAlign || "left"
501
+ },
502
+ style
503
+ ],
504
+ placeholderTextColor,
505
+ maxLength,
506
+ testID: dataTestId || id,
507
+ accessibilityLabel: ariaLabel,
508
+ accessibilityHint: ariaDescribedBy,
509
+ accessibilityState: {
510
+ disabled: disabled || ariaDisabled
511
+ },
512
+ accessible: true
513
+ }
514
+ );
515
+ }
516
+ );
517
+ TextAreaPrimitive.displayName = "TextAreaPrimitive";
518
+
519
+ // src/Segmented.tsx
520
+ var import_xui_core = require("@xsolla/xui-core");
521
+ var import_jsx_runtime8 = require("react/jsx-runtime");
522
+ var Segmented = ({
523
+ items,
524
+ activeId,
525
+ onChange,
526
+ size = "m",
527
+ stroke = false,
528
+ id,
529
+ testID,
530
+ fullWidth = false
531
+ }) => {
532
+ const { theme } = (0, import_xui_core.useDesignSystem)();
533
+ const sizeStyles = theme.sizing.segmented(size);
534
+ const containerId = id ? `${id}-container` : void 0;
535
+ const itemRefs = (0, import_react4.useRef)([]);
536
+ const enabledIndices = items.map((item, index) => !item.disabled ? index : -1).filter((i) => i !== -1);
537
+ const focusItem = (0, import_react4.useCallback)((index) => {
538
+ const element = itemRefs.current[index];
539
+ if (element) {
540
+ element.focus();
541
+ }
542
+ }, []);
543
+ const handleKeyDown = (0, import_react4.useCallback)(
544
+ (e, currentIndex) => {
545
+ const currentEnabledIndex = enabledIndices.indexOf(currentIndex);
546
+ switch (e.key) {
547
+ case "ArrowRight":
548
+ case "ArrowDown":
549
+ e.preventDefault();
550
+ {
551
+ const nextEnabledIndex = currentEnabledIndex < enabledIndices.length - 1 ? enabledIndices[currentEnabledIndex + 1] : enabledIndices[0];
552
+ focusItem(nextEnabledIndex);
553
+ }
554
+ break;
555
+ case "ArrowLeft":
556
+ case "ArrowUp":
557
+ e.preventDefault();
558
+ {
559
+ const prevEnabledIndex = currentEnabledIndex > 0 ? enabledIndices[currentEnabledIndex - 1] : enabledIndices[enabledIndices.length - 1];
560
+ focusItem(prevEnabledIndex);
561
+ }
562
+ break;
563
+ case "Enter":
564
+ case " ":
565
+ e.preventDefault();
566
+ if (onChange && !items[currentIndex].disabled) {
567
+ onChange(items[currentIndex].id);
568
+ }
569
+ break;
570
+ default:
571
+ break;
572
+ }
573
+ },
574
+ [enabledIndices, focusItem, onChange, items]
575
+ );
576
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
577
+ Box,
578
+ {
579
+ id: containerId,
580
+ role: "radiogroup",
581
+ testID,
582
+ flexDirection: "row",
583
+ alignItems: "center",
584
+ flexShrink: 0,
585
+ width: fullWidth ? "100%" : "fit-content",
586
+ height: sizeStyles.height,
587
+ backgroundColor: theme.colors.overlay.mono,
588
+ borderRadius: theme.radius.button,
589
+ padding: stroke ? 1 : 0,
590
+ borderWidth: stroke ? 1 : 0,
591
+ borderColor: theme.colors.border.secondary,
592
+ borderStyle: "solid",
593
+ overflow: "hidden",
594
+ children: items.map((item, index) => {
595
+ const isActive = item.id === activeId;
596
+ const isDisabled = item.disabled;
597
+ const itemId = id ? `${id}-item-${item.id}` : void 0;
598
+ const handlePress = () => {
599
+ if (!isDisabled && onChange) {
600
+ onChange(item.id);
601
+ }
602
+ };
603
+ const textColor = isDisabled ? theme.colors.content.tertiary : isActive ? theme.colors.content.primary : theme.colors.content.secondary;
604
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
605
+ Box,
606
+ {
607
+ as: "button",
608
+ role: "radio",
609
+ id: itemId,
610
+ "aria-checked": isActive,
611
+ "aria-disabled": isDisabled,
612
+ "aria-label": item["aria-label"] || item.label,
613
+ tabIndex: isActive ? 0 : -1,
614
+ disabled: isDisabled,
615
+ ref: (el) => {
616
+ itemRefs.current[index] = el;
617
+ },
618
+ onPress: handlePress,
619
+ onKeyDown: (e) => handleKeyDown(e, index),
620
+ flex: fullWidth ? 1 : void 0,
621
+ flexShrink: 0,
622
+ height: "100%",
623
+ paddingHorizontal: sizeStyles.padding,
624
+ flexDirection: "row",
625
+ alignItems: "center",
626
+ justifyContent: "center",
627
+ gap: 8,
628
+ backgroundColor: isActive ? theme.colors.background.primary : "transparent",
629
+ borderRadius: isActive ? theme.radius.button - (stroke ? 1 : 0) : 0,
630
+ cursor: isDisabled ? "not-allowed" : "pointer",
631
+ boxShadow: isActive ? "0px 1px 2px rgba(0, 0, 0, 0.1)" : "none",
632
+ hoverStyle: !isDisabled && !isActive ? {
633
+ backgroundColor: theme.colors.overlay.mono
634
+ } : void 0,
635
+ children: [
636
+ item.icon && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { size: sizeStyles.iconSize, color: textColor, "aria-hidden": true, children: item.icon }),
637
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
638
+ Text,
639
+ {
640
+ color: textColor,
641
+ fontSize: sizeStyles.fontSize,
642
+ fontWeight: isActive ? "600" : "500",
643
+ textAlign: "center",
644
+ whiteSpace: "nowrap",
645
+ children: item.label
646
+ }
647
+ )
648
+ ]
649
+ },
650
+ item.id
651
+ );
652
+ })
653
+ }
654
+ );
655
+ };
656
+ Segmented.displayName = "Segmented";
657
+ // Annotate the CommonJS export names for ESM import in node:
658
+ 0 && (module.exports = {
659
+ Segmented
660
+ });
661
+ //# sourceMappingURL=index.js.map