Button

What happens if I press this huge red one labeled "Don't touch!"
Includes a Ruby component and corresponding Rails helper
Ruby

Example

<%= nk_button("Button") %>

See API compatibility for link_to and button_to examples.

Variants

Nitro Kit gives you 4 variants by default. Most buttons in your app should just be buttons. Every page should preferably not have more than one primary button.

nk_button

nk_primary_button

nk_destructive_button

nk_ghost_button

Read more about variants

Sizes

:xs
:sm
:md

With icons

<%= nk_button(icon: "fuel") %>
<%= nk_button("Text and icon", icon: "caravan") %>
<%= nk_button("Icon right", icon_right: "car") %>

Button groups

<%= nk_button_group do %>
  <%= nk_button("Button") %>
  <%= nk_button("Button") %>
  <%= nk_primary_button("Button") %>
<% end %>

API compatibility

nk_button_link_to

Matches link_to

Go home
nk_button_to

Matches button_to

<%= nk_button_link_to "Go home", root_path %>

<%= nk_destructive_button_to "Delete post", posts_path,
    method: :delete, data: { turbo_frame: "test-result" }  %>

Usage

nk_button(
  text = nil,
  href: nil,
  variant: :default,
  size: :md,
  icon: nil,
  icon_right: nil,
  **attrs
) { ... }
PropertyDefaultDescription
textnilPlain text content
hrefnil If truthy, the button will be an a element. Otherwise it's button.
variant:defaultOne of :default / :primary / :destructive / :ghost
size:mdOne of :xs / :sm / :md
iconnil Left side icon. See Icon docs.
icon_rightnil Right side icon. See Icon docs.
**attrsHTML attributes for <button> element
nk_button_group(**attrs) { ... }
PropertyDefaultDescription
**attrsHTML attributes for <div> element