Skip to content
Components

Switch

An on or off setting that submits like a checkbox.

After the one-time setup, call the helper directly from ERB. No component import is needed.

<%= lc_stack gap: :related do %>
  <%= lc_switch "Public project", name: "project[public]", checked: true %>
  <%= lc_switch "Allow comments", name: "project[comments]", hint: "Members can comment on pages." %>
<% end %>
<%= lc_stack gap: :related do %>
  <%= lc_switch "Public project", name: "project[public]", checked: true %>
  <%= lc_switch "Allow comments", name: "project[comments]", hint: "Members can comment on pages." %>
<% end %>

Helpers render semantic HTML and include their interaction wiring. Pass native attributes through class:, data:, aria: and the usual Rails options. Blocks use captured ERB content.

lc_switch

lc_switch(label, name: nil, value: "1", checked: false, unchecked_value: "0", hint: nil, **attributes)
InputDefaultValues
labelRequiredAccessible name, visible where applicable
namenil—
value"1"—
checkedfalsetrue · false
unchecked_value"0"—
hintnil—
attributes{}Native HTML attributes; class:, data: and aria: merge with defaults

The examples also use lc_stack. Each is documented on its own page.

Styling and extension

Use class: to merge utilities, native attributes for application behavior, and the theming guide for the shared palette. For custom markup, the advanced class helpers expose the same styles, including glass surfaces and class merging.

API JSON · LLM reference