@xaui/native 0.0.2 → 0.0.4

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,488 @@
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/components/checkbox/index.ts
31
+ var checkbox_exports = {};
32
+ __export(checkbox_exports, {
33
+ Checkbox: () => Checkbox
34
+ });
35
+ module.exports = __toCommonJS(checkbox_exports);
36
+
37
+ // src/components/checkbox/checkbox.tsx
38
+ var import_react5 = __toESM(require("react"), 1);
39
+ var import_react_native6 = require("react-native");
40
+
41
+ // src/components/checkbox/checkbox-icon.tsx
42
+ var import_react = __toESM(require("react"), 1);
43
+ var import_react_native2 = require("react-native");
44
+ var import_react_native_svg = __toESM(require("react-native-svg"), 1);
45
+
46
+ // src/components/checkbox/checkbox.animation.ts
47
+ var import_react_native = require("react-native");
48
+ var runCheckAnimation = (opacity, strokeDashoffset) => {
49
+ import_react_native.Animated.parallel([
50
+ import_react_native.Animated.timing(opacity, {
51
+ toValue: 1,
52
+ duration: 200,
53
+ useNativeDriver: false
54
+ }),
55
+ import_react_native.Animated.timing(strokeDashoffset, {
56
+ toValue: 44,
57
+ duration: 250,
58
+ useNativeDriver: false
59
+ })
60
+ ]).start();
61
+ };
62
+ var runUncheckAnimation = (opacity, strokeDashoffset) => {
63
+ import_react_native.Animated.parallel([
64
+ import_react_native.Animated.timing(opacity, {
65
+ toValue: 0,
66
+ duration: 200,
67
+ useNativeDriver: false
68
+ }),
69
+ import_react_native.Animated.timing(strokeDashoffset, {
70
+ toValue: 66,
71
+ duration: 250,
72
+ useNativeDriver: false
73
+ })
74
+ ]).start();
75
+ };
76
+ var runBackgroundInAnimation = (backgroundScale, backgroundOpacity) => {
77
+ import_react_native.Animated.parallel([
78
+ import_react_native.Animated.timing(backgroundScale, {
79
+ toValue: 1,
80
+ duration: 200,
81
+ useNativeDriver: true
82
+ }),
83
+ import_react_native.Animated.timing(backgroundOpacity, {
84
+ toValue: 1,
85
+ duration: 200,
86
+ useNativeDriver: true
87
+ })
88
+ ]).start();
89
+ };
90
+ var runBackgroundOutAnimation = (backgroundScale, backgroundOpacity) => {
91
+ import_react_native.Animated.parallel([
92
+ import_react_native.Animated.timing(backgroundScale, {
93
+ toValue: 0.5,
94
+ duration: 200,
95
+ useNativeDriver: true
96
+ }),
97
+ import_react_native.Animated.timing(backgroundOpacity, {
98
+ toValue: 0,
99
+ duration: 200,
100
+ useNativeDriver: true
101
+ })
102
+ ]).start();
103
+ };
104
+ var runPressInAnimation = (scale) => {
105
+ import_react_native.Animated.spring(scale, {
106
+ toValue: 0.95,
107
+ useNativeDriver: true
108
+ }).start();
109
+ };
110
+ var runPressOutAnimation = (scale) => {
111
+ import_react_native.Animated.spring(scale, {
112
+ toValue: 1,
113
+ useNativeDriver: true
114
+ }).start();
115
+ };
116
+
117
+ // src/components/checkbox/checkbox-icon.tsx
118
+ var AnimatedSvg = import_react_native2.Animated.createAnimatedComponent(import_react_native_svg.default);
119
+ var AnimatedPolyline = import_react_native2.Animated.createAnimatedComponent(import_react_native_svg.Polyline);
120
+ function CheckIcon({
121
+ isChecked,
122
+ color,
123
+ size
124
+ }) {
125
+ const opacity = (0, import_react.useRef)(new import_react_native2.Animated.Value(0)).current;
126
+ const strokeDashoffset = (0, import_react.useRef)(new import_react_native2.Animated.Value(66)).current;
127
+ (0, import_react.useEffect)(() => {
128
+ if (isChecked) {
129
+ runCheckAnimation(opacity, strokeDashoffset);
130
+ } else {
131
+ runUncheckAnimation(opacity, strokeDashoffset);
132
+ }
133
+ }, [isChecked, opacity, strokeDashoffset]);
134
+ return /* @__PURE__ */ import_react.default.createElement(
135
+ AnimatedSvg,
136
+ {
137
+ width: size,
138
+ height: size,
139
+ viewBox: "0 0 17 18",
140
+ fill: "none",
141
+ opacity
142
+ },
143
+ /* @__PURE__ */ import_react.default.createElement(
144
+ AnimatedPolyline,
145
+ {
146
+ points: "1 9 7 14 15 4",
147
+ stroke: color,
148
+ strokeWidth: 2,
149
+ strokeLinecap: "round",
150
+ strokeLinejoin: "round",
151
+ strokeDasharray: "22",
152
+ strokeDashoffset
153
+ }
154
+ )
155
+ );
156
+ }
157
+ function PlaceholderCheckIcon({ color, size }) {
158
+ return /* @__PURE__ */ import_react.default.createElement(import_react_native_svg.default, { width: size, height: size, viewBox: "0 0 17 18" }, /* @__PURE__ */ import_react.default.createElement(
159
+ import_react_native_svg.Path,
160
+ {
161
+ d: "M 1 9 L 7 14 L 15 4",
162
+ stroke: color,
163
+ strokeWidth: 2,
164
+ strokeLinecap: "round",
165
+ strokeLinejoin: "round",
166
+ fill: "none"
167
+ }
168
+ ));
169
+ }
170
+ function IndeterminateCheckIcon({
171
+ color,
172
+ size
173
+ }) {
174
+ return /* @__PURE__ */ import_react.default.createElement(import_react_native_svg.default, { width: size, height: size, viewBox: "0 0 24 24" }, /* @__PURE__ */ import_react.default.createElement(import_react_native_svg.Line, { x1: "21", y1: "12", x2: "3", y2: "12", stroke: color, strokeWidth: 3 }));
175
+ }
176
+ function CheckboxIcon({ isIndeterminate, variant, ...props }) {
177
+ const BaseIcon = isIndeterminate ? IndeterminateCheckIcon : CheckIcon;
178
+ if (variant === "light" && !props.isChecked && !isIndeterminate) {
179
+ return /* @__PURE__ */ import_react.default.createElement(PlaceholderCheckIcon, { size: props.size, color: props.placeholderColor ?? "" });
180
+ }
181
+ return /* @__PURE__ */ import_react.default.createElement(BaseIcon, { ...props });
182
+ }
183
+
184
+ // src/components/checkbox/checkbox.hook.ts
185
+ var import_react4 = require("react");
186
+ var import_core = require("@xaui/core");
187
+
188
+ // src/core/theme-context.tsx
189
+ var import_react2 = __toESM(require("react"), 1);
190
+ var import_react_native3 = require("react-native");
191
+ var import_theme = require("@xaui/core/theme");
192
+ var XUIThemeContext = (0, import_react2.createContext)(null);
193
+
194
+ // src/core/theme-hooks.ts
195
+ var import_react3 = require("react");
196
+ var import_react_native4 = require("react-native");
197
+ function useXUITheme() {
198
+ const theme = (0, import_react3.useContext)(XUIThemeContext);
199
+ if (!theme) {
200
+ throw new Error("useXUITheme must be used within XUIProvider");
201
+ }
202
+ return theme;
203
+ }
204
+
205
+ // src/components/checkbox/checkbox.hook.ts
206
+ function useSizeStyles(size, variant) {
207
+ const theme = useXUITheme();
208
+ const sizeStyles = (0, import_react4.useMemo)(() => {
209
+ const sizes = {
210
+ xs: {
211
+ checkboxSize: 14,
212
+ fontSize: theme.fontSizes.xs,
213
+ iconSize: variant === "light" ? 10 : 8
214
+ },
215
+ sm: {
216
+ checkboxSize: 18,
217
+ fontSize: theme.fontSizes.sm,
218
+ iconSize: variant === "light" ? 14 : 12
219
+ },
220
+ md: {
221
+ checkboxSize: 22,
222
+ fontSize: theme.fontSizes.md,
223
+ iconSize: variant === "light" ? 18 : 14
224
+ },
225
+ lg: {
226
+ checkboxSize: 26,
227
+ fontSize: theme.fontSizes.lg,
228
+ iconSize: variant === "light" ? 22 : 16
229
+ }
230
+ };
231
+ return sizes[size];
232
+ }, [size, variant, theme]);
233
+ return sizeStyles;
234
+ }
235
+ function useRadiusStyles(radius) {
236
+ const theme = useXUITheme();
237
+ const radiusStyles = (0, import_react4.useMemo)(() => {
238
+ const radii = {
239
+ none: theme.borderRadius.none,
240
+ sm: theme.borderRadius.sm,
241
+ md: theme.borderRadius.md,
242
+ lg: theme.borderRadius.lg,
243
+ full: theme.borderRadius.full
244
+ };
245
+ return { borderRadius: radii[radius] };
246
+ }, [radius, theme]);
247
+ return radiusStyles;
248
+ }
249
+ function useCheckmarkColors(themeColor, variant, isActive) {
250
+ const theme = useXUITheme();
251
+ const safeThemeColor = (0, import_core.getSafeThemeColor)(themeColor);
252
+ const colorScheme = theme.colors[safeThemeColor];
253
+ const checkmarkColors = (0, import_react4.useMemo)(() => {
254
+ if (variant === "filled") {
255
+ return {
256
+ checked: colorScheme.foreground,
257
+ unchecked: void 0
258
+ };
259
+ }
260
+ if (isActive) {
261
+ return {
262
+ checked: colorScheme.main,
263
+ unchecked: void 0
264
+ };
265
+ }
266
+ if (themeColor !== "default") {
267
+ return {
268
+ checked: colorScheme.foreground,
269
+ unchecked: colorScheme.background
270
+ };
271
+ }
272
+ return {
273
+ checked: theme.colors.foreground,
274
+ unchecked: theme.colors.background
275
+ };
276
+ }, [variant, colorScheme, isActive, themeColor, theme.colors]);
277
+ return checkmarkColors;
278
+ }
279
+ function useVariantStyles(themeColor, variant, isActive) {
280
+ const theme = useXUITheme();
281
+ const safeThemeColor = (0, import_core.getSafeThemeColor)(themeColor);
282
+ const colorScheme = theme.colors[safeThemeColor];
283
+ const variantStyles = (0, import_react4.useMemo)(() => {
284
+ if (variant === "filled") {
285
+ return {
286
+ backgroundColor: "transparent",
287
+ borderWidth: isActive ? 0 : theme.borderWidth.md,
288
+ borderColor: isActive ? "transparent" : colorScheme.main
289
+ };
290
+ }
291
+ return {
292
+ backgroundColor: "transparent",
293
+ borderWidth: 0,
294
+ borderColor: "transparent"
295
+ };
296
+ }, [variant, isActive, colorScheme, theme]);
297
+ return variantStyles;
298
+ }
299
+ function useContainerStyles(labelAlignment) {
300
+ const containerStyles = (0, import_react4.useMemo)(() => {
301
+ const isJustified = labelAlignment === "justify-left" || labelAlignment === "justify-right";
302
+ return {
303
+ flexDirection: labelAlignment === "left" || labelAlignment === "justify-left" ? "row-reverse" : "row",
304
+ justifyContent: isJustified ? "space-between" : "flex-start"
305
+ };
306
+ }, [labelAlignment]);
307
+ return containerStyles;
308
+ }
309
+
310
+ // src/components/checkbox/checkbox.style.ts
311
+ var import_react_native5 = require("react-native");
312
+ var styles = import_react_native5.StyleSheet.create({
313
+ container: {
314
+ flexDirection: "row",
315
+ alignItems: "center",
316
+ gap: 10
317
+ },
318
+ fullWidth: {
319
+ width: "100%"
320
+ },
321
+ checkbox: {
322
+ alignItems: "center",
323
+ justifyContent: "center",
324
+ overflow: "hidden",
325
+ position: "relative"
326
+ },
327
+ background: {
328
+ position: "absolute",
329
+ width: "100%",
330
+ height: "100%"
331
+ },
332
+ checkmarkContainer: {
333
+ alignItems: "center",
334
+ justifyContent: "center",
335
+ zIndex: 10
336
+ },
337
+ label: {
338
+ fontWeight: "400"
339
+ },
340
+ disabled: {
341
+ opacity: 0.5
342
+ },
343
+ disabledText: {
344
+ opacity: 0.7
345
+ }
346
+ });
347
+
348
+ // src/components/checkbox/checkbox.tsx
349
+ var import_core4 = require("@xaui/core");
350
+ var Checkbox = ({
351
+ label,
352
+ labelAlignment = "right",
353
+ themeColor = "default",
354
+ variant = "filled",
355
+ size = "md",
356
+ radius = "sm",
357
+ fullWidth = false,
358
+ isChecked: isCheckedProp,
359
+ isIndeterminate = false,
360
+ isDisabled = false,
361
+ labelStyle,
362
+ style,
363
+ onValueChange
364
+ }) => {
365
+ const theme = useXUITheme();
366
+ const colorScheme = theme.colors[(0, import_core4.getSafeThemeColor)(themeColor)];
367
+ const isControlled = typeof isCheckedProp === "boolean";
368
+ const [internalChecked, setInternalChecked] = (0, import_react5.useState)(isCheckedProp ?? false);
369
+ const isChecked = isControlled ? isCheckedProp : internalChecked;
370
+ const scale = (0, import_react5.useRef)(new import_react_native6.Animated.Value(1)).current;
371
+ const backgroundScale = (0, import_react5.useRef)(new import_react_native6.Animated.Value(0.5)).current;
372
+ const backgroundOpacity = (0, import_react5.useRef)(new import_react_native6.Animated.Value(0)).current;
373
+ const isActive = isChecked || isIndeterminate;
374
+ const sizeStyles = useSizeStyles(size, variant);
375
+ const radiusStyles = useRadiusStyles(radius);
376
+ const checkmarkColors = useCheckmarkColors(themeColor, variant, isActive);
377
+ const variantStyles = useVariantStyles(themeColor, variant, isActive);
378
+ const containerStyles = useContainerStyles(labelAlignment);
379
+ (0, import_react5.useEffect)(() => {
380
+ if (variant !== "filled") return;
381
+ if (isActive) {
382
+ runBackgroundInAnimation(backgroundScale, backgroundOpacity);
383
+ } else {
384
+ runBackgroundOutAnimation(backgroundScale, backgroundOpacity);
385
+ }
386
+ }, [isActive, variant, backgroundScale, backgroundOpacity]);
387
+ const handlePress = () => {
388
+ if (!isDisabled) {
389
+ const nextValue = isIndeterminate ? true : !isChecked;
390
+ onValueChange?.(nextValue);
391
+ if (!isControlled) {
392
+ setInternalChecked(nextValue);
393
+ }
394
+ }
395
+ };
396
+ const handlePressIn = () => {
397
+ if (!isDisabled) {
398
+ runPressInAnimation(scale);
399
+ }
400
+ };
401
+ const handlePressOut = () => {
402
+ if (!isDisabled) {
403
+ runPressOutAnimation(scale);
404
+ }
405
+ };
406
+ const accessibilityChecked = isIndeterminate ? "mixed" : isChecked;
407
+ return /* @__PURE__ */ import_react5.default.createElement(
408
+ import_react_native6.Pressable,
409
+ {
410
+ onPress: handlePress,
411
+ onPressIn: handlePressIn,
412
+ onPressOut: handlePressOut,
413
+ disabled: isDisabled,
414
+ accessible: true,
415
+ accessibilityRole: "checkbox",
416
+ accessibilityLabel: label,
417
+ accessibilityState: {
418
+ disabled: isDisabled,
419
+ checked: accessibilityChecked
420
+ },
421
+ style: [
422
+ styles.container,
423
+ containerStyles,
424
+ fullWidth && styles.fullWidth,
425
+ isDisabled && styles.disabled,
426
+ style
427
+ ]
428
+ },
429
+ /* @__PURE__ */ import_react5.default.createElement(
430
+ import_react_native6.Animated.View,
431
+ {
432
+ style: [
433
+ styles.checkbox,
434
+ {
435
+ width: sizeStyles.checkboxSize,
436
+ height: sizeStyles.checkboxSize,
437
+ ...radiusStyles,
438
+ ...variantStyles
439
+ },
440
+ {
441
+ transform: [{ scale }]
442
+ }
443
+ ]
444
+ },
445
+ variant === "filled" && /* @__PURE__ */ import_react5.default.createElement(
446
+ import_react_native6.Animated.View,
447
+ {
448
+ style: [
449
+ styles.background,
450
+ radiusStyles,
451
+ {
452
+ backgroundColor: colorScheme.main,
453
+ transform: [{ scale: backgroundScale }],
454
+ opacity: backgroundOpacity
455
+ }
456
+ ]
457
+ }
458
+ ),
459
+ /* @__PURE__ */ import_react5.default.createElement(import_react_native6.View, { style: styles.checkmarkContainer }, /* @__PURE__ */ import_react5.default.createElement(
460
+ CheckboxIcon,
461
+ {
462
+ isChecked: isActive,
463
+ isIndeterminate,
464
+ color: checkmarkColors.checked,
465
+ size: sizeStyles.iconSize,
466
+ placeholderColor: checkmarkColors.unchecked,
467
+ variant
468
+ }
469
+ ))
470
+ ),
471
+ label && /* @__PURE__ */ import_react5.default.createElement(
472
+ import_react_native6.Text,
473
+ {
474
+ style: [
475
+ styles.label,
476
+ { fontSize: sizeStyles.fontSize, color: theme.colors.foreground },
477
+ isDisabled && styles.disabledText,
478
+ labelStyle
479
+ ]
480
+ },
481
+ label
482
+ )
483
+ );
484
+ };
485
+ // Annotate the CommonJS export names for ESM import in node:
486
+ 0 && (module.exports = {
487
+ Checkbox
488
+ });
@@ -0,0 +1,73 @@
1
+ import React from 'react';
2
+ import { TextStyle, ViewStyle } from 'react-native';
3
+ import { T as ThemeColor, S as Size, R as Radius } from '../index-BOw6tbkc.cjs';
4
+
5
+ type CheckboxVariant = 'filled' | 'light';
6
+ type CheckboxLabelAlignment = 'left' | 'right' | 'justify-left' | 'justify-right';
7
+ type CheckboxProps = {
8
+ /**
9
+ * The label to display alongside the checkbox.
10
+ */
11
+ label?: string;
12
+ /**
13
+ * Alignment of the label relative to the checkbox.
14
+ * @default 'right'
15
+ */
16
+ labelAlignment?: CheckboxLabelAlignment;
17
+ /**
18
+ * The theme color of the checkbox.
19
+ * @default 'default'
20
+ */
21
+ themeColor?: ThemeColor;
22
+ /**
23
+ * The variant of the checkbox.
24
+ * @default 'filled'
25
+ */
26
+ variant?: CheckboxVariant;
27
+ /**
28
+ * The size of the checkbox.
29
+ * @default 'md'
30
+ */
31
+ size?: Size;
32
+ /**
33
+ * The border radius of the checkbox.
34
+ * @default 'sm'
35
+ */
36
+ radius?: Radius;
37
+ /**
38
+ * Whether the checkbox should take the full width of its container.
39
+ * @default false
40
+ */
41
+ fullWidth?: boolean;
42
+ /**
43
+ * Whether the checkbox is checked.
44
+ * @default false
45
+ */
46
+ isChecked?: boolean;
47
+ /**
48
+ * Whether the checkbox is in an indeterminate state.
49
+ * @default false
50
+ */
51
+ isIndeterminate?: boolean;
52
+ /**
53
+ * Whether the checkbox is disabled.
54
+ * @default false
55
+ */
56
+ isDisabled?: boolean;
57
+ /**
58
+ * Custom style for the label text.
59
+ */
60
+ labelStyle?: TextStyle;
61
+ /**
62
+ * Custom style for the checkbox container.
63
+ */
64
+ style?: ViewStyle;
65
+ /**
66
+ * Callback fired when the checkbox value changes.
67
+ */
68
+ onValueChange?: (isChecked: boolean) => void;
69
+ };
70
+
71
+ declare const Checkbox: React.FC<CheckboxProps>;
72
+
73
+ export { Checkbox, type CheckboxLabelAlignment, type CheckboxProps, type CheckboxVariant };
@@ -0,0 +1,73 @@
1
+ import React from 'react';
2
+ import { TextStyle, ViewStyle } from 'react-native';
3
+ import { T as ThemeColor, S as Size, R as Radius } from '../index-BOw6tbkc.js';
4
+
5
+ type CheckboxVariant = 'filled' | 'light';
6
+ type CheckboxLabelAlignment = 'left' | 'right' | 'justify-left' | 'justify-right';
7
+ type CheckboxProps = {
8
+ /**
9
+ * The label to display alongside the checkbox.
10
+ */
11
+ label?: string;
12
+ /**
13
+ * Alignment of the label relative to the checkbox.
14
+ * @default 'right'
15
+ */
16
+ labelAlignment?: CheckboxLabelAlignment;
17
+ /**
18
+ * The theme color of the checkbox.
19
+ * @default 'default'
20
+ */
21
+ themeColor?: ThemeColor;
22
+ /**
23
+ * The variant of the checkbox.
24
+ * @default 'filled'
25
+ */
26
+ variant?: CheckboxVariant;
27
+ /**
28
+ * The size of the checkbox.
29
+ * @default 'md'
30
+ */
31
+ size?: Size;
32
+ /**
33
+ * The border radius of the checkbox.
34
+ * @default 'sm'
35
+ */
36
+ radius?: Radius;
37
+ /**
38
+ * Whether the checkbox should take the full width of its container.
39
+ * @default false
40
+ */
41
+ fullWidth?: boolean;
42
+ /**
43
+ * Whether the checkbox is checked.
44
+ * @default false
45
+ */
46
+ isChecked?: boolean;
47
+ /**
48
+ * Whether the checkbox is in an indeterminate state.
49
+ * @default false
50
+ */
51
+ isIndeterminate?: boolean;
52
+ /**
53
+ * Whether the checkbox is disabled.
54
+ * @default false
55
+ */
56
+ isDisabled?: boolean;
57
+ /**
58
+ * Custom style for the label text.
59
+ */
60
+ labelStyle?: TextStyle;
61
+ /**
62
+ * Custom style for the checkbox container.
63
+ */
64
+ style?: ViewStyle;
65
+ /**
66
+ * Callback fired when the checkbox value changes.
67
+ */
68
+ onValueChange?: (isChecked: boolean) => void;
69
+ };
70
+
71
+ declare const Checkbox: React.FC<CheckboxProps>;
72
+
73
+ export { Checkbox, type CheckboxLabelAlignment, type CheckboxProps, type CheckboxVariant };