evodata/app/helpers/application_helper.rb

27 lines
733 B
Ruby
Raw Normal View History

2021-12-18 15:52:01 +01:00
module ApplicationHelper
2023-02-26 15:09:08 +01:00
def colored_pill_tag(content_or_options_with_block = nil, options = nil, &block)
if block
options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
end
2023-02-26 15:09:08 +01:00
color_classes = case options.fetch(:color)
when "red"
"bg-red-100 text-red-800"
when "green"
"bg-green-100 text-green-800"
when "orange"
"bg-orange-100 text-orange-800"
else
"bg-gray-100 text-gray-800"
end
2023-02-26 15:09:08 +01:00
classes = "px-2 inline-flex text-xs leading-5 font-semibold rounded-full #{color_classes}"
2023-02-26 15:09:08 +01:00
if block
content_tag(:span, class: classes, &block)
else
content_tag(:span, content_or_options_with_block, class: classes)
end
2023-02-26 15:09:08 +01:00
end
2021-12-18 15:52:01 +01:00
end