Sha256: 92c9689e6a8c137d27f424a6d61d472cbbb13fd35c16e10fa970c8ffec2c4456

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

require_relative 'button'
require_relative 'card'
require_relative 'accordion/button'
require_relative 'accordion/card'

module Bootstrap
  module ViewHelpers
    module Components
      class Accordion < Component
        def to_html
          content_tag(:div, options.merge({ id: accordion_id })) do
            block.call(self)
          end
        end

        def group(title, options = {}, &block)
          options[:title] = title
          options[:body] = true
          options[:parent] = accordion_id
          Card.new(view, options, &block).to_html
        end

        protected

        def accordion_id
          @id ||= options[:id] || "accordion_#{random_uid}"
        end

        def random_uid
          SecureRandom.urlsafe_base64
        end

        def assign_and_validate_style
          @style = ContextualClasses::LINK
        end

        def inject_aria_attributes(opts)
          opts[:aria] ||= {}
          opts[:aria][:controls] = ''
          opts[:aria][:expanded] = false
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bootstrap-view_helpers-0.0.3 lib/bootstrap/view_helpers/components/accordion.rb
bootstrap-view_helpers-0.0.2 lib/bootstrap/view_helpers/components/accordion.rb