Sha256: 34049cf43e23e1328e841b34c2ebf5906ff7910f6c8128c67f39c71a31494425
Contents?: true
Size: 731 Bytes
Versions: 5
Compression:
Stored size: 731 Bytes
Contents
# frozen_string_literal: true module Bs5 class AlertComponent < ViewComponent::Base attr_reader :style, :is_dismissable include ActiveModel::Validations validates :style, style: true def initialize(style: :primary, is_dismissable: false) @style = style.to_sym @is_dismissable = is_dismissable end def before_render raise errors.full_messages.to_sentence if invalid? end def render? content.present? end private def component_class class_names = ['alert', contextual_class] class_names << %w[alert-dismissible fade show] if is_dismissable class_names.join(' ') end def contextual_class "alert-#{@style}" end end end
Version data entries
5 entries across 5 versions & 1 rubygems