@cdx-ui/components 0.0.1-alpha.1 → 0.0.1-alpha.10

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.
Files changed (85) hide show
  1. package/README.md +1 -1
  2. package/lib/commonjs/components/Button/styles.js +12 -12
  3. package/lib/commonjs/components/Button/styles.js.map +1 -1
  4. package/lib/commonjs/components/Checkbox/index.js +173 -0
  5. package/lib/commonjs/components/Checkbox/index.js.map +1 -0
  6. package/lib/commonjs/components/Checkbox/styles.js +67 -0
  7. package/lib/commonjs/components/Checkbox/styles.js.map +1 -0
  8. package/lib/commonjs/components/Stack/HStack.js +8 -21
  9. package/lib/commonjs/components/Stack/HStack.js.map +1 -1
  10. package/lib/commonjs/components/Stack/VStack.js +8 -21
  11. package/lib/commonjs/components/Stack/VStack.js.map +1 -1
  12. package/lib/commonjs/components/Stack/styles.js +51 -0
  13. package/lib/commonjs/components/Stack/styles.js.map +1 -0
  14. package/lib/commonjs/components/Switch/BaseSwitch.js +46 -0
  15. package/lib/commonjs/components/Switch/BaseSwitch.js.map +1 -0
  16. package/lib/commonjs/components/Switch/BaseSwitch.web.js +56 -0
  17. package/lib/commonjs/components/Switch/BaseSwitch.web.js.map +1 -0
  18. package/lib/commonjs/components/Switch/index.js +13 -0
  19. package/lib/commonjs/components/Switch/index.js.map +1 -0
  20. package/lib/commonjs/components/Switch/styles.js +128 -0
  21. package/lib/commonjs/components/Switch/styles.js.map +1 -0
  22. package/lib/commonjs/components/index.js +24 -0
  23. package/lib/commonjs/components/index.js.map +1 -1
  24. package/lib/commonjs/metro/withCdxMetroConfig.js +24 -0
  25. package/lib/commonjs/metro/withCdxMetroConfig.js.map +1 -0
  26. package/lib/module/components/Button/styles.js +12 -12
  27. package/lib/module/components/Button/styles.js.map +1 -1
  28. package/lib/module/components/Checkbox/index.js +169 -0
  29. package/lib/module/components/Checkbox/index.js.map +1 -0
  30. package/lib/module/components/Checkbox/styles.js +63 -0
  31. package/lib/module/components/Checkbox/styles.js.map +1 -0
  32. package/lib/module/components/Stack/HStack.js +8 -21
  33. package/lib/module/components/Stack/HStack.js.map +1 -1
  34. package/lib/module/components/Stack/VStack.js +8 -21
  35. package/lib/module/components/Stack/VStack.js.map +1 -1
  36. package/lib/module/components/Stack/styles.js +47 -0
  37. package/lib/module/components/Stack/styles.js.map +1 -0
  38. package/lib/module/components/Switch/BaseSwitch.js +42 -0
  39. package/lib/module/components/Switch/BaseSwitch.js.map +1 -0
  40. package/lib/module/components/Switch/BaseSwitch.web.js +52 -0
  41. package/lib/module/components/Switch/BaseSwitch.web.js.map +1 -0
  42. package/lib/module/components/Switch/index.js +9 -0
  43. package/lib/module/components/Switch/index.js.map +1 -0
  44. package/lib/module/components/Switch/styles.js +125 -0
  45. package/lib/module/components/Switch/styles.js.map +1 -0
  46. package/lib/module/components/index.js +2 -0
  47. package/lib/module/components/index.js.map +1 -1
  48. package/lib/module/metro/withCdxMetroConfig.js +20 -0
  49. package/lib/module/metro/withCdxMetroConfig.js.map +1 -0
  50. package/lib/typescript/components/Button/styles.d.ts.map +1 -1
  51. package/lib/typescript/components/Checkbox/index.d.ts +44 -0
  52. package/lib/typescript/components/Checkbox/index.d.ts.map +1 -0
  53. package/lib/typescript/components/Checkbox/styles.d.ts +18 -0
  54. package/lib/typescript/components/Checkbox/styles.d.ts.map +1 -0
  55. package/lib/typescript/components/Stack/HStack.d.ts +1 -12
  56. package/lib/typescript/components/Stack/HStack.d.ts.map +1 -1
  57. package/lib/typescript/components/Stack/VStack.d.ts +1 -12
  58. package/lib/typescript/components/Stack/VStack.d.ts.map +1 -1
  59. package/lib/typescript/components/Stack/styles.d.ts +10 -0
  60. package/lib/typescript/components/Stack/styles.d.ts.map +1 -0
  61. package/lib/typescript/components/Switch/BaseSwitch.d.ts +9 -0
  62. package/lib/typescript/components/Switch/BaseSwitch.d.ts.map +1 -0
  63. package/lib/typescript/components/Switch/BaseSwitch.web.d.ts +15 -0
  64. package/lib/typescript/components/Switch/BaseSwitch.web.d.ts.map +1 -0
  65. package/lib/typescript/components/Switch/index.d.ts +8 -0
  66. package/lib/typescript/components/Switch/index.d.ts.map +1 -0
  67. package/lib/typescript/components/Switch/styles.d.ts +26 -0
  68. package/lib/typescript/components/Switch/styles.d.ts.map +1 -0
  69. package/lib/typescript/components/index.d.ts +2 -0
  70. package/lib/typescript/components/index.d.ts.map +1 -1
  71. package/lib/typescript/metro/withCdxMetroConfig.d.ts +19 -0
  72. package/lib/typescript/metro/withCdxMetroConfig.d.ts.map +1 -0
  73. package/package.json +17 -15
  74. package/src/components/Button/styles.ts +15 -10
  75. package/src/components/Checkbox/index.tsx +215 -0
  76. package/src/components/Checkbox/styles.ts +94 -0
  77. package/src/components/Stack/HStack.tsx +8 -19
  78. package/src/components/Stack/VStack.tsx +8 -23
  79. package/src/components/Stack/styles.ts +49 -0
  80. package/src/components/Switch/BaseSwitch.tsx +38 -0
  81. package/src/components/Switch/BaseSwitch.web.tsx +69 -0
  82. package/src/components/Switch/index.tsx +13 -0
  83. package/src/components/Switch/styles.ts +120 -0
  84. package/src/components/index.ts +2 -0
  85. package/src/metro/withCdxMetroConfig.ts +29 -0
@@ -1,7 +1,9 @@
1
1
  export * from './Box';
2
2
  export * from './Button';
3
+ export * from './Checkbox';
3
4
  export * from './Input';
4
5
  export * from './Select';
6
+ export * from './Switch';
5
7
  export { HStack, VStack } from './Stack';
6
8
  export * from './Text';
7
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACzC,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACzC,cAAc,QAAQ,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { MetroConfig } from 'metro-config';
2
+ export interface CdxMetroConfigOptions {
3
+ /** Path to the CSS entry file (e.g., `'./global.css'`). */
4
+ cssEntryFile: string;
5
+ /** Path where generated Tailwind class type definitions are written. */
6
+ generatedTypesFile?: string;
7
+ }
8
+ /**
9
+ * Wraps a Metro config with CDX UI's styling-layer configuration.
10
+ *
11
+ * Today this delegates to Uniwind. If the styling layer is swapped (see
12
+ * `docs/research/uniwind-to-nativewind-contingency.md`), only the internals
13
+ * of this function change — consuming Metro configs stay the same.
14
+ *
15
+ * Must be the **outermost** Metro config wrapper (after any other wrappers
16
+ * like `withStorybook`).
17
+ */
18
+ export declare function withCdxMetroConfig<T extends MetroConfig>(config: T, options: CdxMetroConfigOptions): T;
19
+ //# sourceMappingURL=withCdxMetroConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withCdxMetroConfig.d.ts","sourceRoot":"","sources":["../../../src/metro/withCdxMetroConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,qBAAqB;IACpC,2DAA2D;IAC3D,YAAY,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,WAAW,EACtD,MAAM,EAAE,CAAC,EACT,OAAO,EAAE,qBAAqB,GAC7B,CAAC,CAKH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdx-ui/components",
3
- "version": "0.0.1-alpha.1",
3
+ "version": "0.0.1-alpha.10",
4
4
  "main": "lib/commonjs/index.js",
5
5
  "module": "lib/module/index.js",
6
6
  "react-native": "src/index.ts",
@@ -9,13 +9,18 @@
9
9
  "exports": {
10
10
  ".": {
11
11
  "react-native": "./src/index.ts",
12
- "source": "./src/index.ts",
13
12
  "types": "./lib/typescript/index.d.ts",
14
13
  "import": "./lib/module/index.js",
15
14
  "require": "./lib/commonjs/index.js",
16
15
  "default": "./lib/module/index.js"
17
16
  },
18
- "./styles.css": "./src/styles.css"
17
+ "./styles.css": "./src/styles.css",
18
+ "./metro": {
19
+ "types": "./lib/typescript/metro/withCdxMetroConfig.d.ts",
20
+ "require": "./lib/commonjs/metro/withCdxMetroConfig.js",
21
+ "import": "./lib/module/metro/withCdxMetroConfig.js",
22
+ "default": "./lib/commonjs/metro/withCdxMetroConfig.js"
23
+ }
19
24
  },
20
25
  "files": [
21
26
  "lib",
@@ -36,30 +41,27 @@
36
41
  ]
37
42
  },
38
43
  "peerDependencies": {
39
- "react": ">=18.0.0",
40
- "react-dom": ">=18.0.0",
41
- "react-native": ">=0.74.0",
42
- "react-native-web": ">=0.19.0",
43
- "uniwind": ">=1.3.0"
44
+ "react": "^18.2.0 || ^19.0.0",
45
+ "react-native": ">=0.76.0",
46
+ "react-native-reanimated": ">=3.0.0",
47
+ "react-native-web": ">=0.19.0"
44
48
  },
45
49
  "peerDependenciesMeta": {
46
50
  "react-native": {
47
51
  "optional": true
48
52
  },
49
- "react-native-web": {
53
+ "react-native-reanimated": {
50
54
  "optional": true
51
55
  },
52
- "react-dom": {
53
- "optional": true
54
- },
55
- "uniwind": {
56
+ "react-native-web": {
56
57
  "optional": true
57
58
  }
58
59
  },
59
60
  "dependencies": {
60
61
  "class-variance-authority": "^0.7.1",
61
- "@cdx-ui/primitives": "0.0.1-alpha.1",
62
- "@cdx-ui/utils": "0.0.1-alpha.1"
62
+ "uniwind": "1.4.1",
63
+ "@cdx-ui/primitives": "0.0.1-alpha.10",
64
+ "@cdx-ui/utils": "0.0.1-alpha.10"
63
65
  },
64
66
  "devDependencies": {
65
67
  "@types/react": "*",
@@ -8,9 +8,10 @@ export const buttonRootVariants = cva(
8
8
  [
9
9
  'flex-row items-center justify-center',
10
10
  'rounded-md',
11
+ 'web:outline-none web:focus:outline-none web:focus-visible:outline-none',
11
12
  'transition-colors duration-150', // TODO: Transition not working on mobile
12
13
  'data-[disabled=true]:opacity-60 data-[disabled=true]:cursor-not-allowed data-[disabled=true]:pointer-events-none',
13
- 'data-[focus-visible=true]:ring-2 data-[focus-visible=true]:ring-ring data-[focus-visible=true]:ring-offset-2 data-[focus-visible=true]:ring-offset-bg',
14
+ 'web:data-[focus-visible=true]:ring-3',
14
15
  ],
15
16
  {
16
17
  variants: {
@@ -18,21 +19,21 @@ export const buttonRootVariants = cva(
18
19
  solid: [],
19
20
  subtle: [],
20
21
  outline: [
21
- 'bg-transparent border border-border',
22
- 'data-[hover=true]:bg-surface',
23
- 'data-[active=true]:bg-surface-raised',
22
+ 'bg-transparent border border-neutral-border-strong',
23
+ 'data-[hover=true]:bg-neutral-background',
24
+ 'data-[active=true]:bg-neutral-border',
24
25
  ],
25
26
  ghost: [
26
27
  'bg-transparent',
27
- 'data-[hover=true]:bg-surface',
28
- 'data-[active=true]:bg-surface-raised',
28
+ 'data-[hover=true]:bg-neutral-background',
29
+ 'data-[active=true]:bg-neutral-border',
29
30
  ],
30
31
  },
31
32
  color: {
32
- primary: [],
33
- secondary: [],
34
- success: [],
35
- danger: [],
33
+ primary: 'web:data-[focus-visible=true]:ring-blue-300/50',
34
+ secondary: 'web:data-[focus-visible=true]:ring-amber-300/50',
35
+ success: 'web:data-[focus-visible=true]:ring-green-300/50',
36
+ danger: 'web:data-[focus-visible=true]:ring-red-300/50',
36
37
  },
37
38
  size: {
38
39
  sm: 'h-8 px-3 gap-1.5',
@@ -138,6 +139,7 @@ export const buttonRootVariants = cva(
138
139
  color: 'primary',
139
140
  className: [
140
141
  'border-blue-500',
142
+ 'data-[focus-visible=true]:border-blue-500',
141
143
  Platform.select({
142
144
  default: 'data-[active=true]:border-blue-700 data-[active=true]:bg-blue-100',
143
145
  web: 'data-[hover=true]:border-blue-600 data-[hover=true]:bg-blue-100 data-[active=true]:data-[hover=true]:border-blue-700 data-[active=true]:data-[hover=true]:bg-blue-200',
@@ -149,6 +151,7 @@ export const buttonRootVariants = cva(
149
151
  color: 'secondary',
150
152
  className: [
151
153
  'border-amber-500',
154
+ 'data-[focus-visible=true]:border-amber-500',
152
155
  Platform.select({
153
156
  default: 'data-[active=true]:border-amber-700 data-[active=true]:bg-amber-50',
154
157
  web: 'data-[hover=true]:border-amber-600 data-[hover=true]:bg-amber-50 data-[active=true]:data-[hover=true]:border-amber-700 data-[active=true]:data-[hover=true]:bg-amber-100',
@@ -160,6 +163,7 @@ export const buttonRootVariants = cva(
160
163
  color: 'success',
161
164
  className: [
162
165
  'border-green-500',
166
+ 'data-[focus-visible=true]:border-green-500',
163
167
  Platform.select({
164
168
  default: 'data-[active=true]:border-green-700 data-[active=true]:bg-green-100',
165
169
  web: 'data-[hover=true]:border-green-600 data-[hover=true]:bg-green-100 data-[active=true]:data-[hover=true]:border-green-700 data-[active=true]:data-[hover=true]:bg-green-200',
@@ -171,6 +175,7 @@ export const buttonRootVariants = cva(
171
175
  color: 'danger',
172
176
  className: [
173
177
  'border-red-500',
178
+ 'data-[focus-visible=true]:border-red-500',
174
179
  Platform.select({
175
180
  default: 'data-[active=true]:border-red-700 data-[active=true]:bg-red-100',
176
181
  web: 'data-[hover=true]:border-red-600 data-[hover=true]:bg-red-100 data-[active=true]:data-[hover=true]:border-red-700 data-[active=true]:data-[hover=true]:bg-red-200',
@@ -0,0 +1,215 @@
1
+ import { forwardRef, type ReactNode } from 'react';
2
+ import { Pressable, Text, type TextProps, View, type ViewProps } from 'react-native';
3
+ import { createCheckbox, type ICheckboxProps } from '@cdx-ui/primitives';
4
+ import { cn, useStyleContext, withStyleContext } from '@cdx-ui/utils';
5
+ import {
6
+ type CheckboxVariantProps,
7
+ checkboxGroupVariants,
8
+ checkboxIconVariants,
9
+ checkboxIndicatorVariants,
10
+ checkboxLabelVariants,
11
+ checkboxRootVariants,
12
+ } from './styles';
13
+
14
+ const SCOPE = 'CHECKBOX';
15
+
16
+ const Root = withStyleContext(Pressable, SCOPE);
17
+
18
+ const useCheckboxStyleContext = () => useStyleContext(SCOPE) as CheckboxVariantProps;
19
+
20
+ const CheckboxPrimitive = createCheckbox({
21
+ Root,
22
+ Indicator: View,
23
+ Icon: View,
24
+ Label: Text,
25
+ Group: View,
26
+ });
27
+
28
+ // =============================================================================
29
+ // CHECKBOX ROOT
30
+ // =============================================================================
31
+
32
+ export interface CheckboxProps extends ICheckboxProps, CheckboxVariantProps {
33
+ className?: string;
34
+ children?: ReactNode;
35
+ }
36
+
37
+ const CheckboxRoot = forwardRef<View, CheckboxProps>(
38
+ ({ size = 'md', className, children, style, ...props }, ref) => {
39
+ const computedClassName = cn(checkboxRootVariants({ size }), className);
40
+
41
+ return (
42
+ <CheckboxPrimitive
43
+ ref={ref as any}
44
+ className={computedClassName}
45
+ style={style}
46
+ context={{ size }}
47
+ {...props}
48
+ >
49
+ {children}
50
+ </CheckboxPrimitive>
51
+ );
52
+ },
53
+ );
54
+
55
+ CheckboxRoot.displayName = 'Checkbox';
56
+
57
+ // =============================================================================
58
+ // CHECKBOX INDICATOR
59
+ // =============================================================================
60
+
61
+ export interface CheckboxIndicatorProps extends ViewProps {
62
+ className?: string;
63
+ children?: ReactNode;
64
+ }
65
+
66
+ const CheckboxIndicator = forwardRef<View, CheckboxIndicatorProps>(
67
+ ({ className, children, style, ...props }, ref) => {
68
+ const { size } = useCheckboxStyleContext();
69
+ const computedClassName = cn(checkboxIndicatorVariants({ size }), className);
70
+
71
+ return (
72
+ <CheckboxPrimitive.Indicator
73
+ ref={ref as any}
74
+ className={computedClassName}
75
+ style={style}
76
+ {...props}
77
+ >
78
+ {children}
79
+ </CheckboxPrimitive.Indicator>
80
+ );
81
+ },
82
+ );
83
+
84
+ CheckboxIndicator.displayName = 'Checkbox.Indicator';
85
+
86
+ // =============================================================================
87
+ // CHECKBOX ICON
88
+ // =============================================================================
89
+
90
+ export interface CheckboxIconProps extends ViewProps {
91
+ className?: string;
92
+ children?: ReactNode;
93
+ }
94
+
95
+ const CheckboxIcon = forwardRef<View, CheckboxIconProps>(
96
+ ({ className, children, style, ...props }, ref) => {
97
+ const { size } = useCheckboxStyleContext();
98
+ const computedClassName = cn(checkboxIconVariants({ size }), className);
99
+
100
+ return (
101
+ <CheckboxPrimitive.Icon
102
+ ref={ref as any}
103
+ className={computedClassName}
104
+ style={style}
105
+ {...props}
106
+ >
107
+ {children}
108
+ </CheckboxPrimitive.Icon>
109
+ );
110
+ },
111
+ );
112
+
113
+ CheckboxIcon.displayName = 'Checkbox.Icon';
114
+
115
+ // =============================================================================
116
+ // CHECKBOX LABEL
117
+ // =============================================================================
118
+
119
+ export interface CheckboxLabelProps extends TextProps {
120
+ className?: string;
121
+ children?: ReactNode;
122
+ }
123
+
124
+ const CheckboxLabel = forwardRef<Text, CheckboxLabelProps>(
125
+ ({ className, children, style, ...props }, ref) => {
126
+ const { size } = useCheckboxStyleContext();
127
+ const computedClassName = cn(checkboxLabelVariants({ size }), className);
128
+
129
+ return (
130
+ <CheckboxPrimitive.Label
131
+ ref={ref as any}
132
+ className={computedClassName}
133
+ style={style}
134
+ {...props}
135
+ >
136
+ {children}
137
+ </CheckboxPrimitive.Label>
138
+ );
139
+ },
140
+ );
141
+
142
+ CheckboxLabel.displayName = 'Checkbox.Label';
143
+
144
+ // =============================================================================
145
+ // CHECKBOX GROUP
146
+ // =============================================================================
147
+
148
+ export interface CheckboxGroupProps extends ViewProps {
149
+ className?: string;
150
+ children?: ReactNode;
151
+ value?: string[];
152
+ onChange?: (value: string[]) => void;
153
+ isDisabled?: boolean;
154
+ isInvalid?: boolean;
155
+ isReadOnly?: boolean;
156
+ direction?: 'column' | 'row';
157
+ }
158
+
159
+ const CheckboxGroup = forwardRef<View, CheckboxGroupProps>(
160
+ (
161
+ {
162
+ className,
163
+ children,
164
+ style,
165
+ direction = 'column',
166
+ value,
167
+ onChange,
168
+ isDisabled,
169
+ isInvalid,
170
+ isReadOnly,
171
+ ...viewProps
172
+ },
173
+ ref,
174
+ ) => {
175
+ const computedClassName = cn(checkboxGroupVariants({ direction }), className);
176
+
177
+ return (
178
+ <CheckboxPrimitive.Group
179
+ ref={ref as any}
180
+ className={computedClassName}
181
+ style={style}
182
+ value={value ?? []}
183
+ onChange={onChange}
184
+ isDisabled={isDisabled}
185
+ isInvalid={isInvalid}
186
+ isReadOnly={isReadOnly}
187
+ {...viewProps}
188
+ >
189
+ {children}
190
+ </CheckboxPrimitive.Group>
191
+ );
192
+ },
193
+ );
194
+
195
+ CheckboxGroup.displayName = 'Checkbox.Group';
196
+
197
+ // =============================================================================
198
+ // COMPOUND COMPONENT
199
+ // =============================================================================
200
+
201
+ type CheckboxCompoundComponent = typeof CheckboxRoot & {
202
+ Indicator: typeof CheckboxIndicator;
203
+ Icon: typeof CheckboxIcon;
204
+ Label: typeof CheckboxLabel;
205
+ Group: typeof CheckboxGroup;
206
+ };
207
+
208
+ export const Checkbox = Object.assign(CheckboxRoot, {
209
+ Indicator: CheckboxIndicator,
210
+ Icon: CheckboxIcon,
211
+ Label: CheckboxLabel,
212
+ Group: CheckboxGroup,
213
+ }) as CheckboxCompoundComponent;
214
+
215
+ export type { CheckboxVariantProps };
@@ -0,0 +1,94 @@
1
+ import { Platform } from 'react-native';
2
+ import { cva, type VariantProps } from 'class-variance-authority';
3
+
4
+ export const checkboxRootVariants = cva(
5
+ [
6
+ 'flex-row items-center',
7
+ 'data-[disabled=true]:opacity-60 data-[disabled=true]:cursor-not-allowed',
8
+ ],
9
+ {
10
+ variants: {
11
+ size: {
12
+ sm: 'gap-2',
13
+ md: 'gap-2.5',
14
+ },
15
+ },
16
+ defaultVariants: {
17
+ size: 'md',
18
+ },
19
+ },
20
+ );
21
+
22
+ export const checkboxIndicatorVariants = cva(
23
+ [
24
+ 'items-center justify-center',
25
+ 'rounded',
26
+ 'border-2 border-neutral-border-strong',
27
+ 'data-[checked=true]:bg-blue-500 data-[checked=true]:border-blue-500',
28
+ 'data-[disabled=true]:opacity-60',
29
+ 'data-[invalid=true]:border-red-500',
30
+ 'data-[checked=true]:data-[invalid=true]:bg-red-500 data-[checked=true]:data-[invalid=true]:border-red-500',
31
+ Platform.select({
32
+ web: [
33
+ 'transition-colors duration-150',
34
+ 'data-[hover=true]:border-zinc-500 data-[hover=true]:bg-zinc-50',
35
+ 'data-[focus-visible=true]:ring-2 data-[focus-visible=true]:ring-blue-300/50 data-[focus-visible=true]:ring-offset-1',
36
+ 'data-[invalid=true]:data-[hover=true]:border-red-400',
37
+ 'data-[invalid=true]:data-[focus-visible=true]:ring-red-300/50',
38
+ ].join(' '),
39
+ default: '',
40
+ }),
41
+ ],
42
+ {
43
+ variants: {
44
+ size: {
45
+ sm: 'h-4 w-4',
46
+ md: 'h-5 w-5',
47
+ },
48
+ },
49
+ defaultVariants: {
50
+ size: 'md',
51
+ },
52
+ },
53
+ );
54
+
55
+ export const checkboxIconVariants = cva(['text-white'], {
56
+ variants: {
57
+ size: {
58
+ sm: 'h-3 w-3',
59
+ md: 'h-3.5 w-3.5',
60
+ },
61
+ },
62
+ defaultVariants: {
63
+ size: 'md',
64
+ },
65
+ });
66
+
67
+ export const checkboxLabelVariants = cva(
68
+ ['text-neutral-text-primary', 'data-[disabled=true]:text-neutral-text-tertiary'],
69
+ {
70
+ variants: {
71
+ size: {
72
+ sm: 'text-sm',
73
+ md: 'text-base',
74
+ },
75
+ },
76
+ defaultVariants: {
77
+ size: 'md',
78
+ },
79
+ },
80
+ );
81
+
82
+ export const checkboxGroupVariants = cva([], {
83
+ variants: {
84
+ direction: {
85
+ column: 'gap-2',
86
+ row: 'flex-row gap-4',
87
+ },
88
+ },
89
+ defaultVariants: {
90
+ direction: 'column',
91
+ },
92
+ });
93
+
94
+ export type CheckboxVariantProps = VariantProps<typeof checkboxRootVariants>;
@@ -1,21 +1,8 @@
1
1
  import type { ForwardedRef } from 'react';
2
2
  import { forwardRef } from 'react';
3
3
  import { View, type ViewProps } from 'react-native';
4
- // import { spacing } from '@cdx-ui/tokens';
5
-
6
- // TODO: Integrate with tokens (multiply by spacing)
7
- const spaceScale = {
8
- xs: 1,
9
- sm: 2,
10
- md: 3,
11
- lg: 4,
12
- xl: 5,
13
- '2xl': 6,
14
- '3xl': 7,
15
- '4xl': 8,
16
- } as const;
17
-
18
- type StackSpace = keyof typeof spaceScale;
4
+ import { cn } from '@cdx-ui/utils';
5
+ import { hStackRootVariants, type StackSpace } from './styles';
19
6
 
20
7
  export interface HStackProps extends ViewProps {
21
8
  className?: string;
@@ -24,13 +11,15 @@ export interface HStackProps extends ViewProps {
24
11
  }
25
12
 
26
13
  export const HStack = forwardRef<View, HStackProps>(
27
- ({ space, reversed, style, className, children, ...restProps }, ref: ForwardedRef<View>) => {
28
- const gap = space ? spaceScale[space] : undefined;
14
+ (
15
+ { reversed = false, space, style, className, children, ...restProps },
16
+ ref: ForwardedRef<View>,
17
+ ) => {
29
18
  return (
30
19
  <View
31
20
  ref={ref}
32
- className={className}
33
- style={[{ flexDirection: reversed ? 'row-reverse' : 'row' }, gap ? { gap } : null, style]}
21
+ className={cn(hStackRootVariants({ reversed, space }), className)}
22
+ style={style}
34
23
  {...restProps}
35
24
  >
36
25
  {children}
@@ -1,21 +1,8 @@
1
1
  import type { ForwardedRef } from 'react';
2
2
  import { forwardRef } from 'react';
3
3
  import { View, type ViewProps } from 'react-native';
4
- // import { spacing } from '@cdx-ui/tokens';
5
-
6
- // TODO: Integrate with tokens (multiply by spacing)
7
- const spaceScale = {
8
- xs: 1,
9
- sm: 2,
10
- md: 3,
11
- lg: 4,
12
- xl: 5,
13
- '2xl': 6,
14
- '3xl': 7,
15
- '4xl': 8,
16
- } as const;
17
-
18
- type StackSpace = keyof typeof spaceScale;
4
+ import { cn } from '@cdx-ui/utils';
5
+ import { vStackRootVariants, type StackSpace } from './styles';
19
6
 
20
7
  export interface VStackProps extends ViewProps {
21
8
  className?: string;
@@ -24,17 +11,15 @@ export interface VStackProps extends ViewProps {
24
11
  }
25
12
 
26
13
  export const VStack = forwardRef<View, VStackProps>(
27
- ({ space, reversed, style, className, children, ...restProps }, ref: ForwardedRef<View>) => {
28
- const gap = space ? spaceScale[space] : undefined;
14
+ (
15
+ { reversed = false, space, style, className, children, ...restProps },
16
+ ref: ForwardedRef<View>,
17
+ ) => {
29
18
  return (
30
19
  <View
31
20
  ref={ref}
32
- className={className}
33
- style={[
34
- { flexDirection: reversed ? 'column-reverse' : 'column' },
35
- gap ? { gap } : null,
36
- style,
37
- ]}
21
+ className={cn(vStackRootVariants({ reversed, space }), className)}
22
+ style={style}
38
23
  {...restProps}
39
24
  >
40
25
  {children}
@@ -0,0 +1,49 @@
1
+ import { cva } from 'class-variance-authority';
2
+
3
+ export type StackSpace = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
4
+
5
+ const spaceMap = {
6
+ xs: 'gap-1',
7
+ sm: 'gap-2',
8
+ md: 'gap-3',
9
+ lg: 'gap-4',
10
+ xl: 'gap-5',
11
+ } as const satisfies Record<StackSpace, string>;
12
+
13
+ export const hStackRootVariants = cva([], {
14
+ variants: {
15
+ reversed: {
16
+ true: 'flex-row-reverse',
17
+ false: 'flex-row',
18
+ },
19
+ space: {
20
+ xs: spaceMap.xs,
21
+ sm: spaceMap.sm,
22
+ md: spaceMap.md,
23
+ lg: spaceMap.lg,
24
+ xl: spaceMap.xl,
25
+ },
26
+ },
27
+ defaultVariants: {
28
+ reversed: false,
29
+ },
30
+ });
31
+
32
+ export const vStackRootVariants = cva([], {
33
+ variants: {
34
+ reversed: {
35
+ true: 'flex-col-reverse',
36
+ false: 'flex-col',
37
+ },
38
+ space: {
39
+ xs: spaceMap.xs,
40
+ sm: spaceMap.sm,
41
+ md: spaceMap.md,
42
+ lg: spaceMap.lg,
43
+ xl: spaceMap.xl,
44
+ },
45
+ },
46
+ defaultVariants: {
47
+ reversed: false,
48
+ },
49
+ });
@@ -0,0 +1,38 @@
1
+ import { forwardRef } from 'react';
2
+ import { Switch as RNSwitch, type SwitchProps } from 'react-native';
3
+ import { cn } from '@cdx-ui/utils';
4
+ import {
5
+ switchIosBgVariants,
6
+ switchThumbColorVariants,
7
+ switchTrackOffVariants,
8
+ switchTrackOnVariants,
9
+ } from './styles';
10
+
11
+ export interface BaseSwitchProps extends Omit<SwitchProps, 'className'> {
12
+ states?: Record<string, boolean | undefined>;
13
+ dataSet?: Record<string, string>;
14
+ className?: string;
15
+ size?: string;
16
+ }
17
+
18
+ export const BaseSwitch = forwardRef<RNSwitch, BaseSwitchProps>(
19
+ ({ states, className, disabled, value, ...props }, ref) => {
20
+ const isChecked = value ?? states?.checked ?? false;
21
+ const isDisabled = disabled ?? states?.disabled ?? false;
22
+ const isInvalid = states?.invalid ?? false;
23
+
24
+ const uniwindProps: Record<string, string | undefined> = {
25
+ className,
26
+ thumbColorClassName: cn(switchThumbColorVariants({ isDisabled })),
27
+ trackColorOnClassName: cn(switchTrackOnVariants({ isInvalid })),
28
+ trackColorOffClassName: cn(switchTrackOffVariants({ isInvalid })),
29
+ ios_backgroundColorClassName: cn(switchIosBgVariants({ isInvalid })),
30
+ };
31
+
32
+ return (
33
+ <RNSwitch ref={ref} value={isChecked} disabled={isDisabled} {...uniwindProps} {...props} />
34
+ );
35
+ },
36
+ );
37
+
38
+ BaseSwitch.displayName = 'BaseSwitch';