简体   繁体   English

MUI 5 使用带有子组件道具的样式化组件

[英]MUI 5 using styled components with child component props

I'm converting from MUI 4 to 5. Working on converting from makeStyles() to styled components.我正在从 MUI 4 转换到 5。正在从makeStyles()转换为样式化组件。 Is there an example somewhere using the styled() method with a component that has child component props?是否有使用styled()方法和具有子组件道具的组件的示例? For example, <ListItemText /> has primaryTypographyProps and secondaryTypographyProps , both of which I'm setting the inner className property for custom styles.例如, <ListItemText />primaryTypographyPropssecondaryTypographyProps ,我正在为自定义 styles 设置内部className属性。

How does something like this...这种东西怎么...

<ListItemText
  {...props}
  primaryTypographyProps={{
    variant: 'body2',
    className: classes.primary,
  }}
  secondaryTypographyProps={{
    variant: 'body1',
    className: classes.secondary,
  }}
/>

...convert to something like this? ...转换成这样的东西?

const StyledListItemText = styled(ListItemText)(({ theme }) => ({
  ...???...
}));

[Edit] This is the closest I've been able to find, but it's not quite there. [编辑] 这是我能找到的最接近的,但它并不完全在那里。 What I'm trying to do is pass it through a props object, rather than whole components.我想要做的是通过一个道具 object 传递它,而不是整个组件。

I haven't had a chance to verify if this works, but I'm assuming this is the direction I need to go with this:我没有机会验证这是否有效,但我假设这是我需要 go 的方向:

const StyledListItemText = styled(ListItemText)(() => ({
  'MuiListItemText-primary': { ... },
  'MuiListItemText-secondary': { ... },
}));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM