Sha256: c7de7db3560e596ed5e8b77ca41450cbf37bb9ed691097b56aefa9b4b1ab25ad

Contents?: true

Size: 834 Bytes

Versions: 1

Compression:

Stored size: 834 Bytes

Contents

# frozen_string_literal: true

module Phlexi
  module Display
    module Components
      class Base < COMPONENT_BASE
        attr_reader :field, :attributes

        def initialize(field, **attributes)
          @field = field
          @attributes = attributes

          build_attributes
          append_attribute_classes
        end

        protected

        def build_attributes
          attributes.fetch(:id) { attributes[:id] = "#{field.dom.id}_#{component_name}" }
        end

        def append_attribute_classes
          return if attributes[:class] == false

          attributes[:class] = tokens(
            component_name,
            attributes[:class]
          )
        end

        def component_name
          @component_name ||= self.class.name.demodulize.underscore
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
phlexi-display-0.0.2 lib/phlexi/display/components/base.rb