cpk-ui 0.5.5 → 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 (130) 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.map +1 -1
  9. package/components/uis/Button/Button.js +10 -10
  10. package/components/uis/Card/Card.d.ts +2 -1
  11. package/components/uis/Card/Card.d.ts.map +1 -1
  12. package/components/uis/Card/Card.js +12 -3
  13. package/components/uis/Checkbox/Checkbox.d.ts.map +1 -1
  14. package/components/uis/Checkbox/Checkbox.js +1 -1
  15. package/components/uis/CustomPressable/CustomPressable.d.ts.map +1 -1
  16. package/components/uis/CustomPressable/CustomPressable.js +6 -6
  17. package/components/uis/EditText/EditText.d.ts.map +1 -1
  18. package/components/uis/EditText/EditText.js +17 -12
  19. package/components/uis/Fab/Fab.d.ts +2 -2
  20. package/components/uis/Fab/Fab.d.ts.map +1 -1
  21. package/components/uis/Fab/Fab.js +22 -4
  22. package/components/uis/Icon/Icon.d.ts.map +1 -1
  23. package/components/uis/Icon/Icon.js +6 -3
  24. package/components/uis/IconButton/IconButton.d.ts.map +1 -1
  25. package/components/uis/IconButton/IconButton.js +43 -41
  26. package/components/uis/LoadingIndicator/LoadingIndicator.d.ts +2 -1
  27. package/components/uis/LoadingIndicator/LoadingIndicator.d.ts.map +1 -1
  28. package/components/uis/LoadingIndicator/LoadingIndicator.js +4 -4
  29. package/components/uis/RadioGroup/RadioButton.d.ts.map +1 -1
  30. package/components/uis/RadioGroup/RadioButton.js +1 -1
  31. package/components/uis/RadioGroup/RadioGroup.d.ts.map +1 -1
  32. package/components/uis/RadioGroup/RadioGroup.js +16 -3
  33. package/components/uis/Rating/Rating.d.ts.map +1 -1
  34. package/components/uis/Rating/Rating.js +23 -19
  35. package/components/uis/SegmentedControl/SegmentedControl.d.ts.map +1 -1
  36. package/components/uis/SegmentedControl/SegmentedControl.js +1 -1
  37. package/components/uis/StatusbarBrightness/StatusBarBrightness.d.ts +2 -2
  38. package/components/uis/StatusbarBrightness/StatusBarBrightness.d.ts.map +1 -1
  39. package/components/uis/StatusbarBrightness/StatusBarBrightness.js +1 -1
  40. package/components/uis/SwitchToggle/SwitchToggle.d.ts.map +1 -1
  41. package/components/uis/SwitchToggle/SwitchToggle.js +1 -1
  42. package/hooks/useHoverState.d.ts +8 -0
  43. package/hooks/useHoverState.d.ts.map +1 -0
  44. package/hooks/useHoverState.js +16 -0
  45. package/package.json +18 -6
  46. package/providers/ThemeProvider.d.ts.map +1 -1
  47. package/providers/ThemeProvider.js +0 -1
  48. package/providers/index.d.ts.map +1 -1
  49. package/providers/index.js +3 -2
  50. package/components/uis/Icon/selection.json +0 -1
  51. package/src/components/common/ErrorBoundary/ErrorBoundary.tsx +0 -75
  52. package/src/components/modals/AlertDialog/AlertDialog.stories.tsx +0 -216
  53. package/src/components/modals/AlertDialog/AlertDialog.test.tsx +0 -251
  54. package/src/components/modals/AlertDialog/AlertDialog.tsx +0 -356
  55. package/src/components/modals/Snackbar/Snackbar.stories.tsx +0 -182
  56. package/src/components/modals/Snackbar/Snackbar.test.tsx +0 -319
  57. package/src/components/modals/Snackbar/Snackbar.tsx +0 -260
  58. package/src/components/modals/Snackbar/const.ts +0 -4
  59. package/src/components/uis/Accordion/Accordion.stories.tsx +0 -167
  60. package/src/components/uis/Accordion/Accordion.test.tsx +0 -272
  61. package/src/components/uis/Accordion/Accordion.tsx +0 -109
  62. package/src/components/uis/Accordion/AccordionItem.tsx +0 -306
  63. package/src/components/uis/Button/Button.stories.tsx +0 -218
  64. package/src/components/uis/Button/Button.test.tsx +0 -694
  65. package/src/components/uis/Button/Button.tsx +0 -440
  66. package/src/components/uis/Card/Card.test.tsx +0 -146
  67. package/src/components/uis/Card/Card.tsx +0 -102
  68. package/src/components/uis/Checkbox/Checkbox.stories.tsx +0 -216
  69. package/src/components/uis/Checkbox/Checkbox.test.tsx +0 -267
  70. package/src/components/uis/Checkbox/Checkbox.tsx +0 -225
  71. package/src/components/uis/CustomPressable/CustomPressable.tsx +0 -48
  72. package/src/components/uis/EditText/EditText.stories.tsx +0 -124
  73. package/src/components/uis/EditText/EditText.test.tsx +0 -477
  74. package/src/components/uis/EditText/EditText.tsx +0 -593
  75. package/src/components/uis/Fab/Fab.stories.tsx +0 -133
  76. package/src/components/uis/Fab/Fab.test.tsx +0 -110
  77. package/src/components/uis/Fab/Fab.tsx +0 -168
  78. package/src/components/uis/Hr/Hr.test.tsx +0 -26
  79. package/src/components/uis/Hr/Hr.tsx +0 -19
  80. package/src/components/uis/Icon/Icon.stories.tsx +0 -98
  81. package/src/components/uis/Icon/Icon.test.tsx +0 -49
  82. package/src/components/uis/Icon/Icon.tsx +0 -3819
  83. package/src/components/uis/IconButton/IconButton.test.tsx +0 -204
  84. package/src/components/uis/IconButton/IconButton.tsx +0 -279
  85. package/src/components/uis/LoadingIndicator/LoadingIndicator.tsx +0 -126
  86. package/src/components/uis/LoadingIndicator/LodingIndicator.stories.tsx +0 -81
  87. package/src/components/uis/PinchZoom/PinchZoom.stories.tsx +0 -266
  88. package/src/components/uis/PinchZoom/PinchZoom.test.tsx +0 -113
  89. package/src/components/uis/PinchZoom/PinchZoom.tsx +0 -424
  90. package/src/components/uis/RadioGroup/RadioButton.tsx +0 -193
  91. package/src/components/uis/RadioGroup/RadioGroup.stories.tsx +0 -188
  92. package/src/components/uis/RadioGroup/RadioGroup.test.tsx +0 -354
  93. package/src/components/uis/RadioGroup/RadioGroup.tsx +0 -109
  94. package/src/components/uis/Rating/Rating.test.tsx +0 -98
  95. package/src/components/uis/Rating/Rating.tsx +0 -200
  96. package/src/components/uis/SegmentedControl/SegmentedControl.stories.tsx +0 -546
  97. package/src/components/uis/SegmentedControl/SegmentedControl.test.tsx +0 -274
  98. package/src/components/uis/SegmentedControl/SegmentedControl.tsx +0 -232
  99. package/src/components/uis/StatusbarBrightness/StatusBarBrightness.test.tsx +0 -41
  100. package/src/components/uis/StatusbarBrightness/StatusBarBrightness.tsx +0 -26
  101. package/src/components/uis/Styled/StyledComponents.tsx +0 -217
  102. package/src/components/uis/SwitchToggle/SwitchToggle.stories.tsx +0 -75
  103. package/src/components/uis/SwitchToggle/SwitchToggle.test.tsx +0 -149
  104. package/src/components/uis/SwitchToggle/SwitchToggle.tsx +0 -309
  105. package/src/components/uis/Typography/Typography.stories.tsx +0 -149
  106. package/src/components/uis/Typography/Typography.test.tsx +0 -58
  107. package/src/components/uis/Typography/Typography.tsx +0 -386
  108. package/src/hooks/index.ts +0 -2
  109. package/src/hooks/useAnimations.ts +0 -71
  110. package/src/hooks/useDebouncedColorScheme.tsx +0 -30
  111. package/src/hooks/useOptimizedStyles.ts +0 -22
  112. package/src/hooks/usePerformance.ts +0 -93
  113. package/src/index.tsx +0 -38
  114. package/src/providers/ThemeProvider.tsx +0 -177
  115. package/src/providers/index.tsx +0 -130
  116. package/src/test/testUtils.tsx +0 -101
  117. package/src/types/common.ts +0 -77
  118. package/src/types/index.ts +0 -1
  119. package/src/types/kstyled.d.ts +0 -6
  120. package/src/utils/accessibility.ts +0 -110
  121. package/src/utils/colors.ts +0 -151
  122. package/src/utils/createCtx.tsx +0 -26
  123. package/src/utils/guards.ts +0 -93
  124. package/src/utils/index.ts +0 -2
  125. package/src/utils/performanceTest.ts +0 -174
  126. package/src/utils/platform.ts +0 -69
  127. package/src/utils/theme.ts +0 -38
  128. package/test/testUtils.d.ts +0 -113
  129. package/test/testUtils.d.ts.map +0 -1
  130. package/test/testUtils.js +0 -65
@@ -1,188 +0,0 @@
1
- import {useState} from 'react';
2
- import type {Meta, StoryObj} from '@storybook/react';
3
-
4
- import {withThemeProvider} from '../../../../.storybook/decorators';
5
- import {RadioButtonType, RadioGroup} from './RadioGroup';
6
- import type {RadioButtonSizeType} from './RadioButton';
7
-
8
- const meta = {
9
- title: 'RadioGroup',
10
- component: (props) => <RadioGroup {...props} />,
11
- parameters: {
12
- notes: `
13
- A flexible RadioGroup component that allows users to select a single option from a set of choices.
14
-
15
- ## Features
16
- - **Flexible Sizing**: Supports preset sizes (small, medium, large) and custom numeric values
17
- - **Color Variants**: Multiple color options for different contexts
18
- - **Disabled State**: Can disable the entire radio group
19
- - **Optional Title**: Display an optional title above the radio group
20
- - **Label Positioning**: Position labels on the left or right of radio buttons
21
-
22
- ## Size Options
23
- - \`small\`: 16px radio button
24
- - \`medium\`: 20px radio button (default)
25
- - \`large\`: 24px radio button
26
- - Custom number: Any pixel value (e.g., \`size={28}\`)
27
-
28
- ## Usage
29
- \`\`\`tsx
30
- <RadioGroup
31
- data={['Option 1', 'Option 2', 'Option 3']}
32
- labels={['Option 1', 'Option 2', 'Option 3']}
33
- selectedValue="Option 1"
34
- selectValue={setSelectedValue}
35
- size="medium"
36
- type="primary"
37
- title="Choose an option"
38
- />
39
- \`\`\`
40
- `,
41
- docs: {
42
- description: {
43
- component: `
44
- A flexible RadioGroup component that allows users to select a single option from a set of choices.
45
-
46
- ## Features
47
- - **Flexible Sizing**: Supports preset sizes (small, medium, large) and custom numeric values
48
- - **Color Variants**: Multiple color options for different contexts
49
- - **Disabled State**: Can disable the entire radio group
50
- - **Optional Title**: Display an optional title above the radio group
51
- - **Label Positioning**: Position labels on the left or right of radio buttons
52
-
53
- ## Size Options
54
- - \`small\`: 16px radio button
55
- - \`medium\`: 20px radio button (default)
56
- - \`large\`: 24px radio button
57
- - Custom number: Any pixel value (e.g., \`size={28}\`)
58
-
59
- ## Usage
60
- \`\`\`tsx
61
- <RadioGroup
62
- data={['Option 1', 'Option 2', 'Option 3']}
63
- labels={['Option 1', 'Option 2', 'Option 3']}
64
- selectedValue="Option 1"
65
- selectValue={setSelectedValue}
66
- size="medium"
67
- type="primary"
68
- title="Choose an option"
69
- />
70
- \`\`\`
71
- `,
72
- },
73
- },
74
- },
75
- argTypes: {
76
- type: {
77
- control: 'select',
78
- options: [
79
- 'danger',
80
- 'info',
81
- 'primary',
82
- 'light',
83
- 'secondary',
84
- 'success',
85
- 'warning',
86
- ] as RadioButtonType[],
87
- description: 'Color variant of the radio buttons',
88
- },
89
- size: {
90
- control: 'radio',
91
- options: ['small', 'medium', 'large', 16, 20, 24, 32],
92
- description: 'Size can be "small" (16px), "medium" (20px), "large" (24px) or a custom number in pixels',
93
- },
94
- disabled: {
95
- control: 'boolean',
96
- description: 'Disables all radio buttons in the group',
97
- },
98
- title: {
99
- description: 'Optional title displayed above the radio group',
100
- },
101
- labelPosition: {
102
- description: 'Position of the label text relative to the radio button',
103
- },
104
- },
105
- decorators: [withThemeProvider],
106
- } satisfies Meta<typeof RadioGroup>;
107
-
108
- export default meta;
109
-
110
- type Story = StoryObj<typeof meta>;
111
-
112
- export const Basic: Story = {
113
- render: (args) => {
114
- const [selectedValue, setSelectedValue] = useState(args.selectedValue);
115
-
116
- return (
117
- <RadioGroup
118
- data={args.data}
119
- labels={args.labels}
120
- title={args.title}
121
- labelPosition={args.labelPosition}
122
- type={args.type}
123
- size={args.size}
124
- disabled={args.disabled}
125
- selectedValue={selectedValue}
126
- selectValue={setSelectedValue}
127
- />
128
- );
129
- },
130
- args: {
131
- theme: 'light',
132
- data: ['Person', 'Animal', 'Bird', 'Other'],
133
- labels: ['Person', 'Animal', 'Bird', 'Other'],
134
- selectedValue: 'Person',
135
- title: 'RadioGroup',
136
- labelPosition: 'right',
137
- type: 'primary',
138
- size: 'medium',
139
- disabled: false,
140
- },
141
- argTypes: {
142
- theme: {
143
- control: 'select',
144
- options: ['light', 'dark'],
145
- },
146
- },
147
- };
148
-
149
- export const CustomSize: Story = {
150
- render: (args) => {
151
- const [selectedValue, setSelectedValue] = useState(args.selectedValue);
152
-
153
- return (
154
- <RadioGroup
155
- data={args.data}
156
- labels={args.labels}
157
- title={args.title}
158
- labelPosition={args.labelPosition}
159
- type={args.type}
160
- size={args.size}
161
- disabled={args.disabled}
162
- selectedValue={selectedValue}
163
- selectValue={setSelectedValue}
164
- />
165
- );
166
- },
167
- args: {
168
- theme: 'light',
169
- data: ['Person', 'Animal', 'Bird', 'Other'],
170
- labels: ['Person', 'Animal', 'Bird', 'Other'],
171
- selectedValue: 'Person',
172
- title: 'RadioGroup with Custom Size',
173
- labelPosition: 'right',
174
- type: 'primary',
175
- size: 28,
176
- disabled: false,
177
- },
178
- argTypes: {
179
- theme: {
180
- control: 'select',
181
- options: ['light', 'dark'],
182
- },
183
- size: {
184
- control: {type: 'number', min: 12, max: 48, step: 2},
185
- description: 'Custom size in pixels',
186
- },
187
- },
188
- };
@@ -1,354 +0,0 @@
1
- import * as React from 'react';
2
- import {type ReactElement} from 'react';
3
- import {StyleSheet, View} from 'react-native';
4
- import type {RenderAPI} from '@testing-library/react-native';
5
- import {act, fireEvent, render, waitFor} from '@testing-library/react-native';
6
-
7
- import {createComponent, createTestProps} from '../../../../test/testUtils';
8
- import RadioButton from './RadioButton';
9
- import {type RadioButtonType, RadioGroup} from './RadioGroup';
10
-
11
- let props: any;
12
- let component: ReactElement;
13
- let testingLib: RenderAPI;
14
-
15
- const data = ['Person', 'Animal', 'Bird', 'Other'];
16
-
17
- describe('[RadioButton] render', () => {
18
- it('should render without crashing', async () => {
19
- props = createTestProps({
20
- selectedValue: data[0],
21
- selectValue: (value: string) => (props.selectedValue = value),
22
- });
23
-
24
- component = createComponent(
25
- <View style={{flexDirection: 'row', marginTop: 24}}>
26
- <RadioGroup<string>
27
- data={data}
28
- selectValue={props.selectValue}
29
- selectedValue={props.selectedValue}
30
- title="title"
31
- />
32
- </View>,
33
- );
34
-
35
- testingLib = render(component);
36
-
37
- const baseElement = await waitFor(() => testingLib.toJSON());
38
- expect(baseElement).toBeTruthy();
39
- });
40
-
41
- describe('label', () => {
42
- it('should render `labels`', async () => {
43
- props = createTestProps();
44
-
45
- component = createComponent(
46
- <View>
47
- <View style={{flexDirection: 'row', marginTop: 24}}>
48
- <RadioGroup<string>
49
- data={data}
50
- labels={data}
51
- selectedValue={data[0]}
52
- title="title"
53
- />
54
- </View>
55
- </View>,
56
- );
57
-
58
- testingLib = render(component);
59
-
60
- const baseElement = await waitFor(() => testingLib.toJSON());
61
- expect(baseElement).toBeTruthy();
62
- });
63
-
64
- it('should render `labels` with left position', async () => {
65
- props = createTestProps();
66
-
67
- component = createComponent(
68
- <View>
69
- <View style={{flexDirection: 'row', marginTop: 24}}>
70
- <RadioGroup<string>
71
- data={data}
72
- labelPosition="left"
73
- labels={data}
74
- selectedValue={data[0]}
75
- title="title"
76
- />
77
- </View>
78
- </View>,
79
- );
80
-
81
- testingLib = render(component);
82
-
83
- const baseElement = await waitFor(() => testingLib.toJSON());
84
- expect(baseElement).toBeTruthy();
85
- });
86
- });
87
-
88
- it('should trigger `selectValue` and change `selectedValue` props', () => {
89
- props = createTestProps({
90
- selectedValue: data[0],
91
- selectValue: (value: string) => (props.selectedValue = value),
92
- });
93
-
94
- component = createComponent(
95
- <View style={{flexDirection: 'row', marginTop: 24}}>
96
- <RadioGroup<string>
97
- data={data}
98
- selectValue={props.selectValue}
99
- selectedValue={props.selectedValue}
100
- title="title"
101
- />
102
- </View>,
103
- );
104
-
105
- testingLib = render(component);
106
-
107
- const secondOption = testingLib.getByTestId('radio-1');
108
- expect(props.selectedValue).toEqual(data[0]);
109
-
110
- fireEvent.press(secondOption);
111
- expect(props.selectedValue).toEqual(data[1]);
112
- });
113
- });
114
-
115
- describe('[RadioButton]', () => {
116
- it('should render and trigger `onLayout` and change `innerLayout`', () => {
117
- props = createTestProps({
118
- selectedValue: data[0],
119
- selectValue: (value: string) => (props.selectedValue = value),
120
- });
121
-
122
- component = createComponent(
123
- <View style={{flexDirection: 'row', marginTop: 24}}>
124
- <RadioGroup<string>
125
- data={data}
126
- selectValue={props.selectValue}
127
- selectedValue={props.selectedValue}
128
- title="title"
129
- />
130
- </View>,
131
- );
132
-
133
- testingLib = render(component);
134
-
135
- const circleRadio = testingLib.getByTestId('circle-radio-0');
136
- // Get initial styles before layout
137
- const initialStyle = StyleSheet.flatten(circleRadio.props.style) ?? {};
138
- const initialMargin =
139
- initialStyle.margin ??
140
- initialStyle.marginTop ??
141
- initialStyle.marginRight ??
142
- initialStyle.marginBottom ??
143
- initialStyle.marginLeft;
144
-
145
- // Initially margin should be 0 since innerLayout is not set
146
- expect(initialMargin).toBe(0);
147
-
148
- act(() => {
149
- circleRadio.props.onLayout({
150
- nativeEvent: {
151
- layout: {
152
- width: 40,
153
- height: 40,
154
- },
155
- },
156
- });
157
- });
158
-
159
- // After layout, the styles should reflect the innerLayout values
160
- // margin should be 2 and borderRadius should be width/2 = 20
161
- const updatedStyle =
162
- StyleSheet.flatten(testingLib.getByTestId('circle-radio-0').props.style) ??
163
- {};
164
- const updatedMargin =
165
- updatedStyle.margin ??
166
- updatedStyle.marginTop ??
167
- updatedStyle.marginRight ??
168
- updatedStyle.marginBottom ??
169
- updatedStyle.marginLeft;
170
-
171
- expect(updatedMargin).toBe(2);
172
- expect(updatedStyle.borderRadius).toBe(20); // 40 / 2
173
- });
174
-
175
- describe('colors', () => {
176
- const types = [
177
- 'primary',
178
- 'secondary',
179
- 'success',
180
- 'info',
181
- 'warning',
182
- 'danger',
183
- ];
184
-
185
- it('should render all colors', async () => {
186
- component = createComponent(
187
- <View>
188
- {types.map((el) => {
189
- return (
190
- <View key={el} style={{flexDirection: 'row', marginTop: 24}}>
191
- <RadioGroup<string>
192
- data={data}
193
- labels={data}
194
- selectedValue={data[0]}
195
- title={el}
196
- type={el as RadioButtonType}
197
- />
198
- </View>
199
- );
200
- })}
201
- </View>,
202
- );
203
-
204
- testingLib = render(component);
205
-
206
- const baseElement = await waitFor(() => testingLib.toJSON());
207
- expect(baseElement).toBeTruthy();
208
- });
209
-
210
- it('should render `disabled color', async () => {
211
- component = createComponent(
212
- <RadioButton disabled={true} label="label" />,
213
- );
214
-
215
- testingLib = render(component);
216
-
217
- const baseElement = await waitFor(() => testingLib.toJSON());
218
- expect(baseElement).toBeTruthy();
219
- });
220
- });
221
-
222
- describe('sizes', () => {
223
- it('should render with small size', async () => {
224
- component = createComponent(
225
- <RadioGroup<string>
226
- data={data}
227
- labels={data}
228
- selectedValue={data[0]}
229
- size="small"
230
- />,
231
- );
232
-
233
- testingLib = render(component);
234
-
235
- const baseElement = await waitFor(() => testingLib.toJSON());
236
- expect(baseElement).toBeTruthy();
237
- });
238
-
239
- it('should render with medium size', async () => {
240
- component = createComponent(
241
- <RadioGroup<string>
242
- data={data}
243
- labels={data}
244
- selectedValue={data[0]}
245
- size="medium"
246
- />,
247
- );
248
-
249
- testingLib = render(component);
250
-
251
- const baseElement = await waitFor(() => testingLib.toJSON());
252
- expect(baseElement).toBeTruthy();
253
- });
254
-
255
- it('should render with large size', async () => {
256
- component = createComponent(
257
- <RadioGroup<string>
258
- data={data}
259
- labels={data}
260
- selectedValue={data[0]}
261
- size="large"
262
- />,
263
- );
264
-
265
- testingLib = render(component);
266
-
267
- const baseElement = await waitFor(() => testingLib.toJSON());
268
- expect(baseElement).toBeTruthy();
269
- });
270
-
271
- it('should render with custom numeric size', async () => {
272
- component = createComponent(
273
- <RadioGroup<string>
274
- data={data}
275
- labels={data}
276
- selectedValue={data[0]}
277
- size={24}
278
- />,
279
- );
280
-
281
- testingLib = render(component);
282
-
283
- const baseElement = await waitFor(() => testingLib.toJSON());
284
- expect(baseElement).toBeTruthy();
285
- });
286
- });
287
-
288
- describe('accessibility', () => {
289
- it('should have accessibilityRole="radio" on RadioButton', async () => {
290
- component = createComponent(
291
- <RadioButton label="Option 1" testID="radio-a11y" />,
292
- );
293
-
294
- testingLib = render(component);
295
-
296
- const radioButton = testingLib.getByTestId('radio-a11y');
297
- expect(radioButton.props.accessibilityRole).toBe('radio');
298
- });
299
-
300
- it('should use label as default accessibilityLabel', async () => {
301
- component = createComponent(
302
- <RadioButton label="Option 1" testID="radio-a11y" />,
303
- );
304
-
305
- testingLib = render(component);
306
-
307
- const radioButton = testingLib.getByTestId('radio-a11y');
308
- expect(radioButton.props.accessibilityLabel).toBe('Option 1');
309
- });
310
-
311
- it('should use custom accessibilityLabel when provided', async () => {
312
- component = createComponent(
313
- <RadioButton
314
- label="Option 1"
315
- testID="radio-a11y"
316
- accessibilityLabel="Select option one"
317
- />,
318
- );
319
-
320
- testingLib = render(component);
321
-
322
- const radioButton = testingLib.getByTestId('radio-a11y');
323
- expect(radioButton.props.accessibilityLabel).toBe('Select option one');
324
- });
325
-
326
- it('should have accessibilityState with selected=true when selected', async () => {
327
- component = createComponent(
328
- <RadioButton label="Option 1" testID="radio-a11y" selected={true} />,
329
- );
330
-
331
- testingLib = render(component);
332
-
333
- const radioButton = testingLib.getByTestId('radio-a11y');
334
- expect(radioButton.props.accessibilityState).toEqual({
335
- selected: true,
336
- disabled: false,
337
- });
338
- });
339
-
340
- it('should have accessibilityState with disabled=true when disabled', async () => {
341
- component = createComponent(
342
- <RadioButton label="Option 1" testID="radio-a11y" disabled={true} />,
343
- );
344
-
345
- testingLib = render(component);
346
-
347
- const radioButton = testingLib.getByTestId('radio-a11y');
348
- expect(radioButton.props.accessibilityState).toEqual({
349
- selected: undefined,
350
- disabled: true,
351
- });
352
- });
353
- });
354
- });
@@ -1,109 +0,0 @@
1
- import React, {useCallback, useMemo, type ReactElement} from 'react';
2
- import type {StyleProp, TextStyle, ViewStyle} from 'react-native';
3
- import {View} from 'react-native';
4
- import {styled} from 'kstyled';
5
-
6
- import type {RadioButtonProps, RadioButtonStyles, RadioButtonSizeType} from './RadioButton';
7
- import RadioButtonComp from './RadioButton';
8
- import {Typography} from '../Typography/Typography';
9
-
10
- type Styles = {
11
- container?: StyleProp<ViewStyle>;
12
- title?: StyleProp<TextStyle>;
13
- radio?: StyleProp<ViewStyle>;
14
- radioStyles?: RadioButtonStyles;
15
- };
16
-
17
- export type RadioButtonType =
18
- | 'primary'
19
- | 'secondary'
20
- | 'success'
21
- | 'danger'
22
- | 'warning'
23
- | 'info'
24
- | 'light';
25
-
26
- type Props<T> = {
27
- title?: string;
28
- data: T[];
29
- selectedValue: T;
30
- selectValue?: (item: T) => void;
31
- type?: RadioButtonType;
32
- size?: RadioButtonSizeType;
33
- disabled?: boolean;
34
- style?: StyleProp<ViewStyle>;
35
- styles?: Styles;
36
- labels?: string[];
37
- radioType?: Omit<RadioButtonProps, 'type' | 'size' | 'disabled'>;
38
- labelPosition?: 'left' | 'right';
39
- };
40
-
41
- const Container = styled.View`
42
- flex-direction: column;
43
- justify-content: center;
44
- `;
45
-
46
- const Content = styled.View`
47
- flex-direction: row;
48
- `;
49
-
50
- function RadioGroupContainer<T>({
51
- title,
52
- data,
53
- selectedValue,
54
- selectValue,
55
- style,
56
- styles,
57
- type,
58
- size = 'medium',
59
- disabled = false,
60
- labels,
61
- labelPosition,
62
- radioType,
63
- }: Omit<Props<T>, 'selected'>): ReactElement {
64
- // Memoize title spacer to avoid re-creating View
65
- const titleSpacer = useMemo(() =>
66
- title ? <View style={{height: 8}} /> : null,
67
- [title]
68
- );
69
-
70
- // Memoize radio buttons to prevent unnecessary re-renders
71
- const radioButtons = useMemo(() =>
72
- data.map((datum, i) => {
73
- const handlePress = () => !disabled && selectValue?.(datum);
74
-
75
- return (
76
- <RadioButtonComp
77
- key={`radio-${i}`}
78
- testID={`radio-${i}`}
79
- {...radioType}
80
- label={labels?.[i] || ''}
81
- labelPosition={labelPosition}
82
- onPress={handlePress}
83
- selected={selectedValue === datum}
84
- style={styles?.radio}
85
- styles={styles?.radioStyles}
86
- type={type}
87
- size={size}
88
- disabled={disabled}
89
- />
90
- );
91
- }),
92
- [data, selectedValue, selectValue, labels, labelPosition, radioType, styles?.radio, styles?.radioStyles, type, size, disabled]
93
- );
94
-
95
- return (
96
- <Container style={style}>
97
- {title ? <Typography.Heading3 style={styles?.title}>{title}</Typography.Heading3> : null}
98
- {titleSpacer}
99
- <Content style={styles?.container}>
100
- {radioButtons}
101
- </Content>
102
- </Container>
103
- );
104
- }
105
-
106
- // Export memoized component for better performance
107
- export const RadioGroup = React.memo(RadioGroupContainer) as typeof RadioGroupContainer;
108
-
109
- export const RadioButton = RadioButtonComp;