Provides a button UI component.
Adopting this in a host app
A mix phx.new app already has its own button/1 in CoreComponents. Both
names are in scope once you import this one, and no change here resolves that
— the ambiguity is the name plus the import, not the body. Pick one:
import MyAppWeb.CoreComponents, except: [button: 1]or delete your scaffold's version. Host LiveViews receive nothing from PhoenixKit automatically; importing is a deliberate step.
Summary
Functions
Renders a button, or a link styled as one when given a navigation attribute.
Functions
Renders a button, or a link styled as one when given a navigation attribute.
Examples
<.button>Send!</.button>
<.button phx-click="go" class="ml-2">Send!</.button>
<.button variant="ghost" size="sm">Cancel</.button>
<.button navigate={~p"/users/new"}>New user</.button>Variants
variant REPLACES the base colour rather than adding to it. It used to
append: the class list hardcoded btn-primary, so class="btn-ghost" left
both on the element and daisyUI's rule ordering decided the winner.
The vocabulary matches pk_link_button/1's, which is the kit's own set —
not the scaffold's values: ~w(primary), a knob that cannot vary. For a
colour outside it, pass class="btn-error": that is the intended escape
hatch, not a workaround.
Variant and size map to literal classes rather than interpolating
"btn-#{@variant}", because Tailwind scans source for literal class
names — an interpolated class is invisible to it and the CSS would simply not
exist unless something else in the codebase happened to write it out.
Attributes
type(:string) - Defaults tonil.variant(:string) - Base colour. Replaces the default; useclassfor anything outside this set. Defaults to"primary". Must be one of"primary","secondary","accent","neutral","ghost","link", or"outline".size(:string) - daisyUI button size. Omitted leaves daisyUI's default. Defaults tonil. Must be one ofnil,"xs","sm","md", or"lg".navigate(:string) - Renders a<.link navigate=…>instead of a button. Defaults tonil.patch(:string) - Renders a<.link patch=…>instead of a button. Defaults tonil.href(:any) - Renders a<.link href=…>instead of a button. Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted. Supports all globals plus:
["disabled", "form", "name", "value", "download", "target", "rel", "method"].
Slots
inner_block(required)