-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created mui-themeable higher order component to wrap theme passing th…
…rough context
- Loading branch information
Showing
3 changed files
with
52 additions
and
13 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,25 @@ | ||
import {Component, PropTypes} from 'react'; | ||
|
||
class ThemeProvider extends Component { | ||
|
||
static propTypes = { | ||
children: PropTypes.element, | ||
muiTheme: PropTypes.object, | ||
}; | ||
|
||
static childContextTypes = { | ||
muiTheme: PropTypes.object, | ||
}; | ||
|
||
getChildContext() { | ||
return { | ||
muiTheme: this.props.muiTheme, | ||
}; | ||
} | ||
|
||
render() { | ||
return this.props.children; | ||
} | ||
} | ||
|
||
export default ThemeProvider; |
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,23 @@ | ||
import React from 'react'; | ||
import DefaultRawTheme from './styles/raw-themes/light-raw-theme'; | ||
import ThemeManager from './styles/theme-manager'; | ||
|
||
function getDisplayName(WrappedComponent) { | ||
return WrappedComponent.displayName || WrappedComponent.name || 'Component'; | ||
} | ||
|
||
export default function muiThemeable(WrappedComponent) { | ||
const MuiComponent = (props, {muiTheme = ThemeManager.getMuiTheme(DefaultRawTheme)}) => { | ||
return <WrappedComponent {...props} muiTheme={muiTheme} />; | ||
}; | ||
|
||
MuiComponent.displayName = getDisplayName(WrappedComponent); | ||
MuiComponent.contextTypes = { | ||
muiTheme: React.PropTypes.object, | ||
}; | ||
MuiComponent.childContextTypes = { | ||
muiTheme: React.PropTypes.object, | ||
}; | ||
|
||
return MuiComponent; | ||
} |