[英]MUI 5 using styled components with child component props
我正在從 MUI 4 轉換到 5。正在從makeStyles()
轉換為樣式化組件。 是否有使用styled()
方法和具有子組件道具的組件的示例? 例如, <ListItemText />
有primaryTypographyProps
和secondaryTypographyProps
,我正在為自定義 styles 設置內部className
屬性。
這種東西怎么...
<ListItemText
{...props}
primaryTypographyProps={{
variant: 'body2',
className: classes.primary,
}}
secondaryTypographyProps={{
variant: 'body1',
className: classes.secondary,
}}
/>
...轉換成這樣的東西?
const StyledListItemText = styled(ListItemText)(({ theme }) => ({
...???...
}));
[編輯] 這是我能找到的最接近的,但它並不完全在那里。 我想要做的是通過一個道具 object 傳遞它,而不是整個組件。
我沒有機會驗證這是否有效,但我假設這是我需要 go 的方向:
const StyledListItemText = styled(ListItemText)(() => ({
'MuiListItemText-primary': { ... },
'MuiListItemText-secondary': { ... },
}));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.