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,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';
|
package/src/types/kstyled.d.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import type {AccessibilityProps} from '../types/common';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Generate accessibility props for button-like components
|
|
5
|
-
*/
|
|
6
|
-
export function getButtonAccessibilityProps(
|
|
7
|
-
label: string,
|
|
8
|
-
disabled?: boolean,
|
|
9
|
-
pressed?: boolean,
|
|
10
|
-
): AccessibilityProps {
|
|
11
|
-
return {
|
|
12
|
-
accessibilityRole: 'button',
|
|
13
|
-
accessibilityLabel: label,
|
|
14
|
-
accessibilityState: {
|
|
15
|
-
disabled: disabled ?? false,
|
|
16
|
-
...(pressed !== undefined && {selected: pressed}),
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Generate accessibility props for checkbox components
|
|
23
|
-
*/
|
|
24
|
-
export function getCheckboxAccessibilityProps(
|
|
25
|
-
label: string,
|
|
26
|
-
checked: boolean,
|
|
27
|
-
disabled?: boolean,
|
|
28
|
-
): AccessibilityProps {
|
|
29
|
-
return {
|
|
30
|
-
accessibilityRole: 'checkbox',
|
|
31
|
-
accessibilityLabel: label,
|
|
32
|
-
accessibilityState: {
|
|
33
|
-
checked,
|
|
34
|
-
disabled: disabled ?? false,
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Generate accessibility props for radio button components
|
|
41
|
-
*/
|
|
42
|
-
export function getRadioAccessibilityProps(
|
|
43
|
-
label: string,
|
|
44
|
-
selected: boolean,
|
|
45
|
-
disabled?: boolean,
|
|
46
|
-
): AccessibilityProps {
|
|
47
|
-
return {
|
|
48
|
-
accessibilityRole: 'radio',
|
|
49
|
-
accessibilityLabel: label,
|
|
50
|
-
accessibilityState: {
|
|
51
|
-
selected,
|
|
52
|
-
disabled: disabled ?? false,
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Generate accessibility props for text input components
|
|
59
|
-
*/
|
|
60
|
-
export function getTextInputAccessibilityProps(
|
|
61
|
-
label: string,
|
|
62
|
-
placeholder?: string,
|
|
63
|
-
required?: boolean,
|
|
64
|
-
invalid?: boolean,
|
|
65
|
-
): AccessibilityProps {
|
|
66
|
-
return {
|
|
67
|
-
accessibilityRole: 'text',
|
|
68
|
-
accessibilityLabel: label,
|
|
69
|
-
accessibilityHint: placeholder,
|
|
70
|
-
accessibilityState: {
|
|
71
|
-
...(required && {busy: true}),
|
|
72
|
-
...(invalid && {selected: false}),
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Generate accessibility props for switch/toggle components
|
|
79
|
-
*/
|
|
80
|
-
export function getSwitchAccessibilityProps(
|
|
81
|
-
label: string,
|
|
82
|
-
value: boolean,
|
|
83
|
-
disabled?: boolean,
|
|
84
|
-
): AccessibilityProps {
|
|
85
|
-
return {
|
|
86
|
-
accessibilityRole: 'switch',
|
|
87
|
-
accessibilityLabel: label,
|
|
88
|
-
accessibilityState: {
|
|
89
|
-
checked: value,
|
|
90
|
-
disabled: disabled ?? false,
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Generate accessibility props for expandable components (like Accordion)
|
|
97
|
-
*/
|
|
98
|
-
export function getExpandableAccessibilityProps(
|
|
99
|
-
label: string,
|
|
100
|
-
expanded: boolean,
|
|
101
|
-
): AccessibilityProps {
|
|
102
|
-
return {
|
|
103
|
-
accessibilityRole: 'button',
|
|
104
|
-
accessibilityLabel: label,
|
|
105
|
-
accessibilityState: {
|
|
106
|
-
expanded,
|
|
107
|
-
},
|
|
108
|
-
accessibilityHint: expanded ? 'Double tap to collapse' : 'Double tap to expand',
|
|
109
|
-
};
|
|
110
|
-
}
|