@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
@@ -1,5 +1,13 @@
1
+ import { FunctionComponent } from 'react';
2
+ import Button, { ButtonProps } from './Button';
1
3
  import IconButton from './IconButton';
2
4
 
3
- const Button = { Icon: IconButton } as const;
5
+ interface CompoundButtonProps extends FunctionComponent<ButtonProps> {
6
+ Icon: typeof IconButton;
7
+ }
4
8
 
5
- export default Button;
9
+ const CompoundButton = Button as CompoundButtonProps;
10
+
11
+ CompoundButton.Icon = IconButton;
12
+
13
+ export default CompoundButton;
@@ -1,10 +1,32 @@
1
1
  import { View } from 'react-native';
2
2
  import styled from '@emotion/native';
3
+ import { scale } from '../../utils/scale';
3
4
 
4
- const StyledCard = styled(View)(({ theme }) => ({
5
- borderRadius: theme.__hd__.card.radii.default,
6
- padding: theme.__hd__.card.padding.default,
7
- overflow: 'hidden',
5
+ const StyledCard = styled(View)<{ themeVariant: 'basic' | 'data' }>(
6
+ ({ themeVariant, theme }) => {
7
+ const sharedStyles = {
8
+ borderRadius: theme.__hd__.card.radii.default,
9
+ overflow: 'hidden',
10
+ } as const;
11
+
12
+ const dataStyles = {
13
+ flex: 1,
14
+ flexDirection: 'row',
15
+ };
16
+
17
+ switch (themeVariant) {
18
+ case 'basic':
19
+ return sharedStyles;
20
+ case 'data':
21
+ return { ...sharedStyles, ...dataStyles };
22
+ }
23
+ }
24
+ );
25
+
26
+ const LeftDataCard = styled(View)(({ theme }) => ({
27
+ backgroundColor: theme.__hd__.card.colors.dataCardIndicator,
28
+ width: scale(16),
29
+ height: '100%',
8
30
  }));
9
31
 
10
- export { StyledCard };
32
+ export { StyledCard, LeftDataCard };
@@ -1,10 +1,22 @@
1
1
  import React from 'react';
2
2
  import renderWithTheme from '../../../testHelpers/renderWithTheme';
3
- import { StyledCard } from '../StyledCard';
3
+ import { StyledCard, LeftDataCard } from '../StyledCard';
4
4
 
5
5
  describe('StyledCard', () => {
6
- it('renders correct style', () => {
7
- const { toJSON } = renderWithTheme(<StyledCard />);
6
+ it('renders correct basic style', () => {
7
+ const { toJSON } = renderWithTheme(<StyledCard themeVariant="basic" />);
8
+ expect(toJSON()).toMatchSnapshot();
9
+ });
10
+
11
+ it('renders correct data style', () => {
12
+ const { toJSON } = renderWithTheme(<StyledCard themeVariant="data" />);
13
+ expect(toJSON()).toMatchSnapshot();
14
+ });
15
+ });
16
+
17
+ describe('LeftDataCard', () => {
18
+ it('renders correctly', () => {
19
+ const { toJSON } = renderWithTheme(<LeftDataCard />);
8
20
  expect(toJSON()).toMatchSnapshot();
9
21
  });
10
22
  });
@@ -1,16 +1,48 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`StyledCard renders correct style 1`] = `
3
+ exports[`LeftDataCard renders correctly 1`] = `
4
+ <View
5
+ style={
6
+ Array [
7
+ Object {
8
+ "backgroundColor": "#a26fb0",
9
+ "height": "100%",
10
+ "width": 16,
11
+ },
12
+ undefined,
13
+ ]
14
+ }
15
+ />
16
+ `;
17
+
18
+ exports[`StyledCard renders correct basic style 1`] = `
19
+ <View
20
+ style={
21
+ Array [
22
+ Object {
23
+ "borderRadius": 12,
24
+ "overflow": "hidden",
25
+ },
26
+ undefined,
27
+ ]
28
+ }
29
+ themeVariant="basic"
30
+ />
31
+ `;
32
+
33
+ exports[`StyledCard renders correct data style 1`] = `
4
34
  <View
5
35
  style={
6
36
  Array [
7
37
  Object {
8
38
  "borderRadius": 12,
39
+ "flex": 1,
40
+ "flexDirection": "row",
9
41
  "overflow": "hidden",
10
- "padding": 8,
11
42
  },
12
43
  undefined,
13
44
  ]
14
45
  }
46
+ themeVariant="data"
15
47
  />
16
48
  `;
@@ -1,35 +1,30 @@
1
1
  import React from 'react';
2
- import { RenderAPI } from '@testing-library/react-native';
3
2
  import { View } from 'react-native';
4
3
  import renderWithTheme from '../../../testHelpers/renderWithTheme';
5
- import { theme } from '../../../index';
6
4
  import Card from '..';
7
5
 
8
6
  describe('Card', () => {
9
- let wrapper: RenderAPI;
10
-
11
- beforeEach(() => {
12
- wrapper = renderWithTheme(
13
- <Card
14
- style={{ backgroundColor: theme.colors.backgroundDark }}
15
- testID="card"
16
- nativeID="card-native-id"
17
- hitSlop={{ top: 1, left: 1, bottom: 1, right: 1 }}
18
- pointerEvents="box-only"
19
- removeClippedSubviews
20
- >
7
+ it('renders basic card', () => {
8
+ const { queryAllByTestId } = renderWithTheme(
9
+ <Card testID="card" variant="basic">
21
10
  <View testID="child-view" />
22
11
  </Card>
23
12
  );
24
- });
25
13
 
26
- it('renders correct', () => {
27
- expect(wrapper.queryAllByTestId('card')).toHaveLength(1);
28
-
29
- expect(wrapper.toJSON()).toMatchSnapshot();
14
+ expect(queryAllByTestId('card')).toHaveLength(1);
15
+ expect(queryAllByTestId('child-view')).toHaveLength(1);
16
+ expect(queryAllByTestId('data-card-indicator')).toHaveLength(0);
30
17
  });
31
18
 
32
- it('has child', () => {
33
- expect(wrapper.queryAllByTestId('child-view')).toHaveLength(1);
19
+ it('renders data card', () => {
20
+ const { queryAllByTestId } = renderWithTheme(
21
+ <Card testID="card" variant="data">
22
+ <View testID="child-view" />
23
+ </Card>
24
+ );
25
+
26
+ expect(queryAllByTestId('card')).toHaveLength(1);
27
+ expect(queryAllByTestId('child-view')).toHaveLength(1);
28
+ expect(queryAllByTestId('data-card-indicator')).toHaveLength(1);
34
29
  });
35
30
  });
@@ -1,12 +1,16 @@
1
1
  import React, { ReactNode } from 'react';
2
2
  import { StyleProp, ViewStyle, ViewProps } from 'react-native';
3
- import { StyledCard } from './StyledCard';
3
+ import { StyledCard, LeftDataCard } from './StyledCard';
4
4
 
5
5
  interface CardProps extends ViewProps {
6
6
  /**
7
7
  * Card's content.
8
8
  */
9
9
  children?: ReactNode;
10
+ /**
11
+ * Card type.
12
+ */
13
+ variant?: 'basic' | 'data';
10
14
  /**
11
15
  * Addditional style.
12
16
  */
@@ -17,6 +21,15 @@ interface CardProps extends ViewProps {
17
21
  testID?: string;
18
22
  }
19
23
 
20
- const Card = (props: CardProps): JSX.Element => <StyledCard {...props} />;
24
+ const Card = ({
25
+ variant = 'basic',
26
+ children,
27
+ ...nativeProps
28
+ }: CardProps): JSX.Element => (
29
+ <StyledCard {...nativeProps} testID="card" themeVariant={variant}>
30
+ {variant === 'data' && <LeftDataCard testID="data-card-indicator" />}
31
+ {children}
32
+ </StyledCard>
33
+ );
21
34
 
22
35
  export default Card;
@@ -0,0 +1,15 @@
1
+ import { Animated, View } from 'react-native';
2
+ import styled from '@emotion/native';
3
+
4
+ const StyledWrapper = styled(Animated.View)(() => ({
5
+ margin: 0,
6
+ padding: 0,
7
+ overflow: 'hidden',
8
+ }));
9
+
10
+ const StyledChildWrapper = styled(View)(() => ({
11
+ margin: 0,
12
+ padding: 0,
13
+ }));
14
+
15
+ export { StyledWrapper, StyledChildWrapper };
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { Text } from 'react-native';
3
+ import renderWithTheme from '../../../testHelpers/renderWithTheme';
4
+ import { StyledWrapper, StyledChildWrapper } from '../StyledCollapse';
5
+
6
+ describe('StyledWrapper', () => {
7
+ it('renders correct style', () => {
8
+ const { toJSON } = renderWithTheme(
9
+ <StyledWrapper>
10
+ <Text>Sample Child</Text>
11
+ </StyledWrapper>
12
+ );
13
+ expect(toJSON()).toMatchSnapshot();
14
+ });
15
+ });
16
+
17
+ describe('StyledChildWrapper', () => {
18
+ it('renders correct style', () => {
19
+ const { toJSON } = renderWithTheme(
20
+ <StyledChildWrapper>
21
+ <Text>Sample Child</Text>
22
+ </StyledChildWrapper>
23
+ );
24
+ expect(toJSON()).toMatchSnapshot();
25
+ });
26
+ });
@@ -0,0 +1,37 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`StyledChildWrapper renders correct style 1`] = `
4
+ <View
5
+ style={
6
+ Array [
7
+ Object {
8
+ "margin": 0,
9
+ "padding": 0,
10
+ },
11
+ undefined,
12
+ ]
13
+ }
14
+ >
15
+ <Text>
16
+ Sample Child
17
+ </Text>
18
+ </View>
19
+ `;
20
+
21
+ exports[`StyledWrapper renders correct style 1`] = `
22
+ <View
23
+ collapsable={false}
24
+ nativeID="animatedComponent"
25
+ style={
26
+ Object {
27
+ "margin": 0,
28
+ "overflow": "hidden",
29
+ "padding": 0,
30
+ }
31
+ }
32
+ >
33
+ <Text>
34
+ Sample Child
35
+ </Text>
36
+ </View>
37
+ `;
@@ -0,0 +1,84 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Collapse renders correctly 1`] = `
4
+ <View
5
+ collapsable={false}
6
+ nativeID="animatedComponent"
7
+ onLayout={[Function]}
8
+ style={
9
+ Object {
10
+ "margin": 0,
11
+ "maxHeight": "0%",
12
+ "overflow": "hidden",
13
+ "padding": 0,
14
+ }
15
+ }
16
+ testID="collapse"
17
+ >
18
+ <View
19
+ style={
20
+ Array [
21
+ Object {
22
+ "margin": 0,
23
+ "padding": 0,
24
+ },
25
+ undefined,
26
+ ]
27
+ }
28
+ >
29
+ <Text>
30
+ Sample Text
31
+ </Text>
32
+ </View>
33
+ </View>
34
+ `;
35
+
36
+ exports[`Collapse should not render Sample Text 1`] = `
37
+ <View
38
+ collapsable={false}
39
+ nativeID="animatedComponent"
40
+ onLayout={[Function]}
41
+ style={
42
+ Object {
43
+ "margin": 0,
44
+ "maxHeight": "0%",
45
+ "overflow": "hidden",
46
+ "padding": 0,
47
+ }
48
+ }
49
+ testID="collapse"
50
+ />
51
+ `;
52
+
53
+ exports[`Collapse should render Sample Text but not visible 1`] = `
54
+ <View
55
+ collapsable={false}
56
+ nativeID="animatedComponent"
57
+ onLayout={[Function]}
58
+ style={
59
+ Object {
60
+ "margin": 0,
61
+ "maxHeight": "0%",
62
+ "overflow": "hidden",
63
+ "padding": 0,
64
+ }
65
+ }
66
+ testID="collapse"
67
+ >
68
+ <View
69
+ style={
70
+ Array [
71
+ Object {
72
+ "margin": 0,
73
+ "padding": 0,
74
+ },
75
+ undefined,
76
+ ]
77
+ }
78
+ >
79
+ <Text>
80
+ Sample Text
81
+ </Text>
82
+ </View>
83
+ </View>
84
+ `;
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+ import { Text } from 'react-native';
3
+ import renderWithTheme from '../../../testHelpers/renderWithTheme';
4
+ import Collapse from '..';
5
+
6
+ describe('Collapse', () => {
7
+ it('renders correctly', () => {
8
+ const wrapper = renderWithTheme(
9
+ <Collapse open testID="collapse">
10
+ <Text>Sample Text</Text>
11
+ </Collapse>
12
+ );
13
+ expect(wrapper.queryAllByTestId('collapse')).toHaveLength(1);
14
+ expect(wrapper.getByText('Sample Text')).toBeDefined();
15
+
16
+ expect(wrapper.toJSON()).toMatchSnapshot();
17
+ });
18
+
19
+ it('should not render Sample Text', () => {
20
+ const wrapper = renderWithTheme(
21
+ <Collapse testID="collapse">
22
+ <Text>Sample Text</Text>
23
+ </Collapse>
24
+ );
25
+ expect(wrapper.queryAllByTestId('collapse')).toHaveLength(1);
26
+ expect(wrapper.queryByText('Sample Text')).toBeNull();
27
+
28
+ expect(wrapper.toJSON()).toMatchSnapshot();
29
+ });
30
+
31
+ it('should render Sample Text but not visible', () => {
32
+ const wrapper = renderWithTheme(
33
+ <Collapse testID="collapse" keepChildrenMounted>
34
+ <Text>Sample Text</Text>
35
+ </Collapse>
36
+ );
37
+ expect(wrapper.queryAllByTestId('collapse')).toHaveLength(1);
38
+ expect(wrapper.queryByText('Sample Text')).toBeDefined();
39
+
40
+ expect(wrapper.toJSON()).toMatchSnapshot();
41
+ });
42
+ });
@@ -0,0 +1,109 @@
1
+ import {
2
+ Animated,
3
+ Easing,
4
+ StyleProp,
5
+ ViewProps,
6
+ ViewStyle,
7
+ } from 'react-native';
8
+ import React, { ReactNode, useCallback, useEffect, useState } from 'react';
9
+ import { StyledChildWrapper, StyledWrapper } from './StyledCollapse';
10
+ import { usePrevious } from '../../utils/hooks';
11
+
12
+ type HeightSource = 'percent' | 'container';
13
+
14
+ interface CollapseProps extends ViewProps {
15
+ /*
16
+ * The collapse's content.
17
+ */
18
+ children: ReactNode;
19
+ /**
20
+ * Whether the child components will remain mounted when the Collapse is closed.
21
+ */
22
+ keepChildrenMounted?: boolean;
23
+ /**
24
+ * Whether the component is open or closed.
25
+ */
26
+ open?: boolean;
27
+ /**
28
+ * Addditional style.
29
+ */
30
+ style?: StyleProp<ViewStyle>;
31
+ /**
32
+ * Testing id of the component.
33
+ */
34
+ testID?: string;
35
+ }
36
+
37
+ const Collapse = ({
38
+ open = false,
39
+ keepChildrenMounted = false,
40
+ children,
41
+ testID,
42
+ style,
43
+ }: CollapseProps) => {
44
+ const collapseAnim = React.useRef(new Animated.Value(0)).current;
45
+ const innerRef = React.useRef(null);
46
+ const [contentHeight, setContentHeight] = React.useState<number>(0);
47
+ const [maxHeight, setMaxHeight] = React.useState<number>(0);
48
+ const [isWaitingToClose, setIsWaitingToClose] = useState<boolean>(false);
49
+ const [heightSource, setHeightSource] = useState<HeightSource>('percent');
50
+
51
+ const previousOpenState = usePrevious(open);
52
+
53
+ const animatedCallback = useCallback(() => {
54
+ if (open === true) {
55
+ setIsWaitingToClose(true);
56
+ setMaxHeight(contentHeight);
57
+ } else {
58
+ setIsWaitingToClose(false);
59
+ }
60
+ }, [open, contentHeight]);
61
+
62
+ useEffect(() => {
63
+ if (open !== previousOpenState && previousOpenState !== undefined) {
64
+ const useHeightValue = maxHeight || 100;
65
+ setHeightSource(useHeightValue > 100 ? 'container' : 'percent');
66
+ Animated.timing(collapseAnim, {
67
+ toValue: open ? useHeightValue : 0,
68
+ easing: Easing.inOut(Easing.ease),
69
+ useNativeDriver: false,
70
+ }).start(animatedCallback);
71
+ }
72
+ }, [open, previousOpenState, maxHeight]);
73
+
74
+ const checkMaxHeight = useCallback(
75
+ ({ height }) => {
76
+ if (height > contentHeight) {
77
+ setContentHeight(height);
78
+ }
79
+ },
80
+ [contentHeight]
81
+ );
82
+
83
+ return (
84
+ <StyledWrapper
85
+ onLayout={event => checkMaxHeight(event.nativeEvent.layout)}
86
+ style={[
87
+ style,
88
+ {
89
+ maxHeight:
90
+ heightSource === 'container'
91
+ ? collapseAnim
92
+ : collapseAnim.interpolate({
93
+ inputRange: [0, 100],
94
+ outputRange: ['0%', '100%'],
95
+ }),
96
+ },
97
+ ]}
98
+ testID={testID}
99
+ >
100
+ {(keepChildrenMounted === true ||
101
+ open === true ||
102
+ (open === false && isWaitingToClose === true)) && (
103
+ <StyledChildWrapper ref={innerRef}>{children}</StyledChildWrapper>
104
+ )}
105
+ </StyledWrapper>
106
+ );
107
+ };
108
+
109
+ export default Collapse;
@@ -29,11 +29,11 @@ const Divider = ({
29
29
  ...nativeProps
30
30
  }: DividerProps) => (
31
31
  <StyledDivider
32
+ {...nativeProps}
32
33
  themeMarginHorizontal={marginHorizontal}
33
34
  themeMarginVertical={marginVertical}
34
35
  style={style}
35
36
  testID={testID}
36
- {...nativeProps}
37
37
  />
38
38
  );
39
39
 
@@ -0,0 +1,39 @@
1
+ import styled from '@emotion/native';
2
+ import { ComponentProps } from 'react';
3
+ import { Animated, Pressable, StyleSheet, View } from 'react-native';
4
+
5
+ const AnimatedPressable = Animated.createAnimatedComponent(Pressable);
6
+
7
+ const StyledContainer = styled(View)<{ enableShadow: boolean }>(
8
+ ({ theme, enableShadow }) => ({
9
+ ...StyleSheet.absoluteFillObject,
10
+ shadowColor: enableShadow
11
+ ? theme.__hd__.drawer.colors.shadow
12
+ : 'transparent',
13
+ shadowOffset: theme.__hd__.drawer.shadows.offset,
14
+ shadowOpacity: theme.__hd__.drawer.shadows.opacity,
15
+ shadowRadius: theme.__hd__.drawer.shadows.radius,
16
+ overflow: 'hidden',
17
+ zIndex: 9999,
18
+ elevation: 9999,
19
+ })
20
+ );
21
+
22
+ const StyledBackdrop = styled(AnimatedPressable)<
23
+ ComponentProps<typeof AnimatedPressable>
24
+ >(({ theme }) => ({
25
+ ...StyleSheet.absoluteFillObject,
26
+ backgroundColor: theme.__hd__.drawer.colors.backdrop,
27
+ }));
28
+
29
+ const StyledDrawerContainer = styled(Animated.View)<{ enableShadow: boolean }>(
30
+ ({ theme, enableShadow }) => ({
31
+ borderBottomLeftRadius: theme.__hd__.drawer.radii.default,
32
+ borderBottomRightRadius: theme.__hd__.drawer.radii.default,
33
+ backgroundColor: theme.__hd__.drawer.colors.background,
34
+ elevation: enableShadow ? theme.__hd__.drawer.shadows.elevation : undefined,
35
+ overflow: 'hidden',
36
+ })
37
+ );
38
+
39
+ export { StyledBackdrop, StyledContainer, StyledDrawerContainer };