Class: NitroKit::PageHeader
- Defined in:
- app/components/nitro_kit/page_header.rb
Defined Under Namespace
Classes: Child
Constant Summary collapse
- TITLE_LEVELS =
(1..6).freeze
Constants inherited from Component
Component::ADDITIVE_DATA_ATTRIBUTES, Component::COMPONENT_OWNED_DATA_ATTRIBUTES, Component::FORBIDDEN_ATTRIBUTES, Component::RESERVED_DATA_ATTRIBUTES
Instance Attribute Summary collapse
-
#level ⇒ Object
readonly
Returns the value of attribute level.
Instance Method Summary collapse
- #actions(component, &content) ⇒ Object
- #description(text = nil, &block) ⇒ Object
- #eyebrow(text = nil, &block) ⇒ Object
-
#initialize(title: nil, eyebrow: nil, description: nil, level: 1, id: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ PageHeader
constructor
A new instance of PageHeader.
- #title(text = nil, &block) ⇒ Object
- #view_template {|_self| ... } ⇒ Object
Constructor Details
#initialize(title: nil, eyebrow: nil, description: nil, level: 1, id: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ PageHeader
Returns a new instance of PageHeader.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/components/nitro_kit/page_header.rb', line 8 def initialize( title: nil, eyebrow: nil, description: nil, level: 1, id: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil ) @title_content = content_from_keyword(:title, title) @eyebrow_content = content_from_keyword(:eyebrow, eyebrow) @description_content = content_from_keyword(:description, description) @level = validate_choice!(:level, level, TITLE_LEVELS) @actions = nil super( component: :page_header, attributes: { id: }.compact, html:, aria:, data:, desperately_need_a_class: ) end |
Instance Attribute Details
#level ⇒ Object (readonly)
Returns the value of attribute level.
35 36 37 |
# File 'app/components/nitro_kit/page_header.rb', line 35 def level @level end |
Instance Method Details
#actions(component, &content) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'app/components/nitro_kit/page_header.rb', line 66 def actions(component, &content) unless component.is_a?(NitroKit::ButtonGroup) raise ArgumentError, "PageHeader actions must be a NitroKit::ButtonGroup" end raise ArgumentError, "PageHeader accepts at most one actions group" if @actions @actions = Child.new(component:, content:) nil end |
#description(text = nil, &block) ⇒ Object
61 62 63 64 |
# File 'app/components/nitro_kit/page_header.rb', line 61 def description(text = nil, &block) @description_content = declare_content(:description, @description_content, text, &block) nil end |
#eyebrow(text = nil, &block) ⇒ Object
51 52 53 54 |
# File 'app/components/nitro_kit/page_header.rb', line 51 def eyebrow(text = nil, &block) @eyebrow_content = declare_content(:eyebrow, @eyebrow_content, text, &block) nil end |
#title(text = nil, &block) ⇒ Object
56 57 58 59 |
# File 'app/components/nitro_kit/page_header.rb', line 56 def title(text = nil, &block) @title_content = declare_content(:title, @title_content, text, &block) nil end |
#view_template {|_self| ... } ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/components/nitro_kit/page_header.rb', line 37 def view_template yield self if block_given? require_content!("PageHeader", :title, @title_content) header(**root_attributes) do p(**slot_attributes(:eyebrow)) { render_deferred_content(@eyebrow_content) } if @eyebrow_content public_send(:"h#{level}", **slot_attributes(:title)) { render_deferred_content(@title_content) } if @description_content p(**slot_attributes(:description)) { render_deferred_content(@description_content) } end render_in_slot(@actions.component, :actions, &@actions.content) if @actions end end |