Skip to content

Btn

Button element to handle click events

Basic Usage

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

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

Props

Label
label: string
MiniMarkup

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

vue
<Btn 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
<Btn icon="rocket_launch"/>

Icon Right
icon-right: string

vue
<Btn 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 Btn to mount an a element instead of a button. In addition, Btn 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
<Btn label="Link" link-to="/path"/>

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

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

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

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

Theme
theme: theme = 'brand'

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

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 Btn props based on whether the link is active:

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

<template>
    <Btn :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, Btn 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>
    <Btn :exposed link-to="{/* ... */}" v-bind="f(exposed)"/>
    <Btn :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'
size'xs' | 'sm' | 'md' | 'lg' | 'xl''md'
radius'none' | 'sm' | 'md' | 'lg' | 'full''md'
spacing'' | 'compact' | 'extended'''
exposedobject

Configuration options

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

btn.<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.btn/>

<span.btn-backdrop/>

<div.btn-content/>

<Icon.icon/>

<slot name="default"/>

<Icon.icon/>

<div.btn-loader/>

<span.btn-spinner/>

<p.btn-label/>

<slot name="aside"/>