Button
A versatile button component that supports multiple variants, sizes, and states. Can be used as a button or link with rich customization options.
Overview
The Button component is a fundamental UI element that can be used to trigger actions or navigate to different pages. It supports various styles, sizes, and states to match your application's design needs.
Features
- Multiple variants (solid, soft, subtle, ghost, link)
- Different sizes (xs to xl)
- Support for icons (leading and trailing)
- Loading and disabled states
- Can act as a button or link
- Full width option
- Customizable rounded corners
Usage
Basic Button
The simplest way to use the button is with text content:
<template>
<MButton>Click me</MButton>
</template>
Variants
The button comes in five different variants to suit different contexts:
<template>
<div class="flex gap-2 flex-wrap">
<MButton variant="solid" label="Solid" />
<MButton variant="soft" label="Soft" />
<MButton variant="subtle" label="Subtle" />
<MButton variant="ghost" label="Ghost" />
<MButton variant="link" label="Link" />
</div>
</template>
Colors
Buttons support three color schemes:
<template>
<div class="flex gap-2 flex-wrap">
<MButton color="primary" label="Primary" />
<MButton color="neutral" label="Neutral" />
<MButton color="danger" label="Danger" />
</div>
</template>
Sizes
Choose from five different sizes:
<template>
<div class="flex gap-2 items-center flex-wrap">
<MButton size="xs" label="XS" />
<MButton size="sm" label="SM" />
<MButton size="md" label="MD" />
<MButton size="lg" label="LG" />
<MButton size="xl" label="XL" />
</div>
</template>
Icons
Add icons to your buttons using the leadingIcon
or trailingIcon
props:
<template>
<div class="flex gap-2 flex-wrap">
<MButton label="Settings" leadingIcon="i-lucide-settings" />
<MButton label="Next" trailingIcon="i-lucide-arrow-right" />
<MButton square icon="i-lucide-plus" />
</div>
</template>
States
Buttons support various states including loading and disabled:
<template>
<div class="flex gap-2 flex-wrap">
<MButton loading label="Loading..." />
<MButton disabled label="Disabled" />
</div>
</template>
Links
Use the to
prop to make the button act as a link:
<template>
<MButton to="/" label="Home Page" />
</template>
Props
Text content of the button. Can be used instead of the default slot.
The color scheme of the button.
The visual style variant of the button.
The size of the button.
Controls the border radius of the button.
When true, applies equal padding on all sides. Automatically set to true for icon-only buttons.
Makes the button take the full width of its container.
Shows a loading spinner and disables the button.
Disables the button, preventing user interaction.
Icon name to display before the label.
Icon name to display after the label.
When provided, the button becomes a link to the specified URL or route.
Additional CSS classes to apply to the button.
Additional CSS classes to apply to the icons.
Additional CSS classes to apply to the label.
Slots
The default slot for button content. Alternative to using the label
prop.
Slot for custom leading content, typically used for custom icons.
Slot for custom trailing content, typically used for custom icons.
Best Practices
- Use appropriate colors to convey meaning:
primary
for main actionsneutral
for secondary actionsdanger
for destructive actions
- Choose the right variant:
solid
for primary actionssoft
orsubtle
for secondary actionsghost
orlink
for tertiary actions
- Maintain consistent sizing:
- Use
md
size by default - Use larger sizes (
lg
,xl
) for main call-to-action buttons - Use smaller sizes (
xs
,sm
) for compact interfaces
- Use
- Add loading states for async actions to provide feedback
- Use icons thoughtfully to enhance visual communication