Skip to content

Commit

Permalink
Add the Accordion component (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
stdstaff committed Jan 19, 2023
1 parent 03acb68 commit 900341c
Show file tree
Hide file tree
Showing 9 changed files with 467 additions and 51 deletions.
96 changes: 55 additions & 41 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
govuk-design-system-rails (0.9.7)
govuk-design-system-rails (0.9.8)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -66,41 +66,54 @@ GEM
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
ast (2.4.2)
attr_extras (6.2.5)
attr_extras (7.0.0)
builder (3.2.4)
compare-xml (0.66)
nokogiri (~> 1.8)
concurrent-ruby (1.1.10)
crass (1.0.6)
date (3.3.3)
diff-lcs (1.5.0)
erubi (1.11.0)
erubi (1.12.0)
globalid (1.0.0)
activesupport (>= 5.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
json (2.6.2)
loofah (2.19.0)
json (2.6.3)
loofah (2.19.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mail (2.8.0.1)
mini_mime (>= 0.1.1)
net-imap
net-pop
net-smtp
marcel (1.0.2)
method_source (1.0.0)
mini_mime (1.1.2)
mini_portile2 (2.8.0)
minitest (5.16.3)
mini_portile2 (2.8.1)
minitest (5.17.0)
net-imap (0.3.4)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
timeout
net-smtp (0.3.3)
net-protocol
nio4r (2.5.8)
nokogiri (1.13.8)
nokogiri (1.14.0)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
optimist (3.0.1)
parallel (1.22.1)
parser (3.1.2.1)
parser (3.2.0.0)
ast (~> 2.4.1)
patience_diff (1.2.0)
optimist (~> 3.0)
racc (1.6.0)
rack (2.2.4)
racc (1.6.2)
rack (2.2.6)
rack-test (2.0.2)
rack (>= 1.3)
rails (6.1.7)
Expand All @@ -121,8 +134,8 @@ GEM
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.4.3)
loofah (~> 2.3)
rails-html-sanitizer (1.4.4)
loofah (~> 2.19, >= 2.19.1)
railties (6.1.7)
actionpack (= 6.1.7)
activesupport (= 6.1.7)
Expand All @@ -131,76 +144,77 @@ GEM
thor (~> 1.0)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.6.0)
regexp_parser (2.6.1)
rexml (3.2.5)
rspec-core (3.11.0)
rspec-support (~> 3.11.0)
rspec-expectations (3.11.1)
rspec-core (3.12.0)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-mocks (3.11.1)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-rails (6.0.0)
rspec-support (~> 3.12.0)
rspec-rails (6.0.1)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
rspec-core (~> 3.11)
rspec-expectations (~> 3.11)
rspec-mocks (~> 3.11)
rspec-support (~> 3.11)
rspec-support (3.11.1)
rubocop (1.35.0)
rspec-support (3.12.0)
rubocop (1.39.0)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.1.2.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.20.1, < 2.0)
rubocop-ast (>= 1.23.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.21.0)
rubocop-ast (1.23.0)
parser (>= 3.1.1.0)
rubocop-govuk (4.7.0)
rubocop (= 1.35.0)
rubocop-ast (= 1.21.0)
rubocop-rails (= 2.15.2)
rubocop-govuk (4.9.0)
rubocop (= 1.39.0)
rubocop-ast (= 1.23.0)
rubocop-rails (= 2.17.3)
rubocop-rake (= 0.6.0)
rubocop-rspec (= 2.12.1)
rubocop-performance (1.15.0)
rubocop-rspec (= 2.15.0)
rubocop-performance (1.15.2)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.15.2)
rubocop-rails (2.17.3)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.7.0, < 2.0)
rubocop (>= 1.33.0, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.12.1)
rubocop (~> 1.31)
rubocop-rspec (2.15.0)
rubocop (~> 1.33)
ruby-progressbar (1.11.0)
sprockets (4.1.1)
sprockets (4.2.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
rack (>= 2.2.4, < 4)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.5.3)
sqlite3 (1.6.0)
mini_portile2 (~> 2.8.0)
super_diff (0.9.0)
attr_extras (>= 6.2.4)
diff-lcs
patience_diff
thor (1.2.1)
timeout (0.3.1)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
unicode-display_width (2.3.0)
unicode-display_width (2.4.2)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.1)
zeitwerk (2.6.6)

PLATFORMS
ruby
Expand Down
7 changes: 7 additions & 0 deletions app/helpers/govuk_design_system/accordion_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module GovukDesignSystem
module AccordionHelper
def govukAccordion(kwargs = {})
render "components/govuk_accordion", **kwargs
end
end
end
44 changes: 44 additions & 0 deletions app/views/components/_govuk_accordion.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<%
id = local_assigns[:id]
heading_level = local_assigns[:headingLevel].presence || 2
div_attributes = {
id: id,
class: class_names("govuk-accordion", local_assigns[:classes]),
data: { module: "govuk-accordion" },
"data-i18n" => {}
}
div_attributes["data-i18n"]["hide-all-sections"] = local_assigns[:hideAllSectionsText] if local_assigns[:hideAllSectionsText].present?
div_attributes["data-i18n"]["hide-section"] = local_assigns[:hideSectionText] if local_assigns[:hideSectionText].present?
div_attributes["data-i18n"]["hide-section-aria-label"] = local_assigns[:hideSectionAriaLabelText] if local_assigns[:hideSectionAriaLabelText].present?
div_attributes["data-i18n"]["show-all-sections"] = local_assigns[:showAllSectionsText] if local_assigns[:showAllSectionsText].present?
div_attributes["data-i18n"]["show-section"] = local_assigns[:showSectionText] if local_assigns[:showSectionText].present?
div_attributes["data-i18n"]["show-section-aria-label"] = local_assigns[:showSectionAriaLabelText] if local_assigns[:showSectionAriaLabelText].present?
div_attributes.merge!(local_assigns[:attributes]) if local_assigns[:attributes].present?
div_attributes.delete("data-i18n") if div_attributes["data-i18n"] == {}
%>
<%= tag.div(**div_attributes) do %>
<% local_assigns[:items].each.with_index(1) do |item, index| %>
<% next unless item.present? %>
<div class="<%= class_names "govuk-accordion__section", { "govuk-accordion__section--expanded" => item[:expanded] } %>">
<div class="govuk-accordion__section-header">
<h<%= heading_level %> class="govuk-accordion__section-heading">
<span class="govuk-accordion__section-button" id="<%= id %>-heading-<%= index %>">
<%= item.dig(:heading, :html).presence || item.dig(:heading, :text) %>
</span>
</h<%= heading_level %>>
<% if item.dig(:summary, :html).present? || item.dig(:summary, :text).present? %>
<div class="govuk-accordion__section-summary govuk-body" id="<%= id %>-summary-<%= index %>">
<%= item.dig(:summary, :html).presence || item.dig(:summary, :text) %>
</div>
<% end %>
</div>
<div id="<%= id %>-content-<%= index %>" class="govuk-accordion__section-content" aria-labelledby="<%= id %>-heading-<%= index %>">
<% if item.dig(:content, :html).present? %>
<%= item.dig(:content, :html) %>
<% elsif item.dig(:content, :text).present? %>
<p class="govuk-body"><%= item.dig(:content, :text) %></p>
<% end %>
</div>
</div>
<% end %>
<% end %>
3 changes: 1 addition & 2 deletions app/views/components/_govuk_fieldset.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<%
fieldset_attributes = {
class: ("govuk-fieldset #{local_assigns[:classes]}").strip,
class: class_names("govuk-fieldset", local_assigns[:classes])
}

fieldset_attributes.merge!(role: local_assigns[:role]) if local_assigns[:role]
fieldset_attributes.merge!("aria-describedby" => local_assigns[:describedBy]) if local_assigns[:describedBy]
%>
Expand Down
2 changes: 1 addition & 1 deletion govuk_design_system-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $LOAD_PATH.push File.expand_path("lib", __dir__)

Gem::Specification.new do |s|
s.name = "govuk-design-system-rails"
s.version = "0.9.7"
s.version = "0.9.8"
s.authors = %w[OfficeForProductSafetyAndStandards]
s.summary = "An implementation of the govuk-frontend macros in Ruby on Rails"
s.test_files = Dir["spec/**/*"]
Expand Down
1 change: 1 addition & 0 deletions lib/govuk_design_system/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Engine < ::Rails::Engine
# NOTE: These includes make the helpers available in every view of the
# consuming application. If a helper is not listed here, it will be
# isolated, and unavailable to apps which use this gem.
ActionView::Base.include GovukDesignSystem::AccordionHelper
ActionView::Base.include GovukDesignSystem::BackLinkHelper
ActionView::Base.include GovukDesignSystem::BreadcrumbsHelper
ActionView::Base.include GovukDesignSystem::ButtonHelper
Expand Down

0 comments on commit 900341c

Please sign in to comment.