diff --git a/README.md b/README.md index dd5b657..032aeb3 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Itacomp is a [View Component](https://viewcomponent.org/) and [Helper](https://a * [ita_progress](app/helpers/itacomp/common_helper.rb) * [ita_spinner](app/helpers/itacomp/common_helper.rb) * [ita_visually_hidden](app/helpers/itacomp/common_helper.rb) +* [ita_badge](app/helpers/itacomp/common_helper.rb) * [ita_size](app/helpers/itacomp/common_helper.rb) * [ita_bg](app/helpers/itacomp/common_helper.rb) * [ita_text](app/helpers/itacomp/common_helper.rb) diff --git a/app/helpers/itacomp/common_helper.rb b/app/helpers/itacomp/common_helper.rb index f018589..94fbc8a 100644 --- a/app/helpers/itacomp/common_helper.rb +++ b/app/helpers/itacomp/common_helper.rb @@ -133,6 +133,19 @@ def ita_progress(value = nil, type: nil) tag.div tag.div(**opts), class: progress_class end + # return a span.badge tag with an optional span.visually-hidden tag + # + # ==== Options + # * value [String], default nil, mandatory.badge content + # * msg [String], default nil, optional visually-hidden span message for accessibility + # * :class [String,Array] default nil, if present is added as tag class after badge + # * **opts [Hash] default {}, each other named params is delegated to span.badge tag. + def ita_badge(value, msg = nil, **opts) + opts[:class] = [ "badge", opts[:class] ] + hidden = msg.present? ? ita_visually_hidden(msg) : nil + safe_join([ tag.span(value, **opts), hidden ]) + end + # return size class from bootstrap-italia size types. # # ==== Options diff --git a/test/helpers/common_helper_test.rb b/test/helpers/common_helper_test.rb index 43d4887..9a6f541 100644 --- a/test/helpers/common_helper_test.rb +++ b/test/helpers/common_helper_test.rb @@ -33,6 +33,12 @@ class CommonHelperTest < ActionView::TestCase assert_equal '