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,48 +0,0 @@
|
|
|
1
|
-
import React, {useMemo, type ReactElement} from 'react';
|
|
2
|
-
import type {PressableProps, StyleProp, ViewStyle} from 'react-native';
|
|
3
|
-
import {Pressable} from 'react-native';
|
|
4
|
-
import {css} from 'kstyled';
|
|
5
|
-
import {useCPK} from '../../../providers';
|
|
6
|
-
|
|
7
|
-
const DEFAULT_HIT_SLOP = {top: 4, bottom: 4, left: 6, right: 6};
|
|
8
|
-
|
|
9
|
-
function CustomPressable(
|
|
10
|
-
props: PressableProps & {style?: StyleProp<ViewStyle>},
|
|
11
|
-
): ReactElement {
|
|
12
|
-
const {children, style, hitSlop, ...restProps} = props;
|
|
13
|
-
const {theme} = useCPK();
|
|
14
|
-
|
|
15
|
-
const effectiveHitSlop = useMemo(() =>
|
|
16
|
-
hitSlop || DEFAULT_HIT_SLOP,
|
|
17
|
-
[hitSlop]
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
const styleFunction = useMemo(
|
|
21
|
-
() => ({pressed}: {pressed: boolean}) => {
|
|
22
|
-
if (pressed) {
|
|
23
|
-
return [
|
|
24
|
-
css`
|
|
25
|
-
background-color: ${theme.role.underlay};
|
|
26
|
-
`,
|
|
27
|
-
style,
|
|
28
|
-
];
|
|
29
|
-
}
|
|
30
|
-
return style;
|
|
31
|
-
},
|
|
32
|
-
[theme.role.underlay, style]
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<Pressable
|
|
37
|
-
hitSlop={effectiveHitSlop}
|
|
38
|
-
style={styleFunction}
|
|
39
|
-
{...restProps}
|
|
40
|
-
>
|
|
41
|
-
{children}
|
|
42
|
-
</Pressable>
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Export memoized component for better performance
|
|
47
|
-
export default React.memo(CustomPressable) as typeof CustomPressable;
|
|
48
|
-
export {CustomPressable};
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import type {ComponentProps} from 'react';
|
|
2
|
-
import type {Meta, StoryObj} from '@storybook/react';
|
|
3
|
-
import {withThemeProvider} from '../../../../.storybook/decorators';
|
|
4
|
-
import {EditText} from './EditText';
|
|
5
|
-
|
|
6
|
-
const EDITTEXT_DOCS = `
|
|
7
|
-
A flexible text input component with various styling and validation options.
|
|
8
|
-
|
|
9
|
-
## Features
|
|
10
|
-
- **Flexible Sizing**: Preset sizes and custom numeric values
|
|
11
|
-
- **Two Decoration Styles**: Underline or boxed input styles
|
|
12
|
-
- **Layout Directions**: Row or column layout for label and input
|
|
13
|
-
- **Validation Support**: Built-in error message display
|
|
14
|
-
- **Character Counter**: Optional character counter with maxLength support
|
|
15
|
-
- **Multiline Support**: Can be used as a textarea
|
|
16
|
-
- **Secure Text Entry**: Password input support
|
|
17
|
-
- **Status States**: Visual feedback for focused, hovered, error, and disabled states
|
|
18
|
-
- **Custom Elements**: Support for left and right elements/icons
|
|
19
|
-
|
|
20
|
-
## Decoration Options
|
|
21
|
-
- \`underline\`: Bottom border style (default)
|
|
22
|
-
- \`boxed\`: Full border box style
|
|
23
|
-
|
|
24
|
-
## Direction Options
|
|
25
|
-
- \`row\`: Label and input side by side
|
|
26
|
-
- \`column\`: Label above input (default)
|
|
27
|
-
|
|
28
|
-
## Size Options
|
|
29
|
-
- \`small\`: 14px font size with proportional padding
|
|
30
|
-
- \`medium\`: 16px font size with proportional padding (default)
|
|
31
|
-
- \`large\`: 18px font size with proportional padding
|
|
32
|
-
- Custom number: Custom font size in pixels with proportional padding
|
|
33
|
-
|
|
34
|
-
## Usage
|
|
35
|
-
\`\`\`tsx
|
|
36
|
-
<EditText
|
|
37
|
-
label="Email"
|
|
38
|
-
placeholder="Enter your email"
|
|
39
|
-
value={email}
|
|
40
|
-
onChangeText={setEmail}
|
|
41
|
-
size="medium"
|
|
42
|
-
decoration="boxed"
|
|
43
|
-
direction="column"
|
|
44
|
-
required
|
|
45
|
-
/>
|
|
46
|
-
\`\`\`
|
|
47
|
-
|
|
48
|
-
### With Validation
|
|
49
|
-
\`\`\`tsx
|
|
50
|
-
<EditText
|
|
51
|
-
label="Password"
|
|
52
|
-
placeholder="Enter password"
|
|
53
|
-
value={password}
|
|
54
|
-
onChangeText={setPassword}
|
|
55
|
-
secureTextEntry
|
|
56
|
-
error={passwordError}
|
|
57
|
-
maxLength={20}
|
|
58
|
-
/>
|
|
59
|
-
\`\`\`
|
|
60
|
-
`;
|
|
61
|
-
|
|
62
|
-
const meta = {
|
|
63
|
-
title: 'EditText',
|
|
64
|
-
component: (props) => <EditText {...props} />,
|
|
65
|
-
parameters: {
|
|
66
|
-
notes: EDITTEXT_DOCS,
|
|
67
|
-
docs: {
|
|
68
|
-
description: {
|
|
69
|
-
component: EDITTEXT_DOCS,
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
argTypes: {
|
|
74
|
-
size: {
|
|
75
|
-
control: 'radio',
|
|
76
|
-
options: ['small', 'medium', 'large', 14, 16, 18, 20],
|
|
77
|
-
description: 'Input size: "small" (14px), "medium" (16px), "large" (18px), or custom number in pixels',
|
|
78
|
-
},
|
|
79
|
-
required: {type: 'boolean', description: 'Shows required indicator'},
|
|
80
|
-
label: {type: 'string', description: 'Label text for the input'},
|
|
81
|
-
error: {type: 'string', description: 'Error message to display'},
|
|
82
|
-
value: {type: 'string', description: 'Current input value'},
|
|
83
|
-
multiline: {type: 'boolean', description: 'Enables multiline input'},
|
|
84
|
-
placeholder: {type: 'string', description: 'Placeholder text'},
|
|
85
|
-
placeholderColor: {type: 'string', description: 'Custom placeholder color'},
|
|
86
|
-
editable: {type: 'boolean', description: 'Controls if input is editable'},
|
|
87
|
-
secureTextEntry: {type: 'boolean', description: 'Hides text for password input'},
|
|
88
|
-
numberOfLines: {type: 'number', description: 'Number of lines for multiline input'},
|
|
89
|
-
maxLength: {type: 'number', description: 'Maximum character length'},
|
|
90
|
-
hideCounter: {type: 'boolean', description: 'Hides character counter'},
|
|
91
|
-
direction: {
|
|
92
|
-
control: 'select',
|
|
93
|
-
options: ['row', 'column'],
|
|
94
|
-
description: 'Layout direction of label and input',
|
|
95
|
-
},
|
|
96
|
-
decoration: {
|
|
97
|
-
control: 'select',
|
|
98
|
-
options: ['underline', 'boxed'],
|
|
99
|
-
description: 'Visual style of the input',
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
decorators: [withThemeProvider],
|
|
103
|
-
} satisfies Meta<typeof EditText>;
|
|
104
|
-
|
|
105
|
-
export default meta;
|
|
106
|
-
|
|
107
|
-
type Story = StoryObj<typeof meta>;
|
|
108
|
-
|
|
109
|
-
export const Basic: Story = {
|
|
110
|
-
args: {
|
|
111
|
-
size: 'medium',
|
|
112
|
-
onChangeText: () => {},
|
|
113
|
-
direction: 'column',
|
|
114
|
-
decoration: 'boxed',
|
|
115
|
-
placeholder: 'Write something...',
|
|
116
|
-
editable: true,
|
|
117
|
-
},
|
|
118
|
-
argTypes: {
|
|
119
|
-
theme: {
|
|
120
|
-
control: 'select',
|
|
121
|
-
options: ['light', 'dark'],
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
};
|
|
@@ -1,477 +0,0 @@
|
|
|
1
|
-
// Mock Platform API before any imports
|
|
2
|
-
jest.mock('react-native/Libraries/Utilities/Platform', () => ({
|
|
3
|
-
OS: 'web',
|
|
4
|
-
select: (obj) => obj.web || obj.default,
|
|
5
|
-
}));
|
|
6
|
-
|
|
7
|
-
// Mock @expo/vector-icons
|
|
8
|
-
jest.mock('@expo/vector-icons', () => ({
|
|
9
|
-
AntDesign: 'AntDesign',
|
|
10
|
-
createIconSetFromIcoMoon: () => 'Icon',
|
|
11
|
-
// Add any other exports from @expo/vector-icons that you're using
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
import '@testing-library/jest-native/extend-expect';
|
|
15
|
-
|
|
16
|
-
import React, {type ReactElement} from 'react';
|
|
17
|
-
import {Text} from 'react-native';
|
|
18
|
-
import RNWebHooks from 'react-native-web-hooks';
|
|
19
|
-
import type {RenderAPI} from '@testing-library/react-native';
|
|
20
|
-
import {act, fireEvent, render} from '@testing-library/react-native';
|
|
21
|
-
|
|
22
|
-
import {createComponent} from '../../../../test/testUtils';
|
|
23
|
-
import type {EditTextProps} from './EditText';
|
|
24
|
-
import {EditText} from './EditText';
|
|
25
|
-
import {light} from '../../../utils/colors';
|
|
26
|
-
|
|
27
|
-
jest.mock('react-native-web-hooks', () => ({
|
|
28
|
-
useHover: () => false,
|
|
29
|
-
}));
|
|
30
|
-
|
|
31
|
-
let testingLib: RenderAPI;
|
|
32
|
-
|
|
33
|
-
const Component = (editProps?: EditTextProps): ReactElement =>
|
|
34
|
-
createComponent(<EditText {...editProps} />);
|
|
35
|
-
|
|
36
|
-
describe('[EditText]', () => {
|
|
37
|
-
jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
38
|
-
|
|
39
|
-
beforeAll(() => {
|
|
40
|
-
testingLib = render(Component());
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe('hovered', () => {
|
|
44
|
-
beforeAll(() => {
|
|
45
|
-
jest.spyOn(RNWebHooks, 'useHover').mockImplementation(() => true);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
describe('label', () => {
|
|
49
|
-
it('renders label text', async () => {
|
|
50
|
-
testingLib = render(Component({label: 'label text'}));
|
|
51
|
-
const label = testingLib.getByText('label text');
|
|
52
|
-
expect(label).toBeTruthy();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('renders label style', async () => {
|
|
56
|
-
testingLib = render(
|
|
57
|
-
Component({
|
|
58
|
-
label: 'label text',
|
|
59
|
-
colors: {
|
|
60
|
-
basic: 'blue',
|
|
61
|
-
placeholder: 'green',
|
|
62
|
-
disabled: 'red',
|
|
63
|
-
error: 'yellow',
|
|
64
|
-
focused: 'purple',
|
|
65
|
-
hovered: 'orange',
|
|
66
|
-
},
|
|
67
|
-
}),
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
const label = testingLib.getByText('label text');
|
|
71
|
-
|
|
72
|
-
expect(label).toHaveStyle({color: 'orange'});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('renders custom label style', async () => {
|
|
76
|
-
const renderCustomLabel = (): ReactElement => {
|
|
77
|
-
return (
|
|
78
|
-
<Text
|
|
79
|
-
style={{
|
|
80
|
-
color: 'blue',
|
|
81
|
-
fontSize: 12,
|
|
82
|
-
fontWeight: 'bold',
|
|
83
|
-
}}
|
|
84
|
-
>
|
|
85
|
-
Custom label
|
|
86
|
-
</Text>
|
|
87
|
-
);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
testingLib = render(
|
|
91
|
-
Component({
|
|
92
|
-
label: renderCustomLabel,
|
|
93
|
-
}),
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
const label = testingLib.getByText('Custom label');
|
|
97
|
-
|
|
98
|
-
expect(label).toBeTruthy();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe('unhovered', () => {
|
|
102
|
-
beforeAll(() => {
|
|
103
|
-
jest.spyOn(RNWebHooks, 'useHover').mockImplementation(() => false);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('should contain `focusColor` when focused', async () => {
|
|
107
|
-
testingLib = render(
|
|
108
|
-
Component({
|
|
109
|
-
testID: 'INPUT_TEST',
|
|
110
|
-
label: 'label text',
|
|
111
|
-
colors: {
|
|
112
|
-
basic: 'blue',
|
|
113
|
-
placeholder: 'green',
|
|
114
|
-
disabled: 'red',
|
|
115
|
-
error: 'yellow',
|
|
116
|
-
focused: 'purple',
|
|
117
|
-
hovered: 'orange',
|
|
118
|
-
},
|
|
119
|
-
}),
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
const input = testingLib.getByTestId('INPUT_TEST');
|
|
123
|
-
expect(input).toHaveStyle({color: 'green'});
|
|
124
|
-
|
|
125
|
-
act(() => {
|
|
126
|
-
input.props.onFocus();
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
const label = testingLib.getByText('label text');
|
|
130
|
-
|
|
131
|
-
expect(label).toHaveStyle({color: 'purple'});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('renders error element when provided', async () => {
|
|
135
|
-
testingLib = render(
|
|
136
|
-
Component({
|
|
137
|
-
testID: 'INPUT_TEST',
|
|
138
|
-
label: 'label text',
|
|
139
|
-
error: 'error text',
|
|
140
|
-
styles: {
|
|
141
|
-
label: {
|
|
142
|
-
color: 'green',
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
}),
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
const input = testingLib.getByTestId('INPUT_TEST');
|
|
149
|
-
|
|
150
|
-
act(() => {
|
|
151
|
-
input.props.onFocus();
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
const error = testingLib.getByText('error text');
|
|
155
|
-
expect(error).toBeTruthy();
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
describe('layout', () => {
|
|
162
|
-
it('renders [direction] row', () => {
|
|
163
|
-
testingLib = render(
|
|
164
|
-
Component({
|
|
165
|
-
testID: 'INPUT_TEST',
|
|
166
|
-
direction: 'row',
|
|
167
|
-
}),
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
const input = testingLib.getByTestId('INPUT_TEST');
|
|
171
|
-
// const container = testingLib.getByTestId('container');
|
|
172
|
-
|
|
173
|
-
expect(input).toBeTruthy();
|
|
174
|
-
// expect(container).toHaveStyle({flexDirection: 'row'});
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it('renders [decoration] boxed', () => {
|
|
178
|
-
testingLib = render(
|
|
179
|
-
Component({
|
|
180
|
-
testID: 'INPUT_TEST',
|
|
181
|
-
decoration: 'boxed',
|
|
182
|
-
}),
|
|
183
|
-
);
|
|
184
|
-
|
|
185
|
-
const input = testingLib.getByTestId('INPUT_TEST');
|
|
186
|
-
// const container = testingLib.getByTestId('container');
|
|
187
|
-
|
|
188
|
-
expect(input).toBeTruthy();
|
|
189
|
-
// expect(container).toHaveStyle({borderWidth: 1});
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
describe('start and end elements', () => {
|
|
194
|
-
it('renders start element', () => {
|
|
195
|
-
testingLib = render(
|
|
196
|
-
Component({
|
|
197
|
-
testID: 'INPUT_TEST',
|
|
198
|
-
startElement: <Text>Start</Text>,
|
|
199
|
-
}),
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
const input = testingLib.getByText('Start');
|
|
203
|
-
expect(input).toBeTruthy();
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('renders end element', () => {
|
|
207
|
-
testingLib = render(
|
|
208
|
-
Component({
|
|
209
|
-
testID: 'INPUT_TEST',
|
|
210
|
-
endElement: <Text>End</Text>,
|
|
211
|
-
}),
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
const input = testingLib.getByText('End');
|
|
215
|
-
expect(input).toBeTruthy();
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
describe('web', () => {
|
|
220
|
-
it('renders web style', () => {
|
|
221
|
-
testingLib = render(
|
|
222
|
-
Component({
|
|
223
|
-
testID: 'INPUT_TEST',
|
|
224
|
-
}),
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
const input = testingLib.getByTestId('INPUT_TEST');
|
|
228
|
-
expect(input).toBeTruthy();
|
|
229
|
-
// No need to check for outlineWidth: 0 since we handle this dynamically now
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
describe('input', () => {
|
|
234
|
-
it('should trigger text changes', () => {
|
|
235
|
-
const CHANGE_TEXT = 'content';
|
|
236
|
-
const mockedFn = jest.fn();
|
|
237
|
-
|
|
238
|
-
const onChangeTextMock = (str: string): void => {
|
|
239
|
-
mockedFn(str);
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
testingLib = render(
|
|
243
|
-
Component({
|
|
244
|
-
testID: 'INPUT_TEST',
|
|
245
|
-
editable: false,
|
|
246
|
-
onChangeText: onChangeTextMock,
|
|
247
|
-
}),
|
|
248
|
-
);
|
|
249
|
-
|
|
250
|
-
const input = testingLib.getByTestId('INPUT_TEST');
|
|
251
|
-
expect(input).toBeTruthy();
|
|
252
|
-
|
|
253
|
-
fireEvent.changeText(input, CHANGE_TEXT);
|
|
254
|
-
expect(mockedFn).toBeCalledWith(CHANGE_TEXT);
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it('should have value', () => {
|
|
258
|
-
testingLib = render(
|
|
259
|
-
Component({
|
|
260
|
-
testID: 'INPUT_TEST',
|
|
261
|
-
value: 'text123',
|
|
262
|
-
}),
|
|
263
|
-
);
|
|
264
|
-
|
|
265
|
-
const input = testingLib.getByTestId('INPUT_TEST');
|
|
266
|
-
|
|
267
|
-
expect(input).toBeTruthy();
|
|
268
|
-
|
|
269
|
-
expect(input).toHaveProp('value', 'text123');
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
it('should have render counter', () => {
|
|
273
|
-
testingLib = render(
|
|
274
|
-
Component({
|
|
275
|
-
testID: 'INPUT_TEST',
|
|
276
|
-
value: 'text123',
|
|
277
|
-
maxLength: 100,
|
|
278
|
-
}),
|
|
279
|
-
);
|
|
280
|
-
|
|
281
|
-
const counter = testingLib.getByText('7/100');
|
|
282
|
-
|
|
283
|
-
expect(counter).toBeTruthy();
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
it('should have render custom error', () => {
|
|
287
|
-
const renderCustomError = (): ReactElement => <Text>custom error</Text>;
|
|
288
|
-
|
|
289
|
-
testingLib = render(
|
|
290
|
-
Component({
|
|
291
|
-
testID: 'INPUT_TEST',
|
|
292
|
-
value: 'text123',
|
|
293
|
-
error: renderCustomError,
|
|
294
|
-
}),
|
|
295
|
-
);
|
|
296
|
-
|
|
297
|
-
const error = testingLib.getByText('custom error');
|
|
298
|
-
|
|
299
|
-
expect(error).toBeTruthy();
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
describe('disabled', () => {
|
|
304
|
-
it('renders [default] disabled style', () => {
|
|
305
|
-
testingLib = render(
|
|
306
|
-
Component({
|
|
307
|
-
testID: 'INPUT_TEST',
|
|
308
|
-
editable: false,
|
|
309
|
-
}),
|
|
310
|
-
);
|
|
311
|
-
|
|
312
|
-
const input = testingLib.getByTestId('INPUT_TEST');
|
|
313
|
-
|
|
314
|
-
expect(input).toBeTruthy();
|
|
315
|
-
|
|
316
|
-
expect(input).toHaveStyle({color: light.text.disabled});
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
it('renders [custom] disabled style', () => {
|
|
320
|
-
testingLib = render(
|
|
321
|
-
Component({
|
|
322
|
-
testID: 'INPUT_TEST',
|
|
323
|
-
colors: {disabled: 'yellow'},
|
|
324
|
-
editable: false,
|
|
325
|
-
}),
|
|
326
|
-
);
|
|
327
|
-
|
|
328
|
-
const input = testingLib.getByTestId('INPUT_TEST');
|
|
329
|
-
|
|
330
|
-
expect(input).toBeTruthy();
|
|
331
|
-
|
|
332
|
-
expect(input).toHaveStyle({color: 'yellow'});
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
describe('focus', () => {
|
|
337
|
-
it('should trigger `onFocus`', async () => {
|
|
338
|
-
testingLib = render(
|
|
339
|
-
Component({
|
|
340
|
-
testID: 'INPUT_TEST',
|
|
341
|
-
onFocus: jest.fn(),
|
|
342
|
-
}),
|
|
343
|
-
);
|
|
344
|
-
|
|
345
|
-
const input = testingLib.getByTestId('INPUT_TEST');
|
|
346
|
-
|
|
347
|
-
expect(input).toBeTruthy();
|
|
348
|
-
|
|
349
|
-
fireEvent(input, 'focus');
|
|
350
|
-
|
|
351
|
-
expect(input).toHaveStyle({color: light.text.basic});
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
it('should trigger `onFocus` and render custom color', async () => {
|
|
355
|
-
testingLib = render(
|
|
356
|
-
Component({
|
|
357
|
-
testID: 'INPUT_TEST',
|
|
358
|
-
onFocus: jest.fn(),
|
|
359
|
-
colors: {focused: 'yellow'},
|
|
360
|
-
}),
|
|
361
|
-
);
|
|
362
|
-
|
|
363
|
-
const input = testingLib.getByTestId('INPUT_TEST');
|
|
364
|
-
|
|
365
|
-
expect(input).toBeTruthy();
|
|
366
|
-
|
|
367
|
-
fireEvent(input, 'focus');
|
|
368
|
-
|
|
369
|
-
expect(input).toHaveStyle({color: 'yellow'});
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
it('should trigger `onFocus` when touching container', async () => {
|
|
373
|
-
const focusFn = jest.fn();
|
|
374
|
-
|
|
375
|
-
testingLib = render(
|
|
376
|
-
Component({
|
|
377
|
-
onFocus: focusFn,
|
|
378
|
-
colors: {focused: 'yellow'},
|
|
379
|
-
}),
|
|
380
|
-
);
|
|
381
|
-
|
|
382
|
-
const touch = testingLib.getByTestId('container-touch');
|
|
383
|
-
|
|
384
|
-
expect(touch).toBeTruthy();
|
|
385
|
-
|
|
386
|
-
fireEvent(touch, 'press');
|
|
387
|
-
// Below should work but no luck in testing-library
|
|
388
|
-
// expect(focusFn).toBeCalled();
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
describe('onBlur (focused === false)', () => {
|
|
392
|
-
it('should trigger blur without errorText', async () => {
|
|
393
|
-
testingLib = render(
|
|
394
|
-
Component({
|
|
395
|
-
onBlur: () => {},
|
|
396
|
-
testID: 'INPUT_TEST',
|
|
397
|
-
colors: {placeholder: 'green'},
|
|
398
|
-
}),
|
|
399
|
-
);
|
|
400
|
-
|
|
401
|
-
const input = testingLib.getByTestId('INPUT_TEST');
|
|
402
|
-
|
|
403
|
-
expect(input).toBeTruthy();
|
|
404
|
-
|
|
405
|
-
fireEvent(input, 'blur');
|
|
406
|
-
|
|
407
|
-
expect(input).toHaveStyle({color: 'green'});
|
|
408
|
-
});
|
|
409
|
-
});
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
describe('sizes', () => {
|
|
413
|
-
it('should render with small size', () => {
|
|
414
|
-
testingLib = render(
|
|
415
|
-
Component({
|
|
416
|
-
testID: 'INPUT_TEST',
|
|
417
|
-
size: 'small',
|
|
418
|
-
label: 'Small Input',
|
|
419
|
-
}),
|
|
420
|
-
);
|
|
421
|
-
|
|
422
|
-
const input = testingLib.getByTestId('INPUT_TEST');
|
|
423
|
-
expect(input).toBeTruthy();
|
|
424
|
-
|
|
425
|
-
const label = testingLib.getByText('Small Input');
|
|
426
|
-
expect(label).toBeTruthy();
|
|
427
|
-
});
|
|
428
|
-
|
|
429
|
-
it('should render with medium size', () => {
|
|
430
|
-
testingLib = render(
|
|
431
|
-
Component({
|
|
432
|
-
testID: 'INPUT_TEST',
|
|
433
|
-
size: 'medium',
|
|
434
|
-
label: 'Medium Input',
|
|
435
|
-
}),
|
|
436
|
-
);
|
|
437
|
-
|
|
438
|
-
const input = testingLib.getByTestId('INPUT_TEST');
|
|
439
|
-
expect(input).toBeTruthy();
|
|
440
|
-
|
|
441
|
-
const label = testingLib.getByText('Medium Input');
|
|
442
|
-
expect(label).toBeTruthy();
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
it('should render with large size', () => {
|
|
446
|
-
testingLib = render(
|
|
447
|
-
Component({
|
|
448
|
-
testID: 'INPUT_TEST',
|
|
449
|
-
size: 'large',
|
|
450
|
-
label: 'Large Input',
|
|
451
|
-
}),
|
|
452
|
-
);
|
|
453
|
-
|
|
454
|
-
const input = testingLib.getByTestId('INPUT_TEST');
|
|
455
|
-
expect(input).toBeTruthy();
|
|
456
|
-
|
|
457
|
-
const label = testingLib.getByText('Large Input');
|
|
458
|
-
expect(label).toBeTruthy();
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
it('should render with custom numeric size', () => {
|
|
462
|
-
testingLib = render(
|
|
463
|
-
Component({
|
|
464
|
-
testID: 'INPUT_TEST',
|
|
465
|
-
size: 20,
|
|
466
|
-
label: 'Custom Size Input',
|
|
467
|
-
}),
|
|
468
|
-
);
|
|
469
|
-
|
|
470
|
-
const input = testingLib.getByTestId('INPUT_TEST');
|
|
471
|
-
expect(input).toBeTruthy();
|
|
472
|
-
|
|
473
|
-
const label = testingLib.getByText('Custom Size Input');
|
|
474
|
-
expect(label).toBeTruthy();
|
|
475
|
-
});
|
|
476
|
-
});
|
|
477
|
-
});
|