Vitral 0.2
Button

Button

A command in eight severities, four variants and three sizes, with icons, a loading state, a badge, and rendering as a link.

Import

main.ts
import { Button } from '@vitral/vue';

Severities

Filled is the default variant. `secondary` is the quiet button of a toolbar; `primary` is the one that commits.

<script setup lang="ts">import { Button } from '@vitral/vue'; const severities = ['primary', 'secondary', 'success', 'info', 'warn', 'danger', 'help', 'contrast'] as const;</script> <template>    <Button v-for="s in severities" :key="s" :label="s" :severity="s" /></template>

Outlined

<script setup lang="ts">import { Button } from '@vitral/vue'; const severities = ['primary', 'secondary', 'success', 'info', 'warn', 'danger', 'help', 'contrast'] as const;</script> <template>    <Button v-for="s in severities" :key="s" :label="s" :severity="s" variant="outlined" /></template>

Text

<script setup lang="ts">import { Button } from '@vitral/vue'; const severities = ['primary', 'secondary', 'success', 'info', 'warn', 'danger', 'help', 'contrast'] as const;</script> <template>    <Button v-for="s in severities" :key="s" :label="s" :severity="s" variant="text" /></template>

Icons

<script setup lang="ts">import { Button } from '@vitral/vue';</script> <template>    <Button label="New" icon="plus" />    <Button label="Next" icon="arrowRight" icon-pos="right" severity="secondary" />    <Button label="Upload" icon="upload" icon-pos="top" severity="secondary" variant="outlined" />    <Button icon="search" aria-label="Search" />    <Button icon="trash" severity="danger" variant="text" aria-label="Delete" />    <Button icon="star" rounded severity="warn" aria-label="Favourite" /></template>

Icons from anywhere

An imported icon, another library's component, or trusted SVG markup. An icon font's classes work too: `icon="fa-solid fa-user"`, once its stylesheet is on the page.

<script setup lang="ts">import { graduationCap } from '@vitral/icons';import { Button } from '@vitral/vue';import { h } from 'vue'; // Stands in for another library's icon component (lucide-vue-next, @iconify/vue…).const Sparkle = () =>    h('svg', { viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', 'stroke-linecap': 'round', 'stroke-linejoin': 'round' }, [        h('path', { d: 'M12 3v4M12 17v4M3 12h4M17 12h4M6 6l2.5 2.5M15.5 15.5L18 18M6 18l2.5-2.5M15.5 8.5L18 6' })    ]);const markup = '<svg viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="12" r="6"/></svg>';</script> <template>    <Button label="Course" :icon="graduationCap" severity="secondary" />    <Button label="Component" :icon="Sparkle" severity="secondary" />    <Button label="Markup" :icon="markup" severity="secondary" /></template>

Sizes and shape

<script setup lang="ts">import { Button } from '@vitral/vue';</script> <template>    <Button label="Small" size="small" />    <Button label="Normal" />    <Button label="Large" size="large" />    <Button label="Rounded" rounded severity="help" />    <Button label="Raised" raised severity="secondary" /></template>

States

Loading disables the button and sets aria-busy.

A link
<script setup lang="ts">import { Button } from '@vitral/vue';import { ref } from 'vue'; const loading = ref(false); function load() {    loading.value = true;    setTimeout(() => (loading.value = false), 1600);}</script> <template>    <Button label="Save" icon="check" :loading="loading" @click="load" />    <Button label="Disabled" disabled />    <Button label="Notifications" icon="bell" badge="8" severity="secondary" />    <Button as="a" href="https://github.com/vitralui/vitral" target="_blank" label="A link" icon="externalLink" icon-pos="right" variant="link" /></template>

API

Read from packages/vue/src/components/Button/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
labelstring—
iconIconProp—
iconPos'left' | 'right' | 'top' | 'bottom'—
loadingbooleanShows a spinner, disables the button and marks it busy.
loadingIconIconProp—
severityButtonSeverity—
variantButtonVariant—
sizeSize—
roundedboolean—
raisedboolean—
fluidboolean—
badgestring | number—
disabledboolean—
type'button' | 'submit' | 'reset'—
asstring | ComponentRender as another element or component (`'a'`, `RouterLink`), keeping the button's look and behaviour.

Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.

Slots

NameSlot propsDescription
default——
icon——
loadingicon——