Class: CCS::Components::GovUK::ServiceNavigation
- Defined in:
- lib/ccs/components/govuk/service_navigation.rb,
lib/ccs/components/govuk/service_navigation/link.rb,
lib/ccs/components/govuk/service_navigation/navigation.rb
Overview
GOV.UK Service Navigation
This is used to generate the service navigation component from the GDS - Components - Service navigation
Defined Under Namespace
Classes: Link, Navigation
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
The default attributes for the service navigation
{ class: 'govuk-service-navigation', data: { module: 'govuk-service-navigation' } }.freeze
Instance Attribute Summary collapse
-
#href ⇒ String
readonly
The href for the service navigation.
-
#text ⇒ String
readonly
Text for the service navigation.
Instance Method Summary collapse
-
#initialize(navigation: nil, menu_button: nil, service: nil, **options) ⇒ ServiceNavigation
constructor
A new instance of ServiceNavigation.
-
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Service navigation component.
Constructor Details
#initialize(navigation: nil, menu_button: nil, service: nil, **options) ⇒ ServiceNavigation
Returns a new instance of ServiceNavigation.
37 38 39 40 41 42 43 44 |
# File 'lib/ccs/components/govuk/service_navigation.rb', line 37 def initialize(navigation: nil, menu_button: nil, service: nil, **) super(**) (@options[:attributes][:aria] ||= {})[:label] ||= 'Service information' if service @navigation = Navigation.new(navigation: , menu_button: , context: @context) if && [:items].present? @service = service end |
Instance Attribute Details
#href ⇒ String (readonly)
Returns The href for the service navigation.
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 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 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ccs/components/govuk/service_navigation.rb', line 17 class ServiceNavigation < Base private attr_reader :navigation, :service public # @param navigation [Hash] options for the navigation section of the service navigation. # See {Components::GovUK::ServiceNavigation::Navigation#initialize Navigation#initialize} for details of the options. # @param menu_button [Hash] options for the menu button in the service navigation. # See {Components::GovUK::ServiceNavigation::Navigation#initialize Navigation#initialize} for details of the options. # @param service [Hash] options for the service name # @param options [Hash] options that will be used in customising the HTML # # @option service [String] :name the name of the service, included in the service navigation # @option service [String] :href URL for the service name anchor # # @option options [String] :classes additional CSS classes for the service navigation HTML # @option options [Hash] :attributes additional attributes that will added as part of the service navigation HTML def initialize(navigation: nil, menu_button: nil, service: nil, **) super(**) (@options[:attributes][:aria] ||= {})[:label] ||= 'Service information' if service @navigation = Navigation.new(navigation: , menu_button: , context: @context) if && [:items].present? @service = service end # Generates the HTML for the GOV.UK Service navigation component # # @return [ActiveSupport::SafeBuffer] def render if service tag.section(inner_content, **[:attributes]) else tag.div(inner_content, **[:attributes]) end end # The default attributes for the service navigation DEFAULT_ATTRIBUTES = { class: 'govuk-service-navigation', data: { module: 'govuk-service-navigation' } }.freeze private # Generates the HTML for the inner content of the GOV.UK Service navigation component # # @return [ActiveSupport::SafeBuffer] def inner_content tag.div(class: 'govuk-width-container') do tag.div(class: 'govuk-service-navigation__container') do concat(tag.span(, class: 'govuk-service-navigation__service-name')) if service concat(.render) if end end end # Generates the service name section # # @return [ActiveSupport::SafeBuffer] def if service[:href] link_to(service[:name], service[:href], class: 'govuk-service-navigation__link') else tag.span(service[:name], class: 'govuk-service-navigation__text') end end end |
#text ⇒ String (readonly)
Returns Text for the service navigation.
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 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 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ccs/components/govuk/service_navigation.rb', line 17 class ServiceNavigation < Base private attr_reader :navigation, :service public # @param navigation [Hash] options for the navigation section of the service navigation. # See {Components::GovUK::ServiceNavigation::Navigation#initialize Navigation#initialize} for details of the options. # @param menu_button [Hash] options for the menu button in the service navigation. # See {Components::GovUK::ServiceNavigation::Navigation#initialize Navigation#initialize} for details of the options. # @param service [Hash] options for the service name # @param options [Hash] options that will be used in customising the HTML # # @option service [String] :name the name of the service, included in the service navigation # @option service [String] :href URL for the service name anchor # # @option options [String] :classes additional CSS classes for the service navigation HTML # @option options [Hash] :attributes additional attributes that will added as part of the service navigation HTML def initialize(navigation: nil, menu_button: nil, service: nil, **) super(**) (@options[:attributes][:aria] ||= {})[:label] ||= 'Service information' if service @navigation = Navigation.new(navigation: , menu_button: , context: @context) if && [:items].present? @service = service end # Generates the HTML for the GOV.UK Service navigation component # # @return [ActiveSupport::SafeBuffer] def render if service tag.section(inner_content, **[:attributes]) else tag.div(inner_content, **[:attributes]) end end # The default attributes for the service navigation DEFAULT_ATTRIBUTES = { class: 'govuk-service-navigation', data: { module: 'govuk-service-navigation' } }.freeze private # Generates the HTML for the inner content of the GOV.UK Service navigation component # # @return [ActiveSupport::SafeBuffer] def inner_content tag.div(class: 'govuk-width-container') do tag.div(class: 'govuk-service-navigation__container') do concat(tag.span(, class: 'govuk-service-navigation__service-name')) if service concat(.render) if end end end # Generates the service name section # # @return [ActiveSupport::SafeBuffer] def if service[:href] link_to(service[:name], service[:href], class: 'govuk-service-navigation__link') else tag.span(service[:name], class: 'govuk-service-navigation__text') end end end |
Instance Method Details
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Service navigation component
50 51 52 53 54 55 56 |
# File 'lib/ccs/components/govuk/service_navigation.rb', line 50 def render if service tag.section(inner_content, **[:attributes]) else tag.div(inner_content, **[:attributes]) end end |