Notification Badge
import { NotificationBadge } from "stylus-ui/NotificationBadge";
export default () => <NotificationBadge />;Counts
Section titled “Counts”The badge will display a count of unread notifications.
import { NotificationBadge } from "stylus-ui/NotificationBadge";
export default () => <NotificationBadge count={1} />;Max Digits
Section titled “Max Digits”By default, the badge will max out after 2 digits at 99.
import { NotificationBadge } from "stylus-ui/NotificationBadge";
// The count is 1000, but the badge will only display 99.export default () => <NotificationBadge count={1000} />;To change the max number displayed, set maxDigits.
import { NotificationBadge } from "stylus-ui/NotificationBadge";
export default () => <NotificationBadge count={1000} maxDigits={3} />;To display the full count regardless of length, set maxDigits to 0.
import { NotificationBadge } from "stylus-ui/NotificationBadge";
export default () => <NotificationBadge count={15225} maxDigits={0} />;Sizing
Section titled “Sizing”A smaller badge, which does not show a count, can be used by setting size to sm.
import { NotificationBadge } from "stylus-ui/NotificationBadge";
export default () => <NotificationBadge size="sm" />;The smallest badge, best for inline text, can be used by setting size to xs.
import { NotificationBadge } from "stylus-ui/NotificationBadge";
export default () => ( <div className="flex items-center gap-2"> <span>Notifications</span> <NotificationBadge size="xs" /> </div>);Positioning
Section titled “Positioning”The badge can be positioned in the top right corner of another element by passing that element as a child.
import { faMessage } from "@fortawesome/pro-regular-svg-icons";import { Button } from "stylus-ui/Button";import { NotificationBadge } from "stylus-ui/NotificationBadge";
export default () => ( <NotificationBadge count={1}> <Button variant="secondary" icon={faMessage}> Comments </Button> </NotificationBadge>);This also works for the small badge.
import { faMessage } from "@fortawesome/pro-regular-svg-icons";import { Button } from "stylus-ui/Button";import { NotificationBadge } from "stylus-ui/NotificationBadge";
export default () => ( <NotificationBadge size="sm"> <Button variant="secondary" icon={faMessage}> Comments </Button> </NotificationBadge>);Pulse Animation
Section titled “Pulse Animation”When drawing attention to a notification, you can animate the badge by setting pulse to true. This should be used sparingly and generally reserved for important new features.
import { faMessage } from "@fortawesome/pro-regular-svg-icons";import { Button } from "stylus-ui/Button";import { NotificationBadge } from "stylus-ui/NotificationBadge";
export default () => ( <NotificationBadge size="sm" pulse> <Button variant="secondary" icon={faMessage} aria-label="Comments" /> </NotificationBadge>);API Reference
Section titled “API Reference”NotificationBadge
Section titled “NotificationBadge”Use to display a count of unread notifications.
children
To position the badge in the top right corner of another element, pass that element as a child.
className
Optional styles for the badge.
count
The total notification count.
maxDigits
The maximum number of digits to display. Counts above this value will display a plus sign. For example, if the count is 1000, and maxDigits is 2, the badge will display 99+. Set to ‘0’ to always show the full count.
pulse
Animate a beacon pulse on the badge.
size
The size of the badge. The sm and xs badges do not show a count.
theme
The theme of the badge.
wrapperClassName
Optional styles for the badge wrapper. Only used if the badge receives a child element.