Class: GovukPublishingComponents::Presenters::ButtonHelper
- Inherits:
-
Object
- Object
- GovukPublishingComponents::Presenters::ButtonHelper
- Defined in:
- lib/govuk_publishing_components/presenters/button_helper.rb
Instance Attribute Summary collapse
-
#aria_controls ⇒ Object
readonly
Returns the value of attribute aria_controls.
-
#aria_describedby ⇒ Object
readonly
Returns the value of attribute aria_describedby.
-
#aria_label ⇒ Object
readonly
Returns the value of attribute aria_label.
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#data_attributes ⇒ Object
readonly
Returns the value of attribute data_attributes.
-
#destructive ⇒ Object
readonly
Returns the value of attribute destructive.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#info_text ⇒ Object
readonly
Returns the value of attribute info_text.
-
#info_text_classes ⇒ Object
readonly
Returns the value of attribute info_text_classes.
-
#inline_layout ⇒ Object
readonly
Returns the value of attribute inline_layout.
-
#margin_bottom ⇒ Object
readonly
Returns the value of attribute margin_bottom.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rel ⇒ Object
readonly
Returns the value of attribute rel.
-
#secondary ⇒ Object
readonly
Returns the value of attribute secondary.
-
#secondary_quiet ⇒ Object
readonly
Returns the value of attribute secondary_quiet.
-
#secondary_solid ⇒ Object
readonly
Returns the value of attribute secondary_solid.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #aria_labelledby ⇒ Object
- #button_type ⇒ Object
- #html_options ⇒ Object
- #info_text? ⇒ Boolean
- #info_text_options ⇒ Object
-
#initialize(local_assigns) ⇒ ButtonHelper
constructor
A new instance of ButtonHelper.
- #link? ⇒ Boolean
Constructor Details
#initialize(local_assigns) ⇒ ButtonHelper
Returns a new instance of ButtonHelper.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 30 def initialize(local_assigns) @disable_ga4 = local_assigns[:disable_ga4] @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]&.symbolize_keys || {} @data_attributes[:module] = "govuk-button #{data_attributes[:module]}".strip if link? @margin_bottom = local_assigns[:margin_bottom] @inline_layout = local_assigns[:inline_layout] @target = local_assigns[:target] @type = local_assigns[:type] @start = local_assigns[:start] @data_attributes[:ga4_attributes] = ga4_attribute if 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] @info_text_id = "info-text-id-#{SecureRandom.hex(4)}" @button_id = "button-id-#{SecureRandom.hex(4)}" @aria_controls = local_assigns[:aria_controls] @aria_describedby = local_assigns[:aria_describedby] end |
Instance Attribute Details
#aria_controls ⇒ Object (readonly)
Returns the value of attribute aria_controls.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def aria_controls @aria_controls end |
#aria_describedby ⇒ Object (readonly)
Returns the value of attribute aria_describedby.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def aria_describedby @aria_describedby end |
#aria_label ⇒ Object (readonly)
Returns the value of attribute aria_label.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def aria_label @aria_label end |
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def classes @classes end |
#data_attributes ⇒ Object (readonly)
Returns the value of attribute data_attributes.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def data_attributes @data_attributes end |
#destructive ⇒ Object (readonly)
Returns the value of attribute destructive.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def destructive @destructive end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def href @href end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def id @id end |
#info_text ⇒ Object (readonly)
Returns the value of attribute info_text.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def info_text @info_text end |
#info_text_classes ⇒ Object (readonly)
Returns the value of attribute info_text_classes.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def info_text_classes @info_text_classes end |
#inline_layout ⇒ Object (readonly)
Returns the value of attribute inline_layout.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def inline_layout @inline_layout end |
#margin_bottom ⇒ Object (readonly)
Returns the value of attribute margin_bottom.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def margin_bottom @margin_bottom end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def name @name end |
#rel ⇒ Object (readonly)
Returns the value of attribute rel.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def rel @rel end |
#secondary ⇒ Object (readonly)
Returns the value of attribute secondary.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def secondary @secondary end |
#secondary_quiet ⇒ Object (readonly)
Returns the value of attribute secondary_quiet.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def secondary_quiet @secondary_quiet end |
#secondary_solid ⇒ Object (readonly)
Returns the value of attribute secondary_solid.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def secondary_solid @secondary_solid end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def start @start end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def target @target end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def text @text end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 6 def value @value end |
Instance Method Details
#aria_labelledby ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 72 def aria_labelledby if info_text? text = "#{@button_id} " text << @info_text_id text end end |
#button_type ⇒ Object
106 107 108 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 106 def type || "submit" unless link? end |
#html_options ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 87 def = { class: css_classes } [:role] = "button" if link? [:type] = [:id] = @button_id if info_text? [:aria] = { labelledby: aria_labelledby } [:rel] = rel if rel [:data] = data_attributes if data_attributes [:title] = title if title [:target] = target if target [:name] = name if name.present? && value.present? [:value] = value if name.present? && value.present? [:aria] = { label: aria_label } if aria_label [:aria][:controls] = aria_controls if aria_controls [:aria][:describedby] = aria_describedby if aria_describedby [:draggable] = false if link? end |
#info_text? ⇒ Boolean
68 69 70 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 68 def info_text? info_text.present? end |
#info_text_options ⇒ Object
80 81 82 83 84 85 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 80 def = { class: info_text_classes } [:aria] = { hidden: true } if info_text? [:id] = @info_text_id if info_text? end |
#link? ⇒ Boolean
64 65 66 |
# File 'lib/govuk_publishing_components/presenters/button_helper.rb', line 64 def link? href.present? end |