From 88d116a680e22888e4f9dd4fa354551865b5768b Mon Sep 17 00:00:00 2001 From: Andy Sellick Date: Wed, 18 Dec 2024 13:13:42 +0000 Subject: [PATCH 1/2] Use component wrapper helper on published dates --- .../components/_published_dates.html.erb | 74 ++++++++++--------- app/views/components/docs/published_dates.yml | 7 +- test/components/published_dates_test.rb | 9 ++- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/app/views/components/_published_dates.html.erb b/app/views/components/_published_dates.html.erb index 8f2b370a2..eca22e07f 100644 --- a/app/views/components/_published_dates.html.erb +++ b/app/views/components/_published_dates.html.erb @@ -1,46 +1,50 @@ -<% add_app_component_stylesheet("published-dates") %> <% + add_app_component_stylesheet("published-dates") + published ||= false history ||= [] history = Array(history) last_updated ||= false link_to_history ||= false - shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns) - classes = %w(app-c-published-dates) - classes << "app-c-published-dates--history" if history.any? - classes << shared_helper.get_margin_bottom if local_assigns[:margin_bottom] + + component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns) + component_helper.add_class("app-c-published-dates") + component_helper.add_class("app-c-published-dates--history") if history.any? + component_helper.set_id("full-publication-update-history") if history.any? + component_helper.add_data_attribute({ module: "gem-toggle" }) if history.any? + component_helper.set_lang("en") %> <% if published || last_updated %> -

<%= t('components.published_dates.hidden_heading') %>

-
id="full-publication-update-history" data-module="gem-toggle"<% end %> lang="en"> - <% if published %> - <%= t('components.published_dates.published', date: published) %> - <% end %> - <% if last_updated %> - <% if published %>
<% end %><%= t('components.published_dates.last_updated', date: last_updated) %> - <% if link_to_history && history.empty? %> - — <%= t('components.published_dates.see_all_updates', locale: :en) %> - <% elsif history.any? %> - " - data-ga4-expandable - >+ <%= t('components.published_dates.show_all_updates', locale: :en) %> -
-
    - <% history.each do |change| %> -
  1. - -

    <%= change[:note].strip %>

    -
  2. - <% end %> -
-
+ <%= tag.div(**component_helper.all_attributes) do %> +

<%= t('components.published_dates.hidden_heading') %>

+ <% if published %> + <%= t('components.published_dates.published', date: published) %> + <% end %> + <% if last_updated %> + <% if published %>
<% end %><%= t('components.published_dates.last_updated', date: last_updated) %> + <% if link_to_history && history.empty? %> + — <%= t('components.published_dates.see_all_updates', locale: :en) %> + <% elsif history.any? %> + " + data-ga4-expandable + >+ <%= t('components.published_dates.show_all_updates', locale: :en) %> +
+
    + <% history.each do |change| %> +
  1. + +

    <%= change[:note].strip %>

    +
  2. + <% end %> +
+
+ <% end %> <% end %> <% end %> -
<% end %> diff --git a/app/views/components/docs/published_dates.yml b/app/views/components/docs/published_dates.yml index 0aef1bd74..382fbc193 100644 --- a/app/views/components/docs/published_dates.yml +++ b/app/views/components/docs/published_dates.yml @@ -8,6 +8,7 @@ accessibility_criteria: | - be usable with a keyboard shared_accessibility_criteria: - link +uses_component_wrapper_helper: true examples: default: data: @@ -40,9 +41,3 @@ examples: - display_time: 14th October 2000 note: Updated information on pupil premium reviews and what information schools need to publish on their websites. timestamp: 2000-10-14T15:42:37.000+00:00 - with_custom_margin_bottom: - description: | - The component accepts a number for margin bottom from 0 to 9 (0px to 60px) using the [GOV.UK Frontend spacing scale](https://design-system.service.gov.uk/styles/spacing/#the-responsive-spacing-scale). By default, the component does not have a bottom margin. - data: - published: 1st January 1990 - margin_bottom: 8 diff --git a/test/components/published_dates_test.rb b/test/components/published_dates_test.rb index 642e35263..36814aade 100644 --- a/test/components/published_dates_test.rb +++ b/test/components/published_dates_test.rb @@ -11,14 +11,15 @@ def component_name test "renders published date" do render_component(published: "1st November 2000") - assert_select ".app-c-published-dates", text: "Published 1st November 2000" + assert_select ".app-c-published-dates", text: "Updates to this page + Published 1st November 2000" end test "renders published date and last updated date" do render_component(published: "1st November 2000", last_updated: "15th July 2015") - assert_select ".app-c-published-dates", - text: "Published 1st November 2000 - Last updated 15th July 2015" + assert_select ".app-c-published-dates", text: "Updates to this page + Published 1st November 2000 + Last updated 15th July 2015" end test "links to full page history" do From 1dd5045c864a8be0fac333fca979107f9f02f67e Mon Sep 17 00:00:00 2001 From: Andy Sellick Date: Wed, 18 Dec 2024 13:13:58 +0000 Subject: [PATCH 2/2] Fix unrelated Sass warning --- app/assets/stylesheets/helpers/_parts.scss | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/assets/stylesheets/helpers/_parts.scss b/app/assets/stylesheets/helpers/_parts.scss index b5d45fa27..5d9e7041e 100644 --- a/app/assets/stylesheets/helpers/_parts.scss +++ b/app/assets/stylesheets/helpers/_parts.scss @@ -3,13 +3,12 @@ margin-top: govuk-spacing(6); margin-bottom: govuk-spacing(6); padding-bottom: govuk-spacing(3); + border-bottom: 1px solid govuk-colour("mid-grey"); @include govuk-media-query($from: tablet) { margin-top: 0; margin-bottom: 0; } - - border-bottom: 1px solid govuk-colour("mid-grey"); } .part-navigation {