cpk-ui 0.5.4 → 0.7.0

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 (136) hide show
  1. package/README.md +80 -147
  2. package/components/modals/AlertDialog/AlertDialog.d.ts.map +1 -1
  3. package/components/modals/AlertDialog/AlertDialog.js +14 -7
  4. package/components/modals/Snackbar/Snackbar.d.ts.map +1 -1
  5. package/components/modals/Snackbar/Snackbar.js +20 -17
  6. package/components/uis/Accordion/AccordionItem.d.ts.map +1 -1
  7. package/components/uis/Accordion/AccordionItem.js +41 -17
  8. package/components/uis/Button/Button.d.ts +2 -1
  9. package/components/uis/Button/Button.d.ts.map +1 -1
  10. package/components/uis/Button/Button.js +11 -11
  11. package/components/uis/Card/Card.d.ts +2 -1
  12. package/components/uis/Card/Card.d.ts.map +1 -1
  13. package/components/uis/Card/Card.js +12 -3
  14. package/components/uis/Checkbox/Checkbox.d.ts +2 -1
  15. package/components/uis/Checkbox/Checkbox.d.ts.map +1 -1
  16. package/components/uis/Checkbox/Checkbox.js +2 -2
  17. package/components/uis/CustomPressable/CustomPressable.d.ts.map +1 -1
  18. package/components/uis/CustomPressable/CustomPressable.js +6 -6
  19. package/components/uis/EditText/EditText.d.ts +1 -0
  20. package/components/uis/EditText/EditText.d.ts.map +1 -1
  21. package/components/uis/EditText/EditText.js +18 -13
  22. package/components/uis/Fab/Fab.d.ts +2 -2
  23. package/components/uis/Fab/Fab.d.ts.map +1 -1
  24. package/components/uis/Fab/Fab.js +22 -4
  25. package/components/uis/Icon/Icon.d.ts.map +1 -1
  26. package/components/uis/Icon/Icon.js +6 -3
  27. package/components/uis/IconButton/IconButton.d.ts +2 -1
  28. package/components/uis/IconButton/IconButton.d.ts.map +1 -1
  29. package/components/uis/IconButton/IconButton.js +44 -42
  30. package/components/uis/LoadingIndicator/LoadingIndicator.d.ts +2 -1
  31. package/components/uis/LoadingIndicator/LoadingIndicator.d.ts.map +1 -1
  32. package/components/uis/LoadingIndicator/LoadingIndicator.js +4 -4
  33. package/components/uis/RadioGroup/RadioButton.d.ts +2 -1
  34. package/components/uis/RadioGroup/RadioButton.d.ts.map +1 -1
  35. package/components/uis/RadioGroup/RadioButton.js +2 -2
  36. package/components/uis/RadioGroup/RadioGroup.d.ts.map +1 -1
  37. package/components/uis/RadioGroup/RadioGroup.js +16 -3
  38. package/components/uis/Rating/Rating.d.ts.map +1 -1
  39. package/components/uis/Rating/Rating.js +23 -19
  40. package/components/uis/SegmentedControl/SegmentedControl.d.ts.map +1 -1
  41. package/components/uis/SegmentedControl/SegmentedControl.js +1 -1
  42. package/components/uis/StatusbarBrightness/StatusBarBrightness.d.ts +2 -2
  43. package/components/uis/StatusbarBrightness/StatusBarBrightness.d.ts.map +1 -1
  44. package/components/uis/StatusbarBrightness/StatusBarBrightness.js +1 -1
  45. package/components/uis/SwitchToggle/SwitchToggle.d.ts +2 -1
  46. package/components/uis/SwitchToggle/SwitchToggle.d.ts.map +1 -1
  47. package/components/uis/SwitchToggle/SwitchToggle.js +2 -2
  48. package/hooks/useHoverState.d.ts +8 -0
  49. package/hooks/useHoverState.d.ts.map +1 -0
  50. package/hooks/useHoverState.js +16 -0
  51. package/package.json +18 -6
  52. package/providers/ThemeProvider.d.ts.map +1 -1
  53. package/providers/ThemeProvider.js +0 -1
  54. package/providers/index.d.ts.map +1 -1
  55. package/providers/index.js +3 -2
  56. package/components/uis/Icon/selection.json +0 -1
  57. package/src/components/common/ErrorBoundary/ErrorBoundary.tsx +0 -75
  58. package/src/components/modals/AlertDialog/AlertDialog.stories.tsx +0 -216
  59. package/src/components/modals/AlertDialog/AlertDialog.test.tsx +0 -251
  60. package/src/components/modals/AlertDialog/AlertDialog.tsx +0 -356
  61. package/src/components/modals/Snackbar/Snackbar.stories.tsx +0 -182
  62. package/src/components/modals/Snackbar/Snackbar.test.tsx +0 -319
  63. package/src/components/modals/Snackbar/Snackbar.tsx +0 -260
  64. package/src/components/modals/Snackbar/const.ts +0 -4
  65. package/src/components/uis/Accordion/Accordion.stories.tsx +0 -167
  66. package/src/components/uis/Accordion/Accordion.test.tsx +0 -272
  67. package/src/components/uis/Accordion/Accordion.tsx +0 -109
  68. package/src/components/uis/Accordion/AccordionItem.tsx +0 -306
  69. package/src/components/uis/Button/Button.stories.tsx +0 -218
  70. package/src/components/uis/Button/Button.test.tsx +0 -620
  71. package/src/components/uis/Button/Button.tsx +0 -436
  72. package/src/components/uis/Card/Card.test.tsx +0 -146
  73. package/src/components/uis/Card/Card.tsx +0 -102
  74. package/src/components/uis/Checkbox/Checkbox.stories.tsx +0 -216
  75. package/src/components/uis/Checkbox/Checkbox.test.tsx +0 -173
  76. package/src/components/uis/Checkbox/Checkbox.tsx +0 -220
  77. package/src/components/uis/CustomPressable/CustomPressable.tsx +0 -48
  78. package/src/components/uis/EditText/EditText.stories.tsx +0 -124
  79. package/src/components/uis/EditText/EditText.test.tsx +0 -477
  80. package/src/components/uis/EditText/EditText.tsx +0 -590
  81. package/src/components/uis/Fab/Fab.stories.tsx +0 -133
  82. package/src/components/uis/Fab/Fab.test.tsx +0 -110
  83. package/src/components/uis/Fab/Fab.tsx +0 -168
  84. package/src/components/uis/Hr/Hr.test.tsx +0 -26
  85. package/src/components/uis/Hr/Hr.tsx +0 -19
  86. package/src/components/uis/Icon/Icon.stories.tsx +0 -98
  87. package/src/components/uis/Icon/Icon.test.tsx +0 -49
  88. package/src/components/uis/Icon/Icon.tsx +0 -3819
  89. package/src/components/uis/IconButton/IconButton.test.tsx +0 -165
  90. package/src/components/uis/IconButton/IconButton.tsx +0 -275
  91. package/src/components/uis/LoadingIndicator/LoadingIndicator.tsx +0 -126
  92. package/src/components/uis/LoadingIndicator/LodingIndicator.stories.tsx +0 -81
  93. package/src/components/uis/PinchZoom/PinchZoom.stories.tsx +0 -266
  94. package/src/components/uis/PinchZoom/PinchZoom.test.tsx +0 -113
  95. package/src/components/uis/PinchZoom/PinchZoom.tsx +0 -424
  96. package/src/components/uis/RadioGroup/RadioButton.tsx +0 -188
  97. package/src/components/uis/RadioGroup/RadioGroup.stories.tsx +0 -188
  98. package/src/components/uis/RadioGroup/RadioGroup.test.tsx +0 -287
  99. package/src/components/uis/RadioGroup/RadioGroup.tsx +0 -109
  100. package/src/components/uis/Rating/Rating.test.tsx +0 -98
  101. package/src/components/uis/Rating/Rating.tsx +0 -200
  102. package/src/components/uis/SegmentedControl/SegmentedControl.stories.tsx +0 -546
  103. package/src/components/uis/SegmentedControl/SegmentedControl.test.tsx +0 -274
  104. package/src/components/uis/SegmentedControl/SegmentedControl.tsx +0 -229
  105. package/src/components/uis/StatusbarBrightness/StatusBarBrightness.test.tsx +0 -41
  106. package/src/components/uis/StatusbarBrightness/StatusBarBrightness.tsx +0 -26
  107. package/src/components/uis/Styled/StyledComponents.tsx +0 -217
  108. package/src/components/uis/SwitchToggle/SwitchToggle.stories.tsx +0 -75
  109. package/src/components/uis/SwitchToggle/SwitchToggle.test.tsx +0 -105
  110. package/src/components/uis/SwitchToggle/SwitchToggle.tsx +0 -305
  111. package/src/components/uis/Typography/Typography.stories.tsx +0 -149
  112. package/src/components/uis/Typography/Typography.test.tsx +0 -58
  113. package/src/components/uis/Typography/Typography.tsx +0 -386
  114. package/src/hooks/index.ts +0 -2
  115. package/src/hooks/useAnimations.ts +0 -71
  116. package/src/hooks/useDebouncedColorScheme.tsx +0 -30
  117. package/src/hooks/useOptimizedStyles.ts +0 -22
  118. package/src/hooks/usePerformance.ts +0 -93
  119. package/src/index.tsx +0 -38
  120. package/src/providers/ThemeProvider.tsx +0 -177
  121. package/src/providers/index.tsx +0 -130
  122. package/src/test/testUtils.tsx +0 -101
  123. package/src/types/common.ts +0 -77
  124. package/src/types/index.ts +0 -1
  125. package/src/types/kstyled.d.ts +0 -6
  126. package/src/utils/accessibility.ts +0 -110
  127. package/src/utils/colors.ts +0 -151
  128. package/src/utils/createCtx.tsx +0 -26
  129. package/src/utils/guards.ts +0 -93
  130. package/src/utils/index.ts +0 -2
  131. package/src/utils/performanceTest.ts +0 -174
  132. package/src/utils/platform.ts +0 -69
  133. package/src/utils/theme.ts +0 -38
  134. package/test/testUtils.d.ts +0 -113
  135. package/test/testUtils.d.ts.map +0 -1
  136. package/test/testUtils.js +0 -65
@@ -1,216 +0,0 @@
1
- import {type ComponentProps} from 'react';
2
- import {Text} from 'react-native';
3
- import {css} from 'kstyled';
4
- import type {Meta, StoryObj} from '@storybook/react';
5
-
6
- import {withThemeProvider} from '../../../../.storybook/decorators';
7
- import {Checkbox, CheckboxColor} from './Checkbox';
8
- import {Typography} from '../Typography/Typography';
9
-
10
- const colors: CheckboxColor[] = [
11
- 'primary',
12
- 'success',
13
- 'info',
14
- 'warning',
15
- 'danger',
16
- 'secondary',
17
- ];
18
-
19
- const meta = {
20
- title: 'Checkbox',
21
- component: (props) => <Checkbox {...props} />,
22
- parameters: {
23
- notes: `
24
- An animated Checkbox component with smooth transitions and flexible sizing options.
25
-
26
- ## Features
27
- - **Smooth Animations**: Spring-based fade and scale animations
28
- - **Flexible Sizing**: Preset sizes and custom numeric values
29
- - **Color Variants**: Multiple color options for different contexts
30
- - **Disabled State**: Can disable checkbox interaction
31
- - **Icon Elements**: Add elements before or after the checkbox
32
- - **Optimized Performance**: Memoized for better performance
33
-
34
- ## Size Options
35
- - \`small\`: 16px checkbox
36
- - \`medium\`: 20px checkbox (default)
37
- - \`large\`: 24px checkbox
38
- - Custom number: Any pixel value (e.g., \`size={28}\`)
39
-
40
- ## Animation Details
41
- The checkbox uses two simultaneous animations:
42
- - **Fade**: Opacity transition from 0 to 1
43
- - **Scale**: Size transition from 0.8 to 1.0
44
-
45
- ## Usage
46
-
47
- ### With String Text
48
- \`\`\`tsx
49
- <Checkbox
50
- checked={isChecked}
51
- onPress={() => setIsChecked(!isChecked)}
52
- size="medium"
53
- color="primary"
54
- text="Accept terms"
55
- direction="right"
56
- />
57
- \`\`\`
58
-
59
- ### With Custom Element
60
- \`\`\`tsx
61
- <Checkbox
62
- checked={isChecked}
63
- onPress={() => setIsChecked(!isChecked)}
64
- size="large"
65
- color="success"
66
- text={<CustomComponent />}
67
- direction="left"
68
- />
69
- \`\`\`
70
- `,
71
- docs: {
72
- description: {
73
- component: `
74
- An animated Checkbox component with smooth transitions and flexible sizing options.
75
-
76
- ## Features
77
- - **Smooth Animations**: Spring-based fade and scale animations
78
- - **Flexible Sizing**: Preset sizes and custom numeric values
79
- - **Color Variants**: Multiple color options for different contexts
80
- - **Disabled State**: Can disable checkbox interaction
81
- - **Icon Elements**: Add elements before or after the checkbox
82
- - **Optimized Performance**: Memoized for better performance
83
-
84
- ## Size Options
85
- - \`small\`: 16px checkbox
86
- - \`medium\`: 20px checkbox (default)
87
- - \`large\`: 24px checkbox
88
- - Custom number: Any pixel value (e.g., \`size={28}\`)
89
-
90
- ## Animation Details
91
- The checkbox uses two simultaneous animations:
92
- - **Fade**: Opacity transition from 0 to 1
93
- - **Scale**: Size transition from 0.8 to 1.0
94
-
95
- ## Usage
96
-
97
- ### With String Text
98
- \`\`\`tsx
99
- <Checkbox
100
- checked={isChecked}
101
- onPress={() => setIsChecked(!isChecked)}
102
- size="medium"
103
- color="primary"
104
- text="Accept terms"
105
- direction="right"
106
- />
107
- \`\`\`
108
-
109
- ### With Custom Element
110
- \`\`\`tsx
111
- <Checkbox
112
- checked={isChecked}
113
- onPress={() => setIsChecked(!isChecked)}
114
- size="large"
115
- color="success"
116
- text={<CustomComponent />}
117
- direction="left"
118
- />
119
- \`\`\`
120
- `,
121
- },
122
- },
123
- },
124
- argTypes: {
125
- color: {
126
- control: 'select',
127
- options: colors,
128
- description: 'Color variant of the checkbox',
129
- },
130
- size: {
131
- control: 'radio',
132
- options: ['small', 'medium', 'large', 16, 20, 24, 32],
133
- description: 'Checkbox size: "small" (16px), "medium" (20px), "large" (24px), or custom number in pixels',
134
- },
135
- checked: {
136
- defaultValue: false,
137
- type: 'boolean',
138
- description: 'Whether the checkbox is checked',
139
- },
140
- disabled: {
141
- description: 'Disables checkbox interaction',
142
- },
143
- direction: {
144
- control: 'radio',
145
- options: ['left', 'right'],
146
- description: 'Position of the text relative to the checkbox',
147
- },
148
- text: {
149
- description: 'Text or custom element to display next to the checkbox',
150
- },
151
- },
152
- decorators: [withThemeProvider],
153
- } satisfies Meta<typeof Checkbox>;
154
-
155
- export default meta;
156
-
157
- type Story = StoryObj<typeof meta>;
158
-
159
- export const Basic: Story = {
160
- args: {
161
- color: 'primary',
162
- size: 'medium',
163
- text: 'Click Checkbox!',
164
- direction: 'right',
165
- checked: false,
166
- onPress: () => {},
167
- },
168
- argTypes: {
169
- theme: {
170
- control: 'select',
171
- options: ['light', 'dark'],
172
- },
173
- },
174
- };
175
-
176
- export const WithLeftText: Story = {
177
- args: {
178
- color: 'primary',
179
- size: 'medium',
180
- text: 'Accept terms and conditions',
181
- direction: 'left',
182
- checked: false,
183
- onPress: () => {},
184
- },
185
- argTypes: {
186
- theme: {
187
- control: 'select',
188
- options: ['light', 'dark'],
189
- },
190
- },
191
- };
192
-
193
- export const WithCustomElement: Story = {
194
- args: {
195
- color: 'success',
196
- size: 'large',
197
- text: (
198
- <Typography.Body2
199
- style={css`
200
- font-weight: bold;
201
- `}
202
- >
203
- Custom Element
204
- </Typography.Body2>
205
- ),
206
- direction: 'right',
207
- checked: true,
208
- onPress: () => {},
209
- },
210
- argTypes: {
211
- theme: {
212
- control: 'select',
213
- options: ['light', 'dark'],
214
- },
215
- },
216
- };
@@ -1,173 +0,0 @@
1
- import React, {type ReactElement} from 'react';
2
- import {View} from 'react-native';
3
- import type {RenderAPI} from '@testing-library/react-native';
4
- import {render} from '@testing-library/react-native';
5
-
6
- import {createComponent} from '../../../../test/testUtils';
7
- import {Checkbox, type CheckboxProps} from './Checkbox';
8
- import {light} from '../../../utils/colors';
9
-
10
- let testingLib: RenderAPI;
11
-
12
- const Component = (props?: CheckboxProps): ReactElement =>
13
- createComponent(<Checkbox {...props} />);
14
-
15
- describe('[Checkbox]', () => {
16
- it('should render without crashing', () => {
17
- testingLib = render(Component());
18
-
19
- const json = testingLib.toJSON();
20
-
21
- expect(json).toBeTruthy();
22
- });
23
-
24
- it('should render `disabled` button', () => {
25
- testingLib = render(
26
- Component({
27
- disabled: true,
28
- }),
29
- );
30
-
31
- const json = testingLib.toJSON();
32
-
33
- expect(json).toBeTruthy();
34
- });
35
-
36
- it('should render `startElement`', () => {
37
- testingLib = render(
38
- Component({
39
- startElement: <View />,
40
- }),
41
- );
42
-
43
- const json = testingLib.toJSON();
44
-
45
- expect(json).toBeTruthy();
46
- });
47
-
48
- it('should render `endElement`', () => {
49
- testingLib = render(
50
- Component({
51
- endElement: <View />,
52
- }),
53
- );
54
-
55
- const json = testingLib.toJSON();
56
-
57
- expect(json).toBeTruthy();
58
- });
59
-
60
- describe('colors', () => {
61
- const colors = [
62
- 'primary',
63
- 'secondary',
64
- 'success',
65
- 'info',
66
- 'warning',
67
- 'danger',
68
- ];
69
-
70
- it('should render all colors', () => {
71
- testingLib = render(
72
- createComponent(
73
- <View>
74
- {colors.map((color) => (
75
- <Checkbox
76
- key={color}
77
- checked={true}
78
- color={color as any}
79
- />
80
- ))}
81
- </View>,
82
- ),
83
- );
84
-
85
- const json = testingLib.toJSON();
86
- // $type is a transient prop used for styling only,
87
- // so it's not accessible via props in tests
88
- // Just verify the component renders correctly with all colors
89
- expect(json).toBeTruthy();
90
- });
91
-
92
- it('should render with specific color type and verify checked state', () => {
93
- testingLib = render(
94
- Component({
95
- color: 'success',
96
- checked: true,
97
- }),
98
- );
99
-
100
- const checkbox = testingLib.getByTestId('cpk-ui-checkbox');
101
-
102
- // While we can't directly test transient props ($type, $checked),
103
- // we can verify the component renders and has the testID
104
- expect(checkbox).toBeTruthy();
105
-
106
- // The checkbox wrapper receives $checked prop which affects its styling
107
- // We can verify it's rendered in checked state by checking the component structure
108
- expect(checkbox).toBeDefined();
109
- });
110
-
111
- it('should render unchecked state', () => {
112
- testingLib = render(
113
- Component({
114
- color: 'primary',
115
- checked: false,
116
- }),
117
- );
118
-
119
- const checkbox = testingLib.getByTestId('cpk-ui-checkbox');
120
- expect(checkbox).toBeTruthy();
121
- });
122
- });
123
-
124
- describe('sizes', () => {
125
- it('should render with small size', () => {
126
- testingLib = render(
127
- Component({
128
- size: 'small',
129
- checked: true,
130
- }),
131
- );
132
-
133
- const checkbox = testingLib.getByTestId('cpk-ui-checkbox');
134
- expect(checkbox).toBeTruthy();
135
- });
136
-
137
- it('should render with medium size', () => {
138
- testingLib = render(
139
- Component({
140
- size: 'medium',
141
- checked: true,
142
- }),
143
- );
144
-
145
- const checkbox = testingLib.getByTestId('cpk-ui-checkbox');
146
- expect(checkbox).toBeTruthy();
147
- });
148
-
149
- it('should render with large size', () => {
150
- testingLib = render(
151
- Component({
152
- size: 'large',
153
- checked: true,
154
- }),
155
- );
156
-
157
- const checkbox = testingLib.getByTestId('cpk-ui-checkbox');
158
- expect(checkbox).toBeTruthy();
159
- });
160
-
161
- it('should render with custom numeric size', () => {
162
- testingLib = render(
163
- Component({
164
- size: 24,
165
- checked: true,
166
- }),
167
- );
168
-
169
- const checkbox = testingLib.getByTestId('cpk-ui-checkbox');
170
- expect(checkbox).toBeTruthy();
171
- });
172
- });
173
- });
@@ -1,220 +0,0 @@
1
- import React, {useCallback, useEffect, useMemo, useRef, type ReactElement} from 'react';
2
- import type {StyleProp, TextStyle, ViewStyle} from 'react-native';
3
- import {Animated, Platform, TouchableOpacity, View} from 'react-native';
4
- import {styled, css} from 'kstyled';
5
-
6
- import {
7
- CheckboxWrapper,
8
- CheckboxWrapperOutlined,
9
- } from '../Styled/StyledComponents';
10
- import {Icon} from '../Icon/Icon';
11
- import {Typography} from '../Typography/Typography';
12
- import {useTheme} from '../../../providers/ThemeProvider';
13
-
14
- type Styles = {
15
- container?: StyleProp<ViewStyle>;
16
- checkbox?: StyleProp<ViewStyle>;
17
- check?: ViewStyle;
18
- text?: StyleProp<TextStyle>;
19
- };
20
-
21
- export type CheckboxColor =
22
- | 'primary'
23
- | 'secondary'
24
- | 'success'
25
- | 'danger'
26
- | 'warning'
27
- | 'info';
28
-
29
- export type CheckboxSizeType = 'small' | 'medium' | 'large' | number;
30
-
31
- export interface CheckboxProps {
32
- onPress?: () => void;
33
- style?: StyleProp<ViewStyle>;
34
- styles?: Styles;
35
- color?: CheckboxColor;
36
- size?: CheckboxSizeType;
37
- disabled?: boolean;
38
- checked?: boolean;
39
- text?: string | ReactElement;
40
- direction?: 'left' | 'right';
41
- }
42
-
43
- const Container = styled(TouchableOpacity)`
44
- flex-direction: row;
45
- align-items: center;
46
- `;
47
-
48
- const StyledCheckboxOutlined = styled(CheckboxWrapperOutlined)`
49
- border-width: 1px;
50
- margin: 0 6px;
51
-
52
- justify-content: center;
53
- align-items: center;
54
- `;
55
-
56
- // Create animated version for checkbox that needs animation
57
- const AnimatedView = Animated.createAnimatedComponent(View);
58
- const AnimatedCheckbox = styled(AnimatedView)`
59
- margin: 0 6px;
60
-
61
- justify-content: center;
62
- align-items: center;
63
- `;
64
-
65
- const StyledCheck = styled(Icon)<{$checked?: boolean}>`
66
- font-weight: bold;
67
- color: ${({theme, $checked}) => ($checked ? theme.bg.basic : 'transparent')};
68
- `;
69
-
70
- export function Checkbox({
71
- style,
72
- styles,
73
- text,
74
- direction = 'right',
75
- color = 'primary',
76
- size = 'medium',
77
- disabled = false,
78
- checked = false,
79
- onPress,
80
- }: CheckboxProps): ReactElement {
81
- const checkboxSize = typeof size === 'number'
82
- ? size
83
- : size === 'small'
84
- ? 16
85
- : size === 'large'
86
- ? 24
87
- : 20;
88
-
89
- const textFontSize = typeof size === 'number'
90
- ? size * 0.7
91
- : size === 'small'
92
- ? 12
93
- : size === 'large'
94
- ? 16
95
- : 14;
96
- // Separate animated values for fade and scale
97
- const fadeAnim = useRef(new Animated.Value(checked ? 1 : 0)).current;
98
- const scaleAnim = useRef(new Animated.Value(checked ? 1 : 0.8)).current; // Start from 0.8, not 0
99
- const {theme} = useTheme();
100
-
101
- // Memoize animation config
102
- const animationConfig = useMemo(
103
- () => ({
104
- useNativeDriver: Platform.select({
105
- web: false,
106
- default: true,
107
- }),
108
- }),
109
- [],
110
- );
111
-
112
- useEffect(() => {
113
- Animated.parallel([
114
- Animated.spring(fadeAnim, {
115
- toValue: checked ? 1 : 0,
116
- ...animationConfig,
117
- }),
118
- Animated.spring(scaleAnim, {
119
- toValue: checked ? 1 : 0.8, // Scale to 0.8 when unchecked, not 0
120
- ...animationConfig,
121
- }),
122
- ]).start();
123
- }, [fadeAnim, scaleAnim, checked, animationConfig]);
124
-
125
- // Memoize container styles
126
- const containerStyles = useMemo(
127
- () => [
128
- css`
129
- flex: 1;
130
- padding: 6px 0;
131
-
132
- flex-direction: ${direction === 'left' ? 'row-reverse' : 'row'};
133
- column-gap: 2px;
134
- align-items: center;
135
- `,
136
- styles?.container,
137
- ],
138
- [styles?.container, direction],
139
- );
140
-
141
- // Memoize checkbox size styles
142
- const checkboxSizeStyles = useMemo(
143
- () => ({
144
- width: checkboxSize,
145
- height: checkboxSize,
146
- }),
147
- [checkboxSize],
148
- );
149
-
150
- // Memoize animated styles
151
- const animatedStyles = useMemo(
152
- () => [
153
- checkboxSizeStyles,
154
- styles?.checkbox,
155
- {
156
- opacity: fadeAnim,
157
- transform: [{scale: scaleAnim}],
158
- },
159
- ],
160
- [checkboxSizeStyles, styles?.checkbox, fadeAnim, scaleAnim],
161
- );
162
-
163
- // Memoize text styles
164
- const textStyles = useMemo(
165
- () => [
166
- css`
167
- font-size: ${textFontSize}px;
168
- `,
169
- styles?.text,
170
- ],
171
- [textFontSize, styles?.text],
172
- );
173
-
174
- // Render text element
175
- const TextElement = useMemo(() => {
176
- if (!text) return null;
177
-
178
- if (typeof text === 'string') {
179
- return (
180
- <Typography.Body2 style={textStyles}>
181
- {text}
182
- </Typography.Body2>
183
- );
184
- }
185
-
186
- return text;
187
- }, [text, textStyles]);
188
-
189
- return (
190
- <Container
191
- activeOpacity={0.9}
192
- disabled={disabled}
193
- onPress={onPress}
194
- style={style}
195
- >
196
- <View style={containerStyles}>
197
- <StyledCheckboxOutlined
198
- $checked={checked}
199
- $disabled={disabled}
200
- style={[checkboxSizeStyles, styles?.checkbox]}
201
- testID="cpk-ui-checkbox"
202
- $type={color}
203
- >
204
- <AnimatedCheckbox style={animatedStyles}>
205
- <StyledCheck
206
- $checked={checked}
207
- name="Check"
208
- size={checkboxSize * 0.7}
209
- style={styles?.check}
210
- />
211
- </AnimatedCheckbox>
212
- </StyledCheckboxOutlined>
213
- {TextElement}
214
- </View>
215
- </Container>
216
- );
217
- }
218
-
219
- // Export memoized component for better performance
220
- export default React.memo(Checkbox) as typeof Checkbox;
@@ -1,48 +0,0 @@
1
- import React, {useMemo, type ReactElement} from 'react';
2
- import type {PressableProps, StyleProp, ViewStyle} from 'react-native';
3
- import {Pressable} from 'react-native';
4
- import {css} from 'kstyled';
5
- import {useCPK} from '../../../providers';
6
-
7
- const DEFAULT_HIT_SLOP = {top: 4, bottom: 4, left: 6, right: 6};
8
-
9
- function CustomPressable(
10
- props: PressableProps & {style?: StyleProp<ViewStyle>},
11
- ): ReactElement {
12
- const {children, style, hitSlop, ...restProps} = props;
13
- const {theme} = useCPK();
14
-
15
- const effectiveHitSlop = useMemo(() =>
16
- hitSlop || DEFAULT_HIT_SLOP,
17
- [hitSlop]
18
- );
19
-
20
- const styleFunction = useMemo(
21
- () => ({pressed}: {pressed: boolean}) => {
22
- if (pressed) {
23
- return [
24
- css`
25
- background-color: ${theme.role.underlay};
26
- `,
27
- style,
28
- ];
29
- }
30
- return style;
31
- },
32
- [theme.role.underlay, style]
33
- );
34
-
35
- return (
36
- <Pressable
37
- hitSlop={effectiveHitSlop}
38
- style={styleFunction}
39
- {...restProps}
40
- >
41
- {children}
42
- </Pressable>
43
- );
44
- }
45
-
46
- // Export memoized component for better performance
47
- export default React.memo(CustomPressable) as typeof CustomPressable;
48
- export {CustomPressable};