Badge 徽章
徽章组件会在其子项(们)的右上角生成一个小徽章。
444
<Badge badgeContent={4} color="primary">
<MailIcon />
</Badge>
<Badge badgeContent={4} color="secondary">
<MailIcon />
</Badge>
<Badge badgeContent={4} color="error">
<MailIcon />
</Badge>
自定义徽章
以下是自定义组件的一个示例。 您可以在 重写文档页面 中了解更多有关此内容的信息。
<IconButton aria-label="cart">
<StyledBadge badgeContent={4} color="secondary">
<ShoppingCartIcon />
</StyledBadge>
</IconButton>
1
当 badgeContent 为零时,徽章组件将会自动隐藏。 您可以使用 showZero
属性覆盖它。
0
<Badge color="secondary" badgeContent={0}>
<MailIcon />
</Badge>
<Badge color="secondary" badgeContent={0} showZero>
<MailIcon />
</Badge>
9999+999+
<Badge badgeContent={99} {...defaultProps} />
<Badge badgeContent={100} {...defaultProps} />
<Badge badgeContent={1000} max={999} {...defaultProps} />
Typography
<Badge color="secondary" variant="dot">
<MailIcon />
</Badge>
<Badge color="secondary" variant="dot">
<Typography>Typography</Typography>
</Badge>
<Badge color="secondary" badgeContent=" ">
{rectangle}
</Badge>
<Badge color="secondary" badgeContent=" " variant="dot">
{rectangle}
</Badge>
<Badge color="secondary" overlap="circular" badgeContent=" ">
{circle}
</Badge>
<Badge color="secondary" overlap="circular" badgeContent=" " variant="dot">
{circle}
</Badge>
11299+999+
<Badge
anchorOrigin={{
vertical: 'top',
horizontal: 'right',
}}
>
5
<StyledBadge badgeContent={5} overlap="circular" sx={{ mr: 2 }}>
<BadgeContent />
</StyledBadge>
<StyledBadge badgeContent={5} variant="dot" overlap="circular">
<BadgeContent />
</StyledBadge>