Class: Plushie::Widget::Sensor
- Inherits:
-
Object
- Object
- Plushie::Widget::Sensor
- Defined in:
- lib/plushie/widget/sensor.rb
Overview
Sensor -- detects visibility and size changes on child content.
Props:
- delay (integer) -- delay in ms before emitting events.
- anticipate (number) -- anticipation distance in pixels.
- on_resize (string) -- event tag for resize events.
- event_rate (integer) -- max events per second.
- a11y (hash) -- accessibility overrides.
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[delay anticipate on_resize event_rate a11y].freeze
Instance Attribute Summary collapse
-
#a11y ⇒ Object
readonly
Returns the value of attribute a11y.
-
#anticipate ⇒ Object
readonly
Returns the value of attribute anticipate.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#delay ⇒ Object
readonly
Returns the value of attribute delay.
-
#event_rate ⇒ Object
readonly
Returns the value of attribute event_rate.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#on_resize ⇒ Object
readonly
Returns the value of attribute on_resize.
Instance Method Summary collapse
- #build ⇒ Plushie::Node
-
#initialize(id, **opts) ⇒ Sensor
constructor
A new instance of Sensor.
-
#push(child) ⇒ Sensor
Append a child widget.
Constructor Details
#initialize(id, **opts) ⇒ Sensor
Returns a new instance of Sensor.
29 30 31 32 33 |
# File 'lib/plushie/widget/sensor.rb', line 29 def initialize(id, **opts) @id = id.to_s @children = opts.delete(:children) || [] PROPS.each { |k| instance_variable_set(:"@#{k}", opts[k]) if opts.key?(k) } end |
Instance Attribute Details
#a11y ⇒ Object (readonly)
Returns the value of attribute a11y.
1 2 3 |
# File 'lib/plushie/widget/sensor.rb', line 1 def a11y @a11y end |
#anticipate ⇒ Object (readonly)
Returns the value of attribute anticipate.
1 2 3 |
# File 'lib/plushie/widget/sensor.rb', line 1 def anticipate @anticipate end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
1 2 3 |
# File 'lib/plushie/widget/sensor.rb', line 1 def children @children end |
#delay ⇒ Object (readonly)
Returns the value of attribute delay.
1 2 3 |
# File 'lib/plushie/widget/sensor.rb', line 1 def delay @delay end |
#event_rate ⇒ Object (readonly)
Returns the value of attribute event_rate.
1 2 3 |
# File 'lib/plushie/widget/sensor.rb', line 1 def event_rate @event_rate end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
1 2 3 |
# File 'lib/plushie/widget/sensor.rb', line 1 def id @id end |
#on_resize ⇒ Object (readonly)
Returns the value of attribute on_resize.
1 2 3 |
# File 'lib/plushie/widget/sensor.rb', line 1 def on_resize @on_resize end |
Instance Method Details
#build ⇒ Plushie::Node
49 50 51 52 53 54 55 56 57 |
# File 'lib/plushie/widget/sensor.rb', line 49 def build props = {} PROPS.each do |key| val = instance_variable_get(:"@#{key}") Build.put_if(props, key, val) end Node.new(id: @id, type: "sensor", props: props, children: Build.children_to_nodes(@children)) end |
#push(child) ⇒ Sensor
Append a child widget.
44 45 46 |
# File 'lib/plushie/widget/sensor.rb', line 44 def push(child) dup.tap { _1.instance_variable_set(:@children, @children + [child]) } end |