From 4cdccfe39f422c0a33c6a622bf229cae3cb516b4 Mon Sep 17 00:00:00 2001 From: AshGDS <8880610+AshGDS@users.noreply.github.com> Date: Tue, 26 Nov 2024 15:19:14 +0000 Subject: [PATCH] Add component wrapper helper to the list component --- .../components/_list.html.erb | 18 ++++++------------ .../components/docs/list.yml | 4 +++- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/app/views/govuk_publishing_components/components/_list.html.erb b/app/views/govuk_publishing_components/components/_list.html.erb index 8c3badad12..e87b66b395 100644 --- a/app/views/govuk_publishing_components/components/_list.html.erb +++ b/app/views/govuk_publishing_components/components/_list.html.erb @@ -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" @@ -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| %>