@hero-design/rn 7.12.0 → 7.13.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/.turbo/turbo-build.log +2 -2
- package/es/index.js +4908 -4728
- package/lib/index.js +4907 -4726
- package/package.json +2 -2
- package/src/components/Button/Button.tsx +64 -60
- package/src/components/Button/StyledButton.tsx +4 -6
- package/src/components/Button/__tests__/StyledButton.spec.tsx +11 -4
- package/src/components/Button/__tests__/__snapshots__/StyledButton.spec.tsx.snap +312 -78
- package/src/components/DatePicker/DatePickerAndroid.tsx +59 -0
- package/src/components/DatePicker/DatePickerIOS.tsx +87 -0
- package/src/components/DatePicker/StyledDatePicker.tsx +8 -0
- package/src/components/DatePicker/__tests__/DatePicker.spec.tsx +34 -0
- package/src/components/DatePicker/__tests__/DatePickerAndroid.spec.tsx +39 -0
- package/src/components/DatePicker/__tests__/DatePickerIOS.spec.tsx +46 -0
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerAndroid.spec.tsx.snap +199 -0
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerIOS.spec.tsx.snap +513 -0
- package/src/components/DatePicker/index.tsx +15 -0
- package/src/components/DatePicker/types.ts +49 -0
- package/src/components/TimePicker/TimePickerIOS.tsx +1 -1
- package/src/components/TimePicker/types.ts +1 -1
- package/src/index.ts +2 -0
- package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +18 -0
- package/src/theme/components/button.ts +12 -0
- package/src/theme/components/datePicker.ts +11 -0
- package/src/theme/global/colors.ts +1 -0
- package/src/theme/index.ts +3 -0
- package/types/components/Button/StyledButton.d.ts +3 -3
- package/types/components/DatePicker/DatePickerAndroid.d.ts +3 -0
- package/types/components/DatePicker/DatePickerIOS.d.ts +3 -0
- package/types/components/DatePicker/StyledDatePicker.d.ts +8 -0
- package/types/components/DatePicker/__tests__/DatePicker.spec.d.ts +1 -0
- package/types/components/DatePicker/__tests__/DatePickerAndroid.spec.d.ts +1 -0
- package/types/components/DatePicker/__tests__/DatePickerIOS.spec.d.ts +1 -0
- package/types/components/DatePicker/index.d.ts +3 -0
- package/types/components/DatePicker/types.d.ts +48 -0
- package/types/components/TimePicker/types.d.ts +1 -1
- package/types/index.d.ts +2 -1
- package/types/theme/components/button.d.ts +12 -0
- package/types/theme/components/datePicker.d.ts +6 -0
- package/types/theme/global/colors.d.ts +1 -0
- package/types/theme/global/index.d.ts +1 -0
- package/types/theme/index.d.ts +2 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import DateTimePicker from '@react-native-community/datetimepicker';
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import { TouchableOpacity, View } from 'react-native';
|
|
4
|
+
import formatDate from 'date-fns/fp/format';
|
|
5
|
+
|
|
6
|
+
import TextInput from '../TextInput';
|
|
7
|
+
import { DatePickerProps } from './types';
|
|
8
|
+
|
|
9
|
+
const DatePickerAndroid = ({
|
|
10
|
+
value,
|
|
11
|
+
label,
|
|
12
|
+
placeholder,
|
|
13
|
+
onChange,
|
|
14
|
+
displayFormat = 'dd/MM/yyyy',
|
|
15
|
+
disabled = false,
|
|
16
|
+
required,
|
|
17
|
+
error,
|
|
18
|
+
style,
|
|
19
|
+
testID,
|
|
20
|
+
}: DatePickerProps) => {
|
|
21
|
+
const [open, setOpen] = useState(false);
|
|
22
|
+
|
|
23
|
+
const displayValue = value ? formatDate(displayFormat, value) : '';
|
|
24
|
+
const pickerInitValue = value || new Date();
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<TouchableOpacity onPress={() => setOpen(true)} disabled={disabled}>
|
|
28
|
+
<View pointerEvents="none" testID="datePickerInputAndroid">
|
|
29
|
+
<TextInput
|
|
30
|
+
label={label}
|
|
31
|
+
value={displayValue}
|
|
32
|
+
suffix="calendar-dates-outlined"
|
|
33
|
+
placeholder={placeholder || displayFormat}
|
|
34
|
+
disabled={disabled}
|
|
35
|
+
error={error}
|
|
36
|
+
required={required}
|
|
37
|
+
style={style}
|
|
38
|
+
testID={testID}
|
|
39
|
+
/>
|
|
40
|
+
</View>
|
|
41
|
+
{open ? (
|
|
42
|
+
<DateTimePicker
|
|
43
|
+
testID="datePickerAndroid"
|
|
44
|
+
mode="date"
|
|
45
|
+
value={pickerInitValue}
|
|
46
|
+
display="default"
|
|
47
|
+
onChange={(_: any, date: Date | undefined) => {
|
|
48
|
+
setOpen(false);
|
|
49
|
+
if (date) {
|
|
50
|
+
onChange(date);
|
|
51
|
+
}
|
|
52
|
+
}}
|
|
53
|
+
/>
|
|
54
|
+
) : null}
|
|
55
|
+
</TouchableOpacity>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default DatePickerAndroid;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import DateTimePicker from '@react-native-community/datetimepicker';
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import { TouchableOpacity, View } from 'react-native';
|
|
4
|
+
import formatDate from 'date-fns/fp/format';
|
|
5
|
+
|
|
6
|
+
import BottomSheet from '../BottomSheet';
|
|
7
|
+
import TextInput from '../TextInput';
|
|
8
|
+
import Typography from '../Typography';
|
|
9
|
+
import { StyledPickerWrapper } from './StyledDatePicker';
|
|
10
|
+
import { DatePickerProps } from './types';
|
|
11
|
+
|
|
12
|
+
const DatePickerIOS = ({
|
|
13
|
+
value,
|
|
14
|
+
label,
|
|
15
|
+
placeholder,
|
|
16
|
+
onChange,
|
|
17
|
+
confirmLabel,
|
|
18
|
+
displayFormat = 'dd/MM/yyyy',
|
|
19
|
+
disabled = false,
|
|
20
|
+
required,
|
|
21
|
+
error,
|
|
22
|
+
style,
|
|
23
|
+
testID,
|
|
24
|
+
}: DatePickerProps) => {
|
|
25
|
+
const [selectingDate, setSelectingDate] = useState<Date | undefined>(value);
|
|
26
|
+
const [open, setOpen] = useState(false);
|
|
27
|
+
|
|
28
|
+
const displayValue = value ? formatDate(displayFormat, value) : '';
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<TouchableOpacity onPress={() => setOpen(true)} disabled={disabled}>
|
|
32
|
+
<View pointerEvents="none" testID="datePickerInputIOS">
|
|
33
|
+
<TextInput
|
|
34
|
+
label={label}
|
|
35
|
+
value={displayValue}
|
|
36
|
+
suffix="calendar-dates-outlined"
|
|
37
|
+
placeholder={placeholder || displayFormat}
|
|
38
|
+
disabled={disabled}
|
|
39
|
+
error={error}
|
|
40
|
+
required={required}
|
|
41
|
+
testID={testID}
|
|
42
|
+
style={style}
|
|
43
|
+
/>
|
|
44
|
+
</View>
|
|
45
|
+
<BottomSheet
|
|
46
|
+
open={open}
|
|
47
|
+
onRequestClose={() => setOpen(false)}
|
|
48
|
+
header={label}
|
|
49
|
+
footer={
|
|
50
|
+
<TouchableOpacity
|
|
51
|
+
onPress={() => {
|
|
52
|
+
if (selectingDate) {
|
|
53
|
+
onChange(selectingDate);
|
|
54
|
+
}
|
|
55
|
+
setOpen(false);
|
|
56
|
+
}}
|
|
57
|
+
>
|
|
58
|
+
<Typography.Text
|
|
59
|
+
fontSize="large"
|
|
60
|
+
fontWeight="semi-bold"
|
|
61
|
+
intent="primary"
|
|
62
|
+
>
|
|
63
|
+
{confirmLabel}
|
|
64
|
+
</Typography.Text>
|
|
65
|
+
</TouchableOpacity>
|
|
66
|
+
}
|
|
67
|
+
>
|
|
68
|
+
<StyledPickerWrapper>
|
|
69
|
+
<DateTimePicker
|
|
70
|
+
testID="datePickerIOS"
|
|
71
|
+
value={selectingDate || new Date()}
|
|
72
|
+
mode="date"
|
|
73
|
+
onChange={(_: any, date: Date | undefined) => {
|
|
74
|
+
if (date) {
|
|
75
|
+
setSelectingDate(date);
|
|
76
|
+
}
|
|
77
|
+
}}
|
|
78
|
+
display="spinner"
|
|
79
|
+
style={{ flex: 1 }}
|
|
80
|
+
/>
|
|
81
|
+
</StyledPickerWrapper>
|
|
82
|
+
</BottomSheet>
|
|
83
|
+
</TouchableOpacity>
|
|
84
|
+
);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export default DatePickerIOS;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
import DatePicker from '..';
|
|
4
|
+
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
5
|
+
|
|
6
|
+
describe('DatePicker', () => {
|
|
7
|
+
it('renders DatePickerIOS when OS is iOS', () => {
|
|
8
|
+
Platform.OS = 'ios';
|
|
9
|
+
const { getByTestId } = renderWithTheme(
|
|
10
|
+
<DatePicker
|
|
11
|
+
label="Start date"
|
|
12
|
+
value={new Date('December 17, 1995')}
|
|
13
|
+
confirmLabel="Confirm"
|
|
14
|
+
onChange={jest.fn()}
|
|
15
|
+
/>
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
expect(getByTestId('datePickerInputIOS')).toBeDefined();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('renders DatePickerAndroid when OS is android', () => {
|
|
22
|
+
Platform.OS = 'android';
|
|
23
|
+
const { getByTestId } = renderWithTheme(
|
|
24
|
+
<DatePicker
|
|
25
|
+
label="Start date"
|
|
26
|
+
value={new Date('December 17, 1995')}
|
|
27
|
+
confirmLabel="Confirm"
|
|
28
|
+
onChange={jest.fn()}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
expect(getByTestId('datePickerInputAndroid')).toBeDefined();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { fireEvent } from '@testing-library/react-native';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
4
|
+
import DatePickerAndroid from '../DatePickerAndroid';
|
|
5
|
+
|
|
6
|
+
describe('DatePickerAndroid', () => {
|
|
7
|
+
it('renders correctly', () => {
|
|
8
|
+
const onChange = jest.fn();
|
|
9
|
+
|
|
10
|
+
const { getByText, queryByTestId, toJSON } = renderWithTheme(
|
|
11
|
+
<DatePickerAndroid
|
|
12
|
+
value={new Date('December 21, 1995')}
|
|
13
|
+
label="Start date"
|
|
14
|
+
confirmLabel="Confirm"
|
|
15
|
+
onChange={onChange}
|
|
16
|
+
/>
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
expect(getByText('Start date')).toBeDefined();
|
|
20
|
+
expect(queryByTestId('text-input').props.value).toBe('21/12/1995');
|
|
21
|
+
expect(queryByTestId('datePickerAndroid')).toBeNull();
|
|
22
|
+
|
|
23
|
+
// Open date picker
|
|
24
|
+
fireEvent.press(getByText('Start date'));
|
|
25
|
+
expect(queryByTestId('datePickerAndroid')).toBeTruthy();
|
|
26
|
+
|
|
27
|
+
expect(toJSON()).toMatchSnapshot();
|
|
28
|
+
|
|
29
|
+
// Change date
|
|
30
|
+
fireEvent(
|
|
31
|
+
queryByTestId('datePickerAndroid'),
|
|
32
|
+
'onChange',
|
|
33
|
+
null,
|
|
34
|
+
new Date('December 17, 1995')
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
expect(onChange).toBeCalledWith(new Date('December 17, 1995'));
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { fireEvent } from '@testing-library/react-native';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ModalProps } from 'react-native';
|
|
4
|
+
|
|
5
|
+
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
6
|
+
import DatePickerIOS from '../DatePickerIOS';
|
|
7
|
+
|
|
8
|
+
jest.mock('react-native/Libraries/Modal/Modal', () => {
|
|
9
|
+
const Modal = jest.requireActual('react-native/Libraries/Modal/Modal');
|
|
10
|
+
return (props: ModalProps) => <Modal {...props} />;
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe('DatePickerIOS', () => {
|
|
14
|
+
it('renders correctly', () => {
|
|
15
|
+
const onChange = jest.fn();
|
|
16
|
+
const { getByText, queryByTestId, toJSON } = renderWithTheme(
|
|
17
|
+
<DatePickerIOS
|
|
18
|
+
value={new Date('December 21, 1995')}
|
|
19
|
+
label="Start date"
|
|
20
|
+
confirmLabel="Confirm"
|
|
21
|
+
onChange={onChange}
|
|
22
|
+
/>
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
expect(getByText('Start date')).toBeDefined();
|
|
26
|
+
expect(queryByTestId('text-input').props.value).toBe('21/12/1995');
|
|
27
|
+
expect(queryByTestId('datePickerIOS')).toBeNull();
|
|
28
|
+
|
|
29
|
+
// Open date picker
|
|
30
|
+
fireEvent.press(getByText('Start date'));
|
|
31
|
+
expect(queryByTestId('datePickerIOS')).toBeTruthy();
|
|
32
|
+
|
|
33
|
+
expect(toJSON()).toMatchSnapshot();
|
|
34
|
+
|
|
35
|
+
// Change date
|
|
36
|
+
fireEvent(
|
|
37
|
+
queryByTestId('datePickerIOS'),
|
|
38
|
+
'onChange',
|
|
39
|
+
null,
|
|
40
|
+
new Date('December 17, 1995')
|
|
41
|
+
);
|
|
42
|
+
fireEvent.press(getByText('Confirm'));
|
|
43
|
+
|
|
44
|
+
expect(onChange).toBeCalledWith(new Date('December 17, 1995'));
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`DatePickerAndroid renders correctly 1`] = `
|
|
4
|
+
<View
|
|
5
|
+
accessible={true}
|
|
6
|
+
focusable={true}
|
|
7
|
+
onClick={[Function]}
|
|
8
|
+
onResponderGrant={[Function]}
|
|
9
|
+
onResponderMove={[Function]}
|
|
10
|
+
onResponderRelease={[Function]}
|
|
11
|
+
onResponderTerminate={[Function]}
|
|
12
|
+
onResponderTerminationRequest={[Function]}
|
|
13
|
+
onStartShouldSetResponder={[Function]}
|
|
14
|
+
style={
|
|
15
|
+
Object {
|
|
16
|
+
"opacity": 1,
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
>
|
|
20
|
+
<View
|
|
21
|
+
pointerEvents="none"
|
|
22
|
+
testID="datePickerInputAndroid"
|
|
23
|
+
>
|
|
24
|
+
<View
|
|
25
|
+
pointerEvents="auto"
|
|
26
|
+
style={
|
|
27
|
+
Array [
|
|
28
|
+
Object {
|
|
29
|
+
"marginVertical": 8,
|
|
30
|
+
"width": "100%",
|
|
31
|
+
},
|
|
32
|
+
undefined,
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
>
|
|
36
|
+
<View
|
|
37
|
+
style={
|
|
38
|
+
Array [
|
|
39
|
+
Object {
|
|
40
|
+
"alignItems": "center",
|
|
41
|
+
"flexDirection": "row",
|
|
42
|
+
"padding": 16,
|
|
43
|
+
},
|
|
44
|
+
undefined,
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
>
|
|
48
|
+
<View
|
|
49
|
+
style={
|
|
50
|
+
Array [
|
|
51
|
+
Object {
|
|
52
|
+
"borderColor": "#292a2b",
|
|
53
|
+
"borderRadius": 8,
|
|
54
|
+
"borderWidth": 1,
|
|
55
|
+
"bottom": 0,
|
|
56
|
+
"left": 0,
|
|
57
|
+
"position": "absolute",
|
|
58
|
+
"right": 0,
|
|
59
|
+
"top": 0,
|
|
60
|
+
},
|
|
61
|
+
undefined,
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
themeVariant="filled"
|
|
65
|
+
/>
|
|
66
|
+
<View
|
|
67
|
+
pointerEvents="none"
|
|
68
|
+
style={
|
|
69
|
+
Array [
|
|
70
|
+
Object {
|
|
71
|
+
"backgroundColor": "#ffffff",
|
|
72
|
+
"flexDirection": "row",
|
|
73
|
+
"left": 16,
|
|
74
|
+
"paddingHorizontal": 4,
|
|
75
|
+
"position": "absolute",
|
|
76
|
+
"top": -10,
|
|
77
|
+
"zIndex": 1,
|
|
78
|
+
},
|
|
79
|
+
undefined,
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
>
|
|
83
|
+
<Text
|
|
84
|
+
style={
|
|
85
|
+
Array [
|
|
86
|
+
Object {
|
|
87
|
+
"color": "#292a2b",
|
|
88
|
+
"fontFamily": "BeVietnamPro-Regular",
|
|
89
|
+
"fontSize": 12,
|
|
90
|
+
"letterSpacing": 0.36,
|
|
91
|
+
"lineHeight": 20,
|
|
92
|
+
},
|
|
93
|
+
Array [
|
|
94
|
+
Object {
|
|
95
|
+
"color": "#292a2b",
|
|
96
|
+
},
|
|
97
|
+
undefined,
|
|
98
|
+
],
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
testID="input-label"
|
|
102
|
+
themeFontSize="small"
|
|
103
|
+
themeFontWeight="regular"
|
|
104
|
+
themeIntent="body"
|
|
105
|
+
themeVariant="filled"
|
|
106
|
+
>
|
|
107
|
+
Start date
|
|
108
|
+
</Text>
|
|
109
|
+
</View>
|
|
110
|
+
<View
|
|
111
|
+
style={
|
|
112
|
+
Array [
|
|
113
|
+
Object {
|
|
114
|
+
"alignItems": "center",
|
|
115
|
+
"alignSelf": "stretch",
|
|
116
|
+
"flexDirection": "row",
|
|
117
|
+
"flexGrow": 2,
|
|
118
|
+
},
|
|
119
|
+
undefined,
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
>
|
|
123
|
+
<TextInput
|
|
124
|
+
accessibilityState={
|
|
125
|
+
Object {
|
|
126
|
+
"disabled": false,
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
editable={true}
|
|
130
|
+
onBlur={[Function]}
|
|
131
|
+
onChangeText={[Function]}
|
|
132
|
+
onFocus={[Function]}
|
|
133
|
+
style={
|
|
134
|
+
Array [
|
|
135
|
+
Object {
|
|
136
|
+
"alignSelf": "stretch",
|
|
137
|
+
"flexGrow": 2,
|
|
138
|
+
"fontSize": 14,
|
|
139
|
+
"marginHorizontal": 8,
|
|
140
|
+
"textAlignVertical": "center",
|
|
141
|
+
},
|
|
142
|
+
Object {
|
|
143
|
+
"color": "#292a2b",
|
|
144
|
+
},
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
testID="text-input"
|
|
148
|
+
value="21/12/1995"
|
|
149
|
+
/>
|
|
150
|
+
</View>
|
|
151
|
+
<HeroIcon
|
|
152
|
+
name="calendar-dates-outlined"
|
|
153
|
+
style={
|
|
154
|
+
Array [
|
|
155
|
+
Object {
|
|
156
|
+
"color": "#292a2b",
|
|
157
|
+
"fontSize": 16,
|
|
158
|
+
},
|
|
159
|
+
undefined,
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
testID="input-suffix"
|
|
163
|
+
themeIntent="text"
|
|
164
|
+
themeSize="xsmall"
|
|
165
|
+
/>
|
|
166
|
+
</View>
|
|
167
|
+
<View
|
|
168
|
+
style={
|
|
169
|
+
Array [
|
|
170
|
+
Object {
|
|
171
|
+
"paddingLeft": 16,
|
|
172
|
+
},
|
|
173
|
+
undefined,
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
>
|
|
177
|
+
<View
|
|
178
|
+
style={
|
|
179
|
+
Array [
|
|
180
|
+
Object {
|
|
181
|
+
"flexDirection": "row",
|
|
182
|
+
"justifyContent": "space-between",
|
|
183
|
+
},
|
|
184
|
+
undefined,
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
/>
|
|
188
|
+
</View>
|
|
189
|
+
</View>
|
|
190
|
+
</View>
|
|
191
|
+
<Picker
|
|
192
|
+
display="default"
|
|
193
|
+
mode="date"
|
|
194
|
+
onChange={[Function]}
|
|
195
|
+
testID="datePickerAndroid"
|
|
196
|
+
value={1995-12-21T00:00:00.000Z}
|
|
197
|
+
/>
|
|
198
|
+
</View>
|
|
199
|
+
`;
|