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.
- 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.map +1 -1
- package/components/uis/Button/Button.js +10 -10
- 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.map +1 -1
- package/components/uis/Checkbox/Checkbox.js +1 -1
- 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.map +1 -1
- package/components/uis/EditText/EditText.js +17 -12
- 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.map +1 -1
- package/components/uis/IconButton/IconButton.js +43 -41
- 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.map +1 -1
- package/components/uis/RadioGroup/RadioButton.js +1 -1
- 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.map +1 -1
- package/components/uis/SwitchToggle/SwitchToggle.js +1 -1
- 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 -694
- package/src/components/uis/Button/Button.tsx +0 -440
- 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 -267
- package/src/components/uis/Checkbox/Checkbox.tsx +0 -225
- 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 -593
- 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 -204
- package/src/components/uis/IconButton/IconButton.tsx +0 -279
- 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 -193
- package/src/components/uis/RadioGroup/RadioGroup.stories.tsx +0 -188
- package/src/components/uis/RadioGroup/RadioGroup.test.tsx +0 -354
- 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 -232
- 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 -149
- package/src/components/uis/SwitchToggle/SwitchToggle.tsx +0 -309
- 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,356 +0,0 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
cloneElement,
|
|
3
|
-
forwardRef,
|
|
4
|
-
useEffect,
|
|
5
|
-
useImperativeHandle,
|
|
6
|
-
useState,
|
|
7
|
-
useCallback,
|
|
8
|
-
useMemo,
|
|
9
|
-
type ReactElement,
|
|
10
|
-
} from 'react';
|
|
11
|
-
import type {StyleProp, TextStyle, ViewStyle} from 'react-native';
|
|
12
|
-
import {
|
|
13
|
-
Modal,
|
|
14
|
-
Platform,
|
|
15
|
-
StyleSheet,
|
|
16
|
-
TouchableWithoutFeedback,
|
|
17
|
-
View,
|
|
18
|
-
} from 'react-native';
|
|
19
|
-
import {styled, css} from 'kstyled';
|
|
20
|
-
import {useTheme} from '../../../providers/ThemeProvider';
|
|
21
|
-
import {Typography} from '../../uis/Typography/Typography';
|
|
22
|
-
import {Button} from '../../uis/Button/Button';
|
|
23
|
-
import {Icon} from '../../uis/Icon/Icon';
|
|
24
|
-
|
|
25
|
-
const Container = styled.View`
|
|
26
|
-
flex: 1;
|
|
27
|
-
justify-content: center;
|
|
28
|
-
align-items: center;
|
|
29
|
-
|
|
30
|
-
flex-direction: row;
|
|
31
|
-
`;
|
|
32
|
-
|
|
33
|
-
const AlertDialogContainer = styled.View<{$size?: AlertDialogSizeType}>`
|
|
34
|
-
flex: 0.87;
|
|
35
|
-
background-color: ${({theme}) => theme.bg.basic};
|
|
36
|
-
padding-top: ${({$size = 'medium'}) => {
|
|
37
|
-
if (typeof $size === 'number') return $size * 1.25;
|
|
38
|
-
return $size === 'small' ? 16 : $size === 'large' ? 24 : 20;
|
|
39
|
-
}};
|
|
40
|
-
padding-right: ${({$size = 'medium'}) => {
|
|
41
|
-
if (typeof $size === 'number') return $size * 1.25;
|
|
42
|
-
return $size === 'small' ? 16 : $size === 'large' ? 24 : 20;
|
|
43
|
-
}};
|
|
44
|
-
padding-bottom: ${({$size = 'medium'}) => {
|
|
45
|
-
if (typeof $size === 'number') return $size * 1.75;
|
|
46
|
-
return $size === 'small' ? 22 : $size === 'large' ? 32 : 28;
|
|
47
|
-
}};
|
|
48
|
-
padding-left: ${({$size = 'medium'}) => {
|
|
49
|
-
if (typeof $size === 'number') return $size * 1.5;
|
|
50
|
-
return $size === 'small' ? 18 : $size === 'large' ? 28 : 24;
|
|
51
|
-
}};
|
|
52
|
-
border-radius: 8px;
|
|
53
|
-
`;
|
|
54
|
-
|
|
55
|
-
const TitleRow = styled.View`
|
|
56
|
-
flex-direction: row;
|
|
57
|
-
justify-content: space-between;
|
|
58
|
-
align-items: center;
|
|
59
|
-
`;
|
|
60
|
-
|
|
61
|
-
const BodyRow = styled.View<{$marginTop: number; $marginBottom: number}>`
|
|
62
|
-
margin-top: ${({$marginTop}) => $marginTop};
|
|
63
|
-
margin-bottom: ${({$marginBottom}) => $marginBottom};
|
|
64
|
-
`;
|
|
65
|
-
|
|
66
|
-
const ActionRow = styled.View<{$marginTop: number}>`
|
|
67
|
-
margin-top: ${({$marginTop}) => $marginTop};
|
|
68
|
-
padding-right: 4px;
|
|
69
|
-
flex-direction: row;
|
|
70
|
-
`;
|
|
71
|
-
|
|
72
|
-
export type AlertDialogSizeType = 'small' | 'medium' | 'large' | number;
|
|
73
|
-
|
|
74
|
-
export type AlertDialogProps = {
|
|
75
|
-
style?: StyleProp<ViewStyle>;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export type AlertDialogStyles = {
|
|
79
|
-
container?: StyleProp<ViewStyle>;
|
|
80
|
-
titleContainer?: StyleProp<ViewStyle>;
|
|
81
|
-
title?: StyleProp<TextStyle>;
|
|
82
|
-
bodyContainer?: StyleProp<ViewStyle>;
|
|
83
|
-
body?: StyleProp<TextStyle>;
|
|
84
|
-
actionContainer?: StyleProp<ViewStyle>;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export type AlertDialogOptions = {
|
|
88
|
-
styles?: AlertDialogStyles;
|
|
89
|
-
title?: string | ReactElement;
|
|
90
|
-
body?: string | ReactElement;
|
|
91
|
-
backdropOpacity?: number;
|
|
92
|
-
closeOnTouchOutside?: boolean;
|
|
93
|
-
actions?: ReactElement[];
|
|
94
|
-
showCloseButton?: boolean;
|
|
95
|
-
size?: AlertDialogSizeType;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export type AlertDialogContext = {
|
|
99
|
-
open(alertDialogOptions?: AlertDialogOptions): void;
|
|
100
|
-
close(): void;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
function AlertDialog(
|
|
104
|
-
{style}: AlertDialogProps,
|
|
105
|
-
ref: React.Ref<AlertDialogContext>,
|
|
106
|
-
): ReactElement {
|
|
107
|
-
const [options, setOptions] = useState<AlertDialogOptions | null>(null);
|
|
108
|
-
const [visible, setVisible] = useState(false);
|
|
109
|
-
const {theme, themeType} = useTheme();
|
|
110
|
-
|
|
111
|
-
// Memoize the cleanup effect
|
|
112
|
-
useEffect(() => {
|
|
113
|
-
if (!visible) {
|
|
114
|
-
const timeoutId = setTimeout(() => {
|
|
115
|
-
setOptions(null);
|
|
116
|
-
// Run after modal has finished transition
|
|
117
|
-
}, 300);
|
|
118
|
-
|
|
119
|
-
return () => clearTimeout(timeoutId);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Return an empty cleanup function when visible is true
|
|
123
|
-
return () => {};
|
|
124
|
-
}, [visible]);
|
|
125
|
-
|
|
126
|
-
// Memoize the close handler
|
|
127
|
-
const handleClose = useCallback(() => {
|
|
128
|
-
setVisible(false);
|
|
129
|
-
}, []);
|
|
130
|
-
|
|
131
|
-
// Memoize the open handler
|
|
132
|
-
const handleOpen = useCallback((alertDialogOptions?: AlertDialogOptions) => {
|
|
133
|
-
setVisible(true);
|
|
134
|
-
if (alertDialogOptions) {
|
|
135
|
-
setOptions(alertDialogOptions);
|
|
136
|
-
}
|
|
137
|
-
}, []);
|
|
138
|
-
|
|
139
|
-
useImperativeHandle(ref, () => ({
|
|
140
|
-
open: handleOpen,
|
|
141
|
-
close: handleClose,
|
|
142
|
-
}), [handleOpen, handleClose]);
|
|
143
|
-
|
|
144
|
-
const {
|
|
145
|
-
backdropOpacity = 0.2,
|
|
146
|
-
title,
|
|
147
|
-
body,
|
|
148
|
-
styles,
|
|
149
|
-
actions,
|
|
150
|
-
closeOnTouchOutside = true,
|
|
151
|
-
showCloseButton = true,
|
|
152
|
-
size = 'medium',
|
|
153
|
-
} = options ?? {};
|
|
154
|
-
|
|
155
|
-
// Calculate sizes based on size prop
|
|
156
|
-
const sizeConfig = useMemo(() => {
|
|
157
|
-
if (typeof size === 'number') {
|
|
158
|
-
return {
|
|
159
|
-
titleFontSize: size,
|
|
160
|
-
bodyFontSize: size * 0.875,
|
|
161
|
-
iconSize: size * 1.125,
|
|
162
|
-
actionMarginTop: size * 1.25,
|
|
163
|
-
bodyMarginTop: size * 0.75,
|
|
164
|
-
bodyMarginBottom: size * 0.5,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
switch (size) {
|
|
169
|
-
case 'small':
|
|
170
|
-
return {
|
|
171
|
-
titleFontSize: 14,
|
|
172
|
-
bodyFontSize: 12,
|
|
173
|
-
iconSize: 16,
|
|
174
|
-
actionMarginTop: 16,
|
|
175
|
-
bodyMarginTop: 10,
|
|
176
|
-
bodyMarginBottom: 6,
|
|
177
|
-
};
|
|
178
|
-
case 'large':
|
|
179
|
-
return {
|
|
180
|
-
titleFontSize: 18,
|
|
181
|
-
bodyFontSize: 16,
|
|
182
|
-
iconSize: 20,
|
|
183
|
-
actionMarginTop: 24,
|
|
184
|
-
bodyMarginTop: 14,
|
|
185
|
-
bodyMarginBottom: 10,
|
|
186
|
-
};
|
|
187
|
-
default: // 'medium'
|
|
188
|
-
return {
|
|
189
|
-
titleFontSize: 16,
|
|
190
|
-
bodyFontSize: 14,
|
|
191
|
-
iconSize: 18,
|
|
192
|
-
actionMarginTop: 20,
|
|
193
|
-
bodyMarginTop: 12,
|
|
194
|
-
bodyMarginBottom: 8,
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
}, [size]);
|
|
198
|
-
|
|
199
|
-
// Memoize backdrop color calculation
|
|
200
|
-
const backdropColor = useMemo(() =>
|
|
201
|
-
themeType === 'light'
|
|
202
|
-
? `rgba(0,0,0,${backdropOpacity})`
|
|
203
|
-
: `rgba(255,255,255,${backdropOpacity})`,
|
|
204
|
-
[themeType, backdropOpacity]
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
// Memoize shadow styles
|
|
208
|
-
const shadowStyles = useMemo(() =>
|
|
209
|
-
Platform.OS !== 'web' ? {
|
|
210
|
-
shadowOffset: {width: 0, height: 4},
|
|
211
|
-
shadowColor: theme.text.basic,
|
|
212
|
-
} : {},
|
|
213
|
-
[theme.text.basic]
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
// Memoize container styles
|
|
217
|
-
const containerStyles = useMemo(() =>
|
|
218
|
-
StyleSheet.flatten([shadowStyles, styles?.container]),
|
|
219
|
-
[shadowStyles, styles?.container]
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
// Memoize backdrop press handler
|
|
223
|
-
const handleBackdropPress = useCallback(() => {
|
|
224
|
-
if (closeOnTouchOutside) {
|
|
225
|
-
setVisible(false);
|
|
226
|
-
}
|
|
227
|
-
}, [closeOnTouchOutside]);
|
|
228
|
-
|
|
229
|
-
// Memoize close button press handler
|
|
230
|
-
const handleCloseButtonPress = useCallback(() => setVisible(false), []);
|
|
231
|
-
|
|
232
|
-
// Memoize title content
|
|
233
|
-
const titleContent = useMemo(() =>
|
|
234
|
-
typeof title === 'string' ? (
|
|
235
|
-
<Typography.Heading3 style={[{fontSize: sizeConfig.titleFontSize}, styles?.title]}>
|
|
236
|
-
{title}
|
|
237
|
-
</Typography.Heading3>
|
|
238
|
-
) : (
|
|
239
|
-
title
|
|
240
|
-
),
|
|
241
|
-
[title, sizeConfig.titleFontSize, styles?.title]
|
|
242
|
-
);
|
|
243
|
-
|
|
244
|
-
// Memoize body content
|
|
245
|
-
const bodyContent = useMemo(() =>
|
|
246
|
-
typeof body === 'string' ? (
|
|
247
|
-
<Typography.Body3 style={[{fontSize: sizeConfig.bodyFontSize}, styles?.body]}>{body}</Typography.Body3>
|
|
248
|
-
) : (
|
|
249
|
-
body
|
|
250
|
-
),
|
|
251
|
-
[body, sizeConfig.bodyFontSize, styles?.body]
|
|
252
|
-
);
|
|
253
|
-
|
|
254
|
-
// Memoize actions content
|
|
255
|
-
const actionsContent = useMemo(() =>
|
|
256
|
-
actions ? (
|
|
257
|
-
<ActionRow $marginTop={sizeConfig.actionMarginTop} style={styles?.actionContainer}>
|
|
258
|
-
{actions.map((action, index) =>
|
|
259
|
-
cloneElement(action, {
|
|
260
|
-
key: `action-${index}`,
|
|
261
|
-
style: {
|
|
262
|
-
flex: 1,
|
|
263
|
-
marginLeft: index !== 0 ? 12 : 0,
|
|
264
|
-
},
|
|
265
|
-
} as any),
|
|
266
|
-
)}
|
|
267
|
-
</ActionRow>
|
|
268
|
-
) : null,
|
|
269
|
-
[actions, sizeConfig.actionMarginTop, styles?.actionContainer]
|
|
270
|
-
);
|
|
271
|
-
|
|
272
|
-
// Memoize close button content
|
|
273
|
-
const closeButtonContent = useMemo(() =>
|
|
274
|
-
showCloseButton ? (
|
|
275
|
-
<Button
|
|
276
|
-
onPress={handleCloseButtonPress}
|
|
277
|
-
borderRadius={24}
|
|
278
|
-
text={<Icon color={theme.text.basic} name="X" size={sizeConfig.iconSize} />}
|
|
279
|
-
type="text"
|
|
280
|
-
/>
|
|
281
|
-
) : null,
|
|
282
|
-
[showCloseButton, handleCloseButtonPress, sizeConfig.iconSize, theme.text.basic]
|
|
283
|
-
);
|
|
284
|
-
|
|
285
|
-
const AlertDialogContent = useMemo(() => (
|
|
286
|
-
<Container
|
|
287
|
-
style={css`
|
|
288
|
-
background-color: ${backdropColor};
|
|
289
|
-
`}
|
|
290
|
-
>
|
|
291
|
-
<TouchableWithoutFeedback
|
|
292
|
-
onPress={closeOnTouchOutside ? handleCloseButtonPress : undefined}
|
|
293
|
-
>
|
|
294
|
-
<View style={StyleSheet.absoluteFill} />
|
|
295
|
-
</TouchableWithoutFeedback>
|
|
296
|
-
|
|
297
|
-
<AlertDialogContainer
|
|
298
|
-
$size={size}
|
|
299
|
-
accessibilityRole="alert"
|
|
300
|
-
accessibilityLabel={typeof title === 'string' ? title : 'Alert dialog'}
|
|
301
|
-
style={containerStyles}
|
|
302
|
-
>
|
|
303
|
-
<TitleRow style={styles?.titleContainer}>
|
|
304
|
-
{titleContent}
|
|
305
|
-
{closeButtonContent}
|
|
306
|
-
</TitleRow>
|
|
307
|
-
<BodyRow $marginTop={sizeConfig.bodyMarginTop} $marginBottom={sizeConfig.bodyMarginBottom} style={styles?.bodyContainer}>
|
|
308
|
-
{bodyContent}
|
|
309
|
-
</BodyRow>
|
|
310
|
-
{actionsContent}
|
|
311
|
-
</AlertDialogContainer>
|
|
312
|
-
</Container>
|
|
313
|
-
), [
|
|
314
|
-
backdropColor,
|
|
315
|
-
closeOnTouchOutside,
|
|
316
|
-
handleCloseButtonPress,
|
|
317
|
-
title,
|
|
318
|
-
size,
|
|
319
|
-
containerStyles,
|
|
320
|
-
styles?.titleContainer,
|
|
321
|
-
styles?.bodyContainer,
|
|
322
|
-
sizeConfig.bodyMarginTop,
|
|
323
|
-
sizeConfig.bodyMarginBottom,
|
|
324
|
-
titleContent,
|
|
325
|
-
closeButtonContent,
|
|
326
|
-
bodyContent,
|
|
327
|
-
actionsContent,
|
|
328
|
-
]);
|
|
329
|
-
|
|
330
|
-
return (
|
|
331
|
-
// https://github.com/facebook/react-native/issues/48526#issuecomment-2579478884
|
|
332
|
-
<View style={style}>
|
|
333
|
-
<Modal
|
|
334
|
-
animationType="fade"
|
|
335
|
-
transparent={true}
|
|
336
|
-
visible={visible}
|
|
337
|
-
>
|
|
338
|
-
{closeOnTouchOutside ? (
|
|
339
|
-
<TouchableWithoutFeedback
|
|
340
|
-
onPress={handleBackdropPress}
|
|
341
|
-
style={css`
|
|
342
|
-
flex: 1;
|
|
343
|
-
`}
|
|
344
|
-
>
|
|
345
|
-
{AlertDialogContent}
|
|
346
|
-
</TouchableWithoutFeedback>
|
|
347
|
-
) : (
|
|
348
|
-
AlertDialogContent
|
|
349
|
-
)}
|
|
350
|
-
</Modal>
|
|
351
|
-
</View>
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// Export memoized component for better performance
|
|
356
|
-
export default React.memo(forwardRef<AlertDialogContext, AlertDialogProps>(AlertDialog));
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import React, {type ReactElement} from 'react';
|
|
2
|
-
import type {ComponentProps} from 'react';
|
|
3
|
-
import {SafeAreaView} from 'react-native';
|
|
4
|
-
import {styled, css} from 'kstyled';
|
|
5
|
-
import type {Meta, StoryObj} from '@storybook/react';
|
|
6
|
-
import {useCPK} from '../../../providers';
|
|
7
|
-
import {Typography} from '../../uis/Typography/Typography';
|
|
8
|
-
import {Button} from '../../uis/Button/Button';
|
|
9
|
-
import {withThemeProvider} from '../../../../.storybook/decorators';
|
|
10
|
-
import Snackbar, {type SnackbarSizeType} from './Snackbar';
|
|
11
|
-
|
|
12
|
-
const Container = styled(SafeAreaView)`
|
|
13
|
-
flex-direction: column;
|
|
14
|
-
padding: 48px 24px;
|
|
15
|
-
align-self: stretch;
|
|
16
|
-
justify-content: center;
|
|
17
|
-
align-items: center;
|
|
18
|
-
`;
|
|
19
|
-
|
|
20
|
-
type SnackbarBasicStoryProps = {
|
|
21
|
-
size: SnackbarSizeType;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
function SnackbarBasicStory({size}: SnackbarBasicStoryProps): ReactElement {
|
|
25
|
-
const {snackbar} = useCPK();
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<Container>
|
|
29
|
-
<Typography.Title>Snackbar</Typography.Title>
|
|
30
|
-
<Button
|
|
31
|
-
color="primary"
|
|
32
|
-
onPress={() =>
|
|
33
|
-
snackbar.open({
|
|
34
|
-
text: 'Hello there!',
|
|
35
|
-
size,
|
|
36
|
-
})
|
|
37
|
-
}
|
|
38
|
-
style={{marginTop: 60, width: 200}}
|
|
39
|
-
text="Snackbar"
|
|
40
|
-
/>
|
|
41
|
-
<Button
|
|
42
|
-
color="primary"
|
|
43
|
-
onPress={() =>
|
|
44
|
-
snackbar.open({
|
|
45
|
-
text: 'Hello there!',
|
|
46
|
-
actionText: 'Cancel',
|
|
47
|
-
size,
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
style={{marginTop: 20, width: 200}}
|
|
51
|
-
text="With action"
|
|
52
|
-
/>
|
|
53
|
-
<Button
|
|
54
|
-
color="info"
|
|
55
|
-
onPress={() =>
|
|
56
|
-
snackbar.open({
|
|
57
|
-
text: 'Hello there!',
|
|
58
|
-
color: 'info',
|
|
59
|
-
size,
|
|
60
|
-
})
|
|
61
|
-
}
|
|
62
|
-
style={{marginTop: 20, width: 200}}
|
|
63
|
-
text="Color = info"
|
|
64
|
-
/>
|
|
65
|
-
<Button
|
|
66
|
-
color="danger"
|
|
67
|
-
onPress={() =>
|
|
68
|
-
snackbar.open({
|
|
69
|
-
text: 'Hello there!',
|
|
70
|
-
color: 'danger',
|
|
71
|
-
size,
|
|
72
|
-
})
|
|
73
|
-
}
|
|
74
|
-
style={{marginTop: 20, width: 200}}
|
|
75
|
-
text="Color = danger"
|
|
76
|
-
/>
|
|
77
|
-
<Button
|
|
78
|
-
color="light"
|
|
79
|
-
onPress={() =>
|
|
80
|
-
snackbar.open({
|
|
81
|
-
text: 'Hello there!',
|
|
82
|
-
color: 'light',
|
|
83
|
-
size,
|
|
84
|
-
})
|
|
85
|
-
}
|
|
86
|
-
style={{marginTop: 20, width: 200}}
|
|
87
|
-
text="Color = light"
|
|
88
|
-
/>
|
|
89
|
-
</Container>
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const meta = {
|
|
94
|
-
title: 'Snackbar',
|
|
95
|
-
component: SnackbarBasicStory,
|
|
96
|
-
parameters: {
|
|
97
|
-
docs: {
|
|
98
|
-
description: {
|
|
99
|
-
component: `
|
|
100
|
-
A brief message component that appears at the bottom of the screen to provide feedback about an operation.
|
|
101
|
-
|
|
102
|
-
## Features
|
|
103
|
-
- **Flexible Sizing**: Preset sizes (small, medium, large) and custom numeric values
|
|
104
|
-
- **Color Variants**: Support for primary, info, danger, light, and other theme colors
|
|
105
|
-
- **Action Button**: Optional action button with custom text
|
|
106
|
-
- **Auto-dismiss**: Automatically dismisses after a configurable timer
|
|
107
|
-
- **Customizable**: Custom styles for container, text, and action elements
|
|
108
|
-
|
|
109
|
-
## Size Options
|
|
110
|
-
- \`small\`: 12px text, 14px icon
|
|
111
|
-
- \`medium\`: 14px text, 16px icon (default)
|
|
112
|
-
- \`large\`: 16px text, 18px icon
|
|
113
|
-
- Custom number: Custom font size in pixels with proportional spacing
|
|
114
|
-
|
|
115
|
-
## Usage
|
|
116
|
-
\`\`\`tsx
|
|
117
|
-
const {snackbar} = useCPK();
|
|
118
|
-
|
|
119
|
-
snackbar.open({
|
|
120
|
-
text: 'Item saved successfully',
|
|
121
|
-
size: 'medium',
|
|
122
|
-
color: 'primary',
|
|
123
|
-
});
|
|
124
|
-
\`\`\`
|
|
125
|
-
|
|
126
|
-
### Basic Snackbar
|
|
127
|
-
\`\`\`tsx
|
|
128
|
-
snackbar.open({
|
|
129
|
-
text: 'Hello there!',
|
|
130
|
-
size: 'medium',
|
|
131
|
-
});
|
|
132
|
-
\`\`\`
|
|
133
|
-
|
|
134
|
-
### With Action Button
|
|
135
|
-
\`\`\`tsx
|
|
136
|
-
snackbar.open({
|
|
137
|
-
text: 'Item deleted',
|
|
138
|
-
actionText: 'Undo',
|
|
139
|
-
size: 'large',
|
|
140
|
-
color: 'danger',
|
|
141
|
-
});
|
|
142
|
-
\`\`\`
|
|
143
|
-
|
|
144
|
-
### With Custom Timer
|
|
145
|
-
\`\`\`tsx
|
|
146
|
-
snackbar.open({
|
|
147
|
-
text: 'Connection established',
|
|
148
|
-
size: 'small',
|
|
149
|
-
color: 'info',
|
|
150
|
-
timer: 5000, // 5 seconds
|
|
151
|
-
});
|
|
152
|
-
\`\`\`
|
|
153
|
-
`,
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
argTypes: {
|
|
158
|
-
size: {
|
|
159
|
-
control: 'radio',
|
|
160
|
-
options: ['small', 'medium', 'large', 12, 14, 16, 18],
|
|
161
|
-
description: 'Snackbar size: "small" (12px text), "medium" (14px text), "large" (16px text), or custom number in pixels',
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
decorators: [withThemeProvider],
|
|
165
|
-
} satisfies Meta<typeof SnackbarBasicStory>;
|
|
166
|
-
|
|
167
|
-
export default meta;
|
|
168
|
-
|
|
169
|
-
type Story = StoryObj<typeof meta>;
|
|
170
|
-
|
|
171
|
-
export const Basic: Story = {
|
|
172
|
-
args: {
|
|
173
|
-
size: 'medium',
|
|
174
|
-
},
|
|
175
|
-
argTypes: {
|
|
176
|
-
// @ts-expect-error - theme is for storybook control
|
|
177
|
-
theme: {
|
|
178
|
-
control: 'select',
|
|
179
|
-
options: ['light', 'dark'],
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
};
|