Badge 徽章
徽章组件会在其子项(们)的右上角生成一个小徽章。
4
<Badge badgeContent={4} color="primary">
<MailIcon color="action" />
</Badge>
44
<Badge badgeContent={4} color="secondary">
<MailIcon color="action" />
</Badge>
<Badge badgeContent={4} color="success">
<MailIcon color="action" />
</Badge>
徽章组件的可见性
以下是自定义组件的一个示例。 您可以在 重写文档页面 中了解更多有关此内容的信息。
<IconButton aria-label="cart">
<StyledBadge badgeContent={4} color="secondary">
<ShoppingCartIcon />
</StyledBadge>
</IconButton>
1
The badge hides automatically when badgeContent
is zero. 您可以使用 showZero
属性覆盖它。
0
<Badge color="secondary" badgeContent={0}>
<MailIcon />
</Badge>
<Badge color="secondary" badgeContent={0} showZero>
<MailIcon />
</Badge>
9999+999+
<Badge color="secondary" badgeContent={99}>
<MailIcon />
</Badge>
<Badge color="secondary" badgeContent={100}>
<MailIcon />
</Badge>
<Badge color="secondary" badgeContent={1000} max={999}>
<MailIcon />
</Badge>
<Badge color="secondary" variant="dot">
<MailIcon />
</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',
}}
>
<IconButton aria-label={notificationsLabel(100)}>
<Badge badgeContent={100} color="secondary">
<MailIcon />
</Badge>
</IconButton>
Unstyled
The component also comes with an unstyled version. It's ideal for doing heavy customizations and minimizing bundle size.