Skip to content

Button

Neo-brutalist button component supporting 9 variants, 4 sizes + icon mode, loading state, and asChild composition support.

Demo

Preview

变体

尺寸

状态

提交按钮

Installation

pnpm dlx brutx-vue@latest add button

Usage

vue
<script setup>
import { Button } from 'brutx-ui-vue'
</script>

<template>
    <Button variant="primary" size="default">
        Click me
    </Button>
</template>

Loading State

vue
<script setup>
import { ref } from 'vue'
import { Button } from 'brutx-ui-vue'

const isLoading = ref(false)

async function handleSubmit() {
    isLoading.value = true
    await new Promise(resolve => setTimeout(resolve, 2000))
    isLoading.value = false
}
</script>

<template>
    <Button variant="primary" :loading="isLoading" @click="handleSubmit">
        Save Changes
    </Button>
</template>

Disabled State

vue
<script setup>
import { Button } from 'brutx-ui-vue'
</script>

<template>
    <Button variant="primary" disabled>
        Disabled
    </Button>
</template>

Submit Button and Pending Text

Set type="submit" to render the button as a form submit button. Combined with loading and pendingText, the button displays a pending text (replacing the slot content) during submission. When pendingText is not provided, it falls back to the i18n default (submitButton.submitting):

vue
<script setup>
import { ref } from 'vue'
import { Button } from 'brutx-ui-vue'

const isLoading = ref(false)

async function handleSubmit() {
    isLoading.value = true
    await new Promise(resolve => setTimeout(resolve, 2000))
    isLoading.value = false
}
</script>

<template>
    <form @submit.prevent="handleSubmit">
        <Button type="submit" variant="primary" :loading="isLoading" pending-text="Saving...">
            Save
        </Button>
    </form>
</template>

The pending text is shown and the slot content is hidden only when type="submit" and loading=true. In all other cases, the slot content renders normally and the loading icon still appears.

asChild

Use asChild to render button styles onto a custom element (e.g., a router link):

vue
<script setup>
import { Button } from 'brutx-ui-vue'
import { RouterLink } from 'vue-router'
</script>

<template>
    <Button as-child>
        <RouterLink to="/about">About</RouterLink>
    </Button>
</template>

Glitch Effect

Button includes effect="glitch" for the glitch tear animation.

vue
<template>
    <Button
        effect="glitch"
        variant="primary"
        glitch-trigger="click"
        glitch-speed="fast"
        glitch-direction="both"
        data-text="GLITCH"
    >
        GLITCH
    </Button>
</template>

Variants

VariantDescription
defaultBackground color with hard shadow
primaryPrimary (coral) background
secondarySecondary (mint) background
accentAccent (yellow) background
dangerDestructive (red) background with white text
successSuccess (green) background
outlineTransparent background with inversion on hover
ghostNo border or shadow with subtle hover effect
linkNo border or shadow with underline on hover
vue
<template>
    <Button variant="primary">Primary variant</Button>
</template>

Sizes

SizeHeightPaddingFont Size
smh-9px-3 py-1text-sm
defaulth-11px-5 py-2text-base
lgh-14px-8 py-3text-lg
xlh-16px-10 py-4text-xl
iconh-11 w-11p-0

Props

PropTypeDefaultDescription
variant'default' | 'primary' | 'secondary' | 'accent' | 'danger' | 'success' | 'outline' | 'ghost' | 'link''default'Button variant style
size'sm' | 'default' | 'lg' | 'xl' | 'icon''default'Button size; icon is a square icon button
asChildbooleanfalseRenders button styles onto the child element, useful for composing router links, etc.
type'button' | 'submit' | 'reset'undefinedNative button type; enables pendingText behavior when set to submit
loadingbooleanfalseShows loading animation and disables the button
disabledbooleanfalseDisables the button
pendingTextstringundefined (falls back to i18n submitButton.submitting)Pending text displayed during loading; only effective when type="submit" and loading
effect'none' | 'glitch''none'Optional visual effect
glitchTrigger'hover' | 'click' | 'autoplay' | 'none''hover'Glitch animation trigger, only active with effect="glitch"
glitchIntervalnumber3000Autoplay interval in milliseconds, only active with glitchTrigger="autoplay"
glitchSpeed'slow' | 'medium' | 'fast''medium'Glitch animation speed
glitchDirection'horizontal' | 'vertical' | 'both''horizontal'Glitch tear direction
classstringundefinedCustom CSS class name

Events

The Button component propagates all native DOM events (e.g., click, mouseenter, etc.) without additional configuration.

EventPayloadDescription
clickMouseEventFired when the button is clicked; not triggered in loading or disabled state

Slots

SlotScopeDescription
defaultButton content

Accessibility

  • Keyboard: Supports Space / Enter to trigger click
  • ARIA Attributes: Automatically sets the disabled attribute (non-asChild mode) or aria-disabled="true" (asChild mode) when disabled; automatically sets aria-busy="true" when loading
  • Focus Management: Supports keyboard navigation and focus styles (focus:outline)

Brute force builds.