@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
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Status Badge renders correctly 1`] = `
|
|
4
|
+
<View>
|
|
5
|
+
<HeroIcon
|
|
6
|
+
name="activate"
|
|
7
|
+
style={
|
|
8
|
+
Array [
|
|
9
|
+
Object {
|
|
10
|
+
"color": "#292a2b",
|
|
11
|
+
"fontSize": 24,
|
|
12
|
+
},
|
|
13
|
+
undefined,
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
testID="activate-icon"
|
|
17
|
+
themeIntent="text"
|
|
18
|
+
themeSize="medium"
|
|
19
|
+
/>
|
|
20
|
+
<View
|
|
21
|
+
collapsable={false}
|
|
22
|
+
nativeID="animatedComponent"
|
|
23
|
+
style={
|
|
24
|
+
Object {
|
|
25
|
+
"backgroundColor": "#de350b",
|
|
26
|
+
"borderRadius": 999,
|
|
27
|
+
"height": 8,
|
|
28
|
+
"opacity": 1,
|
|
29
|
+
"position": "absolute",
|
|
30
|
+
"right": -2,
|
|
31
|
+
"top": -2,
|
|
32
|
+
"transform": Array [
|
|
33
|
+
Object {
|
|
34
|
+
"scale": 1,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
"width": 8,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
themeIntent="danger"
|
|
41
|
+
/>
|
|
42
|
+
</View>
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
exports[`Status Badge renders correctly with intent 1`] = `
|
|
46
|
+
<View>
|
|
47
|
+
<Text
|
|
48
|
+
style={
|
|
49
|
+
Array [
|
|
50
|
+
Object {
|
|
51
|
+
"color": "#292a2b",
|
|
52
|
+
"fontFamily": "BeVietnamPro-Regular",
|
|
53
|
+
"fontSize": 14,
|
|
54
|
+
"letterSpacing": 0.42,
|
|
55
|
+
"lineHeight": 22,
|
|
56
|
+
},
|
|
57
|
+
undefined,
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
themeFontSize="medium"
|
|
61
|
+
themeFontWeight="regular"
|
|
62
|
+
themeIntent="body"
|
|
63
|
+
>
|
|
64
|
+
Activity
|
|
65
|
+
</Text>
|
|
66
|
+
<View
|
|
67
|
+
collapsable={false}
|
|
68
|
+
nativeID="animatedComponent"
|
|
69
|
+
style={
|
|
70
|
+
Object {
|
|
71
|
+
"backgroundColor": "#017d6d",
|
|
72
|
+
"borderRadius": 999,
|
|
73
|
+
"height": 8,
|
|
74
|
+
"opacity": 1,
|
|
75
|
+
"position": "absolute",
|
|
76
|
+
"right": -2,
|
|
77
|
+
"top": -2,
|
|
78
|
+
"transform": Array [
|
|
79
|
+
Object {
|
|
80
|
+
"scale": 1,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
"width": 8,
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
themeIntent="success"
|
|
87
|
+
/>
|
|
88
|
+
</View>
|
|
89
|
+
`;
|
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
import { StyleProp, ViewStyle
|
|
2
|
-
import React
|
|
1
|
+
import { Animated, StyleProp, ViewStyle } from 'react-native';
|
|
2
|
+
import React from 'react';
|
|
3
3
|
import { StyledView, StyledText } from './StyledBadge';
|
|
4
|
+
import BadgeStatus from './Status';
|
|
4
5
|
|
|
5
|
-
interface BadgeProps extends
|
|
6
|
+
interface BadgeProps extends React.ComponentProps<typeof Animated.View> {
|
|
6
7
|
/**
|
|
7
8
|
* Content of the Badge.
|
|
8
9
|
*/
|
|
9
|
-
content: string;
|
|
10
|
+
content: string | number;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the Badge is visible.
|
|
13
|
+
*/
|
|
14
|
+
visible?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The maximum number displayed on the badge. If number exceeds this value, `${max}+` are displayed instead. (Only applied when content is number.)
|
|
17
|
+
*/
|
|
18
|
+
max?: number;
|
|
10
19
|
/**
|
|
11
20
|
* Visual intent color to apply to Badge.
|
|
12
21
|
*/
|
|
13
|
-
intent?: 'success' | 'warning' | 'danger' | 'info';
|
|
22
|
+
intent?: 'success' | 'warning' | 'danger' | 'info' | 'archived';
|
|
14
23
|
/**
|
|
15
24
|
* Additional style.
|
|
16
25
|
*/
|
|
@@ -21,21 +30,70 @@ interface BadgeProps extends ViewProps {
|
|
|
21
30
|
testID?: string;
|
|
22
31
|
}
|
|
23
32
|
|
|
33
|
+
const DEFAULT_MAX_NUMBER = 99;
|
|
34
|
+
|
|
35
|
+
const getPaddingState = (content: string): 'narrowContent' | 'wideContent' =>
|
|
36
|
+
content.length > 1 ? 'wideContent' : 'narrowContent';
|
|
37
|
+
|
|
24
38
|
const Badge = ({
|
|
25
|
-
content,
|
|
26
|
-
|
|
39
|
+
content: originalContent,
|
|
40
|
+
visible = true,
|
|
41
|
+
max = DEFAULT_MAX_NUMBER,
|
|
42
|
+
intent = 'danger',
|
|
27
43
|
style,
|
|
28
44
|
testID,
|
|
29
45
|
...nativeProps
|
|
30
|
-
}: BadgeProps):
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
}: BadgeProps): JSX.Element => {
|
|
47
|
+
const { current: opacity } = React.useRef<Animated.Value>(
|
|
48
|
+
new Animated.Value(visible ? 1 : 0)
|
|
49
|
+
);
|
|
50
|
+
const isFirstRendering = React.useRef<boolean>(true);
|
|
51
|
+
|
|
52
|
+
React.useEffect(() => {
|
|
53
|
+
// Do not run animation on very first rendering
|
|
54
|
+
if (isFirstRendering.current) {
|
|
55
|
+
isFirstRendering.current = false;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
Animated.timing(opacity, {
|
|
60
|
+
toValue: visible ? 1 : 0,
|
|
61
|
+
duration: 150,
|
|
62
|
+
useNativeDriver: true,
|
|
63
|
+
}).start();
|
|
64
|
+
}, [visible, opacity]);
|
|
65
|
+
|
|
66
|
+
const content =
|
|
67
|
+
typeof originalContent === 'number' && originalContent > max
|
|
68
|
+
? `${max}+`
|
|
69
|
+
: String(originalContent);
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<StyledView
|
|
73
|
+
{...nativeProps}
|
|
74
|
+
themeIntent={intent}
|
|
75
|
+
themePadding={getPaddingState(content)}
|
|
76
|
+
style={[
|
|
77
|
+
{
|
|
78
|
+
opacity,
|
|
79
|
+
transform: [
|
|
80
|
+
{
|
|
81
|
+
scale: opacity.interpolate({
|
|
82
|
+
inputRange: [0, 1],
|
|
83
|
+
outputRange: [0.5, 1],
|
|
84
|
+
}),
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
style,
|
|
89
|
+
]}
|
|
90
|
+
testID={testID}
|
|
91
|
+
>
|
|
92
|
+
<StyledText>{content}</StyledText>
|
|
93
|
+
</StyledView>
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export default Object.assign(Badge, {
|
|
98
|
+
Status: BadgeStatus,
|
|
99
|
+
});
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import React, { ReactChild } from 'react';
|
|
2
|
+
import { Pressable, StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { IconName } from '../Icon';
|
|
5
|
+
import LoadingIndicator from './LoadingIndicator';
|
|
6
|
+
import {
|
|
7
|
+
Intent,
|
|
8
|
+
StyledButtonContainer,
|
|
9
|
+
StyledButtonText,
|
|
10
|
+
StyledButtonIconWrapper,
|
|
11
|
+
StyledButtonIcon,
|
|
12
|
+
ThemeVariant,
|
|
13
|
+
} from './StyledButton';
|
|
14
|
+
|
|
15
|
+
export interface ButtonProps {
|
|
16
|
+
/**
|
|
17
|
+
* Helps users understand what will happen when they perform an action on the accessibility element when that result is not clear from the accessibility label.
|
|
18
|
+
*/
|
|
19
|
+
accessibilityHint?: string;
|
|
20
|
+
/**
|
|
21
|
+
* A succinct label in a localized string that identifies the accessibility element
|
|
22
|
+
*/
|
|
23
|
+
accessibilityLabel?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Disable state of button.
|
|
26
|
+
*/
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Places an icon within the button, before the button's text
|
|
30
|
+
*/
|
|
31
|
+
icon?: IconName;
|
|
32
|
+
/**
|
|
33
|
+
* Visual intent color to apply to button. It is required for `filled`, `outlined` and `text` variants.
|
|
34
|
+
*/
|
|
35
|
+
intent?: 'primary' | 'secondary';
|
|
36
|
+
/**
|
|
37
|
+
* Loading state of button.
|
|
38
|
+
*/
|
|
39
|
+
loading?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Set the handler to handle press event.
|
|
42
|
+
*/
|
|
43
|
+
onPress: () => void;
|
|
44
|
+
/**
|
|
45
|
+
* Places an icon within the button, after the button's text
|
|
46
|
+
*/
|
|
47
|
+
rightIcon?: IconName;
|
|
48
|
+
/**
|
|
49
|
+
* Addditional style.
|
|
50
|
+
*/
|
|
51
|
+
style?: StyleProp<ViewStyle>;
|
|
52
|
+
/**
|
|
53
|
+
* Testing id of the component.
|
|
54
|
+
*/
|
|
55
|
+
testID?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Button label.
|
|
58
|
+
*/
|
|
59
|
+
text: ReactChild;
|
|
60
|
+
/**
|
|
61
|
+
* Button type.
|
|
62
|
+
*/
|
|
63
|
+
variant?: 'basic-transparent' | 'filled' | 'outlined';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const FILLED_VARIANTS = {
|
|
67
|
+
primary: 'filled-primary',
|
|
68
|
+
secondary: 'filled-secondary',
|
|
69
|
+
} as const;
|
|
70
|
+
|
|
71
|
+
const OUTLINED_VARIANTS = {
|
|
72
|
+
primary: 'outlined-primary',
|
|
73
|
+
secondary: 'outlined-secondary',
|
|
74
|
+
} as const;
|
|
75
|
+
|
|
76
|
+
export const getThemeVariant = (
|
|
77
|
+
variant: 'basic-transparent' | 'filled' | 'outlined',
|
|
78
|
+
intent: Intent
|
|
79
|
+
): ThemeVariant => {
|
|
80
|
+
switch (variant) {
|
|
81
|
+
case 'basic-transparent':
|
|
82
|
+
return variant;
|
|
83
|
+
case 'filled':
|
|
84
|
+
return FILLED_VARIANTS[intent];
|
|
85
|
+
case 'outlined':
|
|
86
|
+
return OUTLINED_VARIANTS[intent];
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const Button = ({
|
|
91
|
+
accessibilityHint,
|
|
92
|
+
accessibilityLabel,
|
|
93
|
+
disabled = false,
|
|
94
|
+
icon,
|
|
95
|
+
intent = 'primary',
|
|
96
|
+
loading = false,
|
|
97
|
+
onPress,
|
|
98
|
+
rightIcon,
|
|
99
|
+
style,
|
|
100
|
+
testID,
|
|
101
|
+
text,
|
|
102
|
+
variant = 'filled',
|
|
103
|
+
}: ButtonProps) => (
|
|
104
|
+
<Pressable
|
|
105
|
+
accessibilityHint={accessibilityHint}
|
|
106
|
+
accessibilityLabel={accessibilityLabel}
|
|
107
|
+
disabled={disabled || loading}
|
|
108
|
+
onPress={onPress}
|
|
109
|
+
testID={testID}
|
|
110
|
+
>
|
|
111
|
+
{({ pressed }) => (
|
|
112
|
+
<StyledButtonContainer
|
|
113
|
+
disabled={disabled}
|
|
114
|
+
pressed={pressed}
|
|
115
|
+
style={style}
|
|
116
|
+
themeVariant={getThemeVariant(variant, intent)}
|
|
117
|
+
>
|
|
118
|
+
{loading === true ? (
|
|
119
|
+
<LoadingIndicator
|
|
120
|
+
testID={`${testID}-loading-indicator`}
|
|
121
|
+
themeVariant={getThemeVariant(variant, intent)}
|
|
122
|
+
/>
|
|
123
|
+
) : (
|
|
124
|
+
<>
|
|
125
|
+
{icon !== undefined && (
|
|
126
|
+
<StyledButtonIconWrapper themePosition="left">
|
|
127
|
+
<StyledButtonIcon
|
|
128
|
+
disabled={disabled}
|
|
129
|
+
icon={icon}
|
|
130
|
+
pressed={pressed}
|
|
131
|
+
testID={`${testID}-left-icon`}
|
|
132
|
+
themeVariant={getThemeVariant(variant, intent)}
|
|
133
|
+
/>
|
|
134
|
+
</StyledButtonIconWrapper>
|
|
135
|
+
)}
|
|
136
|
+
<StyledButtonText
|
|
137
|
+
disabled={disabled}
|
|
138
|
+
ellipsizeMode="tail"
|
|
139
|
+
numberOfLines={1}
|
|
140
|
+
pressed={pressed}
|
|
141
|
+
themeVariant={getThemeVariant(variant, intent)}
|
|
142
|
+
>
|
|
143
|
+
{text}
|
|
144
|
+
</StyledButtonText>
|
|
145
|
+
{rightIcon !== undefined && (
|
|
146
|
+
<StyledButtonIconWrapper themePosition="right">
|
|
147
|
+
<StyledButtonIcon
|
|
148
|
+
disabled={disabled}
|
|
149
|
+
icon={rightIcon}
|
|
150
|
+
pressed={pressed}
|
|
151
|
+
testID={`${testID}-right-icon`}
|
|
152
|
+
themeVariant={getThemeVariant(variant, intent)}
|
|
153
|
+
/>
|
|
154
|
+
</StyledButtonIconWrapper>
|
|
155
|
+
)}
|
|
156
|
+
</>
|
|
157
|
+
)}
|
|
158
|
+
</StyledButtonContainer>
|
|
159
|
+
)}
|
|
160
|
+
</Pressable>
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
export default Button;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { View, ViewProps } from 'react-native';
|
|
2
|
+
import styled, { ReactNativeStyle } from '@emotion/native';
|
|
3
|
+
import { Theme } from '@emotion/react';
|
|
4
|
+
|
|
5
|
+
type Intent = 'primary' | 'secondary';
|
|
6
|
+
|
|
7
|
+
type ThemeVariant =
|
|
8
|
+
| 'basic-transparent'
|
|
9
|
+
| 'filled-primary'
|
|
10
|
+
| 'filled-secondary'
|
|
11
|
+
| 'outlined-primary'
|
|
12
|
+
| 'outlined-secondary';
|
|
13
|
+
|
|
14
|
+
const genLoadingIndicatorStyles = (
|
|
15
|
+
theme: Theme,
|
|
16
|
+
intent: Intent
|
|
17
|
+
): ReactNativeStyle => ({
|
|
18
|
+
backgroundColor: theme.__hd__.button.colors[intent],
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const StyledLoadingIndicatorWrapper = styled(View)<ViewProps>(({ theme }) => ({
|
|
22
|
+
flexDirection: 'row',
|
|
23
|
+
justifyContent: 'center',
|
|
24
|
+
alignItems: 'center',
|
|
25
|
+
paddingVertical: theme.space.xxsmall,
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
const StyledLoadingDot = styled(View)<{
|
|
29
|
+
size?: number;
|
|
30
|
+
themeVariant: ThemeVariant;
|
|
31
|
+
}>(({ size = 12, themeVariant, theme }) => {
|
|
32
|
+
const themeStyling = () => {
|
|
33
|
+
switch (themeVariant) {
|
|
34
|
+
case 'basic-transparent':
|
|
35
|
+
case 'filled-primary':
|
|
36
|
+
case 'filled-secondary':
|
|
37
|
+
return {
|
|
38
|
+
backgroundColor: theme.__hd__.button.colors.invertedText,
|
|
39
|
+
};
|
|
40
|
+
case 'outlined-primary':
|
|
41
|
+
return genLoadingIndicatorStyles(theme, 'primary');
|
|
42
|
+
case 'outlined-secondary':
|
|
43
|
+
return genLoadingIndicatorStyles(theme, 'secondary');
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
width: size,
|
|
49
|
+
height: size,
|
|
50
|
+
marginTop: theme.space.xsmall,
|
|
51
|
+
marginBottom: theme.space.xsmall,
|
|
52
|
+
marginHorizontal: theme.space.small,
|
|
53
|
+
borderRadius: theme.space.small,
|
|
54
|
+
...themeStyling(),
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export { StyledLoadingIndicatorWrapper, StyledLoadingDot };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { StyledLoadingDot } from '../StyledLoadingIndicator';
|
|
4
|
+
import renderWithTheme from '../../../../testHelpers/renderWithTheme';
|
|
5
|
+
|
|
6
|
+
describe('StyledLoadingIndicator', () => {
|
|
7
|
+
it.each`
|
|
8
|
+
themeVariant
|
|
9
|
+
${'basic-transparent'}
|
|
10
|
+
${'filled-primary'}
|
|
11
|
+
${'filled-secondary'}
|
|
12
|
+
${'outlined-primary'}
|
|
13
|
+
${'outlined-secondary'}
|
|
14
|
+
`('has $themeVariant style', ({ themeVariant }) => {
|
|
15
|
+
const { toJSON } = renderWithTheme(
|
|
16
|
+
<StyledLoadingDot themeVariant={themeVariant} />
|
|
17
|
+
);
|
|
18
|
+
expect(toJSON()).toMatchSnapshot();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`StyledLoadingIndicator has basic-transparent style 1`] = `
|
|
4
|
+
<View
|
|
5
|
+
style={
|
|
6
|
+
Array [
|
|
7
|
+
Object {
|
|
8
|
+
"backgroundColor": "#ffffff",
|
|
9
|
+
"borderRadius": 8,
|
|
10
|
+
"height": 12,
|
|
11
|
+
"marginBottom": 4,
|
|
12
|
+
"marginHorizontal": 8,
|
|
13
|
+
"marginTop": 4,
|
|
14
|
+
"width": 12,
|
|
15
|
+
},
|
|
16
|
+
undefined,
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
themeVariant="basic-transparent"
|
|
20
|
+
/>
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
exports[`StyledLoadingIndicator has filled-primary style 1`] = `
|
|
24
|
+
<View
|
|
25
|
+
style={
|
|
26
|
+
Array [
|
|
27
|
+
Object {
|
|
28
|
+
"backgroundColor": "#ffffff",
|
|
29
|
+
"borderRadius": 8,
|
|
30
|
+
"height": 12,
|
|
31
|
+
"marginBottom": 4,
|
|
32
|
+
"marginHorizontal": 8,
|
|
33
|
+
"marginTop": 4,
|
|
34
|
+
"width": 12,
|
|
35
|
+
},
|
|
36
|
+
undefined,
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
themeVariant="filled-primary"
|
|
40
|
+
/>
|
|
41
|
+
`;
|
|
42
|
+
|
|
43
|
+
exports[`StyledLoadingIndicator has filled-secondary style 1`] = `
|
|
44
|
+
<View
|
|
45
|
+
style={
|
|
46
|
+
Array [
|
|
47
|
+
Object {
|
|
48
|
+
"backgroundColor": "#ffffff",
|
|
49
|
+
"borderRadius": 8,
|
|
50
|
+
"height": 12,
|
|
51
|
+
"marginBottom": 4,
|
|
52
|
+
"marginHorizontal": 8,
|
|
53
|
+
"marginTop": 4,
|
|
54
|
+
"width": 12,
|
|
55
|
+
},
|
|
56
|
+
undefined,
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
themeVariant="filled-secondary"
|
|
60
|
+
/>
|
|
61
|
+
`;
|
|
62
|
+
|
|
63
|
+
exports[`StyledLoadingIndicator has outlined-primary style 1`] = `
|
|
64
|
+
<View
|
|
65
|
+
style={
|
|
66
|
+
Array [
|
|
67
|
+
Object {
|
|
68
|
+
"backgroundColor": "#7622d7",
|
|
69
|
+
"borderRadius": 8,
|
|
70
|
+
"height": 12,
|
|
71
|
+
"marginBottom": 4,
|
|
72
|
+
"marginHorizontal": 8,
|
|
73
|
+
"marginTop": 4,
|
|
74
|
+
"width": 12,
|
|
75
|
+
},
|
|
76
|
+
undefined,
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
themeVariant="outlined-primary"
|
|
80
|
+
/>
|
|
81
|
+
`;
|
|
82
|
+
|
|
83
|
+
exports[`StyledLoadingIndicator has outlined-secondary style 1`] = `
|
|
84
|
+
<View
|
|
85
|
+
style={
|
|
86
|
+
Array [
|
|
87
|
+
Object {
|
|
88
|
+
"backgroundColor": "#4568fb",
|
|
89
|
+
"borderRadius": 8,
|
|
90
|
+
"height": 12,
|
|
91
|
+
"marginBottom": 4,
|
|
92
|
+
"marginHorizontal": 8,
|
|
93
|
+
"marginTop": 4,
|
|
94
|
+
"width": 12,
|
|
95
|
+
},
|
|
96
|
+
undefined,
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
themeVariant="outlined-secondary"
|
|
100
|
+
/>
|
|
101
|
+
`;
|