@hero-design/rn 7.20.0 → 7.21.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 +1 -0
- package/.turbo/turbo-build.log +2 -2
- package/es/index.js +410 -285
- package/lib/index.js +410 -282
- package/package.json +4 -2
- package/rollup.config.js +1 -0
- package/src/components/BottomSheet/index.tsx +6 -1
- package/src/components/Checkbox/__tests__/__snapshots__/StyledCheckbox.spec.tsx.snap +4 -4
- package/src/components/Checkbox/__tests__/__snapshots__/index.spec.tsx.snap +13 -13
- package/src/components/Empty/StyledEmpty.tsx +1 -9
- package/src/components/Empty/__tests__/__snapshots__/index.spec.tsx.snap +58 -5
- package/src/components/Empty/__tests__/index.spec.tsx +13 -0
- package/src/components/Empty/index.tsx +38 -18
- package/src/components/Image/__tests__/__snapshots__/index.spec.tsx.snap +81 -0
- package/src/components/Image/__tests__/index.spec.tsx +29 -0
- package/src/components/Image/index.tsx +46 -0
- package/src/components/List/__tests__/__snapshots__/ListItem.spec.tsx.snap +5 -5
- package/src/components/Progress/__tests__/__snapshots__/index.spec.js.snap +60 -60
- package/src/components/RichTextEditor/EditorToolbar.tsx +19 -18
- package/src/components/RichTextEditor/RichTextEditor.tsx +7 -2
- package/src/components/RichTextEditor/StyledRichTextEditor.ts +0 -2
- package/src/components/RichTextEditor/__tests__/RichTextEditor.spec.tsx +7 -4
- package/src/components/RichTextEditor/__tests__/__snapshots__/EditorToolbar.spec.tsx.snap +2 -2
- package/src/components/RichTextEditor/__tests__/__snapshots__/RichTextEditor.spec.tsx.snap +4 -12
- package/src/components/RichTextEditor/constants.ts +0 -11
- package/src/components/RichTextEditor/index.tsx +0 -3
- package/src/components/RichTextEditor/types.ts +9 -0
- package/src/components/Select/MultiSelect/OptionList.tsx +4 -6
- package/src/components/Select/MultiSelect/__tests__/index.spec.tsx +21 -0
- package/src/components/Select/MultiSelect/index.tsx +33 -3
- package/src/components/Select/SingleSelect/OptionList.tsx +4 -5
- package/src/components/Select/SingleSelect/__tests__/index.spec.tsx +16 -0
- package/src/components/Select/SingleSelect/index.tsx +34 -4
- package/src/components/Select/StyledOptionList.tsx +3 -9
- package/src/components/Slider/__tests__/__snapshots__/index.spec.tsx.snap +43 -0
- package/src/components/Slider/__tests__/index.spec.tsx +33 -0
- package/src/components/Slider/index.tsx +89 -0
- package/src/components/Switch/StyledSwitch.tsx +4 -4
- package/src/components/Switch/__tests__/__snapshots__/StyledSwitch.spec.tsx.snap +10 -10
- package/src/components/Switch/__tests__/__snapshots__/index.spec.tsx.snap +8 -8
- package/src/components/Switch/index.tsx +5 -4
- package/src/components/TextInput/index.tsx +43 -37
- package/src/index.ts +4 -0
- package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +56 -11
- package/src/theme/components/alert.ts +1 -2
- package/src/theme/components/avatar.ts +8 -8
- package/src/theme/components/badge.ts +4 -4
- package/src/theme/components/bottomNavigation.ts +1 -1
- package/src/theme/components/bottomSheet.ts +2 -3
- package/src/theme/components/calendar.ts +9 -7
- package/src/theme/components/card.ts +1 -1
- package/src/theme/components/checkbox.ts +2 -5
- package/src/theme/components/datePicker.ts +3 -3
- package/src/theme/components/drawer.ts +2 -3
- package/src/theme/components/empty.ts +3 -8
- package/src/theme/components/fab.ts +2 -2
- package/src/theme/components/image.ts +12 -0
- package/src/theme/components/pinInput.ts +3 -3
- package/src/theme/components/progress.ts +2 -3
- package/src/theme/components/radio.ts +7 -3
- package/src/theme/components/richTextEditor.ts +4 -4
- package/src/theme/components/slider.ts +13 -0
- package/src/theme/components/switch.ts +16 -1
- package/src/theme/components/tabs.ts +1 -1
- package/src/theme/components/timePicker.ts +3 -3
- package/src/theme/components/toast.ts +1 -2
- package/src/theme/getTheme.ts +9 -2
- package/src/theme/global/colors/swag.ts +2 -0
- package/src/theme/global/colors/types.ts +2 -0
- package/src/theme/global/index.ts +3 -0
- package/src/theme/global/scale.ts +3 -0
- package/src/theme/global/sizes.ts +29 -0
- package/src/types.ts +0 -2
- package/testUtils/setup.tsx +14 -0
- package/types/components/BottomSheet/index.d.ts +5 -1
- package/types/components/Empty/StyledEmpty.d.ts +1 -7
- package/types/components/Empty/index.d.ts +8 -2
- package/types/components/Image/__tests__/index.spec.d.ts +1 -0
- package/types/components/Image/index.d.ts +17 -0
- package/types/components/RichTextEditor/EditorToolbar.d.ts +1 -1
- package/types/components/RichTextEditor/RichTextEditor.d.ts +4 -0
- package/types/components/RichTextEditor/constants.d.ts +0 -10
- package/types/components/RichTextEditor/index.d.ts +0 -2
- package/types/components/RichTextEditor/types.d.ts +1 -0
- package/types/components/Select/MultiSelect/OptionList.d.ts +5 -2
- package/types/components/Select/MultiSelect/index.d.ts +7 -1
- package/types/components/Select/SingleSelect/OptionList.d.ts +5 -2
- package/types/components/Select/SingleSelect/index.d.ts +8 -2
- package/types/components/Select/StyledOptionList.d.ts +4 -3
- package/types/components/Select/index.d.ts +1 -1
- package/types/components/Slider/__tests__/index.spec.d.ts +1 -0
- package/types/components/Slider/index.d.ts +52 -0
- package/types/components/TextInput/index.d.ts +2 -1
- package/types/index.d.ts +3 -1
- package/types/theme/components/datePicker.d.ts +2 -1
- package/types/theme/components/empty.d.ts +2 -5
- package/types/theme/components/image.d.ts +8 -0
- package/types/theme/components/slider.d.ts +9 -0
- package/types/theme/components/switch.d.ts +14 -1
- package/types/theme/components/timePicker.d.ts +2 -1
- package/types/theme/getTheme.d.ts +4 -0
- package/types/theme/global/colors/types.d.ts +2 -0
- package/types/theme/global/index.d.ts +3 -0
- package/types/theme/global/scale.d.ts +1 -0
- package/types/theme/global/sizes.d.ts +14 -0
- package/types/types.d.ts +1 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hero-design/rn",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.21.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -20,13 +20,14 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@emotion/native": "^11.9.3",
|
|
22
22
|
"@emotion/react": "^11.9.3",
|
|
23
|
-
"@hero-design/colors": "7.
|
|
23
|
+
"@hero-design/colors": "7.21.0",
|
|
24
24
|
"date-fns": "^2.16.1",
|
|
25
25
|
"events": "^3.2.0",
|
|
26
26
|
"hero-editor": "^1.9.9"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@react-native-community/datetimepicker": "^3.5.2",
|
|
30
|
+
"@react-native-community/slider": "4.1.12",
|
|
30
31
|
"react": "17.0.2",
|
|
31
32
|
"react-native": "0.65.1",
|
|
32
33
|
"react-native-pager-view": "^5.4.25",
|
|
@@ -42,6 +43,7 @@
|
|
|
42
43
|
"@babel/runtime": "^7.18.9",
|
|
43
44
|
"@emotion/jest": "^11.9.3",
|
|
44
45
|
"@react-native-community/datetimepicker": "^3.5.2",
|
|
46
|
+
"@react-native-community/slider": "4.1.12",
|
|
45
47
|
"@rollup/plugin-babel": "^5.3.1",
|
|
46
48
|
"@rollup/plugin-commonjs": "^21.0.1",
|
|
47
49
|
"@rollup/plugin-json": "^4.1.0",
|
package/rollup.config.js
CHANGED
|
@@ -27,6 +27,10 @@ interface BottomSheetProps {
|
|
|
27
27
|
* Bottom sheet's content.
|
|
28
28
|
*/
|
|
29
29
|
children?: ReactNode;
|
|
30
|
+
/**
|
|
31
|
+
* Callback is called when the Bottom Sheet finishes running animation.
|
|
32
|
+
*/
|
|
33
|
+
onAnimationEnd?: () => void;
|
|
30
34
|
/**
|
|
31
35
|
* Callback is called when the Bottom Sheet is opened.
|
|
32
36
|
*/
|
|
@@ -67,6 +71,7 @@ const BottomSheet = ({
|
|
|
67
71
|
header,
|
|
68
72
|
footer,
|
|
69
73
|
children,
|
|
74
|
+
onAnimationEnd,
|
|
70
75
|
onOpen,
|
|
71
76
|
onRequestClose,
|
|
72
77
|
onDismiss,
|
|
@@ -109,7 +114,7 @@ const BottomSheet = ({
|
|
|
109
114
|
useNativeDriver: true,
|
|
110
115
|
});
|
|
111
116
|
|
|
112
|
-
animation.start();
|
|
117
|
+
animation.start(onAnimationEnd);
|
|
113
118
|
|
|
114
119
|
return () => animation.stop();
|
|
115
120
|
}, [open]);
|
|
@@ -9,10 +9,10 @@ exports[`StyledCheckbox renders correctly when disabled is false 1`] = `
|
|
|
9
9
|
"borderRadius": 4,
|
|
10
10
|
"borderWidth": 2,
|
|
11
11
|
"flexDirection": "row",
|
|
12
|
-
"height":
|
|
12
|
+
"height": 24,
|
|
13
13
|
"justifyContent": "center",
|
|
14
14
|
"overflow": "hidden",
|
|
15
|
-
"width":
|
|
15
|
+
"width": 24,
|
|
16
16
|
},
|
|
17
17
|
undefined,
|
|
18
18
|
]
|
|
@@ -30,10 +30,10 @@ exports[`StyledCheckbox renders correctly when disabled is true 1`] = `
|
|
|
30
30
|
"borderRadius": 4,
|
|
31
31
|
"borderWidth": 2,
|
|
32
32
|
"flexDirection": "row",
|
|
33
|
-
"height":
|
|
33
|
+
"height": 24,
|
|
34
34
|
"justifyContent": "center",
|
|
35
35
|
"overflow": "hidden",
|
|
36
|
-
"width":
|
|
36
|
+
"width": 24,
|
|
37
37
|
},
|
|
38
38
|
undefined,
|
|
39
39
|
]
|
|
@@ -28,10 +28,10 @@ exports[`Checkbox renders correctly when checked is false and there is no descri
|
|
|
28
28
|
"borderRadius": 4,
|
|
29
29
|
"borderWidth": 2,
|
|
30
30
|
"flexDirection": "row",
|
|
31
|
-
"height":
|
|
31
|
+
"height": 24,
|
|
32
32
|
"justifyContent": "center",
|
|
33
33
|
"overflow": "hidden",
|
|
34
|
-
"width":
|
|
34
|
+
"width": 24,
|
|
35
35
|
},
|
|
36
36
|
undefined,
|
|
37
37
|
]
|
|
@@ -69,10 +69,10 @@ exports[`Checkbox renders correctly when checked is true and there is no descrip
|
|
|
69
69
|
"borderRadius": 4,
|
|
70
70
|
"borderWidth": 2,
|
|
71
71
|
"flexDirection": "row",
|
|
72
|
-
"height":
|
|
72
|
+
"height": 24,
|
|
73
73
|
"justifyContent": "center",
|
|
74
74
|
"overflow": "hidden",
|
|
75
|
-
"width":
|
|
75
|
+
"width": 24,
|
|
76
76
|
},
|
|
77
77
|
undefined,
|
|
78
78
|
]
|
|
@@ -90,7 +90,7 @@ exports[`Checkbox renders correctly when checked is true and there is no descrip
|
|
|
90
90
|
Array [
|
|
91
91
|
Object {
|
|
92
92
|
"position": "absolute",
|
|
93
|
-
"top":
|
|
93
|
+
"top": 0,
|
|
94
94
|
},
|
|
95
95
|
undefined,
|
|
96
96
|
],
|
|
@@ -157,10 +157,10 @@ exports[`Checkbox renders correctly when disabled is false, withBorder is false
|
|
|
157
157
|
"borderRadius": 4,
|
|
158
158
|
"borderWidth": 2,
|
|
159
159
|
"flexDirection": "row",
|
|
160
|
-
"height":
|
|
160
|
+
"height": 24,
|
|
161
161
|
"justifyContent": "center",
|
|
162
162
|
"overflow": "hidden",
|
|
163
|
-
"width":
|
|
163
|
+
"width": 24,
|
|
164
164
|
},
|
|
165
165
|
undefined,
|
|
166
166
|
]
|
|
@@ -227,10 +227,10 @@ exports[`Checkbox renders correctly when disabled is false, withBorder is true 1
|
|
|
227
227
|
"borderRadius": 4,
|
|
228
228
|
"borderWidth": 2,
|
|
229
229
|
"flexDirection": "row",
|
|
230
|
-
"height":
|
|
230
|
+
"height": 24,
|
|
231
231
|
"justifyContent": "center",
|
|
232
232
|
"overflow": "hidden",
|
|
233
|
-
"width":
|
|
233
|
+
"width": 24,
|
|
234
234
|
},
|
|
235
235
|
undefined,
|
|
236
236
|
]
|
|
@@ -293,10 +293,10 @@ exports[`Checkbox renders correctly when disabled is true, withBorder is false 1
|
|
|
293
293
|
"borderRadius": 4,
|
|
294
294
|
"borderWidth": 2,
|
|
295
295
|
"flexDirection": "row",
|
|
296
|
-
"height":
|
|
296
|
+
"height": 24,
|
|
297
297
|
"justifyContent": "center",
|
|
298
298
|
"overflow": "hidden",
|
|
299
|
-
"width":
|
|
299
|
+
"width": 24,
|
|
300
300
|
},
|
|
301
301
|
undefined,
|
|
302
302
|
]
|
|
@@ -363,10 +363,10 @@ exports[`Checkbox renders correctly when disabled is true, withBorder is true 1`
|
|
|
363
363
|
"borderRadius": 4,
|
|
364
364
|
"borderWidth": 2,
|
|
365
365
|
"flexDirection": "row",
|
|
366
|
-
"height":
|
|
366
|
+
"height": 24,
|
|
367
367
|
"justifyContent": "center",
|
|
368
368
|
"overflow": "hidden",
|
|
369
|
-
"width":
|
|
369
|
+
"width": 24,
|
|
370
370
|
},
|
|
371
371
|
undefined,
|
|
372
372
|
]
|
|
@@ -12,14 +12,6 @@ const StyledWrapper = styled(View)(({ theme }) => ({
|
|
|
12
12
|
padding: theme.__hd__.empty.space.wrapperPadding,
|
|
13
13
|
}));
|
|
14
14
|
|
|
15
|
-
const StyledIllustration = styled(View)(({ theme }) => ({
|
|
16
|
-
height: theme.__hd__.empty.sizes.illustration,
|
|
17
|
-
width: theme.__hd__.empty.sizes.illustration,
|
|
18
|
-
borderRadius: theme.__hd__.empty.radii.illustration,
|
|
19
|
-
backgroundColor: theme.__hd__.empty.colors.illustrationBackground,
|
|
20
|
-
marginBottom: theme.__hd__.empty.space.illustrationMargin,
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
15
|
const StyledTitle = styled(Text)<{ themeVariant: ThemeVariant }>(
|
|
24
16
|
({ theme, themeVariant }) => ({
|
|
25
17
|
fontFamily: theme.__hd__.empty.fonts.title,
|
|
@@ -45,4 +37,4 @@ const StyledDescription = styled(Text)<{ themeVariant: ThemeVariant }>(
|
|
|
45
37
|
})
|
|
46
38
|
);
|
|
47
39
|
|
|
48
|
-
export { StyledWrapper,
|
|
40
|
+
export { StyledWrapper, StyledTitle, StyledDescription };
|
|
@@ -16,15 +16,68 @@ exports[`Empty renders empty state content correctly 1`] = `
|
|
|
16
16
|
]
|
|
17
17
|
}
|
|
18
18
|
>
|
|
19
|
-
<
|
|
19
|
+
<Text
|
|
20
|
+
style={
|
|
21
|
+
Array [
|
|
22
|
+
Object {
|
|
23
|
+
"color": "#001f23",
|
|
24
|
+
"fontFamily": "BeVietnamPro-SemiBold",
|
|
25
|
+
"fontSize": 28,
|
|
26
|
+
"marginBottom": 16,
|
|
27
|
+
"textAlign": "center",
|
|
28
|
+
},
|
|
29
|
+
undefined,
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
themeVariant="light"
|
|
33
|
+
>
|
|
34
|
+
You have no notification at this time
|
|
35
|
+
</Text>
|
|
36
|
+
<Text
|
|
37
|
+
style={
|
|
38
|
+
Array [
|
|
39
|
+
Object {
|
|
40
|
+
"color": "#4d6265",
|
|
41
|
+
"fontFamily": "BeVietnamPro-Light",
|
|
42
|
+
"fontSize": 16,
|
|
43
|
+
"textAlign": "center",
|
|
44
|
+
},
|
|
45
|
+
undefined,
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
themeVariant="light"
|
|
49
|
+
>
|
|
50
|
+
We'll notify you later.
|
|
51
|
+
</Text>
|
|
52
|
+
</View>
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
exports[`Empty renders empty state with image correctly 1`] = `
|
|
56
|
+
<View
|
|
57
|
+
style={
|
|
58
|
+
Array [
|
|
59
|
+
Object {
|
|
60
|
+
"alignItems": "center",
|
|
61
|
+
"display": "flex",
|
|
62
|
+
"flex": 1,
|
|
63
|
+
"flexDirection": "column",
|
|
64
|
+
"justifyContent": "center",
|
|
65
|
+
"padding": 16,
|
|
66
|
+
},
|
|
67
|
+
undefined,
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
>
|
|
71
|
+
<Image
|
|
72
|
+
source={
|
|
73
|
+
Object {
|
|
74
|
+
"uri": "path_to_image",
|
|
75
|
+
}
|
|
76
|
+
}
|
|
20
77
|
style={
|
|
21
78
|
Array [
|
|
22
79
|
Object {
|
|
23
|
-
"backgroundColor": "#ccced1",
|
|
24
|
-
"borderRadius": 999,
|
|
25
|
-
"height": 168,
|
|
26
80
|
"marginBottom": 24,
|
|
27
|
-
"width": 168,
|
|
28
81
|
},
|
|
29
82
|
undefined,
|
|
30
83
|
]
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { Image } from 'react-native';
|
|
2
3
|
|
|
3
4
|
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
4
5
|
import Empty from '..';
|
|
@@ -14,4 +15,16 @@ describe('Empty', () => {
|
|
|
14
15
|
|
|
15
16
|
expect(toJSON()).toMatchSnapshot();
|
|
16
17
|
});
|
|
18
|
+
|
|
19
|
+
it('renders empty state with image correctly', () => {
|
|
20
|
+
const { toJSON } = renderWithTheme(
|
|
21
|
+
<Empty
|
|
22
|
+
image={<Image source={{ uri: 'path_to_image' }} />}
|
|
23
|
+
title="You have no notification at this time"
|
|
24
|
+
description="We'll notify you later."
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
expect(toJSON()).toMatchSnapshot();
|
|
29
|
+
});
|
|
17
30
|
});
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
import type {
|
|
4
|
+
StyleProp,
|
|
5
|
+
ViewStyle,
|
|
6
|
+
ImageProps as RNImageProps,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
|
|
9
|
+
import { useTheme } from '../../theme';
|
|
10
|
+
import { ImageProps } from '../Image';
|
|
11
|
+
import { StyledWrapper, StyledTitle, StyledDescription } from './StyledEmpty';
|
|
9
12
|
|
|
10
13
|
interface EmptyProps {
|
|
14
|
+
/**
|
|
15
|
+
* Image to be displayed.
|
|
16
|
+
*/
|
|
17
|
+
image?: ReactElement<ImageProps | RNImageProps>;
|
|
11
18
|
/**
|
|
12
19
|
* Empty's title.
|
|
13
20
|
*/
|
|
@@ -32,21 +39,34 @@ interface EmptyProps {
|
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
const Empty = ({
|
|
42
|
+
image,
|
|
35
43
|
title,
|
|
36
44
|
description,
|
|
37
45
|
style,
|
|
38
46
|
testID,
|
|
39
47
|
variant = 'light',
|
|
40
|
-
}: EmptyProps): JSX.Element =>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
}: EmptyProps): JSX.Element => {
|
|
49
|
+
const theme = useTheme();
|
|
50
|
+
return (
|
|
51
|
+
<StyledWrapper style={style} testID={testID}>
|
|
52
|
+
{image !== undefined &&
|
|
53
|
+
React.cloneElement(image, {
|
|
54
|
+
...image.props,
|
|
55
|
+
style: [
|
|
56
|
+
{
|
|
57
|
+
marginBottom: theme.__hd__.empty.space.imageMargin,
|
|
58
|
+
},
|
|
59
|
+
image.props.style,
|
|
60
|
+
],
|
|
61
|
+
})}
|
|
62
|
+
<StyledTitle themeVariant={variant}>{title}</StyledTitle>
|
|
63
|
+
{!!description && (
|
|
64
|
+
<StyledDescription themeVariant={variant}>
|
|
65
|
+
{description}
|
|
66
|
+
</StyledDescription>
|
|
67
|
+
)}
|
|
68
|
+
</StyledWrapper>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
51
71
|
|
|
52
72
|
export default Empty;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Image renders correctly when rounded is false 1`] = `
|
|
4
|
+
<Image
|
|
5
|
+
source={
|
|
6
|
+
Object {
|
|
7
|
+
"uri": "path_to_image",
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
style={
|
|
11
|
+
Array [
|
|
12
|
+
Object {
|
|
13
|
+
"borderRadius": 0,
|
|
14
|
+
"height": 72,
|
|
15
|
+
"width": 72,
|
|
16
|
+
},
|
|
17
|
+
undefined,
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
/>
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
exports[`Image renders correctly when rounded is true 1`] = `
|
|
24
|
+
<Image
|
|
25
|
+
source={
|
|
26
|
+
Object {
|
|
27
|
+
"uri": "path_to_image",
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
style={
|
|
31
|
+
Array [
|
|
32
|
+
Object {
|
|
33
|
+
"borderRadius": 36,
|
|
34
|
+
"height": 72,
|
|
35
|
+
"width": 72,
|
|
36
|
+
},
|
|
37
|
+
undefined,
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
/>
|
|
41
|
+
`;
|
|
42
|
+
|
|
43
|
+
exports[`Image renders correctly when size is 6xlarge 1`] = `
|
|
44
|
+
<Image
|
|
45
|
+
source={
|
|
46
|
+
Object {
|
|
47
|
+
"uri": "path_to_image",
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
style={
|
|
51
|
+
Array [
|
|
52
|
+
Object {
|
|
53
|
+
"borderRadius": 0,
|
|
54
|
+
"height": 72,
|
|
55
|
+
"width": 72,
|
|
56
|
+
},
|
|
57
|
+
undefined,
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
/>
|
|
61
|
+
`;
|
|
62
|
+
|
|
63
|
+
exports[`Image renders correctly when size is 15xlarge 1`] = `
|
|
64
|
+
<Image
|
|
65
|
+
source={
|
|
66
|
+
Object {
|
|
67
|
+
"uri": "path_to_image",
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
style={
|
|
71
|
+
Array [
|
|
72
|
+
Object {
|
|
73
|
+
"borderRadius": 0,
|
|
74
|
+
"height": 144,
|
|
75
|
+
"width": 144,
|
|
76
|
+
},
|
|
77
|
+
undefined,
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
/>
|
|
81
|
+
`;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Image from '..';
|
|
3
|
+
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
4
|
+
|
|
5
|
+
describe('Image', () => {
|
|
6
|
+
it.each`
|
|
7
|
+
size
|
|
8
|
+
${'6xlarge'}
|
|
9
|
+
${'15xlarge'}
|
|
10
|
+
`('renders correctly when size is $size', ({ size }) => {
|
|
11
|
+
const { toJSON } = renderWithTheme(
|
|
12
|
+
<Image size={size} source={{ uri: 'path_to_image' }} />
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
expect(toJSON()).toMatchSnapshot();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it.each`
|
|
19
|
+
rounded
|
|
20
|
+
${true}
|
|
21
|
+
${false}
|
|
22
|
+
`('renders correctly when rounded is $rounded', ({ rounded }) => {
|
|
23
|
+
const { toJSON } = renderWithTheme(
|
|
24
|
+
<Image rounded={rounded} source={{ uri: 'path_to_image' }} />
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
expect(toJSON()).toMatchSnapshot();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Image as RNImage } from 'react-native';
|
|
3
|
+
import type { ImageProps as RNImageProps } from 'react-native';
|
|
4
|
+
import { useTheme } from '../../theme';
|
|
5
|
+
|
|
6
|
+
export interface ImageProps extends RNImageProps {
|
|
7
|
+
/**
|
|
8
|
+
* Whether the image is rounded.
|
|
9
|
+
*/
|
|
10
|
+
rounded?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Image sizes, following the same sizes as the `sizes` global theme.
|
|
13
|
+
*/
|
|
14
|
+
size?: '6xlarge' | '15xlarge';
|
|
15
|
+
/**
|
|
16
|
+
* Testing id of the component.
|
|
17
|
+
*/
|
|
18
|
+
testID?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const Image = ({
|
|
22
|
+
rounded = false,
|
|
23
|
+
size = '6xlarge',
|
|
24
|
+
testID,
|
|
25
|
+
style,
|
|
26
|
+
...imageNativeProps
|
|
27
|
+
}: ImageProps): JSX.Element => {
|
|
28
|
+
const theme = useTheme();
|
|
29
|
+
const imageSize = theme.__hd__.image.sizes[size];
|
|
30
|
+
return (
|
|
31
|
+
<RNImage
|
|
32
|
+
testID={testID}
|
|
33
|
+
style={[
|
|
34
|
+
{
|
|
35
|
+
width: imageSize,
|
|
36
|
+
height: imageSize,
|
|
37
|
+
borderRadius: rounded ? imageSize / 2 : 0,
|
|
38
|
+
},
|
|
39
|
+
style,
|
|
40
|
+
]}
|
|
41
|
+
{...imageNativeProps}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export default Image;
|
|
@@ -732,10 +732,10 @@ exports[`ListItem renders correctly ListItem with prefix suffix is React.Element
|
|
|
732
732
|
"backgroundColor": "#8505a2",
|
|
733
733
|
"borderRadius": 999,
|
|
734
734
|
"display": "flex",
|
|
735
|
-
"height":
|
|
735
|
+
"height": 32,
|
|
736
736
|
"justifyContent": "center",
|
|
737
737
|
"paddingHorizontal": 4,
|
|
738
|
-
"width":
|
|
738
|
+
"width": 64,
|
|
739
739
|
},
|
|
740
740
|
undefined,
|
|
741
741
|
]
|
|
@@ -751,9 +751,9 @@ exports[`ListItem renders correctly ListItem with prefix suffix is React.Element
|
|
|
751
751
|
Object {
|
|
752
752
|
"backgroundColor": "#ffffff",
|
|
753
753
|
"borderRadius": 999,
|
|
754
|
-
"height":
|
|
755
|
-
"left":
|
|
756
|
-
"width":
|
|
754
|
+
"height": 24,
|
|
755
|
+
"left": 32,
|
|
756
|
+
"width": 24,
|
|
757
757
|
}
|
|
758
758
|
}
|
|
759
759
|
themeSize="medium"
|