Sha256: 3a36fc62e0a0054db24a8cb3b1061b49ef2a8d725a8eccc98f5cba553443f47a

Contents?: true

Size: 1.74 KB

Versions: 14

Compression:

Stored size: 1.74 KB

Contents

require_relative 'input'

module Voom
  module Presenters
    module DSL
      module Components
        class Select < Input

          attr_reader :required, :full_width, :options

          def initialize(**attribs_, &block)
            super(type: :select, **attribs_, &block)
            @required = attribs.delete(:required)
            @full_width = attribs.delete(:full_width) || true
            @options = []
            expand!
          end

          def label(text=nil)
            return @label if locked?
            @label = text
          end

          def icon(icon=nil, **attribs, &block)
            return @icon if locked?
            @icon = Components::Icon.new(parent: self, icon: icon,
                                         context: context,
                                         **attribs, &block)
          end

          def option(**attribs, &block)
            @options << Option.new(parent: self,
                                   context: context,
                                   **attribs, &block)
          end

          class Option < Base
            attr_reader :selected, :disabled

            def initialize(**attribs_, &block)
              super(type: :select_option, **attribs_, &block)
              @value = self.value(attribs.delete(:value))
              @text = self.text(attribs.delete(:text))
              @selected =  attribs.delete(:selected)
              @disabled =  attribs.delete(:disabled)
              expand!
            end

            def value(value=nil)
              return @value if locked?
              @value = value
            end

            def text(text=nil)
              return @text if locked?
              @text = text
            end
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
voom-presenters-0.1.13 lib/voom/presenters/dsl/components/select.rb
voom-presenters-0.1.12 lib/voom/presenters/dsl/components/select.rb
voom-presenters-0.1.11 lib/voom/presenters/dsl/components/select.rb
voom-presenters-0.1.10 lib/voom/presenters/dsl/components/select.rb
voom-presenters-0.1.9 lib/voom/presenters/dsl/components/select.rb
voom-presenters-0.1.8 lib/voom/presenters/dsl/components/select.rb
voom-presenters-0.1.7 lib/voom/presenters/dsl/components/select.rb
voom-presenters-0.1.6 lib/voom/presenters/dsl/components/select.rb
voom-presenters-0.1.5 lib/voom/presenters/dsl/components/select.rb
voom-presenters-0.1.4 lib/voom/presenters/dsl/components/select.rb
voom-presenters-0.1.3 lib/voom/presenters/dsl/components/select.rb
voom-presenters-0.1.2 lib/voom/presenters/dsl/components/select.rb
voom-presenters-0.1.1 lib/voom/presenters/dsl/components/select.rb
voom-presenters-0.1.0 lib/voom/presenters/dsl/components/select.rb