class UiBibz::Ui::Core::Forms::Buttons::Button
Create a button
This element is an extend of UiBibz::Ui::Core::Component
.
Attributes¶ ↑
-
content
- Content of element -
options
- Options of element -
html_options
- Html Options of element
Options¶ ↑
You can add HTML attributes using the html_options
. You can pass arguments in options attribute:
-
status
- status of element with symbol value: (:primary
,:secondary
,:success
, :info+,:warning
,:danger
,:light
,:dark
) -
size
(:xs
,:sm
,:lg
) -
outline
- Boolean -
state
- Symbol (:active
, +:disabled) -
collapse
- String -
expand_collaspe
- Boolean -
glyph
- Add glyph with name or hash options-
name
- String -
size
- Integer -
type
- Symbol
-
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
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
Calls superclass method
UiBibz::Ui::Core::Component#component_html_classes
# 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
Calls superclass method
UiBibz::Ui::Core::Component#component_html_options
# 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