-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
bd4b46b
commit b99fcab
Showing
2 changed files
with
164 additions
and
154 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,158 +1,9 @@ | ||
// @flow weak | ||
import { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { create } from 'jss'; | ||
import { createStyleManager } from 'jss-theme-reactor/styleManager'; | ||
import jssPreset from 'jss-preset-default'; | ||
import createMuiTheme from './theme'; | ||
import muiThemeProviderFactory, { | ||
MUI_SHEET_ORDER as muiSheetOrder, | ||
} from './muiThemeProviderFactory'; | ||
|
||
export const MUI_SHEET_ORDER = [ | ||
'MuiTextarea', | ||
'MuiInput', | ||
'MuiGrid', | ||
'MuiCollapse', | ||
'MuiFade', | ||
'MuiSlide', | ||
export const MUI_SHEET_ORDER = muiSheetOrder; | ||
|
||
'MuiBackdrop', | ||
'MuiModal', | ||
|
||
'MuiRipple', | ||
'MuiTouchRipple', | ||
|
||
'MuiButtonBase', | ||
|
||
'MuiFormLabel', | ||
'MuiFormGroup', | ||
|
||
'MuiTypography', | ||
'MuiPaper', | ||
'MuiDivider', | ||
|
||
'MuiPopover', | ||
|
||
'MuiButton', | ||
'MuiIconButton', | ||
|
||
'MuiSvgIcon', | ||
'MuiIcon', | ||
|
||
'MuiSwitchBase', | ||
'MuiSwitch', | ||
'MuiCheckbox', | ||
'MuiRadio', | ||
'MuiRadioGroup', | ||
'MuiSwitchLabel', | ||
|
||
'MuiDialog', | ||
'MuiDialogActions', | ||
'MuiDialogContent', | ||
'MuiDialogContentText', | ||
'MuiDialogTitle', | ||
|
||
'MuiTabIndicator', | ||
'MuiTab', | ||
'MuiTabs', | ||
|
||
'MuiBottomNavigationButton', | ||
'MuiBottomNavigation', | ||
|
||
'MuiCircularProgress', | ||
'MuiLinearProgress', | ||
|
||
'MuiAppBar', | ||
'MuiDrawer', | ||
|
||
'MuiAvatar', | ||
|
||
'MuiChip', | ||
|
||
'MuiListItem', | ||
'MuiListItemText', | ||
'MuiListItemSecondaryAction', | ||
'MuiListItemAvatar', | ||
'MuiListItemIcon', | ||
'MuiListSubheader', | ||
'MuiList', | ||
|
||
'MuiMenu', | ||
'MuiMenuItem', | ||
|
||
'MuiCardContent', | ||
'MuiCardMedia', | ||
'MuiCardActions', | ||
'MuiCardHeader', | ||
'MuiCard', | ||
|
||
'MuiTextFieldLabel', | ||
'MuiTextFieldInput', | ||
'MuiTextField', | ||
|
||
'MuiTable', | ||
'MuiTableHead', | ||
'MuiTableRow', | ||
'MuiTableCell', | ||
'MuiTableBody', | ||
'MuiTableSortLabel', | ||
'MuiToolbar', | ||
|
||
'MuiBadge', | ||
]; | ||
|
||
export default class MuiThemeProvider extends Component { | ||
static propTypes = { | ||
children: PropTypes.element.isRequired, | ||
styleManager: PropTypes.object, | ||
theme: PropTypes.object, | ||
}; | ||
|
||
static childContextTypes = { | ||
styleManager: PropTypes.object.isRequired, | ||
}; | ||
|
||
static createDefaultContext(props = {}) { | ||
const theme = props.theme || createMuiTheme(); | ||
const styleManager = | ||
props.styleManager || | ||
createStyleManager({ | ||
theme, | ||
jss: create(jssPreset()), | ||
}); | ||
|
||
if (!styleManager.sheetOrder) { | ||
styleManager.setSheetOrder(MUI_SHEET_ORDER); | ||
} | ||
|
||
return { theme, styleManager }; | ||
} | ||
|
||
getChildContext() { | ||
return { | ||
styleManager: this.styleManager, | ||
}; | ||
} | ||
|
||
componentWillMount() { | ||
const { theme, styleManager } = MuiThemeProvider.createDefaultContext(this.props); | ||
this.theme = theme; | ||
this.styleManager = styleManager; | ||
} | ||
|
||
componentWillUpdate(nextProps) { | ||
if (this.styleManager !== nextProps.styleManager) { | ||
const { theme, styleManager } = MuiThemeProvider.createDefaultContext(nextProps); | ||
this.theme = theme; | ||
this.styleManager = styleManager; | ||
} else if (this.theme && nextProps.theme && nextProps.theme !== this.theme) { | ||
this.theme = nextProps.theme; | ||
this.styleManager.updateTheme(this.theme); | ||
} | ||
} | ||
|
||
theme = undefined; | ||
styleManager = undefined; | ||
|
||
render() { | ||
return this.props.children; | ||
} | ||
} | ||
export default muiThemeProviderFactory(createMuiTheme()); |
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,159 @@ | ||
// @flow weak | ||
import { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { create } from 'jss'; | ||
import { createStyleManager } from 'jss-theme-reactor/styleManager'; | ||
import jssPreset from 'jss-preset-default'; | ||
|
||
export const MUI_SHEET_ORDER = [ | ||
'MuiTextarea', | ||
'MuiInput', | ||
'MuiGrid', | ||
'MuiCollapse', | ||
'MuiFade', | ||
'MuiSlide', | ||
|
||
'MuiBackdrop', | ||
'MuiModal', | ||
|
||
'MuiRipple', | ||
'MuiTouchRipple', | ||
|
||
'MuiButtonBase', | ||
|
||
'MuiFormLabel', | ||
'MuiFormGroup', | ||
|
||
'MuiTypography', | ||
'MuiPaper', | ||
'MuiDivider', | ||
|
||
'MuiPopover', | ||
|
||
'MuiButton', | ||
'MuiIconButton', | ||
|
||
'MuiSvgIcon', | ||
'MuiIcon', | ||
|
||
'MuiSwitchBase', | ||
'MuiSwitch', | ||
'MuiCheckbox', | ||
'MuiRadio', | ||
'MuiRadioGroup', | ||
'MuiSwitchLabel', | ||
|
||
'MuiDialog', | ||
'MuiDialogActions', | ||
'MuiDialogContent', | ||
'MuiDialogContentText', | ||
'MuiDialogTitle', | ||
|
||
'MuiTabIndicator', | ||
'MuiTab', | ||
'MuiTabs', | ||
|
||
'MuiBottomNavigationButton', | ||
'MuiBottomNavigation', | ||
|
||
'MuiCircularProgress', | ||
'MuiLinearProgress', | ||
|
||
'MuiAppBar', | ||
'MuiDrawer', | ||
|
||
'MuiAvatar', | ||
|
||
'MuiChip', | ||
|
||
'MuiListItem', | ||
'MuiListItemText', | ||
'MuiListItemSecondaryAction', | ||
'MuiListItemAvatar', | ||
'MuiListItemIcon', | ||
'MuiListSubheader', | ||
'MuiList', | ||
|
||
'MuiMenu', | ||
'MuiMenuItem', | ||
|
||
'MuiCardContent', | ||
'MuiCardMedia', | ||
'MuiCardActions', | ||
'MuiCardHeader', | ||
'MuiCard', | ||
|
||
'MuiTextFieldLabel', | ||
'MuiTextFieldInput', | ||
'MuiTextField', | ||
|
||
'MuiTable', | ||
'MuiTableHead', | ||
'MuiTableRow', | ||
'MuiTableCell', | ||
'MuiTableBody', | ||
'MuiTableSortLabel', | ||
'MuiToolbar', | ||
|
||
'MuiBadge', | ||
]; | ||
|
||
export default function muiThemeProviderFactory(defaultTheme) { | ||
return class MuiThemeProvider extends Component { | ||
static propTypes = { | ||
children: PropTypes.element.isRequired, | ||
styleManager: PropTypes.object, | ||
theme: PropTypes.object, | ||
}; | ||
|
||
static childContextTypes = { | ||
styleManager: PropTypes.object.isRequired, | ||
}; | ||
|
||
static createDefaultContext(props = {}) { | ||
const theme = props.theme || defaultTheme; | ||
const styleManager = | ||
props.styleManager || | ||
createStyleManager({ | ||
theme, | ||
jss: create(jssPreset()), | ||
}); | ||
|
||
if (!styleManager.sheetOrder) { | ||
styleManager.setSheetOrder(MUI_SHEET_ORDER); | ||
} | ||
|
||
return { theme, styleManager }; | ||
} | ||
|
||
getChildContext() { | ||
return { | ||
styleManager: this.styleManager, | ||
}; | ||
} | ||
|
||
componentWillMount() { | ||
const { theme, styleManager } = MuiThemeProvider.createDefaultContext(this.props); | ||
this.theme = theme; | ||
this.styleManager = styleManager; | ||
} | ||
|
||
componentWillUpdate(nextProps) { | ||
if (this.styleManager !== nextProps.styleManager) { | ||
const { theme, styleManager } = MuiThemeProvider.createDefaultContext(nextProps); | ||
this.theme = theme; | ||
this.styleManager = styleManager; | ||
} else if (this.theme && nextProps.theme && nextProps.theme !== this.theme) { | ||
this.theme = nextProps.theme; | ||
this.styleManager.updateTheme(this.theme); | ||
} | ||
} | ||
|
||
theme = undefined; | ||
styleManager = undefined; | ||
|
||
render() { | ||
return this.props.children; | ||
} | ||
}; | ||
} |