Class: Plushie::Widget::Checkbox

Inherits:
Object
  • Object
show all
Defined in:
lib/plushie/widget/checkbox.rb

Overview

Typed builder for the checkbox widget (Layer 2 API).

Construct a Checkbox, set properties via fluent +set_*+ methods, then call #build to produce a Node for the view tree.

Constant Summary collapse

PROPS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Supported property keys for this widget.

i[label is_toggled spacing width size text_size font
line_height shaping wrapping style icon disabled a11y].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, label, is_toggled = false, **opts) ⇒ Checkbox

Returns a new instance of Checkbox.



19
20
21
22
23
24
25
# File 'lib/plushie/widget/checkbox.rb', line 19

def initialize(id, label, is_toggled = false, **opts)
  @id = id.to_s
  @label = label
  @is_toggled = is_toggled
  PROPS.each { |k| instance_variable_set(:"@#{k}", opts[k]) if opts.key?(k) }
  @label = opts[:label] if opts.key?(:label)
end

Instance Attribute Details

#a11yObject (readonly)

Returns the value of attribute a11y.



1
2
3
# File 'lib/plushie/widget/checkbox.rb', line 1

def a11y
  @a11y
end

#disabledObject (readonly)

Returns the value of attribute disabled.



1
2
3
# File 'lib/plushie/widget/checkbox.rb', line 1

def disabled
  @disabled
end

#fontObject (readonly)

Returns the value of attribute font.



1
2
3
# File 'lib/plushie/widget/checkbox.rb', line 1

def font
  @font
end

#iconObject (readonly)

Returns the value of attribute icon.



1
2
3
# File 'lib/plushie/widget/checkbox.rb', line 1

def icon
  @icon
end

#idObject (readonly)

Returns the value of attribute id.



1
2
3
# File 'lib/plushie/widget/checkbox.rb', line 1

def id
  @id
end

#is_toggledObject (readonly)

Returns the value of attribute is_toggled.



1
2
3
# File 'lib/plushie/widget/checkbox.rb', line 1

def is_toggled
  @is_toggled
end

#labelObject (readonly)

Returns the value of attribute label.



1
2
3
# File 'lib/plushie/widget/checkbox.rb', line 1

def label
  @label
end

#line_heightObject (readonly)

Returns the value of attribute line_height.



1
2
3
# File 'lib/plushie/widget/checkbox.rb', line 1

def line_height
  @line_height
end

#shapingObject (readonly)

Returns the value of attribute shaping.



1
2
3
# File 'lib/plushie/widget/checkbox.rb', line 1

def shaping
  @shaping
end

#sizeObject (readonly)

Returns the value of attribute size.



1
2
3
# File 'lib/plushie/widget/checkbox.rb', line 1

def size
  @size
end

#spacingObject (readonly)

Returns the value of attribute spacing.



1
2
3
# File 'lib/plushie/widget/checkbox.rb', line 1

def spacing
  @spacing
end

#styleObject (readonly)

Returns the value of attribute style.



1
2
3
# File 'lib/plushie/widget/checkbox.rb', line 1

def style
  @style
end

#text_sizeObject (readonly)

Returns the value of attribute text_size.



1
2
3
# File 'lib/plushie/widget/checkbox.rb', line 1

def text_size
  @text_size
end

#widthObject (readonly)

Returns the value of attribute width.



1
2
3
# File 'lib/plushie/widget/checkbox.rb', line 1

def width
  @width
end

#wrappingObject (readonly)

Returns the value of attribute wrapping.



1
2
3
# File 'lib/plushie/widget/checkbox.rb', line 1

def wrapping
  @wrapping
end

Instance Method Details

#buildPlushie::Node

Build a Node from the current property values.

Returns:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/plushie/widget/checkbox.rb', line 36

def build
  props = {}
  Build.put_if(props, :label, @label)
  Build.put_if(props, :checked, @is_toggled)
  Build.put_if(props, :spacing, @spacing)
  Build.put_if(props, :width, @width)
  Build.put_if(props, :size, @size)
  Build.put_if(props, :text_size, @text_size)
  Build.put_if(props, :font, @font)
  Build.put_if(props, :line_height, @line_height)
  Build.put_if(props, :shaping, @shaping)
  Build.put_if(props, :wrapping, @wrapping)
  Build.put_if(props, :style, @style)
  Build.put_if(props, :icon, @icon)
  Build.put_if(props, :disabled, @disabled)
  Build.put_if(props, :a11y, @a11y)
  Node.new(id: @id, type: "checkbox", props: props)
end