diff --git a/CHANGELOG.md b/CHANGELOG.md index 317ff09..bf85a02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## [Unreleased] -* no unreleased changes * +* fix cancel modal button +* re-introdce `btn-default` style +* fix `bootstrap_tab_nav_tag` helper method with required classes +* allow more padding at the end for `bootstrap_list_badge_and_link_to` +* fix offset class name in line with Bootstrap 5 upgrade +* fix `bootstrap_alert_tag` style with close button option + ## 5.0.0 / 2025-01-24 ### Changed diff --git a/app/assets/stylesheets/ndr_ui/index.scss b/app/assets/stylesheets/ndr_ui/index.scss index 993f94e..2bc60c1 100644 --- a/app/assets/stylesheets/ndr_ui/index.scss +++ b/app/assets/stylesheets/ndr_ui/index.scss @@ -19,3 +19,9 @@ $bootstrap-icons-font-dir: "."; border:0; } } + +// Bootstrap don't have btn-default anymore +// however, we keep btn-default in codebase/helpers and set global default setting here. +.btn-default { + @extend .btn-outline-secondary; +} diff --git a/app/helpers/ndr_ui/bootstrap/modal_helper.rb b/app/helpers/ndr_ui/bootstrap/modal_helper.rb index 20f2143..789bd2a 100644 --- a/app/helpers/ndr_ui/bootstrap/modal_helper.rb +++ b/app/helpers/ndr_ui/bootstrap/modal_helper.rb @@ -218,7 +218,7 @@ def bootstrap_modal_save_buttons end def bootstrap_modal_button(label) - button_tag(label, class: 'btn btn-default', 'data-bs-dismiss': 'modal') + button_tag(label, type: 'button', class: 'btn btn-default', 'data-bs-dismiss': 'modal') end private diff --git a/app/helpers/ndr_ui/bootstrap_helper.rb b/app/helpers/ndr_ui/bootstrap_helper.rb index dffb8aa..14e5cd1 100644 --- a/app/helpers/ndr_ui/bootstrap_helper.rb +++ b/app/helpers/ndr_ui/bootstrap_helper.rb @@ -51,8 +51,8 @@ def select_tag(name, option_tags = nil, options = {}) # <%= bootstrap_alert_tag(:info) do %> # Check it out!! # <% end %> - # # =>
Check it out!!
+ # # =>
Check it out!! + #
# # Ids for css and/or javascript are easy to produce: # @@ -79,7 +79,7 @@ def bootstrap_alert_tag(*args, &block) options['class'] = classes.join(' ') if options.delete('dismissible') - message = button_tag('', type: 'button', class: 'btn-close', 'data-bs-dismiss': 'alert') + message + message = message.html_safe + button_tag('', type: 'button', class: 'btn-close', 'data-bs-dismiss': 'alert') end content_tag(:div, message, options) end @@ -203,16 +203,18 @@ def bootstrap_icon_spinner(type = :default) # ==== Examples # # <%= bootstrap_tab_nav_tag("Fruits", "#fruits", true) %> - # # =>
  • Fruits
  • + # # => def bootstrap_tab_nav_tag(title, linkto, active = false) content_tag('li', - link_to(title, linkto, 'data-bs-toggle': 'tab'), - active ? { class: 'active' } : {}) + link_to(title, linkto, 'data-bs-toggle': 'tab', class: "nav-link#{active ? ' active' : ''}"), + class: 'nav-item') end # Convenience wrapper for a bootstrap_list_link_to with badge def bootstrap_list_badge_and_link_to(type, count, name, path) - html = content_tag(:div, bootstrap_badge_tag(type, count), class: 'float-end') + name + html = content_tag(:div, bootstrap_badge_tag(type, count), class: 'float-end') + + content_tag(:div, name, class: 'pe-5') + bootstrap_list_link_to(html, path) end @@ -306,7 +308,7 @@ def bootstrap_form_with(**options, &block) # <%= button_control_group("Apples", class: "some_class") %> # # => #
    - #
    + #
    #
    Apples
    #
    #
    @@ -386,7 +388,7 @@ def bootstrap_progressbar_tag(*args) # def bootstrap_horizontal_form_group(label = nil, ratio = [2, 10], &block) l, r = ratio[0..1].map(&:to_i) - offset = label.nil? ? " col-sm-offset-#{l}" : '' + offset = label.nil? ? " offset-sm-#{l}" : '' # Main content: content = content_tag(:div, class: "col-sm-#{r}" + offset, &block) diff --git a/test/helpers/ndr_ui/bootstrap_helper_test.rb b/test/helpers/ndr_ui/bootstrap_helper_test.rb index ddf0a5d..f0af737 100644 --- a/test/helpers/ndr_ui/bootstrap_helper_test.rb +++ b/test/helpers/ndr_ui/bootstrap_helper_test.rb @@ -8,17 +8,17 @@ module NdrUi # Test bootstrap helpers class BootstrapHelperTest < ActionView::TestCase test 'bootstrap_alert_tag with message parameter' do - assert_dom_equal '
    ' \ + assert_dom_equal '
    Apples' \ '' \ - 'Apples
    ', + '
    ', bootstrap_alert_tag(:danger, 'Apples') - assert_dom_equal '
    ' \ + assert_dom_equal '
    Apples' \ '' \ - 'Apples
    ', + '
    ', bootstrap_alert_tag(:warning, 'Apples') - assert_dom_equal '
    ' \ + assert_dom_equal '
    Apples' \ '' \ - 'Apples
    ', + '
    ', bootstrap_alert_tag(:info, 'Apples') assert_dom_equal '
    ' \ '' \ @@ -28,15 +28,15 @@ class BootstrapHelperTest < ActionView::TestCase '' \ '
    ', bootstrap_alert_tag(:success, '') - assert_dom_equal '
    ' \ + assert_dom_equal '
    Apples' \ '' \ - 'Apples
    ', + '
    ', bootstrap_alert_tag(:warning, 'Apples', dismissible: true) assert_dom_equal '
    Apples
    ', bootstrap_alert_tag(:warning, 'Apples', dismissible: false) - assert_dom_equal '
    ' \ + assert_dom_equal '
    Apples' \ '' \ - 'Apples
    ', + '
    ', bootstrap_alert_tag(:warning, 'Apples', dismissible: true, id: 'apple_123') assert_dom_equal '
    Apples
    ', bootstrap_alert_tag(:warning, 'Apples', dismissible: false, id: 'apple_123') @@ -45,9 +45,9 @@ class BootstrapHelperTest < ActionView::TestCase end test 'bootstrap_alert_tag with message block' do - assert_dom_equal '
    ' \ + assert_dom_equal '
    Pears' \ '' \ - 'Pears
    ', + '
    ', bootstrap_alert_tag(:info) { 'Pears' } assert_dom_equal '
    ' \ @@ -121,11 +121,11 @@ class BootstrapHelperTest < ActionView::TestCase end test 'bootstrap_tab_nav_tag' do - assert_dom_equal '
  • Fruits
  • ', + assert_dom_equal '', bootstrap_tab_nav_tag('Fruits', '#fruits') - assert_dom_equal '
  • Fruits
  • ', + assert_dom_equal '', bootstrap_tab_nav_tag('Fruits', '#fruits', false) - assert_dom_equal '
  • Fruits
  • ', + assert_dom_equal '', bootstrap_tab_nav_tag('Fruits', '#fruits', true) end @@ -135,7 +135,7 @@ class BootstrapHelperTest < ActionView::TestCase refute current_page?(inbox_path) html = content_tag(:div, bootstrap_badge_tag(:important, 99), class: 'float-end') - html += 'Inbox' + html += content_tag(:div, 'Inbox', class: 'pe-5') assert_dom_equal content_tag(:li, link_to(html, inbox_path, class: 'dropdown-item')), bootstrap_list_badge_and_link_to(:important, 99, 'Inbox', inbox_path) end @@ -298,14 +298,14 @@ class BootstrapHelperTest < ActionView::TestCase # TODO: bootstrap_pagination_tag(*args, &block) test 'button_control_group' do - assert_dom_equal '
    ' \ + assert_dom_equal '
    ' \ 'Apples
    ', button_control_group('Apples') html = button_control_group(class: 'some_class') do 'Pears' end - assert_dom_equal '
    ' \ + assert_dom_equal '
    ' \ '
    Pears
    ', html @@ -346,7 +346,7 @@ class BootstrapHelperTest < ActionView::TestCase # Test with no label: actual = bootstrap_horizontal_form_group { 'This is the content' } - expected = '
    ' \ + expected = '
    ' \ 'This is the content
    ' assert_dom_equal expected, actual end