To add the Badge
component to your app:
1 2import { Badge } from '@forge/react';
A badge is a visual indicator for numeric values, such as tallies and scores.
Name | Type | Required | Description |
---|---|---|---|
appearance | "added" | "default" | "important" | "primary" | "primaryInverted" | "removed" | No | Affects the visual style of the badge. |
children | string | number | Yes | The value displayed within the badge. A badge should only be used in cases where you want to represent a number. Use a lozenge for non-numeric information. |
max | number | false | No | The maximum value to display. Defaults to 99. If the value is 100, and max is 50, "50+" will be displayed. This value should be greater than 0. If set to false the original value will be displayed regardless of whether it is larger than the default maximum value. |
The default form of a badge.
1 2const BadgeDefaultExample = () => { return <Badge>{25}</Badge>; };
Use a primary
badge to help draw attention to new or updated information.
1 2const BadgePrimaryExample = () => { return <Badge appearance="primary">{25}</Badge>; };
Use a primaryInverted
badge when high contrast against a darker background color is needed.
1 2const BadgePrimaryInvertedExample = () => { return <Badge appearance="primaryInverted">{25}</Badge>; };
Use an important
badge to call attention to information that needs to stand out. For example, notifications in Confluence.
1 2const BadgeImportantExample = ()=> { return <Badge appearance="important">{25}</Badge>; };
Use an added
badge to indicate when an item has been added. For example, in a changelog or activity feed.
1 2const BadgeAddedExample = () => { return <Badge appearance="added">{25}</Badge>; };
Use a removed
badge to indicate when an item has been removed. For example, in a changelog or activity feed.
1 2const BadgeRemovedExample = () => { return <Badge appearance="removed">{25}</Badge>; };
Use the max prop to cap the value of a badge. When the value to display is greater than the max prop, a + will be appended. The default max value of a badge is 99.
1 2const BadgeMaxDefault = () => { return ( <Badge appearance="primary"> {100} </Badge> ); };
1 2const BadgeMaxValueEnabled = () => { return ( <Badge appearance="primary" max={500}> {1000} </Badge> ); };
1 2const BadgeMaxValueDisabled = () => { return ( <Badge appearance="primary" max={false}> {1000} </Badge> ); };
1 2const BadgeWithText = () => { return ( <Inline alignBlock="center" space="space.100"> <Text>New issues</Text> <Badge appearance="added" max={25}>30</Badge> </Inline> ); };
When using the Badge
component, we recommend keeping the following accessibility considerations in mind:
Rate this page: