@xsolla/xui-slider 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,15 @@
1
+ import React from 'react';
2
+
3
+ interface SliderProps {
4
+ value?: number;
5
+ min?: number;
6
+ max?: number;
7
+ step?: number;
8
+ onChange?: (value: number) => void;
9
+ size?: "s" | "m" | "l" | "xl";
10
+ disabled?: boolean;
11
+ label?: string;
12
+ }
13
+ declare const Slider: React.FC<SliderProps>;
14
+
15
+ export { Slider, type SliderProps };
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+
3
+ interface SliderProps {
4
+ value?: number;
5
+ min?: number;
6
+ max?: number;
7
+ step?: number;
8
+ onChange?: (value: number) => void;
9
+ size?: "s" | "m" | "l" | "xl";
10
+ disabled?: boolean;
11
+ label?: string;
12
+ }
13
+ declare const Slider: React.FC<SliderProps>;
14
+
15
+ export { Slider, type SliderProps };
@@ -0,0 +1,609 @@
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
+ Slider: () => Slider
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // src/Slider.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
+
278
+ // ../primitives-native/src/Divider.tsx
279
+ var import_react_native5 = require("react-native");
280
+ var import_jsx_runtime5 = require("react/jsx-runtime");
281
+
282
+ // ../primitives-native/src/Input.tsx
283
+ var import_react2 = require("react");
284
+ var import_react_native6 = require("react-native");
285
+ var import_jsx_runtime6 = require("react/jsx-runtime");
286
+ var keyboardTypeMap = {
287
+ text: "default",
288
+ number: "numeric",
289
+ email: "email-address",
290
+ tel: "phone-pad",
291
+ url: "url",
292
+ decimal: "decimal-pad"
293
+ };
294
+ var inputModeToKeyboardType = {
295
+ none: "default",
296
+ text: "default",
297
+ decimal: "decimal-pad",
298
+ numeric: "number-pad",
299
+ tel: "phone-pad",
300
+ search: "default",
301
+ email: "email-address",
302
+ url: "url"
303
+ };
304
+ var autoCompleteToTextContentType = {
305
+ "one-time-code": "oneTimeCode",
306
+ email: "emailAddress",
307
+ username: "username",
308
+ password: "password",
309
+ "new-password": "newPassword",
310
+ tel: "telephoneNumber",
311
+ "postal-code": "postalCode",
312
+ name: "name"
313
+ };
314
+ var InputPrimitive = (0, import_react2.forwardRef)(
315
+ ({
316
+ value,
317
+ placeholder,
318
+ onChange,
319
+ onChangeText,
320
+ onFocus,
321
+ onBlur,
322
+ onKeyDown,
323
+ disabled,
324
+ secureTextEntry,
325
+ style,
326
+ color,
327
+ fontSize,
328
+ placeholderTextColor,
329
+ maxLength,
330
+ name,
331
+ type,
332
+ inputMode,
333
+ autoComplete,
334
+ id,
335
+ "aria-invalid": ariaInvalid,
336
+ "aria-describedby": ariaDescribedBy,
337
+ "aria-labelledby": ariaLabelledBy,
338
+ "aria-label": ariaLabel,
339
+ "aria-disabled": ariaDisabled,
340
+ "data-testid": dataTestId
341
+ }, ref) => {
342
+ const handleChangeText = (text) => {
343
+ onChangeText?.(text);
344
+ if (onChange) {
345
+ const syntheticEvent = {
346
+ target: { value: text },
347
+ currentTarget: { value: text },
348
+ type: "change",
349
+ nativeEvent: { text },
350
+ preventDefault: () => {
351
+ },
352
+ stopPropagation: () => {
353
+ },
354
+ isTrusted: false
355
+ };
356
+ onChange(syntheticEvent);
357
+ }
358
+ };
359
+ const keyboardType = inputMode ? inputModeToKeyboardType[inputMode] || "default" : type ? keyboardTypeMap[type] || "default" : "default";
360
+ const textContentType = autoComplete ? autoCompleteToTextContentType[autoComplete] : void 0;
361
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
362
+ import_react_native6.TextInput,
363
+ {
364
+ ref,
365
+ value,
366
+ placeholder,
367
+ onChangeText: handleChangeText,
368
+ onFocus,
369
+ onBlur,
370
+ onKeyPress: (e) => {
371
+ if (onKeyDown) {
372
+ onKeyDown({
373
+ key: e.nativeEvent.key,
374
+ preventDefault: () => {
375
+ }
376
+ });
377
+ }
378
+ },
379
+ editable: !disabled,
380
+ secureTextEntry: secureTextEntry || type === "password",
381
+ keyboardType,
382
+ textContentType,
383
+ style: [
384
+ {
385
+ color,
386
+ fontSize: typeof fontSize === "number" ? fontSize : void 0,
387
+ flex: 1,
388
+ padding: 0,
389
+ textAlign: style?.textAlign || "left"
390
+ },
391
+ style
392
+ ],
393
+ placeholderTextColor,
394
+ maxLength,
395
+ testID: dataTestId || id,
396
+ accessibilityLabel: ariaLabel,
397
+ accessibilityHint: ariaDescribedBy,
398
+ accessibilityState: {
399
+ disabled: disabled || ariaDisabled
400
+ },
401
+ accessible: true
402
+ }
403
+ );
404
+ }
405
+ );
406
+ InputPrimitive.displayName = "InputPrimitive";
407
+
408
+ // ../primitives-native/src/TextArea.tsx
409
+ var import_react3 = require("react");
410
+ var import_react_native7 = require("react-native");
411
+ var import_jsx_runtime7 = require("react/jsx-runtime");
412
+ var TextAreaPrimitive = (0, import_react3.forwardRef)(
413
+ ({
414
+ value,
415
+ placeholder,
416
+ onChange,
417
+ onChangeText,
418
+ onFocus,
419
+ onBlur,
420
+ onKeyDown,
421
+ disabled,
422
+ style,
423
+ color,
424
+ fontSize,
425
+ placeholderTextColor,
426
+ maxLength,
427
+ rows,
428
+ id,
429
+ "aria-invalid": ariaInvalid,
430
+ "aria-describedby": ariaDescribedBy,
431
+ "aria-labelledby": ariaLabelledBy,
432
+ "aria-label": ariaLabel,
433
+ "aria-disabled": ariaDisabled,
434
+ "data-testid": dataTestId
435
+ }, ref) => {
436
+ const handleChangeText = (text) => {
437
+ onChangeText?.(text);
438
+ if (onChange) {
439
+ const syntheticEvent = {
440
+ target: { value: text },
441
+ currentTarget: { value: text },
442
+ type: "change",
443
+ nativeEvent: { text },
444
+ preventDefault: () => {
445
+ },
446
+ stopPropagation: () => {
447
+ },
448
+ isTrusted: false
449
+ };
450
+ onChange(syntheticEvent);
451
+ }
452
+ };
453
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
454
+ import_react_native7.TextInput,
455
+ {
456
+ ref,
457
+ value,
458
+ placeholder,
459
+ onChangeText: handleChangeText,
460
+ onFocus,
461
+ onBlur,
462
+ onKeyPress: (e) => {
463
+ if (onKeyDown) {
464
+ onKeyDown({
465
+ key: e.nativeEvent.key,
466
+ preventDefault: () => {
467
+ }
468
+ });
469
+ }
470
+ },
471
+ editable: !disabled,
472
+ multiline: true,
473
+ numberOfLines: rows || 4,
474
+ style: [
475
+ {
476
+ color,
477
+ fontSize: typeof fontSize === "number" ? fontSize : void 0,
478
+ flex: 1,
479
+ padding: 0,
480
+ textAlignVertical: "top",
481
+ textAlign: style?.textAlign || "left"
482
+ },
483
+ style
484
+ ],
485
+ placeholderTextColor,
486
+ maxLength,
487
+ testID: dataTestId || id,
488
+ accessibilityLabel: ariaLabel,
489
+ accessibilityHint: ariaDescribedBy,
490
+ accessibilityState: {
491
+ disabled: disabled || ariaDisabled
492
+ },
493
+ accessible: true
494
+ }
495
+ );
496
+ }
497
+ );
498
+ TextAreaPrimitive.displayName = "TextAreaPrimitive";
499
+
500
+ // src/Slider.tsx
501
+ var import_xui_core = require("@xsolla/xui-core");
502
+ var import_jsx_runtime8 = require("react/jsx-runtime");
503
+ var Slider = ({
504
+ value: propValue = 0,
505
+ min = 0,
506
+ max = 100,
507
+ step = 1,
508
+ onChange,
509
+ size = "m",
510
+ disabled = false,
511
+ label
512
+ }) => {
513
+ const { theme } = (0, import_xui_core.useDesignSystem)();
514
+ const [value, setValue] = (0, import_react4.useState)(propValue);
515
+ const trackRef = (0, import_react4.useRef)(null);
516
+ (0, import_react4.useEffect)(() => {
517
+ setValue(propValue);
518
+ }, [propValue]);
519
+ const sizing = theme.sizing.slider?.(size) || {
520
+ trackHeight: 6,
521
+ thumbSize: 20,
522
+ fontSize: 14
523
+ };
524
+ const calculateValue = (clientX) => {
525
+ if (!trackRef.current) return value;
526
+ const rect = trackRef.current.getBoundingClientRect();
527
+ const percentage2 = Math.max(
528
+ 0,
529
+ Math.min(1, (clientX - rect.left) / rect.width)
530
+ );
531
+ const rawValue = min + percentage2 * (max - min);
532
+ return Math.round(rawValue / step) * step;
533
+ };
534
+ const handleMove = (e) => {
535
+ if (disabled) return;
536
+ const newValue = calculateValue(
537
+ e.clientX || e.touches && e.touches[0].clientX
538
+ );
539
+ setValue(newValue);
540
+ if (onChange) onChange(newValue);
541
+ };
542
+ const handleMouseDown = (e) => {
543
+ if (disabled) return;
544
+ handleMove(e);
545
+ const onMouseMove = (moveEvent) => handleMove(moveEvent);
546
+ const onMouseUp = () => {
547
+ document.removeEventListener("mousemove", onMouseMove);
548
+ document.removeEventListener("mouseup", onMouseUp);
549
+ };
550
+ document.addEventListener("mousemove", onMouseMove);
551
+ document.addEventListener("mouseup", onMouseUp);
552
+ };
553
+ const percentage = (value - min) / (max - min) * 100;
554
+ const checkColors = theme.colors.control.check;
555
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Box, { flexDirection: "column", gap: 8, width: "100%", children: [
556
+ label && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { color: theme.colors.content.secondary, fontSize: sizing.fontSize, children: label }),
557
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
558
+ Box,
559
+ {
560
+ ref: trackRef,
561
+ height: sizing.trackHeight,
562
+ backgroundColor: theme.colors.background.secondary,
563
+ borderRadius: sizing.trackHeight / 2,
564
+ width: "100%",
565
+ position: "relative",
566
+ onPress: handleMouseDown,
567
+ style: { cursor: disabled ? "not-allowed" : "pointer" },
568
+ children: [
569
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
570
+ Box,
571
+ {
572
+ position: "absolute",
573
+ left: 0,
574
+ top: 0,
575
+ height: "100%",
576
+ width: `${percentage}%`,
577
+ backgroundColor: disabled ? checkColors.bgDisable : checkColors.bg,
578
+ borderRadius: sizing.trackHeight / 2
579
+ }
580
+ ),
581
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
582
+ Box,
583
+ {
584
+ position: "absolute",
585
+ left: `${percentage}%`,
586
+ top: "50%",
587
+ width: sizing.thumbSize,
588
+ height: sizing.thumbSize,
589
+ backgroundColor: theme.colors.background.primary,
590
+ borderColor: disabled ? checkColors.bgDisable : checkColors.bg,
591
+ borderWidth: 2,
592
+ borderRadius: sizing.thumbSize / 2,
593
+ style: {
594
+ transform: `translate(-50%, -50%)`,
595
+ boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
596
+ zIndex: 2
597
+ }
598
+ }
599
+ )
600
+ ]
601
+ }
602
+ )
603
+ ] });
604
+ };
605
+ // Annotate the CommonJS export names for ESM import in node:
606
+ 0 && (module.exports = {
607
+ Slider
608
+ });
609
+ //# sourceMappingURL=index.js.map