class GovukPublishingComponents::Presenters::ButtonHelper
Attributes
aria_label[R]
classes[R]
data_attributes[R]
destructive[R]
href[R]
info_text[R]
info_text_classes[R]
inline_layout[R]
margin_bottom[R]
name[R]
rel[R]
secondary[R]
secondary_quiet[R]
secondary_solid[R]
start[R]
target[R]
text[R]
title[R]
type[R]
value[R]
Public Class Methods
new(local_assigns)
click to toggle source
# File lib/govuk_publishing_components/presenters/button_helper.rb, line 27 def initialize(local_assigns) @href = local_assigns[:href] @text = local_assigns[:text] @title = local_assigns[:title] @info_text = local_assigns[:info_text] @info_text_classes = %w[gem-c-button__info-text] if local_assigns[:margin_bottom] margin_class = get_margin_bottom(local_assigns[:margin_bottom], true) @info_text_classes << margin_class end @rel = local_assigns[:rel] @data_attributes = local_assigns[:data_attributes] @margin_bottom = local_assigns[:margin_bottom] @inline_layout = local_assigns[:inline_layout] @target = local_assigns[:target] @type = local_assigns[:type] @start = local_assigns[:start] @secondary = local_assigns[:secondary] @secondary_quiet = local_assigns[:secondary_quiet] @secondary_solid = local_assigns[:secondary_solid] @destructive = local_assigns[:destructive] @name = local_assigns[:name] @value = local_assigns[:value] @classes = local_assigns[:classes] @aria_label = local_assigns[:aria_label] end
Public Instance Methods
html_options()
click to toggle source
# File lib/govuk_publishing_components/presenters/button_helper.rb, line 58 def html_options options = { class: css_classes } options[:role] = "button" if link? options[:type] = button_type options[:rel] = rel if rel options[:data] = data_attributes if data_attributes options[:title] = title if title options[:target] = target if target options[:name] = name if name.present? && value.present? options[:value] = value if name.present? && value.present? options[:aria] = { label: aria_label } if aria_label options end
link?()
click to toggle source
# File lib/govuk_publishing_components/presenters/button_helper.rb, line 54 def link? href.present? end
Private Instance Methods
css_classes()
click to toggle source
# File lib/govuk_publishing_components/presenters/button_helper.rb, line 78 def css_classes css_classes = %w[gem-c-button govuk-button] css_classes << "govuk-button--start" if start css_classes << "gem-c-button--secondary" if secondary 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 css_classes << "gem-c-button--inline" if inline_layout css_classes << classes if classes css_classes.join(" ") end
get_margin_bottom(margin, info_text)
click to toggle source
# File lib/govuk_publishing_components/presenters/button_helper.rb, line 94 def get_margin_bottom(margin, info_text) legacy_class = "gem-c-button--bottom-margin" legacy_class = "gem-c-button__info-text--bottom-margin" if info_text [*0..9].include?(margin) ? "govuk-!-margin-bottom-#{margin}" : legacy_class end