@hero-design/rn 7.0.5 → 7.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babel.config.js +1 -1
- package/es/index.js +150 -41
- package/lib/index.js +149 -38
- package/package.json +3 -3
- package/playground/components/Card.tsx +74 -91
- package/playground/components/FAB.tsx +49 -0
- package/playground/index.tsx +3 -1
- package/src/components/Card/StyledCard.tsx +1 -0
- package/src/components/Card/__tests__/__snapshots__/Card.spec.tsx.snap +5 -4
- package/src/components/Card/__tests__/__snapshots__/StyledCard.spec.tsx.snap +5 -4
- package/src/components/FAB/AnimatedFABIcon.tsx +47 -0
- package/src/components/FAB/StyledFABContainer.tsx +14 -0
- package/src/components/FAB/StyledFABIcon.tsx +9 -0
- package/src/components/FAB/__tests__/AnimatedFABIcon.spec.tsx +20 -0
- package/src/components/FAB/__tests__/StyledFABContainer.spec.tsx +18 -0
- package/src/components/FAB/__tests__/StyledFABIcon.spec.tsx +16 -0
- package/src/components/FAB/__tests__/__snapshots__/AnimatedFABIcon.spec.tsx.snap +71 -0
- package/src/components/FAB/__tests__/__snapshots__/StyledFABContainer.spec.tsx.snap +46 -0
- package/src/components/FAB/__tests__/__snapshots__/StyledFABIcon.spec.tsx.snap +21 -0
- package/src/components/FAB/__tests__/__snapshots__/index.spec.tsx.snap +120 -0
- package/src/components/FAB/__tests__/index.spec.tsx +58 -0
- package/src/components/FAB/index.tsx +56 -0
- package/src/components/Icon/index.tsx +1 -1
- package/src/index.ts +4 -0
- package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +14 -1
- package/src/theme/components/card.ts +1 -1
- package/src/theme/components/fab.ts +21 -0
- package/src/theme/global/space.ts +11 -9
- package/src/theme/global/typography.ts +11 -9
- package/src/theme/index.ts +3 -0
- package/src/utils/__tests__/scale.spec.ts +26 -0
- package/src/utils/scale.ts +10 -0
- package/testUtils/setup.ts +4 -0
- package/types/playground/components/FAB.d.ts +2 -0
- package/types/src/components/FAB/AnimatedFABIcon.d.ts +6 -0
- package/types/src/components/FAB/StyledFABContainer.d.ts +3 -0
- package/types/src/components/FAB/StyledFABIcon.d.ts +3 -0
- package/types/{components/ExampleComponent/__tests__/StyledView.spec.d.ts → src/components/FAB/__tests__/AnimatedFABIcon.spec.d.ts} +0 -0
- package/types/src/components/{Typography/Text/__test__/StyledText.spec.d.ts → FAB/__tests__/StyledFABContainer.spec.d.ts} +0 -0
- package/types/src/components/{Typography/Text/__test__/index.spec.d.ts → FAB/__tests__/StyledFABIcon.spec.d.ts} +0 -0
- package/types/src/components/FAB/__tests__/index.spec.d.ts +1 -0
- package/types/src/components/FAB/index.d.ts +30 -0
- package/types/src/components/Icon/index.d.ts +1 -1
- package/types/src/index.d.ts +3 -1
- package/types/src/theme/components/fab.d.ts +15 -0
- package/types/src/theme/index.d.ts +2 -0
- package/types/src/utils/__tests__/scale.spec.d.ts +1 -0
- package/types/src/utils/scale.d.ts +2 -0
- package/types/components/ExampleComponent/StyledView.d.ts +0 -7
- package/types/components/ExampleComponent/index.d.ts +0 -16
- package/types/index.d.ts +0 -4
- package/types/styled-components.d.ts +0 -6
- package/types/theme/colors.d.ts +0 -24
- package/types/theme/components/demoStyle.d.ts +0 -11
- package/types/theme/components/exampleComponent.d.ts +0 -14
- package/types/theme/global/colors.d.ts +0 -24
- package/types/theme/global/index.d.ts +0 -58
- package/types/theme/global/space.d.ts +0 -12
- package/types/theme/global/typography.d.ts +0 -21
- package/types/theme/index.d.ts +0 -11
- package/types/theme/space.d.ts +0 -12
- package/types/theme/typography.d.ts +0 -21
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
3
|
+
import {
|
|
4
|
+
SafeAreaProvider,
|
|
5
|
+
SafeAreaView,
|
|
6
|
+
useSafeAreaInsets,
|
|
7
|
+
} from 'react-native-safe-area-context';
|
|
8
|
+
import { FAB, useTheme } from '../../src/index';
|
|
9
|
+
|
|
10
|
+
const FABPlayground = (): JSX.Element => {
|
|
11
|
+
const [active, setActive] = useState(false);
|
|
12
|
+
const insets = useSafeAreaInsets();
|
|
13
|
+
const theme = useTheme();
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<SafeAreaProvider>
|
|
17
|
+
<SafeAreaView style={{ flex: 1 }} edges={['right', 'left']}>
|
|
18
|
+
<FAB
|
|
19
|
+
icon="add"
|
|
20
|
+
onPress={() => {
|
|
21
|
+
setActive(!active);
|
|
22
|
+
}}
|
|
23
|
+
animated
|
|
24
|
+
active={active}
|
|
25
|
+
style={{
|
|
26
|
+
position: 'absolute',
|
|
27
|
+
bottom: Math.max(insets.bottom, theme.space.large),
|
|
28
|
+
right: theme.space.large,
|
|
29
|
+
}}
|
|
30
|
+
/>
|
|
31
|
+
|
|
32
|
+
<FAB
|
|
33
|
+
icon="share-1"
|
|
34
|
+
onPress={() => {
|
|
35
|
+
alert('button pressed');
|
|
36
|
+
}}
|
|
37
|
+
style={{
|
|
38
|
+
backgroundColor: theme.colors.primary,
|
|
39
|
+
position: 'absolute',
|
|
40
|
+
bottom: Math.max(insets.bottom, theme.space.large),
|
|
41
|
+
left: theme.space.large,
|
|
42
|
+
}}
|
|
43
|
+
/>
|
|
44
|
+
</SafeAreaView>
|
|
45
|
+
</SafeAreaProvider>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default FABPlayground;
|
package/playground/index.tsx
CHANGED
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
NativeStackScreenProps,
|
|
7
7
|
} from '@react-navigation/native-stack';
|
|
8
8
|
import { useFonts } from 'expo-font';
|
|
9
|
-
/* eslint-enable import/no-extraneous-dependencies */
|
|
10
9
|
import { SafeAreaView, FlatList, Text } from 'react-native';
|
|
11
10
|
import { ThemeProvider, theme, useTheme } from '../src/index';
|
|
12
11
|
import BadgePlayground from './components/Badge';
|
|
@@ -14,6 +13,7 @@ import CardPlayground from './components/Card';
|
|
|
14
13
|
import DividerPlayground from './components/Divider';
|
|
15
14
|
import IconPlayground from './components/Icon';
|
|
16
15
|
import TypographyPlayground from './components/Typography';
|
|
16
|
+
import FABPlayground from './components/FAB';
|
|
17
17
|
|
|
18
18
|
const heroIconFontPath = require('../assets/fonts/hero-icons.ttf');
|
|
19
19
|
|
|
@@ -24,6 +24,7 @@ type RootStackParamList = {
|
|
|
24
24
|
Divider: undefined;
|
|
25
25
|
Icon: undefined;
|
|
26
26
|
Typography: undefined;
|
|
27
|
+
FAB: undefined;
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
type Navigation = NativeStackScreenProps<RootStackParamList>;
|
|
@@ -36,6 +37,7 @@ const components = [
|
|
|
36
37
|
{ name: 'Divider', component: DividerPlayground },
|
|
37
38
|
{ name: 'Icon', component: IconPlayground },
|
|
38
39
|
{ name: 'Typography', component: TypographyPlayground },
|
|
40
|
+
{ name: 'FAB', component: FABPlayground },
|
|
39
41
|
] as const;
|
|
40
42
|
|
|
41
43
|
const ComponentItem = ({
|
|
@@ -4,6 +4,7 @@ import styled from 'styled-components-native';
|
|
|
4
4
|
const StyledCard = styled(View)<{}>`
|
|
5
5
|
border-radius: ${({ theme }) => theme.__hd__.card.radii.default};
|
|
6
6
|
padding: ${({ theme }) => theme.__hd__.card.padding.default};
|
|
7
|
+
overflow: hidden;
|
|
7
8
|
`;
|
|
8
9
|
|
|
9
10
|
export { StyledCard };
|
|
@@ -20,10 +20,11 @@ exports[`Card renders correct 1`] = `
|
|
|
20
20
|
"borderBottomRightRadius": 12,
|
|
21
21
|
"borderTopLeftRadius": 12,
|
|
22
22
|
"borderTopRightRadius": 12,
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
23
|
+
"overflow": "hidden",
|
|
24
|
+
"paddingBottom": 8,
|
|
25
|
+
"paddingLeft": 8,
|
|
26
|
+
"paddingRight": 8,
|
|
27
|
+
"paddingTop": 8,
|
|
27
28
|
},
|
|
28
29
|
Object {
|
|
29
30
|
"backgroundColor": "#292a2b",
|
|
@@ -8,10 +8,11 @@ exports[`StyledCard renders correct style 1`] = `
|
|
|
8
8
|
"borderBottomRightRadius": 12,
|
|
9
9
|
"borderTopLeftRadius": 12,
|
|
10
10
|
"borderTopRightRadius": 12,
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
11
|
+
"overflow": "hidden",
|
|
12
|
+
"paddingBottom": 8,
|
|
13
|
+
"paddingLeft": 8,
|
|
14
|
+
"paddingRight": 8,
|
|
15
|
+
"paddingTop": 8,
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
/>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { Animated, StyleSheet } from 'react-native';
|
|
3
|
+
import { IconProps } from '../Icon';
|
|
4
|
+
import { StyledFABIcon } from './StyledFABIcon';
|
|
5
|
+
|
|
6
|
+
const AnimatedIcons = Animated.createAnimatedComponent(StyledFABIcon);
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
active?: boolean;
|
|
10
|
+
} & IconProps;
|
|
11
|
+
|
|
12
|
+
const AnimatedFABIcon = ({ active, ...iconProps }: Props) => {
|
|
13
|
+
const rotateAnimation = useRef<Animated.Value>(
|
|
14
|
+
new Animated.Value(active ? 1 : 0)
|
|
15
|
+
);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const animation = Animated.timing(rotateAnimation.current, {
|
|
18
|
+
toValue: active ? 1 : 0,
|
|
19
|
+
useNativeDriver: true,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
animation.start();
|
|
23
|
+
|
|
24
|
+
return () => {
|
|
25
|
+
animation.stop();
|
|
26
|
+
};
|
|
27
|
+
}, [active]);
|
|
28
|
+
|
|
29
|
+
const interpolatedRotateAnimation = rotateAnimation.current.interpolate({
|
|
30
|
+
inputRange: [0, 1],
|
|
31
|
+
outputRange: ['0deg', '-45deg'],
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Animated.View
|
|
36
|
+
style={StyleSheet.flatten([
|
|
37
|
+
{
|
|
38
|
+
transform: [{ rotate: interpolatedRotateAnimation }],
|
|
39
|
+
},
|
|
40
|
+
])}
|
|
41
|
+
>
|
|
42
|
+
<AnimatedIcons {...iconProps} />
|
|
43
|
+
</Animated.View>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { AnimatedFABIcon };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TouchableHighlight, TouchableHighlightProps } from 'react-native';
|
|
2
|
+
import styled from 'styled-components-native';
|
|
3
|
+
|
|
4
|
+
const StyledFABContainer = styled(TouchableHighlight)<TouchableHighlightProps>`
|
|
5
|
+
height: ${({ theme }) => theme.__hd__.fab.sizes.height};
|
|
6
|
+
width: ${({ theme }) => theme.__hd__.fab.sizes.width};
|
|
7
|
+
background-color: ${({ theme }) => theme.__hd__.fab.colors.buttonBackground};
|
|
8
|
+
border-radius: 999px;
|
|
9
|
+
align-items: center;
|
|
10
|
+
justify-content: center;
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
export { StyledFABContainer };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import styled from 'styled-components-native';
|
|
2
|
+
import Icon, { IconProps } from '../Icon';
|
|
3
|
+
|
|
4
|
+
const StyledFABIcon = styled(Icon)<IconProps>`
|
|
5
|
+
color: ${({ theme }) => theme.__hd__.fab.colors.icon};
|
|
6
|
+
font-size: ${({ theme }) => theme.__hd__.fab.fontSizes.default};
|
|
7
|
+
`;
|
|
8
|
+
|
|
9
|
+
export { StyledFABIcon };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react-native';
|
|
3
|
+
import { ThemeProvider, theme } from '../../../index';
|
|
4
|
+
import { AnimatedFABIcon } from '../AnimatedFABIcon';
|
|
5
|
+
|
|
6
|
+
describe('AnimatedFABIcon', () => {
|
|
7
|
+
it.each`
|
|
8
|
+
active
|
|
9
|
+
${true}
|
|
10
|
+
${false}
|
|
11
|
+
`('renders correctly when isActive is $active', ({ active }) => {
|
|
12
|
+
const { toJSON } = render(
|
|
13
|
+
<ThemeProvider theme={theme}>
|
|
14
|
+
<AnimatedFABIcon active={active} icon="add" />
|
|
15
|
+
</ThemeProvider>
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
expect(toJSON()).toMatchSnapshot();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react-native';
|
|
3
|
+
import { ThemeProvider, theme, Typography } from '../../../index';
|
|
4
|
+
import { StyledFABContainer } from '../StyledFABContainer';
|
|
5
|
+
|
|
6
|
+
describe('StyledFABContainer', () => {
|
|
7
|
+
it('renders correctly', () => {
|
|
8
|
+
const { toJSON } = render(
|
|
9
|
+
<ThemeProvider theme={theme}>
|
|
10
|
+
<StyledFABContainer>
|
|
11
|
+
<Typography.Text> button </Typography.Text>
|
|
12
|
+
</StyledFABContainer>
|
|
13
|
+
</ThemeProvider>
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
expect(toJSON()).toMatchSnapshot();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react-native';
|
|
3
|
+
import { ThemeProvider, theme } from '../../../index';
|
|
4
|
+
import { StyledFABIcon } from '../StyledFABIcon';
|
|
5
|
+
|
|
6
|
+
describe('StyledFABIcon', () => {
|
|
7
|
+
it('renders correctly', () => {
|
|
8
|
+
const { toJSON } = render(
|
|
9
|
+
<ThemeProvider theme={theme}>
|
|
10
|
+
<StyledFABIcon icon="add" />
|
|
11
|
+
</ThemeProvider>
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
expect(toJSON()).toMatchSnapshot();
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`AnimatedFABIcon renders correctly when isActive is false 1`] = `
|
|
4
|
+
<View
|
|
5
|
+
collapsable={false}
|
|
6
|
+
nativeID="animatedComponent"
|
|
7
|
+
style={
|
|
8
|
+
Object {
|
|
9
|
+
"transform": Array [
|
|
10
|
+
Object {
|
|
11
|
+
"rotate": "0deg",
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
>
|
|
17
|
+
<HeroIcon
|
|
18
|
+
name="add"
|
|
19
|
+
style={
|
|
20
|
+
Array [
|
|
21
|
+
Object {
|
|
22
|
+
"color": "#292a2b",
|
|
23
|
+
"fontSize": 24,
|
|
24
|
+
},
|
|
25
|
+
Object {
|
|
26
|
+
"color": "#ffffff",
|
|
27
|
+
"fontSize": 28,
|
|
28
|
+
},
|
|
29
|
+
Object {},
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
themeIntent="text"
|
|
33
|
+
themeSize="medium"
|
|
34
|
+
/>
|
|
35
|
+
</View>
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
exports[`AnimatedFABIcon renders correctly when isActive is true 1`] = `
|
|
39
|
+
<View
|
|
40
|
+
collapsable={false}
|
|
41
|
+
nativeID="animatedComponent"
|
|
42
|
+
style={
|
|
43
|
+
Object {
|
|
44
|
+
"transform": Array [
|
|
45
|
+
Object {
|
|
46
|
+
"rotate": "-45deg",
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
>
|
|
52
|
+
<HeroIcon
|
|
53
|
+
name="add"
|
|
54
|
+
style={
|
|
55
|
+
Array [
|
|
56
|
+
Object {
|
|
57
|
+
"color": "#292a2b",
|
|
58
|
+
"fontSize": 24,
|
|
59
|
+
},
|
|
60
|
+
Object {
|
|
61
|
+
"color": "#ffffff",
|
|
62
|
+
"fontSize": 28,
|
|
63
|
+
},
|
|
64
|
+
Object {},
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
themeIntent="text"
|
|
68
|
+
themeSize="medium"
|
|
69
|
+
/>
|
|
70
|
+
</View>
|
|
71
|
+
`;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`StyledFABContainer renders correctly 1`] = `
|
|
4
|
+
<View
|
|
5
|
+
accessible={true}
|
|
6
|
+
focusable={false}
|
|
7
|
+
onClick={[Function]}
|
|
8
|
+
onResponderGrant={[Function]}
|
|
9
|
+
onResponderMove={[Function]}
|
|
10
|
+
onResponderRelease={[Function]}
|
|
11
|
+
onResponderTerminate={[Function]}
|
|
12
|
+
onResponderTerminationRequest={[Function]}
|
|
13
|
+
onStartShouldSetResponder={[Function]}
|
|
14
|
+
style={
|
|
15
|
+
Object {
|
|
16
|
+
"alignItems": "center",
|
|
17
|
+
"backgroundColor": "#292a2b",
|
|
18
|
+
"borderBottomLeftRadius": 999,
|
|
19
|
+
"borderBottomRightRadius": 999,
|
|
20
|
+
"borderTopLeftRadius": 999,
|
|
21
|
+
"borderTopRightRadius": 999,
|
|
22
|
+
"height": 64,
|
|
23
|
+
"justifyContent": "center",
|
|
24
|
+
"overflow": "hidden",
|
|
25
|
+
"width": 64,
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
>
|
|
29
|
+
<Text
|
|
30
|
+
style={
|
|
31
|
+
Object {
|
|
32
|
+
"color": "#292a2b",
|
|
33
|
+
"fontSize": 14,
|
|
34
|
+
"fontWeight": "400",
|
|
35
|
+
"letterSpacing": 0.42,
|
|
36
|
+
"lineHeight": 22,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
themeFontSize="medium"
|
|
40
|
+
themeFontWeight="regular"
|
|
41
|
+
themeIntent="body"
|
|
42
|
+
>
|
|
43
|
+
button
|
|
44
|
+
</Text>
|
|
45
|
+
</View>
|
|
46
|
+
`;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`StyledFABIcon renders correctly 1`] = `
|
|
4
|
+
<HeroIcon
|
|
5
|
+
name="add"
|
|
6
|
+
style={
|
|
7
|
+
Array [
|
|
8
|
+
Object {
|
|
9
|
+
"color": "#292a2b",
|
|
10
|
+
"fontSize": 24,
|
|
11
|
+
},
|
|
12
|
+
Object {
|
|
13
|
+
"color": "#ffffff",
|
|
14
|
+
"fontSize": 28,
|
|
15
|
+
},
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
themeIntent="text"
|
|
19
|
+
themeSize="medium"
|
|
20
|
+
/>
|
|
21
|
+
`;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`FAB when animated is false renders styledFABIcon 1`] = `
|
|
4
|
+
<View
|
|
5
|
+
accessible={true}
|
|
6
|
+
focusable={true}
|
|
7
|
+
onClick={[Function]}
|
|
8
|
+
onResponderGrant={[Function]}
|
|
9
|
+
onResponderMove={[Function]}
|
|
10
|
+
onResponderRelease={[Function]}
|
|
11
|
+
onResponderTerminate={[Function]}
|
|
12
|
+
onResponderTerminationRequest={[Function]}
|
|
13
|
+
onStartShouldSetResponder={[Function]}
|
|
14
|
+
style={
|
|
15
|
+
Array [
|
|
16
|
+
Object {
|
|
17
|
+
"alignItems": "center",
|
|
18
|
+
"backgroundColor": "#292a2b",
|
|
19
|
+
"borderBottomLeftRadius": 999,
|
|
20
|
+
"borderBottomRightRadius": 999,
|
|
21
|
+
"borderTopLeftRadius": 999,
|
|
22
|
+
"borderTopRightRadius": 999,
|
|
23
|
+
"height": 64,
|
|
24
|
+
"justifyContent": "center",
|
|
25
|
+
"overflow": "hidden",
|
|
26
|
+
"width": 64,
|
|
27
|
+
},
|
|
28
|
+
Object {
|
|
29
|
+
"backgroundColor": "#292a2b",
|
|
30
|
+
},
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
>
|
|
34
|
+
<HeroIcon
|
|
35
|
+
name="add"
|
|
36
|
+
style={
|
|
37
|
+
Array [
|
|
38
|
+
Object {
|
|
39
|
+
"color": "#292a2b",
|
|
40
|
+
"fontSize": 24,
|
|
41
|
+
},
|
|
42
|
+
Object {
|
|
43
|
+
"color": "#ffffff",
|
|
44
|
+
"fontSize": 28,
|
|
45
|
+
},
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
testID="styledFABIcon"
|
|
49
|
+
themeIntent="text"
|
|
50
|
+
themeSize="medium"
|
|
51
|
+
/>
|
|
52
|
+
</View>
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
exports[`FAB when animated is true renders animatedFABIcon 1`] = `
|
|
56
|
+
<View
|
|
57
|
+
accessible={true}
|
|
58
|
+
focusable={true}
|
|
59
|
+
onClick={[Function]}
|
|
60
|
+
onResponderGrant={[Function]}
|
|
61
|
+
onResponderMove={[Function]}
|
|
62
|
+
onResponderRelease={[Function]}
|
|
63
|
+
onResponderTerminate={[Function]}
|
|
64
|
+
onResponderTerminationRequest={[Function]}
|
|
65
|
+
onStartShouldSetResponder={[Function]}
|
|
66
|
+
style={
|
|
67
|
+
Array [
|
|
68
|
+
Object {
|
|
69
|
+
"alignItems": "center",
|
|
70
|
+
"backgroundColor": "#292a2b",
|
|
71
|
+
"borderBottomLeftRadius": 999,
|
|
72
|
+
"borderBottomRightRadius": 999,
|
|
73
|
+
"borderTopLeftRadius": 999,
|
|
74
|
+
"borderTopRightRadius": 999,
|
|
75
|
+
"height": 64,
|
|
76
|
+
"justifyContent": "center",
|
|
77
|
+
"overflow": "hidden",
|
|
78
|
+
"width": 64,
|
|
79
|
+
},
|
|
80
|
+
Object {
|
|
81
|
+
"backgroundColor": "#292a2b",
|
|
82
|
+
},
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
>
|
|
86
|
+
<View
|
|
87
|
+
collapsable={false}
|
|
88
|
+
nativeID="animatedComponent"
|
|
89
|
+
style={
|
|
90
|
+
Object {
|
|
91
|
+
"transform": Array [
|
|
92
|
+
Object {
|
|
93
|
+
"rotate": "0deg",
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
>
|
|
99
|
+
<HeroIcon
|
|
100
|
+
name="add"
|
|
101
|
+
style={
|
|
102
|
+
Array [
|
|
103
|
+
Object {
|
|
104
|
+
"color": "#292a2b",
|
|
105
|
+
"fontSize": 24,
|
|
106
|
+
},
|
|
107
|
+
Object {
|
|
108
|
+
"color": "#ffffff",
|
|
109
|
+
"fontSize": 28,
|
|
110
|
+
},
|
|
111
|
+
Object {},
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
testID="animatedFABIcon"
|
|
115
|
+
themeIntent="text"
|
|
116
|
+
themeSize="medium"
|
|
117
|
+
/>
|
|
118
|
+
</View>
|
|
119
|
+
</View>
|
|
120
|
+
`;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { fireEvent, render } from '@testing-library/react-native';
|
|
3
|
+
import { ThemeProvider, theme } from '../../../index';
|
|
4
|
+
import FAB from '..';
|
|
5
|
+
|
|
6
|
+
describe('FAB', () => {
|
|
7
|
+
describe('when animated is true', () => {
|
|
8
|
+
it('renders animatedFABIcon', () => {
|
|
9
|
+
const { queryAllByTestId, toJSON } = render(
|
|
10
|
+
<ThemeProvider theme={theme}>
|
|
11
|
+
<FAB
|
|
12
|
+
icon="add"
|
|
13
|
+
animated
|
|
14
|
+
style={{ backgroundColor: theme.colors.backgroundDark }}
|
|
15
|
+
/>
|
|
16
|
+
</ThemeProvider>
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
expect(toJSON()).toMatchSnapshot();
|
|
20
|
+
expect(queryAllByTestId('animatedFABIcon')).toHaveLength(1);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('when animated is false', () => {
|
|
25
|
+
it('renders styledFABIcon', () => {
|
|
26
|
+
const { queryAllByTestId, toJSON } = render(
|
|
27
|
+
<ThemeProvider theme={theme}>
|
|
28
|
+
<FAB
|
|
29
|
+
icon="add"
|
|
30
|
+
style={{ backgroundColor: theme.colors.backgroundDark }}
|
|
31
|
+
/>
|
|
32
|
+
</ThemeProvider>
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
expect(toJSON()).toMatchSnapshot();
|
|
36
|
+
expect(queryAllByTestId('styledFABIcon')).toHaveLength(1);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('when onPress', () => {
|
|
41
|
+
it('triggers onPress', () => {
|
|
42
|
+
const onPressSpy = jest.fn();
|
|
43
|
+
const { getByTestId } = render(
|
|
44
|
+
<ThemeProvider theme={theme}>
|
|
45
|
+
<FAB
|
|
46
|
+
onPress={onPressSpy}
|
|
47
|
+
icon="add"
|
|
48
|
+
style={{ backgroundColor: theme.colors.backgroundDark }}
|
|
49
|
+
testID="FAB"
|
|
50
|
+
/>
|
|
51
|
+
</ThemeProvider>
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
fireEvent(getByTestId('FAB'), 'press');
|
|
55
|
+
expect(onPressSpy).toBeCalledTimes(1);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
import { IconProps } from '../Icon';
|
|
4
|
+
import { AnimatedFABIcon } from './AnimatedFABIcon';
|
|
5
|
+
import { StyledFABContainer } from './StyledFABContainer';
|
|
6
|
+
import { StyledFABIcon } from './StyledFABIcon';
|
|
7
|
+
|
|
8
|
+
interface FABProps {
|
|
9
|
+
/**
|
|
10
|
+
* Name of the Icon.
|
|
11
|
+
*/
|
|
12
|
+
icon: IconProps['icon'];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This function is called on pressing the button.
|
|
16
|
+
* */
|
|
17
|
+
onPress?: () => void;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Specify if the button is animated.
|
|
21
|
+
*/
|
|
22
|
+
animated?: boolean;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Specify if the button is in active state. It only works if animated is true.
|
|
26
|
+
*/
|
|
27
|
+
active?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Addditional style.
|
|
30
|
+
*/
|
|
31
|
+
style?: StyleProp<ViewStyle>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Testing id of the component.
|
|
35
|
+
*/
|
|
36
|
+
testID?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const FAB = ({ onPress, icon, animated, testID, active, style }: FABProps) => (
|
|
40
|
+
<StyledFABContainer
|
|
41
|
+
testID={testID}
|
|
42
|
+
onPress={() => {
|
|
43
|
+
onPress?.();
|
|
44
|
+
}}
|
|
45
|
+
activeOpacity={0.6}
|
|
46
|
+
style={style}
|
|
47
|
+
>
|
|
48
|
+
{animated ? (
|
|
49
|
+
<AnimatedFABIcon active={active} icon={icon} testID="animatedFABIcon" />
|
|
50
|
+
) : (
|
|
51
|
+
<StyledFABIcon icon={icon} testID="styledFABIcon" />
|
|
52
|
+
)}
|
|
53
|
+
</StyledFABContainer>
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
export default FAB;
|
package/src/index.ts
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { ThemeProvider, useTheme } from 'styled-components-native';
|
|
2
2
|
import theme, { getTheme } from './theme';
|
|
3
|
+
import { scale } from './utils/scale';
|
|
3
4
|
|
|
4
5
|
import Badge from './components/Badge';
|
|
5
6
|
import Card from './components/Card';
|
|
6
7
|
import Divider from './components/Divider';
|
|
7
8
|
import Icon from './components/Icon';
|
|
8
9
|
import Typography from './components/Typography';
|
|
10
|
+
import FAB from './components/FAB';
|
|
9
11
|
|
|
10
12
|
export {
|
|
11
13
|
theme,
|
|
12
14
|
getTheme,
|
|
13
15
|
useTheme,
|
|
16
|
+
scale,
|
|
14
17
|
ThemeProvider,
|
|
15
18
|
Badge,
|
|
16
19
|
Card,
|
|
17
20
|
Divider,
|
|
18
21
|
Icon,
|
|
19
22
|
Typography,
|
|
23
|
+
FAB,
|
|
20
24
|
};
|