Class: Sirens::RadioButton

Inherits:
PrimitiveComponent show all
Defined in:
lib/components/widgets/radio_button.rb

Instance Method Summary collapse

Methods inherited from PrimitiveComponent

#apply_props, #initialize, #on_component_added, #on_model_changed, #populate_popup_menu, #set_props, #subscribe_to_model_events, #sync_ui_from_model

Methods inherited from AbstractComponent

#add_all_components, #add_component, #child_components, #default_model, #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

#clickObject

Actions



17
18
19
# File 'lib/components/widgets/radio_button.rb', line 17

def click()
    view.click
end

#create_viewObject

Returns a ButtonView.



6
7
8
9
10
11
12
13
# File 'lib/components/widgets/radio_button.rb', line 6

def create_view()
    previous_button = props[:previous_button].nil? ? nil : props[:previous_button].view

    RadioButtonView.new(
        previous_button: previous_button,
        on_toggled: proc{ |state:| on_toggled(state: state) }
    )
end

#on_toggled(state:) ⇒ Object



27
28
29
30
31
# File 'lib/components/widgets/radio_button.rb', line 27

def on_toggled(state:)
    return if model.nil?

    model.set_selection(props[:id]) if state == true
end

#on_value_changed(announcement) ⇒ Object

Events



23
24
25
# File 'lib/components/widgets/radio_button.rb', line 23

def on_value_changed(announcement)
    view.set_value(announcement.new_value)
end