Class: CCS::Components::GovUK::ServiceNavigation::Navigation
- Inherits:
-
Object
- Object
- CCS::Components::GovUK::ServiceNavigation::Navigation
- Includes:
- ActionView::Context, ActionView::Helpers
- Defined in:
- lib/ccs/components/govuk/service_navigation/navigation.rb
Overview
GOV.UK Service navigation navigation
The service navigation navigation section
Instance Attribute Summary collapse
-
#navigation_classes ⇒ String
readonly
The classes for the navigation.
-
#navigation_id ⇒ String
readonly
The id for the navigation.
-
#navigation_label ⇒ String
readonly
The aria label for the navigation.
Instance Method Summary collapse
-
#initialize(navigation:, context:, menu_button: nil) ⇒ Navigation
constructor
A new instance of Navigation.
-
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Service Navigation navigation.
Constructor Details
#initialize(navigation:, context:, menu_button: nil) ⇒ Navigation
Returns a new instance of Navigation.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ccs/components/govuk/service_navigation/navigation.rb', line 48 def initialize(navigation:, context:, menu_button: nil) ||= {} [:text] ||= 'Menu' @navigation = { id: [:id] || 'navigation' } [:aria] = { controls: @navigation[:id] } [:aria][:label] = [:label] if [:label] && [:label] != [:text] @menu_button = @navigation[:links] = [:items].map { || Link.new(context: context, **) } @navigation[:label] = [:label] || [:text] @navigation[:class] = "govuk-service-navigation__wrapper #{[:classes]}".rstrip end |
Instance Attribute Details
#navigation_classes ⇒ String (readonly)
Returns The classes for the navigation.
22 23 24 25 26 27 28 29 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ccs/components/govuk/service_navigation/navigation.rb', line 22 class Navigation include ActionView::Context include ActionView::Helpers private attr_reader :navigation, :menu_button public # rubocop:disable Metrics/CyclomaticComplexity # @param navigation [Hash] options for the navigation # @param context [ActionView::Base] the view context # @param menu_button [Hash] options for the menu button # # @option navigation [Array] :items an array of links for the navigation section. # See {Components::GovUK::ServiceNavigation::Link#initialize Link#initialize} for details of the items in the array. # @option navigation [String] :classes additional CSS classes for the navigation HTML # @option navigation [String] :label text for the aria-label attribute of the navigation. Defaults to the menu button text # # @option menu_button [String] :text text for the button that opens the mobile navigation menu. # By default, this is set to +Menu+. # @option menu_button [String] :label text for the aria-label attribute of the button that opens the mobile navigation. # Defaults to +Show or hide menu+. def initialize(navigation:, context:, menu_button: nil) ||= {} [:text] ||= 'Menu' @navigation = { id: [:id] || 'navigation' } [:aria] = { controls: @navigation[:id] } [:aria][:label] = [:label] if [:label] && [:label] != [:text] @menu_button = @navigation[:links] = [:items].map { || Link.new(context: context, **) } @navigation[:label] = [:label] || [:text] @navigation[:class] = "govuk-service-navigation__wrapper #{[:classes]}".rstrip end # rubocop:enable Metrics/CyclomaticComplexity # Generates the HTML for the GOV.UK Service Navigation navigation # # @return [ActiveSupport::SafeBuffer] def render tag.nav(aria: { label: [:label] }, class: [:class]) do concat(([:text], type: :button, class: 'govuk-service-navigation__toggle govuk-js-service-navigation-toggle', aria: [:aria], hidden: true)) concat(tag.ul(id: [:id], class: 'govuk-service-navigation__list') do [:links].each { || concat(.render) } end) end end end |
#navigation_id ⇒ String (readonly)
Returns The id for the navigation.
22 23 24 25 26 27 28 29 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ccs/components/govuk/service_navigation/navigation.rb', line 22 class Navigation include ActionView::Context include ActionView::Helpers private attr_reader :navigation, :menu_button public # rubocop:disable Metrics/CyclomaticComplexity # @param navigation [Hash] options for the navigation # @param context [ActionView::Base] the view context # @param menu_button [Hash] options for the menu button # # @option navigation [Array] :items an array of links for the navigation section. # See {Components::GovUK::ServiceNavigation::Link#initialize Link#initialize} for details of the items in the array. # @option navigation [String] :classes additional CSS classes for the navigation HTML # @option navigation [String] :label text for the aria-label attribute of the navigation. Defaults to the menu button text # # @option menu_button [String] :text text for the button that opens the mobile navigation menu. # By default, this is set to +Menu+. # @option menu_button [String] :label text for the aria-label attribute of the button that opens the mobile navigation. # Defaults to +Show or hide menu+. def initialize(navigation:, context:, menu_button: nil) ||= {} [:text] ||= 'Menu' @navigation = { id: [:id] || 'navigation' } [:aria] = { controls: @navigation[:id] } [:aria][:label] = [:label] if [:label] && [:label] != [:text] @menu_button = @navigation[:links] = [:items].map { || Link.new(context: context, **) } @navigation[:label] = [:label] || [:text] @navigation[:class] = "govuk-service-navigation__wrapper #{[:classes]}".rstrip end # rubocop:enable Metrics/CyclomaticComplexity # Generates the HTML for the GOV.UK Service Navigation navigation # # @return [ActiveSupport::SafeBuffer] def render tag.nav(aria: { label: [:label] }, class: [:class]) do concat(([:text], type: :button, class: 'govuk-service-navigation__toggle govuk-js-service-navigation-toggle', aria: [:aria], hidden: true)) concat(tag.ul(id: [:id], class: 'govuk-service-navigation__list') do [:links].each { || concat(.render) } end) end end end |
#navigation_label ⇒ String (readonly)
Returns The aria label for the navigation.
22 23 24 25 26 27 28 29 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ccs/components/govuk/service_navigation/navigation.rb', line 22 class Navigation include ActionView::Context include ActionView::Helpers private attr_reader :navigation, :menu_button public # rubocop:disable Metrics/CyclomaticComplexity # @param navigation [Hash] options for the navigation # @param context [ActionView::Base] the view context # @param menu_button [Hash] options for the menu button # # @option navigation [Array] :items an array of links for the navigation section. # See {Components::GovUK::ServiceNavigation::Link#initialize Link#initialize} for details of the items in the array. # @option navigation [String] :classes additional CSS classes for the navigation HTML # @option navigation [String] :label text for the aria-label attribute of the navigation. Defaults to the menu button text # # @option menu_button [String] :text text for the button that opens the mobile navigation menu. # By default, this is set to +Menu+. # @option menu_button [String] :label text for the aria-label attribute of the button that opens the mobile navigation. # Defaults to +Show or hide menu+. def initialize(navigation:, context:, menu_button: nil) ||= {} [:text] ||= 'Menu' @navigation = { id: [:id] || 'navigation' } [:aria] = { controls: @navigation[:id] } [:aria][:label] = [:label] if [:label] && [:label] != [:text] @menu_button = @navigation[:links] = [:items].map { || Link.new(context: context, **) } @navigation[:label] = [:label] || [:text] @navigation[:class] = "govuk-service-navigation__wrapper #{[:classes]}".rstrip end # rubocop:enable Metrics/CyclomaticComplexity # Generates the HTML for the GOV.UK Service Navigation navigation # # @return [ActiveSupport::SafeBuffer] def render tag.nav(aria: { label: [:label] }, class: [:class]) do concat(([:text], type: :button, class: 'govuk-service-navigation__toggle govuk-js-service-navigation-toggle', aria: [:aria], hidden: true)) concat(tag.ul(id: [:id], class: 'govuk-service-navigation__list') do [:links].each { || concat(.render) } end) end end end |
Instance Method Details
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Service Navigation navigation
69 70 71 72 73 74 75 76 |
# File 'lib/ccs/components/govuk/service_navigation/navigation.rb', line 69 def render tag.nav(aria: { label: [:label] }, class: [:class]) do concat(([:text], type: :button, class: 'govuk-service-navigation__toggle govuk-js-service-navigation-toggle', aria: [:aria], hidden: true)) concat(tag.ul(id: [:id], class: 'govuk-service-navigation__list') do [:links].each { || concat(.render) } end) end end |