PhoenixDuskmoon.Component.Action.Button (PhoenixDuskmoon v10.1.4)

Copy Markdown View Source

Button component using el-dm-button custom element.

Provides four button modes:

  • Standard button with variants and sizes
  • Native submit button for forms that must work without JavaScript
  • Button with confirmation modal (Invoker Commands API)
  • Noise effect button (decorative)

When command / commandfor or interestfor are set, renders a native <button> so the invoker APIs work (custom element hosts are not valid invokers). Set native_submit to render a native <button type="submit"> without the custom element runtime.

Pass aria-label for icon-only buttons or aria-labelledby to reference labels in the same document. The custom element synchronizes these attributes and changes to referenced labels with its native shadow button.

With confirm, interestfor, title, and accessible labels/descriptions also reach the visible trigger. Caller styles stay on that trigger. LiveView events, hooks, and form submission attributes stay on the confirmed action, whose ID is #{id}-confirm. Labels are retained on the action as well; tooltip targeting and anchor styles are not.

Examples

<.dm_btn>Click me</.dm_btn>

<.dm_btn variant="primary" size="lg">Primary</.dm_btn>

<.dm_btn variant="error" confirm="Are you sure?">Delete</.dm_btn>

<.dm_btn native_submit variant="primary">Save</.dm_btn>

<.dm_btn command="show-modal" commandfor="my-modal">Open</.dm_btn>

<.dm_btn noise content="SUBMIT">Submit</.dm_btn>

Summary

Functions

Generates a button.

Functions

dm_btn(assigns)

@spec dm_btn(map()) :: Phoenix.LiveView.Rendered.t()

Generates a button.

Examples

<.dm_btn id="show-btn">Show</.dm_btn>

<.dm_btn variant="primary" size="lg">Primary Button</.dm_btn>

<.dm_btn navigate="/dashboard" variant="ghost">Dashboard</.dm_btn>

<.dm_btn native_submit variant="primary">Save</.dm_btn>

<.dm_btn confirm="Are you sure?" confirm_title="Confirm Action">Delete</.dm_btn>

Attributes

  • id (:any) - HTML id attribute. Defaults to nil.
  • class (:any) - Additional CSS classes. Defaults to nil.
  • variant (:string) - Button color variant. Defaults to nil. Must be one of nil, "primary", "secondary", "accent", "info", "success", "warning", "error", "ghost", "link", or "outline".
  • size (:string) - Button size. Defaults to nil. Must be one of nil, "xs", "sm", "md", or "lg".
  • shape (:string) - Button shape. Defaults to nil. Must be one of nil, "square", or "circle".
  • loading (:boolean) - Show loading state. Defaults to false.
  • disabled (:boolean) - Disable the button. Defaults to false.
  • native_submit (:boolean) - Render a native submit button for forms that must work without JavaScript. Defaults to false.
  • navigate (:string) - Navigates from a LiveView to a new LiveView. Defaults to nil.
  • patch (:string) - Patches the current LiveView. Defaults to nil.
  • href (:any) - Uses traditional browser navigation to the new location. Defaults to nil.
  • replace (:boolean) - Replace browser history when using navigate or patch. Defaults to false.
  • noise (:boolean) - Use noise effect button style. Defaults to false.
  • content (:string) - Content text for noise button. Defaults to "".
  • confirm (:string) - Confirmation message (enables confirm modal). Defaults to "".
  • confirm_title (:string) - Title for confirmation modal. Defaults to "".
  • confirm_text (:string) - Text for the confirm button in modal. Defaults to "Yes".
  • cancel_text (:string) - Text for the cancel button in modal. Defaults to "Cancel".
  • confirm_class (:any) - CSS class for confirm button. Defaults to nil.
  • cancel_class (:any) - CSS class for cancel button. Defaults to nil.
  • show_cancel_action (:boolean) - Show cancel button in modal. Defaults to true.
  • confirm_label (:string) - Accessible fallback label for confirm modal when no title is set (i18n). Defaults to "Confirmation".
  • Global attributes are accepted. Additional HTML attributes. Supports all globals plus: ["phx-click", "phx-target", "phx-value-id", "phx-disable-with", "name", "value", "type", "form", "command", "commandfor", "interestfor"].

Slots

  • inner_block (required) - Button content.
  • prefix - Content before button text (e.g., icon).
  • suffix - Content after button text (e.g., icon).
  • confirm_action - Custom confirm action button content.