Button
The button that triggers an action, and the reference from which the tone and variant tables of every other coloured component are taken. It renders a native <button>, or an <a> as soon as it is given an href.
Usage
Examples
Variants and tones
variant offers four ways of painting the button, and tone three meanings: accent, neutral and danger.
Elevated
elevated applies the shadow scale to whichever variant is in use. A ghost or outline button also gains a raised background.
Sizes
size sets the height: 24, 32, 40, 48 or 56 pixels. The type, the padding and the icons follow.
Compact
compact takes 4px off the height, nothing else moving.
Full width
fullWidth stretches the button across the inline size of its parent and makes it block level.
With icons
iconStart and iconEnd put an icon on either side of the label, and iconFilled switches them to their filled form. The #start and #end slots take over when the content is more than an icon.
Custom icons
Both icon props take an IconSource: one of the library icons, a name handed to the resolver your application installed, SVG path data, a component, or an image.
Link
href renders the button as an <a>. A disabled or loading link is made inert, its address dropped.
States
disabled greys the button out through the colour tokens. loading disables it, announces it as busy and puts a spinner where the start icon was.
API
Props
| Prop | Type | Default |
|---|---|---|
variant | ButtonVariant'solid' | 'outline' | 'ghost' | 'soft' | 'solid' |
How much visual weight the action carries: solid is filled with the tone, soft uses a tinted background, outline keeps only a border, and ghost shows nothing until it is hovered. Inside a VButtonGroup the group decides it, as it does the size, the density and the elevation. | ||
tone | ButtonTone'accent' | 'neutral' | 'danger' | 'accent' |
What the action means: accent for the ordinary one, neutral for a secondary one, danger for one that destroys something. On a button a tone is an intention, which is why states such as success or warning are not offered here. Left out inside a VButtonGroup it takes the group's tone; on its own the button is accent. | ||
elevated | boolean | false |
| Raises the button off the page with the shadow scale, whatever the variant. A ghost or outline button also gains a raised surface, because in the dark theme a shadow lying on the page background has nothing casting it. | ||
size | ButtonSize'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'md' |
| The height of the button, taken from the size scale shared by every control: 24, 32, 40, 48 and 56 pixels. | ||
compact | boolean | false |
| Takes 4px off the height, leaving the padding, the text and the icons as they are. | ||
fullWidth | boolean | false |
| Stretches the button across the whole inline size of its parent instead of leaving it as wide as its label. It also becomes block-level, so it no longer sits on a line of text. | ||
href | string | none |
Turns the button into an <a> pointing at this address. A disabled or loading link becomes inert: the address is dropped, so it can be neither focused nor followed. | ||
type | ButtonHTMLAttributes['type'] | 'button' |
The native type of the button. It is ignored as soon as href makes it a link. | ||
disabled | boolean | false |
| Makes the button unusable: it stops responding, leaves the tab order and greys out through the colour tokens rather than through opacity. | ||
loading | boolean | false |
| Shows a spinner, disables the button and announces it as busy. The spinner takes the place of the start icon, so the two are never shown side by side. | ||
iconStart | IconSource | none |
An icon before the label. The #start slot replaces it. | ||
iconEnd | IconSource | none |
An icon after the label. The #end slot replaces it. | ||
iconFilled | boolean | false |
Renders both icons in their filled form, the font's FILL axis. It has no effect on the #start and #end slots, whose icons you build yourself. | ||
Slots
| Slot | Type |
|---|---|
default | {} |
| The label of the button. | |
start | {} |
Content placed before the label, usually an icon. Mark it aria-hidden when it only repeats what the label already says. | |
end | {} |
| Content placed after the label. | |
Types
The types the tables above name, written as the library declares them. The ones carrying export can be imported from vectis-ui to type your own code; the others are the shape of what a slot hands out.
export interface BuiltinIcon {
name: string
paths: readonly [string] | readonly [string, string]
}export type IconRender =
| { path: string; viewBox?: string }
| { component: Component; props?: Record<string, unknown> }
| { src: string }
| { text: string; class?: string }
| { class: string }export type IconSource = string | BuiltinIcon | IconRender