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.
- package/README.md +80 -147
- package/components/modals/AlertDialog/AlertDialog.d.ts.map +1 -1
- package/components/modals/AlertDialog/AlertDialog.js +14 -7
- package/components/modals/Snackbar/Snackbar.d.ts.map +1 -1
- package/components/modals/Snackbar/Snackbar.js +20 -17
- package/components/uis/Accordion/AccordionItem.d.ts.map +1 -1
- package/components/uis/Accordion/AccordionItem.js +41 -17
- package/components/uis/Button/Button.d.ts +2 -1
- package/components/uis/Button/Button.d.ts.map +1 -1
- package/components/uis/Button/Button.js +11 -11
- package/components/uis/Card/Card.d.ts +2 -1
- package/components/uis/Card/Card.d.ts.map +1 -1
- package/components/uis/Card/Card.js +12 -3
- package/components/uis/Checkbox/Checkbox.d.ts +2 -1
- package/components/uis/Checkbox/Checkbox.d.ts.map +1 -1
- package/components/uis/Checkbox/Checkbox.js +2 -2
- package/components/uis/CustomPressable/CustomPressable.d.ts.map +1 -1
- package/components/uis/CustomPressable/CustomPressable.js +6 -6
- package/components/uis/EditText/EditText.d.ts +1 -0
- package/components/uis/EditText/EditText.d.ts.map +1 -1
- package/components/uis/EditText/EditText.js +18 -13
- package/components/uis/Fab/Fab.d.ts +2 -2
- package/components/uis/Fab/Fab.d.ts.map +1 -1
- package/components/uis/Fab/Fab.js +22 -4
- package/components/uis/Icon/Icon.d.ts.map +1 -1
- package/components/uis/Icon/Icon.js +6 -3
- package/components/uis/IconButton/IconButton.d.ts +2 -1
- package/components/uis/IconButton/IconButton.d.ts.map +1 -1
- package/components/uis/IconButton/IconButton.js +44 -42
- package/components/uis/LoadingIndicator/LoadingIndicator.d.ts +2 -1
- package/components/uis/LoadingIndicator/LoadingIndicator.d.ts.map +1 -1
- package/components/uis/LoadingIndicator/LoadingIndicator.js +4 -4
- package/components/uis/RadioGroup/RadioButton.d.ts +2 -1
- package/components/uis/RadioGroup/RadioButton.d.ts.map +1 -1
- package/components/uis/RadioGroup/RadioButton.js +2 -2
- package/components/uis/RadioGroup/RadioGroup.d.ts.map +1 -1
- package/components/uis/RadioGroup/RadioGroup.js +16 -3
- package/components/uis/Rating/Rating.d.ts.map +1 -1
- package/components/uis/Rating/Rating.js +23 -19
- package/components/uis/SegmentedControl/SegmentedControl.d.ts.map +1 -1
- package/components/uis/SegmentedControl/SegmentedControl.js +1 -1
- package/components/uis/StatusbarBrightness/StatusBarBrightness.d.ts +2 -2
- package/components/uis/StatusbarBrightness/StatusBarBrightness.d.ts.map +1 -1
- package/components/uis/StatusbarBrightness/StatusBarBrightness.js +1 -1
- package/components/uis/SwitchToggle/SwitchToggle.d.ts +2 -1
- package/components/uis/SwitchToggle/SwitchToggle.d.ts.map +1 -1
- package/components/uis/SwitchToggle/SwitchToggle.js +2 -2
- package/hooks/useHoverState.d.ts +8 -0
- package/hooks/useHoverState.d.ts.map +1 -0
- package/hooks/useHoverState.js +16 -0
- package/package.json +18 -6
- package/providers/ThemeProvider.d.ts.map +1 -1
- package/providers/ThemeProvider.js +0 -1
- package/providers/index.d.ts.map +1 -1
- package/providers/index.js +3 -2
- package/components/uis/Icon/selection.json +0 -1
- package/src/components/common/ErrorBoundary/ErrorBoundary.tsx +0 -75
- package/src/components/modals/AlertDialog/AlertDialog.stories.tsx +0 -216
- package/src/components/modals/AlertDialog/AlertDialog.test.tsx +0 -251
- package/src/components/modals/AlertDialog/AlertDialog.tsx +0 -356
- package/src/components/modals/Snackbar/Snackbar.stories.tsx +0 -182
- package/src/components/modals/Snackbar/Snackbar.test.tsx +0 -319
- package/src/components/modals/Snackbar/Snackbar.tsx +0 -260
- package/src/components/modals/Snackbar/const.ts +0 -4
- package/src/components/uis/Accordion/Accordion.stories.tsx +0 -167
- package/src/components/uis/Accordion/Accordion.test.tsx +0 -272
- package/src/components/uis/Accordion/Accordion.tsx +0 -109
- package/src/components/uis/Accordion/AccordionItem.tsx +0 -306
- package/src/components/uis/Button/Button.stories.tsx +0 -218
- package/src/components/uis/Button/Button.test.tsx +0 -620
- package/src/components/uis/Button/Button.tsx +0 -436
- package/src/components/uis/Card/Card.test.tsx +0 -146
- package/src/components/uis/Card/Card.tsx +0 -102
- package/src/components/uis/Checkbox/Checkbox.stories.tsx +0 -216
- package/src/components/uis/Checkbox/Checkbox.test.tsx +0 -173
- package/src/components/uis/Checkbox/Checkbox.tsx +0 -220
- package/src/components/uis/CustomPressable/CustomPressable.tsx +0 -48
- package/src/components/uis/EditText/EditText.stories.tsx +0 -124
- package/src/components/uis/EditText/EditText.test.tsx +0 -477
- package/src/components/uis/EditText/EditText.tsx +0 -590
- package/src/components/uis/Fab/Fab.stories.tsx +0 -133
- package/src/components/uis/Fab/Fab.test.tsx +0 -110
- package/src/components/uis/Fab/Fab.tsx +0 -168
- package/src/components/uis/Hr/Hr.test.tsx +0 -26
- package/src/components/uis/Hr/Hr.tsx +0 -19
- package/src/components/uis/Icon/Icon.stories.tsx +0 -98
- package/src/components/uis/Icon/Icon.test.tsx +0 -49
- package/src/components/uis/Icon/Icon.tsx +0 -3819
- package/src/components/uis/IconButton/IconButton.test.tsx +0 -165
- package/src/components/uis/IconButton/IconButton.tsx +0 -275
- package/src/components/uis/LoadingIndicator/LoadingIndicator.tsx +0 -126
- package/src/components/uis/LoadingIndicator/LodingIndicator.stories.tsx +0 -81
- package/src/components/uis/PinchZoom/PinchZoom.stories.tsx +0 -266
- package/src/components/uis/PinchZoom/PinchZoom.test.tsx +0 -113
- package/src/components/uis/PinchZoom/PinchZoom.tsx +0 -424
- package/src/components/uis/RadioGroup/RadioButton.tsx +0 -188
- package/src/components/uis/RadioGroup/RadioGroup.stories.tsx +0 -188
- package/src/components/uis/RadioGroup/RadioGroup.test.tsx +0 -287
- package/src/components/uis/RadioGroup/RadioGroup.tsx +0 -109
- package/src/components/uis/Rating/Rating.test.tsx +0 -98
- package/src/components/uis/Rating/Rating.tsx +0 -200
- package/src/components/uis/SegmentedControl/SegmentedControl.stories.tsx +0 -546
- package/src/components/uis/SegmentedControl/SegmentedControl.test.tsx +0 -274
- package/src/components/uis/SegmentedControl/SegmentedControl.tsx +0 -229
- package/src/components/uis/StatusbarBrightness/StatusBarBrightness.test.tsx +0 -41
- package/src/components/uis/StatusbarBrightness/StatusBarBrightness.tsx +0 -26
- package/src/components/uis/Styled/StyledComponents.tsx +0 -217
- package/src/components/uis/SwitchToggle/SwitchToggle.stories.tsx +0 -75
- package/src/components/uis/SwitchToggle/SwitchToggle.test.tsx +0 -105
- package/src/components/uis/SwitchToggle/SwitchToggle.tsx +0 -305
- package/src/components/uis/Typography/Typography.stories.tsx +0 -149
- package/src/components/uis/Typography/Typography.test.tsx +0 -58
- package/src/components/uis/Typography/Typography.tsx +0 -386
- package/src/hooks/index.ts +0 -2
- package/src/hooks/useAnimations.ts +0 -71
- package/src/hooks/useDebouncedColorScheme.tsx +0 -30
- package/src/hooks/useOptimizedStyles.ts +0 -22
- package/src/hooks/usePerformance.ts +0 -93
- package/src/index.tsx +0 -38
- package/src/providers/ThemeProvider.tsx +0 -177
- package/src/providers/index.tsx +0 -130
- package/src/test/testUtils.tsx +0 -101
- package/src/types/common.ts +0 -77
- package/src/types/index.ts +0 -1
- package/src/types/kstyled.d.ts +0 -6
- package/src/utils/accessibility.ts +0 -110
- package/src/utils/colors.ts +0 -151
- package/src/utils/createCtx.tsx +0 -26
- package/src/utils/guards.ts +0 -93
- package/src/utils/index.ts +0 -2
- package/src/utils/performanceTest.ts +0 -174
- package/src/utils/platform.ts +0 -69
- package/src/utils/theme.ts +0 -38
- package/test/testUtils.d.ts +0 -113
- package/test/testUtils.d.ts.map +0 -1
- 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;
|