UIButton
UIButton
A versatile button component that supports different types, sizes, states, and customizations.
<template> <UIButton type="primary" size="medium" :loading="loading" :disabled="disabled" @click="handleClick" > <template #icon> <PlusIcon class="w-5 h-5" /> </template> Create New </UIButton></template>
<script setup lang="ts">const loading = ref(false)const disabled = ref(false)
const handleClick = () => { loading.value = true // Handle click action}</script>Props
type(‘default’ | ‘primary’ | ‘success’ | ‘warning’ | ‘error’ | ‘info’): Button typesize(‘small’ | ‘medium’ | ‘large’): Button sizeloading(boolean): Show loading statedisabled(boolean): Disable buttonblock(boolean): Full width buttonghost(boolean): Transparent backgrounddashed(boolean): Dashed border styletext(boolean): Text only stylelink(boolean): Link styleround(boolean): Round cornerscircle(boolean): Circular shapeicon(boolean): Icon only buttonhtmlType(‘button’ | ‘submit’ | ‘reset’): HTML button typehref(string): URL for link buttonstarget(string): Target for link buttons
Events
click: Emitted when button is clickedfocus: Emitted when button is focusedblur: Emitted when button loses focus
Slots
default: Button contenticon: Icon contentloading: Custom loading indicator
Usage Examples
- Primary Button:
<template> <UIButton type="primary"> Submit </UIButton></template>- Loading Button:
<template> <UIButton type="primary" :loading="isLoading" @click="handleSubmit" > {{ isLoading ? 'Submitting...' : 'Submit' }} </UIButton></template>- Icon Button:
<template> <UIButton type="default" :circle="true" > <template #icon> <EditIcon class="w-5 h-5" /> </template> </UIButton></template>- Text Button:
<template> <UIButton text> Cancel </UIButton></template>- Link Button:
<template> <UIButton link href="https://example.com" target="_blank" > Learn More </UIButton></template>Best Practices
-
Visual Hierarchy:
- Use primary buttons for main actions
- Use default buttons for secondary actions
- Use text/link buttons for tertiary actions
- Maintain consistent sizing within contexts
-
Loading States:
- Show loading state during async operations
- Disable button while loading
- Provide feedback on completion
-
Accessibility:
- Use descriptive text for screen readers
- Maintain sufficient color contrast
- Support keyboard navigation
- Add aria-labels when needed
-
Responsive Design:
- Use appropriate sizes for different screens
- Consider touch targets on mobile
- Adapt button width as needed
- Handle long text gracefully
-
Error Prevention:
- Disable buttons when actions are invalid
- Confirm destructive actions
- Provide clear feedback
- Handle double clicks appropriately