@hero-design/rn 7.0.6 → 7.1.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.
Files changed (48) hide show
  1. package/.expo/packager-info.json +1 -1
  2. package/babel.config.js +1 -1
  3. package/es/index.js +148 -41
  4. package/lib/index.js +147 -38
  5. package/package.json +3 -3
  6. package/playground/components/Card.tsx +74 -91
  7. package/playground/components/FAB.tsx +49 -0
  8. package/playground/index.tsx +3 -1
  9. package/src/components/Card/__tests__/__snapshots__/Card.spec.tsx.snap +4 -4
  10. package/src/components/Card/__tests__/__snapshots__/StyledCard.spec.tsx.snap +4 -4
  11. package/src/components/FAB/AnimatedFABIcon.tsx +47 -0
  12. package/src/components/FAB/StyledFABContainer.tsx +14 -0
  13. package/src/components/FAB/StyledFABIcon.tsx +9 -0
  14. package/src/components/FAB/__tests__/AnimatedFABIcon.spec.tsx +20 -0
  15. package/src/components/FAB/__tests__/StyledFABContainer.spec.tsx +18 -0
  16. package/src/components/FAB/__tests__/StyledFABIcon.spec.tsx +16 -0
  17. package/src/components/FAB/__tests__/__snapshots__/AnimatedFABIcon.spec.tsx.snap +71 -0
  18. package/src/components/FAB/__tests__/__snapshots__/StyledFABContainer.spec.tsx.snap +46 -0
  19. package/src/components/FAB/__tests__/__snapshots__/StyledFABIcon.spec.tsx.snap +21 -0
  20. package/src/components/FAB/__tests__/__snapshots__/index.spec.tsx.snap +120 -0
  21. package/src/components/FAB/__tests__/index.spec.tsx +58 -0
  22. package/src/components/FAB/index.tsx +56 -0
  23. package/src/components/Icon/index.tsx +1 -1
  24. package/src/index.ts +4 -0
  25. package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +14 -1
  26. package/src/theme/components/card.ts +1 -1
  27. package/src/theme/components/fab.ts +21 -0
  28. package/src/theme/global/space.ts +11 -9
  29. package/src/theme/global/typography.ts +11 -9
  30. package/src/theme/index.ts +3 -0
  31. package/src/utils/__tests__/scale.spec.ts +26 -0
  32. package/src/utils/scale.ts +10 -0
  33. package/testUtils/setup.ts +4 -0
  34. package/types/playground/components/FAB.d.ts +2 -0
  35. package/types/src/components/FAB/AnimatedFABIcon.d.ts +6 -0
  36. package/types/src/components/FAB/StyledFABContainer.d.ts +3 -0
  37. package/types/src/components/FAB/StyledFABIcon.d.ts +3 -0
  38. package/types/src/components/FAB/__tests__/AnimatedFABIcon.spec.d.ts +1 -0
  39. package/types/src/components/FAB/__tests__/StyledFABContainer.spec.d.ts +1 -0
  40. package/types/src/components/FAB/__tests__/StyledFABIcon.spec.d.ts +1 -0
  41. package/types/src/components/FAB/__tests__/index.spec.d.ts +1 -0
  42. package/types/src/components/FAB/index.d.ts +30 -0
  43. package/types/src/components/Icon/index.d.ts +1 -1
  44. package/types/src/index.d.ts +3 -1
  45. package/types/src/theme/components/fab.d.ts +15 -0
  46. package/types/src/theme/index.d.ts +2 -0
  47. package/types/src/utils/__tests__/scale.spec.d.ts +1 -0
  48. package/types/src/utils/scale.d.ts +2 -0
@@ -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;
@@ -5,7 +5,7 @@ import HeroIcon from './HeroIcon';
5
5
 
6
6
  type IconName = typeof IconList[number];
7
7
 
8
- interface IconProps {
8
+ export interface IconProps {
9
9
  /**
10
10
  * Name of the Icon.
11
11
  */
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
  };
@@ -32,7 +32,7 @@ Object {
32
32
  },
33
33
  "card": Object {
34
34
  "padding": Object {
35
- "default": "16px",
35
+ "default": "8px",
36
36
  },
37
37
  "radii": Object {
38
38
  "default": "12px",
@@ -53,6 +53,19 @@ Object {
53
53
  "xsmall": "4px",
54
54
  },
55
55
  },
56
+ "fab": Object {
57
+ "colors": Object {
58
+ "buttonBackground": "#292a2b",
59
+ "icon": "#ffffff",
60
+ },
61
+ "fontSizes": Object {
62
+ "default": "28px",
63
+ },
64
+ "sizes": Object {
65
+ "height": "64px",
66
+ "width": "64px",
67
+ },
68
+ },
56
69
  "icon": Object {
57
70
  "colors": Object {
58
71
  "danger": "#de350b",
@@ -6,7 +6,7 @@ const getCardTheme = (theme: GlobalTheme) => {
6
6
  };
7
7
 
8
8
  const padding = {
9
- default: `${theme.space.medium}px`,
9
+ default: `${theme.space.small}px`,
10
10
  };
11
11
 
12
12
  return { radii, padding };
@@ -0,0 +1,21 @@
1
+ import { GlobalTheme } from '../global';
2
+
3
+ const getFABTheme = (theme: GlobalTheme) => {
4
+ const colors = {
5
+ buttonBackground: theme.colors.backgroundDark,
6
+ icon: theme.colors.invertedText,
7
+ };
8
+
9
+ const sizes = {
10
+ width: '64px',
11
+ height: '64px',
12
+ };
13
+
14
+ const fontSizes = {
15
+ default: `${theme.fontSizes.xxxxlarge}px`,
16
+ };
17
+
18
+ return { fontSizes, colors, sizes };
19
+ };
20
+
21
+ export default getFABTheme;
@@ -1,15 +1,17 @@
1
+ import { scale } from '../../utils/scale';
2
+
1
3
  const BASE = 8;
2
4
 
3
5
  const space = {
4
- xxsmall: BASE * 0.25,
5
- xsmall: BASE * 0.5,
6
- small: BASE,
7
- medium: BASE * 2,
8
- large: BASE * 3,
9
- xlarge: BASE * 4,
10
- xxlarge: BASE * 5,
11
- xxxlarge: BASE * 6,
12
- xxxxlarge: BASE * 7,
6
+ xxsmall: scale(BASE * 0.25),
7
+ xsmall: scale(BASE * 0.5),
8
+ small: scale(BASE),
9
+ medium: scale(BASE * 2),
10
+ large: scale(BASE * 3),
11
+ xlarge: scale(BASE * 4),
12
+ xxlarge: scale(BASE * 5),
13
+ xxxlarge: scale(BASE * 6),
14
+ xxxxlarge: scale(BASE * 7),
13
15
  };
14
16
 
15
17
  export { space };
@@ -1,15 +1,17 @@
1
+ import { scale } from '../../utils/scale';
2
+
1
3
  const BASE = 16;
2
4
 
3
5
  const fontSizes = {
4
- xxxxxlarge: BASE * 2, // 32
5
- xxxxlarge: BASE * 1.75, // 28
6
- xxxlarge: BASE * 1.5, // 24
7
- xxlarge: BASE * 1.25, // 20
8
- xlarge: BASE * 1.125, // 18
9
- large: BASE, // 16
10
- medium: BASE * 0.875, // 14
11
- small: BASE * 0.75, // 12
12
- xsmall: BASE * 0.625, // 10
6
+ xxxxxlarge: scale(BASE * 2), // 32
7
+ xxxxlarge: scale(BASE * 1.75), // 28
8
+ xxxlarge: scale(BASE * 1.5), // 24
9
+ xxlarge: scale(BASE * 1.25), // 20
10
+ xlarge: scale(BASE * 1.125), // 18
11
+ large: scale(BASE), // 16
12
+ medium: scale(BASE * 0.875), // 14
13
+ small: scale(BASE * 0.75), // 12
14
+ xsmall: scale(BASE * 0.625), // 10
13
15
  };
14
16
 
15
17
  const fontWeights = {
@@ -5,6 +5,7 @@ import getCardTheme from './components/card';
5
5
  import getDividerTheme from './components/divider';
6
6
  import getIconTheme from './components/icon';
7
7
  import getTypographyTheme from './components/typography';
8
+ import getFABTheme from './components/fab';
8
9
 
9
10
  type Theme = GlobalTheme & {
10
11
  __hd__: {
@@ -13,6 +14,7 @@ type Theme = GlobalTheme & {
13
14
  divider: ReturnType<typeof getDividerTheme>;
14
15
  icon: ReturnType<typeof getIconTheme>;
15
16
  typography: ReturnType<typeof getTypographyTheme>;
17
+ fab: ReturnType<typeof getFABTheme>;
16
18
  };
17
19
  };
18
20
 
@@ -24,6 +26,7 @@ const getTheme = (theme: GlobalTheme = globalTheme): Theme => ({
24
26
  divider: getDividerTheme(theme),
25
27
  icon: getIconTheme(theme),
26
28
  typography: getTypographyTheme(theme),
29
+ fab: getFABTheme(theme),
27
30
  },
28
31
  });
29
32
 
@@ -0,0 +1,26 @@
1
+ import { Dimensions } from 'react-native';
2
+ import { scale, BASE_WIDTH } from '../scale';
3
+
4
+ jest.unmock('../scale'); // Unmock global mocking of scale for other tests
5
+
6
+ describe('scale', () => {
7
+ it('returns scale based on width when width < height', () => {
8
+ jest
9
+ .spyOn(Dimensions, 'get')
10
+ .mockReturnValue({ width: 400, height: 500, scale: 1, fontScale: 1 });
11
+
12
+ const size = 10;
13
+
14
+ expect(scale(size)).toBe((400 / BASE_WIDTH) * size);
15
+ });
16
+
17
+ it('returns scale based on height when width > height', () => {
18
+ jest
19
+ .spyOn(Dimensions, 'get')
20
+ .mockReturnValue({ width: 700, height: 350, scale: 1, fontScale: 1 });
21
+
22
+ const size = 10;
23
+
24
+ expect(scale(size)).toBe((350 / BASE_WIDTH) * size);
25
+ });
26
+ });
@@ -0,0 +1,10 @@
1
+ import { Dimensions } from 'react-native';
2
+
3
+ export const BASE_WIDTH = 390; // Based on iPhone 13's viewport size
4
+
5
+ export const scale = (size: number) => {
6
+ const { width, height } = Dimensions.get('window');
7
+ const shortDimension = width < height ? width : height;
8
+
9
+ return (shortDimension / BASE_WIDTH) * size;
10
+ };
@@ -1,3 +1,7 @@
1
1
  jest.mock('react-native-vector-icons', () => ({
2
2
  createIconSetFromIcoMoon: jest.fn(() => 'HeroIcon'),
3
3
  }));
4
+
5
+ jest.mock('../src/utils/scale', () => ({
6
+ scale: jest.fn(size => size),
7
+ }));
@@ -0,0 +1,2 @@
1
+ declare const FABPlayground: () => JSX.Element;
2
+ export default FABPlayground;
@@ -0,0 +1,6 @@
1
+ import { IconProps } from '../Icon';
2
+ declare type Props = {
3
+ active?: boolean;
4
+ } & IconProps;
5
+ declare const AnimatedFABIcon: ({ active, ...iconProps }: Props) => JSX.Element;
6
+ export { AnimatedFABIcon };
@@ -0,0 +1,3 @@
1
+ import { TouchableHighlight, TouchableHighlightProps } from 'react-native';
2
+ declare const StyledFABContainer: import("styled-components").StyledComponent<typeof TouchableHighlight, import("../../theme").Theme, TouchableHighlightProps, never>;
3
+ export { StyledFABContainer };
@@ -0,0 +1,3 @@
1
+ import { IconProps } from '../Icon';
2
+ declare const StyledFABIcon: import("styled-components").StyledComponent<({ icon, style, size, intent, testID, }: IconProps) => JSX.Element, import("../../theme").Theme, IconProps, never>;
3
+ export { StyledFABIcon };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ import { StyleProp, ViewStyle } from 'react-native';
2
+ import { IconProps } from '../Icon';
3
+ interface FABProps {
4
+ /**
5
+ * Name of the Icon.
6
+ */
7
+ icon: IconProps['icon'];
8
+ /**
9
+ * This function is called on pressing the button.
10
+ * */
11
+ onPress?: () => void;
12
+ /**
13
+ * Specify if the button is animated.
14
+ */
15
+ animated?: boolean;
16
+ /**
17
+ * Specify if the button is in active state. It only works if animated is true.
18
+ */
19
+ active?: boolean;
20
+ /**
21
+ * Addditional style.
22
+ */
23
+ style?: StyleProp<ViewStyle>;
24
+ /**
25
+ * Testing id of the component.
26
+ */
27
+ testID?: string;
28
+ }
29
+ declare const FAB: ({ onPress, icon, animated, testID, active, style }: FABProps) => JSX.Element;
30
+ export default FAB;
@@ -1,7 +1,7 @@
1
1
  import { StyleProp, TextStyle } from 'react-native';
2
2
  import IconList from './IconList';
3
3
  declare type IconName = typeof IconList[number];
4
- interface IconProps {
4
+ export interface IconProps {
5
5
  /**
6
6
  * Name of the Icon.
7
7
  */
@@ -1,8 +1,10 @@
1
1
  import { ThemeProvider, useTheme } from 'styled-components-native';
2
2
  import theme, { getTheme } from './theme';
3
+ import { scale } from './utils/scale';
3
4
  import Badge from './components/Badge';
4
5
  import Card from './components/Card';
5
6
  import Divider from './components/Divider';
6
7
  import Icon from './components/Icon';
7
8
  import Typography from './components/Typography';
8
- export { theme, getTheme, useTheme, ThemeProvider, Badge, Card, Divider, Icon, Typography, };
9
+ import FAB from './components/FAB';
10
+ export { theme, getTheme, useTheme, scale, ThemeProvider, Badge, Card, Divider, Icon, Typography, FAB, };
@@ -0,0 +1,15 @@
1
+ import { GlobalTheme } from '../global';
2
+ declare const getFABTheme: (theme: GlobalTheme) => {
3
+ fontSizes: {
4
+ default: string;
5
+ };
6
+ colors: {
7
+ buttonBackground: string;
8
+ icon: string;
9
+ };
10
+ sizes: {
11
+ width: string;
12
+ height: string;
13
+ };
14
+ };
15
+ export default getFABTheme;
@@ -4,6 +4,7 @@ import getCardTheme from './components/card';
4
4
  import getDividerTheme from './components/divider';
5
5
  import getIconTheme from './components/icon';
6
6
  import getTypographyTheme from './components/typography';
7
+ import getFABTheme from './components/fab';
7
8
  declare type Theme = GlobalTheme & {
8
9
  __hd__: {
9
10
  badge: ReturnType<typeof getBadgeTheme>;
@@ -11,6 +12,7 @@ declare type Theme = GlobalTheme & {
11
12
  divider: ReturnType<typeof getDividerTheme>;
12
13
  icon: ReturnType<typeof getIconTheme>;
13
14
  typography: ReturnType<typeof getTypographyTheme>;
15
+ fab: ReturnType<typeof getFABTheme>;
14
16
  };
15
17
  };
16
18
  declare const getTheme: (theme?: GlobalTheme) => Theme;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const BASE_WIDTH = 390;
2
+ export declare const scale: (size: number) => number;