@hero-design/rn 6.7.0 → 6.7.3

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/package.json CHANGED
@@ -1,20 +1,22 @@
1
1
  {
2
2
  "name": "@hero-design/rn",
3
- "version": "6.7.0",
3
+ "version": "6.7.3",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
7
+ "types": "types/index.d.ts",
7
8
  "scripts": {
8
- "lint": "eslint src --ext .js,.jsx,.ts,.tsx --ignore-path ../../.gitignore",
9
+ "lint": "eslint src playground --ext .js,.jsx,.ts,.tsx --ignore-path ../../.gitignore",
9
10
  "type-check": "tsc --noEmit",
10
11
  "dev": "expo start",
11
12
  "test": "jest --runInBand",
12
13
  "build:js": "rollup -c",
13
14
  "build:types": "tsc --noEmit false --emitDeclarationOnly",
14
- "build": "yarn build:js && yarn build:types"
15
+ "build": "yarn build:js && yarn build:types",
16
+ "publish:npm": "yarn publish --access public"
15
17
  },
16
18
  "dependencies": {
17
- "@hero-design/colors": "^6.7.0",
19
+ "@hero-design/colors": "6.7.3",
18
20
  "styled-components": "6.0.0-alpha.5"
19
21
  },
20
22
  "peerDependencies": {
@@ -26,6 +28,8 @@
26
28
  "@babel/preset-env": "^7.16.11",
27
29
  "@babel/preset-react": "^7.16.7",
28
30
  "@babel/preset-typescript": "^7.16.7",
31
+ "@react-navigation/native": "^6.0.10",
32
+ "@react-navigation/native-stack": "^6.6.2",
29
33
  "@rollup/plugin-babel": "^5.3.1",
30
34
  "@rollup/plugin-commonjs": "^21.0.1",
31
35
  "@rollup/plugin-json": "^4.1.0",
@@ -54,6 +58,8 @@
54
58
  "prettier": "^2.5.1",
55
59
  "react": "17.0.2",
56
60
  "react-native": "0.65.1",
61
+ "react-native-safe-area-context": "^4.2.5",
62
+ "react-native-screens": "^3.13.1",
57
63
  "react-test-renderer": "17.0.2",
58
64
  "rollup": "^2.68.0",
59
65
  "ts-jest": "^27.0.7",
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { ExampleComponent } from '../../src/index';
3
+
4
+ const ExampleComponentPlayground = () => (
5
+ <ExampleComponent size="large" margin="large" bgColor="primary" />
6
+ );
7
+
8
+ export default ExampleComponentPlayground;
@@ -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;
@@ -1,3 +1,26 @@
1
- import { palette, systemPalette } from '@hero-design/colors';
1
+ import { palette } from '@hero-design/colors';
2
+
3
+ const systemPalette = {
4
+ primary: palette.violet,
5
+ primaryLight: palette.violetLight60,
6
+ info: palette.dodgerBlue,
7
+ infoLight: palette.dodgerBlueLight75,
8
+ infoBackground: palette.dodgerBlueLight90,
9
+ success: palette.green,
10
+ successDark: palette.greenDark30,
11
+ successLight: palette.greenDark75,
12
+ successBackground: palette.grotesqueGreenLight90,
13
+ danger: palette.red,
14
+ dangerLight: palette.redLight60,
15
+ dangerBackground: palette.redLight90,
16
+ warning: palette.orange,
17
+ warningDark: palette.orangeDark15,
18
+ warningBackground: palette.orangeLight90,
19
+ platformBackground: palette.greyLight95,
20
+ backgroundDark: palette.greyDark75,
21
+ text: palette.greyDark75,
22
+ disabledText: palette.greyDark15,
23
+ invertedText: palette.white,
24
+ };
2
25
 
3
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;
@@ -0,0 +1,26 @@
1
+ const BASE = 16;
2
+
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
9
+ };
10
+
11
+ const fontWeights = {
12
+ light: 200,
13
+ regular: 400,
14
+ semiBold: 600,
15
+ bold: 700,
16
+ };
17
+
18
+ const lineHeights = {
19
+ xlarge: fontSizes.xlarge + 8,
20
+ large: fontSizes.large + 8,
21
+ medium: fontSizes.medium + 8,
22
+ small: fontSizes.small + 8,
23
+ xsmall: fontSizes.xsmall + 8,
24
+ };
25
+
26
+ export { fontSizes, fontWeights, lineHeights };
@@ -1,22 +1,22 @@
1
- import { palette, systemPalette } from './global/colors';
2
- import { space } from './global/space';
1
+ import globalTheme, { GlobalTheme } from './global';
3
2
 
4
- import { demoStyleColors, demoStyleSpace } from './components/demoStyle';
3
+ import getExampleComponentTheme from './components/exampleComponent';
5
4
 
6
- const theme = {
7
- colors: {
8
- ...palette,
9
- ...systemPalette,
10
- demoStyle: demoStyleColors,
11
- },
12
- space: {
13
- ...space,
14
- demoStyle: demoStyleSpace,
15
- },
5
+ type Theme = GlobalTheme & {
6
+ __hd__: {
7
+ exampleComponent: ReturnType<typeof getExampleComponentTheme>;
8
+ };
16
9
  };
17
10
 
18
- 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();
19
19
 
20
- export { Theme };
20
+ export { Theme, getTheme };
21
21
 
22
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,24 @@
1
+ import { palette } from '@hero-design/colors';
2
+ declare const systemPalette: {
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
+ export { palette, systemPalette };
@@ -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;
@@ -1,2 +1,24 @@
1
- import { palette, systemPalette } from '@hero-design/colors';
1
+ import { palette } from '@hero-design/colors';
2
+ declare const systemPalette: {
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
+ };
2
24
  export { palette, systemPalette };