Sha256: f1c22abc84c3f28f12ea9e99587fdf6fc128611087fe0fb41209e8aae79e0329
Contents?: true
Size: 1.24 KB
Versions: 13
Compression:
Stored size: 1.24 KB
Contents
# frozen_string_literal: true module Bs5 class AccordionComponent < ViewComponent::Base include ComponentsHelper include ViewComponent::SlotableV2 renders_many :items, 'ItemComponent' def initialize(flush: false) @flush = flush end def flush? @flush end def id "accordion-#{object_id}" end def component_class class_names = ['accordion'] class_names << %w[accordion-flush] if flush? class_names.join(' ') end class ItemComponent < ViewComponent::Base attr_reader :title def initialize(title:, collapsed: true) @title = title @collapsed = collapsed end def call content end def id object_id end def header_id "header-#{id}" end def collapse_id "collapse-#{id}" end def collapsed? @collapsed end def button_class class_names = ['accordion-button'] class_names << %w[collapsed] if collapsed? class_names.join(' ') end def collapse_class class_names = %w[accordion-collapse collapse] class_names << %w[show] unless collapsed? class_names.join(' ') end end end end
Version data entries
13 entries across 13 versions & 1 rubygems