Class: GovukPublishingComponents::Presenters::SelectHelper

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::FormOptionsHelper
Defined in:
lib/govuk_publishing_components/presenters/select_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(local_assigns) ⇒ SelectHelper

Returns a new instance of SelectHelper.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 8

def initialize(local_assigns)
  @options = local_assigns[:options] || []
  @error_items = local_assigns[:error_items] || []
  @error_items << { text: local_assigns[:error_message] } if local_assigns[:error_message]
  @error_id = local_assigns[:error_id] || nil
  @hint = local_assigns[:hint] || nil
  @hint_id = local_assigns[:hint_id] || nil
  @heading_size = local_assigns[:heading_size]
  @full_width = local_assigns[:full_width] || false
  @options_markup = options_for_select(get_options, @selected_option)
  @describedby = get_describedby
end

Instance Attribute Details

#describedbyObject (readonly)

Returns the value of attribute describedby.



6
7
8
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 6

def describedby
  @describedby
end

#error_idObject (readonly)

Returns the value of attribute error_id.



6
7
8
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 6

def error_id
  @error_id
end

#error_itemsObject (readonly)

Returns the value of attribute error_items.



6
7
8
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 6

def error_items
  @error_items
end

#hintObject (readonly)

Returns the value of attribute hint.



6
7
8
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 6

def hint
  @hint
end

#hint_idObject (readonly)

Returns the value of attribute hint_id.



6
7
8
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 6

def hint_id
  @hint_id
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 6

def options
  @options
end

#options_markupObject (readonly)

Returns the value of attribute options_markup.



6
7
8
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 6

def options_markup
  @options_markup
end

Instance Method Details

#css_classesObject



21
22
23
24
25
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 21

def css_classes
  classes = %w[govuk-form-group gem-c-select]
  classes << "govuk-form-group--error" if @error_items.present?
  classes
end

#label_classesObject



34
35
36
37
38
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 34

def label_classes
  classes = %w[govuk-label]
  classes << "govuk-label--#{@heading_size}" if @heading_size
  classes
end

#select_classesObject



27
28
29
30
31
32
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 27

def select_classes
  classes = %w[govuk-select]
  classes << "gem-c-select__select--full-width" if @full_width
  classes << "govuk-select--error" if @error_id
  classes
end