class UiBibz::Ui::Core::Notifications::Toast
Create an alert
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: (:default
,:primary
,:info
,:warning
,:danger
) -
glyph
- [String | Hash] Add glyph with name or hash options-
name
- [String]
*
timeout
- [Integer] -
Signatures¶ ↑
UiBibz::Ui::Core::Notifications::Toast.new(content, options = nil, html_options = nil) UiBibz::Ui::Core::Notifications::Toast.new(options = nil, html_options = nil) do content end
Examples¶ ↑
UiBibz::Ui::Core::Notifications::Toast.new(class: 'my-toast').tap |t| t.header "My header toast", glyph: 'eye', time: 'now' t.body "My body toast" end UiBibz::Ui::Core::Notifications::Toast.new(class: 'my-toast').tap |t| t.header glyph: 'eye', time: 'now' do My header toast end t.body class: 'my-body-toast' do My body toast end end.render
Helper¶ ↑
ui_toast(options = {}, html_options = {}) do |t| t.header "My header toast", glyph: 'eye', time: 'now' t.body "My body toast" end
Public Class Methods
new(content = nil, options = nil, html_options = nil, &block)
click to toggle source
See UiBibz::Ui::Core::Component.initialize
Calls superclass method
UiBibz::Ui::Core::Component::new
# File lib/ui_bibz/ui/core/notifications/toast.rb, line 59 def initialize(content = nil, options = nil, html_options = nil, &block) super body(@content) unless @tapped end
Public Instance Methods
body(content = nil, options = nil, html_options = nil, &block)
click to toggle source
Add Body which is a component
# File lib/ui_bibz/ui/core/notifications/toast.rb, line 78 def body(content = nil, options = nil, html_options = nil, &block) @body = if @header.nil? content_tag :div, class: 'd-flex' do concat UiBibz::Ui::Core::Notifications::Components::ToastBody.new(content, options, html_options, &block).render concat close_html if (options || {})[:closable] end else UiBibz::Ui::Core::Notifications::Components::ToastBody.new(content, options, html_options, &block).render end end
header(content = nil, options = nil, html_options = nil, &block)
click to toggle source
Add Header which is a component
# File lib/ui_bibz/ui/core/notifications/toast.rb, line 73 def header(content = nil, options = nil, html_options = nil, &block) @header = UiBibz::Ui::Core::Notifications::Components::ToastHeader.new(content, options, html_options, &block).render end
pre_render()
click to toggle source
Render html tag
# File lib/ui_bibz/ui/core/notifications/toast.rb, line 65 def pre_render content_tag :div, html_options do concat @header concat @body end end
Private Instance Methods
align_items_center()
click to toggle source
# File lib/ui_bibz/ui/core/notifications/toast.rb, line 117 def align_items_center 'align-items-center' if @header.nil? end
close_html()
click to toggle source
# File lib/ui_bibz/ui/core/notifications/toast.rb, line 95 def close_html content_tag :button, '', type: 'button', class: close_button_classes, 'data-bs-dismiss' => 'toast', 'aria-label' => 'Close' end
component_html_classes()
click to toggle source
Calls superclass method
UiBibz::Ui::Core::Component#component_html_classes
# File lib/ui_bibz/ui/core/notifications/toast.rb, line 100 def component_html_classes super << ['toast', status, white_text_color, align_items_center] end
component_html_data()
click to toggle source
Calls superclass method
UiBibz::Ui::Core::Component#component_html_data
# File lib/ui_bibz/ui/core/notifications/toast.rb, line 108 def component_html_data super add_html_data 'bs-autohide', value: options[:auto_hide] if options[:auto_hide] end
component_html_options()
click to toggle source
# File lib/ui_bibz/ui/core/notifications/toast.rb, line 104 def component_html_options { role: 'alert', 'aria-live': 'assertive', 'aria-atomic': true } end
only_body_html()
click to toggle source
# File lib/ui_bibz/ui/core/notifications/toast.rb, line 91 def only_body_html @body = UiBibz::Ui::Core::Notifications::Components::ToastBody.new(content, options, html_options, &block).render end
status()
click to toggle source
# File lib/ui_bibz/ui/core/notifications/toast.rb, line 113 def status "bg-#{options[:status]}" if options[:status] end
white_btn_color()
click to toggle source
# File lib/ui_bibz/ui/core/notifications/toast.rb, line 127 def white_btn_color return if options[:status].nil? 'btn-close-white' unless %i[info warning info light].include?(options[:status]) end
white_text_color()
click to toggle source
# File lib/ui_bibz/ui/core/notifications/toast.rb, line 121 def white_text_color return if options[:status].nil? 'text-white' unless %i[info warning info light].include?(options[:status]) end