PUI.Button (pui v1.0.0-beta.12)

Copy Markdown

A versatile button component with multiple variants and sizes.

Basic Usage

<.button>Click me</.button>

Variants

Use the variant attribute to change the button style:

<.button variant="default">Default</.button>
<.button variant="secondary">Secondary</.button>
<.button variant="destructive">Destructive</.button>
<.button variant="outline">Outline</.button>
<.button variant="ghost">Ghost</.button>
<.button variant="link">Link</.button>

Sizes

Use the size attribute to adjust the button size:

<.button size="sm">Small</.button>
<.button size="default">Default</.button>
<.button size="lg">Large</.button>
<.button size="icon">
  <.icon name="hero-heart" />
</.button>

With Icons

Include icons within the button content:

<.button>
  <.icon name="hero-heart" class="w-4 h-4" />
  Like
</.button>

Buttons can act as links using standard Phoenix link attributes:

<.button navigate={~p"/profile"}>Navigate</.button>
<.button patch={~p"/settings"}>Patch</.button>
<.button href="/logout">Href</.button>

Disabled State

<.button disabled>Disabled</.button>

Unstyled Variant

Use variant="unstyled" for complete control over styling:

<.button variant="unstyled" class="px-4 py-2 bg-blue-500 text-white rounded">
  Custom Button
</.button>

Attributes

AttributeTypeDefaultDescription
variantstring"default"Button style variant
sizestring"default"Button size: "sm", "default", "lg", "icon"
classstring""Additional CSS classes
restglobal-HTML attributes including href, navigate, patch, disabled

Slots

SlotDescription
inner_blockButton content (required)

Summary

Functions

button(assigns)

Attributes

  • class (:string) - Defaults to "".
  • variant (:string) - Defaults to "default". Must be one of "default", "destructive", "outline", "secondary", "ghost", "link", or "unstyled".
  • size (:string) - Defaults to "default". Must be one of "default", "sm", "lg", or "icon".
  • Global attributes are accepted. Supports all globals plus: ["href", "navigate", "patch", "method", "download", "name", "value", "disabled"].

Slots

  • inner_block (required)