@xsolla/xui-checkbox 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.
- package/native/index.d.mts +44 -0
- package/native/index.d.ts +44 -0
- package/native/index.js +755 -0
- package/native/index.js.map +1 -0
- package/native/index.mjs +727 -0
- package/native/index.mjs.map +1 -0
- package/package.json +57 -0
- package/web/index.d.mts +44 -0
- package/web/index.d.ts +44 -0
- package/web/index.js +743 -0
- package/web/index.js.map +1 -0
- package/web/index.mjs +711 -0
- package/web/index.mjs.map +1 -0
package/native/index.js
ADDED
|
@@ -0,0 +1,755 @@
|
|
|
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
|
+
Checkbox: () => Checkbox
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/Checkbox.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/Checkbox.tsx
|
|
501
|
+
var import_xui_core = require("@xsolla/xui-core");
|
|
502
|
+
var import_xui_icons = require("@xsolla/xui-icons");
|
|
503
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
504
|
+
var iconSizeMap = {
|
|
505
|
+
s: 12,
|
|
506
|
+
m: 14,
|
|
507
|
+
l: 16,
|
|
508
|
+
xl: 18
|
|
509
|
+
};
|
|
510
|
+
var checkboxSizeMap = {
|
|
511
|
+
s: 16,
|
|
512
|
+
m: 18,
|
|
513
|
+
l: 20,
|
|
514
|
+
xl: 22
|
|
515
|
+
};
|
|
516
|
+
var labelGapMap = {
|
|
517
|
+
s: 8,
|
|
518
|
+
m: 8,
|
|
519
|
+
l: 10,
|
|
520
|
+
xl: 12
|
|
521
|
+
};
|
|
522
|
+
var textGapMap = {
|
|
523
|
+
s: 0,
|
|
524
|
+
m: 2,
|
|
525
|
+
l: 2,
|
|
526
|
+
xl: 4
|
|
527
|
+
};
|
|
528
|
+
var fontSizeMap = {
|
|
529
|
+
s: 14,
|
|
530
|
+
m: 16,
|
|
531
|
+
l: 18,
|
|
532
|
+
xl: 18
|
|
533
|
+
};
|
|
534
|
+
var lineHeightMap = {
|
|
535
|
+
s: 16,
|
|
536
|
+
m: 18,
|
|
537
|
+
l: 20,
|
|
538
|
+
xl: 22
|
|
539
|
+
};
|
|
540
|
+
var descriptionFontSizeMap = {
|
|
541
|
+
s: 12,
|
|
542
|
+
m: 14,
|
|
543
|
+
l: 16,
|
|
544
|
+
xl: 16
|
|
545
|
+
};
|
|
546
|
+
var descriptionLineHeightMap = {
|
|
547
|
+
s: 14,
|
|
548
|
+
m: 16,
|
|
549
|
+
l: 18,
|
|
550
|
+
xl: 18
|
|
551
|
+
};
|
|
552
|
+
var Checkbox = (0, import_react4.forwardRef)(
|
|
553
|
+
function Checkbox2({
|
|
554
|
+
children,
|
|
555
|
+
size = "m",
|
|
556
|
+
checked,
|
|
557
|
+
indeterminate = false,
|
|
558
|
+
description,
|
|
559
|
+
errorMessage,
|
|
560
|
+
error,
|
|
561
|
+
disabled,
|
|
562
|
+
name,
|
|
563
|
+
value,
|
|
564
|
+
onChange,
|
|
565
|
+
id: providedId,
|
|
566
|
+
"aria-label": ariaLabel
|
|
567
|
+
}, ref) {
|
|
568
|
+
const { theme } = (0, import_xui_core.useDesignSystem)();
|
|
569
|
+
const containerRef = (0, import_react4.useRef)(null);
|
|
570
|
+
const [internalChecked, setInternalChecked] = (0, import_react4.useState)(false);
|
|
571
|
+
const rawId = (0, import_xui_core.useId)();
|
|
572
|
+
const safeId = rawId.replace(/:/g, "");
|
|
573
|
+
const checkboxId = providedId || `checkbox-${safeId}`;
|
|
574
|
+
const labelId = `${checkboxId}-label`;
|
|
575
|
+
const descriptionId = `${checkboxId}-description`;
|
|
576
|
+
const errorId = `${checkboxId}-error`;
|
|
577
|
+
const isControlled = checked !== void 0;
|
|
578
|
+
const isChecked = isControlled ? checked : internalChecked;
|
|
579
|
+
(0, import_react4.useImperativeHandle)(
|
|
580
|
+
ref,
|
|
581
|
+
() => ({
|
|
582
|
+
focus: () => containerRef.current?.focus(),
|
|
583
|
+
blur: () => containerRef.current?.blur()
|
|
584
|
+
}),
|
|
585
|
+
[]
|
|
586
|
+
);
|
|
587
|
+
const handleToggle = () => {
|
|
588
|
+
if (disabled) return;
|
|
589
|
+
const newChecked = indeterminate ? true : !isChecked;
|
|
590
|
+
if (!isControlled) {
|
|
591
|
+
setInternalChecked(newChecked);
|
|
592
|
+
}
|
|
593
|
+
onChange?.({
|
|
594
|
+
target: {
|
|
595
|
+
checked: newChecked,
|
|
596
|
+
name,
|
|
597
|
+
value
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
};
|
|
601
|
+
const handleKeyDown = (event) => {
|
|
602
|
+
const key = event.key;
|
|
603
|
+
const isSpace = key === " " || key === "Spacebar" || key === "Space";
|
|
604
|
+
if (isSpace || key === "Enter") {
|
|
605
|
+
event.preventDefault();
|
|
606
|
+
handleToggle();
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
const isError = !!(errorMessage || error);
|
|
610
|
+
const hasTexts = !!children || !!description;
|
|
611
|
+
const isShowErrorMessage = !!errorMessage && hasTexts;
|
|
612
|
+
const isCheckedOrIndeterminate = isChecked || indeterminate;
|
|
613
|
+
const ariaDescribedByParts = [];
|
|
614
|
+
if (description) ariaDescribedByParts.push(descriptionId);
|
|
615
|
+
if (isShowErrorMessage) ariaDescribedByParts.push(errorId);
|
|
616
|
+
const ariaDescribedBy = ariaDescribedByParts.length > 0 ? ariaDescribedByParts.join(" ") : void 0;
|
|
617
|
+
const checkColors = theme.colors.control.check;
|
|
618
|
+
const faintColors = theme.colors.control.faint;
|
|
619
|
+
const textColors = theme.colors.control.text;
|
|
620
|
+
const contentColors = theme.colors.content;
|
|
621
|
+
const borderColors = theme.colors.border;
|
|
622
|
+
const getCheckboxBgColor = () => {
|
|
623
|
+
if (disabled) {
|
|
624
|
+
return checkColors.bgDisable;
|
|
625
|
+
}
|
|
626
|
+
if (isCheckedOrIndeterminate) {
|
|
627
|
+
return checkColors.bg;
|
|
628
|
+
}
|
|
629
|
+
return faintColors.bg;
|
|
630
|
+
};
|
|
631
|
+
const getBorderColor = () => {
|
|
632
|
+
if (isError && !isCheckedOrIndeterminate) {
|
|
633
|
+
return borderColors.alert;
|
|
634
|
+
}
|
|
635
|
+
if (isCheckedOrIndeterminate && !disabled) {
|
|
636
|
+
return checkColors.bg;
|
|
637
|
+
}
|
|
638
|
+
return faintColors.border;
|
|
639
|
+
};
|
|
640
|
+
const getLabelColor = () => {
|
|
641
|
+
if (disabled) return textColors.disable;
|
|
642
|
+
return textColors.primary;
|
|
643
|
+
};
|
|
644
|
+
const getDescriptionColor = () => {
|
|
645
|
+
if (disabled) return textColors.disable;
|
|
646
|
+
return contentColors.tertiary;
|
|
647
|
+
};
|
|
648
|
+
const getErrorMessageColor = () => {
|
|
649
|
+
return contentColors.alert.primary;
|
|
650
|
+
};
|
|
651
|
+
const getIconColor = () => {
|
|
652
|
+
if (disabled) return textColors.disable;
|
|
653
|
+
return textColors.faint;
|
|
654
|
+
};
|
|
655
|
+
const getAriaChecked = () => {
|
|
656
|
+
if (indeterminate) return "mixed";
|
|
657
|
+
return isChecked ? "true" : "false";
|
|
658
|
+
};
|
|
659
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
660
|
+
Box,
|
|
661
|
+
{
|
|
662
|
+
id: checkboxId,
|
|
663
|
+
ref: containerRef,
|
|
664
|
+
flexDirection: "row",
|
|
665
|
+
alignItems: "flex-start",
|
|
666
|
+
gap: labelGapMap[size],
|
|
667
|
+
onPress: handleToggle,
|
|
668
|
+
disabled,
|
|
669
|
+
role: "checkbox",
|
|
670
|
+
"aria-checked": getAriaChecked(),
|
|
671
|
+
"aria-disabled": disabled || void 0,
|
|
672
|
+
"aria-invalid": isError || void 0,
|
|
673
|
+
"aria-describedby": ariaDescribedBy,
|
|
674
|
+
"aria-labelledby": children ? labelId : void 0,
|
|
675
|
+
"aria-label": !children ? ariaLabel : void 0,
|
|
676
|
+
tabIndex: disabled ? -1 : 0,
|
|
677
|
+
onKeyDown: handleKeyDown,
|
|
678
|
+
"data-testid": "checkbox",
|
|
679
|
+
children: [
|
|
680
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
681
|
+
Box,
|
|
682
|
+
{
|
|
683
|
+
width: checkboxSizeMap[size],
|
|
684
|
+
height: checkboxSizeMap[size],
|
|
685
|
+
backgroundColor: getCheckboxBgColor(),
|
|
686
|
+
borderColor: getBorderColor(),
|
|
687
|
+
borderWidth: 2,
|
|
688
|
+
borderRadius: 2,
|
|
689
|
+
alignItems: "center",
|
|
690
|
+
justifyContent: "center",
|
|
691
|
+
flexShrink: 0,
|
|
692
|
+
hoverStyle: !disabled ? {
|
|
693
|
+
backgroundColor: isCheckedOrIndeterminate ? checkColors.bgHover : faintColors.bgHover,
|
|
694
|
+
borderColor: isError && !isCheckedOrIndeterminate ? borderColors.alert : isCheckedOrIndeterminate ? checkColors.bgHover : faintColors.borderHover
|
|
695
|
+
} : void 0,
|
|
696
|
+
"data-testid": "checkbox__box",
|
|
697
|
+
children: isCheckedOrIndeterminate && (indeterminate ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_xui_icons.Minus, { size: iconSizeMap[size], color: getIconColor() }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_xui_icons.Check, { size: iconSizeMap[size], color: getIconColor() }))
|
|
698
|
+
}
|
|
699
|
+
),
|
|
700
|
+
hasTexts && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
701
|
+
Box,
|
|
702
|
+
{
|
|
703
|
+
flexDirection: "column",
|
|
704
|
+
alignItems: "flex-start",
|
|
705
|
+
gap: textGapMap[size],
|
|
706
|
+
children: [
|
|
707
|
+
children && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
708
|
+
Text,
|
|
709
|
+
{
|
|
710
|
+
id: labelId,
|
|
711
|
+
color: getLabelColor(),
|
|
712
|
+
fontSize: fontSizeMap[size],
|
|
713
|
+
lineHeight: lineHeightMap[size],
|
|
714
|
+
fontWeight: 400,
|
|
715
|
+
"data-testid": "checkbox__label",
|
|
716
|
+
children
|
|
717
|
+
}
|
|
718
|
+
),
|
|
719
|
+
description && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
720
|
+
Text,
|
|
721
|
+
{
|
|
722
|
+
id: descriptionId,
|
|
723
|
+
color: getDescriptionColor(),
|
|
724
|
+
fontSize: descriptionFontSizeMap[size],
|
|
725
|
+
lineHeight: descriptionLineHeightMap[size],
|
|
726
|
+
"data-testid": "checkbox__description",
|
|
727
|
+
children: description
|
|
728
|
+
}
|
|
729
|
+
),
|
|
730
|
+
isShowErrorMessage && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
731
|
+
Text,
|
|
732
|
+
{
|
|
733
|
+
id: errorId,
|
|
734
|
+
role: "alert",
|
|
735
|
+
color: getErrorMessageColor(),
|
|
736
|
+
fontSize: descriptionFontSizeMap[size],
|
|
737
|
+
lineHeight: descriptionLineHeightMap[size],
|
|
738
|
+
"data-testid": "checkbox__error",
|
|
739
|
+
children: errorMessage
|
|
740
|
+
}
|
|
741
|
+
)
|
|
742
|
+
]
|
|
743
|
+
}
|
|
744
|
+
)
|
|
745
|
+
]
|
|
746
|
+
}
|
|
747
|
+
);
|
|
748
|
+
}
|
|
749
|
+
);
|
|
750
|
+
Checkbox.displayName = "Checkbox";
|
|
751
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
752
|
+
0 && (module.exports = {
|
|
753
|
+
Checkbox
|
|
754
|
+
});
|
|
755
|
+
//# sourceMappingURL=index.js.map
|