Skip to content

Button

Triggers an action or event, such as submitting a form or opening a dialog. Same markup and props in every style: switch the style in the header to see it change.

Variants

Use primary for the main action on a screen, and the quieter variants for everything else.

button-variants.html
<button type="button" class="vin-btn">Primary</button>
<button type="button" class="vin-btn vin-btn--secondary">Secondary</button>
<button type="button" class="vin-btn vin-btn--outline">Outline</button>
<button type="button" class="vin-btn vin-btn--ghost">Ghost</button>
<button type="button" class="vin-btn vin-btn--danger">Delete</button>

Sizes

Sizes come from the style's scale, and Customize → Density adjusts all of them together. Icon buttons need an aria-label.

button-sizes.html
<button type="button" class="vin-btn vin-btn--sm">Small</button>
<button type="button" class="vin-btn">Medium</button>
<button type="button" class="vin-btn vin-btn--lg">Large</button>
<button type="button" class="vin-btn vin-btn--outline vin-btn--icon" aria-label="Add item">
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M12 5v14M5 12h14"/></svg>
</button>

Icons, disabled, links

Pass href and the React Button renders a link. A disabled link gets aria-disabled and leaves the tab order.

As a link
button-states.html
<button type="button" class="vin-btn">
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M12 3v12M7 10l5 5 5-5M5 21h14"/></svg>
  Download
</button>
<button type="button" class="vin-btn vin-btn--outline">
  Next
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
</button>
<button type="button" class="vin-btn" disabled>Disabled</button>
<a class="vin-btn vin-btn--secondary" href="#states">As a link</a>

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add button
React
import { Button, buttonClasses } from "@/components/vin/button";
Vue
import Button, { buttonClasses } from "@/components/vin/button.vue";
Svelte
import Button, { buttonClasses } from "$lib/components/vin/button.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. It needs no JavaScript.

API

From spec/button.json, which every framework version is tested against.

PropValuesDefaultIn HTML
variantprimarysecondaryoutlineghostdangerprimaryvin-btn--{value}
sizesmmdlgiconmdvin-btn--{value}
disabledbooleanfalsedisabled attribute on <button>, aria-disabled="true" on <a>
hrefstring—renders an <a class="vin-btn"> instead of a <button>

Parts

React, Vue, SvelteHTML classes
<Button>.vin-btn.vin-btn--secondary.vin-btn--outline.vin-btn--ghost.vin-btn--danger.vin-btn--sm.vin-btn--lg.vin-btn--icon

Accessibility

  • Native <button> element, so Enter and Space work without JavaScript.
  • type="button" by default so it never submits a form by accident.
  • Icon-only buttons (size="icon") need an aria-label.
  • Visible focus ring in every style and mode.