04 · Forms — selection

RadioChoice

variant basic · outline · card (control start/end) · chip · segmented · tile × color × size xs–lg × shape circle/squircle

A single choice among visible options, in six forms: simple radio, outline, cards, chips, segmented and tiles.

segmented

.heex
<.radio_group id="rc-01" variant="segmented" class="w-[320px] relative [--n:3] before:absolute before:inset-y-[3px] before:left-[3px] before:w-[calc((100%-6px-2px*(var(--n)-1))/var(--n))] before:rounded-[7px] before:bg-panel before:shadow-[var(--lu-shadow-xs),0_0_0_1px_var(--lu-line)] before:animate-[lu-segslide_6s_cubic-bezier(.4,0,.2,1)_infinite] [&>button]:relative [&>button]:flex-1 [&>button]:justify-center" options={["Mensal", "Trimestral", "Anual"]} />

chip

.heex
<.radio_group id="rc-02" variant="chip" class="flex flex-wrap items-center gap-2 [&>label]:animate-[lu-chipon_6s_ease-in-out_infinite] [&>label:nth-child(2)]:[animation-delay:1.5s] [&>label:nth-child(3)]:[animation-delay:3s] [&>label:nth-child(4)]:[animation-delay:4.5s]" options={[{"Pix", "pix"}, {"Boleto", "boleto"}, {"Cartão", "cartao"}, {"Dinheiro", "dinheiro"}]} />

basic · color × size

xssmmdlgneutral
primary
secondary
info
success
warning
error
.heex
<div class="grid grid-cols-[100px_repeat(4,minmax(0,1fr))] items-center gap-x-3 gap-y-2.5"><span></span><span class="text-center font-mono text-xs text-muted">xs</span><span class="text-center font-mono text-xs text-muted">sm</span><span class="text-center font-mono text-xs text-muted">md</span><span class="text-center font-mono text-xs text-muted">lg</span><span class="font-mono text-xs text-muted">neutral</span><div class="flex min-w-0 justify-center"><.radio_group color="neutral" size="xs" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="neutral" size="sm" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="neutral" size="md" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="neutral" size="lg" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><span class="font-mono text-xs text-muted">primary</span><div class="flex min-w-0 justify-center"><.radio_group color="primary" size="xs" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="primary" size="sm" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="primary" size="md" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="primary" size="lg" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><span class="font-mono text-xs text-muted">secondary</span><div class="flex min-w-0 justify-center"><.radio_group color="secondary" size="xs" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="secondary" size="sm" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="secondary" size="md" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="secondary" size="lg" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><span class="font-mono text-xs text-muted">info</span><div class="flex min-w-0 justify-center"><.radio_group color="info" size="xs" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="info" size="sm" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="info" size="md" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="info" size="lg" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><span class="font-mono text-xs text-muted">success</span><div class="flex min-w-0 justify-center"><.radio_group color="success" size="xs" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="success" size="sm" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="success" size="md" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="success" size="lg" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><span class="font-mono text-xs text-muted">warning</span><div class="flex min-w-0 justify-center"><.radio_group color="warning" size="xs" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="warning" size="sm" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="warning" size="md" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="warning" size="lg" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><span class="font-mono text-xs text-muted">error</span><div class="flex min-w-0 justify-center"><.radio_group color="error" size="xs" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="error" size="sm" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="error" size="md" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div><div class="flex min-w-0 justify-center"><.radio_group color="error" size="lg" class="flex flex-wrap items-center gap-2.5" value="a" options={[{"", "a"}, {"", "b"}]} /></div></div>

shape · filled · outline

.heex
<.radio_group id="rc-04" color="primary" class="flex flex-wrap items-center gap-2.5">
  <:radio value="circle" checked>circle</:radio>
  <:radio value="squircle" shape="squircle" checked>squircle</:radio>
  <:radio value="filled" filled>filled</:radio>
  <:radio value="dis" disabled checked>desabilitado</:radio>
</.radio_group>

card · control start / end

.heex
<div class="grid grid-cols-2 gap-4">
  <.radio_group id="rc-05-a" name="plano" variant="card" class="flex flex-col gap-2.5" options={[%{label: "Essencial", value: "essencial", description: "Até 500 notas/mês", count: "R$ 89"}, %{label: "Profissional", value: "profissional", description: "Notas ilimitadas", count: "R$ 189"}]} />
  <.radio_group id="rc-05-b" name="plano_end" variant="card" control="end" value="essencial" class="flex flex-col gap-2.5" options={[%{label: "Essencial", value: "essencial", description: "Até 500 notas/mês", count: "R$ 89"}, %{label: "Profissional", value: "profissional", description: "Notas ilimitadas", count: "R$ 189"}]} />
</div>

chip · rounded and pill

.heex
<div class="flex flex-col gap-2.5">
  <.radio_group id="rc-06-a" variant="chip" value="boleto" options={[{"Pix", "pix"}, {"Boleto", "boleto"}, {"Cartão", "cartao"}, {"Dinheiro", "dinheiro"}]} />
  <.radio_group id="rc-06-b" variant="chip" shape="pill" color="success" value="aberto" options={[{"Aberto", "aberto"}, {"Pago", "pago"}, {"Vencido", "vencido"}]} />
</div>

tile

.heex
<.radio_group id="rc-07" variant="tile">
  <:radio value="pp">PP</:radio>
  <:radio value="p">P</:radio>
  <:radio value="m" checked>M</:radio>
  <:radio value="g">G</:radio>
  <:radio value="gg">GG</:radio>
  <:radio value="1" color="secondary">1</:radio>
  <:radio value="2" color="secondary" checked>2</:radio>
  <:radio value="3" color="secondary">3</:radio>
</.radio_group>

Usage

<.radio field={@form[:plan]} options={[{"Mensal", "m"}, {"Anual", "a"}]} />
<.radio field={@form[:plan]} variant="card" control="end" options={@plans} />
<.radio field={@form[:size]} variant="tile" options={~w(P M G GG)} />

Rules

  • card for choices with a price or description; segmented for 2 to 4 short options.
  • tile: 52px squares for sizes, numbers or letters.
  • Selected: a 1px border and ring in the color, a soft background.

API reference

Todos os function components, atributos, valores e slots que este componente cobre.

Single choice among visible options: radio_group/1, in six forms.

<.radio_group field={@form[:plan]} options={[{"Free", "free"}, {"Pro", "pro"}]} color="primary" />

<.radio_group name="basic" value="primary">
  <:radio value="default">Default</:radio>
  <:radio value="error" color="error" disabled>Error</:radio>
</.radio_group>

<.radio_group field={@form[:status]} variant="chip" options={[
  %{label: "Todos", value: "all", count: 128}, %{label: "Draft", value: "draft"}]} />

variant is basic/outline (the round radio of checkbox/1), card (with control="end"), chip (shape="pill" for round ends), segmented (the look of LedgerUI.Components.Segmented, a button per option over a real radio) and tile (a 52px square with free content and an aria_label). Every variant keeps a real radio, so the form, field errors, the arrow keys and phx-change work; the chosen look follows the radio (has-checked: utilities, and the LedgerUI.Segmented hook for segmented).

card takes <:trailing :let={opt}>: content at the right, inside the card (a badge, a button), given each option. The card then is a div (the radio, a <label for> stretched over the card and the trailing box), so a button there never sits inside a <label>: it takes its own click and does not select the radio, while a click on the card or on a non-interactive trailing selects it. A disabled option makes the whole card, trailing included, inert.

<.radio_group field={@form[:signer]} variant="card" options={@signers}>
  <:trailing :let={opt}>
    <.button :if={opt.value == "ana"} size="sm" variant="outline">Enviar certificado</.button>
  </:trailing>
</.radio_group>

Options are {label, value} tuples, plain values, maps with :label, :value, :description, :count, :icon, :color, :disabled, or :radio slots.

<.radio_group>

Attr Type Default Values / notes
id :string nil
name :string nil
value :any nil
field {:struct, Phoenix.HTML.FormField} nil
options :list []
color :string "neutral" neutral, primary, secondary, info, success, warning, error
variant :string "basic" basic, outline, card, chip, segmented, tile
control :string "start" start, end
filled :boolean false
shape :string "circle" circle, squircle, pill
size :string "md" xs, sm, md, lg
label :string nil
label_class :any nil
label_hint :string nil
help :string nil
errors :list []
disabled :boolean false
wrapper_class :any nil
radio_class :any nil
class :any nil

Any other HTML/phx attribute goes to the root element, including form, required.

Slots:

  • <:radio> - attrs: value, label, color, disabled, aria_label, description, count, icon, class, style, checked, shape, filled
  • <:trailing> - card only: content at the right of each card; receives the option (:let={opt}).

<.radio_choice>

Same as radio_group/1 (same attributes and slots), under the name the design vitrine uses.

Attr Type Default Values / notes
id :string nil
name :string nil
value :any nil
field {:struct, Phoenix.HTML.FormField} nil
options :list []
color :string "neutral" neutral, primary, secondary, info, success, warning, error
variant :string "basic" basic, outline, card, chip, segmented, tile
control :string "start" start, end
filled :boolean false
shape :string "circle" circle, squircle, pill
size :string "md" xs, sm, md, lg
label :string nil
label_class :any nil
label_hint :string nil
help :string nil
errors :list []
disabled :boolean false
wrapper_class :any nil
radio_class :any nil
class :any nil

Any other HTML/phx attribute goes to the root element, including form, required.

Slots:

  • <:radio> - attrs: value, label, color, disabled, aria_label, description, count, icon, class, style, checked, shape, filled
  • <:trailing> - card only: content at the right of each card; receives the option (:let={opt}).

<.radio>

A radio, or a group of them: with options (or <:radio> slots) it is radio_group/1; without, one radio with its label, color and size.

<.radio name="plan" value="pro" label="Pro" checked />
<.radio field={@form[:plan]} options={[{"Monthly", "m"}, {"Yearly", "y"}]} />
Attr Type Default Values / notes
id :string nil
name :string nil
value :any nil
field {:struct, Phoenix.HTML.FormField} nil
options :list []
color :string "neutral" neutral, primary, secondary, info, success, warning, error
variant :string "basic" basic, outline, card, chip, segmented, tile
control :string "start" start, end
filled :boolean false
shape :string "circle" circle, squircle, pill
size :string "md" xs, sm, md, lg
label :string nil
label_class :any nil
label_hint :string nil
help :string nil
errors :list []
disabled :boolean false
wrapper_class :any nil
radio_class :any nil
class :any nil
checked :boolean false A lone radio (no options, no <:radio>): whether it is the chosen one.

Any other HTML/phx attribute goes to the root element, including form, required.

Slots:

  • <:radio> - attrs: value, label, color, disabled, aria_label, description, count, icon, class, style, checked, shape, filled
  • <:trailing> - card only: content at the right of each card; receives the option (:let={opt}).