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,436 +0,0 @@
1
- import React, {useCallback, useMemo, useRef, type ReactElement} from 'react';
2
- import type {
3
- Insets,
4
- StyleProp,
5
- TextStyle,
6
- TouchableHighlightProps,
7
- ViewStyle,
8
- } from 'react-native';
9
- import {Platform, TouchableHighlight, View} from 'react-native';
10
- import {useHover} from 'react-native-web-hooks';
11
- import {styled, css} from 'kstyled';
12
-
13
- import {useTheme} from '../../../providers/ThemeProvider';
14
- import {cloneElemWithDefaultColors} from '../../../utils/guards';
15
- import type {CpkTheme} from '../../../utils/theme';
16
- import {LoadingIndicator} from '../LoadingIndicator/LoadingIndicator';
17
- import {Typography} from '../Typography/Typography';
18
- import * as Haptics from 'expo-haptics';
19
-
20
- export type ButtonType = 'text' | 'solid' | 'outlined';
21
- export type ButtonColorType =
22
- | 'primary'
23
- | 'secondary'
24
- | 'success'
25
- | 'danger'
26
- | 'warning'
27
- | 'info'
28
- | 'light';
29
- export type ButtonSizeType = 'small' | 'medium' | 'large' | number;
30
-
31
- export type Props = {
32
- testID?: string;
33
- type?: ButtonType;
34
- color?: ButtonColorType;
35
- size?: ButtonSizeType;
36
- disabled?: boolean;
37
- loading?: boolean;
38
- loadingColor?: string;
39
- loadingElement?: ReactElement;
40
- text?: string | ReactElement;
41
- borderRadius?: number;
42
- startElement?: ReactElement;
43
- endElement?: ReactElement;
44
- style?: StyleProp<Omit<ViewStyle, 'borderRadius' | 'padding'>>;
45
- styles?: Styles;
46
- onPress?: TouchableHighlightProps['onPress'];
47
- activeOpacity?: TouchableHighlightProps['activeOpacity'];
48
- touchableHighlightProps?: Omit<
49
- TouchableHighlightProps,
50
- 'onPress' | 'activeOpacity' | 'style'
51
- >;
52
- hitSlop?: null | Insets | number | undefined;
53
- hapticFeedback?: Haptics.ImpactFeedbackStyle;
54
- };
55
-
56
- type Styles = {
57
- container?: StyleProp<ViewStyle>;
58
- content?: StyleProp<ViewStyle>;
59
- loading?: StyleProp<ViewStyle>;
60
- text?: StyleProp<TextStyle>;
61
- disabled?: StyleProp<ViewStyle>;
62
- disabledText?: StyleProp<TextStyle>;
63
- hovered?: StyleProp<ViewStyle>;
64
- };
65
-
66
- type ButtonContainerStyleProps = {
67
- $type: ButtonType;
68
- $size?: ButtonSizeType;
69
- $outlined?: boolean;
70
- $disabled?: boolean;
71
- $loading?: boolean;
72
- };
73
-
74
- const ButtonContainer = styled.View<ButtonContainerStyleProps>`
75
- align-self: stretch;
76
- flex-direction: row;
77
- align-items: center;
78
- justify-content: center;
79
- `;
80
-
81
- // Memoize style calculation function
82
- const calculateStyles = ({
83
- theme,
84
- type,
85
- color,
86
- size,
87
- loading,
88
- disabled,
89
- borderRadius,
90
- hovered,
91
- styles,
92
- }: {
93
- theme: CpkTheme;
94
- type: ButtonType;
95
- color: ButtonColorType;
96
- size: ButtonSizeType;
97
- loading: boolean;
98
- disabled: boolean;
99
- borderRadius: number;
100
- hovered: boolean;
101
- styles?: Styles;
102
- }): Styles => {
103
- const isDisabled = disabled || loading;
104
- const padding =
105
- type === 'text'
106
- ? '8px'
107
- : typeof size === 'number'
108
- ? `${size * 0.6}px ${size * 1.2}px`
109
- : size === 'large'
110
- ? '16px 24px'
111
- : size === 'medium'
112
- ? '12px 24px'
113
- : size === 'small'
114
- ? '8px 16px'
115
- : '12px 24px';
116
-
117
- const borderWidth = type === 'outlined' ? 1 : 0;
118
- const backgroundColor =
119
- type === 'solid'
120
- ? isDisabled
121
- ? theme.button.disabled.bg
122
- : theme.button[color].bg
123
- : type === 'outlined'
124
- ? theme.bg.basic
125
- : 'transparent';
126
-
127
- const borderColor =
128
- type === 'outlined'
129
- ? isDisabled
130
- ? theme.bg.disabled
131
- : theme.button[color].bg
132
- : backgroundColor;
133
-
134
- const textColor = isDisabled
135
- ? theme.button.disabled.text
136
- : type === 'solid'
137
- ? theme.button[color].text
138
- : theme.button[color].bg;
139
-
140
- return {
141
- container: [
142
- css`
143
- background-color: ${backgroundColor};
144
- border-top-color: ${borderColor};
145
- border-bottom-color: ${borderColor};
146
- border-left-color: ${borderColor};
147
- border-right-color: ${borderColor};
148
- border-width: ${borderWidth}px;
149
- padding: ${padding};
150
- `,
151
- styles?.container,
152
- ],
153
- content: [
154
- css`
155
- flex-direction: row;
156
- align-items: center;
157
- opacity: ${loading ? '0' : '1'};
158
- gap: 8px;
159
- `,
160
- styles?.content,
161
- ],
162
- loading: [
163
- css`
164
- position: absolute;
165
- opacity: ${loading ? '1' : '0'};
166
- `,
167
- styles?.loading,
168
- ],
169
- text: [
170
- css`
171
- color: ${textColor};
172
- `,
173
- styles?.text,
174
- ],
175
- hovered: hovered
176
- ? [
177
- {
178
- shadowColor: 'black',
179
- shadowOpacity: 0.24,
180
- shadowRadius: 16,
181
- elevation: 10,
182
- borderRadius,
183
- },
184
- styles?.hovered,
185
- ]
186
- : undefined,
187
- disabled: isDisabled
188
- ? [
189
- css`
190
- background-color: ${theme.button.disabled.bg};
191
- border-top-color: ${theme.bg.disabled};
192
- border-bottom-color: ${theme.bg.disabled};
193
- border-left-color: ${theme.bg.disabled};
194
- border-right-color: ${theme.bg.disabled};
195
- `,
196
- styles?.disabled,
197
- ]
198
- : undefined,
199
- };
200
- };
201
-
202
- // Memoize button state hook
203
- const useButtonState = ({
204
- disabled,
205
- onPress,
206
- loading,
207
- }: {
208
- disabled?: boolean;
209
- onPress?: TouchableHighlightProps['onPress'];
210
- loading: boolean;
211
- }): {
212
- innerDisabled: boolean;
213
- isLoading: boolean;
214
- } => {
215
- return useMemo(
216
- () => ({
217
- innerDisabled: disabled || !onPress,
218
- isLoading: loading,
219
- }),
220
- [disabled, onPress, loading],
221
- );
222
- };
223
-
224
- export function Button({
225
- testID,
226
- type = 'solid',
227
- color = 'primary',
228
- size = 'medium',
229
- disabled,
230
- loading = false,
231
- loadingElement,
232
- text,
233
- startElement,
234
- endElement,
235
- style,
236
- styles,
237
- onPress,
238
- activeOpacity = 0.8,
239
- touchableHighlightProps,
240
- borderRadius = 4,
241
- loadingColor,
242
- hitSlop = {top: 8, bottom: 8, left: 8, right: 8},
243
- hapticFeedback,
244
- }: Props): ReactElement {
245
- const ref = useRef<React.ElementRef<typeof TouchableHighlight>>(null);
246
- const hovered = useHover(ref);
247
- const {theme} = useTheme();
248
-
249
- const {innerDisabled} = useButtonState({disabled, onPress, loading});
250
-
251
- // Memoize styles calculation
252
- const compositeStyles: Styles = useMemo(
253
- () =>
254
- calculateStyles({
255
- theme,
256
- type,
257
- color,
258
- size,
259
- loading,
260
- disabled: innerDisabled,
261
- borderRadius,
262
- hovered,
263
- styles,
264
- }),
265
- [
266
- theme,
267
- type,
268
- color,
269
- size,
270
- loading,
271
- innerDisabled,
272
- borderRadius,
273
- hovered,
274
- styles,
275
- ],
276
- );
277
-
278
- // Memoize loading view
279
- const LoadingView = useMemo(
280
- () =>
281
- loadingElement ?? (
282
- <LoadingIndicator
283
- color={
284
- loadingColor
285
- ? loadingColor
286
- : type === 'solid'
287
- ? theme.text.contrast
288
- : theme.text.basic
289
- }
290
- size="small"
291
- />
292
- ),
293
- [loadingElement, loadingColor, type, theme.text.contrast, theme.text.basic],
294
- );
295
-
296
- // Memoize style resolvers
297
- const resolveStyle = useCallback(<T,>(style: StyleProp<T>): T | undefined => {
298
- if (Array.isArray(style)) {
299
- return style.find((s): s is T => !!s);
300
- }
301
- return (style as T) || undefined;
302
- }, []);
303
-
304
- const viewStyle = useMemo(
305
- () => resolveStyle<ViewStyle>(compositeStyles.container),
306
- [resolveStyle, compositeStyles.container],
307
- );
308
- const textStyle = useMemo(
309
- () => resolveStyle<TextStyle>(compositeStyles.text),
310
- [resolveStyle, compositeStyles.text],
311
- );
312
-
313
- // Memoize child view
314
- const ChildView = useMemo(
315
- () => (
316
- <>
317
- {cloneElemWithDefaultColors({
318
- element: startElement,
319
- backgroundColor: viewStyle?.backgroundColor,
320
- color: textStyle?.color,
321
- })}
322
- {!text || typeof text === 'string' ? (
323
- <Typography.Body2 style={compositeStyles.text}>
324
- {text}
325
- </Typography.Body2>
326
- ) : (
327
- text
328
- )}
329
- {cloneElemWithDefaultColors({
330
- element: endElement,
331
- backgroundColor: viewStyle?.backgroundColor,
332
- color: textStyle?.color,
333
- })}
334
- </>
335
- ),
336
- [
337
- startElement,
338
- endElement,
339
- text,
340
- compositeStyles.text,
341
- viewStyle?.backgroundColor,
342
- textStyle?.color,
343
- ],
344
- );
345
-
346
- // Memoize container renderer
347
- const renderContainer = useCallback(
348
- ({
349
- children,
350
- loadingView,
351
- }: {
352
- children: ReactElement;
353
- loadingView: ReactElement;
354
- }): ReactElement => (
355
- <ButtonContainer
356
- $disabled={innerDisabled}
357
- $size={size}
358
- style={[
359
- hovered && !innerDisabled && compositeStyles.hovered,
360
- compositeStyles.container,
361
- type === 'text' &&
362
- css`
363
- background-color: transparent;
364
- `,
365
- innerDisabled && compositeStyles.disabled,
366
- !!borderRadius && {borderRadius},
367
- ]}
368
- testID={loading ? 'loading-view' : 'button-container'}
369
- $type={type}
370
- >
371
- <View style={compositeStyles.content}>{children}</View>
372
- <View style={compositeStyles.loading}>{loadingView}</View>
373
- </ButtonContainer>
374
- ),
375
- [
376
- innerDisabled,
377
- size,
378
- compositeStyles.container,
379
- compositeStyles.hovered,
380
- compositeStyles.disabled,
381
- compositeStyles.content,
382
- compositeStyles.loading,
383
- hovered,
384
- type,
385
- loading,
386
- ],
387
- );
388
-
389
- // Memoize press handler
390
- const handlePress = useCallback(
391
- (e: any) => {
392
- onPress?.(e);
393
- if (hapticFeedback) {
394
- Haptics.impactAsync(hapticFeedback);
395
- }
396
- },
397
- [onPress, hapticFeedback],
398
- );
399
-
400
- // Memoize button styles
401
- const buttonStyles = useMemo(
402
- () => [
403
- style,
404
- css`
405
- border-radius: ${borderRadius}px;
406
- `,
407
- ],
408
- [style, borderRadius],
409
- );
410
-
411
- return (
412
- <TouchableHighlight
413
- activeOpacity={activeOpacity}
414
- delayPressIn={30}
415
- disabled={innerDisabled || loading || !onPress}
416
- hitSlop={hitSlop}
417
- onPress={handlePress}
418
- ref={Platform.select({
419
- web: ref,
420
- default: undefined,
421
- })}
422
- style={buttonStyles}
423
- testID={testID}
424
- underlayColor={type === 'text' ? 'transparent' : theme.role.underlay}
425
- {...touchableHighlightProps}
426
- >
427
- {renderContainer({
428
- children: ChildView,
429
- loadingView: LoadingView,
430
- })}
431
- </TouchableHighlight>
432
- );
433
- }
434
-
435
- // Export memoized component for better performance
436
- export default React.memo(Button) as typeof Button;
@@ -1,146 +0,0 @@
1
- import '@testing-library/jest-native/extend-expect';
2
-
3
- import React, {type ReactElement} from 'react';
4
- import {Text} from 'react-native';
5
- import type {RenderAPI} from '@testing-library/react-native';
6
- import {fireEvent, render} from '@testing-library/react-native';
7
-
8
- import {createComponent} from '../../../../test/testUtils';
9
- import {Card} from './Card';
10
- import type {CardProps} from './Card';
11
- import type {ThemeType} from '../../../providers/ThemeProvider';
12
-
13
- let testingLib: RenderAPI;
14
-
15
- const Component = ({
16
- props,
17
- themeType,
18
- }: {
19
- props?: CardProps;
20
- themeType?: ThemeType;
21
- }): ReactElement =>
22
- createComponent(
23
- <Card {...props}>
24
- <Text>Test Content</Text>
25
- </Card>,
26
- themeType,
27
- );
28
-
29
- describe('[Card]', () => {
30
- it('should render without crashing', () => {
31
- testingLib = render(Component({}));
32
-
33
- const json = testingLib.toJSON();
34
- expect(json).toBeTruthy();
35
- });
36
-
37
- it('should render with default props', () => {
38
- testingLib = render(Component({}));
39
-
40
- const cardContainer = testingLib.getByTestId('card-container');
41
- expect(cardContainer).toBeTruthy();
42
- });
43
-
44
- it('should render children content', () => {
45
- testingLib = render(Component({}));
46
-
47
- expect(testingLib.getByText('Test Content')).toBeTruthy();
48
- });
49
-
50
- it('should handle onPress when provided', () => {
51
- const mockOnPress = jest.fn();
52
- testingLib = render(Component({props: {onPress: mockOnPress}}));
53
-
54
- const cardContainer = testingLib.getByTestId('card-container');
55
- fireEvent.press(cardContainer);
56
-
57
- expect(mockOnPress).toHaveBeenCalledTimes(1);
58
- });
59
-
60
- it('should apply custom testID', () => {
61
- const customTestID = 'custom-card';
62
- testingLib = render(Component({props: {testID: customTestID}}));
63
-
64
- expect(testingLib.getByTestId(customTestID)).toBeTruthy();
65
- });
66
-
67
- it('should apply custom elevation', () => {
68
- testingLib = render(Component({props: {elevation: 5}}));
69
-
70
- const cardContainer = testingLib.getByTestId('card-container');
71
- expect(cardContainer).toBeTruthy();
72
- });
73
-
74
- it('should apply custom border radius', () => {
75
- testingLib = render(Component({props: {borderRadius: 12}}));
76
-
77
- const cardContainer = testingLib.getByTestId('card-container');
78
- expect(cardContainer).toBeTruthy();
79
- });
80
-
81
- it('should apply custom padding', () => {
82
- testingLib = render(Component({props: {padding: 24}}));
83
-
84
- const cardContainer = testingLib.getByTestId('card-container');
85
- expect(cardContainer).toBeTruthy();
86
- });
87
-
88
- it('should apply custom margin', () => {
89
- testingLib = render(Component({props: {margin: 16}}));
90
-
91
- const cardContainer = testingLib.getByTestId('card-container');
92
- expect(cardContainer).toBeTruthy();
93
- });
94
-
95
- it('should apply custom background color', () => {
96
- testingLib = render(Component({props: {backgroundColor: '#ff0000'}}));
97
-
98
- const cardContainer = testingLib.getByTestId('card-container');
99
- expect(cardContainer).toBeTruthy();
100
- });
101
-
102
- describe('Themes', () => {
103
- it('should render correctly with light theme', () => {
104
- testingLib = render(Component({themeType: 'light'}));
105
-
106
- const cardContainer = testingLib.getByTestId('card-container');
107
- expect(cardContainer).toBeTruthy();
108
- });
109
-
110
- it('should render correctly with dark theme', () => {
111
- testingLib = render(Component({themeType: 'dark'}));
112
-
113
- const cardContainer = testingLib.getByTestId('card-container');
114
- expect(cardContainer).toBeTruthy();
115
- });
116
- });
117
-
118
- describe('Custom Styles', () => {
119
- it('should apply custom container styles', () => {
120
- const customStyles = {
121
- container: {
122
- borderWidth: 2,
123
- borderColor: '#000',
124
- },
125
- };
126
-
127
- testingLib = render(Component({props: {styles: customStyles}}));
128
-
129
- const cardContainer = testingLib.getByTestId('card-container');
130
- expect(cardContainer).toBeTruthy();
131
- });
132
-
133
- it('should apply custom content styles', () => {
134
- const customStyles = {
135
- content: {
136
- alignItems: 'center' as const,
137
- },
138
- };
139
-
140
- testingLib = render(Component({props: {styles: customStyles}}));
141
-
142
- const cardContainer = testingLib.getByTestId('card-container');
143
- expect(cardContainer).toBeTruthy();
144
- });
145
- });
146
- });
@@ -1,102 +0,0 @@
1
- /**
2
- * @name Card
3
- *
4
- * See the style guide: https://github.com/hyochan/style-guide/blob/main/docs/REACT.md
5
- */
6
- import React from 'react';
7
- import type {StyleProp, ViewStyle} from 'react-native';
8
- import {TouchableOpacity, View} from 'react-native';
9
- import {styled, css} from 'kstyled';
10
-
11
- import {useTheme} from '../../../providers/ThemeProvider';
12
-
13
- type Styles = {
14
- container?: StyleProp<ViewStyle>;
15
- content?: StyleProp<ViewStyle>;
16
- };
17
-
18
- export type CardProps = {
19
- testID?: string;
20
- children?: React.ReactNode;
21
- elevation?: number;
22
- borderRadius?: number;
23
- padding?: number;
24
- margin?: number;
25
- backgroundColor?: string;
26
- style?: StyleProp<ViewStyle>;
27
- styles?: Styles;
28
- onPress?: () => void;
29
- };
30
-
31
- export default function Card({
32
- testID = 'card-container',
33
- children,
34
- elevation = 2,
35
- borderRadius = 8,
36
- padding = 16,
37
- margin = 0,
38
- backgroundColor,
39
- style,
40
- styles,
41
- onPress,
42
- }: CardProps): JSX.Element {
43
- const {theme} = useTheme();
44
-
45
- const shadowStyle = React.useMemo(() => ({
46
- elevation: elevation,
47
- shadowOffset: {
48
- width: 0,
49
- height: elevation / 2,
50
- },
51
- shadowOpacity: 0.1,
52
- shadowRadius: elevation,
53
- shadowColor: theme.text.basic,
54
- }), [elevation, theme.text.basic]);
55
-
56
- const containerStyle = React.useMemo(() => [
57
- {
58
- backgroundColor: backgroundColor || theme.bg.paper,
59
- borderRadius: borderRadius,
60
- padding: padding,
61
- margin: margin,
62
- },
63
- shadowStyle,
64
- style,
65
- styles?.container,
66
- ], [backgroundColor, theme.bg.paper, borderRadius, padding, margin, shadowStyle, style, styles?.container]);
67
-
68
- if (onPress) {
69
- return (
70
- <TouchableContainer
71
- testID={testID}
72
- style={containerStyle}
73
- onPress={onPress}
74
- activeOpacity={0.8}
75
- >
76
- <View style={styles?.content}>
77
- {children}
78
- </View>
79
- </TouchableContainer>
80
- );
81
- }
82
-
83
- return (
84
- <Container testID={testID} style={containerStyle}>
85
- <View style={styles?.content}>
86
- {children}
87
- </View>
88
- </Container>
89
- );
90
- }
91
-
92
- const Container = styled.View`
93
- background-color: ${({theme}) => theme.bg.paper};
94
- border-radius: 8px;
95
- `;
96
-
97
- const TouchableContainer = styled.TouchableOpacity`
98
- background-color: ${({theme}) => theme.bg.paper};
99
- border-radius: 8px;
100
- `;
101
-
102
- export {Card};