我试图将Material UI仪表板转换为TypeScript。 https://github.com/mui-org/material-ui/blob/master/docs/src/pages/page-layout-examples/dashboard/Dashboard.js
当前,我面临的问题是在导出仪表板时,无法在withStyles函数上设置CSS样式定义。
const styles = (theme: Theme) => ({
root: {
display: 'flex',
},
toolbar: {
paddingRight: 24, // keep right padding when drawer closed
},
toolbarIcon: {
display: 'flex',
alignItems: 'center',
justifyContent: 'flex-end',
padding: '0 8px',
...theme.mixins.toolbar,
},
appBar: {
zIndex: theme.zIndex.drawer + 1,
transition: theme.transitions.create(['width', 'margin'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
},
.....
});
如果我正确理解,则需要此主题参考以将样式调整为当前主题。但是,调用样式函数时如何获得当前主题?
export default withStyles(styles(/*WHAT TO PUT IN HERE?*/))(Dashboard);
答案 0 :(得分:1)
export default withStyles(styles)(Dashboard);
withStyles
将确定是否需要使用主题进行调用。
withTheme
或withStyles(stylesObjectOrCreator, { withTheme: true })
仅在需要通过道具访问组件内部的theme
时才需要。