Class: Plushie::Widget::Button
- Inherits:
-
Object
- Object
- Plushie::Widget::Button
- Defined in:
- lib/plushie/widget/button.rb
Overview
Typed builder for the button widget (Layer 2 API).
Construct a Button, set properties via fluent +set_+ methods, then call #build to produce a Node for the view tree. Each +set_+ method returns a shallow copy, so the original is never mutated -- safe for reuse across renders.
PROPS holds the list of supported property keys: label, width, height, padding, clip, style, disabled, a11y.
Constant Summary collapse
- PROPS =
Supported property keys for the button widget.
i[label width height padding clip style disabled a11y].freeze
Instance Attribute Summary collapse
-
#a11y ⇒ Object
readonly
Returns the value of attribute a11y.
-
#clip ⇒ Object
readonly
Returns the value of attribute clip.
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#padding ⇒ Object
readonly
Returns the value of attribute padding.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#build ⇒ Plushie::Node
Build a Node from the current property values.
-
#initialize(id, label = nil, **opts) ⇒ Button
constructor
A new instance of Button.
Constructor Details
#initialize(id, label = nil, **opts) ⇒ Button
Returns a new instance of Button.
31 32 33 34 35 36 |
# File 'lib/plushie/widget/button.rb', line 31 def initialize(id, label = nil, **opts) @id = id.to_s @label = label PROPS.each { |k| instance_variable_set(:"@#{k}", opts[k]) if opts.key?(k) } @label ||= opts[:label] end |
Instance Attribute Details
#a11y ⇒ Object (readonly)
Returns the value of attribute a11y.
1 2 3 |
# File 'lib/plushie/widget/button.rb', line 1 def a11y @a11y end |
#clip ⇒ Object (readonly)
Returns the value of attribute clip.
1 2 3 |
# File 'lib/plushie/widget/button.rb', line 1 def clip @clip end |
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
1 2 3 |
# File 'lib/plushie/widget/button.rb', line 1 def disabled @disabled end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
1 2 3 |
# File 'lib/plushie/widget/button.rb', line 1 def height @height end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
1 2 3 |
# File 'lib/plushie/widget/button.rb', line 1 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
1 2 3 |
# File 'lib/plushie/widget/button.rb', line 1 def label @label end |
#padding ⇒ Object (readonly)
Returns the value of attribute padding.
1 2 3 |
# File 'lib/plushie/widget/button.rb', line 1 def padding @padding end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
1 2 3 |
# File 'lib/plushie/widget/button.rb', line 1 def style @style end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
1 2 3 |
# File 'lib/plushie/widget/button.rb', line 1 def width @width end |
Instance Method Details
#build ⇒ Plushie::Node
Build a Node from the current property values.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/plushie/widget/button.rb', line 47 def build props = {} Build.put_if(props, :label, @label) Build.put_if(props, :width, @width) Build.put_if(props, :height, @height) Build.put_if(props, :padding, @padding) Build.put_if(props, :clip, @clip) Build.put_if(props, :style, @style) Build.put_if(props, :disabled, @disabled) Build.put_if(props, :a11y, @a11y) Node.new(id: @id, type: "button", props: props) end |