lib/voom/presenters/dsl/components/button.rb in voom-presenters-0.2.0 vs lib/voom/presenters/dsl/components/button.rb in voom-presenters-2.0.0
- old
+ new
@@ -1,39 +1,39 @@
-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
+ include Mixins::Padding
BUTTON_TYPES = %i(raised flat fab icon)
- attr_accessor :text, :icon, :button_type, :color, :disabled, :size, :position, :full_width, :hidden
+ attr_accessor :text, :icon, :button_type, :color, :background_color, :disabled,
+ :size, :position, :full_width, :hidden, :wrap_text, :disabled_on_post_finished
def initialize(type: nil, **attribs_, &block)
- @button_type = h(type) || ((attribs_[:icon] && !attribs_[:text]) ? :icon : nil) || :flat
+ @button_type = 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)
+ @background_color = attribs.delete(:background_color)
+ self.icon(attribs.delete(:icon), color: color) if attribs.key?(:icon)
+ @text = attribs.delete(:text)
@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
+ @wrap_text = attribs.delete(:wrap_text) {true}
+ @position = Array(default_position).compact
+ @disabled_on_post_finished = attribs.delete(:disabled_on_post_finished) {false}
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)
-
+ @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)
@@ -43,9 +43,13 @@
return @menu if locked?
@menu = Components::Menu.new(parent: self, position: menu_position, **attributes, &block)
end
private
+
+ def default_position
+ attribs.delete(:position){button_type == :fab ? %i(top right) : nil}
+ end
def menu_position
position.include?(:right) ? :right : nil
end
end