Class: Sirens::Checkbox
- Inherits:
-
PrimitiveComponent
- Object
- AbstractComponent
- PrimitiveComponent
- Sirens::Checkbox
- Defined in:
- lib/components/widgets/checkbox.rb
Instance Method Summary collapse
-
#click ⇒ Object
Actions.
-
#create_view ⇒ Object
Returns a CheckboxView.
-
#default_model ⇒ Object
Returns a default model if none is given during the initialization of this component.
- #on_toggled(state:) ⇒ Object
-
#on_value_changed(announcement) ⇒ Object
Events.
- #sync_ui_from_model ⇒ Object
Methods inherited from PrimitiveComponent
#apply_props, #initialize, #on_component_added, #on_model_changed, #populate_popup_menu, #set_props, #subscribe_to_model_events
Methods inherited from AbstractComponent
#add_all_components, #add_component, #child_components, #initialize, #model, #on_component_added, #on_model_changed, open, #props, #remove_component_at, #remove_last_component, #set_model, #set_props, #view
Constructor Details
This class inherits a constructor from Sirens::PrimitiveComponent
Instance Method Details
#click ⇒ Object
Actions
19 20 21 |
# File 'lib/components/widgets/checkbox.rb', line 19 def click() view.click end |
#create_view ⇒ Object
Returns a CheckboxView.
6 7 8 |
# File 'lib/components/widgets/checkbox.rb', line 6 def create_view() CheckboxView.new(on_toggled: proc{ |state:| on_toggled(state: state) }) end |
#default_model ⇒ Object
Returns a default model if none is given during the initialization of this component.
13 14 15 |
# File 'lib/components/widgets/checkbox.rb', line 13 def default_model() ValueModel.on(false) end |
#on_toggled(state:) ⇒ Object
33 34 35 36 37 |
# File 'lib/components/widgets/checkbox.rb', line 33 def on_toggled(state:) return if model.nil? model.set_value(state) end |
#on_value_changed(announcement) ⇒ Object
Events
29 30 31 |
# File 'lib/components/widgets/checkbox.rb', line 29 def on_value_changed(announcement) view.set_value(announcement.new_value) end |
#sync_ui_from_model ⇒ Object
23 24 25 |
# File 'lib/components/widgets/checkbox.rb', line 23 def sync_ui_from_model() view.set_value(model.value) unless view.nil? end |