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