Skip to content

Commit

Permalink
Switch components to new system
Browse files Browse the repository at this point in the history
- switch any components using the shared_helper for margin_bottom, that also use the component wrapper helper, to not use the shared_helper for margin_bottom
- note that some components still use the shared_helper for margin_bottom, but aren't using the component wrapper helper yet, so can't be switched
  • Loading branch information
andysellick committed Dec 13, 2024
1 parent f75cc44 commit bfad545
Show file tree
Hide file tree
Showing 16 changed files with 7 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.set_id(id)
component_helper.add_class("gem-c-accordion govuk-accordion")
component_helper.add_class(shared_helper.get_margin_bottom)

component_helper.add_data_attribute({ module: "govuk-accordion gem-accordion" })
component_helper.add_data_attribute({ module: "ga4-event-tracker" }) unless disable_ga4
component_helper.add_data_attribute({ ga4_expandable: "" }) unless disable_ga4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
add_gem_component_stylesheet("action-link")

local_assigns[:margin_bottom] ||= 0
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)

text ||= false
nowrap_text ||= false
href ||= false
Expand All @@ -26,7 +24,6 @@
css_classes << "gem-c-action-link--simple-light" if simple_light
css_classes << "gem-c-action-link--with-subtext" if subtext
css_classes << "gem-c-action-link--mobile-subtext" if mobile_subtext
css_classes << shared_helper.get_margin_bottom

link_classes = %w(govuk-link gem-c-action-link__link gem-c-force-print-link-styles)
link_classes << "govuk-link--inverse" if inverse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
minimal ||= false
hide_heading ||= minimal
link ||= false
local_assigns[:margin_bottom] ||= 3

chart_id = "chart-id-#{SecureRandom.hex(4)}"
table_id = "table-id-#{SecureRandom.hex(4)}"
@external_script ||= OpenStruct.new(loaded: 0)
@external_script[:loaded] += 1

chart_helper = GovukPublishingComponents::Presenters::ChartHelper.new(local_assigns)
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("gem-c-chart")
component_helper.add_class(shared_helper.get_margin_bottom)
component_helper.add_class("gem-c-chart--minimal") if minimal

require "chartkick"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
border_bottom ||= false
disable_ga4 ||= false
margin_top_until_tablet ||= false
local_assigns[:margin_bottom] ||= 6

component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("gem-c-chat-entry")
component_helper.add_class("gem-c-chat-entry--border-top") if border_top
component_helper.add_class("gem-c-chat-entry--border-bottom") if border_bottom
component_helper.add_class("gem-c-chat-entry--margin-top-until-tablet") if margin_top_until_tablet
component_helper.add_class(shared_helper.get_margin_bottom)
component_helper.add_data_attribute({ module: "ga4-link-tracker" }) unless disable_ga4

unless disable_ga4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
local_assigns[:aria] ||= {}
local_assigns[:margin_bottom] ||= 4

shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
cl_helper = GovukPublishingComponents::Presenters::ContentsListHelper.new(local_assigns)
brand_helper = GovukPublishingComponents::AppHelpers::BrandHelper.new(brand)

Expand All @@ -29,7 +28,6 @@
component_helper.add_class("gem-c-contents-list #{brand_helper.brand_class}")
component_helper.add_class("gem-c-contents-list--alternative-line-style") if alternative_line_style
component_helper.add_class("gem-c-contents-list--custom-title") if title
component_helper.add_class(shared_helper.get_margin_bottom)
component_helper.add_data_attribute({ module: "ga4-link-tracker" }) unless disable_ga4
component_helper.add_aria_attribute({ label: t("components.contents_list.contents") }) unless local_assigns[:aria][:label]
component_helper.add_role("navigation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
disable_ga4 ||= false
request.query_parameters[:disable_ga4] = disable_ga4
navigation = GovukPublishingComponents::Presenters::ContextualNavigation.new(content_item, request)
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
show_ukraine_cta = navigation.show_ukraine_cta?
ga4_tracking_counts = OpenStruct.new(index_section_count: 0)
ga4_tracking_counts.index_section_count = 1 if show_ukraine_cta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
add_gem_component_stylesheet("document-list")

local_assigns[:margin_bottom] ||= 5
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
items ||= []

component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("gem-c-document-list")
component_helper.add_class("gem-c-document-list--no-top-border") if local_assigns[:remove_top_border]
component_helper.add_class("gem-c-document-list--no-top-border-first-child") if local_assigns[:remove_top_border_from_first_child]
component_helper.add_class("gem-c-document-list--equal-item-spacing") if local_assigns[:equal_item_spacing]
component_helper.add_class(shared_helper.get_margin_bottom)

extra_link_classes = "govuk-link--no-underline" if local_assigns[:remove_underline]
title_with_context_class = " gem-c-document-list__item-title--context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
direction_class = "gem-c-govspeak--direction-#{direction}" if local_assigns.include?(:direction)
disable_youtube_expansions = local_assigns.fetch(:disable_youtube_expansions) if local_assigns.include?(:disable_youtube_expansions)

shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("gem-c-govspeak govuk-govspeak")
component_helper.add_class(direction_class) if direction_class
component_helper.add_class("js-disable-youtube") if disable_youtube_expansions
component_helper.add_class("gem-c-govspeak--inverse") if inverse
component_helper.add_class(shared_helper.get_margin_bottom)
component_helper.add_data_attribute({ module: "govspeak" })
%>
<%= tag.div(**component_helper.all_attributes) do %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@

id ||= "inset-text-#{SecureRandom.hex(4)}"
margin_top ||= 6
margin_bottom ||= 6
local_assigns[:margin_bottom] ||= 6

shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new({
margin_top: margin_top,
margin_bottom: margin_bottom
})

component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("gem-c-inset-text govuk-inset-text gem-c-force-print-link-styles-within")
component_helper.add_class(shared_helper.get_margin_top)
component_helper.add_class(shared_helper.get_margin_bottom)
component_helper.set_id(id)
%>
<%= tag.div(**component_helper.all_attributes) do %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@

text ||= ""
inverse ||= false
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)

component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("gem-c-lead-paragraph")
component_helper.add_class("gem-c-lead-paragraph--inverse") if inverse
component_helper.add_class(shared_helper.get_margin_bottom) if [*0..9].include?(local_assigns[:margin_bottom])
%>
<% if text.present? %>
<%= tag.p(**component_helper.all_attributes) do %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
direction_class = ""
direction_class = " direction-#{direction}" if local_assigns.include?(:direction)

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

component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("gem-c-metadata")
component_helper.add_class("direction-#{direction}") if local_assigns.include?(:direction)
Expand All @@ -27,7 +25,6 @@
component_helper.add_class("gem-c-metadata--inverse-padded") unless inverse_compress
end

component_helper.add_class(shared_helper.get_margin_bottom) if local_assigns[:margin_bottom]
component_helper.add_data_attribute({ module: "metadata" })

disable_ga4 ||= false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
show_banner_title ||= false
heading_level = show_banner_title ? "h3" : "h2"

shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("govuk-notification-banner gem-c-notice")
component_helper.add_class(shared_helper.get_margin_bottom)

component_helper.add_aria_attribute({ label: "Notice" })
component_helper.add_aria_attribute({ live: "polite" }) if aria_live
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
add_gem_component_stylesheet("password-input")

label_text ||= t("components.password_input.label")

local_assigns[:margin_bottom] ||= 3
error_text ||= nil
error_text_prefix ||= t("components.password_input.error_text_prefix")

Expand All @@ -15,7 +15,6 @@

name ||= "password"

shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_data_attribute({
module: "govuk-password-input",
Expand All @@ -30,7 +29,6 @@
component_helper.add_class('govuk-form-group--error') if error_text
component_helper.add_class('govuk-password-input')
component_helper.add_class('gem-c-password-input')
component_helper.add_class(shared_helper.get_margin_bottom)

uid = SecureRandom.hex(4)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
hint ||= nil
error_message ||= nil
error_items ||= []
margin_bottom = margin_bottom ||= 6

has_error = error_message || error_items.any?
hint_id = "hint-#{SecureRandom.hex(4)}" if hint
Expand All @@ -40,7 +39,6 @@
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("govuk-form-group")
component_helper.add_class("govuk-form-group--error") if has_error
component_helper.add_class(shared_helper.get_margin_bottom)
component_helper.set_id(id)

radio_classes = %w(govuk-radios)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("gem-c-signup-link govuk-!-display-none-print")
component_helper.add_class(shared_helper.get_margin_bottom)
component_helper.add_class("gem-c-signup-link--link-only") unless heading
component_helper.add_class("gem-c-signup-link--with-background-and-border") if background
%>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<%
add_gem_component_stylesheet("single-page-notification-button")

local_assigns[:margin_bottom] ||= 3

spnb_helper = GovukPublishingComponents::Presenters::SinglePageNotificationButtonHelper.new(local_assigns)
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)

wrapper_classes = %w(govuk-!-display-none-print)
wrapper_classes << shared_helper.get_margin_bottom

ga4_data_attributes = ga4_data_attributes ||= nil
ga4_link_data_attributes = ga4_data_attributes[:ga4_link] if ga4_data_attributes
ga4_link_data_attributes[:url] = spnb_helper.form_action if ga4_link_data_attributes

component_helper.add_class(wrapper_classes.join(" "))
component_helper.add_class("govuk-!-display-none-print")
component_helper.add_data_attribute({ module: ga4_data_attributes[:module] }) if ga4_data_attributes
%>
<% button_text = capture do %>
Expand Down

0 comments on commit bfad545

Please sign in to comment.