Skip to content

Commit

Permalink
Add component wrapper helper to the list component
Browse files Browse the repository at this point in the history
  • Loading branch information
AshGDS committed Jan 10, 2025
1 parent 6f6e033 commit 4cdccfe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
18 changes: 6 additions & 12 deletions app/views/govuk_publishing_components/components/_list.html.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
<%
aria_label ||= nil
extra_spacing ||= nil
id ||= nil
items ||= []
list_type ||= "unordered"
visible_counters ||= nil

shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)

classes = %w[gem-c-list govuk-list]
classes << "govuk-list--bullet" if visible_counters and list_type === "unordered"
classes << "govuk-list--number" if visible_counters and list_type === "number"
classes << "govuk-list--spaced" if extra_spacing
# Setting the `margin_bottom` to 4 is the same as the default margin - so we
# can omit the override class. To do this we leave out `4` from the array:
classes << shared_helper.get_margin_bottom if [0,1,2,3,5,6,7,8,9].include?(local_assigns[:margin_bottom])
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("gem-c-list govuk-list")
component_helper.add_class("govuk-list--bullet") if visible_counters and list_type === "unordered"
component_helper.add_class("govuk-list--number") if visible_counters and list_type === "number"
component_helper.add_class("govuk-list--spaced") if extra_spacing

# Default list type is unordered list.
list_tag = "ul"
Expand All @@ -23,7 +17,7 @@
list_tag = "ol" if list_type === "number"
%>
<% if items.any? %>
<%= content_tag list_tag, class: classes, id: id, "aria-label": aria_label do %>
<%= content_tag list_tag, **component_helper.all_attributes do %>
<% items.each do |item| %>
<li><%= raw(item) %></li>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ body: |
The `items` parameter can include HTML to display - such as links or another
list. This HTML can either be directly coded or come from another component.
uses_component_wrapper_helper: true
accessibility_criteria: |
The list must:
Expand All @@ -31,7 +32,8 @@ examples:
unordered_list_with_aria-label:
description: "A list with an aria-label"
data:
aria_label: "A list of delicious chocolate bars."
aria:
label: "A list of delicious chocolate bars."
<<: *default-example-data
unordered_list_with_bullet_points:
description: "An unordered list with visible bullet points."
Expand Down

0 comments on commit 4cdccfe

Please sign in to comment.