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,75 +0,0 @@
|
|
|
1
|
-
import React, {Component, ReactNode} from 'react';
|
|
2
|
-
import {View, Text} from 'react-native';
|
|
3
|
-
import type {StyleProp, ViewStyle, TextStyle} from 'react-native';
|
|
4
|
-
|
|
5
|
-
interface Props {
|
|
6
|
-
children: ReactNode;
|
|
7
|
-
fallback?: ReactNode;
|
|
8
|
-
onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
|
|
9
|
-
style?: StyleProp<ViewStyle>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface State {
|
|
13
|
-
hasError: boolean;
|
|
14
|
-
error?: Error;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class ErrorBoundary extends Component<Props, State> {
|
|
18
|
-
constructor(props: Props) {
|
|
19
|
-
super(props);
|
|
20
|
-
this.state = {hasError: false};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
static getDerivedStateFromError(error: Error): State {
|
|
24
|
-
return {hasError: true, error};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
|
|
28
|
-
this.props.onError?.(error, errorInfo);
|
|
29
|
-
|
|
30
|
-
// Log error in development
|
|
31
|
-
if (__DEV__) {
|
|
32
|
-
console.error('ErrorBoundary caught an error:', error, errorInfo);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
render() {
|
|
37
|
-
if (this.state.hasError) {
|
|
38
|
-
if (this.props.fallback) {
|
|
39
|
-
return this.props.fallback;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
<View style={[defaultErrorStyle.container, this.props.style]}>
|
|
44
|
-
<Text style={defaultErrorStyle.title}>Something went wrong</Text>
|
|
45
|
-
<Text style={defaultErrorStyle.message}>
|
|
46
|
-
{this.state.error?.message || 'An unexpected error occurred'}
|
|
47
|
-
</Text>
|
|
48
|
-
</View>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return this.props.children;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const defaultErrorStyle = {
|
|
57
|
-
container: {
|
|
58
|
-
flex: 1,
|
|
59
|
-
justifyContent: 'center' as const,
|
|
60
|
-
alignItems: 'center' as const,
|
|
61
|
-
padding: 20,
|
|
62
|
-
backgroundColor: '#f8f9fa',
|
|
63
|
-
},
|
|
64
|
-
title: {
|
|
65
|
-
fontSize: 18,
|
|
66
|
-
fontWeight: 'bold' as const,
|
|
67
|
-
color: '#dc3545',
|
|
68
|
-
marginBottom: 8,
|
|
69
|
-
},
|
|
70
|
-
message: {
|
|
71
|
-
fontSize: 14,
|
|
72
|
-
color: '#6c757d',
|
|
73
|
-
textAlign: 'center' as const,
|
|
74
|
-
},
|
|
75
|
-
} satisfies Record<string, StyleProp<ViewStyle | TextStyle>>;
|
|
@@ -1,216 +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
|
-
|
|
7
|
-
import {withThemeProvider} from '../../../../.storybook/decorators';
|
|
8
|
-
import {useCPK} from '../../../providers';
|
|
9
|
-
import {Typography} from '../../uis/Typography/Typography';
|
|
10
|
-
import {Button} from '../../uis/Button/Button';
|
|
11
|
-
import AlertDialog, {type AlertDialogSizeType} from './AlertDialog';
|
|
12
|
-
|
|
13
|
-
const Container = styled(SafeAreaView)`
|
|
14
|
-
flex-direction: column;
|
|
15
|
-
padding: 48px 24px;
|
|
16
|
-
align-self: stretch;
|
|
17
|
-
justify-content: center;
|
|
18
|
-
align-items: center;
|
|
19
|
-
`;
|
|
20
|
-
|
|
21
|
-
type AlertDialogBasicStoryProps = {
|
|
22
|
-
size: AlertDialogSizeType;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
function AlertDialogBasicStory({size}: AlertDialogBasicStoryProps): ReactElement {
|
|
26
|
-
const {alertDialog} = useCPK();
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<Container>
|
|
30
|
-
<Typography.Title>AlertDialog</Typography.Title>
|
|
31
|
-
<Button
|
|
32
|
-
color="primary"
|
|
33
|
-
onPress={() =>
|
|
34
|
-
alertDialog.open({
|
|
35
|
-
title: 'Hello there!',
|
|
36
|
-
body: 'This is an alert dialog.',
|
|
37
|
-
size,
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
style={{marginTop: 60, width: 200}}
|
|
41
|
-
text="Dialog"
|
|
42
|
-
/>
|
|
43
|
-
<Button
|
|
44
|
-
color="primary"
|
|
45
|
-
onPress={() =>
|
|
46
|
-
alertDialog.open({
|
|
47
|
-
title: 'Hello there!',
|
|
48
|
-
body: 'This is an alert dialog.',
|
|
49
|
-
size,
|
|
50
|
-
actions: [
|
|
51
|
-
<Button
|
|
52
|
-
color="light"
|
|
53
|
-
key="button-cancel"
|
|
54
|
-
onPress={() => alertDialog.close()}
|
|
55
|
-
text="Cancel"
|
|
56
|
-
/>,
|
|
57
|
-
<Button
|
|
58
|
-
key="button-ok"
|
|
59
|
-
onPress={() => alertDialog.close()}
|
|
60
|
-
text="OK"
|
|
61
|
-
/>,
|
|
62
|
-
],
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
style={{marginTop: 20, width: 200}}
|
|
66
|
-
text="With actions"
|
|
67
|
-
/>
|
|
68
|
-
</Container>
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const meta = {
|
|
73
|
-
title: 'AlertDialog',
|
|
74
|
-
component: AlertDialogBasicStory,
|
|
75
|
-
parameters: {
|
|
76
|
-
notes: `
|
|
77
|
-
A modal dialog component for displaying important information or requiring user confirmation.
|
|
78
|
-
|
|
79
|
-
## Features
|
|
80
|
-
- **Flexible Sizing**: Preset sizes (small, medium, large) and custom numeric values
|
|
81
|
-
- **Customizable Actions**: Support for multiple action buttons
|
|
82
|
-
- **Backdrop Control**: Configurable backdrop opacity and outside click behavior
|
|
83
|
-
- **Close Button**: Optional close button in the header
|
|
84
|
-
- **Custom Content**: Support for custom title and body elements
|
|
85
|
-
- **Accessibility**: Built-in accessibility support with proper roles and labels
|
|
86
|
-
|
|
87
|
-
## Size Options
|
|
88
|
-
- \`small\`: 14px title, 12px body, 16px icon
|
|
89
|
-
- \`medium\`: 16px title, 14px body, 18px icon (default)
|
|
90
|
-
- \`large\`: 18px title, 16px body, 20px icon
|
|
91
|
-
- Custom number: Custom font size in pixels with proportional spacing
|
|
92
|
-
|
|
93
|
-
## Usage
|
|
94
|
-
\`\`\`tsx
|
|
95
|
-
const {alertDialog} = useCPK();
|
|
96
|
-
|
|
97
|
-
alertDialog.open({
|
|
98
|
-
title: 'Confirm Action',
|
|
99
|
-
body: 'Are you sure you want to proceed?',
|
|
100
|
-
size: 'medium',
|
|
101
|
-
actions: [
|
|
102
|
-
<Button text="Cancel" onPress={() => alertDialog.close()} />,
|
|
103
|
-
<Button text="Confirm" onPress={handleConfirm} />
|
|
104
|
-
]
|
|
105
|
-
});
|
|
106
|
-
\`\`\`
|
|
107
|
-
|
|
108
|
-
### Basic Dialog
|
|
109
|
-
\`\`\`tsx
|
|
110
|
-
alertDialog.open({
|
|
111
|
-
title: 'Hello',
|
|
112
|
-
body: 'This is a basic alert dialog.',
|
|
113
|
-
size: 'medium',
|
|
114
|
-
});
|
|
115
|
-
\`\`\`
|
|
116
|
-
|
|
117
|
-
### With Custom Actions
|
|
118
|
-
\`\`\`tsx
|
|
119
|
-
alertDialog.open({
|
|
120
|
-
title: 'Delete Item',
|
|
121
|
-
body: 'This action cannot be undone.',
|
|
122
|
-
size: 'large',
|
|
123
|
-
actions: [
|
|
124
|
-
<Button color="light" text="Cancel" onPress={() => alertDialog.close()} />,
|
|
125
|
-
<Button color="danger" text="Delete" onPress={handleDelete} />
|
|
126
|
-
],
|
|
127
|
-
showCloseButton: false
|
|
128
|
-
});
|
|
129
|
-
\`\`\`
|
|
130
|
-
`,
|
|
131
|
-
docs: {
|
|
132
|
-
description: {
|
|
133
|
-
component: `
|
|
134
|
-
A modal dialog component for displaying important information or requiring user confirmation.
|
|
135
|
-
|
|
136
|
-
## Features
|
|
137
|
-
- **Flexible Sizing**: Preset sizes (small, medium, large) and custom numeric values
|
|
138
|
-
- **Customizable Actions**: Support for multiple action buttons
|
|
139
|
-
- **Backdrop Control**: Configurable backdrop opacity and outside click behavior
|
|
140
|
-
- **Close Button**: Optional close button in the header
|
|
141
|
-
- **Custom Content**: Support for custom title and body elements
|
|
142
|
-
- **Accessibility**: Built-in accessibility support with proper roles and labels
|
|
143
|
-
|
|
144
|
-
## Size Options
|
|
145
|
-
- \`small\`: 14px title, 12px body, 16px icon
|
|
146
|
-
- \`medium\`: 16px title, 14px body, 18px icon (default)
|
|
147
|
-
- \`large\`: 18px title, 16px body, 20px icon
|
|
148
|
-
- Custom number: Custom font size in pixels with proportional spacing
|
|
149
|
-
|
|
150
|
-
## Usage
|
|
151
|
-
\`\`\`tsx
|
|
152
|
-
const {alertDialog} = useCPK();
|
|
153
|
-
|
|
154
|
-
alertDialog.open({
|
|
155
|
-
title: 'Confirm Action',
|
|
156
|
-
body: 'Are you sure you want to proceed?',
|
|
157
|
-
size: 'medium',
|
|
158
|
-
actions: [
|
|
159
|
-
<Button text="Cancel" onPress={() => alertDialog.close()} />,
|
|
160
|
-
<Button text="Confirm" onPress={handleConfirm} />
|
|
161
|
-
]
|
|
162
|
-
});
|
|
163
|
-
\`\`\`
|
|
164
|
-
|
|
165
|
-
### Basic Dialog
|
|
166
|
-
\`\`\`tsx
|
|
167
|
-
alertDialog.open({
|
|
168
|
-
title: 'Hello',
|
|
169
|
-
body: 'This is a basic alert dialog.',
|
|
170
|
-
size: 'medium',
|
|
171
|
-
});
|
|
172
|
-
\`\`\`
|
|
173
|
-
|
|
174
|
-
### With Custom Actions
|
|
175
|
-
\`\`\`tsx
|
|
176
|
-
alertDialog.open({
|
|
177
|
-
title: 'Delete Item',
|
|
178
|
-
body: 'This action cannot be undone.',
|
|
179
|
-
size: 'large',
|
|
180
|
-
actions: [
|
|
181
|
-
<Button color="light" text="Cancel" onPress={() => alertDialog.close()} />,
|
|
182
|
-
<Button color="danger" text="Delete" onPress={handleDelete} />
|
|
183
|
-
],
|
|
184
|
-
showCloseButton: false
|
|
185
|
-
});
|
|
186
|
-
\`\`\`
|
|
187
|
-
`,
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
argTypes: {
|
|
192
|
-
size: {
|
|
193
|
-
control: 'radio',
|
|
194
|
-
options: ['small', 'medium', 'large', 14, 16, 18, 20],
|
|
195
|
-
description: 'Dialog size: "small" (14px title), "medium" (16px title), "large" (18px title), or custom number in pixels',
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
decorators: [withThemeProvider],
|
|
199
|
-
} satisfies Meta<typeof AlertDialogBasicStory>;
|
|
200
|
-
|
|
201
|
-
export default meta;
|
|
202
|
-
|
|
203
|
-
type Story = StoryObj<typeof meta>;
|
|
204
|
-
|
|
205
|
-
export const Basic: Story = {
|
|
206
|
-
args: {
|
|
207
|
-
size: 'medium',
|
|
208
|
-
},
|
|
209
|
-
argTypes: {
|
|
210
|
-
// @ts-expect-error - theme is for storybook control
|
|
211
|
-
theme: {
|
|
212
|
-
control: 'select',
|
|
213
|
-
options: ['light', 'dark'],
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
};
|
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-native/extend-expect';
|
|
2
|
-
|
|
3
|
-
import React, {type ReactElement, useRef} from 'react';
|
|
4
|
-
import type {RenderAPI} from '@testing-library/react-native';
|
|
5
|
-
import {render, waitFor} from '@testing-library/react-native';
|
|
6
|
-
|
|
7
|
-
import {createComponent} from '../../../../test/testUtils';
|
|
8
|
-
import AlertDialog, {type AlertDialogContext} from './AlertDialog';
|
|
9
|
-
import {ThemeType} from '../../../providers/ThemeProvider';
|
|
10
|
-
|
|
11
|
-
let testingLib: RenderAPI;
|
|
12
|
-
|
|
13
|
-
const TestComponent = ({
|
|
14
|
-
themeType,
|
|
15
|
-
}: {
|
|
16
|
-
themeType?: ThemeType;
|
|
17
|
-
}): ReactElement => {
|
|
18
|
-
const alertDialogRef = useRef<AlertDialogContext>(null);
|
|
19
|
-
|
|
20
|
-
return createComponent(<AlertDialog ref={alertDialogRef} />, themeType);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
describe('[AlertDialog]', () => {
|
|
24
|
-
it('should render without crashing', () => {
|
|
25
|
-
testingLib = render(<TestComponent />);
|
|
26
|
-
|
|
27
|
-
const json = testingLib.toJSON();
|
|
28
|
-
expect(json).toBeTruthy();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('Size prop', () => {
|
|
32
|
-
it('should accept small size', async () => {
|
|
33
|
-
const TestWithSize = (): ReactElement => {
|
|
34
|
-
const alertDialogRef = useRef<AlertDialogContext>(null);
|
|
35
|
-
|
|
36
|
-
React.useEffect(() => {
|
|
37
|
-
alertDialogRef.current?.open({
|
|
38
|
-
title: 'Test Title',
|
|
39
|
-
body: 'Test Body',
|
|
40
|
-
size: 'small',
|
|
41
|
-
});
|
|
42
|
-
}, []);
|
|
43
|
-
|
|
44
|
-
return createComponent(<AlertDialog ref={alertDialogRef} />);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
testingLib = render(<TestWithSize />);
|
|
48
|
-
|
|
49
|
-
await waitFor(() => {
|
|
50
|
-
expect(testingLib.getByText('Test Title')).toBeTruthy();
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should accept medium size', async () => {
|
|
55
|
-
const TestWithSize = (): ReactElement => {
|
|
56
|
-
const alertDialogRef = useRef<AlertDialogContext>(null);
|
|
57
|
-
|
|
58
|
-
React.useEffect(() => {
|
|
59
|
-
alertDialogRef.current?.open({
|
|
60
|
-
title: 'Test Title',
|
|
61
|
-
body: 'Test Body',
|
|
62
|
-
size: 'medium',
|
|
63
|
-
});
|
|
64
|
-
}, []);
|
|
65
|
-
|
|
66
|
-
return createComponent(<AlertDialog ref={alertDialogRef} />);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
testingLib = render(<TestWithSize />);
|
|
70
|
-
|
|
71
|
-
await waitFor(() => {
|
|
72
|
-
expect(testingLib.getByText('Test Title')).toBeTruthy();
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should accept large size', async () => {
|
|
77
|
-
const TestWithSize = (): ReactElement => {
|
|
78
|
-
const alertDialogRef = useRef<AlertDialogContext>(null);
|
|
79
|
-
|
|
80
|
-
React.useEffect(() => {
|
|
81
|
-
alertDialogRef.current?.open({
|
|
82
|
-
title: 'Test Title',
|
|
83
|
-
body: 'Test Body',
|
|
84
|
-
size: 'large',
|
|
85
|
-
});
|
|
86
|
-
}, []);
|
|
87
|
-
|
|
88
|
-
return createComponent(<AlertDialog ref={alertDialogRef} />);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
testingLib = render(<TestWithSize />);
|
|
92
|
-
|
|
93
|
-
await waitFor(() => {
|
|
94
|
-
expect(testingLib.getByText('Test Title')).toBeTruthy();
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('should accept custom numeric size', async () => {
|
|
99
|
-
const TestWithSize = (): ReactElement => {
|
|
100
|
-
const alertDialogRef = useRef<AlertDialogContext>(null);
|
|
101
|
-
|
|
102
|
-
React.useEffect(() => {
|
|
103
|
-
alertDialogRef.current?.open({
|
|
104
|
-
title: 'Test Title',
|
|
105
|
-
body: 'Test Body',
|
|
106
|
-
size: 20,
|
|
107
|
-
});
|
|
108
|
-
}, []);
|
|
109
|
-
|
|
110
|
-
return createComponent(<AlertDialog ref={alertDialogRef} />);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
testingLib = render(<TestWithSize />);
|
|
114
|
-
|
|
115
|
-
await waitFor(() => {
|
|
116
|
-
expect(testingLib.getByText('Test Title')).toBeTruthy();
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('should default to medium size when size is not specified', async () => {
|
|
121
|
-
const TestWithoutSize = (): ReactElement => {
|
|
122
|
-
const alertDialogRef = useRef<AlertDialogContext>(null);
|
|
123
|
-
|
|
124
|
-
React.useEffect(() => {
|
|
125
|
-
alertDialogRef.current?.open({
|
|
126
|
-
title: 'Test Title',
|
|
127
|
-
body: 'Test Body',
|
|
128
|
-
});
|
|
129
|
-
}, []);
|
|
130
|
-
|
|
131
|
-
return createComponent(<AlertDialog ref={alertDialogRef} />);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
testingLib = render(<TestWithoutSize />);
|
|
135
|
-
|
|
136
|
-
await waitFor(() => {
|
|
137
|
-
expect(testingLib.getByText('Test Title')).toBeTruthy();
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
describe('Content rendering', () => {
|
|
143
|
-
it('should render title and body', async () => {
|
|
144
|
-
const TestWithContent = (): ReactElement => {
|
|
145
|
-
const alertDialogRef = useRef<AlertDialogContext>(null);
|
|
146
|
-
|
|
147
|
-
React.useEffect(() => {
|
|
148
|
-
alertDialogRef.current?.open({
|
|
149
|
-
title: 'Alert Title',
|
|
150
|
-
body: 'Alert Body Content',
|
|
151
|
-
size: 'medium',
|
|
152
|
-
});
|
|
153
|
-
}, []);
|
|
154
|
-
|
|
155
|
-
return createComponent(<AlertDialog ref={alertDialogRef} />);
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
testingLib = render(<TestWithContent />);
|
|
159
|
-
|
|
160
|
-
await waitFor(() => {
|
|
161
|
-
expect(testingLib.getByText('Alert Title')).toBeTruthy();
|
|
162
|
-
expect(testingLib.getByText('Alert Body Content')).toBeTruthy();
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('should render with actions', async () => {
|
|
167
|
-
const TestWithActions = (): ReactElement => {
|
|
168
|
-
const alertDialogRef = useRef<AlertDialogContext>(null);
|
|
169
|
-
|
|
170
|
-
React.useEffect(() => {
|
|
171
|
-
alertDialogRef.current?.open({
|
|
172
|
-
title: 'Confirm',
|
|
173
|
-
body: 'Are you sure?',
|
|
174
|
-
size: 'medium',
|
|
175
|
-
actions: [
|
|
176
|
-
<button key="cancel">Cancel</button>,
|
|
177
|
-
<button key="ok">OK</button>,
|
|
178
|
-
],
|
|
179
|
-
});
|
|
180
|
-
}, []);
|
|
181
|
-
|
|
182
|
-
return createComponent(<AlertDialog ref={alertDialogRef} />);
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
testingLib = render(<TestWithActions />);
|
|
186
|
-
|
|
187
|
-
await waitFor(() => {
|
|
188
|
-
expect(testingLib.getByText('Confirm')).toBeTruthy();
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
describe('Close functionality', () => {
|
|
194
|
-
it('should close dialog when close is called', async () => {
|
|
195
|
-
const TestWithClose = (): ReactElement => {
|
|
196
|
-
const alertDialogRef = useRef<AlertDialogContext>(null);
|
|
197
|
-
|
|
198
|
-
React.useEffect(() => {
|
|
199
|
-
alertDialogRef.current?.open({
|
|
200
|
-
title: 'Test Title',
|
|
201
|
-
body: 'Test Body',
|
|
202
|
-
size: 'medium',
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
setTimeout(() => {
|
|
206
|
-
alertDialogRef.current?.close();
|
|
207
|
-
}, 100);
|
|
208
|
-
}, []);
|
|
209
|
-
|
|
210
|
-
return createComponent(<AlertDialog ref={alertDialogRef} />);
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
testingLib = render(<TestWithClose />);
|
|
214
|
-
|
|
215
|
-
await waitFor(() => {
|
|
216
|
-
expect(testingLib.getByText('Test Title')).toBeTruthy();
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
await waitFor(
|
|
220
|
-
() => {
|
|
221
|
-
expect(testingLib.queryByText('Test Title')).toBeNull();
|
|
222
|
-
},
|
|
223
|
-
{timeout: 500},
|
|
224
|
-
);
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
describe('Dark mode', () => {
|
|
229
|
-
it('should render in dark mode', async () => {
|
|
230
|
-
const TestDarkMode = (): ReactElement => {
|
|
231
|
-
const alertDialogRef = useRef<AlertDialogContext>(null);
|
|
232
|
-
|
|
233
|
-
React.useEffect(() => {
|
|
234
|
-
alertDialogRef.current?.open({
|
|
235
|
-
title: 'Dark Mode Title',
|
|
236
|
-
body: 'Dark Mode Body',
|
|
237
|
-
size: 'medium',
|
|
238
|
-
});
|
|
239
|
-
}, []);
|
|
240
|
-
|
|
241
|
-
return createComponent(<AlertDialog ref={alertDialogRef} />, 'dark');
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
testingLib = render(<TestDarkMode />);
|
|
245
|
-
|
|
246
|
-
await waitFor(() => {
|
|
247
|
-
expect(testingLib.getByText('Dark Mode Title')).toBeTruthy();
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
});
|