Sha256: 7466428a437fafaae5d3230342b9fbdb01638b91baf286cd14ea401486419d9d

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

require 'voom/presenters/dsl/components/mixins/common'
require 'voom/presenters/dsl/components/mixins/tooltips'

module Voom
  module Presenters
    module DSL
      module Components
        class Button < EventBase
          include Mixins::Tooltips

          BUTTON_TYPES = %i(raised flat fab icon)

          attr_accessor :text, :icon, :button_type, :color, :disabled, :size, :position, :full_width, :hidden

          def initialize(type: nil, **attribs_, &block)
            @button_type = h(type) || ((attribs_[:icon] && !attribs_[:text]) ? :icon : nil) || :flat
            super(type: :button, **attribs_, &block)
            self.icon(attribs.delete(:icon)) if attribs.key?(:icon)
            @text = attribs.delete(:text)
            @color = attribs.delete(:color)
            @disabled = attribs.delete(:disabled) {false}
            @hidden = attribs.delete(:hidden) {false}
            @size = attribs.delete(:size)
            @full_width = attribs.delete(:full_width) {false}
            @position = Array(attribs.delete(:position)).compact
            expand!
            @event_parent_id = self.parent(:form)&.id || id
          end

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

          end

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

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

          private

          def menu_position
            position.include?(:right) ? :right : nil
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
voom-presenters-0.2.0 lib/voom/presenters/dsl/components/button.rb