Skip to content

Button

Button element to handle click events

Basic Usage

vue
<script setup>
import { Button } from '@vrgl/vergil/components'
</script>

<template>
    <Button>Keep it Clean!</Button>
</template>

Props

Label
label: string
MiniMarkup

Simple Button text content can be specified through the default slot or the label prop. The slot content overrides the label prop.

vue
<Button label="Click"/>

Variant
variant: ('solid' | 'soft' | 'subtle') = 'solid'

Mask
mask: ('ghost' | 'form-field')

Outline
outline: (boolean | 'subtle' | 'regular' | 'strong')

The 'regular' and true values are equivalent. For the solid variant, only buttons with mask are affected.

Fill
fill: boolean
only for masked buttons

Underline
underline: boolean

Icon
icon: string
alias:
icon-left

vue
<Button icon="rocket_launch"/>

Icon Right
icon-right: string

vue
<Button label="Omega" icon-right="special_character"/>

Squared
squared: boolean

Adding squared sets padding to the same value on all sides.

The link-to prop instructs Button to mount an a element instead of a button. In addition, Button supports RouterLink and NuxtLink by automatically rendering whichever is available when link-to is used (NuxtLink has precedence over RouterLink).

If a plain a element is mounted, link-to becomes its href attribute. Otherwise, link-to is equivalent to RouterLink's to prop.

vue
<Button label="Link" link-to="/path"/>

Additional attributes or props for underlying a element, or RouterLink or NuxtLink components if link-to is provided.

vue
<Button
    label="External Link"
    link-to="/path"
    :link-options="{ target: '_blank' }"
/>

Underlines Button's label on hover when link-to is provided.

vue
<Button label="Link underline" link-to="/path" link-underline/>

Theme
theme: Theme = 'brand'

Interaction Theme
interaction-theme: Theme

Size
size: ('xs' | 'sm' | 'md' | 'lg' | 'xl') = 'md'

Radius
radius: ('none' | 'sm' | 'md' | 'lg' | 'full') = 'md'

Spacing
spacing: ('compact' | 'expanded') = ''

Disabled
disabled: boolean

Loading
loading: boolean

Button group

An element with a button-group class can be used to group Button components together:

html
<div class="button-group">
    <Button variant="soft" outline squared theme="neutral" interaction-theme="brand" icon="edit"/>
    <Button variant="soft" outline squared theme="neutral" interaction-theme="danger" icon="delete"/>
</div>

Exposed

When link-to is provided and RouterLink or NuxtLink is rendered, a corresponding useLink or useNuxtLink instance is exposed.

The exposed link instance may be used, for example, to update Button props based on whether the link is active:

vue
<script setup>
import { useExposed } from '@vrgl/vergil'
const exposed = useExposed()
</script>

<template>
    <Button :exposed link-to="/"
        :theme="exposed.isActive ? 'brand' : 'neutral'"
    />
</template>

WARNING

If link-to is an object defined in-template, an infinite loop may be generated if template-tracked exposed properties are triggered because when the template is re-rendered a new object may be created for link-to. In that case, Button internally creates and exposes a new link instance, and triggers the exposed object, which in turn triggers another template re-render, and so on. To prevent this, defining a link-to object directly in the template should be avoided:

vue
<script setup>
import { useExposed } from '@vrgl/vergil'
const exposed = useExposed()
const linkTo = {/* ... */}
</script>

<template>
    <Button :exposed link-to="{/* ... */}" v-bind="f(exposed)"/>
    <Button :exposed :link-to v-bind="f(exposed)"/>
</template>

API Reference

Props

proptypedefault
labelstring
variant'solid' | 'soft' | 'subtle''solid'
mask'ghost' | 'form-field'
outlineboolean | 'subtle' | 'regular' | 'strong'
underlineboolean
fillboolean
iconstring
iconLeftstring
iconRightstring
squaredbooleanfalse
disabledbooleanfalse
loadingbooleanfalse
linkToRouteLocationRaw
linkOptionsAnchorHTMLAttributes | Omit<RouterLinkProps, 'to'> | Omit<NuxtLinkProps, 'to' | 'href'>
linkUnderlineboolean
descendantboolean
theme'brand' | 'user' | 'ok' | 'info' | 'warn' | 'danger' | 'neutral''brand'
interactionTheme'brand' | 'user' | 'ok' | 'info' | 'warn' | 'danger' | 'neutral'
size'xs' | 'sm' | 'md' | 'lg' | 'xl''md'
radius'none' | 'sm' | 'md' | 'lg' | 'full''md'
spacing'' | 'compact' | 'extended'''
exposedobject

Configuration options

Button's configuration options allow to overwrite some Button props' default values and may be overwritten under the button root-level configuration option.

button.<option>typedefaultglobal
variant'solid' | 'soft' | 'subtle''solid'
<variant>.mask'ghost' | 'form-field'
<variant>.outlineboolean | 'subtle' | 'regular' | 'strong'
<variant>.underlineboolean
<variant>.fillboolean
squaredboolean
themetheme
sizesize
radiusradius
spacingspacing

Anatomy

<button.button/>

<span.button-backdrop/>

<div.button-content/>

<Icon.icon/>

<slot name="default"/>

<Icon.icon/>

<div.button-loader/>

<span.button-spinner/>

<p.button-label/>

<slot name="aside"/>