Class: Shadcn::SelectComponent
- Inherits:
-
Object
- Object
- Shadcn::SelectComponent
- Includes:
- ComponentsHelper
- Defined in:
- app/components/shadcn/select_component.rb
Constant Summary
Constants included from ComponentsHelper
ComponentsHelper::DESTRUCTIVE_CLASSES, ComponentsHelper::GHOST_CLASSES, ComponentsHelper::OUTLINE_CLASSES, ComponentsHelper::PRIMARY_CLASSES, ComponentsHelper::SECONDARY_CLASSES
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#selected ⇒ Object
readonly
Returns the value of attribute selected.
-
#view_context ⇒ Object
readonly
Returns the value of attribute view_context.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(name:, view_context:, selected: nil, **options, &block) ⇒ SelectComponent
constructor
A new instance of SelectComponent.
- #option(value:, label: nil, &block) ⇒ Object
Methods included from ComponentsHelper
Constructor Details
#initialize(name:, view_context:, selected: nil, **options, &block) ⇒ SelectComponent
Returns a new instance of SelectComponent.
5 6 7 8 9 10 11 |
# File 'app/components/shadcn/select_component.rb', line 5 def initialize(name:, view_context:, selected: nil, **, &block) @name = name @view_context = view_context @selected = selected @options = @content = view_context.capture(self, &block) if block end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'app/components/shadcn/select_component.rb', line 3 def name @name end |
#selected ⇒ Object (readonly)
Returns the value of attribute selected.
3 4 5 |
# File 'app/components/shadcn/select_component.rb', line 3 def selected @selected end |
#view_context ⇒ Object (readonly)
Returns the value of attribute view_context.
3 4 5 |
# File 'app/components/shadcn/select_component.rb', line 3 def view_context @view_context end |
Instance Method Details
#call ⇒ Object
20 21 22 |
# File 'app/components/shadcn/select_component.rb', line 20 def call view_context.content_tag :select, @content, name: name, class: tw("rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", @options[:class]) end |
#option(value:, label: nil, &block) ⇒ Object
13 14 15 16 17 18 |
# File 'app/components/shadcn/select_component.rb', line 13 def option(value:, label: nil, &block) content = label || view_context.capture(&block) = {value: value} [:selected] = "selected" if value == selected view_context.content_tag :option, content, end |