Class: NitroKit::Label
- Defined in:
- app/components/nitro_kit/label.rb
Constant Summary
Constants inherited from Component
Component::ADDITIVE_DATA_ATTRIBUTES, Component::COMPONENT_OWNED_DATA_ATTRIBUTES, Component::FORBIDDEN_ATTRIBUTES, Component::RESERVED_DATA_ATTRIBUTES
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text = nil, for: nil, id: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Label
constructor
A new instance of Label.
- #view_template(&block) ⇒ Object
Constructor Details
#initialize(text = nil, for: nil, id: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Label
Returns a new instance of Label.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/components/nitro_kit/label.rb', line 5 def initialize( text = nil, for: nil, id: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil ) if !text.nil? && (!text.is_a?(String) || text.strip.empty?) raise ArgumentError, "label text must be a non-blank String" end @text = text super( component: :label, attributes: { for:, id: }.compact, html:, aria:, data:, desperately_need_a_class: ) end |
Instance Attribute Details
#text ⇒ Object (readonly)
Returns the value of attribute text.
29 30 31 |
# File 'app/components/nitro_kit/label.rb', line 29 def text @text end |
Instance Method Details
#view_template(&block) ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/components/nitro_kit/label.rb', line 31 def view_template(&block) if text.nil? && !block raise ArgumentError, "label requires text or a block" end label(**root_attributes) { text_or_block(text, &block) } end |