Class: NitroKit::Card

Inherits:
Component
  • Object
show all
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

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


44
45
46
47
48
49
# File 'app/components/nitro_kit/card.rb', line 44

def footer(text = nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &block)
  require_region!(:footer, text, block)
  html_footer(**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

Raises:

  • (ArgumentError)


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_bodyObject



25
# File 'app/components/nitro_kit/card.rb', line 25

alias :html_body :body


26
# File 'app/components/nitro_kit/card.rb', line 26

alias :html_footer :footer

#html_titleObject



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_templateObject

Raises:

  • (ArgumentError)


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