diff --git a/src/framework/theme/index.ts b/src/framework/theme/index.ts index 0658c0b57..73b094ef1 100644 --- a/src/framework/theme/index.ts +++ b/src/framework/theme/index.ts @@ -1 +1,5 @@ export const description = '@rk-kit/theme'; +import getThemeProvider from './primitives/themeProvider'; +import withTheme from './primitives/themeConsumer'; + +export {getThemeProvider, withTheme}; \ No newline at end of file diff --git a/src/framework/theme/primitives/createContext.ts b/src/framework/theme/primitives/createContext.ts new file mode 100644 index 000000000..c5ab54f63 --- /dev/null +++ b/src/framework/theme/primitives/createContext.ts @@ -0,0 +1,5 @@ +import React from 'react'; + +const {Consumer, Provider} = React.createContext({}); + +export {Consumer, Provider}; \ No newline at end of file diff --git a/src/framework/theme/primitives/themeConsumer.tsx b/src/framework/theme/primitives/themeConsumer.tsx new file mode 100644 index 000000000..c8bb47fa5 --- /dev/null +++ b/src/framework/theme/primitives/themeConsumer.tsx @@ -0,0 +1,14 @@ +import React from 'react'; +import {Consumer} from './createContext'; + +function withTheme(Component) { + return ( + + {theme => { + return React.cloneElement(Component, {theme}); + }} + + ) +} + +export default withTheme; \ No newline at end of file diff --git a/src/framework/theme/primitives/themeProvider.tsx b/src/framework/theme/primitives/themeProvider.tsx new file mode 100644 index 000000000..fa939e45a --- /dev/null +++ b/src/framework/theme/primitives/themeProvider.tsx @@ -0,0 +1,26 @@ +import React from 'react'; +import {Provider} from './createContext'; + +interface PropsType { + children: JSX.Element, + theme: Object +} + +function getThemeProvider() { + return class ThemeProvider extends React.PureComponent { + + static defaultProps = { + theme: {} + }; + + render() { + return ( + + {this.props.children} + + ) + } + } +} + +export default getThemeProvider; \ No newline at end of file