@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
@@ -0,0 +1,69 @@
1
+ import { forwardRef } from 'react';
2
+ import { Pressable, View } from 'react-native';
3
+ import { cn } from '@cdx-ui/utils';
4
+ import {
5
+ switchThumbVariants,
6
+ switchTrackVariants,
7
+ switchWebTrackColorVariants,
8
+ type SwitchVariantProps,
9
+ } from './styles';
10
+
11
+ export interface BaseSwitchProps {
12
+ value?: boolean;
13
+ onValueChange?: (value: boolean) => void;
14
+ disabled?: boolean;
15
+ states?: Record<string, boolean | undefined>;
16
+ dataSet?: Record<string, string>;
17
+ className?: string;
18
+ size?: SwitchVariantProps['size'];
19
+ onFocus?: () => void;
20
+ onBlur?: () => void;
21
+ }
22
+
23
+ export const BaseSwitch = forwardRef<View, BaseSwitchProps>(
24
+ (
25
+ {
26
+ value,
27
+ onValueChange,
28
+ disabled,
29
+ states,
30
+ dataSet,
31
+ className,
32
+ size = 'md',
33
+ onFocus,
34
+ onBlur,
35
+ ...props
36
+ },
37
+ ref,
38
+ ) => {
39
+ const isChecked = value ?? states?.checked ?? false;
40
+ const isDisabled = disabled ?? states?.disabled ?? false;
41
+ const isInvalid = states?.invalid ?? false;
42
+
43
+ return (
44
+ <Pressable
45
+ ref={ref}
46
+ role="switch"
47
+ aria-checked={isChecked}
48
+ aria-disabled={isDisabled}
49
+ disabled={isDisabled}
50
+ onPress={() => onValueChange?.(!isChecked)}
51
+ onFocus={onFocus}
52
+ onBlur={onBlur}
53
+ tabIndex={0}
54
+ className={cn(
55
+ switchTrackVariants({ size }),
56
+ switchWebTrackColorVariants({ isChecked, isInvalid }),
57
+ className,
58
+ )}
59
+ // @ts-expect-error dataSet is a RNW/Uniwind prop not in Pressable types
60
+ dataSet={dataSet}
61
+ {...props}
62
+ >
63
+ <View className={cn(switchThumbVariants({ size, isChecked }))} />
64
+ </Pressable>
65
+ );
66
+ },
67
+ );
68
+
69
+ BaseSwitch.displayName = 'BaseSwitch';
@@ -0,0 +1,13 @@
1
+ import { type ISwitchProps, createSwitch } from '@cdx-ui/primitives';
2
+ import { BaseSwitch } from './BaseSwitch';
3
+ import type { SwitchVariantProps } from './styles';
4
+
5
+ const SwitchPrimitive = createSwitch({ Root: BaseSwitch });
6
+
7
+ export interface SwitchProps extends ISwitchProps, SwitchVariantProps {
8
+ className?: string;
9
+ }
10
+
11
+ export const Switch = SwitchPrimitive;
12
+
13
+ export type { SwitchVariantProps };
@@ -0,0 +1,120 @@
1
+ import { cva, type VariantProps } from 'class-variance-authority';
2
+
3
+ // =============================================================================
4
+ // NATIVE — Uniwind className bindings for RN Switch
5
+ // =============================================================================
6
+
7
+ export const switchThumbColorVariants = cva(['accent-white'], {
8
+ variants: {
9
+ isDisabled: {
10
+ true: 'accent-gray-200',
11
+ false: '',
12
+ },
13
+ },
14
+ defaultVariants: { isDisabled: false },
15
+ });
16
+
17
+ export const switchTrackOnVariants = cva(['accent-blue-500'], {
18
+ variants: {
19
+ isInvalid: {
20
+ true: 'accent-red-500',
21
+ false: '',
22
+ },
23
+ },
24
+ defaultVariants: { isInvalid: false },
25
+ });
26
+
27
+ export const switchTrackOffVariants = cva(['accent-gray-300'], {
28
+ variants: {
29
+ isInvalid: {
30
+ true: 'accent-red-300',
31
+ false: '',
32
+ },
33
+ },
34
+ defaultVariants: { isInvalid: false },
35
+ });
36
+
37
+ export const switchIosBgVariants = cva(['accent-gray-300'], {
38
+ variants: {
39
+ isInvalid: {
40
+ true: 'accent-red-300',
41
+ false: '',
42
+ },
43
+ },
44
+ defaultVariants: { isInvalid: false },
45
+ });
46
+
47
+ // =============================================================================
48
+ // WEB — Tailwind classes for custom Pressable toggle
49
+ // =============================================================================
50
+
51
+ export const switchTrackVariants = cva(
52
+ [
53
+ 'flex-row items-center rounded-full cursor-pointer',
54
+ 'transition-colors duration-200',
55
+ 'data-[disabled=true]:opacity-50 data-[disabled=true]:cursor-not-allowed',
56
+ 'web:data-[focus-visible=true]:ring-3 web:data-[focus-visible=true]:ring-blue-300/50',
57
+ 'web:data-[invalid=true]:data-[focus-visible=true]:ring-red-300/50',
58
+ ],
59
+ {
60
+ variants: {
61
+ size: {
62
+ sm: 'w-9 h-5 p-0.5',
63
+ md: 'w-11 h-6 p-0.5',
64
+ lg: 'w-14 h-8 p-1',
65
+ },
66
+ },
67
+ defaultVariants: {
68
+ size: 'md',
69
+ },
70
+ },
71
+ );
72
+
73
+ export const switchWebTrackColorVariants = cva([], {
74
+ variants: {
75
+ isChecked: {
76
+ true: 'bg-blue-500 data-[hover=true]:bg-blue-600',
77
+ false: 'bg-gray-300 data-[hover=true]:bg-gray-400',
78
+ },
79
+ isInvalid: {
80
+ true: '',
81
+ false: '',
82
+ },
83
+ },
84
+ compoundVariants: [
85
+ { isChecked: true, isInvalid: true, className: 'bg-red-500 data-[hover=true]:bg-red-600' },
86
+ { isChecked: false, isInvalid: true, className: 'bg-red-300 data-[hover=true]:bg-red-400' },
87
+ ],
88
+ defaultVariants: {
89
+ isChecked: false,
90
+ isInvalid: false,
91
+ },
92
+ });
93
+
94
+ export const switchThumbVariants = cva(
95
+ ['rounded-full bg-white shadow-sm', 'transition-transform duration-200'],
96
+ {
97
+ variants: {
98
+ size: {
99
+ sm: 'w-4 h-4',
100
+ md: 'w-5 h-5',
101
+ lg: 'w-6 h-6',
102
+ },
103
+ isChecked: {
104
+ true: '',
105
+ false: 'translate-x-0',
106
+ },
107
+ },
108
+ compoundVariants: [
109
+ { size: 'sm', isChecked: true, className: 'translate-x-4' },
110
+ { size: 'md', isChecked: true, className: 'translate-x-5' },
111
+ { size: 'lg', isChecked: true, className: 'translate-x-6' },
112
+ ],
113
+ defaultVariants: {
114
+ size: 'md',
115
+ isChecked: false,
116
+ },
117
+ },
118
+ );
119
+
120
+ export type SwitchVariantProps = VariantProps<typeof switchTrackVariants>;
@@ -1,6 +1,8 @@
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';
@@ -0,0 +1,29 @@
1
+ import type { MetroConfig } from 'metro-config';
2
+ import { withUniwindConfig } from 'uniwind/metro';
3
+
4
+ export interface CdxMetroConfigOptions {
5
+ /** Path to the CSS entry file (e.g., `'./global.css'`). */
6
+ cssEntryFile: string;
7
+ /** Path where generated Tailwind class type definitions are written. */
8
+ generatedTypesFile?: string;
9
+ }
10
+
11
+ /**
12
+ * Wraps a Metro config with CDX UI's styling-layer configuration.
13
+ *
14
+ * Today this delegates to Uniwind. If the styling layer is swapped (see
15
+ * `docs/research/uniwind-to-nativewind-contingency.md`), only the internals
16
+ * of this function change — consuming Metro configs stay the same.
17
+ *
18
+ * Must be the **outermost** Metro config wrapper (after any other wrappers
19
+ * like `withStorybook`).
20
+ */
21
+ export function withCdxMetroConfig<T extends MetroConfig>(
22
+ config: T,
23
+ options: CdxMetroConfigOptions,
24
+ ): T {
25
+ return withUniwindConfig(config, {
26
+ cssEntryFile: options.cssEntryFile,
27
+ dtsFile: options.generatedTypesFile,
28
+ }) as T;
29
+ }