Sha256: cbcdce6d129009b914a591acd485c10ef4066207bfc0a3e3d0f271a06518e8b3

Contents?: true

Size: 1.68 KB

Versions: 12

Compression:

Stored size: 1.68 KB

Contents

module Coprl
  module Presenters
    module DSL
      module Components
        class Header < Base
          attr_accessor :title, :image, :placement

          VALID_PLACEMENTS = %i[static fixed].freeze

          def initialize(**attribs_, &block)
            super(type: :header,
                  **attribs_, &block)
            self.title(attribs.delete(:title)) if attribs.key?(:title)
            @image = attribs.delete(:image)
            @placement = validate_placement(attribs.delete(:placement) { :static })
            expand!
          end

          def button(icon=nil, **attributes, &block)
            return @button if locked?
            @button = Components::Button.new(icon: icon, parent: self, **attributes, &block)
          end

          def menu(**attribs, &block)
            return @menu if locked?
            @menu = Components::Menu.new(parent: self,
                             **attribs, &block)
          end

          def nav(**attribs, &block)
            return @nav if locked?
            @nav = Components::Menu.new(parent: self,
                                         **attribs, &block)
          end

          def title(*text, **attribs, &block)
            return @title if locked?
            @title = Components::Typography.new(parent: self, type: :text, text: text, **attribs, &block)
          end

          private

          def validate_placement(value)
            return unless value

            placement = value.to_sym

            unless VALID_PLACEMENTS.include?(placement)
              raise Errors::ParameterValidation, "Invalid placement specified: #{placement}"
            end

            placement
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
coprl-3.0.0.beta.12 lib/coprl/presenters/dsl/components/header.rb
coprl-3.0.0.beta.11 lib/coprl/presenters/dsl/components/header.rb
coprl-3.0.0.beta.10 lib/coprl/presenters/dsl/components/header.rb
coprl-3.0.0.beta.9 lib/coprl/presenters/dsl/components/header.rb
coprl-3.0.0.beta.8 lib/coprl/presenters/dsl/components/header.rb
coprl-3.0.0.beta.7 lib/coprl/presenters/dsl/components/header.rb
coprl-3.0.0.beta.6 lib/coprl/presenters/dsl/components/header.rb
coprl-3.0.0.beta.5 lib/coprl/presenters/dsl/components/header.rb
coprl-3.0.0.beta.4 lib/coprl/presenters/dsl/components/header.rb
coprl-3.0.0.beta.3 lib/coprl/presenters/dsl/components/header.rb
coprl-3.0.0.beta.2 lib/coprl/presenters/dsl/components/header.rb
coprl-3.0.0.beta.1 lib/coprl/presenters/dsl/components/header.rb