You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you are already familiar with native-base, just skip this part.
I was theming native-base yesterday and I thought it would be great if we can do something like that in MUI. Theming in native-base is quite similar to MUI in terms of the structure. It has global theme that will be injected using StyleProvider and connectStyle (= withStyles in MUI) to component that we want to customize. For example,
// In CustomComponent.jsconststyles={container: {flex: 1,backgroundColor: 'green',},textContent: {fontSize: 20,color: 'red',},};classCustomComponentextendsComponent{render(){// connect styles to props.style defined by the themeconststyles=this.props.style;return(<Viewstyle={styles.container}><Textstyle={styles.textContent}>
Your Component with static style
</Text></View>);}}// connect the component to the themeexportdefaultconnectStyle('yourTheme.CustomComponent',styles)(CustomComponent);
// In App.jsimport{Text,StyleProvider}from'native-base';importgetThemefrom'./native-base-theme/components';importmaterialfrom'./native-base-theme/variables/material';
exportdefaultclassThemeExampleextendsComponent{render(){return(<StyleProviderstyle={getTheme(material)}><Text>
I have changed the text color.
</Text></StyleProvider>);}}
Here!
StyleProvider = MuiThemeProvider
ConnectStyle = withStyles
styles = classes
This is what we can do when we want to customize a text inside NativeBaseCard
functionCustomComponent(){return(<Cardcustom1><CardItem><Text></Text></CardItem></Card>);}consttheme={'NativeBaseCard': {'.custom1': {// any style you want to apply// only affect to <Card custom1> and its children'NativeBaseText': {color: '#e5e5e5',}}}}
This is not a v0.x issue.
I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior 🤔
What if MUI is able to reference nested component inside the parent, I think it would be really nice and we can completely separate logic and styles in the component.
We have to use withStyles and write a lot of code. Not clean due to classes inside the component. I don't mean that withStyles is not important, it is very important. If the approach I suggest is possible, withStyles will be use when we want to create new component. For example,
constCustomComponent=withStyles({card: {},// default custom style in cardcardItem: {},// default custom style in card item},'CustomComponent',)(({ classes })=>(<CardclassName={classes.card}><CardItemclassName={classes.cardItem}><Typography></Typography></CardItem></Card>))// and then,// if you want to reuse CustomComponent in another project// override in global theme hereconsttheme={CustomComponent: {MuiCard: {root: {},},MuiTypography: {root: {},}}}
The text was updated successfully, but these errors were encountered:
@siriwatknp Thank you for linking NativeBase system. I don't think that we should reimplement CSS cascading in JavaScript, I think that it's better to rely on Cascading Style Sheets.
Intro
If you are already familiar with native-base, just skip this part.
I was theming native-base yesterday and I thought it would be great if we can do something like that in MUI. Theming in native-base is quite similar to MUI in terms of the structure. It has global theme that will be injected using StyleProvider and connectStyle (= withStyles in MUI) to component that we want to customize. For example,
Here!
This is what we can do when we want to customize a text inside NativeBaseCard
Expected Behavior 🤔
What if MUI is able to reference nested component inside the parent, I think it would be really nice and we can completely separate logic and styles in the component.
Current Behavior 😯
We have to use withStyles and write a lot of code. Not clean due to
classes
inside the component. I don't mean thatwithStyles
is not important, it is very important. If the approach I suggest is possible,withStyles
will be use when we want to create new component. For example,The text was updated successfully, but these errors were encountered: