Button
A styled action control that renders a native <button> by default. Template-only examples below are fragments: import their AppUI components and any icons in the surrounding Vue component.
Import
import { Button, buttonVariants, type ButtonVariants } from '@gxp-dev/app-ui'
Usage
Basic
<template>
<Button>Click me</Button>
</template>
With Click Handler
<script setup lang="ts">
import { Button } from '@gxp-dev/app-ui'
const handleClick = () => {
console.log('Clicked!')
}
</script>
<template>
<Button @click="handleClick">Click me</Button>
</template>
Variants
The Button supports 6 visual variants:
<template>
<div class="flex flex-wrap gap-4">
<Button variant="default">Default</Button>
<Button variant="secondary">Secondary</Button>
<Button variant="destructive">Destructive</Button>
<Button variant="outline">Outline</Button>
<Button variant="ghost">Ghost</Button>
<Button variant="link">Link</Button>
</div>
</template>
Variant Descriptions
| Variant | Use Case | Appearance |
|---|---|---|
default | Primary actions | Solid primary color background |
secondary | Secondary actions | Secondary theme background |
destructive | Dangerous actions (delete, remove) | Red/danger color |
outline | Tertiary actions | Border and background theme color |
ghost | Subtle actions | No border, transparent background |
link | Navigation-like actions | Primary text with underline on hover |
Sizes
The Button supports 6 sizes:
<template>
<div class="flex items-center gap-4">
<Button size="sm">Small</Button>
<Button size="default">Default</Button>
<Button size="lg">Large</Button>
</div>
</template>
Icon Buttons
For icon-only buttons:
<script setup>
import { Button } from '@gxp-dev/app-ui'
import { Plus, Settings, X } from 'lucide-vue-next'
</script>
<template>
<div class="flex items-center gap-4">
<Button type="button" size="icon-sm" aria-label="Close">
<X class="h-3 w-3" />
</Button>
<Button type="button" size="icon" aria-label="Add">
<Plus class="h-4 w-4" />
</Button>
<Button type="button" size="icon-lg" aria-label="Settings">
<Settings class="h-5 w-5" />
</Button>
</div>
</template>
Size Dimensions
The pixel values assume the default spacing scale and a 16px root font. Themes or root font changes can alter them.
| Size | Height | Padding |
|---|---|---|
sm | 36px (h-9) | px-3 |
default | 40px (h-10) | px-4 py-2 |
lg | 44px (h-11) | px-8 |
icon | 40px (h-10 w-10) | - |
icon-sm | 36px (h-9 w-9) | - |
icon-lg | 44px (h-11 w-11) | - |
With Icons
Icon on Left
<script setup>
import { Button } from '@gxp-dev/app-ui'
import { Mail } from 'lucide-vue-next'
</script>
<template>
<Button>
<Mail class="mr-2 h-4 w-4" />
Send Email
</Button>
</template>
Icon on Right
<script setup>
import { Button } from '@gxp-dev/app-ui'
import { ArrowRight } from 'lucide-vue-next'
</script>
<template>
<Button>
Continue
<ArrowRight class="ml-2 h-4 w-4" />
</Button>
</template>
Loading State
<script setup>
import { ref } from 'vue'
import { Button } from '@gxp-dev/app-ui'
import { Loader2 } from 'lucide-vue-next'
const isLoading = ref(false)
</script>
<template>
<Button :disabled="isLoading">
<Loader2 v-if="isLoading" class="mr-2 h-4 w-4 animate-spin" />
{{ isLoading ? 'Loading...' : 'Submit' }}
</Button>
</template>
Disabled State
<template>
<Button disabled>Disabled Button</Button>
</template>
For the default native button, disabled suppresses activation, and the styles reduce opacity and pointer events. The primitive does not add cursor-not-allowed. An anchor or router link does not acquire native disabled semantics from this attribute: the host must prevent navigation/activation and communicate the state accessibly. Set type="button" for actions inside forms that should not submit them.
As Different Element
As Anchor
<template>
<Button as="a" href="https://example.com">
Visit Site
</Button>
</template>
As Router Link
<script setup>
import { RouterLink } from 'vue-router'
import { Button } from '@gxp-dev/app-ui'
</script>
<template>
<Button as-child>
<RouterLink to="/dashboard">
Go to Dashboard
</RouterLink>
</Button>
</template>
Custom Styling
Via Class Prop
<template>
<Button class="rounded-full w-full">
Full Width Rounded
</Button>
</template>
Using buttonVariants
For applying button styles to custom elements:
<script setup>
import { buttonVariants } from '@gxp-dev/app-ui'
</script>
<template>
<a
href="/link"
:class="buttonVariants({ variant: 'outline', size: 'sm' })"
>
Styled Link
</a>
</template>
API Reference
Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'default' | 'secondary' | 'destructive' | 'outline' | 'ghost' | 'link' | 'default' | Visual variant |
size | 'default' | 'sm' | 'lg' | 'icon' | 'icon-sm' | 'icon-lg' | 'default' | Button size |
as | string | Component | 'button' | Element to render as |
asChild | boolean | false | Merge props with child element |
class | HTMLAttributes['class'] | - | Vue string, array or object class binding |
Native attributes such as type and disabled, and listeners such as @click, fall through to the rendered element. They are not separately declared Button props/events. See the generated contract for inherited Primitive props and current types.
Slots
| Slot | Description |
|---|---|
default | Button content |
Exports
// Component
export { Button } from '@gxp-dev/app-ui'
// Variant function
export { buttonVariants } from '@gxp-dev/app-ui'
// Types
export type { ButtonVariants } from '@gxp-dev/app-ui'
Accessibility
- Uses native
<button>element by default - Supports keyboard navigation (Enter/Space to activate)
- Native disabled behavior when rendering a button
- Give icon-only actions an accessible name with
aria-label - Focus visible ring for keyboard users
Examples
Form Submit Button
<template>
<form @submit.prevent="handleSubmit">
<!-- form fields -->
<Button type="submit">
Submit Form
</Button>
</form>
</template>
Button Group
<template>
<div class="flex">
<Button variant="outline" class="rounded-r-none">
Left
</Button>
<Button variant="outline" class="rounded-none border-x-0">
Center
</Button>
<Button variant="outline" class="rounded-l-none">
Right
</Button>
</div>
</template>
Confirmation Button
This local confirmation UI emits confirm; its parent supplies the authorized deletion request, error handling and busy state. It does not delete a record.
<script setup lang="ts">
import { onUnmounted, ref } from 'vue'
import { Button } from '@gxp-dev/app-ui'
const emit = defineEmits<{ confirm: [] }>()
const confirmDelete = ref(false)
let timer: ReturnType<typeof setTimeout> | undefined
onUnmounted(() => clearTimeout(timer))
const handleDelete = () => {
clearTimeout(timer)
if (confirmDelete.value) {
emit('confirm')
confirmDelete.value = false
} else {
confirmDelete.value = true
timer = setTimeout(() => { confirmDelete.value = false }, 3000)
}
}
</script>
<template>
<Button
type="button"
:variant="confirmDelete ? 'destructive' : 'outline'"
@click="handleDelete"
>
{{ confirmDelete ? 'Click again to confirm' : 'Delete' }}
</Button>
</template>