@hero-design/rn 6.7.2 → 6.7.4-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.
Files changed (35) hide show
  1. package/.eslintrc.json +10 -2
  2. package/.expo/README.md +15 -0
  3. package/.expo/packager-info.json +10 -0
  4. package/.expo/settings.json +10 -0
  5. package/es/index.js +63 -80
  6. package/lib/index.js +63 -79
  7. package/package.json +7 -3
  8. package/playground/components/ExampleComponent.tsx +8 -0
  9. package/playground/index.tsx +77 -17
  10. package/src/components/ExampleComponent/StyledView.tsx +16 -22
  11. package/src/components/ExampleComponent/__tests__/StyledView.spec.tsx +6 -3
  12. package/src/components/ExampleComponent/__tests__/__snapshots__/StyledView.spec.tsx.snap +4 -4
  13. package/src/components/ExampleComponent/index.tsx +5 -5
  14. package/src/index.ts +3 -3
  15. package/src/styled-components.ts +14 -0
  16. package/src/styled.d.ts +3 -4
  17. package/src/theme/components/exampleComponent.ts +19 -0
  18. package/src/theme/{colors.ts → global/colors.ts} +1 -1
  19. package/src/theme/global/index.ts +19 -0
  20. package/src/theme/{space.ts → global/space.ts} +0 -0
  21. package/src/theme/{typography.ts → global/typography.ts} +5 -5
  22. package/src/theme/index.ts +15 -19
  23. package/tsconfig.json +2 -1
  24. package/types/components/ExampleComponent/StyledView.d.ts +4 -9
  25. package/types/components/ExampleComponent/index.d.ts +3 -3
  26. package/types/index.d.ts +3 -3
  27. package/types/styled-components.d.ts +6 -0
  28. package/types/theme/components/exampleComponent.d.ts +14 -0
  29. package/types/theme/{colors.d.ts → global/colors.d.ts} +0 -0
  30. package/types/theme/global/index.d.ts +58 -0
  31. package/types/theme/{space.d.ts → global/space.d.ts} +0 -0
  32. package/types/theme/{typography.d.ts → global/typography.d.ts} +0 -0
  33. package/types/theme/index.d.ts +8 -145
  34. package/src/theme/components/demoStyle.ts +0 -16
  35. package/types/theme/components/demoStyle.d.ts +0 -11
@@ -1,25 +1,85 @@
1
- import { SafeAreaView, View } from 'react-native';
2
1
  import React from 'react';
3
- import { theme, ThemeProvider, ExampleComponent } from '../src/index';
2
+ import { NavigationContainer, DefaultTheme } from '@react-navigation/native'; // eslint-disable-line import/no-extraneous-dependencies
3
+ import { createNativeStackNavigator } from '@react-navigation/native-stack'; // eslint-disable-line import/no-extraneous-dependencies
4
+ import { SafeAreaView, FlatList, Text, ListRenderItemInfo } from 'react-native';
5
+ import { ThemeProvider, theme, useTheme } from '../src/index';
6
+ import ExampleComponentPlayground from './components/ExampleComponent';
4
7
 
5
- const App = () => (
6
- <ThemeProvider theme={theme}>
7
- <SafeAreaView
8
+ type ComponentEntry = { name: string; component: React.FC };
9
+
10
+ const Stack = createNativeStackNavigator();
11
+
12
+ const components: ComponentEntry[] = [
13
+ { name: 'ExampleComponent', component: ExampleComponentPlayground },
14
+ ];
15
+
16
+ const ComponentItem = ({
17
+ name,
18
+ onPress,
19
+ }: {
20
+ name: string;
21
+ onPress: () => void;
22
+ }) => {
23
+ const hdTheme = useTheme();
24
+ return (
25
+ <Text
26
+ onPress={onPress}
8
27
  style={{
9
- flex: 1,
10
- justifyContent: 'center',
11
- alignItems: 'center',
28
+ marginTop: hdTheme.space.large,
29
+ fontSize: hdTheme.fontSizes.large,
12
30
  }}
13
31
  >
14
- <View
15
- style={{
16
- borderWidth: 1,
17
- }}
18
- >
19
- <ExampleComponent boxSize="medium" boxSpace="medium" bgColor="danger" />
20
- </View>
32
+ {name}
33
+ </Text>
34
+ );
35
+ };
36
+
37
+ const ComponentList = ({ navigation }) => {
38
+ const hdTheme = useTheme();
39
+ return (
40
+ <SafeAreaView style={{ marginHorizontal: hdTheme.space.large }}>
41
+ <FlatList
42
+ data={components}
43
+ renderItem={({ item }: ListRenderItemInfo<ComponentEntry>) => (
44
+ <ComponentItem
45
+ name={item.name}
46
+ onPress={() => navigation.navigate(item.name)}
47
+ />
48
+ )}
49
+ />
21
50
  </SafeAreaView>
22
- </ThemeProvider>
23
- );
51
+ );
52
+ };
53
+
54
+ const App = () => {
55
+ const CustomNavigationTheme = {
56
+ ...DefaultTheme,
57
+ colors: {
58
+ ...DefaultTheme.colors,
59
+ primary: theme.colors.primary,
60
+ background: theme.colors.platformBackground,
61
+ },
62
+ };
63
+ return (
64
+ <ThemeProvider theme={theme}>
65
+ <NavigationContainer theme={CustomNavigationTheme}>
66
+ <Stack.Navigator initialRouteName="Home">
67
+ <Stack.Screen
68
+ name="Home"
69
+ component={ComponentList}
70
+ options={{ title: 'Mobile Hero Design' }}
71
+ />
72
+ {components.map(component => (
73
+ <Stack.Screen
74
+ key={component.name}
75
+ name={component.name}
76
+ component={component.component}
77
+ />
78
+ ))}
79
+ </Stack.Navigator>
80
+ </NavigationContainer>
81
+ </ThemeProvider>
82
+ );
83
+ };
24
84
 
25
85
  export default App;
@@ -1,23 +1,17 @@
1
1
  import { View } from 'react-native';
2
- import styled, { css } from 'styled-components/native';
3
-
4
- export interface Props {
5
- boxSize: 'small' | 'medium' | 'large';
6
- boxSpace: 'small' | 'medium' | 'large';
7
- bgColor: 'primary' | 'danger' | 'warning';
8
- }
2
+ import styled, { css } from '../../styled-components';
9
3
 
10
4
  const Square = styled(View)<{
11
- boxSize: Props['boxSize'];
12
- boxSpace: Props['boxSpace'];
13
- bgColor: Props['bgColor'];
5
+ themeSize: 'small' | 'medium' | 'large';
6
+ themeMargin: 'small' | 'medium' | 'large';
7
+ themeBgColor: 'primary' | 'danger' | 'warning';
14
8
  }>`
15
9
  display: flex;
16
10
  align-items: center;
17
11
  justify-content: center;
18
12
 
19
- ${({ boxSize }) => {
20
- switch (boxSize) {
13
+ ${({ themeSize }) => {
14
+ switch (themeSize) {
21
15
  case 'small':
22
16
  return css`
23
17
  height: 50px;
@@ -36,36 +30,36 @@ const Square = styled(View)<{
36
30
  }
37
31
  }}
38
32
 
39
- ${({ boxSpace, theme }) => {
40
- switch (boxSpace) {
33
+ ${({ themeMargin, theme }) => {
34
+ switch (themeMargin) {
41
35
  case 'small':
42
36
  return css`
43
- margin: ${theme.space.demoStyle.smallMargin}px;
37
+ margin: ${theme.__hd__.exampleComponent.space.smallMargin}px;
44
38
  `;
45
39
  case 'medium':
46
40
  return css`
47
- margin: ${theme.space.demoStyle.mediumMargin}px;
41
+ margin: ${theme.__hd__.exampleComponent.space.mediumMargin}px;
48
42
  `;
49
43
  case 'large':
50
44
  return css`
51
- margin: ${theme.space.demoStyle.largeMargin}px;
45
+ margin: ${theme.__hd__.exampleComponent.space.largeMargin}px;
52
46
  `;
53
47
  }
54
48
  }}
55
49
 
56
- ${({ bgColor, theme }) => {
57
- switch (bgColor) {
50
+ ${({ themeBgColor, theme }) => {
51
+ switch (themeBgColor) {
58
52
  case 'primary':
59
53
  return css`
60
- background-color: ${theme.colors.demoStyle.primaryBg};
54
+ background-color: ${theme.__hd__.exampleComponent.colors.primaryBg};
61
55
  `;
62
56
  case 'danger':
63
57
  return css`
64
- background-color: ${theme.colors.demoStyle.dangerBg};
58
+ background-color: ${theme.__hd__.exampleComponent.colors.dangerBg};
65
59
  `;
66
60
  case 'warning':
67
61
  return css`
68
- background-color: ${theme.colors.demoStyle.warningBg};
62
+ background-color: ${theme.__hd__.exampleComponent.colors.warningBg};
69
63
  `;
70
64
  }
71
65
  }}
@@ -1,14 +1,17 @@
1
1
  import React from 'react';
2
2
  import { render } from '@testing-library/react-native';
3
- import { ThemeProvider } from 'styled-components/native';
4
- import theme from '../../../theme';
3
+ import { ThemeProvider, theme } from '../../../index';
5
4
  import { Square } from '../StyledView';
6
5
 
7
6
  describe('StyledView', () => {
8
7
  it('renders correct styling', () => {
9
8
  const { toJSON } = render(
10
9
  <ThemeProvider theme={theme}>
11
- <Square boxSize="medium" boxSpace="medium" bgColor="primary" />
10
+ <Square
11
+ themeSize="medium"
12
+ themeMargin="medium"
13
+ themeBgColor="primary"
14
+ />
12
15
  </ThemeProvider>
13
16
  );
14
17
 
@@ -2,13 +2,10 @@
2
2
 
3
3
  exports[`StyledView renders correct styling 1`] = `
4
4
  <View
5
- bgColor="primary"
6
- boxSize="medium"
7
- boxSpace="medium"
8
5
  style={
9
6
  Object {
10
7
  "alignItems": "center",
11
- "backgroundColor": "#f1e9fb",
8
+ "backgroundColor": "#c8a7ef",
12
9
  "display": "flex",
13
10
  "height": 100,
14
11
  "justifyContent": "center",
@@ -19,5 +16,8 @@ exports[`StyledView renders correct styling 1`] = `
19
16
  "width": 250,
20
17
  }
21
18
  }
19
+ themeBgColor="primary"
20
+ themeMargin="medium"
21
+ themeSize="medium"
22
22
  />
23
23
  `;
@@ -6,20 +6,20 @@ interface Props {
6
6
  /**
7
7
  * Size.
8
8
  */
9
- boxSize: 'small' | 'medium' | 'large';
9
+ size?: 'small' | 'medium' | 'large';
10
10
  /**
11
11
  * Margin.
12
12
  */
13
- boxSpace: 'small' | 'medium' | 'large';
13
+ margin: 'small' | 'medium' | 'large';
14
14
  /**
15
15
  * Background color.
16
16
  */
17
17
  bgColor: 'primary' | 'danger' | 'warning';
18
18
  }
19
19
 
20
- const ExampleComponent = ({ boxSize = "small", boxSpace, bgColor }: Props) => (
21
- <Square boxSize={boxSize} boxSpace={boxSpace} bgColor={bgColor}>
22
- <Text>{`Square with ${boxSize} size, ${boxSpace} margin and ${bgColor} background.`}</Text>
20
+ const ExampleComponent = ({ size = 'small', margin, bgColor }: Props) => (
21
+ <Square themeSize={size} themeMargin={margin} themeBgColor={bgColor}>
22
+ <Text>{`Square with ${size} size, ${margin} margin and ${bgColor} background.`}</Text>
23
23
  </Square>
24
24
  );
25
25
 
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { ThemeProvider, useTheme } from 'styled-components/native';
2
- import theme from './theme';
1
+ import { ThemeProvider, useTheme } from './styled-components';
2
+ import theme, { getTheme } from './theme';
3
3
 
4
4
  // Example components
5
5
  import ExampleComponent from './components/ExampleComponent';
6
6
 
7
- export { theme, useTheme, ThemeProvider, ExampleComponent };
7
+ export { theme, getTheme, useTheme, ThemeProvider, ExampleComponent };
@@ -0,0 +1,14 @@
1
+ import * as styledComponents from 'styled-components/native';
2
+
3
+ import type { Theme } from './theme';
4
+
5
+ const {
6
+ default: styled,
7
+ useTheme,
8
+ css,
9
+ ThemeProvider,
10
+ } = styledComponents as styledComponents.ReactNativeThemedStyledComponentsModule<Theme>;
11
+
12
+ export { useTheme, css, ThemeProvider };
13
+
14
+ export default styled;
package/src/styled.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import 'styled-components';
1
+ import 'styled-components/native';
2
2
 
3
- import { Theme } from './theme/index';
3
+ import { Theme } from './theme';
4
4
 
5
- declare module 'styled-components' {
6
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
5
+ declare module 'styled-components/native' {
7
6
  export interface DefaultTheme extends Theme {}
8
7
  }
@@ -0,0 +1,19 @@
1
+ import { GlobalTheme } from '../global';
2
+
3
+ const getExampleComponentTheme = (theme: GlobalTheme) => {
4
+ const colors = {
5
+ primaryBg: theme.colors.primaryLight,
6
+ dangerBg: theme.colors.dangerBackground,
7
+ warningBg: theme.colors.warningBackground,
8
+ };
9
+
10
+ const space = {
11
+ smallMargin: theme.space.xxsmall,
12
+ mediumMargin: theme.space.medium,
13
+ largeMargin: theme.space.xxxxlarge,
14
+ };
15
+
16
+ return { colors, space };
17
+ };
18
+
19
+ export default getExampleComponentTheme;
@@ -21,6 +21,6 @@ const systemPalette = {
21
21
  text: palette.greyDark75,
22
22
  disabledText: palette.greyDark15,
23
23
  invertedText: palette.white,
24
- }
24
+ };
25
25
 
26
26
  export { palette, systemPalette };
@@ -0,0 +1,19 @@
1
+ import { systemPalette } from './colors';
2
+ import { space } from './space';
3
+ import { fontSizes, fontWeights, lineHeights } from './typography';
4
+
5
+ const globalTheme = {
6
+ colors: {
7
+ ...systemPalette,
8
+ },
9
+ space,
10
+ fontSizes,
11
+ fontWeights,
12
+ lineHeights,
13
+ };
14
+
15
+ type GlobalTheme = typeof globalTheme;
16
+
17
+ export { GlobalTheme };
18
+
19
+ export default globalTheme;
File without changes
@@ -1,11 +1,11 @@
1
1
  const BASE = 16;
2
2
 
3
3
  const fontSizes = {
4
- xlarge: BASE * 1.125, // 18
5
- large: BASE, // 16
6
- medium: BASE * 0.875, // 14
7
- small: BASE * 0.75, // 12
8
- xsmall: BASE * 0.625, // 10
4
+ xlarge: BASE * 1.125, // 18
5
+ large: BASE, // 16
6
+ medium: BASE * 0.875, // 14
7
+ small: BASE * 0.75, // 12
8
+ xsmall: BASE * 0.625, // 10
9
9
  };
10
10
 
11
11
  const fontWeights = {
@@ -1,26 +1,22 @@
1
- import { palette, systemPalette } from './colors';
2
- import { space } from './space';
3
- import { fontSizes, fontWeights, lineHeights } from './typography';
1
+ import globalTheme, { GlobalTheme } from './global';
4
2
 
5
- import { demoStyleColors, demoStyleSpace } from './components/demoStyle';
3
+ import getExampleComponentTheme from './components/exampleComponent';
6
4
 
7
- const theme = {
8
- colors: {
9
- ...palette,
10
- ...systemPalette,
11
- demoStyle: demoStyleColors,
12
- },
13
- space: {
14
- ...space,
15
- demoStyle: demoStyleSpace,
16
- },
17
- fontSizes,
18
- fontWeights,
19
- lineHeights,
5
+ type Theme = GlobalTheme & {
6
+ __hd__: {
7
+ exampleComponent: ReturnType<typeof getExampleComponentTheme>;
8
+ };
20
9
  };
21
10
 
22
- type Theme = typeof theme;
11
+ const getTheme = (theme: GlobalTheme = globalTheme): Theme => ({
12
+ ...theme,
13
+ __hd__: {
14
+ exampleComponent: getExampleComponentTheme(theme),
15
+ },
16
+ });
17
+
18
+ const theme = getTheme();
23
19
 
24
- export { Theme };
20
+ export { Theme, getTheme };
25
21
 
26
22
  export default theme;
package/tsconfig.json CHANGED
@@ -11,7 +11,8 @@
11
11
  "noImplicitReturns": true,
12
12
  "noImplicitThis": true,
13
13
  "noUnusedLocals": true,
14
- "skipLibCheck": true
14
+ "skipLibCheck": true,
15
+ "types": ["jest", "styled-components", "styled-components-react-native"],
15
16
  },
16
17
  "include": [
17
18
  "src"
@@ -1,12 +1,7 @@
1
1
  import { View } from 'react-native';
2
- export interface Props {
3
- boxSize: 'small' | 'medium' | 'large';
4
- boxSpace: 'small' | 'medium' | 'large';
5
- bgColor: 'primary' | 'danger' | 'warning';
6
- }
7
- declare const Square: import("styled-components").StyledComponent<typeof View, any, {
8
- boxSize: Props['boxSize'];
9
- boxSpace: Props['boxSpace'];
10
- bgColor: Props['bgColor'];
2
+ declare const Square: import("styled-components").StyledComponent<typeof View, import("../../theme").Theme, {
3
+ themeSize: 'small' | 'medium' | 'large';
4
+ themeMargin: 'small' | 'medium' | 'large';
5
+ themeBgColor: 'primary' | 'danger' | 'warning';
11
6
  }, never>;
12
7
  export { Square };
@@ -2,15 +2,15 @@ interface Props {
2
2
  /**
3
3
  * Size.
4
4
  */
5
- boxSize: 'small' | 'medium' | 'large';
5
+ size?: 'small' | 'medium' | 'large';
6
6
  /**
7
7
  * Margin.
8
8
  */
9
- boxSpace: 'small' | 'medium' | 'large';
9
+ margin: 'small' | 'medium' | 'large';
10
10
  /**
11
11
  * Background color.
12
12
  */
13
13
  bgColor: 'primary' | 'danger' | 'warning';
14
14
  }
15
- declare const ExampleComponent: ({ boxSize, boxSpace, bgColor }: Props) => JSX.Element;
15
+ declare const ExampleComponent: ({ size, margin, bgColor }: Props) => JSX.Element;
16
16
  export default ExampleComponent;
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ThemeProvider, useTheme } from 'styled-components/native';
2
- import theme from './theme';
1
+ import { ThemeProvider, useTheme } from './styled-components';
2
+ import theme, { getTheme } from './theme';
3
3
  import ExampleComponent from './components/ExampleComponent';
4
- export { theme, useTheme, ThemeProvider, ExampleComponent };
4
+ export { theme, getTheme, useTheme, ThemeProvider, ExampleComponent };
@@ -0,0 +1,6 @@
1
+ /// <reference types="styled-components-react-native" />
2
+ import * as styledComponents from 'styled-components/native';
3
+ import type { Theme } from './theme';
4
+ declare const styled: styledComponents.ReactNativeStyledInterface<Theme>, useTheme: () => Theme, css: import("styled-components").ThemedCssFunction<Theme>, ThemeProvider: import("styled-components").ThemeProviderComponent<Theme, Theme>;
5
+ export { useTheme, css, ThemeProvider };
6
+ export default styled;
@@ -0,0 +1,14 @@
1
+ import { GlobalTheme } from '../global';
2
+ declare const getExampleComponentTheme: (theme: GlobalTheme) => {
3
+ colors: {
4
+ primaryBg: string;
5
+ dangerBg: string;
6
+ warningBg: string;
7
+ };
8
+ space: {
9
+ smallMargin: number;
10
+ mediumMargin: number;
11
+ largeMargin: number;
12
+ };
13
+ };
14
+ export default getExampleComponentTheme;
File without changes
@@ -0,0 +1,58 @@
1
+ declare const globalTheme: {
2
+ colors: {
3
+ primary: string;
4
+ primaryLight: string;
5
+ info: string;
6
+ infoLight: string;
7
+ infoBackground: string;
8
+ success: string;
9
+ successDark: string;
10
+ successLight: string;
11
+ successBackground: string;
12
+ danger: string;
13
+ dangerLight: string;
14
+ dangerBackground: string;
15
+ warning: string;
16
+ warningDark: string;
17
+ warningBackground: string;
18
+ platformBackground: string;
19
+ backgroundDark: string;
20
+ text: string;
21
+ disabledText: string;
22
+ invertedText: string;
23
+ };
24
+ space: {
25
+ xxsmall: number;
26
+ xsmall: number;
27
+ small: number;
28
+ medium: number;
29
+ large: number;
30
+ xlarge: number;
31
+ xxlarge: number;
32
+ xxxlarge: number;
33
+ xxxxlarge: number;
34
+ };
35
+ fontSizes: {
36
+ xlarge: number;
37
+ large: number;
38
+ medium: number;
39
+ small: number;
40
+ xsmall: number;
41
+ };
42
+ fontWeights: {
43
+ light: number;
44
+ regular: number;
45
+ semiBold: number;
46
+ bold: number;
47
+ };
48
+ lineHeights: {
49
+ xlarge: number;
50
+ large: number;
51
+ medium: number;
52
+ small: number;
53
+ xsmall: number;
54
+ };
55
+ };
56
+ declare type GlobalTheme = typeof globalTheme;
57
+ export { GlobalTheme };
58
+ export default globalTheme;
File without changes