-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Theming improvement #1662
Theming improvement #1662
Conversation
e359da7
to
31a1a16
Compare
8971cf5
to
b55b770
Compare
90c256e
to
b55b770
Compare
Working on it @oliviertassinari . |
@shaurya947 I can see this :p. You don't need to close the PR. A |
@oliviertassinari I ran into some issues initially and I ranted about those on SO. Due to the process I had to follow (which was essentially a rebase but involved merging my Still getting used to troubleshooting git issues ^_^ |
@oliviertassinari should be good now. |
@shaurya947 Nice 👍 |
Raw Theme is made up of spacing, palette, and font family, whereas MUI theme is made of key:value pairs, each of which represents the styling of a material-ui component based on the given raw theme. In addition, the MUI theme also contains a reference to the raw theme from which it was produced. In every material-ui component, the "state" is used for the theme, and theme is passed down using context. Within the component, theme is always accessed using state. When a component is first mounted, we check whether a theme object is passed down using context in the getInitialState() method. If one is not found, we initialize a default MUI theme based on the default (light) raw theme. Moreover, to listen for updates when the parent changes the theme, the new context is always checked in componentWillReceiveProps(). Now, the ThemeManager module simply contains functions that return new MUI theme objects (support for immutability). The theme itself (raw theme) is a plain JS object containing key:value pairs for spacing, palette, and font family. Users can easily define their own raw themes and require() them in their modules.
Simplified theme wrapper component to be used as another way to pass down theme. Currently, there are some issues regarding owner-based vs parent-based contexts when using the theme wrapper. Hopefully, these will go away with React 0.14
Fixed unit tests to use new theming code.
Modified primary1Color of dark-raw-theme to Colors.grey500
60d4c14
to
438f6b2
Compare
Now, `textTransform` can be applied to all buttons (both `FlatButton` and `RaisedButton`), only `FlatButton`, or only `RaisedButton` on a theme-level. Here is how: ```js let newMuiTheme = ThemeManager.getMuiTheme(LightRawTheme); //override theme variable for button //this override will apply to both FlatButton and RaisedButton newMuiTheme.button.textTransform = 'none'; ``` ```js let newMuiTheme = ThemeManager.getMuiTheme(LightRawTheme); //override theme variable for only RaisedButton or FlatButton (substitute accordingly) newMuiTheme.raisedButton.textTransform = 'none'; ``` `textTransform` corresponds to the CSS `text-transform` property and can take any valid value that the CSS property can take. Related to mui#1576
Re-doing themes for version 0.12:
spacing
,palette
andfontFamily
. The material-ui theme is a much bigger object, and is produced based on the raw theme. It contains a key for every material-ui component, and the corresponding value describes how that component is going to look under that particular theme. The material-ui theme also contains a reference to the raw theme object from which it was produced.ThemeManager
module has been modified. Now, it contains only the following functions that return a material-ui (mui) theme object:getMuiTheme (rawTheme)
: this function takes in a raw theme object and returns the mui theme produced from it.modifyRawThemeSpacing (muiTheme, newSpacing)
,modifyRawThemePalette (muiTheme, newPaletteKeys)
andmodifyRawThemeFontFamily (muiTheme, newFontFamily)
: these three functions are provided as modifiers for the raw theme. They take in the current mui theme object and the new information to be updated, and return a new, re-computed mui theme object. Providing these modifiers separately is an effort to keep the mui theme object immutable throughout the application.this.state.muiTheme
. Reset the theme usingthis.setState()
. This is consistent with the immutability approach as react components re-render whenever the state changes.lib/styles/raw-themes
. Custom raw themes may be defined in a similar manner.getInitialState()
: the context is checked for a theme object here. If no theme is found, a default theme is applied.contextTypes
: to indicate that anmuiTheme
object is expected from the parent.childContextTypes
: to indicate that anmuiTheme
object will be passed down to children.getChildContext()
: to pass down themuiTheme
object to the children.componentWillReceiveProps(nextProps, nextContext)
: every time a new theme is passed down through the context, this method updates the state of the component with the new theme.ThemeDecorator
module can be used to decorate (ES7-style decorators) the app component. These are the two ways that we recommend that you go about theming for now.class
keyword that extendsReact.Component
(as opposed to usingReact.createClass
).