Class: NitroKit::Card
- Defined in:
- app/components/nitro_kit/card.rb
Constant Summary collapse
- TITLE_LEVELS =
(1..6).freeze
Constants inherited from Component
NitroKit::Component::ADDITIVE_DATA_ATTRIBUTES, NitroKit::Component::COMPONENT_OWNED_DATA_ATTRIBUTES, NitroKit::Component::FORBIDDEN_ATTRIBUTES, NitroKit::Component::RESERVED_DATA_ATTRIBUTES
Instance Method Summary collapse
- #body(text = nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &block) ⇒ Object
- #divider(html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Object
- #footer(text = nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &block) ⇒ Object
- #full(html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Object
- #html_body ⇒ Object
- #html_footer ⇒ Object
- #html_title ⇒ Object
-
#initialize(id: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Card
constructor
A new instance of Card.
- #title(text = nil, level: 2, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &block) ⇒ Object
- #view_template ⇒ Object
Constructor Details
#initialize(id: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Card
Returns a new instance of Card.
7 8 9 10 11 12 13 14 15 16 |
# File 'app/components/nitro_kit/card.rb', line 7 def initialize(id: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) super( component: :card, attributes: { id: }.compact, html:, aria:, data:, desperately_need_a_class: ) end |
Instance Method Details
#body(text = nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &block) ⇒ Object
37 38 39 40 41 42 |
# File 'app/components/nitro_kit/card.rb', line 37 def body(text = nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &block) require_region!(:body, text, block) div(**slot_attributes(:body, html:, aria:, data:, desperately_need_a_class:)) do text_or_block(text, &block) end end |
#divider(html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Object
51 52 53 |
# File 'app/components/nitro_kit/card.rb', line 51 def divider(html: {}, aria: {}, data: {}, desperately_need_a_class: nil) hr(**slot_attributes(:divider, html:, aria:, data:, desperately_need_a_class:)) end |
#footer(text = nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &block) ⇒ Object
44 45 46 47 48 49 |
# File 'app/components/nitro_kit/card.rb', line 44 def (text = nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &block) require_region!(:footer, text, block) (**slot_attributes(:footer, html:, aria:, data:, desperately_need_a_class:)) do text_or_block(text, &block) end end |
#full(html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Object
55 56 57 58 59 |
# File 'app/components/nitro_kit/card.rb', line 55 def full(html: {}, aria: {}, data: {}, desperately_need_a_class: nil) raise ArgumentError, "Card full requires a block" unless block_given? div(**slot_attributes(:full, html:, aria:, data:, desperately_need_a_class:)) { yield } end |
#html_body ⇒ Object
25 |
# File 'app/components/nitro_kit/card.rb', line 25 alias :html_body :body |
#html_footer ⇒ Object
26 |
# File 'app/components/nitro_kit/card.rb', line 26 alias :html_footer :footer |
#html_title ⇒ Object
24 |
# File 'app/components/nitro_kit/card.rb', line 24 alias :html_title :title |
#title(text = nil, level: 2, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &block) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'app/components/nitro_kit/card.rb', line 28 def title(text = nil, level: 2, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &block) validate_choice!(:level, level, TITLE_LEVELS) require_region!(:title, text, block) public_send( :"h#{level}", **slot_attributes(:title, html:, aria:, data:, desperately_need_a_class:) ) { text_or_block(text, &block) } end |
#view_template ⇒ Object
18 19 20 21 22 |
# File 'app/components/nitro_kit/card.rb', line 18 def view_template raise ArgumentError, "Card requires a block" unless block_given? article(**root_attributes) { yield } end |