File tree Expand file tree Collapse file tree 4 files changed +42
-22
lines changed Expand file tree Collapse file tree 4 files changed +42
-22
lines changed Original file line number Diff line number Diff line change 1
1
export { default as defaultTheme } from './src/default-theme'
2
- export { ThemeProvider , ThemeConsumer } from './src/ThemeContext'
3
- export { default as withTheme } from './src/withTheme'
2
+ export { ThemeProvider , ThemeConsumer , Theme } from './src/ThemeContext'
3
+ export { withTheme } from './src/withTheme'
Original file line number Diff line number Diff line change 1
1
import React from 'react'
2
2
import defaultTheme from './default-theme'
3
3
4
+ export interface Theme {
5
+ getCodeProps : ( appearance : 'default' | 'minimal' ) => any
6
+ getFontFamily : ( fontFamily ?: string ) => string
7
+ getHeadingStyle : ( size ?: number ) => any
8
+ getLinkClassName : ( color ?: string ) => string
9
+ getParagraphStyle : ( size ?: number ) => any
10
+ getTextColor : ( colorAlias ?: string ) => string
11
+ getTextStyle : ( size ?: number ) => any
12
+ }
13
+
4
14
/**
5
15
* Use React 16.3+ createContext API.
6
16
*/
7
17
const {
8
18
Provider : ThemeProvider ,
9
19
Consumer : ThemeConsumer
10
- } = React . createContext ( defaultTheme )
20
+ } = React . createContext < Theme > ( defaultTheme )
11
21
12
22
export { ThemeProvider , ThemeConsumer }
Original file line number Diff line number Diff line change 1
1
import React from 'react'
2
- import { ThemeConsumer } from './ThemeContext'
2
+ import { ThemeConsumer , Theme } from './ThemeContext'
3
3
4
- type Omit < T , K > = Pick < T , Exclude < keyof T , K > >
4
+ type Difference < T , K > = Pick < T , Exclude < keyof T , keyof K > >
5
5
6
6
interface WithThemeProps {
7
- // TODO: type this
8
- theme : object
7
+ /**
8
+ * The theme context from the ThemeProvider
9
+ */
10
+ theme : Theme
9
11
}
10
12
11
13
/**
12
14
* HOC that injects the `theme` from the ThemeConsumer into the wrapper component.
13
15
*/
14
- export default function withTheme < P extends WithThemeProps > ( Component : React . ComponentType < P > ) {
15
- const displayName =
16
- Component . displayName || Component . name || 'Component'
16
+ export function withTheme < P extends WithThemeProps > (
17
+ Component : React . ComponentType < P >
18
+ ) : React . ComponentClass < Difference < P , WithThemeProps > , { } > {
19
+ const displayName = Component . displayName || Component . name || 'Component'
17
20
18
- return class WithTheme extends React . Component < Omit < P , keyof WithThemeProps > > {
21
+ return class WithTheme extends React . Component <
22
+ Difference < P , WithThemeProps >
23
+ > {
19
24
static displayName = `withTheme(${ displayName } )`
20
25
21
26
render ( ) {
Original file line number Diff line number Diff line change 1
1
import React , { PureComponent } from 'react'
2
2
import Box from 'ui-box'
3
- import { withTheme } from '../../theme'
4
-
5
- interface Theme {
6
- getTextStyle : ( size ?: number ) => any
7
- getTextColor : ( colorAlias ?: string ) => string
8
- getFontFamily : ( fontFamily ?: string ) => string
9
- }
3
+ import { withTheme , Theme } from '../../theme'
10
4
11
5
interface TextProps {
12
- /** The color (alias or valid color) applied to the text */
6
+ /**
7
+ * The color (alias or valid color) applied to the text
8
+ */
13
9
color ?: string
14
- /** The font family alias applied to the text */
10
+
11
+ /**
12
+ * The font family alias applied to the text
13
+ */
15
14
fontFamily ?: 'ui' | 'display' | 'mono'
16
- /** The size of the text style */
15
+
16
+ /**
17
+ * The size of the text style
18
+ */
17
19
size ?: 300 | 400 | 500 | 600
18
- /** Theme provided by ThemeProvider. */
20
+
21
+ /**
22
+ * Theme provided by ThemeProvider.
23
+ */
19
24
theme : Theme
20
25
}
21
26
You can’t perform that action at this time.
0 commit comments