@hero-design/rn 6.7.2 → 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.
@@ -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;
@@ -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,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;
@@ -0,0 +1,12 @@
1
+ declare const space: {
2
+ xxsmall: number;
3
+ xsmall: number;
4
+ small: number;
5
+ medium: number;
6
+ large: number;
7
+ xlarge: number;
8
+ xxlarge: number;
9
+ xxxlarge: number;
10
+ xxxxlarge: number;
11
+ };
12
+ export { space };
@@ -0,0 +1,21 @@
1
+ declare const fontSizes: {
2
+ xlarge: number;
3
+ large: number;
4
+ medium: number;
5
+ small: number;
6
+ xsmall: number;
7
+ };
8
+ declare const fontWeights: {
9
+ light: number;
10
+ regular: number;
11
+ semiBold: number;
12
+ bold: number;
13
+ };
14
+ declare const lineHeights: {
15
+ xlarge: number;
16
+ large: number;
17
+ medium: number;
18
+ small: number;
19
+ xsmall: number;
20
+ };
21
+ export { fontSizes, fontWeights, lineHeights };
@@ -1,148 +1,11 @@
1
- declare const theme: {
2
- colors: {
3
- demoStyle: {
4
- primaryBg: string;
5
- dangerBg: string;
6
- warningBg: string;
7
- };
8
- primary: string;
9
- primaryLight: string;
10
- info: string;
11
- infoLight: string;
12
- infoBackground: string;
13
- success: string;
14
- successDark: string;
15
- successLight: string;
16
- successBackground: string;
17
- danger: string;
18
- dangerLight: string;
19
- dangerBackground: string;
20
- warning: string;
21
- warningDark: string;
22
- warningBackground: string;
23
- platformBackground: string;
24
- backgroundDark: string;
25
- text: string;
26
- disabledText: string;
27
- invertedText: string;
28
- black: string;
29
- blue: string;
30
- blueDark30: string;
31
- blueDark75: string;
32
- blueLight30: string;
33
- blueLight75: string;
34
- blueLight90: string;
35
- dodgerBlue: string;
36
- dodgerBlueDark30: string;
37
- dodgerBlueLight30: string;
38
- dodgerBlueLight75: string;
39
- dodgerBlueLight90: string;
40
- green: string;
41
- greenDark15: string;
42
- greenDark30: string;
43
- greenDark75: string;
44
- greenLight30: string;
45
- greenLight90: string;
46
- grey: string;
47
- greyDark15: string;
48
- greyDark30: string;
49
- greyDark45: string;
50
- greyDark60: string;
51
- greyDark75: string;
52
- greyLight45: string;
53
- greyLight60: string;
54
- greyLight75: string;
55
- greyLight85: string;
56
- greyLight90: string;
57
- greyLight95: string;
58
- grotesqueGreen: string;
59
- grotesqueGreenDark45: string;
60
- grotesqueGreenLight60: string;
61
- grotesqueGreenLight75: string;
62
- grotesqueGreenLight90: string;
63
- orange: string;
64
- orangeDark15: string;
65
- orangeDark30: string;
66
- orangeDark75: string;
67
- orangeLight30: string;
68
- orangeLight75: string;
69
- orangeLight90: string;
70
- pink: string;
71
- pinkDark15: string;
72
- pinkDark30: string;
73
- pinkDark45: string;
74
- pinkDark75: string;
75
- pinkLight30: string;
76
- pinkLight45: string;
77
- pinkLight75: string;
78
- pinkLight90: string;
79
- purple: string;
80
- red: string;
81
- redDark15: string;
82
- redDark30: string;
83
- redDark75: string;
84
- redLight30: string;
85
- redLight60: string;
86
- redLight75: string;
87
- redLight90: string;
88
- smalt: string;
89
- smaltDark75: string;
90
- smaltLight30: string;
91
- smaltLight45: string;
92
- smaltLight90: string;
93
- violet: string;
94
- violetDark15: string;
95
- violetDark30: string;
96
- violetDark45: string;
97
- violetDark75: string;
98
- violetLight30: string;
99
- violetLight60: string;
100
- violetLight75: string;
101
- violetLight90: string;
102
- white: string;
103
- yellow: string;
104
- yellowDark15: string;
105
- yellowDark75: string;
106
- yellowLight60: string;
107
- yellowLight90: string;
108
- };
109
- space: {
110
- demoStyle: {
111
- smallMargin: number;
112
- mediumMargin: number;
113
- largeMargin: number;
114
- };
115
- xxsmall: number;
116
- xsmall: number;
117
- small: number;
118
- medium: number;
119
- large: number;
120
- xlarge: number;
121
- xxlarge: number;
122
- xxxlarge: number;
123
- xxxxlarge: number;
124
- };
125
- fontSizes: {
126
- xlarge: number;
127
- large: number;
128
- medium: number;
129
- small: number;
130
- xsmall: number;
131
- };
132
- fontWeights: {
133
- light: number;
134
- regular: number;
135
- semiBold: number;
136
- bold: number;
137
- };
138
- lineHeights: {
139
- xlarge: number;
140
- large: number;
141
- medium: number;
142
- small: number;
143
- xsmall: number;
1
+ import { GlobalTheme } from './global';
2
+ import getExampleComponentTheme from './components/exampleComponent';
3
+ declare type Theme = GlobalTheme & {
4
+ __hd__: {
5
+ exampleComponent: ReturnType<typeof getExampleComponentTheme>;
144
6
  };
145
7
  };
146
- declare type Theme = typeof theme;
147
- export { Theme };
8
+ declare const getTheme: (theme?: GlobalTheme) => Theme;
9
+ declare const theme: Theme;
10
+ export { Theme, getTheme };
148
11
  export default theme;