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,98 +0,0 @@
1
- import React, {type ReactElement} from 'react';
2
- import {fireEvent, render} from '@testing-library/react-native';
3
-
4
- import type {RatingProps} from './Rating';
5
- import {Rating} from './Rating';
6
- import {createComponent} from '../../../../test/testUtils';
7
-
8
- const Component = (props?: RatingProps): ReactElement =>
9
- createComponent(<Rating {...props} />);
10
-
11
- describe('Rating', () => {
12
- test('renders five stars', () => {
13
- const {getAllByTestId} = render(
14
- Component({
15
- testID: 'star',
16
- }),
17
- );
18
- const stars = getAllByTestId('star');
19
- expect(stars).toHaveLength(5);
20
- });
21
-
22
- test('renders half stars when allowHalfRating is true', () => {
23
- const {getAllByTestId} = render(
24
- Component({
25
- testID: 'half-star',
26
- allowHalfRating: true,
27
- }),
28
- );
29
- const halfStars = getAllByTestId('half-star');
30
- expect(halfStars).toHaveLength(5);
31
- });
32
-
33
- test('renders `dooboo` iconType', () => {
34
- const {getAllByTestId} = render(
35
- Component({
36
- testID: 'star',
37
- iconType: 'dooboo',
38
- }),
39
- );
40
- const stars = getAllByTestId('star');
41
- expect(stars).toHaveLength(5);
42
- });
43
-
44
- test('calls onRatingUpdate when a star is clicked', () => {
45
- const handleRatingUpdate = jest.fn();
46
- const {getAllByRole} = render(
47
- Component({
48
- onRatingUpdate: handleRatingUpdate,
49
- }),
50
- );
51
- const thirdStar = getAllByRole('button')[0];
52
-
53
- fireEvent.press(thirdStar);
54
-
55
- expect(handleRatingUpdate).toHaveBeenCalledWith(0.5);
56
- });
57
-
58
- test('calls onRatingUpdate when a half star is clicked', () => {
59
- const handleRatingUpdate = jest.fn();
60
- const {getAllByRole} = render(
61
- Component({
62
- onRatingUpdate: handleRatingUpdate,
63
- allowHalfRating: true,
64
- }),
65
- );
66
- const thirdHalfStar = getAllByRole('button')[1];
67
-
68
- fireEvent.press(thirdHalfStar);
69
-
70
- expect(handleRatingUpdate).toHaveBeenCalledWith(1);
71
- });
72
-
73
- describe('sizes', () => {
74
- test('renders with small size', () => {
75
- const testingLib = render(Component({size: 'small'}));
76
- const json = testingLib.toJSON();
77
- expect(json).toBeTruthy();
78
- });
79
-
80
- test('renders with medium size', () => {
81
- const testingLib = render(Component({size: 'medium'}));
82
- const json = testingLib.toJSON();
83
- expect(json).toBeTruthy();
84
- });
85
-
86
- test('renders with large size', () => {
87
- const testingLib = render(Component({size: 'large'}));
88
- const json = testingLib.toJSON();
89
- expect(json).toBeTruthy();
90
- });
91
-
92
- test('renders with custom numeric size', () => {
93
- const testingLib = render(Component({size: 32}));
94
- const json = testingLib.toJSON();
95
- expect(json).toBeTruthy();
96
- });
97
- });
98
- });
@@ -1,200 +0,0 @@
1
- // React import is needed for expo-web
2
- import React, {useCallback, useMemo, useState, type ReactElement} from 'react';
3
- import type {StyleProp, ViewStyle} from 'react-native';
4
- import {Pressable, View} from 'react-native';
5
- import {styled, css} from 'kstyled';
6
-
7
- import type {IconName} from '../Icon/Icon';
8
- import {Icon} from '../Icon/Icon';
9
-
10
- const Container = styled(View)`
11
- flex-direction: row;
12
- `;
13
-
14
- const StarContainer = styled(View)`
15
- padding: 1px;
16
-
17
- flex-direction: row;
18
- `;
19
-
20
- type Styles = {
21
- starContainer: StyleProp<ViewStyle>;
22
- };
23
-
24
- export type RatingSizeType = 'small' | 'medium' | 'large' | number;
25
-
26
- export type RatingProps = {
27
- testID?: string;
28
- styles?: Styles;
29
- style?: StyleProp<ViewStyle>;
30
- size?: RatingSizeType;
31
- iconType?: 'star' | 'dooboo';
32
- initialRating?: number;
33
- direction?: 'horizontal' | 'vertical';
34
- allowHalfRating?: boolean;
35
- onRatingUpdate?: (score: number) => void;
36
- disabled?: boolean;
37
- color?: string;
38
- };
39
-
40
- export function Rating({
41
- testID,
42
- style,
43
- styles,
44
- initialRating = 0,
45
- size = 'medium',
46
- iconType = 'star',
47
- onRatingUpdate,
48
- direction = 'horizontal',
49
- allowHalfRating = true,
50
- disabled = false,
51
- color,
52
- }: RatingProps): ReactElement {
53
- const iconSize = typeof size === 'number'
54
- ? size
55
- : size === 'small'
56
- ? 18
57
- : size === 'large'
58
- ? 32
59
- : 24;
60
- const [rating, setRating] = useState(initialRating);
61
-
62
- const iconPrefix = useMemo(
63
- () => (iconType === 'star' ? 'Star' : 'QuestBox'),
64
- [iconType]
65
- );
66
-
67
- const containerStyles = useMemo(
68
- () => [
69
- css`
70
- flex-direction: ${direction === 'horizontal' ? 'row' : 'column'};
71
- `,
72
- style,
73
- ],
74
- [direction, style]
75
- );
76
-
77
- const starContainerStyles = useMemo(
78
- () => [
79
- css`
80
- width: ${size}px;
81
- `,
82
- styles?.starContainer,
83
- ],
84
- [size, styles?.starContainer]
85
- );
86
-
87
- const handlePress = useCallback(
88
- (newRating: number, halfPressed?: boolean) => {
89
- const convertedRating = newRating + (!halfPressed ? 0.5 : 0);
90
-
91
- setRating(convertedRating);
92
-
93
- if (onRatingUpdate) {
94
- onRatingUpdate(convertedRating);
95
- }
96
- },
97
- [onRatingUpdate]
98
- );
99
-
100
- const renderStarIcon = useCallback(
101
- ({
102
- key,
103
- position,
104
- }: {
105
- key: string;
106
- position: number;
107
- }): ReactElement => {
108
- const filled = rating >= position + (allowHalfRating ? 0.5 : 0);
109
- const iconName: IconName = filled ? `${iconPrefix}Fill` : `${iconPrefix}`;
110
- const halfFilled =
111
- rating >= position && rating < position + (allowHalfRating ? 0.5 : 0);
112
-
113
- return (
114
- <StarContainer
115
- key={key}
116
- style={starContainerStyles}
117
- testID={testID}
118
- >
119
- {halfFilled && allowHalfRating ? (
120
- <View style={{position: 'absolute'}}>
121
- <Icon
122
- color={color}
123
- name={`${iconPrefix}` as IconName}
124
- size={iconSize}
125
- style={{position: 'absolute'}}
126
- />
127
- <Icon
128
- color={color}
129
- name={`${iconPrefix}HalfFill` as IconName}
130
- size={iconSize}
131
- />
132
- </View>
133
- ) : (
134
- <Icon
135
- color={color}
136
- name={iconName}
137
- size={iconSize}
138
- style={{position: 'absolute'}}
139
- />
140
- )}
141
- <Pressable
142
- accessibilityRole="button"
143
- disabled={disabled}
144
- onPress={() => handlePress(position, true)}
145
- >
146
- <View
147
- style={{
148
- width: iconSize / 2,
149
- height: iconSize,
150
- backgroundColor: 'transparent',
151
- }}
152
- />
153
- </Pressable>
154
- <Pressable
155
- accessibilityRole="button"
156
- disabled={disabled}
157
- onPress={() => handlePress(position)}
158
- >
159
- <View
160
- style={{
161
- width: iconSize / 2,
162
- height: iconSize,
163
- backgroundColor: 'transparent',
164
- }}
165
- />
166
- </Pressable>
167
- </StarContainer>
168
- );
169
- },
170
- [
171
- rating,
172
- allowHalfRating,
173
- iconPrefix,
174
- starContainerStyles,
175
- testID,
176
- color,
177
- size,
178
- disabled,
179
- handlePress,
180
- ]
181
- );
182
-
183
- const stars = useMemo(
184
- () =>
185
- [...Array(5)].map((_, index) => {
186
- const position = index + (allowHalfRating ? 0.5 : 1);
187
-
188
- return renderStarIcon({key: `${_}-${index}`, position});
189
- }),
190
- [allowHalfRating, renderStarIcon]
191
- );
192
-
193
- return (
194
- <Container style={containerStyles}>
195
- {stars}
196
- </Container>
197
- );
198
- }
199
-
200
- export default React.memo(Rating) as typeof Rating;