Class: UI::ToggleGroup
- Inherits:
-
Phlex::HTML
- Object
- Phlex::HTML
- UI::ToggleGroup
- Includes:
- ToggleGroupBehavior
- Defined in:
- app/components/ui/toggle_group.rb
Overview
ToggleGroup - Phlex implementation
A container for a set of toggle items that can be toggled on or off. Supports single and multiple selection modes.
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Accessor for child components to get parent context.
Instance Method Summary collapse
-
#initialize(type: "single", variant: "default", size: "default", value: nil, spacing: 0, orientation: nil, classes: "", **attributes) ⇒ ToggleGroup
constructor
A new instance of ToggleGroup.
- #view_template(&block) ⇒ Object
Methods included from ToggleGroupBehavior
#toggle_group_classes, #toggle_group_html_attributes
Constructor Details
#initialize(type: "single", variant: "default", size: "default", value: nil, spacing: 0, orientation: nil, classes: "", **attributes) ⇒ ToggleGroup
Returns a new instance of ToggleGroup.
31 32 33 34 35 36 37 38 39 40 |
# File 'app/components/ui/toggle_group.rb', line 31 def initialize(type: "single", variant: "default", size: "default", value: nil, spacing: 0, orientation: nil, classes: "", **attributes) @type = type @variant = variant @size = size @value = value @spacing = spacing @orientation = orientation @classes = classes @attributes = attributes end |
Instance Attribute Details
#context ⇒ Object (readonly)
Accessor for child components to get parent context
63 64 65 |
# File 'app/components/ui/toggle_group.rb', line 63 def context @context end |
Instance Method Details
#view_template(&block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/components/ui/toggle_group.rb', line 42 def view_template(&block) div(**toggle_group_html_attributes.deep_merge(@attributes)) do # Store context for child items to access via thread-local # This works across both Phlex internal render and Rails render calls @context = { variant: @variant, size: @size, type: @type, spacing: @spacing, value: @value } Thread.current[:ui_toggle_group_context] = @context begin yield if block_given? ensure Thread.current[:ui_toggle_group_context] = nil end end end |