@hero-design/rn 7.2.2 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.expo/packager-info.json +1 -1
- package/.expo/prebuild/cached-packages.json +4 -0
- package/.expo/xcodebuild-error.log +2 -0
- package/.expo/xcodebuild.log +11199 -0
- package/.turbo/turbo-build.log +8 -8
- package/.turbo/turbo-build:types.log +2 -0
- package/.turbo/turbo-test.log +131 -0
- package/.turbo/turbo-type-check.log +7 -0
- package/es/index.js +2409 -468
- package/jest.config.js +1 -1
- package/lib/index.js +2430 -484
- package/package.json +4 -2
- package/playground/components/Avatar.tsx +102 -0
- package/playground/components/Badge.tsx +146 -9
- package/playground/components/Button.tsx +138 -35
- package/playground/components/Card.tsx +36 -1
- package/playground/components/Collapse.tsx +99 -0
- package/playground/components/Drawer.tsx +32 -0
- package/playground/components/FAB.tsx +15 -0
- package/playground/components/IconButton.tsx +67 -0
- package/playground/components/Progress.tsx +95 -0
- package/playground/components/Tabs.tsx +106 -14
- package/playground/components/Tag.tsx +45 -0
- package/playground/index.tsx +18 -0
- package/src/components/Avatar/StyledAvatar.tsx +61 -0
- package/src/components/Avatar/__tests__/StyledAvatar.spec.tsx +48 -0
- package/src/components/Avatar/__tests__/__snapshots__/StyledAvatar.spec.tsx.snap +87 -0
- package/src/components/Avatar/__tests__/__snapshots__/index.spec.tsx.snap +88 -0
- package/src/components/Avatar/__tests__/index.spec.tsx +26 -0
- package/src/components/Avatar/index.tsx +71 -0
- package/src/components/Badge/Status.tsx +77 -0
- package/src/components/Badge/StyledBadge.tsx +38 -26
- package/src/components/Badge/__tests__/Badge.spec.tsx +16 -0
- package/src/components/Badge/__tests__/Status.spec.tsx +27 -0
- package/src/components/Badge/__tests__/__snapshots__/Badge.spec.tsx.snap +133 -52
- package/src/components/Badge/__tests__/__snapshots__/Status.spec.tsx.snap +89 -0
- package/src/components/Badge/index.tsx +77 -19
- package/src/components/Button/Button.tsx +163 -0
- package/src/components/Button/LoadingIndicator/StyledLoadingIndicator.tsx +58 -0
- package/src/components/Button/LoadingIndicator/__tests__/StyledLoadingIndicator.spec.tsx +20 -0
- package/src/components/Button/LoadingIndicator/__tests__/__snapshots__/StyledLoadingIndicator.spec.tsx.snap +101 -0
- package/src/components/Button/LoadingIndicator/__tests__/__snapshots__/index.spec.tsx.snap +606 -0
- package/src/components/Button/LoadingIndicator/__tests__/index.spec.tsx +24 -0
- package/src/components/Button/LoadingIndicator/index.tsx +140 -0
- package/src/components/Button/StyledButton.tsx +254 -0
- package/src/components/Button/__tests__/Button.spec.tsx +86 -0
- package/src/components/Button/__tests__/{index.spec.tsx → IconButton.spec.tsx} +0 -0
- package/src/components/Button/__tests__/StyledButton.spec.tsx +154 -0
- package/src/components/Button/__tests__/__snapshots__/{index.spec.tsx.snap → IconButton.spec.tsx.snap} +0 -0
- package/src/components/Button/__tests__/__snapshots__/StyledButton.spec.tsx.snap +895 -0
- package/src/components/Button/index.tsx +10 -2
- package/src/components/Card/StyledCard.tsx +27 -4
- package/src/components/Card/__tests__/StyledCard.spec.tsx +15 -3
- package/src/components/Card/__tests__/__snapshots__/StyledCard.spec.tsx.snap +34 -1
- package/src/components/Card/__tests__/index.spec.tsx +16 -21
- package/src/components/Card/index.tsx +15 -2
- package/src/components/Collapse/StyledCollapse.tsx +15 -0
- package/src/components/Collapse/__tests__/StyledCollapse.spec.tsx +26 -0
- package/src/components/Collapse/__tests__/__snapshots__/StyledCollapse.spec.tsx.snap +37 -0
- package/src/components/Collapse/__tests__/__snapshots__/index.spec.tsx.snap +84 -0
- package/src/components/Collapse/__tests__/index.spec.tsx +42 -0
- package/src/components/Collapse/index.tsx +109 -0
- package/src/components/Divider/index.tsx +1 -1
- package/src/components/Drawer/StyledDrawer.tsx +39 -0
- package/src/components/Drawer/__tests__/__snapshots__/index.spec.tsx.snap +244 -0
- package/src/components/Drawer/__tests__/index.spec.tsx +37 -0
- package/src/components/Drawer/index.tsx +93 -0
- package/src/components/FAB/ActionGroup/__tests__/__snapshots__/index.spec.tsx.snap +78 -62
- package/src/components/FAB/ActionGroup/__tests__/index.spec.tsx +2 -0
- package/src/components/FAB/ActionGroup/index.tsx +13 -0
- package/src/components/FAB/FAB.tsx +63 -13
- package/src/components/FAB/StyledFAB.tsx +25 -6
- package/src/components/FAB/__tests__/__snapshots__/AnimatedFABIcon.spec.tsx.snap +6 -2
- package/src/components/FAB/__tests__/__snapshots__/StyledFAB.spec.tsx.snap +7 -3
- package/src/components/FAB/__tests__/__snapshots__/index.spec.tsx.snap +88 -6
- package/src/components/FAB/__tests__/index.spec.tsx +16 -0
- package/src/components/Progress/ProgressBar.tsx +73 -0
- package/src/components/Progress/ProgressCircle.tsx +165 -0
- package/src/components/Progress/StyledProgressBar.tsx +21 -0
- package/src/components/Progress/StyledProgressCircle.tsx +66 -0
- package/src/components/Progress/__tests__/__snapshots__/index.spec.js.snap +641 -0
- package/src/components/Progress/__tests__/index.spec.js +46 -0
- package/src/components/Progress/index.tsx +6 -0
- package/src/components/Progress/types.ts +1 -0
- package/src/components/Tabs/ActiveTabIndicator.tsx +37 -0
- package/src/components/Tabs/ScrollableTabs.tsx +216 -0
- package/src/components/Tabs/StyledScrollableTabs.tsx +60 -0
- package/src/components/Tabs/StyledTabs.tsx +30 -44
- package/src/components/Tabs/__tests__/ScrollableTabs.spec.tsx +84 -0
- package/src/components/Tabs/__tests__/__snapshots__/ScrollableTabs.spec.tsx.snap +591 -0
- package/src/components/Tabs/__tests__/__snapshots__/index.spec.tsx.snap +317 -224
- package/src/components/Tabs/__tests__/index.spec.tsx +22 -21
- package/src/components/Tabs/index.tsx +155 -114
- package/src/components/Tabs/utils.ts +13 -0
- package/src/components/Tag/StyledTag.tsx +35 -0
- package/src/components/Tag/__tests__/Tag.spec.tsx +41 -0
- package/src/components/Tag/__tests__/__snapshots__/Tag.spec.tsx.snap +153 -0
- package/src/components/Tag/index.tsx +41 -0
- package/src/components/Typography/Text/index.tsx +1 -1
- package/src/index.ts +10 -0
- package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +182 -20
- package/src/theme/components/avatar.ts +40 -0
- package/src/theme/components/badge.ts +14 -16
- package/src/theme/components/button.ts +57 -0
- package/src/theme/components/card.ts +8 -2
- package/src/theme/components/drawer.ts +24 -0
- package/src/theme/components/fab.ts +9 -2
- package/src/theme/components/progress.ts +27 -0
- package/src/theme/components/tabs.ts +22 -7
- package/src/theme/components/tag.ts +39 -0
- package/src/theme/global/borders.ts +13 -1
- package/src/theme/global/colors.ts +6 -1
- package/src/theme/global/index.ts +3 -1
- package/src/theme/global/scale.ts +3 -0
- package/src/theme/index.ts +16 -1
- package/src/utils/hooks.ts +10 -0
- package/testUtils/setup.tsx +43 -0
- package/types/playground/components/Avatar.d.ts +2 -0
- package/types/playground/components/Badge.d.ts +0 -0
- package/types/playground/components/BottomNavigation.d.ts +0 -0
- package/types/playground/components/Button.d.ts +0 -0
- package/types/playground/components/Card.d.ts +0 -0
- package/types/playground/components/Collapse.d.ts +2 -0
- package/types/playground/components/Divider.d.ts +0 -0
- package/types/playground/components/Drawer.d.ts +2 -0
- package/types/playground/components/FAB.d.ts +0 -0
- package/types/playground/components/Icon.d.ts +0 -0
- package/types/playground/components/IconButton.d.ts +2 -0
- package/types/playground/components/Progress.d.ts +2 -0
- package/types/playground/components/Tabs.d.ts +0 -0
- package/types/playground/components/Tag.d.ts +2 -0
- package/types/playground/components/Typography.d.ts +0 -0
- package/types/playground/index.d.ts +0 -0
- package/types/src/components/Avatar/StyledAvatar.d.ts +46 -0
- package/types/src/components/{BottomNavigation/__tests__/BottomNavigation.spec.d.ts → Avatar/__tests__/StyledAvatar.spec.d.ts} +0 -0
- package/types/src/components/{Card/__tests__/Card.spec.d.ts → Avatar/__tests__/index.spec.d.ts} +0 -0
- package/types/src/components/Avatar/index.d.ts +25 -0
- package/types/src/components/Badge/Status.d.ts +24 -0
- package/types/src/components/Badge/StyledBadge.d.ts +17 -9
- package/types/src/components/Badge/__tests__/Badge.spec.d.ts +0 -0
- package/types/src/components/{FAB/__tests__/StyledFABContainer.spec.d.ts → Badge/__tests__/Status.spec.d.ts} +0 -0
- package/types/src/components/Badge/index.d.ts +17 -7
- package/types/src/components/BottomNavigation/StyledBottomNavigation.d.ts +0 -0
- package/types/src/components/BottomNavigation/__tests__/index.spec.d.ts +0 -0
- package/types/src/components/BottomNavigation/index.d.ts +0 -0
- package/types/src/components/Button/Button.d.ts +57 -0
- package/types/src/components/Button/IconButton.d.ts +0 -0
- package/types/src/components/Button/LoadingIndicator/StyledLoadingIndicator.d.ts +20 -0
- package/types/src/components/{FAB/__tests__/StyledFABIcon.spec.d.ts → Button/LoadingIndicator/__tests__/StyledLoadingIndicator.spec.d.ts} +0 -0
- package/types/src/components/{Icon/__tests__/Icon.spec.d.ts → Button/LoadingIndicator/__tests__/index.spec.d.ts} +0 -0
- package/types/src/components/Button/LoadingIndicator/index.d.ts +26 -0
- package/types/src/components/Button/StyledButton.d.ts +40 -0
- package/types/src/components/{Tabs/__tests__/Tabs.spec.d.ts → Button/__tests__/Button.spec.d.ts} +0 -0
- package/types/src/components/Button/__tests__/IconButton.spec.d.ts +1 -0
- package/types/src/components/Button/__tests__/StyledButton.spec.d.ts +1 -0
- package/types/src/components/Button/__tests__/index.spec.d.ts +0 -0
- package/types/src/components/Button/index.d.ts +8 -4
- package/types/src/components/Card/StyledCard.d.ts +9 -1
- package/types/src/components/Card/__tests__/StyledCard.spec.d.ts +0 -0
- package/types/src/components/Card/__tests__/index.spec.d.ts +0 -0
- package/types/src/components/Card/index.d.ts +5 -1
- package/types/src/components/Collapse/StyledCollapse.d.ts +15 -0
- package/types/src/components/Collapse/__tests__/StyledCollapse.spec.d.ts +1 -0
- package/types/src/components/Collapse/__tests__/index.spec.d.ts +1 -0
- package/types/src/components/Collapse/index.d.ts +23 -0
- package/types/src/components/Divider/StyledDivider.d.ts +0 -0
- package/types/src/components/Divider/__tests__/StyledDivider.spec.d.ts +0 -0
- package/types/src/components/Divider/index.d.ts +0 -0
- package/types/src/components/Drawer/StyledDrawer.d.ts +25 -0
- package/types/src/components/Drawer/__tests__/index.spec.d.ts +1 -0
- package/types/src/components/Drawer/index.d.ts +25 -0
- package/types/src/components/FAB/ActionGroup/ActionItem.d.ts +0 -0
- package/types/src/components/FAB/ActionGroup/StyledActionGroup.d.ts +0 -0
- package/types/src/components/FAB/ActionGroup/StyledActionItem.d.ts +0 -0
- package/types/src/components/FAB/ActionGroup/__tests__/index.spec.d.ts +0 -0
- package/types/src/components/FAB/ActionGroup/index.d.ts +5 -1
- package/types/src/components/FAB/AnimatedFABIcon.d.ts +0 -0
- package/types/src/components/FAB/FAB.d.ts +5 -1
- package/types/src/components/FAB/StyledFAB.d.ts +8 -2
- package/types/src/components/FAB/__tests__/AnimatedFABIcon.spec.d.ts +0 -0
- package/types/src/components/FAB/__tests__/StyledFAB.spec.d.ts +0 -0
- package/types/src/components/FAB/__tests__/index.spec.d.ts +0 -0
- package/types/src/components/FAB/index.d.ts +2 -2
- package/types/src/components/Icon/HeroIcon/index.d.ts +0 -0
- package/types/src/components/Icon/IconList.d.ts +0 -0
- package/types/src/components/Icon/__tests__/index.spec.d.ts +0 -0
- package/types/src/components/Icon/index.d.ts +0 -0
- package/types/src/components/Icon/utils.d.ts +1 -1
- package/types/src/components/Progress/ProgressBar.d.ts +18 -0
- package/types/src/components/Progress/ProgressCircle.d.ts +18 -0
- package/types/src/components/Progress/StyledProgressBar.d.ts +18 -0
- package/types/src/components/Progress/StyledProgressCircle.d.ts +38 -0
- package/types/src/components/Progress/__tests__/index.spec.d.ts +1 -0
- package/types/src/components/Progress/index.d.ts +5 -0
- package/types/src/components/Progress/types.d.ts +1 -0
- package/types/src/components/Tabs/ActiveTabIndicator.d.ts +8 -0
- package/types/src/components/Tabs/ScrollableTabs.d.ts +3 -0
- package/types/src/components/Tabs/StyledScrollableTabs.d.ts +61 -0
- package/types/src/components/Tabs/StyledTabs.d.ts +22 -22
- package/types/src/components/Tabs/__tests__/ScrollableTabs.spec.d.ts +1 -0
- package/types/src/components/Tabs/__tests__/index.spec.d.ts +0 -0
- package/types/src/components/Tabs/index.d.ts +28 -19
- package/types/src/components/Tabs/utils.d.ts +2 -0
- package/types/src/components/Tag/StyledTag.d.ts +20 -0
- package/types/src/components/Tag/__tests__/Tag.spec.d.ts +1 -0
- package/types/src/components/Tag/index.d.ts +21 -0
- package/types/src/components/Typography/Text/StyledText.d.ts +0 -0
- package/types/src/components/Typography/Text/__tests__/StyledText.spec.d.ts +0 -0
- package/types/src/components/Typography/Text/__tests__/index.spec.d.ts +0 -0
- package/types/src/components/Typography/Text/index.d.ts +0 -0
- package/types/src/components/Typography/index.d.ts +0 -0
- package/types/src/index.d.ts +6 -1
- package/types/src/testHelpers/renderWithTheme.d.ts +0 -0
- package/types/src/theme/__tests__/index.spec.d.ts +0 -0
- package/types/src/theme/components/avatar.d.ts +32 -0
- package/types/src/theme/components/badge.d.ts +12 -13
- package/types/src/theme/components/bottomNavigation.d.ts +0 -0
- package/types/src/theme/components/button.d.ts +37 -0
- package/types/src/theme/components/card.d.ts +5 -1
- package/types/src/theme/components/divider.d.ts +0 -0
- package/types/src/theme/components/drawer.d.ts +21 -0
- package/types/src/theme/components/fab.d.ts +8 -1
- package/types/src/theme/components/icon.d.ts +0 -0
- package/types/src/theme/components/progress.d.ts +21 -0
- package/types/src/theme/components/tabs.d.ts +14 -2
- package/types/src/theme/components/tag.d.ts +30 -0
- package/types/src/theme/components/typography.d.ts +0 -0
- package/types/src/theme/global/borders.d.ts +7 -1
- package/types/src/theme/global/colors.d.ts +6 -1
- package/types/src/theme/global/index.d.ts +7 -1
- package/types/src/theme/global/scale.d.ts +1 -0
- package/types/src/theme/global/space.d.ts +0 -0
- package/types/src/theme/global/typography.d.ts +0 -0
- package/types/src/theme/index.d.ts +10 -0
- package/types/src/types.d.ts +0 -0
- package/types/src/utils/__tests__/scale.spec.d.ts +0 -0
- package/types/src/utils/helpers.d.ts +0 -0
- package/types/src/utils/hooks.d.ts +1 -0
- package/types/src/utils/scale.d.ts +0 -0
- package/src/components/Card/__tests__/__snapshots__/index.spec.tsx.snap +0 -33
- package/testUtils/setup.ts +0 -18
- package/types/src/components/FAB/StyledFABContainer.d.ts +0 -3
- package/types/src/components/FAB/StyledFABIcon.d.ts +0 -3
- package/types/src/styled-components.d.ts +0 -6
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import { FunctionComponent } from 'react';
|
|
2
|
+
import Button, { ButtonProps } from './Button';
|
|
1
3
|
import IconButton from './IconButton';
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
interface CompoundButtonProps extends FunctionComponent<ButtonProps> {
|
|
6
|
+
Icon: typeof IconButton;
|
|
7
|
+
}
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
const CompoundButton = Button as CompoundButtonProps;
|
|
10
|
+
|
|
11
|
+
CompoundButton.Icon = IconButton;
|
|
12
|
+
|
|
13
|
+
export default CompoundButton;
|
|
@@ -1,9 +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)
|
|
5
|
-
|
|
6
|
-
|
|
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%',
|
|
7
30
|
}));
|
|
8
31
|
|
|
9
|
-
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,15 +1,48 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`
|
|
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
42
|
},
|
|
11
43
|
undefined,
|
|
12
44
|
]
|
|
13
45
|
}
|
|
46
|
+
themeVariant="data"
|
|
14
47
|
/>
|
|
15
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
27
|
-
expect(
|
|
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('
|
|
33
|
-
|
|
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 = (
|
|
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 };
|