Class: NitroKit::Fieldset
- Defined in:
- app/components/nitro_kit/fieldset.rb
Constant Summary
Constants inherited from Component
Component::ADDITIVE_DATA_ATTRIBUTES, Component::COMPONENT_OWNED_DATA_ATTRIBUTES, Component::FORBIDDEN_ATTRIBUTES, Component::RESERVED_DATA_ATTRIBUTES
Instance Method Summary collapse
- #description(text = nil, &block) ⇒ Object
- #html_legend ⇒ Object
-
#initialize(legend: nil, description: nil, disabled: false, name: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Fieldset
constructor
A new instance of Fieldset.
- #legend(text = nil, &block) ⇒ Object
- #view_template(&block) ⇒ Object
Constructor Details
#initialize(legend: nil, description: nil, disabled: false, name: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Fieldset
Returns a new instance of Fieldset.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/components/nitro_kit/fieldset.rb', line 7 def initialize( legend: nil, description: nil, disabled: false, name: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil ) @legend_content = content_from_keyword(:legend, legend) @description_content = content_from_keyword(:description, description) disabled = validate_boolean!(:disabled, disabled) super( component: :fieldset, attributes: { disabled:, name: }.compact, html:, aria:, data:, desperately_need_a_class: ) end |
Instance Method Details
#description(text = nil, &block) ⇒ Object
51 52 53 54 |
# File 'app/components/nitro_kit/fieldset.rb', line 51 def description(text = nil, &block) @description_content = declare_content(:description, @description_content, text, &block) nil end |
#html_legend ⇒ Object
5 |
# File 'app/components/nitro_kit/fieldset.rb', line 5 alias :html_legend :legend |
#legend(text = nil, &block) ⇒ Object
46 47 48 49 |
# File 'app/components/nitro_kit/fieldset.rb', line 46 def legend(text = nil, &block) @legend_content = declare_content(:legend, @legend_content, text, &block) nil end |
#view_template(&block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/components/nitro_kit/fieldset.rb', line 31 def view_template(&block) raise ArgumentError, "Fieldset requires a block" unless block fields = capture(self) { |fieldset| yield fieldset } require_content!("Fieldset", :legend, @legend_content) fieldset(**root_attributes) do html_legend(**slot_attributes(:legend)) { render_deferred_content(@legend_content) } if @description_content p(**slot_attributes(:description)) { render_deferred_content(@description_content) } end div(**slot_attributes(:fields)) { raw(safe(fields)) } end end |