Class: CCS::Components::GovUK::Tabs
- Defined in:
- lib/ccs/components/govuk/tabs.rb,
lib/ccs/components/govuk/tabs/tab.rb,
lib/ccs/components/govuk/tabs/panel.rb
Overview
GOV.UK Tabs
This is used to generate the tabs component from the GDS - Components - Tabs
Defined Under Namespace
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
The default attributes for the tabs
{ class: 'govuk-tabs', data: { module: 'govuk-tabs' } }.freeze
Instance Method Summary collapse
-
#initialize(items:, title: nil, id_prefix: nil, **options) ⇒ Tabs
constructor
A new instance of Tabs.
-
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Tabs component.
Constructor Details
#initialize(items:, title: nil, id_prefix: nil, **options) ⇒ Tabs
Returns a new instance of Tabs.
37 38 39 40 41 42 43 44 |
# File 'lib/ccs/components/govuk/tabs.rb', line 37 def initialize(items:, title: nil, id_prefix: nil, **) super(**) @title = title || 'Contents' id_prefix ||= sanitize_to_id(@title.downcase) @tabs = items.map.with_index(1) { |item, index| Tab.new(index: index, id_prefix: id_prefix, context: @context, **item) } @panels = items.map.with_index(1) { |item, index| Panel.new(index: index, id_prefix: id_prefix, context: @context, **item[:panel]) } end |
Instance Method Details
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Tabs component
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ccs/components/govuk/tabs.rb', line 50 def render tag.div(**[:attributes]) do concat(tag.h2(title, class: 'govuk-tabs__title')) if @tabs.present? concat(tag.ul(class: 'govuk-tabs__list') do @tabs.each { |tab| concat(tab.render) } end) end @panels.each { |panel| concat(panel.render) } end end |