Sha256: 0a5e0f9cfb94aaad230892a851e14185bc1135257f4a959ab3084494de6e5550

Contents?: true

Size: 1012 Bytes

Versions: 14

Compression:

Stored size: 1012 Bytes

Contents

# frozen_string_literal: true

module Bs5
  class ButtonGroupComponent < ViewComponent::Base
    SIZES = { small: :sm, large: :lg }.with_indifferent_access.freeze
    CLASS_PREFIX = 'btn-group'

    attr_reader :vertical, :size

    def initialize(options = {})
      @options = options.symbolize_keys
      @vertical = @options.delete(:vertical)
      @size = @options.delete(:size)
    end

    def render?
      content.present?
    end

    def component_attributes
      default_options = { role: 'group' }
      @options[:class] = component_class
      @options.merge(default_options)
    end

    private

    def component_class
      class_names = Array(@options[:class])
      class_names << vertical_class
      class_names << size_class
      class_names
    end

    def vertical_class
      @vertical ? "#{CLASS_PREFIX}-vertical" : CLASS_PREFIX
    end

    def size_class
      return unless size?

      [CLASS_PREFIX, SIZES[size]].join('-')
    end

    def size?
      !!size
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
bs5-0.0.31 app/components/bs5/button_group_component.rb
bs5-0.0.30 app/components/bs5/button_group_component.rb
bs5-0.0.29 app/components/bs5/button_group_component.rb
bs5-0.0.28 app/components/bs5/button_group_component.rb
bs5-0.0.27 app/components/bs5/button_group_component.rb
bs5-0.0.26 app/components/bs5/button_group_component.rb
bs5-0.0.25 app/components/bs5/button_group_component.rb
bs5-0.0.24 app/components/bs5/button_group_component.rb
bs5-0.0.23 app/components/bs5/button_group_component.rb
bs5-0.0.22 app/components/bs5/button_group_component.rb
bs5-0.0.21 app/components/bs5/button_group_component.rb
bs5-0.0.20 app/components/bs5/button_group_component.rb
bs5-0.0.19 app/components/bs5/button_group_component.rb
bs5-0.0.18 app/components/bs5/button_group_component.rb