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,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;