-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: mui-themeable higher order component #2493
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import React from 'react'; | ||
import DefaultRawTheme from './styles/raw-themes/light-raw-theme'; | ||
import ThemeManager from './styles/theme-manager'; | ||
import muiThemeable from './mui-themeable'; | ||
import styleUtils from './utils/styles'; | ||
|
||
const propTypes = { | ||
|
@@ -20,19 +19,11 @@ const propTypes = { | |
style: React.PropTypes.object, | ||
}; | ||
|
||
const contextTypes = { | ||
muiTheme: React.PropTypes.object, | ||
}; | ||
|
||
const childContextTypes = { | ||
muiTheme: React.PropTypes.object, | ||
}; | ||
|
||
const defaultProps = { | ||
inset: false, | ||
}; | ||
|
||
const Divider = ({inset, style, ...other}, {muiTheme = ThemeManager.getMuiTheme(DefaultRawTheme)}) => { | ||
let Divider = ({inset, muiTheme, style, ...other}) => { | ||
const styles = { | ||
root: { | ||
margin: 0, | ||
|
@@ -49,9 +40,9 @@ const Divider = ({inset, style, ...other}, {muiTheme = ThemeManager.getMuiTheme( | |
); | ||
}; | ||
|
||
Divider.displayName = 'Divider'; | ||
Divider.propTypes = propTypes; | ||
Divider.defaultProps = defaultProps; | ||
Divider.contextTypes = contextTypes; | ||
Divider.childContextTypes = childContextTypes; | ||
Divider = muiThemeable(Divider); | ||
|
||
export default Divider; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could just write export default muiThemeable(Divider); to keep Divider a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried that originally (and wanted to keep it as const)! But I think our eslinter didn't like that for some reason...let me try again and get the actual error There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My mistake, not an eslint error, there is a runtime error saying Will have to investigate this as well. |
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; |
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will have no name, please add a displayName member 😁