Switch

The switch' fancy cousin
Includes a Ruby component and corresponding Rails helper
Ruby
Includes a Stimulus controller
Stimulus

Example

<%= nk_switch %>

Form use

To use in forms, it's easiest to use the Form Builder.

f.switch tries to match Rails' own API.

For extra convenience use the f.field method.

At least for a little bit
<%= nk_form_with model: @session do |f| %>
  <%= f.field :remember_me,
    as: :switch,
    label: "Remember me",
    description: "At least for a little bit" %>
<% end %>

With a label

To add a label, use the label: argument.

<%= nk_switch label: "Accept your fate" %>

Sizes

:sm
:md

Usage

nk_switch(size: :md, **attrs)
PropertyDefaultDescription
size:mdOne of :sm / :md
**attrsHTML attributes for <button> element