Class: GovukPublishingComponents::Presenters::SelectHelper
- Inherits:
-
Object
- Object
- GovukPublishingComponents::Presenters::SelectHelper
- Defined in:
- lib/govuk_publishing_components/presenters/select_helper.rb
Instance Attribute Summary collapse
-
#describedby ⇒ Object
readonly
Returns the value of attribute describedby.
-
#error_id ⇒ Object
readonly
Returns the value of attribute error_id.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#hint ⇒ Object
readonly
Returns the value of attribute hint.
-
#hint_id ⇒ Object
readonly
Returns the value of attribute hint_id.
-
#option_markup ⇒ Object
readonly
Returns the value of attribute option_markup.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#selected_option ⇒ Object
readonly
Returns the value of attribute selected_option.
Instance Method Summary collapse
- #css_classes ⇒ Object
- #data_tracking? ⇒ Boolean
-
#initialize(local_assigns) ⇒ SelectHelper
constructor
A new instance of SelectHelper.
- #label_classes ⇒ Object
- #select_classes ⇒ Object
Constructor Details
#initialize(local_assigns) ⇒ SelectHelper
Returns a new instance of SelectHelper.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 6 def initialize(local_assigns) @options = local_assigns[:options] || [] @error_message = 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 @option_markup = @describedby = get_describedby end |
Instance Attribute Details
#describedby ⇒ Object (readonly)
Returns the value of attribute describedby.
4 5 6 |
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 4 def describedby @describedby end |
#error_id ⇒ Object (readonly)
Returns the value of attribute error_id.
4 5 6 |
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 4 def error_id @error_id end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
4 5 6 |
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 4 def @error_message end |
#hint ⇒ Object (readonly)
Returns the value of attribute hint.
4 5 6 |
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 4 def hint @hint end |
#hint_id ⇒ Object (readonly)
Returns the value of attribute hint_id.
4 5 6 |
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 4 def hint_id @hint_id end |
#option_markup ⇒ Object (readonly)
Returns the value of attribute option_markup.
4 5 6 |
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 4 def option_markup @option_markup end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 4 def @options end |
#selected_option ⇒ Object (readonly)
Returns the value of attribute selected_option.
4 5 6 |
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 4 def selected_option @selected_option end |
Instance Method Details
#css_classes ⇒ Object
22 23 24 25 26 |
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 22 def css_classes classes = %w[govuk-form-group gem-c-select] classes << "govuk-form-group--error" if @error_message classes end |
#data_tracking? ⇒ Boolean
18 19 20 |
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 18 def data_tracking? @options.any? { |item| item[:data_attributes] && item[:data_attributes][:track_category] && item[:data_attributes][:track_action] } end |
#label_classes ⇒ Object
35 36 37 38 39 |
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 35 def label_classes classes = %w[govuk-label] classes << "govuk-label--#{@heading_size}" if @heading_size classes end |
#select_classes ⇒ Object
28 29 30 31 32 33 |
# File 'lib/govuk_publishing_components/presenters/select_helper.rb', line 28 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 |