Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alert: add alert-dismissible class #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/bh/classes/alert_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ class AlertBox < Base
def context_class
AlertBox.contexts[@options.fetch :context, @options[:priority]]
end

# @return [#to_s] the css class which indicates this box is dimissible, to assign to the alert box.
def dismissible_class
'alert-dismissible' if @options[:dismissible]
end

# @return [#to_s] the HTML to show a dismissible button for the alert box.
def dismissible_button
Expand Down
1 change: 1 addition & 0 deletions lib/bh/helpers/alert_box_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def alert_box(*args, &block)

alert_box.append_class! :alert
alert_box.append_class! alert_box.context_class
alert_box.append_class! alert_box.dismissible_class
alert_box.merge! role: :alert
alert_box.prepend_html! alert_box.dismissible_button
alert_box.render_tag :div
Expand Down
6 changes: 6 additions & 0 deletions spec/shared/alert_box_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
shared_examples_for 'the alert_box helper' do
# based on https://getbootstrap.com/components/#alerts
all_tests_pass_with 'no alert options'
all_tests_pass_with 'extra alert options'
all_tests_pass_with 'the :context alert option'
Expand Down Expand Up @@ -37,6 +38,11 @@
html = '<div class="alert alert-info" role="alert">content</div>'
expect(alert_box: {dismissible: false}).to generate html
end

specify 'set to true, adds class alert-dismissible to the alert div' do
html = %r{<div class="alert alert-info alert-dismissible"}
expect(alert_box: {dismissible: true}).to generate html
end

specify 'set to true, displays a button to dismiss the alert' do
html = %r{<span aria-hidden="true">&times;</span>}
Expand Down