@xaui/native 0.0.2 → 0.0.3

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