-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into typescript-css-prop
- Loading branch information
Showing
6 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "es2015", | ||
"declaration": true, | ||
"strict": true, | ||
"allowSyntheticDefaultImports": true, | ||
"moduleResolution": "node", | ||
"jsx": "react" | ||
}, | ||
"include": [ | ||
"./*.ts", | ||
"./*.tsx" | ||
] | ||
} |
38 changes: 38 additions & 0 deletions
38
packages/emotion-theming/typescript_tests/typescript_tests.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import * as emotionTheming from '../'; | ||
import { ThemeProvider, withTheme, EmotionThemingModule } from '../'; | ||
|
||
const theme = { primary: "green", secondary: "white" }; | ||
const CompSFC = (props: { prop: boolean }) => <div />; | ||
declare class CompC extends React.Component<{ prop: boolean }> { } | ||
|
||
/** | ||
* Theme Provider with no type | ||
*/ | ||
<ThemeProvider theme={theme} />; | ||
<ThemeProvider theme={() => theme} />; | ||
|
||
/** | ||
* withTheme with no type | ||
*/ | ||
const ThemedSFC = withTheme(CompSFC); | ||
<ThemedSFC theme={theme} prop />; | ||
<ThemedSFC prop />; | ||
|
||
const ThemedComp = withTheme(CompC); | ||
<ThemedComp theme={theme} prop />; | ||
<ThemedComp prop /> | ||
|
||
const { ThemeProvider: TypedThemeProvider, withTheme: typedWithTheme } = emotionTheming as EmotionThemingModule<typeof theme>; | ||
|
||
<TypedThemeProvider theme={theme} />; | ||
<TypedThemeProvider theme={{ primary: "white" }} />; | ||
<TypedThemeProvider theme={theme => ({ primary: theme.primary, secondary: theme.secondary })} />; | ||
|
||
const TypedThemedSFC = typedWithTheme(ThemedSFC); | ||
<TypedThemedSFC prop />; | ||
<TypedThemedSFC theme={theme} prop/> | ||
|
||
const TypedCompSFC = typedWithTheme(CompSFC); | ||
<TypedCompSFC prop />; | ||
<TypedCompSFC theme={theme} prop />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ComponentClass, SFC } from "react"; | ||
|
||
export type OptionalThemeProps<Props, Theme> = Props & { theme?: Theme }; | ||
|
||
export interface ThemeProviderProps<Theme> { | ||
theme: Partial<Theme> | { (theme: Theme): Theme }; | ||
} | ||
|
||
export type ThemeProviderComponent<Theme> = ComponentClass<ThemeProviderProps<Theme>>; | ||
export const ThemeProvider: ThemeProviderComponent<object>; | ||
|
||
/** | ||
* Inject theme into component | ||
*/ | ||
export function withTheme<Props, Theme = {}>(component: ComponentClass<Props> | SFC<Props>): ComponentClass<OptionalThemeProps<Props, Theme>>; | ||
|
||
export interface EmotionThemingModule<Theme> { | ||
ThemeProvider: ThemeProviderComponent<Theme>; | ||
withTheme<Props>(component: ComponentClass<Props> | SFC<Props>): ComponentClass<OptionalThemeProps<Props, Theme>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters