class UiBibz::Ui::Core::Forms::Buttons::Button

Create a button

This element is an extend of UiBibz::Ui::Core::Component.

Attributes

Options

You can add HTML attributes using the html_options. You can pass arguments in options attribute:

Signatures

UiBibz::Ui::Core::Forms::Buttons::Button.new(content, options = nil, html_options = nil)

UiBibz::Ui::Core::Forms::Buttons::Button.new(options = nil, html_options = nil) do
  content
end

Examples

UiBibz::Ui::Core::Forms::Buttons::Button.new('test', type: :primary, size: :xs).render

UiBibz::Ui::Core::Forms::Buttons::Button.new(type: :primary) do
  test
end.render

Helper

ui_button(content, options = {}, html_options = {})

ui_button(options = {}, html_options = {}) do
  content
end

Public Instance Methods

pre_render() click to toggle source

Render html tag

# File lib/ui_bibz/ui/core/forms/buttons/button.rb, line 56
def pre_render
  button_html_tag
end

Protected Instance Methods

action() click to toggle source
# File lib/ui_bibz/ui/core/forms/buttons/button.rb, line 109
def action
  add_html_data('action', value: options[:action]) unless options[:action].nil?
end
active_html_options() click to toggle source
# File lib/ui_bibz/ui/core/forms/buttons/button.rb, line 105
def active_html_options
  { 'aria-pressed' => true }
end
badge_html() click to toggle source
# File lib/ui_bibz/ui/core/forms/buttons/button.rb, line 113
def badge_html
  if options[:badge].is_a? Hash
    options[:badge][:status] = options[:badge][:status] || options[:status] || :secondary
    UiBibz::Ui::Core::Notifications::Badge.new(options[:badge].delete(:content), options[:badge]).render

  else
    UiBibz::Ui::Core::Notifications::Badge.new(options[:badge], status: (options[:status] || :secondary)).render
  end
end
button_html_tag() click to toggle source
# File lib/ui_bibz/ui/core/forms/buttons/button.rb, line 62
def button_html_tag
  content_tag :button, html_options do
    concat spinner_html unless options[:spinner].nil?
    concat glyph_and_content_html(@content)
    concat badge_html unless options[:badge].nil?
  end
end
collapse() click to toggle source
# File lib/ui_bibz/ui/core/forms/buttons/button.rb, line 83
def collapse
  # Must be flat hash not deep hash
  {
    'data-bs-toggle': :collapse,
    'data-bs-target': "##{options[:collapse]}",
    'aria-controls': options[:collapse],
    'aria-expanded': options[:expand_collapse].nil? ? false : options[:expand_collapse]
  }
end
component_html_classes() click to toggle source
# File lib/ui_bibz/ui/core/forms/buttons/button.rb, line 70
def component_html_classes
  super << ['btn', size]
end
component_html_options() click to toggle source
# File lib/ui_bibz/ui/core/forms/buttons/button.rb, line 74
def component_html_options
  opts = super
  opts = opts.merge(toggle)                   unless options[:toggle].nil?
  opts = opts.merge(collapse)                 unless options[:collapse].nil?
  opts = opts.merge(active_html_options)      if options[:state] == :active
  opts = opts.merge({ disabled: 'disabled' }) if options[:state] == :disabled
  opts
end
outline() click to toggle source
# File lib/ui_bibz/ui/core/forms/buttons/button.rb, line 97
def outline
  'outline' unless options[:outline].nil?
end
size() click to toggle source

:lg, :sm or :xs

# File lib/ui_bibz/ui/core/forms/buttons/button.rb, line 131
def size
  "btn-#{options[:size]}" if options[:size]
end
spinner_html() click to toggle source
# File lib/ui_bibz/ui/core/forms/buttons/button.rb, line 123
def spinner_html
  opts = { size: :sm, tag: :span, class: options[:text] == false ? nil : 'me-2' }
  opts = opts.merge(options[:spinner]) if options[:spinner].is_a? Hash

  UiBibz::Ui::Core::Notifications::Spinner.new(nil, opts).render
end
status() click to toggle source
# File lib/ui_bibz/ui/core/forms/buttons/button.rb, line 93
def status
  ['btn', outline, options[:status] || 'secondary'].compact.join('-')
end
toggle() click to toggle source
# File lib/ui_bibz/ui/core/forms/buttons/button.rb, line 101
def toggle
  { 'data-bs-toggle' => 'button', 'aria-pressed' => false, 'autocomplete' => 'off' }
end