Define colors only in themes.
Define fonts only in themes.
// bad
export default withStyles(() => ({
towerOfPisa: {
fontStyle: 'italic',
},
}))(MyComponent);
// good
export default withStyles(({ font }) => ({
towerOfPisa: {
fontStyle: font.italic,
},
}))(MyComponent);
Define fonts as sets of related styles.
// bad
export default withStyles(() => ({
towerOfPisa: {
fontFamily: 'Italiana, "Times New Roman", serif',
fontSize: '2em',
fontStyle: 'italic',
lineHeight: 1.5,
},
}))(MyComponent);
// good
export default withStyles(({ font }) => ({
towerOfPisa: {
}))(MyComponent);
Define base grid units in theme (either as a value or a function that takes a multiplier).
// bad
export default withStyles(() => ({
rip: {
bottom: '-6912px', // 6 feet
},
}))(MyComponent);
// good
export default withStyles(({ units }) => ({
rip: {
bottom: units(864), // 6 feet, assuming our unit is 8px
},
}))(MyComponent);
// good
export default withStyles(({ unit }) => ({
rip: {
bottom: 864 * unit, // 6 feet, assuming our unit is 8px
},
}))(MyComponent);
Define media queries only in themes.
},
}))(MyComponent);// good
export default withStyles(({ breakpoint }) => ({
container: {width: '100%',
[breakpoint.medium]: {
width: '50%',
},
},
}))(MyComponent);
[fallbacks.display]: 'table',
},
}))(MyComponent);
// good
export default withStyles(({ fallback }) => ({
.muscles {
display: 'flex',
},
.muscles_fallback {
[fallback('display')]: 'table',
},
}))(MyComponent);
```
Create as few custom themes as possible. Many applications may only have one theme.
Namespace custom theme settings under a nested object with a unique and descriptive key.
// bad
ThemedStyleSheet.registerTheme('mySection', {
mySectionPrimaryColor: 'green',
});
// good
ThemedStyleSheet.registerTheme('mySection', {
mySection: {
primaryColor: 'green',
},