@hero-design/rn 8.103.6 → 8.104.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 +3 -3
- package/CHANGELOG.md +18 -0
- package/es/index.js +343 -79
- package/lib/index.js +343 -78
- package/package.json +1 -1
- package/src/components/DatePicker/DatePickerAndroid.tsx +18 -4
- package/src/components/DatePicker/DatePickerCalendar.tsx +18 -4
- package/src/components/DatePicker/DatePickerIOS.tsx +18 -4
- package/src/components/DatePicker/StyledDatePicker.tsx +19 -2
- package/src/components/DatePicker/__tests__/DatePicker.spec.tsx +102 -1
- package/src/components/DatePicker/__tests__/__snapshots__/DatePicker.spec.tsx.snap +3 -0
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerAndroid.spec.tsx.snap +1 -0
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerCalendar.spec.tsx.snap +1 -0
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerIOS.spec.tsx.snap +2 -0
- package/src/components/DatePicker/types.ts +11 -0
- package/src/components/FilterTrigger/StyledFilterTrigger.tsx +104 -0
- package/src/components/FilterTrigger/__tests__/__snapshots__/index.spec.tsx.snap +637 -0
- package/src/components/FilterTrigger/__tests__/index.spec.tsx +161 -0
- package/src/components/FilterTrigger/index.tsx +106 -0
- package/src/components/Icon/HeroIcon/index.tsx +3 -1
- package/src/components/Icon/__tests__/__snapshots__/index.spec.tsx.snap +45 -0
- package/src/components/Icon/__tests__/index.spec.tsx +1 -0
- package/src/components/Icon/index.tsx +2 -1
- package/src/components/TimePicker/StyledTimePicker.tsx +19 -2
- package/src/components/TimePicker/TimePickerAndroid.tsx +18 -4
- package/src/components/TimePicker/TimePickerIOS.tsx +21 -5
- package/src/components/TimePicker/__tests__/TimePicker.spec.tsx +72 -1
- package/src/components/TimePicker/__tests__/__snapshots__/TimePickerAndroid.spec.tsx.snap +2 -0
- package/src/components/TimePicker/__tests__/__snapshots__/TimePickerIOS.spec.tsx.snap +2 -0
- package/src/components/TimePicker/types.ts +11 -0
- package/src/components/Toolbar/StyledToolbar.tsx +0 -1
- package/src/components/Toolbar/__tests__/__snapshots__/ToolbarMessage.spec.tsx.snap +0 -4
- package/src/index.ts +2 -0
- package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +71 -0
- package/src/theme/components/filterTrigger.ts +88 -0
- package/src/theme/components/icon.ts +1 -0
- package/src/theme/getTheme.ts +3 -0
- package/stats/8.103.6/rn-stats.html +0 -2
- package/stats/8.103.7/rn-stats.html +4844 -0
- package/stats/8.104.0/rn-stats.html +4844 -0
- package/types/components/DatePicker/DatePickerAndroid.d.ts +1 -1
- package/types/components/DatePicker/DatePickerCalendar.d.ts +1 -1
- package/types/components/DatePicker/DatePickerIOS.d.ts +1 -1
- package/types/components/DatePicker/StyledDatePicker.d.ts +8 -1
- package/types/components/DatePicker/types.d.ts +11 -0
- package/types/components/FilterTrigger/StyledFilterTrigger.d.ts +20 -0
- package/types/components/FilterTrigger/index.d.ts +39 -0
- package/types/components/Icon/HeroIcon/index.d.ts +1 -1
- package/types/components/Icon/index.d.ts +1 -1
- package/types/components/TimePicker/StyledTimePicker.d.ts +8 -1
- package/types/components/TimePicker/TimePickerAndroid.d.ts +1 -1
- package/types/components/TimePicker/TimePickerIOS.d.ts +1 -1
- package/types/components/TimePicker/types.d.ts +11 -0
- package/types/index.d.ts +2 -1
- package/types/theme/components/filterTrigger.d.ts +72 -0
- package/types/theme/components/icon.d.ts +1 -0
- package/types/theme/getTheme.d.ts +2 -0
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { useState, useCallback } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import TextInput from '../TextInput';
|
|
5
5
|
import AndroidDatePickerDialog from './Dialog/AndroidDialog';
|
|
6
6
|
import useCalculateDate from './hooks/useCalculateDate';
|
|
7
7
|
import useFormatDate from './hooks/useFormatDate';
|
|
8
|
+
import { StyledTouchableOpacity } from './StyledDatePicker';
|
|
8
9
|
import type { InternalDatePickerProps } from './types';
|
|
9
10
|
|
|
10
11
|
type DatePickerAndroidProps = Omit<
|
|
@@ -31,6 +32,8 @@ const DatePickerAndroid = ({
|
|
|
31
32
|
renderSelectedValue,
|
|
32
33
|
locale,
|
|
33
34
|
TextInputComponent,
|
|
35
|
+
inputProps,
|
|
36
|
+
groupStyleEnabled = false,
|
|
34
37
|
}: DatePickerAndroidProps) => {
|
|
35
38
|
const [open, setOpen] = useState(false);
|
|
36
39
|
|
|
@@ -44,10 +47,21 @@ const DatePickerAndroid = ({
|
|
|
44
47
|
|
|
45
48
|
const InputComponent = TextInputComponent || TextInput;
|
|
46
49
|
|
|
50
|
+
const onPress = useCallback(() => {
|
|
51
|
+
setOpen(true);
|
|
52
|
+
}, []);
|
|
53
|
+
|
|
47
54
|
return (
|
|
48
|
-
<
|
|
55
|
+
<StyledTouchableOpacity
|
|
56
|
+
onPress={onPress}
|
|
57
|
+
disabled={disabled}
|
|
58
|
+
themeGroupStyleEnabled={groupStyleEnabled}
|
|
59
|
+
themeHasError={!!error}
|
|
60
|
+
testID="date-picker-android-touchable-opacity"
|
|
61
|
+
>
|
|
49
62
|
<View pointerEvents="none" testID="datePickerInputAndroid">
|
|
50
63
|
<InputComponent
|
|
64
|
+
{...inputProps}
|
|
51
65
|
label={label}
|
|
52
66
|
value={displayValue}
|
|
53
67
|
suffix="calendar-dates-outlined"
|
|
@@ -81,7 +95,7 @@ const DatePickerAndroid = ({
|
|
|
81
95
|
onChange={onChange}
|
|
82
96
|
variant={variant}
|
|
83
97
|
/>
|
|
84
|
-
</
|
|
98
|
+
</StyledTouchableOpacity>
|
|
85
99
|
);
|
|
86
100
|
};
|
|
87
101
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import { Platform, ScrollView,
|
|
1
|
+
import React, { useState, useCallback } from 'react';
|
|
2
|
+
import { Platform, ScrollView, View } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import BottomSheet from '../BottomSheet';
|
|
5
5
|
import Button from '../Button';
|
|
@@ -7,6 +7,7 @@ import Calendar, { CalendarProps } from '../Calendar';
|
|
|
7
7
|
import TextInput from '../TextInput';
|
|
8
8
|
import useCalculateDate from './hooks/useCalculateDate';
|
|
9
9
|
import useFormatDate from './hooks/useFormatDate';
|
|
10
|
+
import { StyledTouchableOpacity } from './StyledDatePicker';
|
|
10
11
|
import type { InternalDatePickerProps } from './types';
|
|
11
12
|
|
|
12
13
|
const InternalCalendar = ({
|
|
@@ -81,6 +82,8 @@ const DatePickerCalendar = ({
|
|
|
81
82
|
renderSelectedValue,
|
|
82
83
|
locale,
|
|
83
84
|
TextInputComponent,
|
|
85
|
+
inputProps,
|
|
86
|
+
groupStyleEnabled = false,
|
|
84
87
|
}: Omit<InternalDatePickerProps, 'variant'>) => {
|
|
85
88
|
const [open, setOpen] = useState(false);
|
|
86
89
|
const [monthPickerVisible, setMonthPickerVisible] = useState(false);
|
|
@@ -98,10 +101,21 @@ const DatePickerCalendar = ({
|
|
|
98
101
|
|
|
99
102
|
const InputComponent = TextInputComponent || TextInput;
|
|
100
103
|
|
|
104
|
+
const onPress = useCallback(() => {
|
|
105
|
+
setOpen(true);
|
|
106
|
+
}, []);
|
|
107
|
+
|
|
101
108
|
return (
|
|
102
|
-
<
|
|
109
|
+
<StyledTouchableOpacity
|
|
110
|
+
onPress={onPress}
|
|
111
|
+
disabled={disabled}
|
|
112
|
+
themeGroupStyleEnabled={groupStyleEnabled}
|
|
113
|
+
themeHasError={!!error}
|
|
114
|
+
testID="date-picker-calendar-touchable-opacity"
|
|
115
|
+
>
|
|
103
116
|
<View pointerEvents="none" testID="datePickerCalendar">
|
|
104
117
|
<InputComponent
|
|
118
|
+
{...inputProps}
|
|
105
119
|
label={label}
|
|
106
120
|
value={displayValue}
|
|
107
121
|
suffix="calendar-dates-outlined"
|
|
@@ -158,7 +172,7 @@ const DatePickerCalendar = ({
|
|
|
158
172
|
/>
|
|
159
173
|
</ScrollView>
|
|
160
174
|
</BottomSheet>
|
|
161
|
-
</
|
|
175
|
+
</StyledTouchableOpacity>
|
|
162
176
|
);
|
|
163
177
|
};
|
|
164
178
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { useState, useCallback } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import { useLocale } from '../LocaleProvider/hooks';
|
|
5
5
|
import TextInput from '../TextInput';
|
|
6
6
|
import IOSDatePickerDialog from './Dialog/IOSDialog';
|
|
7
7
|
import useCalculateDate from './hooks/useCalculateDate';
|
|
8
8
|
import useFormatDate from './hooks/useFormatDate';
|
|
9
|
+
import { StyledTouchableOpacity } from './StyledDatePicker';
|
|
9
10
|
import type { InternalDatePickerProps } from './types';
|
|
10
11
|
|
|
11
12
|
type DatePickerIOSProps = Omit<
|
|
@@ -34,6 +35,8 @@ const DatePickerIOS = ({
|
|
|
34
35
|
locale,
|
|
35
36
|
renderSelectedValue,
|
|
36
37
|
TextInputComponent,
|
|
38
|
+
inputProps,
|
|
39
|
+
groupStyleEnabled = false,
|
|
37
40
|
}: DatePickerIOSProps) => {
|
|
38
41
|
const [open, setOpen] = useState(false);
|
|
39
42
|
const { lang: defaultLocale } = useLocale();
|
|
@@ -47,10 +50,21 @@ const DatePickerIOS = ({
|
|
|
47
50
|
|
|
48
51
|
const InputComponent = TextInputComponent || TextInput;
|
|
49
52
|
|
|
53
|
+
const onPress = useCallback(() => {
|
|
54
|
+
setOpen(true);
|
|
55
|
+
}, []);
|
|
56
|
+
|
|
50
57
|
return (
|
|
51
|
-
<
|
|
58
|
+
<StyledTouchableOpacity
|
|
59
|
+
onPress={onPress}
|
|
60
|
+
disabled={disabled}
|
|
61
|
+
themeGroupStyleEnabled={groupStyleEnabled}
|
|
62
|
+
themeHasError={!!error}
|
|
63
|
+
testID="date-picker-ios-touchable-opacity"
|
|
64
|
+
>
|
|
52
65
|
<View pointerEvents="none" testID="datePickerInputIOS">
|
|
53
66
|
<InputComponent
|
|
67
|
+
{...inputProps}
|
|
54
68
|
label={label}
|
|
55
69
|
value={displayValue}
|
|
56
70
|
suffix="calendar-dates-outlined"
|
|
@@ -88,7 +102,7 @@ const DatePickerIOS = ({
|
|
|
88
102
|
minDate={minDate}
|
|
89
103
|
maxDate={maxDate}
|
|
90
104
|
/>
|
|
91
|
-
</
|
|
105
|
+
</StyledTouchableOpacity>
|
|
92
106
|
);
|
|
93
107
|
};
|
|
94
108
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import styled from '@emotion/native';
|
|
2
|
-
import { View } from 'react-native';
|
|
2
|
+
import { View, TouchableOpacity } from 'react-native';
|
|
3
3
|
import type { ViewProps } from 'react-native';
|
|
4
4
|
|
|
5
5
|
const StyledPickerWrapper = styled(View)<ViewProps>(({ theme }) => ({
|
|
@@ -7,4 +7,21 @@ const StyledPickerWrapper = styled(View)<ViewProps>(({ theme }) => ({
|
|
|
7
7
|
alignItems: 'center',
|
|
8
8
|
}));
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const getZIndexByState = ({ themeHasError }: { themeHasError: boolean }) => {
|
|
11
|
+
if (themeHasError) {
|
|
12
|
+
return 1;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return 0;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const StyledTouchableOpacity = styled(TouchableOpacity)<{
|
|
19
|
+
themeGroupStyleEnabled: boolean;
|
|
20
|
+
themeHasError: boolean;
|
|
21
|
+
}>(({ themeGroupStyleEnabled, themeHasError }) => ({
|
|
22
|
+
...(themeGroupStyleEnabled && {
|
|
23
|
+
zIndex: getZIndexByState({ themeHasError }),
|
|
24
|
+
}),
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
export { StyledPickerWrapper, StyledTouchableOpacity };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Platform } from 'react-native';
|
|
3
3
|
import { fireEvent } from '@testing-library/react-native';
|
|
4
|
-
import
|
|
4
|
+
// Use internal import for full prop support
|
|
5
|
+
import DatePicker from '../index.internal';
|
|
5
6
|
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
6
7
|
import { Button, Typography } from '../../..';
|
|
7
8
|
|
|
@@ -57,6 +58,106 @@ describe('DatePicker', () => {
|
|
|
57
58
|
expect(getByTestId('datePickerCalendar')).toBeDefined();
|
|
58
59
|
});
|
|
59
60
|
|
|
61
|
+
it('renders correctly when inputProps loading is true', () => {
|
|
62
|
+
Platform.OS = 'ios';
|
|
63
|
+
const { getByTestId } = renderWithTheme(
|
|
64
|
+
<DatePicker
|
|
65
|
+
label="Start date"
|
|
66
|
+
value={new Date('1995-12-17T00:00:00.000Z')}
|
|
67
|
+
minDate={new Date('1994-12-17T00:00:00.000Z')}
|
|
68
|
+
maxDate={new Date('1996-12-17T00:00:00.000Z')}
|
|
69
|
+
confirmLabel="Confirm"
|
|
70
|
+
inputProps={{ loading: true }}
|
|
71
|
+
onChange={jest.fn()}
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
expect(getByTestId('input-suffix')).toHaveProp('name', 'loading');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('renders correctly when groupStyleEnabled is true and no error', () => {
|
|
79
|
+
Platform.OS = 'ios';
|
|
80
|
+
const { getByTestId } = renderWithTheme(
|
|
81
|
+
<DatePicker
|
|
82
|
+
label="Start date"
|
|
83
|
+
value={new Date('1995-12-17T00:00:00.000Z')}
|
|
84
|
+
minDate={new Date('1994-12-17T00:00:00.000Z')}
|
|
85
|
+
maxDate={new Date('1996-12-17T00:00:00.000Z')}
|
|
86
|
+
confirmLabel="Confirm"
|
|
87
|
+
groupStyleEnabled
|
|
88
|
+
onChange={jest.fn()}
|
|
89
|
+
/>
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const touchableOpacity = getByTestId('date-picker-ios-touchable-opacity');
|
|
93
|
+
expect(touchableOpacity).toBeTruthy();
|
|
94
|
+
expect(touchableOpacity.props.style).toHaveProperty('zIndex', 0);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('renders correctly when groupStyleEnabled is true and has error', () => {
|
|
98
|
+
Platform.OS = 'ios';
|
|
99
|
+
const { getByTestId } = renderWithTheme(
|
|
100
|
+
<DatePicker
|
|
101
|
+
label="Start date"
|
|
102
|
+
value={new Date('1995-12-17T00:00:00.000Z')}
|
|
103
|
+
minDate={new Date('1994-12-17T00:00:00.000Z')}
|
|
104
|
+
maxDate={new Date('1996-12-17T00:00:00.000Z')}
|
|
105
|
+
confirmLabel="Confirm"
|
|
106
|
+
groupStyleEnabled
|
|
107
|
+
error="This field is required"
|
|
108
|
+
onChange={jest.fn()}
|
|
109
|
+
/>
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const touchableOpacity = getByTestId('date-picker-ios-touchable-opacity');
|
|
113
|
+
expect(touchableOpacity).toBeTruthy();
|
|
114
|
+
expect(touchableOpacity.props.style).toHaveProperty('zIndex', 1);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('renders correctly when groupStyleEnabled is true and has error for Android', () => {
|
|
118
|
+
Platform.OS = 'android';
|
|
119
|
+
const { getByTestId } = renderWithTheme(
|
|
120
|
+
<DatePicker
|
|
121
|
+
label="Start date"
|
|
122
|
+
value={new Date('1995-12-17T00:00:00.000Z')}
|
|
123
|
+
minDate={new Date('1994-12-17T00:00:00.000Z')}
|
|
124
|
+
maxDate={new Date('1996-12-17T00:00:00.000Z')}
|
|
125
|
+
confirmLabel="Confirm"
|
|
126
|
+
groupStyleEnabled
|
|
127
|
+
error="This field is required"
|
|
128
|
+
onChange={jest.fn()}
|
|
129
|
+
/>
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const touchableOpacity = getByTestId(
|
|
133
|
+
'date-picker-android-touchable-opacity'
|
|
134
|
+
);
|
|
135
|
+
expect(touchableOpacity).toBeTruthy();
|
|
136
|
+
expect(touchableOpacity.props.style).toHaveProperty('zIndex', 1);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('renders correctly when groupStyleEnabled is true and has error for Calendar variant', () => {
|
|
140
|
+
const { getByTestId } = renderWithTheme(
|
|
141
|
+
<DatePicker
|
|
142
|
+
label="Start date"
|
|
143
|
+
value={new Date('1995-12-17T00:00:00.000Z')}
|
|
144
|
+
minDate={new Date('1994-12-17T00:00:00.000Z')}
|
|
145
|
+
maxDate={new Date('1996-12-17T00:00:00.000Z')}
|
|
146
|
+
confirmLabel="Confirm"
|
|
147
|
+
variant="calendar"
|
|
148
|
+
groupStyleEnabled
|
|
149
|
+
error="This field is required"
|
|
150
|
+
onChange={jest.fn()}
|
|
151
|
+
/>
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const touchableOpacity = getByTestId(
|
|
155
|
+
'date-picker-calendar-touchable-opacity'
|
|
156
|
+
);
|
|
157
|
+
expect(touchableOpacity).toBeTruthy();
|
|
158
|
+
expect(touchableOpacity.props.style).toHaveProperty('zIndex', 1);
|
|
159
|
+
});
|
|
160
|
+
|
|
60
161
|
it.each`
|
|
61
162
|
OS | variant
|
|
62
163
|
${'ios'} | ${'calendar'}
|
|
@@ -41,6 +41,7 @@ exports[`DatePicker renders DatePickerAndroid when OS is android 1`] = `
|
|
|
41
41
|
"opacity": 1,
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
+
testID="date-picker-android-touchable-opacity"
|
|
44
45
|
>
|
|
45
46
|
<View
|
|
46
47
|
pointerEvents="none"
|
|
@@ -328,6 +329,7 @@ exports[`DatePicker renders DatePickerIOS when OS is iOS 1`] = `
|
|
|
328
329
|
"opacity": 1,
|
|
329
330
|
}
|
|
330
331
|
}
|
|
332
|
+
testID="date-picker-ios-touchable-opacity"
|
|
331
333
|
>
|
|
332
334
|
<View
|
|
333
335
|
pointerEvents="none"
|
|
@@ -615,6 +617,7 @@ exports[`DatePicker renders variant Calendar 1`] = `
|
|
|
615
617
|
"opacity": 1,
|
|
616
618
|
}
|
|
617
619
|
}
|
|
620
|
+
testID="date-picker-calendar-touchable-opacity"
|
|
618
621
|
>
|
|
619
622
|
<View
|
|
620
623
|
pointerEvents="none"
|
|
@@ -41,6 +41,7 @@ exports[`DatePickerIOS renders correctly 1`] = `
|
|
|
41
41
|
"opacity": 1,
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
+
testID="date-picker-ios-touchable-opacity"
|
|
44
45
|
>
|
|
45
46
|
<View
|
|
46
47
|
pointerEvents="none"
|
|
@@ -711,6 +712,7 @@ exports[`DatePickerIOS renders correctly with custom locale 1`] = `
|
|
|
711
712
|
"opacity": 1,
|
|
712
713
|
}
|
|
713
714
|
}
|
|
715
|
+
testID="date-picker-ios-touchable-opacity"
|
|
714
716
|
>
|
|
715
717
|
<View
|
|
716
718
|
pointerEvents="none"
|
|
@@ -104,5 +104,16 @@ export interface DatePickerProps {
|
|
|
104
104
|
|
|
105
105
|
// Add an internal prop type for TextInputComponent, not exported
|
|
106
106
|
export interface InternalDatePickerProps extends DatePickerProps {
|
|
107
|
+
/**
|
|
108
|
+
* Props that are passed to TextInput.
|
|
109
|
+
*/
|
|
110
|
+
inputProps?: Pick<TextInputProps, 'loading' | 'numberOfLines'>;
|
|
111
|
+
/**
|
|
112
|
+
* Whether the component is used within a FormGroup for styling purposes.
|
|
113
|
+
*/
|
|
114
|
+
groupStyleEnabled?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Input component to use instead of the default TextInput.
|
|
117
|
+
*/
|
|
107
118
|
TextInputComponent?: React.ComponentType<TextInputProps>;
|
|
108
119
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import styled from '@emotion/native';
|
|
2
|
+
import { TouchableOpacity } from 'react-native';
|
|
3
|
+
import { Theme } from '../../theme';
|
|
4
|
+
import Badge from '../Badge';
|
|
5
|
+
import Typography from '../Typography';
|
|
6
|
+
|
|
7
|
+
type Variant = 'filled' | 'outlined' | 'ghost';
|
|
8
|
+
|
|
9
|
+
const getBackgroundColor = (
|
|
10
|
+
theme: Theme,
|
|
11
|
+
themeIsActive: boolean,
|
|
12
|
+
themeHasLabel: boolean,
|
|
13
|
+
themeVariant: Variant
|
|
14
|
+
): string => {
|
|
15
|
+
const { colors } = theme.__hd__.filterTrigger;
|
|
16
|
+
|
|
17
|
+
if (themeIsActive && !themeHasLabel && themeVariant === 'filled') {
|
|
18
|
+
return colors.wrapper.background.active.filledLabeless;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const state = themeIsActive ? 'active' : 'inactive';
|
|
22
|
+
return colors.wrapper.background[state][themeVariant];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const getBorderStyles = (
|
|
26
|
+
theme: Theme,
|
|
27
|
+
themeIsActive: boolean,
|
|
28
|
+
themeHasLabel: boolean,
|
|
29
|
+
themeVariant: Variant
|
|
30
|
+
) => {
|
|
31
|
+
const { colors, borderWidths, radii } = theme.__hd__.filterTrigger;
|
|
32
|
+
|
|
33
|
+
let borderColor: string;
|
|
34
|
+
if (themeIsActive && !themeHasLabel && themeVariant === 'filled') {
|
|
35
|
+
borderColor = colors.wrapper.border.active.filledLabeless;
|
|
36
|
+
} else {
|
|
37
|
+
const state = themeIsActive ? 'active' : 'inactive';
|
|
38
|
+
borderColor = colors.wrapper.border[state][themeVariant];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
borderWidth: borderWidths.wrapper[themeVariant],
|
|
43
|
+
borderColor,
|
|
44
|
+
borderRadius: themeHasLabel
|
|
45
|
+
? radii.wrapper.default
|
|
46
|
+
: radii.wrapper.labeless,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const getSpacingStyles = (theme: Theme, themeHasLabel: boolean) => {
|
|
51
|
+
const { space } = theme.__hd__.filterTrigger;
|
|
52
|
+
const paddingConfig = themeHasLabel
|
|
53
|
+
? space.wrapper.default
|
|
54
|
+
: space.wrapper.labeless;
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
gap: space.wrapper.itemGap,
|
|
58
|
+
paddingHorizontal: paddingConfig.paddingHorizontal,
|
|
59
|
+
paddingVertical: paddingConfig.paddingVertical,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const StyledFilterWrapper = styled(TouchableOpacity)<{
|
|
64
|
+
themeActive: boolean;
|
|
65
|
+
themeVariant: Variant;
|
|
66
|
+
themeHasLabel: boolean;
|
|
67
|
+
}>(({ theme, themeActive, themeVariant, themeHasLabel }) => ({
|
|
68
|
+
position: 'relative',
|
|
69
|
+
flexDirection: 'row',
|
|
70
|
+
alignItems: 'center',
|
|
71
|
+
justifyContent: 'center',
|
|
72
|
+
alignSelf: 'flex-start',
|
|
73
|
+
height: theme.__hd__.filterTrigger.sizes.wrapperHeight,
|
|
74
|
+
backgroundColor: getBackgroundColor(
|
|
75
|
+
theme,
|
|
76
|
+
themeActive,
|
|
77
|
+
themeHasLabel,
|
|
78
|
+
themeVariant
|
|
79
|
+
),
|
|
80
|
+
...getBorderStyles(theme, themeActive, themeHasLabel, themeVariant),
|
|
81
|
+
...getSpacingStyles(theme, themeHasLabel),
|
|
82
|
+
}));
|
|
83
|
+
|
|
84
|
+
export const StyledBadge = styled(Badge)<{ themeHasLabel: boolean }>(
|
|
85
|
+
({ theme, themeHasLabel }) => ({
|
|
86
|
+
position: 'absolute',
|
|
87
|
+
|
|
88
|
+
...(themeHasLabel
|
|
89
|
+
? {
|
|
90
|
+
right: 0,
|
|
91
|
+
bottom: 0,
|
|
92
|
+
}
|
|
93
|
+
: {
|
|
94
|
+
right: -theme.__hd__.filterTrigger.space.badge.labelessRight,
|
|
95
|
+
bottom: -theme.__hd__.filterTrigger.space.badge.labelessBottom,
|
|
96
|
+
}),
|
|
97
|
+
})
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
export const StyledText = styled(Typography.Body)(({ theme }) => ({
|
|
101
|
+
lineHeight: theme.__hd__.filterTrigger.lineHeights.text,
|
|
102
|
+
textAlignVertical: 'center',
|
|
103
|
+
includeFontPadding: false,
|
|
104
|
+
}));
|