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.
<><Text fontSize={0} display="block" color="fg.subtle">Token</Text><Token text="Default Token" /></>
<Boxdisplay="flex"sx={{alignItems: 'start',flexDirection: 'column',gap: 6,}}><div><Text fontSize={0} display="block" color="fg.subtle">Resting</Text><Token text="Default Token" /></div><div><Text fontSize={0} display="block" color="fg.subtle">isSelected</Text><Token text="Default Token" isSelected /></div><div><Text fontSize={0} display="block" color="fg.subtle">With `leadingVisual` passed</Text><Token text="Default Token" leadingVisual={GitBranchIcon} /></div><div><Text fontSize={0} display="block" color="fg.subtle">With `onRemove` passed</Text><Tokentext="Default Token"onRemove={() => {console.log('remove me')}}/></div><div><Text fontSize={0} display="block" color="fg.subtle">Size options</Text><Boxdisplay="flex"sx={{alignItems: 'start',gap: 2,}}><Token size="small" text="'small' Token" /><Token size="medium" text="'medium' Token" /><Token size="large" text="'large' Token (default)" /><Token size="xlarge" text="'xlarge' Token" /></Box></div></Box>
leadingVisual
should not be used with the small
size option if you're rendering an icon from Octicons<Boxdisplay="flex"sx={{alignItems: 'start',flexDirection: 'column',gap: 6,}}><Token size="medium" text="'medium' Token" leadingVisual={GitBranchIcon} /><Token size="large" text="'large' Token (default)" leadingVisual={GitBranchIcon} /><Token size="xlarge" text="'xlarge' Token" leadingVisual={GitBranchIcon} /></Box>
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.
onRemove
prop<Boxdisplay="flex"sx={{alignItems: 'start',flexDirection: 'column',gap: 6,}}><div><Text fontSize={0} display="block" color="fg.subtle">Interactive</Text><Boxdisplay="flex"sx={{alignItems: 'start',gap: 2,}}><Token as="a" href="http://google.com/" text="Link" /><Token as="button" onClick={() => console.log('clicked')} text="Button" /><Token as="span" tabIndex={0} onFocus={() => console.log('focused')} text="Focusable Span" /></Box></div><div><Text fontSize={0} display="block" color="fg.subtle">Interactive with `onRemove` passed</Text><Boxdisplay="flex"sx={{alignItems: 'start',gap: 2,}}><Tokenas="a"href="http://google.com/"text="Link"onRemove={() => {console.log('remove me')}}/><Tokenas="button"onClick={() => console.log('clicked')}text="Button"onRemove={() => {console.log('remove me')}}/><Tokenas="span"tabIndex={0}onFocus={() => console.log('focused')}text="Focusable Span"onRemove={() => {console.log('remove me')}}/></Box></div></Box>
Tokens that represent Issue labels should use the IssueLabelToken
component.
<Boxdisplay="flex"sx={{alignItems: 'start',flexDirection: 'column',gap: 6,}}><div><Text fontSize={0} display="block" color="fg.subtle">Resting</Text><IssueLabelToken text="good first issue" fillColor="#0366d6" /></div><div><Text fontSize={0} display="block" color="fg.subtle">isSelected</Text><IssueLabelToken text="good first issue" fillColor="#0366d6" isSelected /></div><div><Text fontSize={0} display="block" color="fg.subtle">With `onRemove` passed</Text><IssueLabelTokentext="good first issue"fillColor="#0366d6"onRemove={() => {console.log('remove me')}}/></div><div><Text fontSize={0} display="block" color="fg.subtle">Size options</Text><Boxdisplay="flex"sx={{alignItems: 'start',gap: 2,}}><IssueLabelTokenfillColor="#0366d6"size="small"text="'small' Token"onRemove={() => {console.log('remove me')}}/><IssueLabelTokenfillColor="#0366d6"size="medium"text="'medium' Token"onRemove={() => {console.log('remove me')}}/><IssueLabelTokenfillColor="#0366d6"size="large"text="'large' Token (default)"onRemove={() => {console.log('remove me')}}/><IssueLabelTokenfillColor="#0366d6"size="xlarge"text="'xlarge' Token"onRemove={() => {console.log('remove me')}}/></Box></div></Box>
Tokens that represent GitHub users should use the AvatarToken
component.
small
or medium
size option<Boxdisplay="flex"sx={{alignItems: 'start',flexDirection: 'column',gap: 6,}}><div><Text fontSize={0} display="block" color="fg.subtle">Resting</Text><AvatarToken avatarSrc="https://avatars.githubusercontent.com/mperrotti" text="Default Token" /></div><div><Text fontSize={0} display="block" color="fg.subtle">isSelected</Text><AvatarToken avatarSrc="https://avatars.githubusercontent.com/mperrotti" text="Default Token" isSelected /></div><div><Text fontSize={0} display="block" color="fg.subtle">With `onRemove` passed</Text><AvatarTokenavatarSrc="https://avatars.githubusercontent.com/mperrotti"text="Default Token"onRemove={() => {console.log('remove me')}}/></div><div><Text fontSize={0} display="block" color="fg.subtle">Size options</Text><Boxdisplay="flex"sx={{alignItems: 'start',gap: 2,}}><AvatarTokenavatarSrc="https://avatars.githubusercontent.com/mperrotti"size="large"text="'large' Token (default)"onRemove={() => {console.log('remove me')}}/><AvatarTokenavatarSrc="https://avatars.githubusercontent.com/mperrotti"size="xlarge"text="'xlarge' Token"onRemove={() => {console.log('remove me')}}/></Box></div></Box>
Name | Type | Default | Description |
---|---|---|---|
leadingVisual | React.ComponentType<React.PropsWithChildren<any>> | A function that renders a component before the token text | |
text Required | string | The text label inside the token | |
as | React.ElementType | 'span' | The underlying element to render — either a HTML element name or a React component. |
onRemove | () => void | The function that gets called when a user clicks the remove button, or keys `Backspace` or `Delete` when focused on the token | |
hideRemoveButton | boolean | Whether the remove button should be rendered in the token | |
isSelected | boolean | Whether the token is selected | |
id | number | string | A unique identifier that can be associated with the token | |
size | 'small' | 'medium' | 'large' | 'xlarge' | Which size the token will be rendered at | |
sx | SystemStyleObject | Style overrides to apply to the component. See also overriding styles. |
Name | Type | Default | Description |
---|---|---|---|
fillColor | string | The color that corresponds to the label | |
text Required | string | The text label inside the token | |
as | React.ElementType | 'span' | The underlying element to render — either a HTML element name or a React component. |
onRemove | () => void | The function that gets called when a user clicks the remove button, or keys `Backspace` or `Delete` when focused on the token | |
hideRemoveButton | boolean | Whether the remove button should be rendered in the token | |
isSelected | boolean | Whether the token is selected | |
id | number | string | A unique identifier that can be associated with the token | |
size | 'small' | 'medium' | 'large' | 'xlarge' | Which size the token will be rendered at | |
sx | SystemStyleObject | Style overrides to apply to the component. See also overriding styles. |
Name | Type | Default | Description |
---|---|---|---|
avatarSrc | string | ||
text Required | string | The text label inside the token | |
as | React.ElementType | 'span' | The underlying element to render — either a HTML element name or a React component. |
onRemove | () => void | The function that gets called when a user clicks the remove button, or keys `Backspace` or `Delete` when focused on the token | |
hideRemoveButton | boolean | Whether the remove button should be rendered in the token | |
isSelected | boolean | Whether the token is selected | |
id | number | string | A unique identifier that can be associated with the token | |
size | 'small' | 'medium' | 'large' | 'xlarge' | Which size the token will be rendered at | |
sx | SystemStyleObject | Style overrides to apply to the component. See also overriding styles. |