Sha256: b0045c20f23161e4788fa67562dde7013af20e13b6670399fb877498d6b3ce90
Contents?: true
Size: 877 Bytes
Versions: 12
Compression:
Stored size: 877 Bytes
Contents
# frozen_string_literal: true module Bs5 class BadgeComponent < ViewComponent::Base STYLES = %i[primary secondary success danger warning info light dark].freeze attr_reader :text, :color include ActiveModel::Validations validates :color, style: true def initialize(text:, color: :secondary, pill: false) @text = text @color = color.to_sym @pill = pill end def before_render raise errors.full_messages.to_sentence if invalid? end private def component_class class_names = ['badge', contextual_class] class_names << %w[rounded-pill] if pill? class_names.join(' ') end def pill? @pill end def contextual_class class_names = ["bg-#{@color}"] class_names << %w[text-dark] if color.in?(%i[warning info light]) class_names.join(' ') end end end
Version data entries
12 entries across 12 versions & 1 rubygems