Shadwire

Search the documentation

Search the documentation and component pages by title and by content.

Get started
Introduction
Installation
shadwire.json
Theming
Dark mode
Tools
CLI
Agent skill
Registry
llms.txt
Guides
Composition
Styling
Forms
Icons
Accessibility
Localisation
Blocks
Overview
Components
Overview
Accordion
Alert
Alert Dialog
Aspect Ratio
Avatar
Badge
Breadcrumb
Button
Button Group
Calendar
Card
Carousel
Chart
Checkbox
Collapsible
Combobox
Command
Context Menu
Data Table
Date Picker
Dialog
Drawer
Dropdown Menu
Empty
Field
Hover Card
Icon
Input
Input Group
Input OTP
Item
Kbd
Label
Menubar
Native Select
Navigation Menu
Pagination
Popover
Progress
Radio Group
Resizable
Scroll Area
Select
Separator
Sheet
Sidebar
Skeleton
Slider
Sonner
Spinner
Switch
Table
Tabs
Textarea
Toggle
Toggle Group
Tooltip

Button

Displays a button, or an element that looks like one.

Installation

Shadwire follows shadcn/ui's open code model: the component's source is copied into your application and becomes yours. Install it with the CLI:

shadwire add button --yes

The button registry item installs these files:

  • app/components/ui_component.rb
  • app/components/ui/button_component.rb
  • app/helpers/ui/button_helper.rb
  • vendor/shadwire/shadwire.css

Haven't installed the CLI yet? gem install shadwire, then shadwire init.

Usage

Use the ui_button helper in any view. It takes the same arguments as the component.

<%= ui_button { "Save" } %>
<%= ui_button(variant: :outline, size: :sm) { "Cancel" } %>

Or render the component Ui::ButtonComponent directly:

<%= render Ui::ButtonComponent.new(variant: :destructive) do %>
  Delete
<% end %>

Examples

Default

The default variant, used for a screen's primary action.

<%= ui_button { "Button" } %>

Secondary

A lower-emphasis alternative for secondary actions.

<%= ui_button(variant: :secondary) { "Secondary" } %>

Destructive

For destructive actions, such as deleting a record.

<%= ui_button(variant: :destructive) { "Destructive" } %>

Outline

A border and no fill, for neutral actions.

<%= ui_button(variant: :outline) { "Outline" } %>

Ghost

No background and no border until hover.

<%= ui_button(variant: :ghost) { "Ghost" } %>

Icon

A square icon-only button (size: :icon). Pass label: on the icon for screen readers.

<%= ui_button(size: :icon, variant: :secondary) do %>
  <%= ui_icon("chevron-right", label: "Next") %>
<% end %>

With icon

Put a ui_icon inside the block and the button sizes the SVG for you.

<%= ui_button do %>
  <%= ui_icon("download") %>
  Download
<% end %>

Sizes

The :sm, :default and :lg sizes side by side.

<%= ui_button(size: :sm) { "Small" } %>
<%= ui_button(size: :default) { "Default" } %>
<%= ui_button(size: :lg) { "Large" } %>

Loading

A loading state: a spinning icon, with the button disabled.

<%= ui_button(variant: :outline, disabled: true) do %>
  <%= ui_icon("loader-circle", class: "animate-spin") %>
  Please wait
<% end %>

Disabled

Pass disabled: true as an HTML attribute.

<%= ui_button(disabled: true) { "Disabled" } %>

API reference

ui_button(**options, &block) wraps Ui::ButtonComponent.new(**options).

Argument Type Default Description
variant Symbol :default :default, :secondary, :destructive, :outline, :ghost, :link
size Symbol :default :default, :sm, :lg, :icon
tag Symbol :button The HTML tag to render (e.g. :button, :a).
disabled Boolean false Renders data-disabled. With tag: :button it also renders disabled by default.
focusable_when_disabled Boolean false With disabled: true, keeps the native button focusable through aria-disabled="true" and tabindex="0" instead of disabled.
class / class_name String nil Extra classes, merged after the variant and size classes.
**attrs Hash {} Free HTML attributes (href, data:, aria:, …).
&block Block — The button's content: text, a ui_icon, or both.