Skip to content

Token

Alpha
A Token represents a piece of data. They are typically used to show a collection of related attributes.

The default Token can be used for most cases, but specialized token components are provided for specific use cases (see below for more info).

All types of tokens may have the same interactive qualities as links or buttons. They also have a sense of being "selected" and ready for user interaction such as being removed from a collection.

Examples

Basic

Kitchen sink

Interactive tokens

If any token is interactive (it is a link or a button), it will become focusable, and react to being hovered or focused on.

If a token is interactive and has a remove button (appears when passing onRemove), the remove button should not get focus. To invoke the onRemove callback without using the cursor, press 'Backspace' when the token is focused.

These rules apply to all token components mentioned in this document.

Interactive tokens with and without an onRemove prop

IssueLabelToken

Tokens that represent Issue labels should use the IssueLabelToken component.

AvatarToken

Tokens that represent GitHub users should use the AvatarToken component.

Props

Token

NameTypeDefaultDescription
text Required
string
The text label inside the token
id
string | number
A unique identifier that can be associated with the token
as
"a" | "button" | "span"
size
TokenSizeKeys
mediumWhich size the token will be rendered at
sx
BetterSystemStyleObject
leadingVisual
any
A function that renders a component before the token text
onRemove
() => void
The function that gets called when a user clicks the remove button, or keys "Backspace" or "Delete" when focused on the token
isSelected
boolean
Whether the token is selected
hideRemoveButton
boolean
Whether the remove button should be rendered in the token

IssueLabelToken

NameTypeDefaultDescription
text Required
string
The text label inside the token
id
string | number
A unique identifier that can be associated with the token
as
"a" | "button" | "span"
size
TokenSizeKeys
mediumWhich size the token will be rendered at
onRemove
() => void
The function that gets called when a user clicks the remove button, or keys "Backspace" or "Delete" when focused on the token
isSelected
boolean
Whether the token is selected
fillColor
string
#999The color that corresponds to the label
hideRemoveButton
boolean
Whether the remove button should be rendered in the token

AvatarToken

NameTypeDefaultDescription
text Required
string
The text label inside the token
avatarSrc Required
string
id
string | number
A unique identifier that can be associated with the token
as
"a" | "button" | "span"
size
TokenSizeKeys
mediumWhich size the token will be rendered at
onRemove
() => void
The function that gets called when a user clicks the remove button, or keys "Backspace" or "Delete" when focused on the token
isSelected
boolean
Whether the token is selected

Status

Alpha

  • Component props are documented on primer.style/react.
  • Component does not have any unnecessary third-party dependencies.
  • Component can adapt to different themes.
  • Component can adapt to different screen sizes.
  • Component has 100% test coverage.

Beta

  • Component is used in a production application.
  • Common usage examples are documented on primer.style/react.
  • Common usage examples are documented in storybook stories.
  • Component has been reviewed by a systems designer and any resulting issues have been addressed.
  • Component has been manually reviewed by the accessibility team and any resulting issues have been addressed.

Stable

  • Component API has been stable with no breaking changes for at least one month.
  • Feedback on API usability has been sought from developers using the component and any resulting issues have been addressed.
  • Component has corresponding design guidelines documented in the interface guidelines.
  • Component has corresponding Figma component in the Primer Web library.
Edit this page on GitHub
2 contributorsmperrotticolebemis
Last edited by mperrotti on January 11, 2022