Class: UI::ToggleComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- UI::ToggleComponent
- Includes:
- ToggleBehavior
- Defined in:
- app/view_components/ui/toggle_component.rb
Overview
ToggleComponent - ViewComponent implementation
A two-state button that can be either on or off. Uses ToggleBehavior module for shared styling logic.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(variant: "default", size: "default", type: "button", pressed: false, disabled: false, classes: "", **attributes) ⇒ ToggleComponent
constructor
A new instance of ToggleComponent.
Methods included from ToggleBehavior
#render_toggle, #toggle_classes, #toggle_html_attributes
Constructor Details
#initialize(variant: "default", size: "default", type: "button", pressed: false, disabled: false, classes: "", **attributes) ⇒ ToggleComponent
Returns a new instance of ToggleComponent.
32 33 34 35 36 37 38 39 40 |
# File 'app/view_components/ui/toggle_component.rb', line 32 def initialize(variant: "default", size: "default", type: "button", pressed: false, disabled: false, classes: "", **attributes) @variant = variant @size = size @type = type @pressed = pressed @disabled = disabled @classes = classes @attributes = attributes end |
Instance Method Details
#call ⇒ Object
42 43 44 45 46 47 |
# File 'app/view_components/ui/toggle_component.rb', line 42 def call attrs = toggle_html_attributes attrs[:data] = attrs[:data].merge(@attributes.fetch(:data, {})) content_tag :button, content, **attrs.merge(@attributes.except(:data)) end |