ccs-frontend_helpers 0.1.0.rc.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -5
  3. data/CHANGELOG.md +2 -4
  4. data/Gemfile +1 -15
  5. data/Gemfile.lock +80 -81
  6. data/ccs-frontend_helpers.gemspec +10 -0
  7. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +79 -0
  8. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +119 -6
  9. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +183 -6
  10. data/lib/ccs/{components/ccs → frontend_helpers/ccs_frontend}/logo.rb +12 -10
  11. data/lib/ccs/frontend_helpers/ccs_frontend.rb +4 -2
  12. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +95 -8
  13. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -6
  14. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +54 -6
  15. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +105 -6
  16. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +114 -6
  17. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +23 -7
  18. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -11
  19. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +65 -13
  20. data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +165 -0
  21. data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +200 -0
  22. data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +153 -0
  23. data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +83 -0
  24. data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +153 -0
  25. data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +201 -0
  26. data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +124 -0
  27. data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +106 -0
  28. data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +213 -0
  29. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +48 -7
  30. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +161 -6
  31. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +24 -13
  32. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +139 -6
  33. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +17 -8
  34. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +21 -7
  35. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +70 -7
  36. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +113 -7
  37. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +314 -6
  38. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +28 -7
  39. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +27 -8
  40. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +18 -6
  41. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +186 -7
  42. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +204 -6
  43. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +100 -11
  44. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +73 -6
  45. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +21 -7
  46. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +30 -7
  47. data/lib/ccs/frontend_helpers/govuk_frontend.rb +19 -17
  48. data/lib/ccs/frontend_helpers/shared_methods.rb +27 -0
  49. data/lib/ccs/frontend_helpers/version.rb +1 -1
  50. metadata +142 -112
  51. data/.ruby-version +0 -1
  52. data/lib/ccs/components/base.rb +0 -64
  53. data/lib/ccs/components/ccs/dashboard_section/panel.rb +0 -57
  54. data/lib/ccs/components/ccs/dashboard_section.rb +0 -71
  55. data/lib/ccs/components/ccs/footer/link.rb +0 -55
  56. data/lib/ccs/components/ccs/footer/meta.rb +0 -59
  57. data/lib/ccs/components/ccs/footer/navigation.rb +0 -60
  58. data/lib/ccs/components/ccs/footer.rb +0 -95
  59. data/lib/ccs/components/ccs/header/link.rb +0 -60
  60. data/lib/ccs/components/ccs/header/navigation.rb +0 -98
  61. data/lib/ccs/components/ccs/header/service_authentication.rb +0 -53
  62. data/lib/ccs/components/ccs/header.rb +0 -110
  63. data/lib/ccs/components/govuk/accordion/section/content.rb +0 -53
  64. data/lib/ccs/components/govuk/accordion/section/header.rb +0 -57
  65. data/lib/ccs/components/govuk/accordion/section.rb +0 -61
  66. data/lib/ccs/components/govuk/accordion.rb +0 -58
  67. data/lib/ccs/components/govuk/back_link.rb +0 -51
  68. data/lib/ccs/components/govuk/breadcrumbs/link.rb +0 -57
  69. data/lib/ccs/components/govuk/breadcrumbs.rb +0 -55
  70. data/lib/ccs/components/govuk/button.rb +0 -107
  71. data/lib/ccs/components/govuk/cookie_banner/action.rb +0 -60
  72. data/lib/ccs/components/govuk/cookie_banner/message.rb +0 -80
  73. data/lib/ccs/components/govuk/cookie_banner.rb +0 -55
  74. data/lib/ccs/components/govuk/details.rb +0 -53
  75. data/lib/ccs/components/govuk/error_message.rb +0 -60
  76. data/lib/ccs/components/govuk/error_summary/item.rb +0 -54
  77. data/lib/ccs/components/govuk/error_summary.rb +0 -70
  78. data/lib/ccs/components/govuk/field/input/character_count.rb +0 -129
  79. data/lib/ccs/components/govuk/field/input/file_upload.rb +0 -44
  80. data/lib/ccs/components/govuk/field/input/select.rb +0 -82
  81. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +0 -55
  82. data/lib/ccs/components/govuk/field/input/text_input.rb +0 -97
  83. data/lib/ccs/components/govuk/field/input/textarea.rb +0 -59
  84. data/lib/ccs/components/govuk/field/input.rb +0 -62
  85. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +0 -69
  86. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +0 -65
  87. data/lib/ccs/components/govuk/field/inputs/date_input.rb +0 -89
  88. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +0 -47
  89. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +0 -43
  90. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +0 -50
  91. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +0 -50
  92. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +0 -44
  93. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +0 -43
  94. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +0 -50
  95. data/lib/ccs/components/govuk/field/inputs/item.rb +0 -111
  96. data/lib/ccs/components/govuk/field/inputs/radios.rb +0 -69
  97. data/lib/ccs/components/govuk/field/inputs.rb +0 -57
  98. data/lib/ccs/components/govuk/field.rb +0 -108
  99. data/lib/ccs/components/govuk/fieldset/legend.rb +0 -65
  100. data/lib/ccs/components/govuk/fieldset.rb +0 -54
  101. data/lib/ccs/components/govuk/footer/link.rb +0 -55
  102. data/lib/ccs/components/govuk/footer/meta.rb +0 -59
  103. data/lib/ccs/components/govuk/footer/navigation.rb +0 -60
  104. data/lib/ccs/components/govuk/footer.rb +0 -131
  105. data/lib/ccs/components/govuk/form_group.rb +0 -60
  106. data/lib/ccs/components/govuk/header/link.rb +0 -56
  107. data/lib/ccs/components/govuk/header/navigation.rb +0 -71
  108. data/lib/ccs/components/govuk/header.rb +0 -107
  109. data/lib/ccs/components/govuk/hint.rb +0 -49
  110. data/lib/ccs/components/govuk/inset_text.rb +0 -52
  111. data/lib/ccs/components/govuk/label.rb +0 -85
  112. data/lib/ccs/components/govuk/notification_banner.rb +0 -107
  113. data/lib/ccs/components/govuk/pagination/increment/next.rb +0 -44
  114. data/lib/ccs/components/govuk/pagination/increment/previous.rb +0 -43
  115. data/lib/ccs/components/govuk/pagination/increment.rb +0 -98
  116. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +0 -28
  117. data/lib/ccs/components/govuk/pagination/item/form.rb +0 -49
  118. data/lib/ccs/components/govuk/pagination/item/tag.rb +0 -47
  119. data/lib/ccs/components/govuk/pagination/item.rb +0 -64
  120. data/lib/ccs/components/govuk/pagination.rb +0 -96
  121. data/lib/ccs/components/govuk/panel.rb +0 -62
  122. data/lib/ccs/components/govuk/phase_banner.rb +0 -69
  123. data/lib/ccs/components/govuk/skip_link.rb +0 -51
  124. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +0 -53
  125. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +0 -50
  126. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +0 -45
  127. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +0 -63
  128. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +0 -69
  129. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +0 -56
  130. data/lib/ccs/components/govuk/step_by_step_navigation.rb +0 -59
  131. data/lib/ccs/components/govuk/summary_list/action/link.rb +0 -59
  132. data/lib/ccs/components/govuk/summary_list/card/actions.rb +0 -59
  133. data/lib/ccs/components/govuk/summary_list/card/title.rb +0 -51
  134. data/lib/ccs/components/govuk/summary_list/card.rb +0 -63
  135. data/lib/ccs/components/govuk/summary_list/row/actions.rb +0 -59
  136. data/lib/ccs/components/govuk/summary_list/row/key.rb +0 -47
  137. data/lib/ccs/components/govuk/summary_list/row/value.rb +0 -47
  138. data/lib/ccs/components/govuk/summary_list/row.rb +0 -67
  139. data/lib/ccs/components/govuk/summary_list.rb +0 -74
  140. data/lib/ccs/components/govuk/table/body/data_cell.rb +0 -53
  141. data/lib/ccs/components/govuk/table/body/head_cell.rb +0 -52
  142. data/lib/ccs/components/govuk/table/header/head_cell.rb +0 -54
  143. data/lib/ccs/components/govuk/table.rb +0 -111
  144. data/lib/ccs/components/govuk/tabs/panel.rb +0 -58
  145. data/lib/ccs/components/govuk/tabs/tab.rb +0 -56
  146. data/lib/ccs/components/govuk/tabs.rb +0 -66
  147. data/lib/ccs/components/govuk/tag.rb +0 -51
  148. data/lib/ccs/components/govuk/warning_text.rb +0 -61
  149. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +0 -27
  150. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +0 -28
  151. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +0 -28
  152. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +0 -28
  153. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +0 -28
  154. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +0 -28
  155. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +0 -28
  156. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +0 -28
  157. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +0 -28
@@ -1,60 +0,0 @@
1
- require_relative 'link'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Footer < Base
7
- # = GOV.UK Footer Navigation
8
- #
9
- # The individual footer navigation item
10
- #
11
- # @!attribute [r] title
12
- # @return [String] Title for the navigation section
13
- # @!attribute [r] navigation_links
14
- # @return [Array<Link>] An array of the initialised navigation links
15
- # @!attribute [r] width
16
- # @return [String] Width of the navigation section
17
- # @!attribute [r] columns
18
- # @return [Integer] Number of columns to display the links in
19
-
20
- class Navigation
21
- include ActionView::Context
22
- include ActionView::Helpers
23
-
24
- private
25
-
26
- attr_reader :title, :navigation_links, :width, :columns
27
-
28
- public
29
-
30
- # @param title [String] the title for the navigation section
31
- # @param items [Array<Hash>] an array of links for the navigation section.
32
- # See {Components::GovUK::Footer::Link#initialize Link#initialize} for details of the items in the array.
33
- # @param width [String] ('full') width of each navigation section in the footer
34
- # @param columns [Integer] (nil) number of columns to display the links
35
- # @param context [ActionView::Base] the view context
36
-
37
- def initialize(title:, items:, context:, width: nil, columns: nil)
38
- @title = title
39
- @navigation_links = items.map { |navigation_link| Link.new(li_class: 'govuk-footer__list-item', context: context, **navigation_link) }
40
- @width = width || 'full'
41
- @columns = columns
42
- end
43
-
44
- # Generates the HTML for the GOV.UK Footer Navigation sections
45
- #
46
- # @return [ActiveSupport::SafeBuffer]
47
-
48
- def render
49
- tag.div(class: "govuk-footer__section govuk-grid-column-#{width}") do
50
- concat(tag.h2(title, class: 'govuk-footer__heading govuk-heading-m'))
51
- concat(tag.ul(class: "govuk-footer__list #{"govuk-footer__list--columns-#{columns}" if columns}".rstrip) do
52
- navigation_links.each { |navigation_link| concat(navigation_link.render) }
53
- end)
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end
60
- end
@@ -1,131 +0,0 @@
1
- require_relative '../base'
2
- require_relative 'footer/navigation'
3
- require_relative 'footer/meta'
4
-
5
- module CCS
6
- module Components
7
- module GovUK
8
- # = GOV.UK Footer
9
- #
10
- # This is used to generate the footer component from the
11
- # {https://design-system.service.gov.uk/components/footer GDS - Components - Footer}
12
- #
13
- # @!attribute [r] navigation
14
- # @return [Array<Navigation>] An array of the initialised navigation sections
15
- # @!attribute [r] meta
16
- # @return [Meta] The initialised meta section
17
-
18
- class Footer < Base
19
- private
20
-
21
- attr_reader :navigation, :meta
22
-
23
- public
24
-
25
- # @param navigation [Array<Hash>] an array of sections for the footer navigation.
26
- # See {Components::GovUK::Footer::Navigation#initialize Navigation#initialize} for details of the items in the array.
27
- # @param meta [Hash] ptions for the meta section of the footer.
28
- # See {Components::GovUK::Footer::Meta#initialize Meta#initialize} for details of the options.
29
- # @param options [Hash] options that will be used in customising the HTML
30
- #
31
- # @option options [String] :classes additional CSS classes for the footer HTML
32
- # @option options [String] :container_class classes that can be added to the inner container
33
- # @option options [ActiveSupport::SafeBuffer,String] :content_licence The content licence information, see {CCS::Components::GovUK::Footer#footer_content_licence footer_content_licence} for default
34
- # @option options [ActiveSupport::SafeBuffer,String] :copyright The copyright information, (default: '© Crown copyright')
35
- # @option options [Hash] :attributes additional attributes that will added as part of the HTML
36
-
37
- def initialize(navigation: nil, meta: nil, **options)
38
- super(**options)
39
-
40
- @options[:attributes][:role] = 'contentinfo'
41
- @options[:copyright] ||= '© Crown copyright'
42
-
43
- @navigation = navigation&.map { |navigation_item| Navigation.new(context: @context, **navigation_item) }
44
- @meta = Meta.new(context: @context, **meta) if meta
45
- end
46
-
47
- # rubocop:disable Metrics/AbcSize
48
-
49
- # Generates the HTML for the GOV.UK Footer component
50
- #
51
- # @return [ActiveSupport::SafeBuffer]
52
-
53
- def render
54
- tag.footer(**options[:attributes]) do
55
- tag.div(class: "govuk-width-container #{options[:container_classes]}".rstrip) do
56
- if navigation
57
- concat(tag.div(class: 'govuk-footer__navigation') do
58
- navigation.each { |navigation_item| concat(navigation_item.render) }
59
- end)
60
- concat(tag.hr(class: 'govuk-footer__section-break'))
61
- end
62
- concat(tag.div(class: 'govuk-footer__meta') do
63
- concat(tag.div(class: 'govuk-footer__meta-item govuk-footer__meta-item--grow') do
64
- concat(meta.render) if meta
65
- concat(footer_logo)
66
- concat(footer_content_licence)
67
- end)
68
- concat(footer_copyright)
69
- end)
70
- end
71
- end
72
- end
73
-
74
- # rubocop:enable Metrics/AbcSize
75
-
76
- # The default attributes for the breadcrumbs
77
-
78
- DEFAULT_ATTRIBUTES = { class: 'govuk-footer' }.freeze
79
-
80
- private
81
-
82
- # Generates the logo used in the footer
83
- #
84
- # @return [ActiveSupport::SafeBuffer]
85
-
86
- def footer_logo
87
- tag.svg(
88
- class: 'govuk-footer__licence-logo',
89
- aria: { hidden: 'true' },
90
- focusable: 'false',
91
- xmlns: 'http://www.w3.org/2000/svg',
92
- viewBox: '0 0 483.2 195.7',
93
- height: '17',
94
- width: '41'
95
- ) do
96
- tag.path(
97
- fill: 'currentColor',
98
- d: 'M421.5 142.8V.1l-50.7 32.3v161.1h112.4v-50.7zm-122.3-9.6A47.12 47.12 0 0 1 221 97.8c0-26 21.1-47.1 47.1-47.1 16.7 0 31.4 8.7 39.7 21.8l42.7-27.2A97.63 97.63 0 0 0 268.1 0c-36.5 0-68.3 20.1-85.1 49.7A98 98 0 0 0 97.8 0C43.9 0 0 43.9 0 97.8s43.9 97.8 97.8 97.8c36.5 0 68.3-20.1 85.1-49.7a97.76 97.76 0 0 0 149.6 25.4l19.4 22.2h3v-87.8h-80l24.3 27.5zM97.8 145c-26 0-47.1-21.1-47.1-47.1s21.1-47.1 47.1-47.1 47.2 21 47.2 47S123.8 145 97.8 145'
99
- )
100
- end
101
- end
102
-
103
- # Generates the content licence for the footer
104
- #
105
- # @return [ActiveSupport::SafeBuffer]
106
-
107
- def footer_content_licence
108
- tag.span(class: 'govuk-footer__licence-description') do
109
- if options[:content_licence]
110
- concat(options[:content_licence])
111
- else
112
- concat('All content is available under the')
113
- concat(link_to('Open Government Licence v3.0', 'https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/', class: 'govuk-footer__link', rel: 'license'))
114
- concat(', except where otherwise stated')
115
- end
116
- end
117
- end
118
-
119
- # Generates the copyright used in the footer
120
- #
121
- # @return [ActiveSupport::SafeBuffer]
122
-
123
- def footer_copyright
124
- tag.div(class: 'govuk-footer__meta-item') do
125
- link_to(options[:copyright], 'https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/', class: 'govuk-footer__link govuk-footer__copyright-logo')
126
- end
127
- end
128
- end
129
- end
130
- end
131
- end
@@ -1,60 +0,0 @@
1
- require_relative '../base'
2
- require_relative 'error_message'
3
-
4
- module CCS
5
- module Components
6
- module GovUK
7
- # = GOV.UK FormGroup
8
- #
9
- # This helper is used for generating the form group component from the Government Design Systems
10
- #
11
- # @!attribute [r] attribute
12
- # @return [String,Symbol] Attribute that the form group is for
13
- # @!attribute [r] error_message
14
- # @return [String] Text for the error message
15
-
16
- class FormGroup < Base
17
- private
18
-
19
- attr_reader :attribute, :error_message
20
-
21
- public
22
-
23
- # @param attribute [String,Symbol] the attribute that the form group is for
24
- # @param error_message [String] (nil) the error message to be displayed
25
- # @param options [Hash] options that will be used in customising the HTML
26
- #
27
- # @option options [String] :classes additional CSS classes for the form group HTML
28
- # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
29
-
30
- def initialize(attribute:, error_message: nil, **options)
31
- super(**options)
32
-
33
- @options[:attributes][:id] ||= "#{attribute}-form-group"
34
- @options[:attributes][:class][..15] = 'govuk-form-group govuk-form-group--error' if error_message
35
-
36
- @attribute = attribute
37
- @error_message = error_message
38
- end
39
-
40
- # Generates the HTML for the GOV.UK Form Group component
41
- #
42
- # @yield HTML that will be contained within the 'govuk-form-group' div
43
- #
44
- # @yieldparam displayed_error_message [ActiveSupport::SafeBuffer] the HTML for the error message (if there is one)
45
- #
46
- # @return [ActiveSupport::SafeBuffer]
47
-
48
- def render
49
- tag.div(**options[:attributes]) do
50
- yield((ErrorMessage.new(message: error_message, attribute: attribute, context: context).render if error_message))
51
- end
52
- end
53
-
54
- # The default attributes for the form group
55
-
56
- DEFAULT_ATTRIBUTES = { class: 'govuk-form-group' }.freeze
57
- end
58
- end
59
- end
60
- end
@@ -1,56 +0,0 @@
1
- require_relative '../../base'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Header < Base
7
- # = GOV.UK Header link
8
- #
9
- # The individual header link item
10
- #
11
- # @!attribute [r] text
12
- # @return [String] Text for the header link
13
- # @!attribute [r] href
14
- # @return [String] The href for the header link
15
-
16
- class Link < Base
17
- private
18
-
19
- attr_reader :text, :href
20
-
21
- public
22
-
23
- # @param text [String] the text for the header link
24
- # @param href [String] the href for the header link
25
- # @param options [Hash] options that will be used in customising the HTML
26
- #
27
- # @option options [Boolean] :active flag to mark the navigation item as active or not
28
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
29
-
30
- def initialize(text:, href: nil, **options)
31
- super(**options)
32
-
33
- @text = text
34
- @href = href
35
- end
36
-
37
- # Generates the HTML for the GOV.UK Header link
38
- #
39
- # @return [ActiveSupport::SafeBuffer]
40
-
41
- def render
42
- tag.li(class: "govuk-header__navigation-item #{'govuk-header__navigation-item--active' if options[:active]}".rstrip) do
43
- if href
44
- options[:attributes][:class] = 'govuk-header__link'
45
-
46
- link_to(text, href, **options[:attributes])
47
- else
48
- text
49
- end
50
- end
51
- end
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,71 +0,0 @@
1
- require_relative 'link'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Header < Base
7
- # = GOV.UK Header navigation
8
- #
9
- # The header navigation section
10
- #
11
- # @!attribute [r] navigation_links
12
- # @return [Array<Link>] An array of the initialised navigation links
13
- # @!attribute [r] navigation_label
14
- # @return [String] The aria label for the navigation
15
- # @!attribute [r] navigation_classes
16
- # @return [String] The classes for the navigation
17
- # @!attribute [r] menu_button
18
- # @return [Hash] The options for the menu button
19
-
20
- class Navigation
21
- include ActionView::Context
22
- include ActionView::Helpers
23
-
24
- private
25
-
26
- attr_reader :navigation_links, :navigation_label, :navigation_classes, :menu_button
27
-
28
- public
29
-
30
- # @param navigation [Hash] options for the navigation
31
- # @param context [ActionView::Base] the view context
32
- # @param menu_button [Hash] options for the menu button
33
- #
34
- # @option navigation [Array] :items an array of links for the navigation section.
35
- # See {Components::GovUK::Header::Link#initialize Link#initialize} for details of the items in the array.
36
- # @option navigation [String] :classes additional CSS classes for the navigation HTML
37
- # @option navigation [String] :label text for the aria-label attribute of the navigation. Defaults to the menu button text
38
- #
39
- # @option menu_button [String] :text text for the button that opens the mobile navigation menu.
40
- # By default, this is set to +Menu+.
41
- # @option menu_button [String] :label text for the aria-label attribute of the button that opens the mobile navigation.
42
- # Defaults to +Show or hide menu+.
43
-
44
- def initialize(navigation:, context:, menu_button: nil)
45
- menu_button ||= {}
46
- menu_button[:text] ||= 'Menu'
47
- menu_button[:label] ||= 'Show or hide menu'
48
-
49
- @menu_button = menu_button
50
- @navigation_links = navigation[:items].map { |navigation_link| Link.new(context: context, **navigation_link) }
51
- @navigation_label = navigation[:label] || menu_button[:text]
52
- @navigation_classes = "govuk-header__navigation #{navigation[:classes]}".rstrip
53
- end
54
-
55
- # Generates the HTML for the GOV.UK Navigation
56
- #
57
- # @return [ActiveSupport::SafeBuffer]
58
-
59
- def render
60
- tag.nav(aria: { label: navigation_label }, class: navigation_classes) do
61
- concat(button_tag(menu_button[:text], type: :button, class: 'govuk-header__menu-button govuk-js-header-toggle', aria: { controls: 'navigation', label: menu_button[:label] }, hidden: true))
62
- concat(tag.ul(id: 'navigation', class: 'govuk-header__navigation-list') do
63
- navigation_links.each { |navigation_link| concat(navigation_link.render) }
64
- end)
65
- end
66
- end
67
- end
68
- end
69
- end
70
- end
71
- end
@@ -1,107 +0,0 @@
1
- require_relative '../base'
2
- require_relative 'header/navigation'
3
-
4
- module CCS
5
- module Components
6
- module GovUK
7
- # = GOV.UK Header
8
- #
9
- # This is used to generate the header component from the
10
- # {https://design-system.service.gov.uk/components/header GDS - Components - Header}
11
- #
12
- # @!attribute [r] navigation
13
- # @return [Navigation] The initialised navigation section
14
- # @!attribute [r] service
15
- # @return [Hash] The options for the service section
16
-
17
- class Header < Base
18
- private
19
-
20
- attr_reader :navigation, :service
21
-
22
- public
23
-
24
- # @param navigation [Hash] options for the navigation section of the header.
25
- # See {Components::GovUK::Header::Navigation#initialize Navigation#initialize} for details of the options.
26
- # @param menu_button [Hash] options for the menu button in the header.
27
- # See {Components::GovUK::Header::Navigation#initialize Navigation#initialize} for details of the options.
28
- # @param service [Hash] options for the service name
29
- # @param options [Hash] options that will be used in customising the HTML
30
- #
31
- # @option service [String] :name the name of the service, included in the header
32
- # @option service [String] :href URL for the service name anchor
33
- #
34
- # @option options [String] :classes additional CSS classes for the header HTML
35
- # @option options [String] :container_classes classes for the container
36
- # @option options [String] :homepage_url URL of the homepage. Defaults to +/+
37
- # @option options [String] :product_name product name, used when the product name follows on directly from ‘GOV.UK
38
- # @option options [Hash] :attributes additional attributes that will added as part of the header HTML
39
-
40
- def initialize(navigation: nil, menu_button: nil, service: nil, **options)
41
- super(**options)
42
-
43
- @options[:attributes][:role] = 'banner'
44
- @options[:container_classes] ||= 'govuk-width-container'
45
- @options[:homepage_url] ||= '/'
46
-
47
- @navigation = Navigation.new(navigation: navigation, menu_button: menu_button, context: @context) if navigation
48
- @service = service
49
- end
50
-
51
- # Generates the HTML for the GOV.UK Header component
52
- #
53
- # @return [ActiveSupport::SafeBuffer]
54
-
55
- def render
56
- tag.header(**options[:attributes]) do
57
- tag.div(class: "govuk-header__container #{options[:container_classes]}") do
58
- concat(header_logo)
59
- if service || navigation
60
- concat(tag.div(class: 'govuk-header__content') do
61
- concat(header_service_name) if service
62
- concat(navigation.render) if navigation
63
- end)
64
- end
65
- end
66
- end
67
- end
68
-
69
- # The default attributes for the breadcrumbs
70
-
71
- DEFAULT_ATTRIBUTES = { class: 'govuk-header', data: { module: 'govuk-header' } }.freeze
72
-
73
- private
74
-
75
- # Generates the logo for header
76
- #
77
- # @return [ActiveSupport::SafeBuffer]
78
-
79
- def header_logo
80
- tag.div(class: 'govuk-header__logo') do
81
- link_to(options[:homepage_url], class: 'govuk-header__link govuk-header__link--homepage') do
82
- concat(tag.span(class: 'govuk-header__logotype') do
83
- concat(tag.svg(class: 'govuk-header__logotype-crown', xmlns: 'http://www.w3.org/2000/svg', height: '30', width: '36', aria: { hidden: 'true' }, focusable: 'false', viewBox: '0 0 132 97') do
84
- tag.path(fill: 'currentColor', 'fill-rule': 'evenodd', d: 'M25 30.2c3.5 1.5 7.7-.2 9.1-3.7 1.5-3.6-.2-7.8-3.9-9.2-3.6-1.4-7.6.3-9.1 3.9-1.4 3.5.3 7.5 3.9 9zM9 39.5c3.6 1.5 7.8-.2 9.2-3.7 1.5-3.6-.2-7.8-3.9-9.1-3.6-1.5-7.6.2-9.1 3.8-1.4 3.5.3 7.5 3.8 9zM4.4 57.2c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.5-1.5-7.6.3-9.1 3.8-1.4 3.5.3 7.6 3.9 9.1zm38.3-21.4c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.6-1.5-7.6.3-9.1 3.8-1.3 3.6.4 7.7 3.9 9.1zm64.4-5.6c-3.6 1.5-7.8-.2-9.1-3.7-1.5-3.6.2-7.8 3.8-9.2 3.6-1.4 7.7.3 9.2 3.9 1.3 3.5-.4 7.5-3.9 9zm15.9 9.3c-3.6 1.5-7.7-.2-9.1-3.7-1.5-3.6.2-7.8 3.7-9.1 3.6-1.5 7.7.2 9.2 3.8 1.5 3.5-.3 7.5-3.8 9zm4.7 17.7c-3.6 1.5-7.8-.2-9.2-3.8-1.5-3.6.2-7.7 3.9-9.1 3.6-1.5 7.7.3 9.2 3.8 1.3 3.5-.4 7.6-3.9 9.1zM89.3 35.8c-3.6 1.5-7.8-.2-9.2-3.8-1.4-3.6.2-7.7 3.9-9.1 3.6-1.5 7.7.3 9.2 3.8 1.4 3.6-.3 7.7-3.9 9.1zM69.7 17.7l8.9 4.7V9.3l-8.9 2.8c-.2-.3-.5-.6-.9-.9L72.4 0H59.6l3.5 11.2c-.3.3-.6.5-.9.9l-8.8-2.8v13.1l8.8-4.7c.3.3.6.7.9.9l-5 15.4v.1c-.2.8-.4 1.6-.4 2.4 0 4.1 3.1 7.5 7 8.1h.2c.3 0 .7.1 1 .1.4 0 .7 0 1-.1h.2c4-.6 7.1-4.1 7.1-8.1 0-.8-.1-1.7-.4-2.4V34l-5.1-15.4c.4-.2.7-.6 1-.9zM66 92.8c16.9 0 32.8 1.1 47.1 3.2 4-16.9 8.9-26.7 14-33.5l-9.6-3.4c1 4.9 1.1 7.2 0 10.2-1.5-1.4-3-4.3-4.2-8.7L108.6 76c2.8-2 5-3.2 7.5-3.3-4.4 9.4-10 11.9-13.6 11.2-4.3-.8-6.3-4.6-5.6-7.9 1-4.7 5.7-5.9 8-.5 4.3-8.7-3-11.4-7.6-8.8 7.1-7.2 7.9-13.5 2.1-21.1-8 6.1-8.1 12.3-4.5 20.8-4.7-5.4-12.1-2.5-9.5 6.2 3.4-5.2 7.9-2 7.2 3.1-.6 4.3-6.4 7.8-13.5 7.2-10.3-.9-10.9-8-11.2-13.8 2.5-.5 7.1 1.8 11 7.3L80.2 60c-4.1 4.4-8 5.3-12.3 5.4 1.4-4.4 8-11.6 8-11.6H55.5s6.4 7.2 7.9 11.6c-4.2-.1-8-1-12.3-5.4l1.4 16.4c3.9-5.5 8.5-7.7 10.9-7.3-.3 5.8-.9 12.8-11.1 13.8-7.2.6-12.9-2.9-13.5-7.2-.7-5 3.8-8.3 7.1-3.1 2.7-8.7-4.6-11.6-9.4-6.2 3.7-8.5 3.6-14.7-4.6-20.8-5.8 7.6-5 13.9 2.2 21.1-4.7-2.6-11.9.1-7.7 8.8 2.3-5.5 7.1-4.2 8.1.5.7 3.3-1.3 7.1-5.7 7.9-3.5.7-9-1.8-13.5-11.2 2.5.1 4.7 1.3 7.5 3.3l-4.7-15.4c-1.2 4.4-2.7 7.2-4.3 8.7-1.1-3-.9-5.3 0-10.2l-9.5 3.4c5 6.9 9.9 16.7 14 33.5 14.8-2.1 30.8-3.2 47.7-3.2z')
85
- end)
86
- concat(tag.span('GOV.UK', class: 'govuk-header__logotype-text'))
87
- end)
88
- concat(tag.span(options[:product_name], class: 'govuk-header__product-name')) if options[:product_name]
89
- end
90
- end
91
- end
92
-
93
- # Generates the service name section
94
- #
95
- # @return [ActiveSupport::SafeBuffer]
96
-
97
- def header_service_name
98
- if service[:href]
99
- link_to(service[:name], service[:href], class: 'govuk-header__link govuk-header__service-name')
100
- else
101
- tag.span(service[:name], class: 'govuk-header__service-name')
102
- end
103
- end
104
- end
105
- end
106
- end
107
- end
@@ -1,49 +0,0 @@
1
- require_relative '../base'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- # = GOV.UK Hint
7
- #
8
- # This is used to generate the hint text component from the Government Design Systems
9
- #
10
- # @!attribute [r] text
11
- # @return [String] Text for the hint
12
-
13
- class Hint < Base
14
- private
15
-
16
- attr_reader :text
17
-
18
- public
19
-
20
- # @param text [String] the hint text.
21
- # If nil, then a block will be rendered
22
- # @param options [Hash] options that will be used in customising the HTML
23
- #
24
- # @option options [String] :classes additional CSS classes for the hint HTML
25
- # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
26
-
27
- def initialize(text: nil, **options)
28
- super(**options)
29
-
30
- @text = text
31
- end
32
-
33
- # Generates the HTML for the GOV.UK Hint component
34
- #
35
- # @return [ActiveSupport::SafeBuffer]
36
-
37
- def render
38
- tag.div(**options[:attributes]) do
39
- text || yield
40
- end
41
- end
42
-
43
- # The default attributes for the hint
44
-
45
- DEFAULT_ATTRIBUTES = { class: 'govuk-hint' }.freeze
46
- end
47
- end
48
- end
49
- end
@@ -1,52 +0,0 @@
1
- require_relative '../base'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- # = GOV.UK Inset Text
7
- #
8
- # This is used to generate the inset text component from the
9
- # {https://design-system.service.gov.uk/components/inset-text GDS - Components - Inset text}
10
- #
11
- # @!attribute [r] text
12
- # @return [String] Text for the inset text
13
-
14
- class InsetText < Base
15
- private
16
-
17
- attr_reader :text
18
-
19
- public
20
-
21
- # @param text [String] text to use within the inset text component.
22
- # If nil, then a block will be rendered
23
- # @param options [Hash] options that will be used in customising the HTML
24
- #
25
- # @option options [String] :classes additional CSS classes for the inset text HTML
26
- # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
27
-
28
- def initialize(text: nil, **options)
29
- super(**options)
30
-
31
- @text = text
32
- end
33
-
34
- # Generates the HTML for the GOV.UK Inset text component
35
- #
36
- # @yield HTML that will be contained within the inset text div. Ignored if inset text is given
37
- #
38
- # @return [ActiveSupport::SafeBuffer]
39
-
40
- def render
41
- tag.div(**options[:attributes]) do
42
- text || yield
43
- end
44
- end
45
-
46
- # The default attributes for the inset text
47
-
48
- DEFAULT_ATTRIBUTES = { class: 'govuk-inset-text' }.freeze
49
- end
50
- end
51
- end
52
- end
@@ -1,85 +0,0 @@
1
- require_relative '../base'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- # = GOV.UK Label
7
- #
8
- # This is used to generate the label component from the Government Design Systems
9
- #
10
- # @!attribute [r] attribute
11
- # @return [String, Symbol] Attribute of the input that requires a label
12
- # @!attribute [r] text
13
- # @return [String] Text for the label
14
- # @!attribute [r] form
15
- # @return [ActionView::Helpers::FormBuilder] Form builder used to create the label
16
-
17
- class Label < Base
18
- private
19
-
20
- attr_reader :attribute, :text, :form
21
-
22
- public
23
-
24
- # @param attribute [String, Symbol] the attribute of the input that requires a label
25
- # @param text [String] (nil) the text for the label
26
- # If nil, then a block will be rendered
27
- # @param form [ActionView::Helpers::FormBuilder] (nil) optional form builder used to create the label
28
- # @param options [Hash] options that will be used in customising the HTML
29
- #
30
- # @option options [String] :classes additional CSS classes for the label HTML
31
- # @option options [Boolean] :is_page_heading (false) if the label is also the heading it will rendered in a h1
32
- # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
33
-
34
- def initialize(attribute:, text: nil, form: nil, **options)
35
- super(**options)
36
-
37
- @attribute = attribute
38
- @text = text
39
- @form = form
40
- end
41
-
42
- # Generates the HTML for the GOV.UK label component
43
- #
44
- # @yield HTML that will be generated for the label
45
- #
46
- # @return [ActiveSupport::SafeBuffer]
47
-
48
- def render(&block)
49
- if options[:is_page_heading]
50
- tag.h1(class: 'govuk-label-wrapper') do
51
- label_html(&block)
52
- end
53
- else
54
- label_html(&block)
55
- end
56
- end
57
-
58
- # The default attributes for the label
59
-
60
- DEFAULT_ATTRIBUTES = { class: 'govuk-label' }.freeze
61
-
62
- private
63
-
64
- # Generates the HTML for the label.
65
- # If +:form+ attribute is present, it will be used to generate the label tag
66
- #
67
- # @yield HTML that will be used in the label. Ignored if text is passed.
68
- #
69
- # @return [ActiveSupport::SafeBuffer]
70
-
71
- def label_html
72
- if form
73
- form.label(attribute, **options[:attributes]) do
74
- text || yield
75
- end
76
- else
77
- label_tag(attribute, **options[:attributes]) do
78
- text || yield
79
- end
80
- end
81
- end
82
- end
83
- end
84
- end
85
- end