crown_marketplace_utils 0.1.0.beta.6 → 0.1.0.beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/accordion.rb +91 -89
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/back_link.rb +24 -22
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/breadcrumbs.rb +56 -54
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/button.rb +109 -107
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/details.rb +33 -31
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/error_message.rb +49 -47
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/character_count.rb +144 -142
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/checkboxes.rb +176 -174
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/date_input.rb +126 -124
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/file_upload.rb +75 -73
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/input.rb +137 -135
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/radios.rb +176 -174
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/select.rb +111 -109
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/textarea.rb +86 -84
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field.rb +181 -179
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/fieldset.rb +56 -54
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/form_group.rb +37 -35
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/header.rb +142 -140
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/hint.rb +25 -23
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/label.rb +69 -67
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/notification_banner.rb +121 -119
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/pagination.rb +290 -288
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/step_by_step_navigation.rb +187 -185
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/tag.rb +29 -27
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/warning_text.rb +39 -37
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper.rb +31 -29
- data/lib/crown_marketplace_utils/version.rb +1 -1
- metadata +1 -1
| @@ -2,224 +2,226 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            require 'action_view'
         | 
| 4 4 |  | 
| 5 | 
            -
            module CrownMarketplaceUtils | 
| 6 | 
            -
              module  | 
| 7 | 
            -
                 | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
                   | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
                     | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
                      tag. | 
| 43 | 
            -
                         | 
| 44 | 
            -
                           | 
| 5 | 
            +
            module CrownMarketplaceUtils
         | 
| 6 | 
            +
              module Helpers
         | 
| 7 | 
            +
                module GovUkHelper
         | 
| 8 | 
            +
                  # = GOV.UK Step by step navigation
         | 
| 9 | 
            +
                  #
         | 
| 10 | 
            +
                  # This helper is used for generating the Step by step navigation component from the
         | 
| 11 | 
            +
                  # {https://design-system.service.gov.uk/patterns/step-by-step-navigation/ GDS - Pages - Step by step navigation}
         | 
| 12 | 
            +
                  #
         | 
| 13 | 
            +
                  # To use this component you need the following from {https://github.com/alphagov/govuk_publishing_components GOV.UK Publishing Components}.
         | 
| 14 | 
            +
                  # For the SCSS components you should add:
         | 
| 15 | 
            +
                  # - {https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss _step-by-step-nav.scss}
         | 
| 16 | 
            +
                  # - {https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-related.scss _step-by-step-nav-related.scss}
         | 
| 17 | 
            +
                  # - {https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-header.scss _step-by-step-nav-header.scss}
         | 
| 18 | 
            +
                  # For the JavaScript you should add:
         | 
| 19 | 
            +
                  # - {https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js step-by-step-nav.js}
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  module StepByStepNavigation
         | 
| 22 | 
            +
                    include ActionView::Helpers
         | 
| 23 | 
            +
                    include ActionView::Context
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    # Generates the HTML for the GOV.UK Step by step navigation component (experimental)
         | 
| 26 | 
            +
                    #
         | 
| 27 | 
            +
                    # @param step_by_step_sections [Array] the navigation items that will be rendered to the page.
         | 
| 28 | 
            +
                    #                                   See {govuk_step_by_step_navigation_section} for more details
         | 
| 29 | 
            +
                    # @param govuk_step_by_step_navigation_options [Hash] options that will be used in customising the HTML
         | 
| 30 | 
            +
                    #
         | 
| 31 | 
            +
                    # @option govuk_step_by_step_navigation_options [String] :classes additional CSS classes for the step by step navigation HTML
         | 
| 32 | 
            +
                    # @option govuk_step_by_step_navigation_options [Hash] :attributes ({data: { module: 'govuk-step-by-step-navigation', 'show-text': 'Show', 'hide-text': 'Hide', 'show-all-text': 'Show all', 'hide-all-text': 'Hide all' } })
         | 
| 33 | 
            +
                    #                                                                  any additional attributes that will added as part of the HTML
         | 
| 34 | 
            +
                    #
         | 
| 35 | 
            +
                    # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Step by step navigation
         | 
| 36 | 
            +
                    #                                     which can then be rendered on the page
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                    def govuk_step_by_step_navigation(step_by_step_sections, **govuk_step_by_step_navigation_options)
         | 
| 39 | 
            +
                      govuk_step_by_step_navigation_classes = ['gem-c-step-nav gem-c-step-nav--large gem-c-step-nav--active']
         | 
| 40 | 
            +
                      govuk_step_by_step_navigation_classes << govuk_step_by_step_navigation_options[:classes]
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                      tag.div(class: govuk_step_by_step_navigation_classes, **govuk_step_by_step_navigation_attributes(**govuk_step_by_step_navigation_options)) do
         | 
| 43 | 
            +
                        tag.ol(class: 'gem-c-step-nav__steps') do
         | 
| 44 | 
            +
                          capture do
         | 
| 45 | 
            +
                            step_by_step_sections.each.with_index(1) { |step_by_step_section, section_index| concat(govuk_step_by_step_navigation_section(step_by_step_section, section_index.to_s)) }
         | 
| 46 | 
            +
                          end
         | 
| 45 47 | 
             
                        end
         | 
| 46 48 | 
             
                      end
         | 
| 47 49 | 
             
                    end
         | 
| 48 | 
            -
                  end
         | 
| 49 | 
            -
             | 
| 50 | 
            -
                  private
         | 
| 51 | 
            -
             | 
| 52 | 
            -
                  # The HTML for a section within GOV.UK Step by step navigation, used by {govuk_step_by_step_navigation}
         | 
| 53 | 
            -
                  #
         | 
| 54 | 
            -
                  # @param step_by_step_section [Hash] the parameters that will be used to create the section
         | 
| 55 | 
            -
                  # @param section_index [String] the index of the section
         | 
| 56 | 
            -
                  #
         | 
| 57 | 
            -
                  # @option step_by_step_section [Hash] :heading the paramaters for the section heading,
         | 
| 58 | 
            -
                  #                                              see {govuk_step_by_step_navigation_heading} for more details
         | 
| 59 | 
            -
                  # @option step_by_step_section [Array] :content the paramaters for the section content,
         | 
| 60 | 
            -
                  #                                               see {govuk_step_by_step_navigation_content} for more details
         | 
| 61 | 
            -
                  #
         | 
| 62 | 
            -
                  # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Step by step navigation section
         | 
| 63 | 
            -
                  #                                     which is used in {govuk_step_by_step_navigation}
         | 
| 64 | 
            -
             | 
| 65 | 
            -
                  def govuk_step_by_step_navigation_section(step_by_step_section, section_index)
         | 
| 66 | 
            -
                    section_id = convert_to_id(step_by_step_section[:heading][:text])
         | 
| 67 50 |  | 
| 68 | 
            -
                     | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 51 | 
            +
                    private
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                    # The HTML for a section within GOV.UK Step by step navigation, used by {govuk_step_by_step_navigation}
         | 
| 54 | 
            +
                    #
         | 
| 55 | 
            +
                    # @param step_by_step_section [Hash] the parameters that will be used to create the section
         | 
| 56 | 
            +
                    # @param section_index [String] the index of the section
         | 
| 57 | 
            +
                    #
         | 
| 58 | 
            +
                    # @option step_by_step_section [Hash] :heading the paramaters for the section heading,
         | 
| 59 | 
            +
                    #                                              see {govuk_step_by_step_navigation_heading} for more details
         | 
| 60 | 
            +
                    # @option step_by_step_section [Array] :content the paramaters for the section content,
         | 
| 61 | 
            +
                    #                                               see {govuk_step_by_step_navigation_content} for more details
         | 
| 62 | 
            +
                    #
         | 
| 63 | 
            +
                    # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Step by step navigation section
         | 
| 64 | 
            +
                    #                                     which is used in {govuk_step_by_step_navigation}
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                    def govuk_step_by_step_navigation_section(step_by_step_section, section_index)
         | 
| 67 | 
            +
                      section_id = convert_to_id(step_by_step_section[:heading][:text])
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                      tag.li(class: 'gem-c-step-nav__step js-step', id: section_id) do
         | 
| 70 | 
            +
                        capture do
         | 
| 71 | 
            +
                          concat(govuk_step_by_step_navigation_heading(step_by_step_section[:heading], section_index))
         | 
| 72 | 
            +
                          concat(govuk_step_by_step_navigation_content(step_by_step_section[:content], section_id, section_index))
         | 
| 73 | 
            +
                        end
         | 
| 72 74 | 
             
                      end
         | 
| 73 75 | 
             
                    end
         | 
| 74 | 
            -
                  end
         | 
| 75 | 
            -
             | 
| 76 | 
            -
                  # The HTML for a section heading within GOV.UK Step by step navigation, used by {govuk_step_by_step_navigation_section}
         | 
| 77 | 
            -
                  #
         | 
| 78 | 
            -
                  # @param section_heading [Hash] the parameters that will be used to create the heading
         | 
| 79 | 
            -
                  # @param section_index [String] the index of the section
         | 
| 80 | 
            -
                  #
         | 
| 81 | 
            -
                  # @option section_heading [Hash] :text text for the section heading
         | 
| 82 | 
            -
                  # @option section_heading [Hash] :logic (nil) text to show instead of a number in the sidebar
         | 
| 83 | 
            -
                  #
         | 
| 84 | 
            -
                  # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Step by step navigation section heading
         | 
| 85 | 
            -
                  #                                     which is used in {govuk_step_by_step_navigation_section}
         | 
| 86 76 |  | 
| 87 | 
            -
             | 
| 88 | 
            -
                     | 
| 89 | 
            -
             | 
| 90 | 
            -
                     | 
| 91 | 
            -
             | 
| 92 | 
            -
             | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 95 | 
            -
             | 
| 96 | 
            -
             | 
| 97 | 
            -
             | 
| 98 | 
            -
             | 
| 77 | 
            +
                    # The HTML for a section heading within GOV.UK Step by step navigation, used by {govuk_step_by_step_navigation_section}
         | 
| 78 | 
            +
                    #
         | 
| 79 | 
            +
                    # @param section_heading [Hash] the parameters that will be used to create the heading
         | 
| 80 | 
            +
                    # @param section_index [String] the index of the section
         | 
| 81 | 
            +
                    #
         | 
| 82 | 
            +
                    # @option section_heading [Hash] :text text for the section heading
         | 
| 83 | 
            +
                    # @option section_heading [Hash] :logic (nil) text to show instead of a number in the sidebar
         | 
| 84 | 
            +
                    #
         | 
| 85 | 
            +
                    # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Step by step navigation section heading
         | 
| 86 | 
            +
                    #                                     which is used in {govuk_step_by_step_navigation_section}
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                    def govuk_step_by_step_navigation_heading(section_heading, section_index)
         | 
| 89 | 
            +
                      logic = section_heading[:logic]
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                      tag.div(class: 'gem-c-step-nav__header js-toggle-panel', data: { position: section_index }) do
         | 
| 92 | 
            +
                        tag.h2(class: 'gem-c-step-nav__title') do
         | 
| 93 | 
            +
                          capture do
         | 
| 94 | 
            +
                            concat(tag.span(class: "gem-c-step-nav__circle gem-c-step-nav__circle--#{logic ? 'logic' : 'number'}") do
         | 
| 95 | 
            +
                              tag.span(class: 'gem-c-step-nav__circle-inner') do
         | 
| 96 | 
            +
                                tag.span(class: 'gem-c-step-nav__circle-background') do
         | 
| 97 | 
            +
                                  capture do
         | 
| 98 | 
            +
                                    concat(tag.span('Step', class: 'govuk-visually-hidden'))
         | 
| 99 | 
            +
                                    concat(logic || section_index)
         | 
| 100 | 
            +
                                  end
         | 
| 99 101 | 
             
                                end
         | 
| 100 102 | 
             
                              end
         | 
| 101 | 
            -
                            end
         | 
| 102 | 
            -
             | 
| 103 | 
            -
             | 
| 104 | 
            -
                             | 
| 105 | 
            -
                          end | 
| 103 | 
            +
                            end)
         | 
| 104 | 
            +
                            concat(tag.span(class: 'js-step-title') do
         | 
| 105 | 
            +
                              tag.span(section_heading[:text], class: 'js-step-title-text')
         | 
| 106 | 
            +
                            end)
         | 
| 107 | 
            +
                          end
         | 
| 106 108 | 
             
                        end
         | 
| 107 109 | 
             
                      end
         | 
| 108 110 | 
             
                    end
         | 
| 109 | 
            -
                  end
         | 
| 110 111 |  | 
| 111 | 
            -
             | 
| 112 | 
            -
             | 
| 113 | 
            -
             | 
| 114 | 
            -
             | 
| 115 | 
            -
             | 
| 116 | 
            -
             | 
| 117 | 
            -
             | 
| 118 | 
            -
             | 
| 119 | 
            -
             | 
| 120 | 
            -
             | 
| 121 | 
            -
             | 
| 122 | 
            -
             | 
| 123 | 
            -
             | 
| 124 | 
            -
             | 
| 125 | 
            -
             | 
| 126 | 
            -
             | 
| 127 | 
            -
             | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 130 | 
            -
             | 
| 131 | 
            -
             | 
| 132 | 
            -
             | 
| 133 | 
            -
             | 
| 134 | 
            -
             | 
| 135 | 
            -
             | 
| 136 | 
            -
             | 
| 137 | 
            -
             | 
| 138 | 
            -
             | 
| 112 | 
            +
                    # The HTML for a section content within GOV.UK Step by step navigation, used by {govuk_step_by_step_navigation_section}
         | 
| 113 | 
            +
                    #
         | 
| 114 | 
            +
                    # @param content [Array] an array of the content items that will be rendered within the section.
         | 
| 115 | 
            +
                    #                        Only two types of content are allowed:
         | 
| 116 | 
            +
                    #                        - +:paragraph+ - see {govuk_step_by_step_navigation_paragraph}
         | 
| 117 | 
            +
                    #                        - +:list+ - see {govuk_step_by_step_navigation_list}
         | 
| 118 | 
            +
                    # @param section_id [String] the id of the section
         | 
| 119 | 
            +
                    # @param section_index [String] the index of the section
         | 
| 120 | 
            +
                    #
         | 
| 121 | 
            +
                    # @option content [Symbol] :type the type of content, either +:paragraph+ or +list+
         | 
| 122 | 
            +
                    # @option content [Symbol] :text the text for the paragraph. Ignored unless the +type+ is +:list+
         | 
| 123 | 
            +
                    # @option content [Symbol] :items the items for the list. Ignored unless the +type+ is +:paragraph+
         | 
| 124 | 
            +
                    #
         | 
| 125 | 
            +
                    # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Step by step navigation section content
         | 
| 126 | 
            +
                    #                                     which is used in {govuk_step_by_step_navigation_section}
         | 
| 127 | 
            +
             | 
| 128 | 
            +
                    def govuk_step_by_step_navigation_content(content, section_id, section_index)
         | 
| 129 | 
            +
                      tag.div(class: 'gem-c-step-nav__panel js-panel', id: "step-panel-#{section_id}-#{section_index}") do
         | 
| 130 | 
            +
                        capture do
         | 
| 131 | 
            +
                          content.each do |element|
         | 
| 132 | 
            +
                            concat(
         | 
| 133 | 
            +
                              case element[:type]
         | 
| 134 | 
            +
                              when :paragraph
         | 
| 135 | 
            +
                                govuk_step_by_step_navigation_paragraph(element[:text])
         | 
| 136 | 
            +
                              when :list
         | 
| 137 | 
            +
                                govuk_step_by_step_navigation_list(element[:items])
         | 
| 138 | 
            +
                              end
         | 
| 139 | 
            +
                            )
         | 
| 140 | 
            +
                          end
         | 
| 139 141 | 
             
                        end
         | 
| 140 142 | 
             
                      end
         | 
| 141 143 | 
             
                    end
         | 
| 142 | 
            -
                  end
         | 
| 143 144 |  | 
| 144 | 
            -
             | 
| 145 | 
            -
             | 
| 146 | 
            -
             | 
| 147 | 
            -
             | 
| 148 | 
            -
             | 
| 149 | 
            -
             | 
| 150 | 
            -
             | 
| 151 | 
            -
             | 
| 152 | 
            -
             | 
| 153 | 
            -
             | 
| 154 | 
            -
             | 
| 155 | 
            -
             | 
| 156 | 
            -
             | 
| 145 | 
            +
                    # The HTML for the paragraph item within the GOV.UK Step by step navigation content, used by {govuk_step_by_step_navigation_content}
         | 
| 146 | 
            +
                    #
         | 
| 147 | 
            +
                    # @param text [String] the text for the paragraph
         | 
| 148 | 
            +
                    #
         | 
| 149 | 
            +
                    # @return [ActiveSupport::SafeBuffer] the HTML for the paragraph
         | 
| 150 | 
            +
                    #                                     which is used in {govuk_step_by_step_navigation_content}
         | 
| 151 | 
            +
             | 
| 152 | 
            +
                    def govuk_step_by_step_navigation_paragraph(text)
         | 
| 153 | 
            +
                      tag.p(
         | 
| 154 | 
            +
                        text,
         | 
| 155 | 
            +
                        class: 'gem-c-step-nav__paragraph',
         | 
| 156 | 
            +
                      )
         | 
| 157 | 
            +
                    end
         | 
| 157 158 |  | 
| 158 | 
            -
             | 
| 159 | 
            -
             | 
| 160 | 
            -
             | 
| 161 | 
            -
             | 
| 162 | 
            -
             | 
| 163 | 
            -
             | 
| 164 | 
            -
             | 
| 165 | 
            -
             | 
| 166 | 
            -
             | 
| 167 | 
            -
             | 
| 168 | 
            -
             | 
| 169 | 
            -
             | 
| 170 | 
            -
             | 
| 159 | 
            +
                    # The HTML for the list items within the GOV.UK Step by step navigation content, used by {govuk_step_by_step_navigation_content}
         | 
| 160 | 
            +
                    #
         | 
| 161 | 
            +
                    # @param items [Array] an array of the list items,
         | 
| 162 | 
            +
                    #                      see {govuk_step_by_step_navigation_list_item} for more details
         | 
| 163 | 
            +
                    #
         | 
| 164 | 
            +
                    # @return [ActiveSupport::SafeBuffer] the HTML for the list
         | 
| 165 | 
            +
                    #                                     which is used in {govuk_step_by_step_navigation_content}
         | 
| 166 | 
            +
             | 
| 167 | 
            +
                    def govuk_step_by_step_navigation_list(items)
         | 
| 168 | 
            +
                      tag.ul(class: 'gem-c-step-nav__list gem-c-step-nav__list--choice', data: { length: items.length.to_s }) do
         | 
| 169 | 
            +
                        capture do
         | 
| 170 | 
            +
                          items.each do |item|
         | 
| 171 | 
            +
                            concat(govuk_step_by_step_navigation_list_item(item[:text], item[:no_marker]))
         | 
| 172 | 
            +
                          end
         | 
| 171 173 | 
             
                        end
         | 
| 172 174 | 
             
                      end
         | 
| 173 175 | 
             
                    end
         | 
| 174 | 
            -
                  end
         | 
| 175 176 |  | 
| 176 | 
            -
             | 
| 177 | 
            -
             | 
| 178 | 
            -
             | 
| 179 | 
            -
             | 
| 180 | 
            -
             | 
| 181 | 
            -
             | 
| 182 | 
            -
             | 
| 177 | 
            +
                    # The HTML for a list item, used by {govuk_step_by_step_navigation_list}
         | 
| 178 | 
            +
                    #
         | 
| 179 | 
            +
                    # @param text [Symbol] the text of the list item
         | 
| 180 | 
            +
                    # @param no_marker [Symbol] (nil) switch to hide the bullet marker
         | 
| 181 | 
            +
                    #
         | 
| 182 | 
            +
                    # @return [ActiveSupport::SafeBuffer] the HTML for the list item
         | 
| 183 | 
            +
                    #                                     which is used in {govuk_step_by_step_navigation_list}
         | 
| 183 184 |  | 
| 184 | 
            -
             | 
| 185 | 
            -
             | 
| 186 | 
            -
             | 
| 185 | 
            +
                    def govuk_step_by_step_navigation_list_item(text, no_marker)
         | 
| 186 | 
            +
                      list_item_classes = ['gem-c-step-nav__list-item js-list-item']
         | 
| 187 | 
            +
                      list_item_classes << 'gem-c-step-nav__list--no-marker' if no_marker
         | 
| 187 188 |  | 
| 188 | 
            -
             | 
| 189 | 
            -
             | 
| 189 | 
            +
                      tag.li(class: list_item_classes) do
         | 
| 190 | 
            +
                        tag.span(text)
         | 
| 191 | 
            +
                      end
         | 
| 190 192 | 
             
                    end
         | 
| 191 | 
            -
                  end
         | 
| 192 193 |  | 
| 193 | 
            -
             | 
| 194 | 
            -
             | 
| 195 | 
            -
             | 
| 196 | 
            -
             | 
| 197 | 
            -
             | 
| 194 | 
            +
                    # Converts the title text into a string to be used as the section id
         | 
| 195 | 
            +
                    #
         | 
| 196 | 
            +
                    # @param title [String] the section title that will be converted
         | 
| 197 | 
            +
                    #
         | 
| 198 | 
            +
                    # @return [String] the section id
         | 
| 198 199 |  | 
| 199 | 
            -
             | 
| 200 | 
            -
             | 
| 201 | 
            -
             | 
| 200 | 
            +
                    def convert_to_id(title)
         | 
| 201 | 
            +
                      title.downcase.gsub(' ', '-').gsub('(', '').gsub(')', '')
         | 
| 202 | 
            +
                    end
         | 
| 202 203 |  | 
| 203 | 
            -
             | 
| 204 | 
            -
             | 
| 205 | 
            -
             | 
| 206 | 
            -
             | 
| 207 | 
            -
             | 
| 208 | 
            -
             | 
| 209 | 
            -
             | 
| 204 | 
            +
                    # Generates a hash with the attributes used in {govuk_step_by_step_navigation}
         | 
| 205 | 
            +
                    #
         | 
| 206 | 
            +
                    # @param govuk_step_by_step_navigation_options [Hash] options that will be used in customising the HTML
         | 
| 207 | 
            +
                    #
         | 
| 208 | 
            +
                    # @option (see govuk_step_by_step_navigation)
         | 
| 209 | 
            +
                    #
         | 
| 210 | 
            +
                    # @return [Hash] contains the HTMl attributes used in {govuk_step_by_step_navigation}
         | 
| 210 211 |  | 
| 211 | 
            -
             | 
| 212 | 
            -
             | 
| 213 | 
            -
             | 
| 212 | 
            +
                    def govuk_step_by_step_navigation_attributes(**govuk_step_by_step_navigation_options)
         | 
| 213 | 
            +
                      govuk_step_by_step_navigation_options[:attributes] ||= {}
         | 
| 214 | 
            +
                      (govuk_step_by_step_navigation_options[:attributes][:data] ||= {}).merge!({ module: 'govuk-step-by-step-navigation' })
         | 
| 214 215 |  | 
| 215 | 
            -
             | 
| 216 | 
            +
                      DEFAULT_SHOW_HIDE_TEXT.each { |key, value| govuk_step_by_step_navigation_options[:attributes][:data][key] ||= value }
         | 
| 216 217 |  | 
| 217 | 
            -
             | 
| 218 | 
            -
             | 
| 218 | 
            +
                      govuk_step_by_step_navigation_options[:attributes]
         | 
| 219 | 
            +
                    end
         | 
| 219 220 |  | 
| 220 | 
            -
             | 
| 221 | 
            +
                    # Default text for the show and hide buttons which are part of each section
         | 
| 221 222 |  | 
| 222 | 
            -
             | 
| 223 | 
            +
                    DEFAULT_SHOW_HIDE_TEXT = { 'show-text': 'Show', 'hide-text': 'Hide', 'show-all-text': 'Show all', 'hide-all-text': 'Hide all' }.freeze
         | 
| 224 | 
            +
                  end
         | 
| 223 225 | 
             
                end
         | 
| 224 226 | 
             
              end
         | 
| 225 227 | 
             
            end
         | 
| @@ -2,37 +2,39 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            require 'action_view'
         | 
| 4 4 |  | 
| 5 | 
            -
            module CrownMarketplaceUtils | 
| 6 | 
            -
              module  | 
| 7 | 
            -
                 | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 5 | 
            +
            module CrownMarketplaceUtils
         | 
| 6 | 
            +
              module Helpers
         | 
| 7 | 
            +
                module GovUkHelper
         | 
| 8 | 
            +
                  # = GOV.UK Tag
         | 
| 9 | 
            +
                  #
         | 
| 10 | 
            +
                  # This helper is used for generating the tag component from the
         | 
| 11 | 
            +
                  # {https://design-system.service.gov.uk/components/tag GDS - Components - Tag}
         | 
| 11 12 |  | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 13 | 
            +
                  module Tag
         | 
| 14 | 
            +
                    include ActionView::Context
         | 
| 15 | 
            +
                    include ActionView::Helpers::TagHelper
         | 
| 15 16 |  | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 17 | 
            +
                    # Generates the HTML for the GOV.UK Tag component
         | 
| 18 | 
            +
                    #
         | 
| 19 | 
            +
                    # @param text [String] the text for the tag
         | 
| 20 | 
            +
                    # @param colour [String] optional colour for the tag,
         | 
| 21 | 
            +
                    #                        see {https://design-system.service.gov.uk/components/tag/#additional-colours Tag - Additional colours}
         | 
| 22 | 
            +
                    #                        for available colours in GOV.UK Frontend
         | 
| 23 | 
            +
                    # @param govuk_tag_options [Hash] options that will be used in customising the HTML
         | 
| 24 | 
            +
                    #
         | 
| 25 | 
            +
                    # @option govuk_tag_options [String] :classes additional CSS classes for the tag HTML
         | 
| 26 | 
            +
                    # @option govuk_tag_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
         | 
| 27 | 
            +
                    #
         | 
| 28 | 
            +
                    # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Tag
         | 
| 29 | 
            +
                    #                                     which can then be rendered on the page
         | 
| 29 30 |  | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 31 | 
            +
                    def govuk_tag(text, colour = nil, **govuk_tag_options)
         | 
| 32 | 
            +
                      govuk_tag_classes = ['govuk-tag']
         | 
| 33 | 
            +
                      govuk_tag_classes << "govuk-tag--#{colour}" if colour
         | 
| 34 | 
            +
                      govuk_tag_classes << govuk_tag_options[:classes]
         | 
| 34 35 |  | 
| 35 | 
            -
             | 
| 36 | 
            +
                      tag.strong(text, class: govuk_tag_classes, **(govuk_tag_options[:attributes] || {}))
         | 
| 37 | 
            +
                    end
         | 
| 36 38 | 
             
                  end
         | 
| 37 39 | 
             
                end
         | 
| 38 40 | 
             
              end
         | 
| @@ -2,48 +2,50 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            require 'action_view'
         | 
| 4 4 |  | 
| 5 | 
            -
            module CrownMarketplaceUtils | 
| 6 | 
            -
              module  | 
| 7 | 
            -
                 | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 5 | 
            +
            module CrownMarketplaceUtils
         | 
| 6 | 
            +
              module Helpers
         | 
| 7 | 
            +
                module GovUkHelper
         | 
| 8 | 
            +
                  # = GOV.UK Warning text
         | 
| 9 | 
            +
                  #
         | 
| 10 | 
            +
                  # This helper is used for generating the warning text component from the
         | 
| 11 | 
            +
                  # {https://design-system.service.gov.uk/components/warning-text GDS - Components - Warning text}
         | 
| 11 12 |  | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 13 | 
            +
                  module WarningText
         | 
| 14 | 
            +
                    include ActionView::Context
         | 
| 15 | 
            +
                    include ActionView::Helpers::TagHelper
         | 
| 16 | 
            +
                    include ActionView::Helpers::TextHelper
         | 
| 16 17 |  | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 18 | 
            +
                    # Generates the HTML for the GOV.UK Warning text component
         | 
| 19 | 
            +
                    #
         | 
| 20 | 
            +
                    # @param text [String] (nil) the text for the warning
         | 
| 21 | 
            +
                    # @param govuk_warning_text_options [Hash] options that will be used in customising the HTML
         | 
| 22 | 
            +
                    #
         | 
| 23 | 
            +
                    # @option govuk_warning_text_options [String] :classes additional CSS classes for the tag HTML
         | 
| 24 | 
            +
                    # @option govuk_warning_text_options [String] :icon_fallback_text the fallback text for the icon (default: +'Warning'+)
         | 
| 25 | 
            +
                    # @option govuk_warning_text_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
         | 
| 26 | 
            +
                    #
         | 
| 27 | 
            +
                    # @yield HTML that will be used in the warning text. Ignored if text is passed.
         | 
| 28 | 
            +
                    #
         | 
| 29 | 
            +
                    # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Warning text
         | 
| 30 | 
            +
                    #                                     which can then be rendered on the page
         | 
| 30 31 |  | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 32 | 
            +
                    def govuk_warning_text(text = nil, **govuk_warning_text_options)
         | 
| 33 | 
            +
                      govuk_warning_text_options[:class] = "govuk-warning-text #{govuk_warning_text_options[:classes]}".rstrip
         | 
| 33 34 |  | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 35 | 
            +
                      tag.div(class: govuk_warning_text_options[:class], **(govuk_warning_text_options[:attributes] || {})) do
         | 
| 36 | 
            +
                        capture do
         | 
| 37 | 
            +
                          concat(tag.span('!', class: 'govuk-warning-text__icon'))
         | 
| 38 | 
            +
                          concat(tag.strong(class: 'govuk-warning-text__text') do
         | 
| 39 | 
            +
                            capture do
         | 
| 40 | 
            +
                              concat(tag.span(govuk_warning_text_options[:icon_fallback_text] || 'Warning', class: 'govuk-warning-text__assistive'))
         | 
| 41 | 
            +
                              if text
         | 
| 42 | 
            +
                                concat(text)
         | 
| 43 | 
            +
                              else
         | 
| 44 | 
            +
                                yield
         | 
| 45 | 
            +
                              end
         | 
| 44 46 | 
             
                            end
         | 
| 45 | 
            -
                          end
         | 
| 46 | 
            -
                        end | 
| 47 | 
            +
                          end)
         | 
| 48 | 
            +
                        end
         | 
| 47 49 | 
             
                      end
         | 
| 48 50 | 
             
                    end
         | 
| 49 51 | 
             
                  end
         |