@hero-design/rn 7.12.1 → 7.14.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/.eslintrc.json +3 -1
- package/.turbo/turbo-build.log +3 -2
- package/assets/fonts/hero-icons.ttf +0 -0
- package/babel.config.js +16 -0
- package/es/index.js +35840 -16325
- package/lib/assets/fonts/hero-icons.ttf +0 -0
- package/lib/index.js +35847 -16327
- package/package.json +9 -4
- package/rollup.config.js +1 -0
- package/src/components/Accordion/AccordionItem.tsx +50 -0
- package/src/components/Accordion/StyledAccordion.tsx +29 -0
- package/src/components/Accordion/__tests__/AccordionItem.spec.tsx +56 -0
- package/src/components/Accordion/__tests__/StyledAccordion.spec.tsx +17 -0
- package/src/components/Accordion/__tests__/__snapshots__/AccordionItem.spec.tsx.snap +529 -0
- package/src/components/Accordion/__tests__/__snapshots__/StyledAccordion.spec.tsx.snap +33 -0
- package/src/components/Accordion/__tests__/__snapshots__/index.spec.tsx.snap +822 -0
- package/src/components/Accordion/__tests__/index.spec.tsx +54 -0
- package/src/components/Accordion/index.tsx +82 -0
- package/src/components/Accordion/utils.tsx +11 -0
- package/src/components/Button/Button.tsx +64 -60
- package/src/components/Button/IconButton.tsx +1 -1
- 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/Calendar/CalendarRowItem.tsx +54 -0
- package/src/components/Calendar/StyledCalendar.tsx +76 -0
- package/src/components/Calendar/__tests__/CalendarRowItem.spec.tsx +76 -0
- package/src/components/Calendar/__tests__/__snapshots__/CalendarRowItem.spec.tsx.snap +411 -0
- package/src/components/Calendar/__tests__/helper.spec.ts +50 -0
- package/src/components/Calendar/__tests__/index.spec.tsx +99 -0
- package/src/components/Calendar/helpers.ts +29 -0
- package/src/components/Calendar/index.tsx +217 -0
- package/src/components/Collapse/index.tsx +13 -15
- package/src/components/ContentNavigator/index.tsx +6 -0
- 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/Empty/StyledEmpty.tsx +47 -0
- package/src/components/Empty/__tests__/__snapshots__/index.spec.tsx.snap +66 -0
- package/src/components/Empty/__tests__/index.spec.tsx +17 -0
- package/src/components/Empty/index.tsx +53 -0
- package/src/components/FAB/ActionGroup/ActionItem.tsx +6 -2
- package/src/components/FAB/ActionGroup/StyledActionGroup.tsx +1 -0
- package/src/components/FAB/ActionGroup/StyledActionItem.tsx +7 -1
- package/src/components/FAB/ActionGroup/__tests__/__snapshots__/index.spec.tsx.snap +84 -22
- package/src/components/FAB/ActionGroup/index.tsx +8 -1
- package/src/components/Icon/HeroIcon/selection.json +1 -1
- package/src/components/Icon/IconList.ts +13 -0
- package/src/components/List/BasicListItem.tsx +44 -34
- package/src/components/List/ListItem.tsx +67 -58
- package/src/components/List/StyledBasicListItem.tsx +2 -3
- package/src/components/List/StyledListItem.tsx +2 -2
- package/src/components/List/__tests__/StyledBasicListItem.spec.tsx +5 -2
- package/src/components/List/__tests__/StyledListItem.spec.tsx +4 -1
- package/src/components/List/__tests__/__snapshots__/BasicListItem.spec.tsx.snap +15 -10
- package/src/components/List/__tests__/__snapshots__/ListItem.spec.tsx.snap +52 -32
- package/src/components/List/__tests__/__snapshots__/StyledBasicListItem.spec.tsx.snap +128 -48
- package/src/components/List/__tests__/__snapshots__/StyledListItem.spec.tsx.snap +132 -52
- package/src/components/RichTextEditor/EditorEvent.ts +7 -0
- package/src/components/RichTextEditor/EditorToolbar.tsx +220 -0
- package/src/components/RichTextEditor/MentionList.tsx +69 -0
- package/src/components/RichTextEditor/RichTextEditor.tsx +396 -0
- package/src/components/RichTextEditor/StyledRichTextEditor.ts +20 -0
- package/src/components/RichTextEditor/StyledToolbar.ts +32 -0
- package/src/components/RichTextEditor/__tests__/EditorToolbar.spec.tsx +130 -0
- package/src/components/RichTextEditor/__tests__/MentionList.spec.tsx +109 -0
- package/src/components/RichTextEditor/__tests__/RichTextEditor.spec.tsx +245 -0
- package/src/components/RichTextEditor/__tests__/__snapshots__/EditorToolbar.spec.tsx.snap +324 -0
- package/src/components/RichTextEditor/__tests__/__snapshots__/MentionList.spec.tsx.snap +45 -0
- package/src/components/RichTextEditor/__tests__/__snapshots__/RichTextEditor.spec.tsx.snap +526 -0
- package/src/components/RichTextEditor/constants.ts +20 -0
- package/src/components/RichTextEditor/hero-editor.d.ts +8 -0
- package/src/components/RichTextEditor/index.tsx +8 -0
- package/src/components/RichTextEditor/utils/events.ts +31 -0
- package/src/components/RichTextEditor/utils/rnWebView.ts +19 -0
- package/src/components/SectionHeading/__tests__/__snapshots__/index.spec.tsx.snap +77 -0
- package/src/components/SectionHeading/__tests__/index.spec.tsx +14 -0
- package/src/components/SectionHeading/index.tsx +16 -9
- package/src/components/Tag/StyledTag.tsx +12 -2
- package/src/components/Tag/__tests__/Tag.spec.tsx +35 -8
- package/src/components/Tag/__tests__/__snapshots__/Tag.spec.tsx.snap +118 -4
- package/src/components/Tag/index.tsx +9 -2
- package/src/components/TextInput/__tests__/__snapshots__/StyledTextInput.spec.tsx.snap +1 -0
- package/src/components/TimePicker/TimePickerIOS.tsx +1 -1
- package/src/components/TimePicker/types.ts +1 -1
- package/src/components/Typography/Text/StyledText.tsx +2 -1
- package/src/components/Typography/Text/__tests__/StyledText.spec.tsx +1 -0
- package/src/components/Typography/Text/__tests__/__snapshots__/StyledText.spec.tsx.snap +22 -0
- package/src/components/Typography/Text/index.tsx +2 -1
- package/src/index.ts +10 -0
- package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +119 -4
- package/src/theme/components/accordion.ts +19 -0
- package/src/theme/components/button.ts +12 -0
- package/src/theme/components/calendar.ts +34 -0
- package/src/theme/components/card.ts +1 -1
- package/src/theme/components/datePicker.ts +11 -0
- package/src/theme/components/empty.ts +38 -0
- package/src/theme/components/fab.ts +4 -3
- package/src/theme/components/list.ts +1 -0
- package/src/theme/components/pinInput.ts +1 -1
- package/src/theme/components/richTextEditor.ts +34 -0
- package/src/theme/components/tag.ts +8 -2
- package/src/theme/components/typography.ts +1 -0
- package/src/theme/global/borders.ts +6 -6
- package/src/theme/global/colors.ts +5 -1
- package/src/theme/index.ts +15 -0
- package/testUtils/setup.tsx +17 -0
- package/types/components/Accordion/AccordionItem.d.ts +14 -0
- package/types/components/Accordion/StyledAccordion.d.ts +32 -0
- package/types/components/Accordion/__tests__/AccordionItem.spec.d.ts +1 -0
- package/types/components/Accordion/__tests__/StyledAccordion.spec.d.ts +1 -0
- package/types/components/Accordion/__tests__/index.spec.d.ts +1 -0
- package/types/components/Accordion/index.d.ts +38 -0
- package/types/components/Accordion/utils.d.ts +1 -0
- package/types/components/Button/IconButton.d.ts +1 -1
- package/types/components/Button/StyledButton.d.ts +3 -3
- package/types/components/Calendar/CalendarRowItem.d.ts +10 -0
- package/types/components/Calendar/StyledCalendar.d.ts +54 -0
- package/types/components/Calendar/__tests__/CalendarRowItem.spec.d.ts +1 -0
- package/types/components/Calendar/__tests__/helper.spec.d.ts +1 -0
- package/types/components/Calendar/__tests__/index.spec.d.ts +1 -0
- package/types/components/Calendar/helpers.d.ts +3 -0
- package/types/components/Calendar/index.d.ts +40 -0
- package/types/components/Collapse/index.d.ts +1 -1
- package/types/components/ContentNavigator/index.d.ts +5 -1
- 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/Empty/StyledEmpty.d.ts +31 -0
- package/types/components/Empty/__tests__/index.spec.d.ts +1 -0
- package/types/components/Empty/index.d.ts +26 -0
- package/types/components/FAB/ActionGroup/StyledActionItem.d.ts +6 -1
- package/types/components/FAB/ActionGroup/index.d.ts +6 -1
- package/types/components/FAB/index.d.ts +1 -1
- package/types/components/Icon/IconList.d.ts +1 -1
- package/types/components/Icon/utils.d.ts +1 -1
- package/types/components/List/StyledBasicListItem.d.ts +3 -3
- package/types/components/List/StyledListItem.d.ts +3 -3
- package/types/components/RichTextEditor/EditorEvent.d.ts +3 -0
- package/types/components/RichTextEditor/EditorToolbar.d.ts +17 -0
- package/types/components/RichTextEditor/MentionList.d.ts +12 -0
- package/types/components/RichTextEditor/RichTextEditor.d.ts +65 -0
- package/types/components/RichTextEditor/StyledRichTextEditor.d.ts +16 -0
- package/types/components/RichTextEditor/StyledToolbar.d.ts +21 -0
- package/types/components/RichTextEditor/__tests__/EditorToolbar.spec.d.ts +1 -0
- package/types/components/RichTextEditor/__tests__/MentionList.spec.d.ts +1 -0
- package/types/components/RichTextEditor/__tests__/RichTextEditor.spec.d.ts +1 -0
- package/types/components/RichTextEditor/constants.d.ts +19 -0
- package/types/components/RichTextEditor/index.d.ts +5 -0
- package/types/components/RichTextEditor/utils/events.d.ts +8 -0
- package/types/components/RichTextEditor/utils/rnWebView.d.ts +7 -0
- package/types/components/SectionHeading/index.d.ts +2 -2
- package/types/components/Select/MultiSelect/OptionList.d.ts +1 -1
- package/types/components/Select/SingleSelect/OptionList.d.ts +1 -1
- package/types/components/Tag/StyledTag.d.ts +1 -1
- package/types/components/Tag/index.d.ts +1 -1
- package/types/components/TimePicker/types.d.ts +1 -1
- package/types/components/Typography/Text/StyledText.d.ts +1 -1
- package/types/components/Typography/Text/index.d.ts +1 -1
- package/types/index.d.ts +6 -1
- package/types/theme/components/accordion.d.ts +13 -0
- package/types/theme/components/button.d.ts +12 -0
- package/types/theme/components/calendar.d.ts +26 -0
- package/types/theme/components/datePicker.d.ts +6 -0
- package/types/theme/components/empty.d.ts +28 -0
- package/types/theme/components/fab.d.ts +1 -0
- package/types/theme/components/list.d.ts +1 -0
- package/types/theme/components/richTextEditor.d.ts +26 -0
- package/types/theme/components/tag.d.ts +8 -2
- package/types/theme/components/typography.d.ts +1 -0
- package/types/theme/global/colors.d.ts +5 -1
- package/types/theme/global/index.d.ts +5 -1
- package/types/theme/index.d.ts +10 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
3
|
+
import Typography from '../../Typography';
|
|
4
|
+
import Accordion, { AccordionProps } from '..';
|
|
5
|
+
|
|
6
|
+
const AccordionExample = (props: Omit<AccordionProps<string>, 'items'>) => (
|
|
7
|
+
<Accordion
|
|
8
|
+
items={[
|
|
9
|
+
{
|
|
10
|
+
header: 'Accordion header 1',
|
|
11
|
+
content: <Typography.Text>Accordion content 1</Typography.Text>,
|
|
12
|
+
key: 'acc1',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
header: 'Accordion header 2',
|
|
16
|
+
content: <Typography.Text>Accordion content 2</Typography.Text>,
|
|
17
|
+
key: 'acc2',
|
|
18
|
+
},
|
|
19
|
+
]}
|
|
20
|
+
{...props}
|
|
21
|
+
/>
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const ControlledAccordionExample = () => {
|
|
25
|
+
const [activeItem, setActiveItem] = React.useState('acc2');
|
|
26
|
+
return (
|
|
27
|
+
<AccordionExample activeItemKey={activeItem} onItemPress={setActiveItem} />
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
describe('Accordion', () => {
|
|
32
|
+
it('renders correctly', () => {
|
|
33
|
+
const wrapper = renderWithTheme(<AccordionExample />);
|
|
34
|
+
|
|
35
|
+
expect(wrapper.getAllByText('Accordion header 1')).toHaveLength(1);
|
|
36
|
+
expect(wrapper.getAllByText('Accordion header 2')).toHaveLength(1);
|
|
37
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('allows fully controlled', () => {
|
|
41
|
+
const wrapper = renderWithTheme(<ControlledAccordionExample />);
|
|
42
|
+
|
|
43
|
+
expect(wrapper.getAllByText('Accordion header 1')).toHaveLength(1);
|
|
44
|
+
expect(wrapper.getAllByText('Accordion header 2')).toHaveLength(1);
|
|
45
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('renders correctly when variant is card', () => {
|
|
49
|
+
const wrapper = renderWithTheme(<AccordionExample variant="card" />);
|
|
50
|
+
|
|
51
|
+
expect(wrapper.getAllByTestId('accordion-spacer')).toHaveLength(1);
|
|
52
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import React, { Key, ReactElement, useMemo } from 'react';
|
|
2
|
+
import { StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
import AccordionItem from './AccordionItem';
|
|
4
|
+
import { Spacer, StyledWrapper } from './StyledAccordion';
|
|
5
|
+
import { usePropsOrInternalState } from './utils';
|
|
6
|
+
|
|
7
|
+
export interface AccordionProps<K extends Key> {
|
|
8
|
+
/**
|
|
9
|
+
* List of accordion items to be rendered. Each item must have an unique key.
|
|
10
|
+
*/
|
|
11
|
+
items: {
|
|
12
|
+
header: string | ReactElement;
|
|
13
|
+
content: ReactElement;
|
|
14
|
+
key: K;
|
|
15
|
+
style?: StyleProp<ViewStyle>;
|
|
16
|
+
testID?: string;
|
|
17
|
+
}[];
|
|
18
|
+
/**
|
|
19
|
+
* Key of the active item.
|
|
20
|
+
* When activeItemKey and onItemPress is passed, the component is fully controlled.
|
|
21
|
+
* Otherwise, it would be uncontrolled.
|
|
22
|
+
*/
|
|
23
|
+
activeItemKey?: K;
|
|
24
|
+
/**
|
|
25
|
+
* Callback invoked when an item is pressed.
|
|
26
|
+
*/
|
|
27
|
+
onItemPress?: (key: K) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Item type.
|
|
30
|
+
*/
|
|
31
|
+
variant?: 'default' | 'card';
|
|
32
|
+
/**
|
|
33
|
+
* Additional style.
|
|
34
|
+
*/
|
|
35
|
+
style?: StyleProp<ViewStyle>;
|
|
36
|
+
/**
|
|
37
|
+
* Testing id of the component.
|
|
38
|
+
*/
|
|
39
|
+
testID?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const Accordion = <K extends Key>({
|
|
43
|
+
items,
|
|
44
|
+
activeItemKey,
|
|
45
|
+
onItemPress,
|
|
46
|
+
variant = 'default',
|
|
47
|
+
style,
|
|
48
|
+
testID,
|
|
49
|
+
}: AccordionProps<K>) => {
|
|
50
|
+
const defaultValue = useMemo(
|
|
51
|
+
() => (typeof activeItemKey === 'number' ? NaN : '') as K,
|
|
52
|
+
[activeItemKey]
|
|
53
|
+
);
|
|
54
|
+
const [_activeItemKey, _onItemPress] = usePropsOrInternalState<K>(
|
|
55
|
+
defaultValue,
|
|
56
|
+
activeItemKey,
|
|
57
|
+
onItemPress
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<StyledWrapper style={style} testID={testID}>
|
|
62
|
+
{items.map(({ key, ...props }, index) => {
|
|
63
|
+
const open = _activeItemKey === key;
|
|
64
|
+
return (
|
|
65
|
+
<React.Fragment key={key}>
|
|
66
|
+
{variant === 'card' && index !== 0 && (
|
|
67
|
+
<Spacer testID="accordion-spacer" />
|
|
68
|
+
)}
|
|
69
|
+
<AccordionItem
|
|
70
|
+
{...props}
|
|
71
|
+
open={open}
|
|
72
|
+
onPress={() => _onItemPress(open ? defaultValue : key)}
|
|
73
|
+
variant={variant}
|
|
74
|
+
/>
|
|
75
|
+
</React.Fragment>
|
|
76
|
+
);
|
|
77
|
+
})}
|
|
78
|
+
</StyledWrapper>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export default Accordion;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export function usePropsOrInternalState<T>(
|
|
4
|
+
initialState: T,
|
|
5
|
+
state: T | undefined,
|
|
6
|
+
setState: ((val: T) => void) | undefined
|
|
7
|
+
): [T, (val: T) => void] {
|
|
8
|
+
const [internalState, setInternalState] = React.useState<T>(initialState);
|
|
9
|
+
|
|
10
|
+
return [state || internalState, setState || setInternalState];
|
|
11
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { useTheme } from '@emotion/react';
|
|
1
2
|
import React, { ReactChild } from 'react';
|
|
2
|
-
import {
|
|
3
|
+
import { StyleProp, ViewStyle } from 'react-native';
|
|
3
4
|
|
|
4
5
|
import { IconName } from '../Icon';
|
|
5
6
|
import LoadingIndicator from './LoadingIndicator';
|
|
@@ -110,64 +111,67 @@ const Button = ({
|
|
|
110
111
|
testID,
|
|
111
112
|
text,
|
|
112
113
|
variant = 'filled',
|
|
113
|
-
}: ButtonProps) =>
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
{
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
)
|
|
114
|
+
}: ButtonProps): JSX.Element => {
|
|
115
|
+
const [pressed, setPressed] = React.useState(false);
|
|
116
|
+
const theme = useTheme();
|
|
117
|
+
const themeVariant = getThemeVariant(variant, intent);
|
|
118
|
+
return (
|
|
119
|
+
<StyledButtonContainer
|
|
120
|
+
onShowUnderlay={() => setPressed(true)}
|
|
121
|
+
onHideUnderlay={() => setPressed(false)}
|
|
122
|
+
underlayColor={theme.__hd__.button.colors.underlayColors[themeVariant]}
|
|
123
|
+
accessibilityHint={accessibilityHint}
|
|
124
|
+
accessibilityLabel={accessibilityLabel}
|
|
125
|
+
disabled={disabled || loading}
|
|
126
|
+
activeOpacity={0.5}
|
|
127
|
+
onPress={onPress}
|
|
128
|
+
testID={testID}
|
|
129
|
+
pressed={pressed}
|
|
130
|
+
themeVariant={themeVariant}
|
|
131
|
+
style={style}
|
|
132
|
+
>
|
|
133
|
+
{loading === true ? (
|
|
134
|
+
<LoadingIndicator
|
|
135
|
+
testID={`${testID}-loading-indicator`}
|
|
136
|
+
themeVariant={themeVariant}
|
|
137
|
+
/>
|
|
138
|
+
) : (
|
|
139
|
+
<>
|
|
140
|
+
{icon !== undefined && (
|
|
141
|
+
<StyledButtonIconWrapper themePosition="left">
|
|
142
|
+
<StyledButtonIcon
|
|
143
|
+
disabled={disabled}
|
|
144
|
+
icon={icon}
|
|
145
|
+
pressed={pressed}
|
|
146
|
+
testID={`${testID}-left-icon`}
|
|
147
|
+
themeVariant={themeVariant}
|
|
148
|
+
/>
|
|
149
|
+
</StyledButtonIconWrapper>
|
|
150
|
+
)}
|
|
151
|
+
<StyledButtonText
|
|
152
|
+
disabled={disabled}
|
|
153
|
+
ellipsizeMode="tail"
|
|
154
|
+
numberOfLines={1}
|
|
155
|
+
pressed={pressed}
|
|
156
|
+
themeVariant={themeVariant}
|
|
157
|
+
>
|
|
158
|
+
{text}
|
|
159
|
+
</StyledButtonText>
|
|
160
|
+
{rightIcon !== undefined && (
|
|
161
|
+
<StyledButtonIconWrapper themePosition="right">
|
|
162
|
+
<StyledButtonIcon
|
|
163
|
+
disabled={disabled}
|
|
164
|
+
icon={rightIcon}
|
|
165
|
+
pressed={pressed}
|
|
166
|
+
testID={`${testID}-right-icon`}
|
|
167
|
+
themeVariant={themeVariant}
|
|
168
|
+
/>
|
|
169
|
+
</StyledButtonIconWrapper>
|
|
170
|
+
)}
|
|
171
|
+
</>
|
|
172
|
+
)}
|
|
173
|
+
</StyledButtonContainer>
|
|
174
|
+
);
|
|
175
|
+
};
|
|
172
176
|
|
|
173
177
|
export default Button;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { View } from 'react-native';
|
|
1
|
+
import { TouchableHighlight, View } from 'react-native';
|
|
2
2
|
import styled, { ReactNativeStyle } from '@emotion/native';
|
|
3
3
|
import { Theme } from '@emotion/react';
|
|
4
4
|
|
|
@@ -79,10 +79,10 @@ const genFilledContainerStyles = (
|
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
return {
|
|
82
|
-
width: '100%',
|
|
83
82
|
flexDirection: 'row',
|
|
84
83
|
justifyContent: 'center',
|
|
85
84
|
alignItems: 'center',
|
|
85
|
+
alignSelf: 'stretch',
|
|
86
86
|
padding: theme.__hd__.button.space.buttonPadding,
|
|
87
87
|
borderRadius: theme.__hd__.button.radii.default,
|
|
88
88
|
...backgroundColorStyling(),
|
|
@@ -112,10 +112,10 @@ const genOutlineContainerStyles = (
|
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
return {
|
|
115
|
-
width: '100%',
|
|
116
115
|
flexDirection: 'row',
|
|
117
116
|
justifyContent: 'center',
|
|
118
117
|
alignItems: 'center',
|
|
118
|
+
alignSelf: 'stretch',
|
|
119
119
|
padding:
|
|
120
120
|
theme.__hd__.button.space.buttonPadding -
|
|
121
121
|
theme.__hd__.button.borderWidth.default,
|
|
@@ -184,7 +184,7 @@ const genTextVariantTextStyles = (
|
|
|
184
184
|
};
|
|
185
185
|
};
|
|
186
186
|
|
|
187
|
-
const StyledButtonContainer = styled(
|
|
187
|
+
const StyledButtonContainer = styled(TouchableHighlight)<{
|
|
188
188
|
disabled?: boolean;
|
|
189
189
|
pressed?: boolean;
|
|
190
190
|
themeVariant: ThemeVariant;
|
|
@@ -208,13 +208,11 @@ const StyledButtonContainer = styled(View)<{
|
|
|
208
208
|
case 'text-secondary':
|
|
209
209
|
case 'text-danger':
|
|
210
210
|
return {
|
|
211
|
-
width: '100%',
|
|
212
211
|
flexDirection: 'row',
|
|
213
212
|
justifyContent: 'center',
|
|
214
213
|
alignItems: 'center',
|
|
215
214
|
padding: theme.__hd__.button.space.buttonPadding,
|
|
216
215
|
borderWidth: 0,
|
|
217
|
-
backgroundColor: 'transparent',
|
|
218
216
|
};
|
|
219
217
|
}
|
|
220
218
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
+
import { Text } from 'react-native';
|
|
3
4
|
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
4
5
|
|
|
5
6
|
import {
|
|
@@ -22,9 +23,11 @@ describe('StyledButtonContainer', () => {
|
|
|
22
23
|
${'text-primary'}
|
|
23
24
|
${'text-secondary'}
|
|
24
25
|
${'text-danger'}
|
|
25
|
-
`('has $themeVariant style', ({ themeVariant }) => {
|
|
26
|
+
`('has $themeVariant style', ({ themeVariant }): void => {
|
|
26
27
|
const { toJSON } = renderWithTheme(
|
|
27
|
-
<StyledButtonContainer themeVariant={themeVariant}
|
|
28
|
+
<StyledButtonContainer themeVariant={themeVariant}>
|
|
29
|
+
<Text>Title</Text>
|
|
30
|
+
</StyledButtonContainer>
|
|
28
31
|
);
|
|
29
32
|
|
|
30
33
|
expect(toJSON()).toMatchSnapshot();
|
|
@@ -46,7 +49,9 @@ describe('StyledButtonContainer', () => {
|
|
|
46
49
|
'has pressed with the correct variant $themeVariant style',
|
|
47
50
|
({ themeVariant }) => {
|
|
48
51
|
const { toJSON } = renderWithTheme(
|
|
49
|
-
<StyledButtonContainer themeVariant={themeVariant} pressed
|
|
52
|
+
<StyledButtonContainer themeVariant={themeVariant} pressed>
|
|
53
|
+
<Text>Title</Text>
|
|
54
|
+
</StyledButtonContainer>
|
|
50
55
|
);
|
|
51
56
|
expect(toJSON()).toMatchSnapshot();
|
|
52
57
|
}
|
|
@@ -54,7 +59,9 @@ describe('StyledButtonContainer', () => {
|
|
|
54
59
|
|
|
55
60
|
it('renders disabled correctly', () => {
|
|
56
61
|
const { toJSON } = renderWithTheme(
|
|
57
|
-
<StyledButtonContainer themeVariant="filled-primary" disabled
|
|
62
|
+
<StyledButtonContainer themeVariant="filled-primary" disabled>
|
|
63
|
+
<Text>Title</Text>
|
|
64
|
+
</StyledButtonContainer>
|
|
58
65
|
);
|
|
59
66
|
|
|
60
67
|
expect(toJSON()).toMatchSnapshot();
|