@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,43 +1,50 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
Animated,
|
|
4
|
+
TouchableWithoutFeedback,
|
|
5
|
+
View,
|
|
4
6
|
StyleProp,
|
|
5
7
|
ViewStyle,
|
|
6
8
|
ViewProps,
|
|
7
|
-
FlatList,
|
|
8
9
|
} from 'react-native';
|
|
9
10
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
11
|
+
import { useTheme } from '@emotion/react';
|
|
12
|
+
import PagerView, {
|
|
13
|
+
PagerViewOnPageScrollEventData,
|
|
14
|
+
} from 'react-native-pager-view';
|
|
15
|
+
import Typography from '../Typography';
|
|
10
16
|
import {
|
|
11
|
-
|
|
17
|
+
ContentWrapper,
|
|
12
18
|
HeaderTabWrapper,
|
|
13
|
-
|
|
14
|
-
StyledHeaderTabIcon,
|
|
19
|
+
HeaderTabItem,
|
|
15
20
|
TabContainer,
|
|
16
21
|
TabScreen,
|
|
17
|
-
|
|
18
|
-
StyledFlatList,
|
|
22
|
+
HeaderTab,
|
|
19
23
|
} from './StyledTabs';
|
|
20
|
-
import
|
|
24
|
+
import Badge from '../Badge';
|
|
21
25
|
import { IconName } from '../Icon';
|
|
26
|
+
import ActiveTabIndicator from './ActiveTabIndicator';
|
|
27
|
+
import ScrollableTabs from './ScrollableTabs';
|
|
28
|
+
|
|
29
|
+
export type ItemType =
|
|
30
|
+
| string
|
|
31
|
+
| IconName
|
|
32
|
+
| ((props: { color: string }) => ReactNode);
|
|
22
33
|
|
|
23
34
|
export type TabType = {
|
|
24
35
|
key: string;
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
activeItem: ItemType;
|
|
37
|
+
inactiveItem?: ItemType;
|
|
27
38
|
component: ReactNode;
|
|
28
39
|
testID?: string;
|
|
40
|
+
showBadge?: boolean;
|
|
29
41
|
};
|
|
30
42
|
|
|
31
|
-
interface TabsProps extends ViewProps {
|
|
43
|
+
export interface TabsProps extends ViewProps {
|
|
32
44
|
/**
|
|
33
45
|
* Callback which is called on tab press, receiving key of upcoming active Tab.
|
|
34
46
|
*/
|
|
35
47
|
onTabPress: (key: string) => void;
|
|
36
|
-
/**
|
|
37
|
-
* Whether inactive tabs should be removed and unmounted in React.
|
|
38
|
-
* Defaults to `false`.
|
|
39
|
-
*/
|
|
40
|
-
renderActiveTabOnly?: boolean;
|
|
41
48
|
/**
|
|
42
49
|
* Current selected tab key.
|
|
43
50
|
*/
|
|
@@ -45,116 +52,154 @@ interface TabsProps extends ViewProps {
|
|
|
45
52
|
/**
|
|
46
53
|
* List of Tabs to be rendered. Each Tab must have an unique key.
|
|
47
54
|
*/
|
|
48
|
-
tabs:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
testID?: string;
|
|
54
|
-
}[];
|
|
55
|
+
tabs: TabType[];
|
|
56
|
+
/**
|
|
57
|
+
* Style for the container of Tab.
|
|
58
|
+
*/
|
|
59
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
55
60
|
/**
|
|
56
|
-
*
|
|
61
|
+
* Style for the tab navigation bar.
|
|
57
62
|
*/
|
|
58
|
-
|
|
63
|
+
barStyle?: StyleProp<ViewStyle>;
|
|
64
|
+
/**
|
|
65
|
+
* Whether inactive screen should be removed and unmounted in React.
|
|
66
|
+
* Defaults value is `false`.
|
|
67
|
+
*/
|
|
68
|
+
lazy?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Only work when lazy is `true`. You can specify how many adjacent screens should be preloaded.
|
|
71
|
+
* Defaults value is `1`.
|
|
72
|
+
*/
|
|
73
|
+
lazyPreloadDistance?: number;
|
|
59
74
|
/**
|
|
60
75
|
* Testing id of the component.
|
|
61
76
|
*/
|
|
62
77
|
testID?: string;
|
|
63
78
|
}
|
|
64
79
|
|
|
80
|
+
const getTabItem = ({
|
|
81
|
+
item,
|
|
82
|
+
color,
|
|
83
|
+
active,
|
|
84
|
+
}: {
|
|
85
|
+
item: ItemType;
|
|
86
|
+
color: string;
|
|
87
|
+
active: boolean;
|
|
88
|
+
}) => {
|
|
89
|
+
if (typeof item === 'string') {
|
|
90
|
+
return (
|
|
91
|
+
<Typography.Text
|
|
92
|
+
fontWeight={active ? 'semi-bold' : 'regular'}
|
|
93
|
+
numberOfLines={1}
|
|
94
|
+
style={{ color }}
|
|
95
|
+
>
|
|
96
|
+
{item}
|
|
97
|
+
</Typography.Text>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return item({ color });
|
|
102
|
+
};
|
|
103
|
+
|
|
65
104
|
const Tabs = ({
|
|
66
105
|
onTabPress,
|
|
67
|
-
renderActiveTabOnly = false,
|
|
68
106
|
selectedTabKey,
|
|
69
107
|
tabs,
|
|
70
|
-
|
|
108
|
+
containerStyle,
|
|
109
|
+
barStyle,
|
|
110
|
+
lazy = false,
|
|
111
|
+
lazyPreloadDistance = 1,
|
|
71
112
|
}: TabsProps): JSX.Element => {
|
|
72
|
-
const
|
|
113
|
+
const theme = useTheme();
|
|
73
114
|
const insets = useSafeAreaInsets();
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const [
|
|
79
|
-
|
|
80
|
-
React.useEffect(() => {
|
|
81
|
-
const selectedTabIndex = tabs.findIndex(
|
|
82
|
-
item => item.key === selectedTabKey
|
|
83
|
-
);
|
|
84
|
-
if (selectedTabIndex !== -1) {
|
|
85
|
-
flatListRef.current?.scrollToIndex({
|
|
86
|
-
index: selectedTabIndex,
|
|
87
|
-
viewPosition: 0.5,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}, [selectedTabKey, tabs]);
|
|
91
|
-
|
|
92
|
-
if (!loaded.includes(selectedTabKey)) {
|
|
93
|
-
// Set the current tab to be loaded if it was not loaded before
|
|
94
|
-
setLoaded(loadedState => [...loadedState, selectedTabKey]);
|
|
95
|
-
}
|
|
115
|
+
const pagerViewRef = React.useRef<PagerView>(null);
|
|
116
|
+
const selectedTabIndex = tabs.findIndex(item => item.key === selectedTabKey);
|
|
117
|
+
const scrollOffsetAnimatedValue = React.useRef(new Animated.Value(0)).current;
|
|
118
|
+
const positionAnimatedValue = React.useRef(new Animated.Value(0)).current;
|
|
119
|
+
const [tabsWidth, setTabsWidth] = React.useState<number>(0);
|
|
96
120
|
|
|
97
121
|
return (
|
|
98
|
-
<TabContainer {
|
|
99
|
-
<HeaderTabWrapper themeInsets={insets}>
|
|
100
|
-
<
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const { key, icon, title, testID } = tab;
|
|
118
|
-
const active = selectedTabKey === key;
|
|
122
|
+
<TabContainer style={containerStyle}>
|
|
123
|
+
<HeaderTabWrapper themeInsets={insets} style={barStyle}>
|
|
124
|
+
<View>
|
|
125
|
+
<HeaderTab
|
|
126
|
+
onLayout={e => {
|
|
127
|
+
const { width } = e.nativeEvent.layout;
|
|
128
|
+
if (tabsWidth !== width) {
|
|
129
|
+
setTabsWidth(width);
|
|
130
|
+
}
|
|
131
|
+
}}
|
|
132
|
+
>
|
|
133
|
+
{tabs.map((tab, index) => {
|
|
134
|
+
const {
|
|
135
|
+
key,
|
|
136
|
+
testID,
|
|
137
|
+
activeItem,
|
|
138
|
+
inactiveItem: originalInactiveItem,
|
|
139
|
+
showBadge = false,
|
|
140
|
+
} = tab;
|
|
119
141
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
<StyledHeaderTabIcon
|
|
128
|
-
icon={icon}
|
|
129
|
-
testID={`hero-icon-${icon}`}
|
|
130
|
-
themeActive={active}
|
|
131
|
-
/>
|
|
132
|
-
<StyledHeaderTabText
|
|
133
|
-
fontWeight="semi-bold"
|
|
134
|
-
numberOfLines={1}
|
|
135
|
-
themeActive={active}
|
|
136
|
-
>
|
|
137
|
-
{title}
|
|
138
|
-
</StyledHeaderTabText>
|
|
139
|
-
</HeaderTabItem>
|
|
140
|
-
</TouchableOpacity>
|
|
141
|
-
);
|
|
142
|
-
}}
|
|
143
|
-
/>
|
|
144
|
-
</HeaderTabWrapper>
|
|
145
|
-
<ContentWrapper>
|
|
146
|
-
{tabs.map(tab => {
|
|
147
|
-
const { key, component, testID } = tab;
|
|
148
|
-
const active = selectedTabKey === key;
|
|
142
|
+
const active = selectedTabKey === key;
|
|
143
|
+
const inactiveItem = originalInactiveItem ?? activeItem;
|
|
144
|
+
const tabItem = getTabItem({
|
|
145
|
+
item: active ? activeItem : inactiveItem,
|
|
146
|
+
color: theme.__hd__.tabs.colors.text,
|
|
147
|
+
active,
|
|
148
|
+
});
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
return (
|
|
151
|
+
<TouchableWithoutFeedback
|
|
152
|
+
key={key}
|
|
153
|
+
onPress={() => {
|
|
154
|
+
onTabPress(key);
|
|
155
|
+
pagerViewRef.current?.setPage(index);
|
|
156
|
+
}}
|
|
157
|
+
testID={testID}
|
|
158
|
+
>
|
|
159
|
+
<HeaderTabItem>
|
|
160
|
+
<Badge.Status visible={showBadge}>{tabItem}</Badge.Status>
|
|
161
|
+
</HeaderTabItem>
|
|
162
|
+
</TouchableWithoutFeedback>
|
|
163
|
+
);
|
|
164
|
+
})}
|
|
165
|
+
</HeaderTab>
|
|
166
|
+
<ActiveTabIndicator
|
|
167
|
+
positionAnimatedValue={positionAnimatedValue}
|
|
168
|
+
scrollOffsetAnimatedValue={scrollOffsetAnimatedValue}
|
|
169
|
+
tabsLength={tabs.length}
|
|
170
|
+
tabsWidth={tabsWidth}
|
|
171
|
+
/>
|
|
172
|
+
</View>
|
|
173
|
+
</HeaderTabWrapper>
|
|
174
|
+
<ContentWrapper
|
|
175
|
+
initialPage={selectedTabIndex}
|
|
176
|
+
ref={pagerViewRef}
|
|
177
|
+
onPageSelected={e => {
|
|
178
|
+
const index = e.nativeEvent.position;
|
|
179
|
+
const selectedItem = tabs[index];
|
|
180
|
+
if (selectedItem) {
|
|
181
|
+
onTabPress(selectedItem.key);
|
|
152
182
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
183
|
+
}}
|
|
184
|
+
onPageScroll={Animated.event<PagerViewOnPageScrollEventData>(
|
|
185
|
+
[
|
|
186
|
+
{
|
|
187
|
+
nativeEvent: {
|
|
188
|
+
offset: scrollOffsetAnimatedValue,
|
|
189
|
+
position: positionAnimatedValue,
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
{
|
|
194
|
+
useNativeDriver: true,
|
|
157
195
|
}
|
|
196
|
+
)}
|
|
197
|
+
>
|
|
198
|
+
{tabs.map((tab, index) => {
|
|
199
|
+
const { key, component, testID } = tab;
|
|
200
|
+
const active = selectedTabKey === key;
|
|
201
|
+
const isLazyScreen =
|
|
202
|
+
lazy && Math.abs(selectedTabIndex - index) > lazyPreloadDistance;
|
|
158
203
|
|
|
159
204
|
return (
|
|
160
205
|
<TabScreen
|
|
@@ -166,14 +211,8 @@ const Tabs = ({
|
|
|
166
211
|
active ? 'auto' : 'no-hide-descendants'
|
|
167
212
|
}
|
|
168
213
|
collapsable={false}
|
|
169
|
-
removeClippedSubviews={
|
|
170
|
-
// On iOS, set removeClippedSubviews to true only when not focused
|
|
171
|
-
// This is an workaround for a bug where the clipped view never re-appears.
|
|
172
|
-
isIOS ? selectedTabKey !== key : true
|
|
173
|
-
}
|
|
174
|
-
themeVisibility={active}
|
|
175
214
|
>
|
|
176
|
-
{component}
|
|
215
|
+
{isLazyScreen ? null : component}
|
|
177
216
|
</TabScreen>
|
|
178
217
|
);
|
|
179
218
|
})}
|
|
@@ -182,4 +221,6 @@ const Tabs = ({
|
|
|
182
221
|
);
|
|
183
222
|
};
|
|
184
223
|
|
|
185
|
-
export default Tabs
|
|
224
|
+
export default Object.assign(Tabs, {
|
|
225
|
+
Scroll: ScrollableTabs,
|
|
226
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Animated } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export const useAnimatedValueArray = (initialValues: number[]) => {
|
|
5
|
+
const refs = React.useRef<Animated.Value[]>([]);
|
|
6
|
+
|
|
7
|
+
refs.current.length = initialValues.length;
|
|
8
|
+
initialValues.forEach((initialValue, i) => {
|
|
9
|
+
refs.current[i] = refs.current[i] ?? new Animated.Value(initialValue);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
return refs.current;
|
|
13
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { View, Text } from 'react-native';
|
|
2
|
+
import styled from '@emotion/native';
|
|
3
|
+
|
|
4
|
+
const BACKGROUND_INTENTS = {
|
|
5
|
+
success: 'successBackground',
|
|
6
|
+
warning: 'warningBackground',
|
|
7
|
+
danger: 'dangerBackground',
|
|
8
|
+
info: 'infoBackground',
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
type ThemeIntent = 'success' | 'warning' | 'danger' | 'info';
|
|
12
|
+
|
|
13
|
+
const StyledView = styled(View)<{ themeIntent: ThemeIntent }>(
|
|
14
|
+
({ themeIntent, theme }) => ({
|
|
15
|
+
borderWidth: theme.__hd__.tag.borderWidths.default,
|
|
16
|
+
borderRadius: theme.__hd__.tag.radii.default,
|
|
17
|
+
paddingVertical: theme.__hd__.tag.space.verticalPadding,
|
|
18
|
+
paddingHorizontal: theme.__hd__.tag.space.horizontalPadding,
|
|
19
|
+
borderColor: theme.__hd__.tag.colors[themeIntent],
|
|
20
|
+
backgroundColor: theme.__hd__.tag.colors[BACKGROUND_INTENTS[themeIntent]],
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const StyledText = styled(Text)<{ themeIntent: ThemeIntent }>(
|
|
25
|
+
({ themeIntent, theme }) => ({
|
|
26
|
+
fontFamily: theme.__hd__.tag.fonts.default,
|
|
27
|
+
fontSize: theme.__hd__.tag.fontSizes.default,
|
|
28
|
+
color: theme.__hd__.tag.colors[themeIntent],
|
|
29
|
+
includeFontPadding: false,
|
|
30
|
+
textAlignVertical: 'center',
|
|
31
|
+
textAlign: 'center',
|
|
32
|
+
})
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
export { StyledView, StyledText };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
3
|
+
import Tag from '..';
|
|
4
|
+
|
|
5
|
+
describe('Tag', () => {
|
|
6
|
+
it('has success style when intent is success', () => {
|
|
7
|
+
const { getByText, toJSON } = renderWithTheme(
|
|
8
|
+
<Tag content="APPROVED" intent="success" />
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
expect(toJSON()).toMatchSnapshot();
|
|
12
|
+
expect(getByText('APPROVED')).toBeDefined();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('has warning style when intent is warning', () => {
|
|
16
|
+
const { getByText, toJSON } = renderWithTheme(
|
|
17
|
+
<Tag content="PENDING" intent="warning" />
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
expect(toJSON()).toMatchSnapshot();
|
|
21
|
+
expect(getByText('PENDING')).toBeDefined();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('has danger style when intent is danger', () => {
|
|
25
|
+
const { getByText, toJSON } = renderWithTheme(
|
|
26
|
+
<Tag content="DECLINED" intent="danger" />
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
expect(toJSON()).toMatchSnapshot();
|
|
30
|
+
expect(getByText('DECLINED')).toBeDefined();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('has info style when intent is info', () => {
|
|
34
|
+
const { getByText, toJSON } = renderWithTheme(
|
|
35
|
+
<Tag content="SUBMITTED" intent="info" />
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
expect(toJSON()).toMatchSnapshot();
|
|
39
|
+
expect(getByText('SUBMITTED')).toBeDefined();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Tag has danger style when intent is danger 1`] = `
|
|
4
|
+
<View
|
|
5
|
+
style={
|
|
6
|
+
Array [
|
|
7
|
+
Object {
|
|
8
|
+
"backgroundColor": "#fcebe7",
|
|
9
|
+
"borderColor": "#de350b",
|
|
10
|
+
"borderRadius": 4,
|
|
11
|
+
"borderWidth": 1,
|
|
12
|
+
"paddingHorizontal": 8,
|
|
13
|
+
"paddingVertical": 2,
|
|
14
|
+
},
|
|
15
|
+
undefined,
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
themeIntent="danger"
|
|
19
|
+
>
|
|
20
|
+
<Text
|
|
21
|
+
style={
|
|
22
|
+
Array [
|
|
23
|
+
Object {
|
|
24
|
+
"color": "#de350b",
|
|
25
|
+
"fontFamily": "BeVietnamPro-SemiBold",
|
|
26
|
+
"fontSize": 12,
|
|
27
|
+
"includeFontPadding": false,
|
|
28
|
+
"textAlign": "center",
|
|
29
|
+
"textAlignVertical": "center",
|
|
30
|
+
},
|
|
31
|
+
undefined,
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
themeIntent="danger"
|
|
35
|
+
>
|
|
36
|
+
DECLINED
|
|
37
|
+
</Text>
|
|
38
|
+
</View>
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
exports[`Tag has info style when intent is info 1`] = `
|
|
42
|
+
<View
|
|
43
|
+
style={
|
|
44
|
+
Array [
|
|
45
|
+
Object {
|
|
46
|
+
"backgroundColor": "#ecf0ff",
|
|
47
|
+
"borderColor": "#4568fb",
|
|
48
|
+
"borderRadius": 4,
|
|
49
|
+
"borderWidth": 1,
|
|
50
|
+
"paddingHorizontal": 8,
|
|
51
|
+
"paddingVertical": 2,
|
|
52
|
+
},
|
|
53
|
+
undefined,
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
themeIntent="info"
|
|
57
|
+
>
|
|
58
|
+
<Text
|
|
59
|
+
style={
|
|
60
|
+
Array [
|
|
61
|
+
Object {
|
|
62
|
+
"color": "#4568fb",
|
|
63
|
+
"fontFamily": "BeVietnamPro-SemiBold",
|
|
64
|
+
"fontSize": 12,
|
|
65
|
+
"includeFontPadding": false,
|
|
66
|
+
"textAlign": "center",
|
|
67
|
+
"textAlignVertical": "center",
|
|
68
|
+
},
|
|
69
|
+
undefined,
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
themeIntent="info"
|
|
73
|
+
>
|
|
74
|
+
SUBMITTED
|
|
75
|
+
</Text>
|
|
76
|
+
</View>
|
|
77
|
+
`;
|
|
78
|
+
|
|
79
|
+
exports[`Tag has success style when intent is success 1`] = `
|
|
80
|
+
<View
|
|
81
|
+
style={
|
|
82
|
+
Array [
|
|
83
|
+
Object {
|
|
84
|
+
"backgroundColor": "#f0fef4",
|
|
85
|
+
"borderColor": "#017d6d",
|
|
86
|
+
"borderRadius": 4,
|
|
87
|
+
"borderWidth": 1,
|
|
88
|
+
"paddingHorizontal": 8,
|
|
89
|
+
"paddingVertical": 2,
|
|
90
|
+
},
|
|
91
|
+
undefined,
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
themeIntent="success"
|
|
95
|
+
>
|
|
96
|
+
<Text
|
|
97
|
+
style={
|
|
98
|
+
Array [
|
|
99
|
+
Object {
|
|
100
|
+
"color": "#017d6d",
|
|
101
|
+
"fontFamily": "BeVietnamPro-SemiBold",
|
|
102
|
+
"fontSize": 12,
|
|
103
|
+
"includeFontPadding": false,
|
|
104
|
+
"textAlign": "center",
|
|
105
|
+
"textAlignVertical": "center",
|
|
106
|
+
},
|
|
107
|
+
undefined,
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
themeIntent="success"
|
|
111
|
+
>
|
|
112
|
+
APPROVED
|
|
113
|
+
</Text>
|
|
114
|
+
</View>
|
|
115
|
+
`;
|
|
116
|
+
|
|
117
|
+
exports[`Tag has warning style when intent is warning 1`] = `
|
|
118
|
+
<View
|
|
119
|
+
style={
|
|
120
|
+
Array [
|
|
121
|
+
Object {
|
|
122
|
+
"backgroundColor": "#fff6eb",
|
|
123
|
+
"borderColor": "#d98a2c",
|
|
124
|
+
"borderRadius": 4,
|
|
125
|
+
"borderWidth": 1,
|
|
126
|
+
"paddingHorizontal": 8,
|
|
127
|
+
"paddingVertical": 2,
|
|
128
|
+
},
|
|
129
|
+
undefined,
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
themeIntent="warning"
|
|
133
|
+
>
|
|
134
|
+
<Text
|
|
135
|
+
style={
|
|
136
|
+
Array [
|
|
137
|
+
Object {
|
|
138
|
+
"color": "#d98a2c",
|
|
139
|
+
"fontFamily": "BeVietnamPro-SemiBold",
|
|
140
|
+
"fontSize": 12,
|
|
141
|
+
"includeFontPadding": false,
|
|
142
|
+
"textAlign": "center",
|
|
143
|
+
"textAlignVertical": "center",
|
|
144
|
+
},
|
|
145
|
+
undefined,
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
themeIntent="warning"
|
|
149
|
+
>
|
|
150
|
+
PENDING
|
|
151
|
+
</Text>
|
|
152
|
+
</View>
|
|
153
|
+
`;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { StyleProp, ViewStyle, ViewProps } from 'react-native';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { StyledView, StyledText } from './StyledTag';
|
|
4
|
+
|
|
5
|
+
interface TagProps extends ViewProps {
|
|
6
|
+
/**
|
|
7
|
+
* Content of the Tag.
|
|
8
|
+
*/
|
|
9
|
+
content: string;
|
|
10
|
+
/**
|
|
11
|
+
* Visual intent color to apply to Tag.
|
|
12
|
+
*/
|
|
13
|
+
intent?: 'success' | 'warning' | 'danger' | 'info';
|
|
14
|
+
/**
|
|
15
|
+
* Additional style.
|
|
16
|
+
*/
|
|
17
|
+
style?: StyleProp<ViewStyle>;
|
|
18
|
+
/**
|
|
19
|
+
* Testing id of the component.
|
|
20
|
+
*/
|
|
21
|
+
testID?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const Tag = ({
|
|
25
|
+
content,
|
|
26
|
+
intent = 'info',
|
|
27
|
+
style,
|
|
28
|
+
testID,
|
|
29
|
+
...nativeProps
|
|
30
|
+
}: TagProps): JSX.Element => (
|
|
31
|
+
<StyledView
|
|
32
|
+
{...nativeProps}
|
|
33
|
+
themeIntent={intent}
|
|
34
|
+
style={style}
|
|
35
|
+
testID={testID}
|
|
36
|
+
>
|
|
37
|
+
<StyledText themeIntent={intent}>{content}</StyledText>
|
|
38
|
+
</StyledView>
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
export default Tag;
|
package/src/index.ts
CHANGED
|
@@ -2,14 +2,19 @@ import { ThemeProvider, useTheme } from '@emotion/react';
|
|
|
2
2
|
import theme, { getTheme } from './theme';
|
|
3
3
|
import { scale } from './utils/scale';
|
|
4
4
|
|
|
5
|
+
import Avatar from './components/Avatar';
|
|
5
6
|
import Badge from './components/Badge';
|
|
6
7
|
import BottomNavigation from './components/BottomNavigation';
|
|
7
8
|
import Button from './components/Button';
|
|
8
9
|
import Card from './components/Card';
|
|
10
|
+
import Collapse from './components/Collapse';
|
|
9
11
|
import Divider from './components/Divider';
|
|
12
|
+
import Drawer from './components/Drawer';
|
|
10
13
|
import FAB from './components/FAB';
|
|
11
14
|
import Icon from './components/Icon';
|
|
15
|
+
import Progress from './components/Progress';
|
|
12
16
|
import Tabs from './components/Tabs';
|
|
17
|
+
import Tag from './components/Tag';
|
|
13
18
|
import Typography from './components/Typography';
|
|
14
19
|
|
|
15
20
|
export {
|
|
@@ -18,14 +23,19 @@ export {
|
|
|
18
23
|
useTheme,
|
|
19
24
|
scale,
|
|
20
25
|
ThemeProvider,
|
|
26
|
+
Avatar,
|
|
21
27
|
Badge,
|
|
22
28
|
BottomNavigation,
|
|
23
29
|
Button,
|
|
24
30
|
Card,
|
|
31
|
+
Collapse,
|
|
25
32
|
Divider,
|
|
33
|
+
Drawer,
|
|
26
34
|
FAB,
|
|
27
35
|
Icon,
|
|
36
|
+
Progress,
|
|
28
37
|
Tabs,
|
|
38
|
+
Tag,
|
|
29
39
|
Typography,
|
|
30
40
|
};
|
|
31
41
|
|