@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,24 @@
1
+ import React from 'react';
2
+ import renderWithTheme from '../../../../testHelpers/renderWithTheme';
3
+
4
+ import LoadingIndicator from '..';
5
+
6
+ describe('LoadingIndicator', () => {
7
+ it.each`
8
+ themeVariant
9
+ ${'basic-transparent'}
10
+ ${'filled-primary'}
11
+ ${'filled-secondary'}
12
+ ${'outlined-primary'}
13
+ ${'outlined-secondary'}
14
+ `(
15
+ 'renders correctly when themeVariant is $themeVariant',
16
+ ({ themeVariant }) => {
17
+ const { toJSON } = renderWithTheme(
18
+ <LoadingIndicator themeVariant={themeVariant} />
19
+ );
20
+
21
+ expect(toJSON()).toMatchSnapshot();
22
+ }
23
+ );
24
+ });
@@ -0,0 +1,140 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import {
3
+ Animated,
4
+ Easing,
5
+ StyleSheet,
6
+ StyleProp,
7
+ ViewStyle,
8
+ ViewProps,
9
+ } from 'react-native';
10
+ import {
11
+ StyledLoadingDot,
12
+ StyledLoadingIndicatorWrapper,
13
+ } from './StyledLoadingIndicator';
14
+
15
+ type ThemeVariant =
16
+ | 'basic-transparent'
17
+ | 'filled-primary'
18
+ | 'filled-secondary'
19
+ | 'outlined-primary'
20
+ | 'outlined-secondary';
21
+
22
+ const AnimatedLoadingIndicatorWrapper = Animated.createAnimatedComponent(
23
+ StyledLoadingIndicatorWrapper
24
+ );
25
+
26
+ const AnimatedLoadingDot = Animated.createAnimatedComponent(StyledLoadingDot);
27
+
28
+ const renderDotComponent = ({
29
+ index,
30
+ size,
31
+ count,
32
+ animation,
33
+ themeVariant,
34
+ }: {
35
+ index: number;
36
+ size: number;
37
+ count: number;
38
+ animation: React.MutableRefObject<Animated.Value>;
39
+ themeVariant: ThemeVariant;
40
+ }) => {
41
+ const interpolatedProgressAnimation = animation.current.interpolate({
42
+ inputRange: [
43
+ 0.0,
44
+ (index + 0.5) / (count + 1),
45
+ (index + 1.0) / (count + 1),
46
+ (index + 1.5) / (count + 1),
47
+ 1.0,
48
+ ],
49
+ outputRange: [1.0, 1.36, 1.56, 1.06, 1.0],
50
+ });
51
+
52
+ return (
53
+ <Animated.View
54
+ style={StyleSheet.flatten([
55
+ {
56
+ transform: [
57
+ {
58
+ scale: interpolatedProgressAnimation,
59
+ },
60
+ ],
61
+ },
62
+ ])}
63
+ {...{ key: index }}
64
+ >
65
+ <AnimatedLoadingDot size={size} themeVariant={themeVariant} />
66
+ </Animated.View>
67
+ );
68
+ };
69
+
70
+ interface LoadingIndicatorProps extends ViewProps {
71
+ /**
72
+ * Size of the loading dot.
73
+ */
74
+ count?: number;
75
+ /**
76
+ * Size of the loading dot.
77
+ */
78
+ size?: number;
79
+ /**
80
+ * Additional style.
81
+ */
82
+ style?: StyleProp<ViewStyle>;
83
+ /**
84
+ * Testing id of the component.
85
+ */
86
+ testID?: string;
87
+ /**
88
+ * Testing id of the component.
89
+ */
90
+ themeVariant: ThemeVariant;
91
+ }
92
+
93
+ const LoadingIndicator = ({
94
+ count = 3,
95
+ size = 12,
96
+ testID,
97
+ themeVariant,
98
+ ...nativeProps
99
+ }: LoadingIndicatorProps) => {
100
+ const progressAnimation = useRef<Animated.Value>(new Animated.Value(0));
101
+
102
+ useEffect(() => {
103
+ const animation = Animated.loop(
104
+ Animated.timing(progressAnimation.current, {
105
+ toValue: 1,
106
+ duration: 1200,
107
+ easing: Easing.linear,
108
+ useNativeDriver: true,
109
+ })
110
+ );
111
+
112
+ animation.start();
113
+
114
+ return () => {
115
+ animation.stop();
116
+ };
117
+ }, []);
118
+
119
+ const renderLoadingDot = (item: any, index: number) => {
120
+ if (typeof renderDotComponent === 'function') {
121
+ return renderDotComponent({
122
+ index,
123
+ count,
124
+ size,
125
+ animation: progressAnimation,
126
+ themeVariant,
127
+ });
128
+ }
129
+
130
+ return null;
131
+ };
132
+
133
+ return (
134
+ <AnimatedLoadingIndicatorWrapper testID={testID} {...nativeProps}>
135
+ {Array.from(new Array(count), renderLoadingDot, themeVariant)}
136
+ </AnimatedLoadingIndicatorWrapper>
137
+ );
138
+ };
139
+
140
+ export default LoadingIndicator;
@@ -0,0 +1,254 @@
1
+ import { View } from 'react-native';
2
+ import styled, { ReactNativeStyle } from '@emotion/native';
3
+ import { Theme } from '@emotion/react';
4
+
5
+ import Icon from '../Icon';
6
+ import Typography from '../Typography';
7
+
8
+ type Intent = 'primary' | 'secondary';
9
+
10
+ type ThemeVariant =
11
+ | 'basic-transparent'
12
+ | 'filled-primary'
13
+ | 'filled-secondary'
14
+ | 'outlined-primary'
15
+ | 'outlined-secondary';
16
+
17
+ const PRESSED_COLORS = {
18
+ primary: 'pressedPrimary',
19
+ secondary: 'pressedSecondary',
20
+ } as const;
21
+
22
+ const genBasicTransparentContainerStyles = (
23
+ theme: Theme,
24
+ pressed: boolean,
25
+ disabled: boolean
26
+ ): ReactNativeStyle => {
27
+ const borderColorStyling = () => {
28
+ if (disabled) {
29
+ return {
30
+ borderColor: theme.__hd__.button.colors.disabledBorder,
31
+ };
32
+ }
33
+
34
+ return { borderColor: theme.__hd__.button.colors.invertedText };
35
+ };
36
+
37
+ return {
38
+ width: '100%',
39
+ flexDirection: 'row',
40
+ justifyContent: 'center',
41
+ alignItems: 'center',
42
+ padding:
43
+ theme.__hd__.button.space.buttonPadding -
44
+ theme.__hd__.button.borderWidth.default,
45
+ borderWidth: theme.__hd__.button.borderWidth.default,
46
+ borderRadius: theme.__hd__.button.radii.default,
47
+ backgroundColor: 'transparent',
48
+ opacity: pressed ? 0.6 : 1,
49
+ ...borderColorStyling(),
50
+ };
51
+ };
52
+
53
+ const genFilledContainerStyles = (
54
+ theme: Theme,
55
+ intent: Intent,
56
+ pressed: boolean,
57
+ disabled: boolean
58
+ ): ReactNativeStyle => {
59
+ const backgroundColorStyling = () => {
60
+ if (disabled) {
61
+ return {
62
+ backgroundColor: theme.__hd__.button.colors.disabledBorder,
63
+ };
64
+ }
65
+
66
+ if (pressed) {
67
+ return {
68
+ backgroundColor: theme.__hd__.button.colors[PRESSED_COLORS[intent]],
69
+ };
70
+ }
71
+
72
+ return { backgroundColor: theme.__hd__.button.colors[intent] };
73
+ };
74
+
75
+ return {
76
+ width: '100%',
77
+ flexDirection: 'row',
78
+ justifyContent: 'center',
79
+ alignItems: 'center',
80
+ padding: theme.__hd__.button.space.buttonPadding,
81
+ borderRadius: theme.__hd__.button.radii.default,
82
+ ...backgroundColorStyling(),
83
+ };
84
+ };
85
+
86
+ const genOutlineContainerStyles = (
87
+ theme: Theme,
88
+ intent: Intent,
89
+ pressed: boolean,
90
+ disabled: boolean
91
+ ): ReactNativeStyle => {
92
+ const borderColorStyling = () => {
93
+ if (disabled) {
94
+ return {
95
+ borderColor: theme.__hd__.button.colors.disabledBorder,
96
+ };
97
+ }
98
+
99
+ if (pressed) {
100
+ return {
101
+ borderColor: theme.__hd__.button.colors[PRESSED_COLORS[intent]],
102
+ };
103
+ }
104
+
105
+ return { borderColor: theme.__hd__.button.colors[intent] };
106
+ };
107
+
108
+ return {
109
+ width: '100%',
110
+ flexDirection: 'row',
111
+ justifyContent: 'center',
112
+ alignItems: 'center',
113
+ padding:
114
+ theme.__hd__.button.space.buttonPadding -
115
+ theme.__hd__.button.borderWidth.default,
116
+ borderWidth: theme.__hd__.button.borderWidth.default,
117
+ borderRadius: theme.__hd__.button.radii.default,
118
+ backgroundColor: 'transparent',
119
+ ...borderColorStyling(),
120
+ };
121
+ };
122
+
123
+ const genOutlineTextStyles = (
124
+ theme: Theme,
125
+ intent: Intent,
126
+ pressed?: boolean,
127
+ disabled?: boolean
128
+ ): ReactNativeStyle => {
129
+ const textColorStyling = () => {
130
+ if (disabled) {
131
+ return {
132
+ color: theme.__hd__.button.colors.disabledText,
133
+ };
134
+ }
135
+
136
+ if (pressed) {
137
+ return {
138
+ color: theme.__hd__.button.colors[PRESSED_COLORS[intent]],
139
+ };
140
+ }
141
+
142
+ return { color: theme.__hd__.button.colors[intent] };
143
+ };
144
+
145
+ return {
146
+ fontSize: theme.__hd__.button.fontSize.default,
147
+ lineHeight: theme.__hd__.button.lineHeight.default,
148
+ ...textColorStyling(),
149
+ };
150
+ };
151
+
152
+ const StyledButtonContainer = styled(View)<{
153
+ disabled?: boolean;
154
+ pressed?: boolean;
155
+ themeVariant: ThemeVariant;
156
+ }>(({ disabled = false, pressed = false, themeVariant, theme }) => {
157
+ switch (themeVariant) {
158
+ case 'basic-transparent':
159
+ return genBasicTransparentContainerStyles(theme, pressed, disabled);
160
+ case 'filled-primary':
161
+ return genFilledContainerStyles(theme, 'primary', pressed, disabled);
162
+ case 'filled-secondary':
163
+ return genFilledContainerStyles(theme, 'secondary', pressed, disabled);
164
+ case 'outlined-primary':
165
+ return genOutlineContainerStyles(theme, 'primary', pressed, disabled);
166
+ case 'outlined-secondary':
167
+ return genOutlineContainerStyles(theme, 'secondary', pressed, disabled);
168
+ }
169
+ });
170
+
171
+ const StyledButtonText = styled(Typography.Text)<{
172
+ disabled?: boolean;
173
+ pressed?: boolean;
174
+ themeVariant: ThemeVariant;
175
+ }>(({ disabled, pressed, themeVariant, theme }) => {
176
+ const themeStyling = () => {
177
+ switch (themeVariant) {
178
+ case 'basic-transparent':
179
+ return {
180
+ fontSize: theme.__hd__.button.fontSize.default,
181
+ lineHeight: theme.__hd__.button.lineHeight.default,
182
+ color: disabled
183
+ ? theme.__hd__.button.colors.disabledText
184
+ : theme.__hd__.button.colors.invertedText,
185
+ };
186
+ case 'filled-primary':
187
+ case 'filled-secondary':
188
+ return {
189
+ fontSize: theme.__hd__.button.fontSize.default,
190
+ lineHeight: theme.__hd__.button.lineHeight.default,
191
+ color: theme.__hd__.button.colors.invertedText,
192
+ };
193
+ case 'outlined-primary':
194
+ return genOutlineTextStyles(theme, 'primary', pressed, disabled);
195
+ case 'outlined-secondary':
196
+ return genOutlineTextStyles(theme, 'secondary', pressed, disabled);
197
+ }
198
+ };
199
+ return {
200
+ flexShrink: 1,
201
+ textAlign: 'center',
202
+ fontFamily: theme.__hd__.button.fonts.default,
203
+ ...themeStyling(),
204
+ };
205
+ });
206
+
207
+ const StyledButtonIconWrapper = styled(View)<{
208
+ themePosition: 'left' | 'right';
209
+ }>(({ themePosition, theme }) => {
210
+ switch (themePosition) {
211
+ case 'left':
212
+ return { paddingRight: theme.__hd__.button.space.iconPadding };
213
+ case 'right':
214
+ return { paddingLeft: theme.__hd__.button.space.iconPadding };
215
+ }
216
+ });
217
+
218
+ const StyledButtonIcon = styled(Icon)<{
219
+ disabled?: boolean;
220
+ pressed?: boolean;
221
+ themeVariant: ThemeVariant;
222
+ }>(({ disabled, pressed, themeVariant, theme }) => {
223
+ const themeStyling = () => {
224
+ switch (themeVariant) {
225
+ case 'basic-transparent':
226
+ return {
227
+ color: disabled
228
+ ? theme.__hd__.button.colors.disabledText
229
+ : theme.__hd__.button.colors.invertedText,
230
+ };
231
+ case 'filled-primary':
232
+ case 'filled-secondary':
233
+ return { color: theme.__hd__.button.colors.invertedText };
234
+ case 'outlined-primary':
235
+ return genOutlineTextStyles(theme, 'primary', pressed, disabled);
236
+ case 'outlined-secondary':
237
+ return genOutlineTextStyles(theme, 'secondary', pressed, disabled);
238
+ }
239
+ };
240
+
241
+ return {
242
+ fontSize: theme.__hd__.button.sizes.iconSize,
243
+ ...themeStyling(),
244
+ };
245
+ });
246
+
247
+ export {
248
+ StyledButtonContainer,
249
+ StyledButtonText,
250
+ StyledButtonIconWrapper,
251
+ StyledButtonIcon,
252
+ Intent,
253
+ ThemeVariant,
254
+ };
@@ -0,0 +1,86 @@
1
+ import React from 'react';
2
+ import { fireEvent } from '@testing-library/react-native';
3
+
4
+ import renderWithTheme from '../../../testHelpers/renderWithTheme';
5
+
6
+ import Button from '..';
7
+ import { getThemeVariant } from '../Button';
8
+
9
+ describe('Button', () => {
10
+ it('renders button text', () => {
11
+ const { getByText } = renderWithTheme(
12
+ <Button text="A button" onPress={() => {}} />
13
+ );
14
+ expect(getByText('A button')).toBeDefined();
15
+ });
16
+
17
+ it('renders no icon by default', () => {
18
+ const { queryByTestId } = renderWithTheme(
19
+ <Button text="A button" testID="button" onPress={() => {}} />
20
+ );
21
+ expect(queryByTestId('button-left-icon')).toBeNull();
22
+ });
23
+
24
+ it('renders icon', () => {
25
+ const { getByTestId } = renderWithTheme(
26
+ <Button text="A button" icon="heart" testID="button" onPress={() => {}} />
27
+ );
28
+ expect(getByTestId('button-left-icon')).toBeDefined();
29
+ });
30
+
31
+ it('renders right icon', () => {
32
+ const { getByTestId } = renderWithTheme(
33
+ <Button
34
+ text="A button"
35
+ rightIcon="heart"
36
+ testID="button"
37
+ onPress={() => {}}
38
+ />
39
+ );
40
+ expect(getByTestId('button-right-icon')).toBeDefined();
41
+ });
42
+
43
+ it('renders loading icon', () => {
44
+ const { getByTestId } = renderWithTheme(
45
+ <Button text="A button" testID="button" onPress={() => {}} loading />
46
+ );
47
+ expect(getByTestId('button-loading-indicator')).toBeDefined();
48
+ });
49
+
50
+ describe('interaction', () => {
51
+ describe('button is disabled', () => {
52
+ it('NOT allows to click on', () => {
53
+ const onPress = jest.fn();
54
+ const { getByText } = renderWithTheme(
55
+ <Button text="A button" disabled onPress={onPress} />
56
+ );
57
+ fireEvent.press(getByText('A button'));
58
+ expect(onPress).not.toHaveBeenCalled();
59
+ });
60
+ });
61
+
62
+ describe('button is enabled', () => {
63
+ it('allows to click on', () => {
64
+ const onPress = jest.fn();
65
+ const { getByText } = renderWithTheme(
66
+ <Button text="A button" onPress={onPress} />
67
+ );
68
+ fireEvent.press(getByText('A button'));
69
+ expect(onPress).toHaveBeenCalledTimes(1);
70
+ });
71
+ });
72
+ });
73
+ });
74
+
75
+ describe('getThemeVariant', () => {
76
+ it.each`
77
+ variant | intent | themeVariant
78
+ ${'basic-transparent'} | ${'primary'} | ${'basic-transparent'}
79
+ ${'filled'} | ${'primary'} | ${'filled-primary'}
80
+ ${'filled'} | ${'secondary'} | ${'filled-secondary'}
81
+ ${'outlined'} | ${'primary'} | ${'outlined-primary'}
82
+ ${'outlined'} | ${'secondary'} | ${'outlined-secondary'}
83
+ `('returns $themeVariant', ({ variant, intent, themeVariant }) => {
84
+ expect(getThemeVariant(variant, intent)).toBe(themeVariant);
85
+ });
86
+ });
@@ -0,0 +1,154 @@
1
+ import React from 'react';
2
+
3
+ import renderWithTheme from '../../../testHelpers/renderWithTheme';
4
+
5
+ import {
6
+ StyledButtonContainer,
7
+ StyledButtonText,
8
+ StyledButtonIconWrapper,
9
+ StyledButtonIcon,
10
+ } from '../StyledButton';
11
+
12
+ describe('StyledButtonContainer', () => {
13
+ it.each`
14
+ themeVariant
15
+ ${'basic-transparent'}
16
+ ${'filled-primary'}
17
+ ${'filled-secondary'}
18
+ ${'outlined-primary'}
19
+ ${'outlined-secondary'}
20
+ `('has $themeVariant style', ({ themeVariant }) => {
21
+ const { toJSON } = renderWithTheme(
22
+ <StyledButtonContainer themeVariant={themeVariant} />
23
+ );
24
+
25
+ expect(toJSON()).toMatchSnapshot();
26
+ });
27
+
28
+ it.each`
29
+ themeVariant
30
+ ${'basic-transparent'}
31
+ ${'filled-primary'}
32
+ ${'filled-secondary'}
33
+ ${'outlined-primary'}
34
+ ${'outlined-secondary'}
35
+ `(
36
+ 'has pressed with the correct variant $themeVariant style',
37
+ ({ themeVariant }) => {
38
+ const { toJSON } = renderWithTheme(
39
+ <StyledButtonContainer themeVariant={themeVariant} pressed />
40
+ );
41
+ expect(toJSON()).toMatchSnapshot();
42
+ }
43
+ );
44
+
45
+ it('renders disabled correctly', () => {
46
+ const { toJSON } = renderWithTheme(
47
+ <StyledButtonContainer themeVariant="filled-primary" disabled />
48
+ );
49
+
50
+ expect(toJSON()).toMatchSnapshot();
51
+ });
52
+ });
53
+
54
+ describe('StyledButtonText', () => {
55
+ it.each`
56
+ themeVariant
57
+ ${'basic-transparent'}
58
+ ${'filled-primary'}
59
+ ${'filled-secondary'}
60
+ ${'outlined-primary'}
61
+ ${'outlined-secondary'}
62
+ `('has $themeVariant style', ({ themeVariant }) => {
63
+ const { toJSON } = renderWithTheme(
64
+ <StyledButtonText themeVariant={themeVariant}>Example</StyledButtonText>
65
+ );
66
+
67
+ expect(toJSON()).toMatchSnapshot();
68
+ });
69
+
70
+ it.each`
71
+ themeVariant
72
+ ${'basic-transparent'}
73
+ ${'filled-primary'}
74
+ ${'filled-secondary'}
75
+ ${'outlined-primary'}
76
+ ${'outlined-secondary'}
77
+ `(
78
+ 'has pressed with the correct variant $themeVariant style',
79
+ ({ themeVariant }) => {
80
+ const { toJSON } = renderWithTheme(
81
+ <StyledButtonText themeVariant={themeVariant} pressed>
82
+ Example
83
+ </StyledButtonText>
84
+ );
85
+ expect(toJSON()).toMatchSnapshot();
86
+ }
87
+ );
88
+
89
+ it('renders disabled correctly', () => {
90
+ const { toJSON } = renderWithTheme(
91
+ <StyledButtonText themeVariant="filled-primary" disabled>
92
+ Example
93
+ </StyledButtonText>
94
+ );
95
+
96
+ expect(toJSON()).toMatchSnapshot();
97
+ });
98
+ });
99
+
100
+ describe('StyledButtonIconWrapper', () => {
101
+ it.each`
102
+ themePosition
103
+ ${'left'}
104
+ ${'right'}
105
+ `('has $themePosition style', ({ themePosition }) => {
106
+ const { toJSON } = renderWithTheme(
107
+ <StyledButtonIconWrapper themePosition={themePosition} />
108
+ );
109
+
110
+ expect(toJSON()).toMatchSnapshot();
111
+ });
112
+ });
113
+
114
+ describe('StyledButtonIcon', () => {
115
+ it.each`
116
+ themeVariant
117
+ ${'basic-transparent'}
118
+ ${'filled-primary'}
119
+ ${'filled-secondary'}
120
+ ${'outlined-primary'}
121
+ ${'outlined-secondary'}
122
+ `('has $themeVariant style', ({ themeVariant }) => {
123
+ const { toJSON } = renderWithTheme(
124
+ <StyledButtonIcon icon="bell" themeVariant={themeVariant} />
125
+ );
126
+
127
+ expect(toJSON()).toMatchSnapshot();
128
+ });
129
+
130
+ it.each`
131
+ themeVariant
132
+ ${'basic-transparent'}
133
+ ${'filled-primary'}
134
+ ${'filled-secondary'}
135
+ ${'outlined-primary'}
136
+ ${'outlined-secondary'}
137
+ `(
138
+ 'has pressed with the correct variant $themeVariant style',
139
+ ({ themeVariant }) => {
140
+ const { toJSON } = renderWithTheme(
141
+ <StyledButtonIcon icon="bell" themeVariant={themeVariant} pressed />
142
+ );
143
+ expect(toJSON()).toMatchSnapshot();
144
+ }
145
+ );
146
+
147
+ it('renders disabled correctly', () => {
148
+ const { toJSON } = renderWithTheme(
149
+ <StyledButtonIcon icon="bell" themeVariant="filled-primary" disabled />
150
+ );
151
+
152
+ expect(toJSON()).toMatchSnapshot();
153
+ });
154
+ });