@hero-design/rn 7.1.3-alpha5 → 7.1.3-alpha8

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 (165) hide show
  1. package/.eslintrc.json +0 -6
  2. package/.expo/packager-info.json +1 -1
  3. package/babel.config.js +0 -14
  4. package/es/index.js +2787 -8941
  5. package/jest-setup.ts +0 -1
  6. package/jest.config.js +2 -4
  7. package/lib/index.js +2822 -8956
  8. package/package.json +5 -7
  9. package/playground/components/BottomNavigation.tsx +14 -11
  10. package/playground/components/Button.tsx +67 -0
  11. package/playground/components/Card.tsx +141 -107
  12. package/playground/components/Tabs.tsx +44 -0
  13. package/playground/index.tsx +13 -7
  14. package/src/components/Badge/StyledBadge.tsx +19 -21
  15. package/src/components/Badge/__tests__/Badge.spec.tsx +9 -18
  16. package/src/components/Badge/__tests__/__snapshots__/Badge.spec.tsx.snap +76 -96
  17. package/src/components/Badge/index.tsx +1 -1
  18. package/src/components/BottomNavigation/StyledBottomNavigation.tsx +44 -42
  19. package/src/components/BottomNavigation/__tests__/__snapshots__/{BottomNavigation.spec.tsx.snap → index.spec.tsx.snap} +130 -96
  20. package/src/components/BottomNavigation/__tests__/{BottomNavigation.spec.tsx → index.spec.tsx} +4 -4
  21. package/src/components/BottomNavigation/index.tsx +28 -32
  22. package/src/components/Button/IconButton.tsx +62 -0
  23. package/src/components/Button/__tests__/__snapshots__/index.spec.tsx.snap +46 -0
  24. package/src/components/Button/__tests__/index.spec.tsx +23 -0
  25. package/src/components/Button/index.tsx +5 -0
  26. package/src/components/Card/StyledCard.tsx +6 -6
  27. package/src/components/Card/__tests__/StyledCard.spec.tsx +2 -7
  28. package/src/components/Card/__tests__/__snapshots__/StyledCard.spec.tsx.snap +8 -11
  29. package/src/components/Card/__tests__/__snapshots__/{Card.spec.tsx.snap → index.spec.tsx.snap} +2 -8
  30. package/src/components/Card/__tests__/index.spec.tsx +35 -0
  31. package/src/components/Divider/StyledDivider.tsx +18 -60
  32. package/src/components/Divider/__tests__/StyledDivider.spec.tsx +5 -10
  33. package/src/components/Divider/__tests__/__snapshots__/StyledDivider.spec.tsx.snap +106 -70
  34. package/src/components/Divider/index.tsx +1 -1
  35. package/src/components/FAB/ActionGroup/ActionItem.tsx +2 -4
  36. package/src/components/FAB/ActionGroup/StyledActionGroup.tsx +36 -37
  37. package/src/components/FAB/ActionGroup/StyledActionItem.tsx +26 -24
  38. package/src/components/FAB/ActionGroup/__tests__/__snapshots__/index.spec.tsx.snap +271 -245
  39. package/src/components/FAB/ActionGroup/__tests__/index.spec.tsx +29 -33
  40. package/src/components/FAB/ActionGroup/index.tsx +1 -5
  41. package/src/components/FAB/AnimatedFABIcon.tsx +1 -1
  42. package/src/components/FAB/FAB.tsx +5 -9
  43. package/src/components/FAB/StyledFAB.tsx +22 -0
  44. package/src/components/FAB/__tests__/AnimatedFABIcon.spec.tsx +3 -6
  45. package/src/components/FAB/__tests__/StyledFAB.spec.tsx +24 -0
  46. package/src/components/FAB/__tests__/__snapshots__/AnimatedFABIcon.spec.tsx.snap +14 -10
  47. package/src/components/FAB/__tests__/__snapshots__/StyledFAB.spec.tsx.snap +72 -0
  48. package/src/components/FAB/__tests__/__snapshots__/index.spec.tsx.snap +16 -17
  49. package/src/components/FAB/__tests__/index.spec.tsx +21 -26
  50. package/src/components/Icon/HeroIcon/index.tsx +5 -7
  51. package/src/components/Icon/__tests__/__snapshots__/{Icon.spec.tsx.snap → index.spec.tsx.snap} +21 -12
  52. package/src/components/Icon/__tests__/index.spec.tsx +25 -0
  53. package/src/components/Icon/index.tsx +1 -1
  54. package/src/components/Tabs/StyledTabs.tsx +70 -0
  55. package/src/components/Tabs/__tests__/__snapshots__/index.spec.tsx.snap +321 -0
  56. package/src/components/Tabs/__tests__/index.spec.tsx +79 -0
  57. package/src/components/Tabs/index.tsx +185 -0
  58. package/src/components/Typography/Text/StyledText.tsx +19 -64
  59. package/src/components/Typography/Text/__tests__/__snapshots__/StyledText.spec.tsx.snap +90 -63
  60. package/src/emotion.d.ts +6 -0
  61. package/src/index.ts +9 -3
  62. package/src/testHelpers/renderWithTheme.tsx +2 -1
  63. package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +70 -48
  64. package/src/theme/components/badge.ts +10 -9
  65. package/src/theme/components/bottomNavigation.ts +7 -3
  66. package/src/theme/components/card.ts +2 -2
  67. package/src/theme/components/divider.ts +6 -6
  68. package/src/theme/components/fab.ts +19 -17
  69. package/src/theme/components/tabs.ts +20 -0
  70. package/src/theme/components/typography.ts +4 -4
  71. package/src/theme/global/borders.ts +8 -2
  72. package/src/theme/global/colors.ts +3 -1
  73. package/src/theme/global/index.ts +31 -17
  74. package/src/theme/global/scale.ts +18 -0
  75. package/src/theme/global/space.ts +23 -13
  76. package/src/theme/global/typography.ts +71 -27
  77. package/src/theme/index.ts +29 -13
  78. package/src/types.ts +7 -0
  79. package/src/utils/__tests__/scale.spec.ts +3 -3
  80. package/testUtils/setup.ts +11 -0
  81. package/tsconfig.json +1 -5
  82. package/types/playground/components/BottomNavigation.d.ts +2 -2
  83. package/types/playground/components/Button.d.ts +2 -0
  84. package/types/playground/components/Tabs.d.ts +2 -0
  85. package/types/src/components/Badge/StyledBadge.d.ts +16 -5
  86. package/types/src/components/Badge/index.d.ts +1 -1
  87. package/types/src/components/BottomNavigation/StyledBottomNavigation.d.ts +44 -9
  88. package/types/src/components/{Typography/Text/__test__ → BottomNavigation/__tests__}/index.spec.d.ts +0 -0
  89. package/types/src/components/BottomNavigation/index.d.ts +19 -14
  90. package/types/src/components/Button/IconButton.d.ts +34 -0
  91. package/types/{theme → src/components/Button}/__tests__/index.spec.d.ts +0 -0
  92. package/types/src/components/Button/index.d.ts +4 -0
  93. package/types/src/components/Card/StyledCard.d.ts +7 -1
  94. package/types/{components/Card/__tests__/Card.spec.d.ts → src/components/Card/__tests__/index.spec.d.ts} +0 -0
  95. package/types/src/components/Divider/StyledDivider.d.ts +8 -2
  96. package/types/src/components/Divider/index.d.ts +1 -1
  97. package/types/src/components/FAB/ActionGroup/StyledActionGroup.d.ts +25 -7
  98. package/types/src/components/FAB/ActionGroup/StyledActionItem.d.ts +11 -2
  99. package/types/src/components/FAB/ActionGroup/index.d.ts +1 -1
  100. package/types/src/components/FAB/FAB.d.ts +4 -4
  101. package/types/src/components/FAB/StyledFAB.d.ts +14 -0
  102. package/types/{components/Card/__tests__/StyledCard.spec.d.ts → src/components/FAB/__tests__/StyledFAB.spec.d.ts} +0 -0
  103. package/types/src/components/Icon/HeroIcon/index.d.ts +8 -2
  104. package/types/{components/Divider/__tests__/StyledDivider.spec.d.ts → src/components/Icon/__tests__/index.spec.d.ts} +0 -0
  105. package/types/src/components/Icon/index.d.ts +1 -1
  106. package/types/src/components/Icon/utils.d.ts +1 -1
  107. package/types/src/components/Tabs/StyledTabs.d.ts +55 -0
  108. package/types/{components/ExampleComponent/__tests__/StyledView.spec.d.ts → src/components/Tabs/__tests__/index.spec.d.ts} +0 -0
  109. package/types/src/components/Tabs/index.d.ts +45 -0
  110. package/types/src/components/Typography/Text/StyledText.d.ts +8 -2
  111. package/types/src/index.d.ts +6 -3
  112. package/types/src/theme/components/badge.d.ts +8 -7
  113. package/types/src/theme/components/bottomNavigation.d.ts +8 -2
  114. package/types/src/theme/components/card.d.ts +2 -2
  115. package/types/src/theme/components/divider.d.ts +6 -6
  116. package/types/src/theme/components/fab.d.ts +19 -17
  117. package/types/src/theme/components/tabs.d.ts +15 -0
  118. package/types/src/theme/components/typography.d.ts +4 -4
  119. package/types/src/theme/global/borders.d.ts +4 -3
  120. package/types/src/theme/global/colors.d.ts +2 -2
  121. package/types/src/theme/global/index.d.ts +10 -45
  122. package/types/src/theme/global/scale.d.ts +8 -0
  123. package/types/src/theme/global/space.d.ts +8 -7
  124. package/types/src/theme/global/typography.d.ts +9 -16
  125. package/types/src/theme/index.d.ts +4 -2
  126. package/types/src/types.d.ts +5 -0
  127. package/lib/assets/fonts/be-vietnam-pro-light.ttf +0 -0
  128. package/lib/assets/fonts/be-vietnam-pro-regular.ttf +0 -0
  129. package/lib/assets/fonts/be-vietnam-pro-semibold.ttf +0 -0
  130. package/src/components/Card/__tests__/Card.spec.tsx +0 -36
  131. package/src/components/FAB/StyledFABContainer.tsx +0 -14
  132. package/src/components/FAB/StyledFABIcon.tsx +0 -9
  133. package/src/components/FAB/__tests__/StyledFABContainer.spec.tsx +0 -18
  134. package/src/components/FAB/__tests__/StyledFABIcon.spec.tsx +0 -16
  135. package/src/components/FAB/__tests__/__snapshots__/StyledFABContainer.spec.tsx.snap +0 -46
  136. package/src/components/FAB/__tests__/__snapshots__/StyledFABIcon.spec.tsx.snap +0 -21
  137. package/src/components/Icon/__tests__/Icon.spec.tsx +0 -36
  138. package/src/styled-components.ts +0 -14
  139. package/src/styled.d.ts +0 -7
  140. package/types/components/Card/StyledCard.d.ts +0 -3
  141. package/types/components/Card/index.d.ts +0 -5
  142. package/types/components/Divider/StyledDivider.d.ts +0 -7
  143. package/types/components/Divider/index.d.ts +0 -12
  144. package/types/components/ExampleComponent/StyledView.d.ts +0 -7
  145. package/types/components/ExampleComponent/index.d.ts +0 -16
  146. package/types/index.d.ts +0 -5
  147. package/types/src/components/BottomNavigation/__tests__/BottomNavigation.spec.d.ts +0 -1
  148. package/types/src/components/Card/__tests__/Card.spec.d.ts +0 -1
  149. package/types/src/components/FAB/StyledFABContainer.d.ts +0 -3
  150. package/types/src/components/FAB/StyledFABIcon.d.ts +0 -3
  151. package/types/src/components/FAB/__tests__/StyledFABContainer.spec.d.ts +0 -1
  152. package/types/src/components/FAB/__tests__/StyledFABIcon.spec.d.ts +0 -1
  153. package/types/src/components/Icon/__tests__/Icon.spec.d.ts +0 -1
  154. package/types/src/components/Typography/Text/__test__/StyledText.spec.d.ts +0 -1
  155. package/types/src/styled-components.d.ts +0 -6
  156. package/types/styled-components.d.ts +0 -6
  157. package/types/theme/components/card.d.ts +0 -10
  158. package/types/theme/components/divider.d.ts +0 -17
  159. package/types/theme/components/exampleComponent.d.ts +0 -14
  160. package/types/theme/global/borders.d.ts +0 -4
  161. package/types/theme/global/colors.d.ts +0 -26
  162. package/types/theme/global/index.d.ts +0 -63
  163. package/types/theme/global/space.d.ts +0 -12
  164. package/types/theme/global/typography.d.ts +0 -21
  165. package/types/theme/index.d.ts +0 -13
@@ -14,21 +14,23 @@ exports[`BottomNavigation renders correctly 1`] = `
14
14
  >
15
15
  <View
16
16
  style={
17
- Object {
18
- "flexBasis": 0,
19
- "flexGrow": 1,
20
- "flexShrink": 1,
21
- "overflow": "hidden",
22
- }
17
+ Array [
18
+ Object {
19
+ "flex": 1,
20
+ "overflow": "hidden",
21
+ },
22
+ undefined,
23
+ ]
23
24
  }
24
25
  >
25
26
  <View
26
27
  style={
27
- Object {
28
- "flexBasis": 0,
29
- "flexGrow": 1,
30
- "flexShrink": 1,
31
- }
28
+ Array [
29
+ Object {
30
+ "flex": 1,
31
+ },
32
+ undefined,
33
+ ]
32
34
  }
33
35
  >
34
36
  <View
@@ -38,14 +40,14 @@ exports[`BottomNavigation renders correctly 1`] = `
38
40
  pointerEvents="auto"
39
41
  removeClippedSubviews={false}
40
42
  style={
41
- Object {
42
- "display": "flex",
43
- "flexBasis": 0,
44
- "flexGrow": 1,
45
- "flexShrink": 1,
46
- }
43
+ Array [
44
+ Object {
45
+ "display": "flex",
46
+ "flex": 1,
47
+ },
48
+ undefined,
49
+ ]
47
50
  }
48
- testID="route-screen-home"
49
51
  themeVisibility={true}
50
52
  >
51
53
  <Text>
@@ -55,21 +57,24 @@ exports[`BottomNavigation renders correctly 1`] = `
55
57
  </View>
56
58
  <View
57
59
  style={
58
- Object {
59
- "backgroundColor": "#ffffff",
60
- "elevation": 10,
61
- "height": 72,
62
- "paddingBottom": 0,
63
- "paddingLeft": 0,
64
- "paddingRight": 0,
65
- "shadowColor": "#292a2b",
66
- "shadowOffset": Object {
67
- "height": 3,
68
- "width": 0,
60
+ Array [
61
+ Object {
62
+ "backgroundColor": "#ffffff",
63
+ "elevation": 10,
64
+ "height": 72,
65
+ "paddingBottom": 0,
66
+ "paddingLeft": 0,
67
+ "paddingRight": 0,
68
+ "shadowColor": "#292a2b",
69
+ "shadowOffset": Object {
70
+ "height": 3,
71
+ "width": 0,
72
+ },
73
+ "shadowOpacity": 0.27,
74
+ "shadowRadius": 4.65,
69
75
  },
70
- "shadowOpacity": 0.27,
71
- "shadowRadius": 4.65,
72
- }
76
+ undefined,
77
+ ]
73
78
  }
74
79
  themeInsets={
75
80
  Object {
@@ -82,14 +87,15 @@ exports[`BottomNavigation renders correctly 1`] = `
82
87
  >
83
88
  <View
84
89
  style={
85
- Object {
86
- "alignItems": "center",
87
- "flexBasis": 0,
88
- "flexDirection": "row",
89
- "flexGrow": 1,
90
- "flexShrink": 1,
91
- "overflow": "hidden",
92
- }
90
+ Array [
91
+ Object {
92
+ "alignItems": "center",
93
+ "flex": 1,
94
+ "flexDirection": "row",
95
+ "overflow": "hidden",
96
+ },
97
+ undefined,
98
+ ]
93
99
  }
94
100
  >
95
101
  <View
@@ -103,21 +109,25 @@ exports[`BottomNavigation renders correctly 1`] = `
103
109
  onResponderTerminationRequest={[Function]}
104
110
  onStartShouldSetResponder={[Function]}
105
111
  style={
106
- Object {
107
- "alignItems": "center",
108
- "flexBasis": 0,
109
- "flexGrow": 1,
110
- "flexShrink": 1,
111
- }
112
+ Array [
113
+ Object {
114
+ "alignItems": "center",
115
+ "flex": 1,
116
+ },
117
+ undefined,
118
+ ]
112
119
  }
113
120
  >
114
121
  <HeroIcon
115
122
  name="home"
116
123
  style={
117
- Object {
118
- "color": "#7622d7",
119
- "fontSize": 24,
120
- }
124
+ Array [
125
+ Object {
126
+ "color": "#7622d7",
127
+ "fontSize": 24,
128
+ },
129
+ undefined,
130
+ ]
121
131
  }
122
132
  testID="hero-icon-home"
123
133
  themeIntent="primary"
@@ -129,14 +139,17 @@ exports[`BottomNavigation renders correctly 1`] = `
129
139
  Array [
130
140
  Object {
131
141
  "color": "#7622d7",
132
- "fontFamily": "Be Vietnam Pro SemiBold",
142
+ "fontFamily": "BeVietnamPro-SemiBold",
133
143
  "fontSize": 12,
134
144
  "letterSpacing": 0.36,
135
145
  "lineHeight": 20,
136
146
  },
137
- Object {
138
- "marginTop": 4,
139
- },
147
+ Array [
148
+ Object {
149
+ "marginTop": 4,
150
+ },
151
+ undefined,
152
+ ],
140
153
  ]
141
154
  }
142
155
  themeFontSize="small"
@@ -157,21 +170,25 @@ exports[`BottomNavigation renders correctly 1`] = `
157
170
  onResponderTerminationRequest={[Function]}
158
171
  onStartShouldSetResponder={[Function]}
159
172
  style={
160
- Object {
161
- "alignItems": "center",
162
- "flexBasis": 0,
163
- "flexGrow": 1,
164
- "flexShrink": 1,
165
- }
173
+ Array [
174
+ Object {
175
+ "alignItems": "center",
176
+ "flex": 1,
177
+ },
178
+ undefined,
179
+ ]
166
180
  }
167
181
  >
168
182
  <HeroIcon
169
183
  name="speaker-outlined"
170
184
  style={
171
- Object {
172
- "color": "#292a2b",
173
- "fontSize": 24,
174
- }
185
+ Array [
186
+ Object {
187
+ "color": "#292a2b",
188
+ "fontSize": 24,
189
+ },
190
+ undefined,
191
+ ]
175
192
  }
176
193
  testID="hero-icon-speaker-outlined"
177
194
  themeIntent="text"
@@ -183,14 +200,17 @@ exports[`BottomNavigation renders correctly 1`] = `
183
200
  Array [
184
201
  Object {
185
202
  "color": "#292a2b",
186
- "fontFamily": "Be Vietnam Pro SemiBold",
203
+ "fontFamily": "BeVietnamPro-SemiBold",
187
204
  "fontSize": 12,
188
205
  "letterSpacing": 0.36,
189
206
  "lineHeight": 20,
190
207
  },
191
- Object {
192
- "marginTop": 4,
193
- },
208
+ Array [
209
+ Object {
210
+ "marginTop": 4,
211
+ },
212
+ undefined,
213
+ ],
194
214
  ]
195
215
  }
196
216
  themeFontSize="small"
@@ -211,21 +231,25 @@ exports[`BottomNavigation renders correctly 1`] = `
211
231
  onResponderTerminationRequest={[Function]}
212
232
  onStartShouldSetResponder={[Function]}
213
233
  style={
214
- Object {
215
- "alignItems": "center",
216
- "flexBasis": 0,
217
- "flexGrow": 1,
218
- "flexShrink": 1,
219
- }
234
+ Array [
235
+ Object {
236
+ "alignItems": "center",
237
+ "flex": 1,
238
+ },
239
+ undefined,
240
+ ]
220
241
  }
221
242
  >
222
243
  <HeroIcon
223
244
  name="bell-outlined"
224
245
  style={
225
- Object {
226
- "color": "#292a2b",
227
- "fontSize": 24,
228
- }
246
+ Array [
247
+ Object {
248
+ "color": "#292a2b",
249
+ "fontSize": 24,
250
+ },
251
+ undefined,
252
+ ]
229
253
  }
230
254
  testID="hero-icon-bell-outlined"
231
255
  themeIntent="text"
@@ -237,14 +261,17 @@ exports[`BottomNavigation renders correctly 1`] = `
237
261
  Array [
238
262
  Object {
239
263
  "color": "#292a2b",
240
- "fontFamily": "Be Vietnam Pro SemiBold",
264
+ "fontFamily": "BeVietnamPro-SemiBold",
241
265
  "fontSize": 12,
242
266
  "letterSpacing": 0.36,
243
267
  "lineHeight": 20,
244
268
  },
245
- Object {
246
- "marginTop": 4,
247
- },
269
+ Array [
270
+ Object {
271
+ "marginTop": 4,
272
+ },
273
+ undefined,
274
+ ],
248
275
  ]
249
276
  }
250
277
  themeFontSize="small"
@@ -265,21 +292,25 @@ exports[`BottomNavigation renders correctly 1`] = `
265
292
  onResponderTerminationRequest={[Function]}
266
293
  onStartShouldSetResponder={[Function]}
267
294
  style={
268
- Object {
269
- "alignItems": "center",
270
- "flexBasis": 0,
271
- "flexGrow": 1,
272
- "flexShrink": 1,
273
- }
295
+ Array [
296
+ Object {
297
+ "alignItems": "center",
298
+ "flex": 1,
299
+ },
300
+ undefined,
301
+ ]
274
302
  }
275
303
  >
276
304
  <HeroIcon
277
305
  name="user-outlined"
278
306
  style={
279
- Object {
280
- "color": "#292a2b",
281
- "fontSize": 24,
282
- }
307
+ Array [
308
+ Object {
309
+ "color": "#292a2b",
310
+ "fontSize": 24,
311
+ },
312
+ undefined,
313
+ ]
283
314
  }
284
315
  testID="hero-icon-user-outlined"
285
316
  themeIntent="text"
@@ -291,14 +322,17 @@ exports[`BottomNavigation renders correctly 1`] = `
291
322
  Array [
292
323
  Object {
293
324
  "color": "#292a2b",
294
- "fontFamily": "Be Vietnam Pro SemiBold",
325
+ "fontFamily": "BeVietnamPro-SemiBold",
295
326
  "fontSize": 12,
296
327
  "letterSpacing": 0.36,
297
328
  "lineHeight": 20,
298
329
  },
299
- Object {
300
- "marginTop": 4,
301
- },
330
+ Array [
331
+ Object {
332
+ "marginTop": 4,
333
+ },
334
+ undefined,
335
+ ],
302
336
  ]
303
337
  }
304
338
  themeFontSize="small"
@@ -3,16 +3,16 @@ import { Text } from 'react-native';
3
3
  import { fireEvent } from '@testing-library/react-native';
4
4
  import { SafeAreaProvider } from 'react-native-safe-area-context';
5
5
  import renderWithTheme from '../../../testHelpers/renderWithTheme';
6
- import BottomNavigation, { Tab } from '..';
6
+ import BottomNavigation, { BottomNavigationTabType } from '..';
7
7
 
8
8
  const TestComponent = (
9
9
  props: Omit<
10
10
  ComponentProps<typeof BottomNavigation>,
11
- 'selectedTabKey' | 'onChange' | 'tabs'
11
+ 'selectedTabKey' | 'onTabPress' | 'tabs'
12
12
  >
13
13
  ) => {
14
14
  const [selectedTabKey, setSelectedTabKey] = React.useState('home');
15
- const tabs: Tab<string>[] = [
15
+ const tabs: BottomNavigationTabType[] = [
16
16
  {
17
17
  key: 'home',
18
18
  title: 'Home',
@@ -50,7 +50,7 @@ const TestComponent = (
50
50
  {...props}
51
51
  tabs={tabs}
52
52
  selectedTabKey={selectedTabKey}
53
- onChange={newTabKey => setSelectedTabKey(newTabKey)}
53
+ onTabPress={newTabKey => setSelectedTabKey(newTabKey)}
54
54
  />
55
55
  </SafeAreaProvider>
56
56
  );
@@ -1,4 +1,4 @@
1
- import React, { ComponentProps, ReactNode } from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
  import {
3
3
  TouchableWithoutFeedback,
4
4
  StyleProp,
@@ -6,10 +6,8 @@ import {
6
6
  ViewProps,
7
7
  } from 'react-native';
8
8
  import { useSafeAreaInsets } from 'react-native-safe-area-context';
9
- import { useTheme } from 'styled-components-native';
10
- import Icon from '../Icon';
9
+ import Icon, { IconName } from '../Icon';
11
10
  import { isHeroIcon } from '../Icon/utils';
12
- import Typography from '../Typography';
13
11
  import {
14
12
  BottomBar,
15
13
  BottomBarItem,
@@ -17,25 +15,23 @@ import {
17
15
  BottomNavigationContainer,
18
16
  BottomNavigationTab,
19
17
  ContentWrapper,
18
+ StyledBottomBarText,
20
19
  } from './StyledBottomNavigation';
21
20
  import { isIOS } from '../../utils/helpers';
22
21
 
23
- type IconType = ComponentProps<typeof Icon>['icon'];
24
-
25
- export type Tab<V> = {
26
- key: V;
22
+ export type BottomNavigationTabType = {
23
+ key: string;
27
24
  title?: string;
28
- icon: IconType;
25
+ icon: IconName;
29
26
  component: ReactNode;
30
27
  testID?: string;
31
28
  };
32
29
 
33
- interface BottomNavigationType<V extends string | number, T extends Tab<V>>
34
- extends ViewProps {
30
+ interface BottomNavigationProps extends ViewProps {
35
31
  /**
36
- * Callback which is called on tab change, receiving id of upcoming active Tab.
32
+ * Callback which is called on tab press, receiving key of upcoming active Tab.
37
33
  */
38
- onChange: (key: V) => void;
34
+ onTabPress: (key: string) => void;
39
35
  /**
40
36
  * Whether inactive tabs should be removed and unmounted in React.
41
37
  * Defaults to `false`.
@@ -44,13 +40,19 @@ interface BottomNavigationType<V extends string | number, T extends Tab<V>>
44
40
  /**
45
41
  * Current selected tab key.
46
42
  */
47
- selectedTabKey: V;
43
+ selectedTabKey: string;
48
44
  /**
49
- * List of Tab to be rendered. Each Tab must have an unique id.
45
+ * List of Tabs to be rendered. Each Tab must have an unique key.
50
46
  */
51
- tabs: T[];
47
+ tabs: {
48
+ key: string;
49
+ title?: string;
50
+ icon: IconName;
51
+ component: ReactNode;
52
+ testID?: string;
53
+ }[];
52
54
  /**
53
- * Addditional style.
55
+ * Additional style.
54
56
  */
55
57
  style?: StyleProp<ViewStyle>;
56
58
  /**
@@ -59,19 +61,18 @@ interface BottomNavigationType<V extends string | number, T extends Tab<V>>
59
61
  testID?: string;
60
62
  }
61
63
 
62
- const getInactiveIcon = (icon: IconType): IconType => {
64
+ const getInactiveIcon = (icon: IconName): IconName => {
63
65
  const inactiveIcon = `${icon}-outlined`;
64
66
  return isHeroIcon(inactiveIcon) ? inactiveIcon : icon;
65
67
  };
66
68
 
67
- const BottomNavigation = <V extends string | number, T extends Tab<V>>({
68
- onChange,
69
+ const BottomNavigation = ({
70
+ onTabPress,
69
71
  renderActiveTabOnly = false,
70
72
  selectedTabKey,
71
73
  tabs,
72
74
  ...nativeProps
73
- }: BottomNavigationType<V, T>): JSX.Element => {
74
- const theme = useTheme();
75
+ }: BottomNavigationProps): JSX.Element => {
75
76
  const insets = useSafeAreaInsets();
76
77
 
77
78
  /**
@@ -88,7 +89,7 @@ const BottomNavigation = <V extends string | number, T extends Tab<V>>({
88
89
  <BottomNavigationContainer {...nativeProps}>
89
90
  <ContentWrapper>
90
91
  {tabs.map(tab => {
91
- const { key, component } = tab;
92
+ const { key, component, testID } = tab;
92
93
  const active = selectedTabKey === key;
93
94
 
94
95
  if (renderActiveTabOnly && !active) {
@@ -103,7 +104,7 @@ const BottomNavigation = <V extends string | number, T extends Tab<V>>({
103
104
  return (
104
105
  <BottomNavigationTab
105
106
  key={key}
106
- testID={`route-screen-${selectedTabKey}`}
107
+ testID={testID ? `route-screen-${testID}` : undefined}
107
108
  pointerEvents={active ? 'auto' : 'none'}
108
109
  accessibilityElementsHidden={!active}
109
110
  importantForAccessibility={
@@ -132,11 +133,7 @@ const BottomNavigation = <V extends string | number, T extends Tab<V>>({
132
133
  return (
133
134
  <TouchableWithoutFeedback
134
135
  key={key}
135
- onPress={() => {
136
- if (key !== selectedTabKey) {
137
- onChange(key);
138
- }
139
- }}
136
+ onPress={() => onTabPress(key)}
140
137
  testID={testID}
141
138
  >
142
139
  <BottomBarItem>
@@ -146,15 +143,14 @@ const BottomNavigation = <V extends string | number, T extends Tab<V>>({
146
143
  testID={`hero-icon-${icon}`}
147
144
  />
148
145
  {title && (
149
- <Typography.Text
146
+ <StyledBottomBarText
150
147
  fontSize="small"
151
148
  fontWeight="semi-bold"
152
149
  intent={active ? 'primary' : 'body'}
153
- style={{ marginTop: theme.space.xsmall }}
154
150
  numberOfLines={1}
155
151
  >
156
152
  {title}
157
- </Typography.Text>
153
+ </StyledBottomBarText>
158
154
  )}
159
155
  </BottomBarItem>
160
156
  </TouchableWithoutFeedback>
@@ -0,0 +1,62 @@
1
+ import React from 'react';
2
+
3
+ import {
4
+ StyleProp,
5
+ ViewStyle,
6
+ TouchableOpacity,
7
+ TouchableOpacityProps,
8
+ } from 'react-native';
9
+
10
+ import Icon, { IconProps, IconName } from '../Icon';
11
+
12
+ export interface IconButtonProps {
13
+ /**
14
+ * Set how far you can touch from the button.
15
+ */
16
+ hitSlop?: TouchableOpacityProps['hitSlop'];
17
+ /**
18
+ * Name of the Icon.
19
+ */
20
+ icon: IconName;
21
+ /**
22
+ * Intent of the Icon.
23
+ */
24
+ intent?: IconProps['intent'];
25
+ /**
26
+ * Set the handler to handle press event.
27
+ */
28
+ onPress: () => void;
29
+ /**
30
+ * Size of the Icon.
31
+ */
32
+ size?: IconProps['size'];
33
+ /**
34
+ * Additional style.
35
+ */
36
+ style?: StyleProp<ViewStyle>;
37
+ /**
38
+ * Testing id of component.
39
+ */
40
+ testID?: string;
41
+ }
42
+
43
+ const IconButton = ({
44
+ hitSlop,
45
+ onPress,
46
+ icon,
47
+ testID,
48
+ style,
49
+ size,
50
+ intent,
51
+ }: IconButtonProps) => (
52
+ <TouchableOpacity
53
+ style={style}
54
+ onPress={onPress}
55
+ testID={testID}
56
+ hitSlop={hitSlop}
57
+ >
58
+ <Icon icon={icon} size={size} intent={intent} />
59
+ </TouchableOpacity>
60
+ );
61
+
62
+ export default IconButton;
@@ -0,0 +1,46 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`IconButton renders correctly 1`] = `
4
+ <View
5
+ accessible={true}
6
+ collapsable={false}
7
+ focusable={true}
8
+ hitSlop={
9
+ Object {
10
+ "bottom": 4,
11
+ "left": 6,
12
+ "right": 6,
13
+ "top": 4,
14
+ }
15
+ }
16
+ nativeID="animatedComponent"
17
+ onClick={[Function]}
18
+ onResponderGrant={[Function]}
19
+ onResponderMove={[Function]}
20
+ onResponderRelease={[Function]}
21
+ onResponderTerminate={[Function]}
22
+ onResponderTerminationRequest={[Function]}
23
+ onStartShouldSetResponder={[Function]}
24
+ style={
25
+ Object {
26
+ "opacity": 1,
27
+ }
28
+ }
29
+ testID="icon-btn"
30
+ >
31
+ <HeroIcon
32
+ name="home"
33
+ style={
34
+ Array [
35
+ Object {
36
+ "color": "#292a2b",
37
+ "fontSize": 24,
38
+ },
39
+ undefined,
40
+ ]
41
+ }
42
+ themeIntent="text"
43
+ themeSize="medium"
44
+ />
45
+ </View>
46
+ `;
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { fireEvent } from '@testing-library/react-native';
3
+ import renderWithTheme from '../../../testHelpers/renderWithTheme';
4
+
5
+ import Button from '..';
6
+
7
+ describe('IconButton', () => {
8
+ it('renders correctly', () => {
9
+ const onPress = jest.fn();
10
+ const { toJSON, getByTestId } = renderWithTheme(
11
+ <Button.Icon
12
+ icon="home"
13
+ onPress={onPress}
14
+ testID="icon-btn"
15
+ hitSlop={{ top: 4, bottom: 4, right: 6, left: 6 }}
16
+ />
17
+ );
18
+
19
+ fireEvent.press(getByTestId('icon-btn'));
20
+ expect(onPress).toBeCalledTimes(1);
21
+ expect(toJSON()).toMatchSnapshot();
22
+ });
23
+ });
@@ -0,0 +1,5 @@
1
+ import IconButton from './IconButton';
2
+
3
+ const Button = { Icon: IconButton } as const;
4
+
5
+ export default Button;
@@ -1,10 +1,10 @@
1
1
  import { View } from 'react-native';
2
- import styled from 'styled-components-native';
2
+ import styled from '@emotion/native';
3
3
 
4
- const StyledCard = styled(View)<{}>`
5
- border-radius: ${({ theme }) => theme.__hd__.card.radii.default};
6
- padding: ${({ theme }) => theme.__hd__.card.padding.default};
7
- overflow: hidden;
8
- `;
4
+ const StyledCard = styled(View)(({ theme }) => ({
5
+ borderRadius: theme.__hd__.card.radii.default,
6
+ padding: theme.__hd__.card.padding.default,
7
+ overflow: 'hidden',
8
+ }));
9
9
 
10
10
  export { StyledCard };