Switch Edit
Examples
<%= render_switch "Ruby on Rails",
id: "ruby_on_rails",
name: "language"
%>
Installation
rails generate shadcn-ui switch
Usage
<%= render_switch text, id:, name: %>
The Switch component introduces:
app/helpers/components/switch_helper.rb
app/javascript/controllers/ui/switch_controller.js
app/views/components/ui/_switch.html.erb
render_switch
accepts one argument for the text near the switch and two keyword arguments for the id
of the button and name
of the hidden input element used to pass the form value of the state. It optionally accepts a state
keyword for the starting value of the switch.
The javascript controller is responsible for the toggle effect by changing the data-state
of the underlying elements.