@hero-design/rn 7.2.1 → 7.3.1

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.
Files changed (190) hide show
  1. package/.expo/packager-info.json +1 -1
  2. package/.expo/prebuild/cached-packages.json +4 -0
  3. package/.expo/xcodebuild-error.log +2 -0
  4. package/.expo/xcodebuild.log +11199 -0
  5. package/.turbo/turbo-build.log +8 -8
  6. package/.turbo/turbo-build:types.log +2 -0
  7. package/.turbo/turbo-test.log +131 -0
  8. package/.turbo/turbo-type-check.log +7 -0
  9. package/es/index.js +2393 -457
  10. package/jest.config.js +1 -1
  11. package/lib/index.js +2407 -466
  12. package/package.json +4 -2
  13. package/playground/components/Avatar.tsx +102 -0
  14. package/playground/components/Badge.tsx +146 -9
  15. package/playground/components/Button.tsx +138 -35
  16. package/playground/components/Card.tsx +39 -13
  17. package/playground/components/Collapse.tsx +99 -0
  18. package/playground/components/Drawer.tsx +32 -0
  19. package/playground/components/FAB.tsx +15 -0
  20. package/playground/components/IconButton.tsx +67 -0
  21. package/playground/components/Progress.tsx +95 -0
  22. package/playground/components/Tabs.tsx +106 -14
  23. package/playground/components/Tag.tsx +45 -0
  24. package/playground/index.tsx +18 -0
  25. package/src/components/Avatar/StyledAvatar.tsx +61 -0
  26. package/src/components/Avatar/__tests__/StyledAvatar.spec.tsx +48 -0
  27. package/src/components/Avatar/__tests__/__snapshots__/StyledAvatar.spec.tsx.snap +87 -0
  28. package/src/components/Avatar/__tests__/__snapshots__/index.spec.tsx.snap +88 -0
  29. package/src/components/Avatar/__tests__/index.spec.tsx +26 -0
  30. package/src/components/Avatar/index.tsx +71 -0
  31. package/src/components/Badge/Status.tsx +77 -0
  32. package/src/components/Badge/StyledBadge.tsx +38 -26
  33. package/src/components/Badge/__tests__/Badge.spec.tsx +16 -0
  34. package/src/components/Badge/__tests__/Status.spec.tsx +27 -0
  35. package/src/components/Badge/__tests__/__snapshots__/Badge.spec.tsx.snap +133 -52
  36. package/src/components/Badge/__tests__/__snapshots__/Status.spec.tsx.snap +89 -0
  37. package/src/components/Badge/index.tsx +77 -19
  38. package/src/components/Button/Button.tsx +163 -0
  39. package/src/components/Button/LoadingIndicator/StyledLoadingIndicator.tsx +58 -0
  40. package/src/components/Button/LoadingIndicator/__tests__/StyledLoadingIndicator.spec.tsx +20 -0
  41. package/src/components/Button/LoadingIndicator/__tests__/__snapshots__/StyledLoadingIndicator.spec.tsx.snap +101 -0
  42. package/src/components/Button/LoadingIndicator/__tests__/__snapshots__/index.spec.tsx.snap +606 -0
  43. package/src/components/Button/LoadingIndicator/__tests__/index.spec.tsx +24 -0
  44. package/src/components/Button/LoadingIndicator/index.tsx +140 -0
  45. package/src/components/Button/StyledButton.tsx +254 -0
  46. package/src/components/Button/__tests__/Button.spec.tsx +86 -0
  47. package/src/components/Button/__tests__/{index.spec.tsx → IconButton.spec.tsx} +0 -0
  48. package/src/components/Button/__tests__/StyledButton.spec.tsx +154 -0
  49. package/src/components/Button/__tests__/__snapshots__/{index.spec.tsx.snap → IconButton.spec.tsx.snap} +0 -0
  50. package/src/components/Button/__tests__/__snapshots__/StyledButton.spec.tsx.snap +895 -0
  51. package/src/components/Button/index.tsx +10 -2
  52. package/src/components/Card/StyledCard.tsx +27 -5
  53. package/src/components/Card/__tests__/StyledCard.spec.tsx +15 -3
  54. package/src/components/Card/__tests__/__snapshots__/StyledCard.spec.tsx.snap +34 -2
  55. package/src/components/Card/__tests__/index.spec.tsx +16 -21
  56. package/src/components/Card/index.tsx +15 -2
  57. package/src/components/Collapse/StyledCollapse.tsx +15 -0
  58. package/src/components/Collapse/__tests__/StyledCollapse.spec.tsx +26 -0
  59. package/src/components/Collapse/__tests__/__snapshots__/StyledCollapse.spec.tsx.snap +37 -0
  60. package/src/components/Collapse/__tests__/__snapshots__/index.spec.tsx.snap +84 -0
  61. package/src/components/Collapse/__tests__/index.spec.tsx +42 -0
  62. package/src/components/Collapse/index.tsx +109 -0
  63. package/src/components/Divider/index.tsx +1 -1
  64. package/src/components/Drawer/StyledDrawer.tsx +39 -0
  65. package/src/components/Drawer/__tests__/__snapshots__/index.spec.tsx.snap +244 -0
  66. package/src/components/Drawer/__tests__/index.spec.tsx +37 -0
  67. package/src/components/Drawer/index.tsx +93 -0
  68. package/src/components/FAB/ActionGroup/__tests__/__snapshots__/index.spec.tsx.snap +78 -62
  69. package/src/components/FAB/ActionGroup/__tests__/index.spec.tsx +2 -0
  70. package/src/components/FAB/ActionGroup/index.tsx +13 -0
  71. package/src/components/FAB/FAB.tsx +63 -13
  72. package/src/components/FAB/StyledFAB.tsx +25 -6
  73. package/src/components/FAB/__tests__/__snapshots__/AnimatedFABIcon.spec.tsx.snap +6 -2
  74. package/src/components/FAB/__tests__/__snapshots__/StyledFAB.spec.tsx.snap +7 -3
  75. package/src/components/FAB/__tests__/__snapshots__/index.spec.tsx.snap +88 -6
  76. package/src/components/FAB/__tests__/index.spec.tsx +16 -0
  77. package/src/components/Progress/ProgressBar.tsx +73 -0
  78. package/src/components/Progress/ProgressCircle.tsx +165 -0
  79. package/src/components/Progress/StyledProgressBar.tsx +21 -0
  80. package/src/components/Progress/StyledProgressCircle.tsx +66 -0
  81. package/src/components/Progress/__tests__/__snapshots__/index.spec.js.snap +641 -0
  82. package/src/components/Progress/__tests__/index.spec.js +46 -0
  83. package/src/components/Progress/index.tsx +6 -0
  84. package/src/components/Progress/types.ts +1 -0
  85. package/src/components/Tabs/ActiveTabIndicator.tsx +37 -0
  86. package/src/components/Tabs/ScrollableTabs.tsx +216 -0
  87. package/src/components/Tabs/StyledScrollableTabs.tsx +60 -0
  88. package/src/components/Tabs/StyledTabs.tsx +30 -44
  89. package/src/components/Tabs/__tests__/ScrollableTabs.spec.tsx +84 -0
  90. package/src/components/Tabs/__tests__/__snapshots__/ScrollableTabs.spec.tsx.snap +591 -0
  91. package/src/components/Tabs/__tests__/__snapshots__/index.spec.tsx.snap +317 -224
  92. package/src/components/Tabs/__tests__/index.spec.tsx +22 -21
  93. package/src/components/Tabs/index.tsx +155 -114
  94. package/src/components/Tabs/utils.ts +13 -0
  95. package/src/components/Tag/StyledTag.tsx +35 -0
  96. package/src/components/Tag/__tests__/Tag.spec.tsx +41 -0
  97. package/src/components/Tag/__tests__/__snapshots__/Tag.spec.tsx.snap +153 -0
  98. package/src/components/Tag/index.tsx +41 -0
  99. package/src/components/Typography/Text/index.tsx +1 -1
  100. package/src/index.ts +10 -0
  101. package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +181 -22
  102. package/src/theme/components/avatar.ts +40 -0
  103. package/src/theme/components/badge.ts +14 -16
  104. package/src/theme/components/button.ts +57 -0
  105. package/src/theme/components/card.ts +5 -5
  106. package/src/theme/components/drawer.ts +24 -0
  107. package/src/theme/components/fab.ts +9 -2
  108. package/src/theme/components/progress.ts +27 -0
  109. package/src/theme/components/tabs.ts +22 -7
  110. package/src/theme/components/tag.ts +39 -0
  111. package/src/theme/global/borders.ts +13 -1
  112. package/src/theme/global/colors.ts +6 -1
  113. package/src/theme/global/index.ts +3 -1
  114. package/src/theme/global/scale.ts +3 -0
  115. package/src/theme/index.ts +15 -0
  116. package/src/utils/hooks.ts +10 -0
  117. package/testUtils/setup.tsx +43 -0
  118. package/types/playground/components/Avatar.d.ts +2 -0
  119. package/types/playground/components/Collapse.d.ts +2 -0
  120. package/types/playground/components/Drawer.d.ts +2 -0
  121. package/types/playground/components/IconButton.d.ts +2 -0
  122. package/types/playground/components/Progress.d.ts +2 -0
  123. package/types/playground/components/Tag.d.ts +2 -0
  124. package/types/src/components/Avatar/StyledAvatar.d.ts +46 -0
  125. package/types/src/components/Avatar/__tests__/StyledAvatar.spec.d.ts +1 -0
  126. package/types/src/components/Avatar/__tests__/index.spec.d.ts +1 -0
  127. package/types/src/components/Avatar/index.d.ts +25 -0
  128. package/types/src/components/Badge/Status.d.ts +24 -0
  129. package/types/src/components/Badge/StyledBadge.d.ts +17 -9
  130. package/types/src/components/Badge/__tests__/Status.spec.d.ts +1 -0
  131. package/types/src/components/Badge/index.d.ts +17 -7
  132. package/types/src/components/Button/Button.d.ts +57 -0
  133. package/types/src/components/Button/LoadingIndicator/StyledLoadingIndicator.d.ts +20 -0
  134. package/types/src/components/Button/LoadingIndicator/__tests__/StyledLoadingIndicator.spec.d.ts +1 -0
  135. package/types/src/components/Button/LoadingIndicator/__tests__/index.spec.d.ts +1 -0
  136. package/types/src/components/Button/LoadingIndicator/index.d.ts +26 -0
  137. package/types/src/components/Button/StyledButton.d.ts +40 -0
  138. package/types/src/components/Button/__tests__/Button.spec.d.ts +1 -0
  139. package/types/src/components/Button/__tests__/IconButton.spec.d.ts +1 -0
  140. package/types/src/components/Button/__tests__/StyledButton.spec.d.ts +1 -0
  141. package/types/src/components/Button/index.d.ts +8 -4
  142. package/types/src/components/Card/StyledCard.d.ts +9 -1
  143. package/types/src/components/Card/index.d.ts +5 -1
  144. package/types/src/components/Collapse/StyledCollapse.d.ts +15 -0
  145. package/types/src/components/Collapse/__tests__/StyledCollapse.spec.d.ts +1 -0
  146. package/types/src/components/Collapse/__tests__/index.spec.d.ts +1 -0
  147. package/types/src/components/Collapse/index.d.ts +23 -0
  148. package/types/src/components/Drawer/StyledDrawer.d.ts +25 -0
  149. package/types/src/components/Drawer/__tests__/index.spec.d.ts +1 -0
  150. package/types/src/components/Drawer/index.d.ts +25 -0
  151. package/types/src/components/FAB/ActionGroup/index.d.ts +5 -1
  152. package/types/src/components/FAB/FAB.d.ts +5 -1
  153. package/types/src/components/FAB/StyledFAB.d.ts +8 -2
  154. package/types/src/components/FAB/index.d.ts +2 -2
  155. package/types/src/components/Icon/utils.d.ts +1 -1
  156. package/types/src/components/Progress/ProgressBar.d.ts +18 -0
  157. package/types/src/components/Progress/ProgressCircle.d.ts +18 -0
  158. package/types/src/components/Progress/StyledProgressBar.d.ts +18 -0
  159. package/types/src/components/Progress/StyledProgressCircle.d.ts +38 -0
  160. package/types/src/components/Progress/__tests__/index.spec.d.ts +1 -0
  161. package/types/src/components/Progress/index.d.ts +5 -0
  162. package/types/src/components/Progress/types.d.ts +1 -0
  163. package/types/src/components/Tabs/ActiveTabIndicator.d.ts +8 -0
  164. package/types/src/components/Tabs/ScrollableTabs.d.ts +3 -0
  165. package/types/src/components/Tabs/StyledScrollableTabs.d.ts +61 -0
  166. package/types/src/components/Tabs/StyledTabs.d.ts +22 -22
  167. package/types/src/components/Tabs/__tests__/ScrollableTabs.spec.d.ts +1 -0
  168. package/types/src/components/Tabs/index.d.ts +28 -19
  169. package/types/src/components/Tabs/utils.d.ts +2 -0
  170. package/types/src/components/Tag/StyledTag.d.ts +20 -0
  171. package/types/src/components/Tag/__tests__/Tag.spec.d.ts +1 -0
  172. package/types/src/components/Tag/index.d.ts +21 -0
  173. package/types/src/index.d.ts +6 -1
  174. package/types/src/theme/components/avatar.d.ts +32 -0
  175. package/types/src/theme/components/badge.d.ts +12 -13
  176. package/types/src/theme/components/button.d.ts +37 -0
  177. package/types/src/theme/components/card.d.ts +3 -3
  178. package/types/src/theme/components/drawer.d.ts +21 -0
  179. package/types/src/theme/components/fab.d.ts +8 -1
  180. package/types/src/theme/components/progress.d.ts +21 -0
  181. package/types/src/theme/components/tabs.d.ts +14 -2
  182. package/types/src/theme/components/tag.d.ts +30 -0
  183. package/types/src/theme/global/borders.d.ts +7 -1
  184. package/types/src/theme/global/colors.d.ts +6 -1
  185. package/types/src/theme/global/index.d.ts +7 -1
  186. package/types/src/theme/global/scale.d.ts +1 -0
  187. package/types/src/theme/index.d.ts +10 -0
  188. package/types/src/utils/hooks.d.ts +1 -0
  189. package/src/components/Card/__tests__/__snapshots__/index.spec.tsx.snap +0 -34
  190. package/testUtils/setup.ts +0 -18
@@ -0,0 +1,87 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`StyledImage renders correct style 1`] = `
4
+ <Image
5
+ source={
6
+ Object {
7
+ "uri": "https://i.pravatar.cc/300",
8
+ }
9
+ }
10
+ style={
11
+ Array [
12
+ Object {
13
+ "height": 32,
14
+ "width": 32,
15
+ },
16
+ undefined,
17
+ ]
18
+ }
19
+ themeSize="small"
20
+ />
21
+ `;
22
+
23
+ exports[`StyledPressable renders correct style 1`] = `
24
+ <View
25
+ accessible={true}
26
+ collapsable={false}
27
+ focusable={false}
28
+ nativeID="animatedComponent"
29
+ onClick={[Function]}
30
+ onResponderGrant={[Function]}
31
+ onResponderMove={[Function]}
32
+ onResponderRelease={[Function]}
33
+ onResponderTerminate={[Function]}
34
+ onResponderTerminationRequest={[Function]}
35
+ onStartShouldSetResponder={[Function]}
36
+ style={
37
+ Object {
38
+ "borderColor": "#7622d7",
39
+ "borderRadius": 16,
40
+ "borderWidth": 1,
41
+ "height": 32,
42
+ "opacity": 1,
43
+ "overflow": "hidden",
44
+ "width": 32,
45
+ }
46
+ }
47
+ />
48
+ `;
49
+
50
+ exports[`StyledText renders correct style 1`] = `
51
+ <Text
52
+ style={
53
+ Array [
54
+ Object {
55
+ "color": "#7622d7",
56
+ "fontSize": 16,
57
+ "overflow": "hidden",
58
+ },
59
+ undefined,
60
+ ]
61
+ }
62
+ themeIntent="primary"
63
+ themeSize="small"
64
+ >
65
+ MD
66
+ </Text>
67
+ `;
68
+
69
+ exports[`StyledView renders correct style 1`] = `
70
+ <View
71
+ style={
72
+ Array [
73
+ Object {
74
+ "borderColor": "#7622d7",
75
+ "borderRadius": 16,
76
+ "borderWidth": 1,
77
+ "height": 32,
78
+ "overflow": "hidden",
79
+ "width": 32,
80
+ },
81
+ undefined,
82
+ ]
83
+ }
84
+ themeIntent="primary"
85
+ themeSize="small"
86
+ />
87
+ `;
@@ -0,0 +1,88 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Avatar renders correctly 1`] = `
4
+ <View
5
+ style={
6
+ Array [
7
+ Object {
8
+ "borderColor": "#7622d7",
9
+ "borderRadius": 16,
10
+ "borderWidth": 1,
11
+ "height": 32,
12
+ "overflow": "hidden",
13
+ "width": 32,
14
+ },
15
+ undefined,
16
+ ]
17
+ }
18
+ testID="avatar"
19
+ themeIntent="primary"
20
+ themeSize="small"
21
+ >
22
+ <Image
23
+ resizeMode="cover"
24
+ source={
25
+ Object {
26
+ "uri": "https://i.pravatar.cc/300",
27
+ }
28
+ }
29
+ style={
30
+ Array [
31
+ Object {
32
+ "height": 32,
33
+ "width": 32,
34
+ },
35
+ undefined,
36
+ ]
37
+ }
38
+ themeSize="small"
39
+ />
40
+ </View>
41
+ `;
42
+
43
+ exports[`Avatar trigger press function correctly 1`] = `
44
+ <View
45
+ accessible={true}
46
+ collapsable={false}
47
+ focusable={true}
48
+ nativeID="animatedComponent"
49
+ onClick={[Function]}
50
+ onResponderGrant={[Function]}
51
+ onResponderMove={[Function]}
52
+ onResponderRelease={[Function]}
53
+ onResponderTerminate={[Function]}
54
+ onResponderTerminationRequest={[Function]}
55
+ onStartShouldSetResponder={[Function]}
56
+ style={
57
+ Object {
58
+ "borderColor": "#7622d7",
59
+ "borderRadius": 16,
60
+ "borderWidth": 1,
61
+ "height": 32,
62
+ "opacity": 1,
63
+ "overflow": "hidden",
64
+ "width": 32,
65
+ }
66
+ }
67
+ testID="avatar"
68
+ >
69
+ <Image
70
+ resizeMode="cover"
71
+ source={
72
+ Object {
73
+ "uri": "https://i.pravatar.cc/300",
74
+ }
75
+ }
76
+ style={
77
+ Array [
78
+ Object {
79
+ "height": 32,
80
+ "width": 32,
81
+ },
82
+ undefined,
83
+ ]
84
+ }
85
+ themeSize="small"
86
+ />
87
+ </View>
88
+ `;
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { fireEvent } from '@testing-library/react-native';
3
+ import renderWithTheme from '../../../testHelpers/renderWithTheme';
4
+ import Avatar from '..';
5
+
6
+ describe('Avatar', () => {
7
+ const source = { uri: 'https://i.pravatar.cc/300' };
8
+ const pressFn = jest.fn();
9
+
10
+ it('renders correctly', () => {
11
+ const wrapper = renderWithTheme(<Avatar testID="avatar" source={source} />);
12
+ expect(wrapper.queryAllByTestId('avatar')).toHaveLength(1);
13
+
14
+ expect(wrapper.toJSON()).toMatchSnapshot();
15
+ });
16
+
17
+ it('trigger press function correctly', () => {
18
+ const wrapper = renderWithTheme(
19
+ <Avatar testID="avatar" source={source} onPress={pressFn} />
20
+ );
21
+ fireEvent.press(wrapper.getByTestId('avatar'));
22
+
23
+ expect(wrapper.toJSON()).toMatchSnapshot();
24
+ expect(pressFn).toBeCalled();
25
+ });
26
+ });
@@ -0,0 +1,71 @@
1
+ import {
2
+ ImageSourcePropType,
3
+ StyleProp,
4
+ ViewProps,
5
+ ViewStyle,
6
+ } from 'react-native';
7
+ import React from 'react';
8
+ import {
9
+ StyledImage,
10
+ StyledPressable,
11
+ StyledText,
12
+ StyledTextWrapper,
13
+ StyledView,
14
+ } from './StyledAvatar';
15
+
16
+ interface AvatarProps extends ViewProps {
17
+ /** Callback function when pressing component. */
18
+ onPress?: () => void;
19
+ /** Image source to be displayed on avatar. */
20
+ source?: ImageSourcePropType;
21
+ /** Renders title in the placeholder. */
22
+ title?: string;
23
+ /**
24
+ * Intent of the Icon.
25
+ */
26
+ intent?: 'primary' | 'info' | 'danger' | 'success' | 'warning';
27
+ /** Size of the avatar. */
28
+ size?: 'small' | 'medium' | 'large' | 'xlarge';
29
+ /**
30
+ * Addditional style.
31
+ */
32
+ style?: StyleProp<ViewStyle>;
33
+ /**
34
+ * Testing id of the component.
35
+ */
36
+ testID?: string;
37
+ }
38
+
39
+ const Avatar = ({
40
+ onPress,
41
+ source,
42
+ testID,
43
+ style,
44
+ title,
45
+ size = 'small',
46
+ intent = 'primary',
47
+ }: AvatarProps) => {
48
+ const Wrapper = onPress ? StyledPressable : StyledView;
49
+ return title !== undefined || source !== undefined ? (
50
+ <Wrapper
51
+ testID={testID}
52
+ onPress={onPress}
53
+ themeIntent={intent}
54
+ themeSize={size}
55
+ style={style}
56
+ >
57
+ {title !== undefined && source === undefined && (
58
+ <StyledTextWrapper>
59
+ <StyledText themeIntent={intent} themeSize={size}>
60
+ {title}
61
+ </StyledText>
62
+ </StyledTextWrapper>
63
+ )}
64
+ {source !== undefined && (
65
+ <StyledImage resizeMode="cover" source={source} themeSize={size} />
66
+ )}
67
+ </Wrapper>
68
+ ) : null;
69
+ };
70
+
71
+ export default Avatar;
@@ -0,0 +1,77 @@
1
+ import { View, StyleProp, ViewStyle, ViewProps, Animated } from 'react-native';
2
+ import React, { ReactNode } from 'react';
3
+ import { StyledStatus } from './StyledBadge';
4
+
5
+ export interface StatusProps extends ViewProps {
6
+ /*
7
+ * The Status Badge's content.
8
+ */
9
+ children: ReactNode;
10
+ /**
11
+ * Whether the Status Badge is visible.
12
+ */
13
+ visible?: boolean;
14
+ /**
15
+ /**
16
+ * Visual intent color to apply to Status Badge.
17
+ */
18
+ intent?: 'success' | 'warning' | 'danger' | 'info' | 'archived';
19
+ /**
20
+ * Additional style.
21
+ */
22
+ style?: StyleProp<ViewStyle>;
23
+ /**
24
+ * Testing id of the component.
25
+ */
26
+ testID?: string;
27
+ }
28
+
29
+ const Status = ({
30
+ children,
31
+ visible = true,
32
+ intent = 'danger',
33
+ style,
34
+ testID,
35
+ ...nativeProps
36
+ }: StatusProps): JSX.Element => {
37
+ const { current: opacity } = React.useRef<Animated.Value>(
38
+ new Animated.Value(visible ? 1 : 0)
39
+ );
40
+ const isFirstRendering = React.useRef<boolean>(true);
41
+
42
+ React.useEffect(() => {
43
+ // Do not run animation on very first rendering
44
+ if (isFirstRendering.current) {
45
+ isFirstRendering.current = false;
46
+ return;
47
+ }
48
+
49
+ Animated.timing(opacity, {
50
+ toValue: visible ? 1 : 0,
51
+ duration: 150,
52
+ useNativeDriver: true,
53
+ }).start();
54
+ }, [visible, opacity]);
55
+
56
+ return (
57
+ <View {...nativeProps} style={style} testID={testID}>
58
+ {children}
59
+ <StyledStatus
60
+ style={{
61
+ opacity,
62
+ transform: [
63
+ {
64
+ scale: opacity.interpolate({
65
+ inputRange: [0, 1],
66
+ outputRange: [0.5, 1],
67
+ }),
68
+ },
69
+ ],
70
+ }}
71
+ themeIntent={intent}
72
+ />
73
+ </View>
74
+ );
75
+ };
76
+
77
+ export default Status;
@@ -1,32 +1,44 @@
1
- import { View, Text } from 'react-native';
1
+ import { Animated, Text } from 'react-native';
2
2
  import styled from '@emotion/native';
3
3
 
4
- const BACKGROUND_INTENTS = {
5
- success: 'successBackground',
6
- warning: 'warningBackground',
7
- danger: 'dangerBackground',
8
- info: 'infoBackground',
9
- } as const;
4
+ type ThemeIntent = 'success' | 'warning' | 'danger' | 'info' | 'archived';
5
+ type ThemePadding = 'narrowContent' | 'wideContent';
10
6
 
11
- type ThemeIntent = 'success' | 'warning' | 'danger' | 'info';
7
+ const StyledView = styled(Animated.View)<{
8
+ themeIntent: ThemeIntent;
9
+ themePadding: ThemePadding;
10
+ }>(({ themeIntent, themePadding, theme }) => ({
11
+ height: theme.__hd__.badge.sizes.height,
12
+ minWidth: theme.__hd__.badge.sizes.minWidth,
13
+ alignItems: 'center',
14
+ justifyContent: 'center',
15
+ backgroundColor: theme.__hd__.badge.colors[themeIntent],
16
+ borderRadius: theme.radii.rounded,
17
+ paddingHorizontal:
18
+ themePadding === 'wideContent'
19
+ ? theme.__hd__.badge.space.horizontalPadding
20
+ : undefined,
21
+ }));
12
22
 
13
- const StyledView = styled(View)<{ themeIntent: ThemeIntent }>(
14
- ({ themeIntent, theme }) => ({
15
- borderWidth: theme.__hd__.badge.borderWidths.default,
16
- borderRadius: theme.__hd__.badge.radii.default,
17
- paddingVertical: theme.__hd__.badge.space.verticalPadding,
18
- paddingHorizontal: theme.__hd__.badge.space.horizontalPadding,
19
- borderColor: theme.__hd__.badge.colors[themeIntent],
20
- backgroundColor: theme.__hd__.badge.colors[BACKGROUND_INTENTS[themeIntent]],
21
- })
22
- );
23
+ const StyledText = styled(Text)(({ theme }) => ({
24
+ fontFamily: theme.__hd__.badge.fonts.default,
25
+ fontSize: theme.__hd__.badge.fontSizes.default,
26
+ color: theme.__hd__.badge.colors.text,
27
+ includeFontPadding: false,
28
+ textAlignVertical: 'center',
29
+ textAlign: 'center',
30
+ }));
23
31
 
24
- const StyledText = styled(Text)<{ themeIntent: ThemeIntent }>(
25
- ({ themeIntent, theme }) => ({
26
- fontFamily: theme.__hd__.badge.font.default,
27
- fontSize: theme.__hd__.badge.fontSize.default,
28
- color: theme.__hd__.badge.colors[themeIntent],
29
- })
30
- );
32
+ const StyledStatus = styled(Animated.View)<{
33
+ themeIntent: ThemeIntent;
34
+ }>(({ themeIntent, theme }) => ({
35
+ position: 'absolute',
36
+ top: theme.__hd__.badge.space.statusPositionTop,
37
+ right: theme.__hd__.badge.space.statusPositionRight,
38
+ height: theme.__hd__.badge.sizes.statusHeight,
39
+ width: theme.__hd__.badge.sizes.statusWidth,
40
+ backgroundColor: theme.__hd__.badge.colors[themeIntent],
41
+ borderRadius: theme.radii.rounded,
42
+ }));
31
43
 
32
- export { StyledView, StyledText };
44
+ export { StyledView, StyledText, StyledStatus };
@@ -38,4 +38,20 @@ describe('Badge', () => {
38
38
  expect(toJSON()).toMatchSnapshot();
39
39
  expect(getByText('SUBMITTED')).toBeDefined();
40
40
  });
41
+
42
+ it('renders correctly with custom props', () => {
43
+ const { getByText, getByTestId, toJSON } = renderWithTheme(
44
+ <Badge
45
+ content={90}
46
+ intent="success"
47
+ max={50}
48
+ visible
49
+ testID="number-badge"
50
+ />
51
+ );
52
+
53
+ expect(toJSON()).toMatchSnapshot();
54
+ expect(getByTestId('number-badge')).toBeDefined();
55
+ expect(getByText('50+')).toBeDefined();
56
+ });
41
57
  });
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import renderWithTheme from '../../../testHelpers/renderWithTheme';
3
+ import Badge from '..';
4
+ import Typography from '../../Typography';
5
+ import Icon from '../../Icon';
6
+
7
+ describe('Status Badge', () => {
8
+ it('renders correctly', () => {
9
+ const { getByTestId, toJSON } = renderWithTheme(
10
+ <Badge.Status>
11
+ <Icon icon="activate" testID="activate-icon" />
12
+ </Badge.Status>
13
+ );
14
+ expect(toJSON()).toMatchSnapshot();
15
+ expect(getByTestId('activate-icon')).toBeDefined();
16
+ });
17
+
18
+ it('renders correctly with intent', () => {
19
+ const { getByText, toJSON } = renderWithTheme(
20
+ <Badge.Status intent="success">
21
+ <Typography.Text>Activity</Typography.Text>
22
+ </Badge.Status>
23
+ );
24
+ expect(toJSON()).toMatchSnapshot();
25
+ expect(getByText('Activity')).toBeDefined();
26
+ });
27
+ });