Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
andysellick committed Jan 14, 2025
1 parent 25d2f00 commit 3d1918f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
# local_assigns[:classes] = shared_helper.classes
button = GovukPublishingComponents::Presenters::ButtonHelper.new(local_assigns)
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("gem-c-button govuk-button")
component_helper.add_class("govuk-button--start") if local_assigns[:start]
component_helper.add_class("gem-c-button--secondary") if local_assigns[:secondary]
component_helper.add_class("gem-c-button--secondary-quiet") if local_assigns[:secondary_quiet]
component_helper.add_class("govuk-button--secondary") if local_assigns[:secondary_solid]
component_helper.add_class("govuk-button--warning") if local_assigns[:destructive]
component_helper.add_class("gem-c-button--inline") if local_assigns[:inline_layout]
component_helper.add_class(button.classes)
component_helper.set_margin_bottom(0) if local_assigns[:info_text]
component_helper.add_data_attribute({ module: "govuk-button" }) if local_assigns[:href]

Expand Down
23 changes: 12 additions & 11 deletions lib/govuk_publishing_components/presenters/button_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ButtonHelper
:id,
:inline_layout,
:target,
# :type,
:type,
:start,
:secondary,
:secondary_quiet,
Expand Down Expand Up @@ -44,7 +44,7 @@ def initialize(local_assigns)
@margin_bottom = local_assigns[:margin_bottom]
@inline_layout = local_assigns[:inline_layout]
@target = local_assigns[:target]
# @type = local_assigns[:type]
@type = button_type(local_assigns[:type])
@start = local_assigns[:start]
@data_attributes[:ga4_attributes] = ga4_attribute if start
@secondary = local_assigns[:secondary]
Expand All @@ -53,7 +53,8 @@ def initialize(local_assigns)
@destructive = local_assigns[:destructive]
@name = local_assigns[:name]
@value = local_assigns[:value]
@classes = local_assigns[:classes]
# @classes = local_assigns[:classes]
@classes = css_classes
@aria_label = local_assigns[:aria_label]
@info_text_id = "info-text-id-#{SecureRandom.hex(4)}"
@button_id = "button-id-#{SecureRandom.hex(4)}"
Expand Down Expand Up @@ -85,7 +86,7 @@ def info_text_options
end

def html_options
options = { class: css_classes }
# options = { class: css_classes }
options[:role] = "button" if link?
# options[:type] = button_type
options[:id] = @button_id if info_text?
Expand All @@ -103,9 +104,9 @@ def html_options
options
end

# def button_type
# type || "submit" unless link?
# end
def button_type(type)
type || "submit" unless link?
end

private

Expand All @@ -116,10 +117,10 @@ def css_classes
css_classes << "gem-c-button--secondary-quiet" if secondary_quiet
css_classes << "govuk-button--secondary" if secondary_solid
css_classes << "govuk-button--warning" if destructive
if margin_bottom && !info_text
margin_class = get_margin_bottom(margin_bottom, false)
css_classes << margin_class
end
# if margin_bottom && !info_text
# margin_class = get_margin_bottom(margin_bottom, false)
# css_classes << margin_class
# end
css_classes << "gem-c-button--inline" if inline_layout
css_classes << classes if classes
css_classes.join(" ")
Expand Down

0 comments on commit 3d1918f

Please sign in to comment.