Module: NitroKit::ButtonHelper

Includes:
Variants
Defined in:
app/helpers/nitro_kit/button_helper.rb

Instance Method Summary collapse

Methods included from Variants

included

Instance Method Details

#nk_button(text = nil, **attrs, &block) ⇒ Object



7
8
9
# File 'app/helpers/nitro_kit/button_helper.rb', line 7

def nk_button(text = nil, **attrs, &block)
  render(NitroKit::Button.from_template(text, **attrs), &block)
end

#nk_button_group(**attrs, &block) ⇒ Object



45
46
47
# File 'app/helpers/nitro_kit/button_helper.rb', line 45

def nk_button_group(**attrs, &block)
  render(ButtonGroup.from_template(**attrs), &block)
end

Matches the API of UrlHelper#link_to



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/nitro_kit/button_helper.rb', line 28

def nk_button_link_to(*args, **attrs, &block)
  case args.length
  when 1
    options, text = args
  when 2
    text, options = args
  else
    raise ArgumentError, "1..2 arguments expected, got #{args.length}"
  end

  href = attrs[:href] || url_target(text, options)

  render(NitroKit::Button.from_template(text, **attrs, href:), &block)
end

#nk_button_to(name = nil, url_for_options = nil, **attrs, &block) ⇒ Object

Matches the API of UrlHelper#button_to



14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/nitro_kit/button_helper.rb', line 14

def nk_button_to(name = nil, url_for_options = nil, **attrs, &block)
  url_for_options = name if block_given?

  form_options = attrs.delete(:form) || {}
  form_options.merge!(attrs.slice(:multipart, :data, :method, :authenticity_token, :remote, :enforce_utf8))

  form_tag(url_for_options, form_options) do
    nk_button(name, type: "submit", **attrs, &block)
  end
end