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,22 +0,0 @@
|
|
|
1
|
-
import {useMemo} from 'react';
|
|
2
|
-
import type {StyleProp, ViewStyle, TextStyle} from 'react-native';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Hook to optimize style objects and prevent unnecessary re-renders
|
|
6
|
-
*/
|
|
7
|
-
export function useOptimizedStyles<T extends Record<string, StyleProp<ViewStyle | TextStyle>>>(
|
|
8
|
-
styleFactory: () => T,
|
|
9
|
-
dependencies: React.DependencyList,
|
|
10
|
-
): T {
|
|
11
|
-
return useMemo(styleFactory, dependencies);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Hook to memoize style arrays
|
|
16
|
-
*/
|
|
17
|
-
export function useStyleArray<T extends StyleProp<ViewStyle | TextStyle>>(
|
|
18
|
-
styles: T[],
|
|
19
|
-
dependencies: React.DependencyList,
|
|
20
|
-
): T[] {
|
|
21
|
-
return useMemo(() => styles, dependencies);
|
|
22
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import {useEffect, useRef} from 'react';
|
|
2
|
-
|
|
3
|
-
interface PerformanceMetrics {
|
|
4
|
-
componentName: string;
|
|
5
|
-
renderCount: number;
|
|
6
|
-
lastRenderTime: number;
|
|
7
|
-
averageRenderTime: number;
|
|
8
|
-
slowRenders: number;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const SLOW_RENDER_THRESHOLD = 16; // 16ms for 60fps
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Hook to monitor component render performance
|
|
15
|
-
* Only active in development mode
|
|
16
|
-
*/
|
|
17
|
-
export function usePerformanceMonitor(
|
|
18
|
-
componentName: string,
|
|
19
|
-
enabled: boolean = __DEV__,
|
|
20
|
-
): PerformanceMetrics | null {
|
|
21
|
-
const metricsRef = useRef<PerformanceMetrics>({
|
|
22
|
-
componentName,
|
|
23
|
-
renderCount: 0,
|
|
24
|
-
lastRenderTime: 0,
|
|
25
|
-
averageRenderTime: 0,
|
|
26
|
-
slowRenders: 0,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const startTimeRef = useRef<number>(0);
|
|
30
|
-
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
if (!enabled) return;
|
|
33
|
-
|
|
34
|
-
const endTime = performance.now();
|
|
35
|
-
const renderTime = endTime - startTimeRef.current;
|
|
36
|
-
|
|
37
|
-
const metrics = metricsRef.current;
|
|
38
|
-
metrics.renderCount++;
|
|
39
|
-
metrics.lastRenderTime = renderTime;
|
|
40
|
-
metrics.averageRenderTime =
|
|
41
|
-
(metrics.averageRenderTime * (metrics.renderCount - 1) + renderTime) /
|
|
42
|
-
metrics.renderCount;
|
|
43
|
-
|
|
44
|
-
if (renderTime > SLOW_RENDER_THRESHOLD) {
|
|
45
|
-
metrics.slowRenders++;
|
|
46
|
-
console.warn(
|
|
47
|
-
`Slow render detected in ${componentName}: ${renderTime.toFixed(2)}ms`,
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
if (enabled) {
|
|
53
|
-
startTimeRef.current = performance.now();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return enabled ? metricsRef.current : null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Hook to track unnecessary re-renders
|
|
61
|
-
*/
|
|
62
|
-
export function useRenderTracker(
|
|
63
|
-
componentName: string,
|
|
64
|
-
props: Record<string, any>,
|
|
65
|
-
enabled: boolean = __DEV__,
|
|
66
|
-
): void {
|
|
67
|
-
const prevPropsRef = useRef<Record<string, any> | undefined>(undefined);
|
|
68
|
-
const renderCountRef = useRef(0);
|
|
69
|
-
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
if (!enabled) return;
|
|
72
|
-
|
|
73
|
-
renderCountRef.current++;
|
|
74
|
-
|
|
75
|
-
if (prevPropsRef.current) {
|
|
76
|
-
const changedProps = Object.keys(props).filter(
|
|
77
|
-
(key) => props[key] !== prevPropsRef.current![key],
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
if (changedProps.length === 0) {
|
|
81
|
-
console.warn(
|
|
82
|
-
`Unnecessary re-render in ${componentName} (render #${renderCountRef.current})`,
|
|
83
|
-
);
|
|
84
|
-
} else if (renderCountRef.current > 10) {
|
|
85
|
-
console.info(
|
|
86
|
-
`${componentName} re-rendered due to: ${changedProps.join(', ')}`,
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
prevPropsRef.current = {...props};
|
|
92
|
-
});
|
|
93
|
-
}
|
package/src/index.tsx
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// Modals
|
|
2
|
-
export * from './components/modals/AlertDialog/AlertDialog';
|
|
3
|
-
export * from './components/modals/Snackbar/Snackbar';
|
|
4
|
-
|
|
5
|
-
// Common Components
|
|
6
|
-
export * from './components/common/ErrorBoundary/ErrorBoundary';
|
|
7
|
-
|
|
8
|
-
// Providers
|
|
9
|
-
export * from './providers';
|
|
10
|
-
|
|
11
|
-
// UIs
|
|
12
|
-
export * from './components/uis/Accordion/Accordion';
|
|
13
|
-
export * from './components/uis/Button/Button';
|
|
14
|
-
export * from './components/uis/Card/Card';
|
|
15
|
-
export * from './components/uis/Checkbox/Checkbox';
|
|
16
|
-
export * from './components/uis/CustomPressable/CustomPressable';
|
|
17
|
-
export * from './components/uis/EditText/EditText';
|
|
18
|
-
export * from './components/uis/Fab/Fab';
|
|
19
|
-
export * from './components/uis/Hr/Hr';
|
|
20
|
-
export * from './components/uis/Icon/Icon';
|
|
21
|
-
export * from './components/uis/IconButton/IconButton';
|
|
22
|
-
export * from './components/uis/LoadingIndicator/LoadingIndicator';
|
|
23
|
-
export * from './components/uis/PinchZoom/PinchZoom';
|
|
24
|
-
export * from './components/uis/Rating/Rating';
|
|
25
|
-
export * from './components/uis/RadioGroup/RadioGroup';
|
|
26
|
-
export * from './components/uis/SegmentedControl/SegmentedControl';
|
|
27
|
-
export * from './components/uis/StatusbarBrightness/StatusBarBrightness';
|
|
28
|
-
export * from './components/uis/SwitchToggle/SwitchToggle';
|
|
29
|
-
export * from './components/uis/Typography/Typography';
|
|
30
|
-
|
|
31
|
-
// Hooks
|
|
32
|
-
export * from './hooks';
|
|
33
|
-
|
|
34
|
-
// Utils
|
|
35
|
-
export * from './utils';
|
|
36
|
-
|
|
37
|
-
// Types
|
|
38
|
-
export * from './types';
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import '@expo/match-media';
|
|
2
|
-
|
|
3
|
-
import React, {useEffect, useState, type ReactElement} from 'react';
|
|
4
|
-
import type {ColorSchemeName} from 'react-native';
|
|
5
|
-
import {useMediaQuery} from 'react-responsive';
|
|
6
|
-
import {ThemeProvider as KStyledThemeProvider} from 'kstyled';
|
|
7
|
-
import type {DefaultTheme} from 'kstyled';
|
|
8
|
-
|
|
9
|
-
import type {CpkTheme, ThemeParam} from '../utils/theme';
|
|
10
|
-
import {dark, light} from '../utils/colors';
|
|
11
|
-
import {useDebouncedColorScheme} from '../hooks/useDebouncedColorScheme';
|
|
12
|
-
import createCtx from '../utils/createCtx';
|
|
13
|
-
|
|
14
|
-
type ResponsiveDesignMode = 'mobile-first' | 'desktop-first';
|
|
15
|
-
export type ThemeType = 'light' | 'dark';
|
|
16
|
-
|
|
17
|
-
export type ThemeContext = {
|
|
18
|
-
themeType: ColorSchemeName;
|
|
19
|
-
media: {
|
|
20
|
-
isPortrait: boolean;
|
|
21
|
-
isMobile: boolean;
|
|
22
|
-
isTablet: boolean;
|
|
23
|
-
isDesktop: boolean;
|
|
24
|
-
};
|
|
25
|
-
theme: DefaultTheme & CpkTheme;
|
|
26
|
-
changeThemeType: (themeType?: ColorSchemeName) => void;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const [useCtx, CpkProvider] = createCtx<ThemeContext>();
|
|
30
|
-
|
|
31
|
-
export type ThemeProps = {
|
|
32
|
-
children?: ReactElement;
|
|
33
|
-
initialThemeType?: ThemeType;
|
|
34
|
-
customTheme?: ThemeParam;
|
|
35
|
-
/*
|
|
36
|
-
@description
|
|
37
|
-
default: mobile-first
|
|
38
|
-
- mobile-first: mobile first responsive design mode
|
|
39
|
-
- desktop-first: desktop first responsive design mode
|
|
40
|
-
*/
|
|
41
|
-
responsiveDesignMode?: ResponsiveDesignMode;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const genTheme = (type: ThemeType, themeParam: ThemeParam): any => {
|
|
45
|
-
const theme = type === 'light' ? light : dark;
|
|
46
|
-
const customTheme = themeParam?.[type] || {};
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
bg: {
|
|
50
|
-
...theme.bg,
|
|
51
|
-
...(customTheme.bg || {}),
|
|
52
|
-
},
|
|
53
|
-
role: {
|
|
54
|
-
...theme.role,
|
|
55
|
-
...(customTheme.role || {}),
|
|
56
|
-
},
|
|
57
|
-
text: {
|
|
58
|
-
...theme.text,
|
|
59
|
-
...(customTheme.text || {}),
|
|
60
|
-
},
|
|
61
|
-
button: {
|
|
62
|
-
...theme.button,
|
|
63
|
-
primary: {
|
|
64
|
-
...theme.button.primary,
|
|
65
|
-
...(customTheme.button?.primary || {}),
|
|
66
|
-
},
|
|
67
|
-
secondary: {
|
|
68
|
-
...theme.button.secondary,
|
|
69
|
-
...(customTheme.button?.secondary || {}),
|
|
70
|
-
},
|
|
71
|
-
success: {
|
|
72
|
-
...theme.button.success,
|
|
73
|
-
...(customTheme.button?.success || {}),
|
|
74
|
-
},
|
|
75
|
-
warning: {
|
|
76
|
-
...theme.button.warning,
|
|
77
|
-
...(customTheme.button?.warning || {}),
|
|
78
|
-
},
|
|
79
|
-
danger: {
|
|
80
|
-
...theme.button.danger,
|
|
81
|
-
...(customTheme.button?.danger || {}),
|
|
82
|
-
},
|
|
83
|
-
info: {
|
|
84
|
-
...theme.button.info,
|
|
85
|
-
...(customTheme.button?.info || {}),
|
|
86
|
-
},
|
|
87
|
-
light: {
|
|
88
|
-
...theme.button.light,
|
|
89
|
-
...(customTheme.button?.light || {}),
|
|
90
|
-
},
|
|
91
|
-
disabled: {
|
|
92
|
-
...theme.button.disabled,
|
|
93
|
-
...(customTheme.button?.disabled || {}),
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
export function ThemeProvider({
|
|
100
|
-
children,
|
|
101
|
-
initialThemeType,
|
|
102
|
-
customTheme = {},
|
|
103
|
-
responsiveDesignMode = 'mobile-first',
|
|
104
|
-
}: ThemeProps): ReactElement {
|
|
105
|
-
console.log('🎨 ThemeProvider rendered with initialThemeType:', initialThemeType);
|
|
106
|
-
|
|
107
|
-
const isPortrait = useMediaQuery({orientation: 'portrait'});
|
|
108
|
-
|
|
109
|
-
const isMobile = useMediaQuery(
|
|
110
|
-
responsiveDesignMode === 'mobile-first'
|
|
111
|
-
? {minWidth: 0}
|
|
112
|
-
: {minWidth: 0, maxWidth: 767},
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
const isTablet = useMediaQuery(
|
|
116
|
-
responsiveDesignMode === 'mobile-first'
|
|
117
|
-
? {minWidth: 767}
|
|
118
|
-
: {minWidth: 768, maxWidth: 992},
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
const isDesktop = useMediaQuery(
|
|
122
|
-
responsiveDesignMode === 'mobile-first' ? {minWidth: 992} : {minWidth: 0},
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
const colorScheme = useDebouncedColorScheme();
|
|
126
|
-
const [themeType, setThemeType] = useState(initialThemeType ?? colorScheme);
|
|
127
|
-
|
|
128
|
-
useEffect(() => {
|
|
129
|
-
if (initialThemeType) {
|
|
130
|
-
setThemeType(initialThemeType);
|
|
131
|
-
} else {
|
|
132
|
-
setThemeType(colorScheme);
|
|
133
|
-
}
|
|
134
|
-
}, [colorScheme, initialThemeType]);
|
|
135
|
-
|
|
136
|
-
const changeThemeType = (themeTypeProp?: ColorSchemeName): void => {
|
|
137
|
-
if (!themeTypeProp) {
|
|
138
|
-
setThemeType(themeType === 'light' ? 'dark' : 'light');
|
|
139
|
-
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
setThemeType(themeTypeProp);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const baseTheme = {
|
|
147
|
-
light: genTheme('light', customTheme),
|
|
148
|
-
dark: genTheme('dark', customTheme),
|
|
149
|
-
}[themeType || 'light'];
|
|
150
|
-
|
|
151
|
-
const media = {
|
|
152
|
-
isPortrait,
|
|
153
|
-
isMobile,
|
|
154
|
-
isTablet,
|
|
155
|
-
isDesktop,
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
const theme = {
|
|
159
|
-
...baseTheme,
|
|
160
|
-
...media,
|
|
161
|
-
} as DefaultTheme & CpkTheme;
|
|
162
|
-
|
|
163
|
-
return (
|
|
164
|
-
<CpkProvider
|
|
165
|
-
value={{
|
|
166
|
-
media,
|
|
167
|
-
themeType,
|
|
168
|
-
changeThemeType,
|
|
169
|
-
theme,
|
|
170
|
-
}}
|
|
171
|
-
>
|
|
172
|
-
<KStyledThemeProvider theme={theme}>{children}</KStyledThemeProvider>
|
|
173
|
-
</CpkProvider>
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export {useCtx as useTheme};
|
package/src/providers/index.tsx
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import React, {type MutableRefObject, useRef, type ReactElement} from 'react';
|
|
2
|
-
import {View} from 'react-native';
|
|
3
|
-
import {css} from 'kstyled';
|
|
4
|
-
import {useFonts} from 'expo-font';
|
|
5
|
-
|
|
6
|
-
import createCtx from '../utils/createCtx';
|
|
7
|
-
import {
|
|
8
|
-
ThemeContext,
|
|
9
|
-
ThemeProps,
|
|
10
|
-
ThemeProvider,
|
|
11
|
-
useTheme,
|
|
12
|
-
} from './ThemeProvider';
|
|
13
|
-
import Snackbar, {
|
|
14
|
-
SnackbarContext,
|
|
15
|
-
SnackbarOptions,
|
|
16
|
-
} from '../components/modals/Snackbar/Snackbar';
|
|
17
|
-
import AlertDialog, {
|
|
18
|
-
AlertDialogContext,
|
|
19
|
-
} from '../components/modals/AlertDialog/AlertDialog';
|
|
20
|
-
import {LoadingIndicator} from '../components/uis/LoadingIndicator/LoadingIndicator';
|
|
21
|
-
|
|
22
|
-
export type ThemeType = ThemeContext['themeType'];
|
|
23
|
-
export type DoobooTheme = ThemeContext['theme'];
|
|
24
|
-
|
|
25
|
-
export type CpkContext = {
|
|
26
|
-
assetLoaded: boolean;
|
|
27
|
-
snackbar: SnackbarContext;
|
|
28
|
-
alertDialog: AlertDialogContext;
|
|
29
|
-
} & ThemeContext;
|
|
30
|
-
|
|
31
|
-
const [useCtx, Provider] = createCtx<CpkContext>();
|
|
32
|
-
|
|
33
|
-
function AppProvider({
|
|
34
|
-
children,
|
|
35
|
-
}: {
|
|
36
|
-
children: ReactElement;
|
|
37
|
-
}): ReactElement {
|
|
38
|
-
const [assetLoaded] = useFonts({
|
|
39
|
-
cpk: require('../components/uis/Icon/cpk.ttf'),
|
|
40
|
-
'Pretendard-Bold': require('../components/uis/Icon/Pretendard-Bold.otf'),
|
|
41
|
-
Pretendard: require('../components/uis/Icon/Pretendard-Regular.otf'),
|
|
42
|
-
'Pretendard-Thin': require('../components/uis/Icon/Pretendard-Thin.otf'),
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const themeContext = useTheme();
|
|
46
|
-
|
|
47
|
-
const snackbar = useRef<SnackbarContext>(
|
|
48
|
-
undefined,
|
|
49
|
-
) as MutableRefObject<SnackbarContext>;
|
|
50
|
-
|
|
51
|
-
const alertDialog = useRef<AlertDialogContext>(
|
|
52
|
-
undefined,
|
|
53
|
-
) as MutableRefObject<AlertDialogContext>;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
** Snackbar
|
|
57
|
-
*/
|
|
58
|
-
const snackbarContext: SnackbarContext = {
|
|
59
|
-
open: (snackbarOption): void => {
|
|
60
|
-
snackbar.current && snackbar.current.open(snackbarOption);
|
|
61
|
-
},
|
|
62
|
-
close: (): void => {
|
|
63
|
-
snackbar.current && snackbar.current.close();
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
** AlertDialog
|
|
69
|
-
*/
|
|
70
|
-
const alertDialogContext: AlertDialogContext = {
|
|
71
|
-
open: (alertDialogOptions): void => {
|
|
72
|
-
alertDialog.current && alertDialog.current.open(alertDialogOptions);
|
|
73
|
-
},
|
|
74
|
-
close: (): void => {
|
|
75
|
-
alertDialog.current && alertDialog.current.close();
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
return (
|
|
80
|
-
<View
|
|
81
|
-
style={css`
|
|
82
|
-
flex: 1;
|
|
83
|
-
`}
|
|
84
|
-
>
|
|
85
|
-
<Provider
|
|
86
|
-
value={{
|
|
87
|
-
...themeContext,
|
|
88
|
-
assetLoaded,
|
|
89
|
-
snackbar: snackbarContext,
|
|
90
|
-
alertDialog: alertDialogContext,
|
|
91
|
-
}}
|
|
92
|
-
>
|
|
93
|
-
{!assetLoaded ? (
|
|
94
|
-
<LoadingIndicator
|
|
95
|
-
style={css`
|
|
96
|
-
align-self: stretch;
|
|
97
|
-
flex: 1;
|
|
98
|
-
justify-content: center;
|
|
99
|
-
background-color: ${themeContext.theme.bg.basic};
|
|
100
|
-
`}
|
|
101
|
-
/>
|
|
102
|
-
) : (
|
|
103
|
-
<>
|
|
104
|
-
{children}
|
|
105
|
-
<Snackbar ref={snackbar} />
|
|
106
|
-
<AlertDialog ref={alertDialog} />
|
|
107
|
-
</>
|
|
108
|
-
)}
|
|
109
|
-
</Provider>
|
|
110
|
-
</View>
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export type CpkProviderProps = {
|
|
115
|
-
themeConfig?: Omit<ThemeProps, 'children'>;
|
|
116
|
-
snackbarConfig?: SnackbarOptions;
|
|
117
|
-
children: ReactElement;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
function CpkWithThemeProvider(props: CpkProviderProps): ReactElement {
|
|
121
|
-
const {themeConfig} = props;
|
|
122
|
-
|
|
123
|
-
return (
|
|
124
|
-
<ThemeProvider {...themeConfig}>
|
|
125
|
-
<AppProvider {...props} />
|
|
126
|
-
</ThemeProvider>
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export {useCtx as useCPK, CpkWithThemeProvider as CpkProvider};
|
package/src/test/testUtils.tsx
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import {render, fireEvent, waitFor} from '@testing-library/react-native';
|
|
2
|
-
import React, {type ReactElement} from 'react';
|
|
3
|
-
import {CpkProvider} from '../providers';
|
|
4
|
-
import {light as lightTheme} from '../utils/colors';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Custom render function that wraps components with necessary providers
|
|
8
|
-
*/
|
|
9
|
-
export function renderWithProviders(
|
|
10
|
-
ui: ReactElement,
|
|
11
|
-
options: {
|
|
12
|
-
theme?: 'light' | 'dark';
|
|
13
|
-
initialTheme?: typeof lightTheme;
|
|
14
|
-
} = {},
|
|
15
|
-
) {
|
|
16
|
-
const {theme = 'light', initialTheme} = options;
|
|
17
|
-
|
|
18
|
-
const Wrapper = ({children}: {children: ReactElement}) => (
|
|
19
|
-
<CpkProvider>{children}</CpkProvider>
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
return render(ui, {wrapper: Wrapper});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Test helper for checking accessibility properties
|
|
27
|
-
*/
|
|
28
|
-
export function expectAccessibilityProps(
|
|
29
|
-
element: any,
|
|
30
|
-
expectedProps: {
|
|
31
|
-
role?: string;
|
|
32
|
-
label?: string;
|
|
33
|
-
hint?: string;
|
|
34
|
-
state?: Record<string, any>;
|
|
35
|
-
},
|
|
36
|
-
) {
|
|
37
|
-
const {role, label, hint, state} = expectedProps;
|
|
38
|
-
|
|
39
|
-
if (role) {
|
|
40
|
-
expect(element.props.accessibilityRole).toBe(role);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (label) {
|
|
44
|
-
expect(element.props.accessibilityLabel).toBe(label);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (hint) {
|
|
48
|
-
expect(element.props.accessibilityHint).toBe(hint);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (state) {
|
|
52
|
-
expect(element.props.accessibilityState).toEqual(
|
|
53
|
-
expect.objectContaining(state),
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Test helper for animation testing
|
|
60
|
-
*/
|
|
61
|
-
export async function waitForAnimation(duration: number = 300) {
|
|
62
|
-
await waitFor(() => {}, {timeout: duration + 100});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Test helper for press events with different delays
|
|
67
|
-
*/
|
|
68
|
-
export async function pressWithDelay(
|
|
69
|
-
element: any,
|
|
70
|
-
delay: number = 0,
|
|
71
|
-
): Promise<void> {
|
|
72
|
-
fireEvent.press(element);
|
|
73
|
-
if (delay > 0) {
|
|
74
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Mock platform for testing
|
|
80
|
-
*/
|
|
81
|
-
export function mockPlatform(platform: 'ios' | 'android' | 'web') {
|
|
82
|
-
const originalPlatform = require('react-native').Platform.OS;
|
|
83
|
-
|
|
84
|
-
beforeEach(() => {
|
|
85
|
-
require('react-native').Platform.OS = platform;
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
afterEach(() => {
|
|
89
|
-
require('react-native').Platform.OS = originalPlatform;
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Test performance of component renders
|
|
95
|
-
*/
|
|
96
|
-
export function measureRenderTime(renderFn: () => void): number {
|
|
97
|
-
const startTime = performance.now();
|
|
98
|
-
renderFn();
|
|
99
|
-
const endTime = performance.now();
|
|
100
|
-
return endTime - startTime;
|
|
101
|
-
}
|
package/src/types/common.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type {StyleProp, ViewStyle, TextStyle} from 'react-native';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Common size types used across components
|
|
5
|
-
*/
|
|
6
|
-
export type ComponentSize = 'small' | 'medium' | 'large';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Common variant types for styled components
|
|
10
|
-
*/
|
|
11
|
-
export type ComponentVariant =
|
|
12
|
-
| 'primary'
|
|
13
|
-
| 'secondary'
|
|
14
|
-
| 'success'
|
|
15
|
-
| 'danger'
|
|
16
|
-
| 'warning'
|
|
17
|
-
| 'info'
|
|
18
|
-
| 'light'
|
|
19
|
-
| 'dark';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Position types for various components
|
|
23
|
-
*/
|
|
24
|
-
export type Position = 'left' | 'right' | 'top' | 'bottom' | 'center';
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Common styles interface that most components should accept
|
|
28
|
-
*/
|
|
29
|
-
export interface BaseStyles {
|
|
30
|
-
container?: StyleProp<ViewStyle>;
|
|
31
|
-
content?: StyleProp<ViewStyle>;
|
|
32
|
-
text?: StyleProp<TextStyle>;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Base props that most UI components should accept
|
|
37
|
-
*/
|
|
38
|
-
export interface BaseComponentProps {
|
|
39
|
-
testID?: string;
|
|
40
|
-
style?: StyleProp<ViewStyle>;
|
|
41
|
-
disabled?: boolean;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Props for components that can be pressed
|
|
46
|
-
*/
|
|
47
|
-
export interface PressableComponentProps extends BaseComponentProps {
|
|
48
|
-
onPress?: () => void;
|
|
49
|
-
activeOpacity?: number;
|
|
50
|
-
disabled?: boolean;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Animation configuration interface
|
|
55
|
-
*/
|
|
56
|
-
export interface AnimationOptions {
|
|
57
|
-
duration?: number;
|
|
58
|
-
delay?: number;
|
|
59
|
-
useNativeDriver?: boolean;
|
|
60
|
-
easing?: (value: number) => number;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Accessibility props interface
|
|
65
|
-
*/
|
|
66
|
-
export interface AccessibilityProps {
|
|
67
|
-
accessibilityLabel?: string;
|
|
68
|
-
accessibilityHint?: string;
|
|
69
|
-
accessibilityRole?: string;
|
|
70
|
-
accessibilityState?: {
|
|
71
|
-
disabled?: boolean;
|
|
72
|
-
selected?: boolean;
|
|
73
|
-
checked?: boolean | 'mixed';
|
|
74
|
-
busy?: boolean;
|
|
75
|
-
expanded?: boolean;
|
|
76
|
-
};
|
|
77
|
-
}
|
package/src/types/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './common';
|