Class: NitroKit::DataSection
- Defined in:
- app/components/nitro_kit/data_section.rb
Defined Under Namespace
Classes: Child
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
- #actions(component, &content) ⇒ Object
- #description(text = nil, &block) ⇒ Object
- #empty_state(component, &content) ⇒ Object
- #html_table ⇒ Object
-
#initialize(title: nil, description: nil, id: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ DataSection
constructor
A new instance of DataSection.
- #table(component, &content) ⇒ Object
- #title(text = nil, &block) ⇒ Object
- #view_template {|_self| ... } ⇒ Object
Constructor Details
#initialize(title: nil, description: nil, id: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ DataSection
Returns a new instance of DataSection.
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/data_section.rb', line 7 def initialize( title: nil, description: nil, id: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil ) @title_content = content_from_keyword(:title, title) @description_content = content_from_keyword(:description, description) @actions = nil @content = nil super( component: :data_section, attributes: { id: }.compact, html:, aria:, data:, desperately_need_a_class: ) end |
Instance Method Details
#actions(component, &content) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'app/components/nitro_kit/data_section.rb', line 62 def actions(component, &content) unless component.is_a?(NitroKit::ButtonGroup) || component.is_a?(NitroKit::Button) raise ArgumentError, "DataSection actions must be a NitroKit::ButtonGroup or NitroKit::Button" end raise ArgumentError, "DataSection accepts at most one actions group" if @actions @actions = Child.new(component:, content:) nil end |
#description(text = nil, &block) ⇒ Object
55 56 57 58 |
# File 'app/components/nitro_kit/data_section.rb', line 55 def description(text = nil, &block) @description_content = declare_content(:description, @description_content, text, &block) nil end |
#empty_state(component, &content) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'app/components/nitro_kit/data_section.rb', line 80 def empty_state(component, &content) unless component.is_a?(NitroKit::EmptyState) raise ArgumentError, "DataSection empty_state must be a NitroKit::EmptyState" end raise ArgumentError, "DataSection EmptyState must use level: 3" if component.level != 3 assign_content(component, &content) end |
#html_table ⇒ Object
60 |
# File 'app/components/nitro_kit/data_section.rb', line 60 alias :html_table :table |
#table(component, &content) ⇒ Object
72 73 74 75 76 77 78 |
# File 'app/components/nitro_kit/data_section.rb', line 72 def table(component, &content) unless table_component?(component) raise ArgumentError, "DataSection table must be a NitroKit::Table or NitroKit::DetailsTable" end assign_content(component, &content) end |
#title(text = nil, &block) ⇒ Object
50 51 52 53 |
# File 'app/components/nitro_kit/data_section.rb', line 50 def title(text = nil, &block) @title_content = declare_content(:title, @title_content, text, &block) nil end |
#view_template {|_self| ... } ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/components/nitro_kit/data_section.rb', line 31 def view_template yield self if block_given? require_content!("DataSection", :title, @title_content) raise ArgumentError, "DataSection requires exactly one table or EmptyState" unless @content section(**root_attributes) do header(**slot_attributes(:header)) do div(**slot_attributes(:heading)) do h2(**slot_attributes(:title)) { render_deferred_content(@title_content) } if @description_content p(**slot_attributes(:description)) { render_deferred_content(@description_content) } end end render_in_slot(@actions.component, :actions, &@actions.content) if @actions end render_in_slot(@content.component, content_slot, &@content.content) end end |