ccs-frontend_helpers 0.1.0 → 0.1.1.rc.1

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 +11 -2
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +4 -1
  5. data/Gemfile +15 -1
  6. data/Gemfile.lock +153 -114
  7. data/ccs-frontend_helpers.gemspec +1 -11
  8. data/lib/ccs/components/base.rb +64 -0
  9. data/lib/ccs/components/ccs/dashboard_section/panel.rb +57 -0
  10. data/lib/ccs/components/ccs/dashboard_section.rb +71 -0
  11. data/lib/ccs/components/ccs/footer/link.rb +55 -0
  12. data/lib/ccs/components/ccs/footer/meta.rb +59 -0
  13. data/lib/ccs/components/ccs/footer/navigation.rb +60 -0
  14. data/lib/ccs/components/ccs/footer.rb +95 -0
  15. data/lib/ccs/components/ccs/header/link.rb +60 -0
  16. data/lib/ccs/components/ccs/header/navigation.rb +98 -0
  17. data/lib/ccs/components/ccs/header/service_authentication.rb +53 -0
  18. data/lib/ccs/components/ccs/header.rb +110 -0
  19. data/lib/ccs/{frontend_helpers/ccs_frontend → components/ccs}/logo.rb +10 -12
  20. data/lib/ccs/components/govuk/accordion/section/content.rb +53 -0
  21. data/lib/ccs/components/govuk/accordion/section/header.rb +57 -0
  22. data/lib/ccs/components/govuk/accordion/section.rb +61 -0
  23. data/lib/ccs/components/govuk/accordion.rb +58 -0
  24. data/lib/ccs/components/govuk/back_link.rb +51 -0
  25. data/lib/ccs/components/govuk/breadcrumbs/link.rb +57 -0
  26. data/lib/ccs/components/govuk/breadcrumbs.rb +55 -0
  27. data/lib/ccs/components/govuk/button.rb +107 -0
  28. data/lib/ccs/components/govuk/cookie_banner/action.rb +60 -0
  29. data/lib/ccs/components/govuk/cookie_banner/message.rb +80 -0
  30. data/lib/ccs/components/govuk/cookie_banner.rb +55 -0
  31. data/lib/ccs/components/govuk/details.rb +53 -0
  32. data/lib/ccs/components/govuk/error_message.rb +60 -0
  33. data/lib/ccs/components/govuk/error_summary/item.rb +54 -0
  34. data/lib/ccs/components/govuk/error_summary.rb +70 -0
  35. data/lib/ccs/components/govuk/field/input/character_count.rb +129 -0
  36. data/lib/ccs/components/govuk/field/input/file_upload.rb +44 -0
  37. data/lib/ccs/components/govuk/field/input/select.rb +82 -0
  38. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +55 -0
  39. data/lib/ccs/components/govuk/field/input/text_input.rb +97 -0
  40. data/lib/ccs/components/govuk/field/input/textarea.rb +59 -0
  41. data/lib/ccs/components/govuk/field/input.rb +62 -0
  42. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +69 -0
  43. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +65 -0
  44. data/lib/ccs/components/govuk/field/inputs/date_input.rb +89 -0
  45. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +47 -0
  46. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +43 -0
  47. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +50 -0
  48. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +50 -0
  49. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +44 -0
  50. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +43 -0
  51. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +50 -0
  52. data/lib/ccs/components/govuk/field/inputs/item.rb +111 -0
  53. data/lib/ccs/components/govuk/field/inputs/radios.rb +69 -0
  54. data/lib/ccs/components/govuk/field/inputs.rb +57 -0
  55. data/lib/ccs/components/govuk/field.rb +108 -0
  56. data/lib/ccs/components/govuk/fieldset/legend.rb +65 -0
  57. data/lib/ccs/components/govuk/fieldset.rb +54 -0
  58. data/lib/ccs/components/govuk/footer/link.rb +55 -0
  59. data/lib/ccs/components/govuk/footer/meta.rb +59 -0
  60. data/lib/ccs/components/govuk/footer/navigation.rb +60 -0
  61. data/lib/ccs/components/govuk/footer.rb +131 -0
  62. data/lib/ccs/components/govuk/form_group.rb +60 -0
  63. data/lib/ccs/components/govuk/header/link.rb +56 -0
  64. data/lib/ccs/components/govuk/header/navigation.rb +71 -0
  65. data/lib/ccs/components/govuk/header.rb +107 -0
  66. data/lib/ccs/components/govuk/hint.rb +49 -0
  67. data/lib/ccs/components/govuk/inset_text.rb +52 -0
  68. data/lib/ccs/components/govuk/label.rb +85 -0
  69. data/lib/ccs/components/govuk/notification_banner.rb +107 -0
  70. data/lib/ccs/components/govuk/pagination/increment/next.rb +44 -0
  71. data/lib/ccs/components/govuk/pagination/increment/previous.rb +43 -0
  72. data/lib/ccs/components/govuk/pagination/increment.rb +98 -0
  73. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +28 -0
  74. data/lib/ccs/components/govuk/pagination/item/form.rb +49 -0
  75. data/lib/ccs/components/govuk/pagination/item/tag.rb +47 -0
  76. data/lib/ccs/components/govuk/pagination/item.rb +64 -0
  77. data/lib/ccs/components/govuk/pagination.rb +96 -0
  78. data/lib/ccs/components/govuk/panel.rb +62 -0
  79. data/lib/ccs/components/govuk/phase_banner.rb +69 -0
  80. data/lib/ccs/components/govuk/skip_link.rb +51 -0
  81. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +53 -0
  82. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +50 -0
  83. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +45 -0
  84. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +63 -0
  85. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +69 -0
  86. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +56 -0
  87. data/lib/ccs/components/govuk/step_by_step_navigation.rb +59 -0
  88. data/lib/ccs/components/govuk/summary_list/action/link.rb +59 -0
  89. data/lib/ccs/components/govuk/summary_list/card/actions.rb +59 -0
  90. data/lib/ccs/components/govuk/summary_list/card/title.rb +51 -0
  91. data/lib/ccs/components/govuk/summary_list/card.rb +63 -0
  92. data/lib/ccs/components/govuk/summary_list/row/actions.rb +59 -0
  93. data/lib/ccs/components/govuk/summary_list/row/key.rb +47 -0
  94. data/lib/ccs/components/govuk/summary_list/row/value.rb +47 -0
  95. data/lib/ccs/components/govuk/summary_list/row.rb +67 -0
  96. data/lib/ccs/components/govuk/summary_list.rb +74 -0
  97. data/lib/ccs/components/govuk/table/body/data_cell.rb +53 -0
  98. data/lib/ccs/components/govuk/table/body/head_cell.rb +52 -0
  99. data/lib/ccs/components/govuk/table/header/head_cell.rb +54 -0
  100. data/lib/ccs/components/govuk/table.rb +111 -0
  101. data/lib/ccs/components/govuk/tabs/panel.rb +58 -0
  102. data/lib/ccs/components/govuk/tabs/tab.rb +56 -0
  103. data/lib/ccs/components/govuk/tabs.rb +66 -0
  104. data/lib/ccs/components/govuk/tag.rb +51 -0
  105. data/lib/ccs/components/govuk/warning_text.rb +61 -0
  106. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +27 -0
  107. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +6 -119
  108. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +6 -183
  109. data/lib/ccs/frontend_helpers/ccs_frontend.rb +2 -4
  110. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +8 -95
  111. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +6 -17
  112. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +6 -54
  113. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +6 -105
  114. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +28 -0
  115. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +28 -0
  116. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +6 -114
  117. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +28 -0
  118. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +7 -23
  119. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +11 -32
  120. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +13 -65
  121. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +7 -48
  122. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +28 -0
  123. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +6 -161
  124. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +13 -24
  125. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +6 -139
  126. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +8 -17
  127. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +28 -0
  128. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +7 -21
  129. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +7 -70
  130. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +7 -113
  131. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +6 -314
  132. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +7 -28
  133. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +8 -27
  134. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +28 -0
  135. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +28 -0
  136. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +6 -18
  137. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +7 -186
  138. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +6 -204
  139. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +11 -100
  140. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +6 -73
  141. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +7 -21
  142. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +28 -0
  143. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +7 -30
  144. data/lib/ccs/frontend_helpers/govuk_frontend.rb +17 -19
  145. data/lib/ccs/frontend_helpers/version.rb +1 -1
  146. metadata +117 -147
  147. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +0 -79
  148. data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +0 -165
  149. data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +0 -200
  150. data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +0 -153
  151. data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +0 -83
  152. data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +0 -153
  153. data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +0 -201
  154. data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +0 -124
  155. data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +0 -106
  156. data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +0 -213
  157. data/lib/ccs/frontend_helpers/shared_methods.rb +0 -27
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_view'
4
-
5
- require_relative '../shared_methods'
3
+ require_relative '../../components/govuk/header'
6
4
 
7
5
  module CCS
8
6
  module FrontendHelpers
@@ -13,147 +11,16 @@ module CCS
13
11
  # {https://design-system.service.gov.uk/components/header GDS - Components - Header}
14
12
 
15
13
  module Header
16
- include SharedMethods
17
- include ActionView::Context
18
- include ActionView::Helpers::FormTagHelper
19
- include ActionView::Helpers::TagHelper
20
- include ActionView::Helpers::TextHelper
21
- include ActionView::Helpers::UrlHelper
22
-
23
14
  # Generates the HTML for the GOV.UK Header component
24
15
  #
25
- # @param govuk_header_options [Hash] options that will be used to generate the header
26
- #
27
- # @option govuk_header_options [String] :classes additional CSS classes for the header HTML
28
- # @option govuk_header_options [Hash] :attributes additional attributes that will added as part of the header HTML
29
- # @option govuk_header_options [String] :container_classes classes for the container
30
- # @option govuk_header_options [String] :homepage_url URL of the homepage. Defaults to +/+
31
- # @option govuk_header_options [String] :product_name product name, used when the product name follows on directly from ‘GOV.UK
32
- # @option govuk_header_options [Hash] :service see {govuk_header_service_name}
33
- # @option govuk_header_options [Hash] :navigation see {govuk_header_navigation}
34
- # @option govuk_header_options [Hash] :menu_button see {govuk_header_navigation}
35
- #
36
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Header
37
- # which can then be rendered on the page
38
-
39
- def govuk_header(**govuk_header_options)
40
- determine_govuk_header_attributes(govuk_header_options)
41
-
42
- tag.header(**govuk_header_options[:attributes]) do
43
- tag.div(class: "govuk-header__container #{govuk_header_options[:container_classes] || 'govuk-width-container'}") do
44
- concat(govuk_header_logo(**govuk_header_options))
45
- if govuk_header_options[:service] || govuk_header_options[:navigation]
46
- concat(tag.div(class: 'govuk-header__content') do
47
- concat(govuk_header_service_name(govuk_header_options[:service])) if govuk_header_options[:service]
48
- concat(govuk_header_navigation(govuk_header_options[:navigation], govuk_header_options[:menu_button])) if govuk_header_options[:navigation]
49
- end)
50
- end
51
- end
52
- end
53
- end
54
-
55
- private
56
-
57
- # Generates the logo for {govuk_header}
58
- #
59
- # @param govuk_header_options [Hash] options that will be used to generate the header
16
+ # @param (see CCS::Components::GovUK::Header#initialize)
60
17
  #
61
- # @option (see govuk_header)
18
+ # @option (see CCS::Components::GovUK::Header#initialize)
62
19
  #
63
- # @return [ActiveSupport::SafeBuffer] the HTML for the logo used in {govuk_header}
64
-
65
- def govuk_header_logo(govuk_header_options)
66
- tag.div(class: 'govuk-header__logo') do
67
- link_to(govuk_header_options[:homepage_url] || '/', class: 'govuk-header__link govuk-header__link--homepage') do
68
- concat(tag.span(class: 'govuk-header__logotype') do
69
- 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
70
- 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')
71
- end)
72
- concat(tag.span('GOV.UK', class: 'govuk-header__logotype-text'))
73
- end)
74
- concat(tag.span(govuk_header_options[:product_name], class: 'govuk-header__product-name')) if govuk_header_options[:product_name]
75
- end
76
- end
77
- end
78
-
79
- # Generates the service name section for {govuk_header}
80
- #
81
- # @param service [Hash] options that will be used in the service name section
82
- #
83
- # @option service [String] :name the name of the service, included in the header
84
- # @option service [String] :href URL for the service name anchor
85
- #
86
- # @return [ActiveSupport::SafeBuffer] the HTML for the service name section which is used in {govuk_header}
87
-
88
- def govuk_header_service_name(service)
89
- if service[:href]
90
- link_to(service[:name], service[:href], class: 'govuk-header__link govuk-header__service-name')
91
- else
92
- tag.span(service[:name], class: 'govuk-header__service-name')
93
- end
94
- end
95
-
96
- # Generates the navigation section for {govuk_header}
97
- #
98
- # @param navigation [Hash] options for the navigation
99
- # @param menu_button [Hash] options for the menu button
100
- #
101
- # @option navigation [String] :classes additional CSS classes for the navigation HTML
102
- # @option navigation [String] :label text for the aria-label attribute of the navigation. Defaults to the menu button text
103
- # @option navigation [Array] :items the navigation items that will be rendered on the page (see {govuk_header_navigation_item})
104
- #
105
- # @option menu_button [String] :text text for the button that opens the mobile navigation menu.
106
- # By default, this is set to +Menu+.
107
- # @option menu_button [String] :label text for the aria-label attribute of the button that opens the mobile navigation.
108
- # Defaults to +Show or hide menu+.
109
- #
110
- # @return [ActiveSupport::SafeBuffer] the HTML for the navigation section which is used in {govuk_header}
111
-
112
- def govuk_header_navigation(navigation, menu_button)
113
- (menu_button ||= {})[:text] ||= 'Menu'
114
-
115
- tag.nav(aria: { label: navigation[:label] || menu_button[:text] }, class: "govuk-header__navigation #{navigation[:classes]}".rstrip) do
116
- concat(button_tag(menu_button[:text], type: :button, class: 'govuk-header__menu-button govuk-js-header-toggle', aria: { controls: 'navigation', label: menu_button[:label] || 'Show or hide menu' }, hidden: true))
117
- concat(tag.ul(id: 'navigation', class: 'govuk-header__navigation-list') do
118
- navigation[:items].each { |navigation_item| concat(govuk_header_navigation_item(navigation_item)) }
119
- end)
120
- end
121
- end
122
-
123
- # Generates a navigation item for {govuk_header_navigation}
124
- #
125
- # @param navigation_item [Hash] options that will be used in customising the HTML
126
- #
127
- # @option navigation_item [Boolean] :active flag to mark the navigation item as active or not
128
- # @option navigation_item [String] :text text for the navigation item
129
- # @option navigation_item [String] :href URL of the navigation item anchor
130
- # @option navigation_item [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
131
- #
132
- # @return [ActiveSupport::SafeBuffer] the HTML for a navigation item which is used in {govuk_header_navigation}
133
-
134
- def govuk_header_navigation_item(navigation_item)
135
- tag.li(class: "govuk-header__navigation-item #{'govuk-header__navigation-item--active' if navigation_item[:active]}".rstrip) do
136
- if navigation_item[:href]
137
- (navigation_item[:attributes] ||= {})[:class] = 'govuk-header__link'
138
-
139
- link_to(navigation_item[:text], navigation_item[:href], **navigation_item[:attributes])
140
- else
141
- navigation_item[:text]
142
- end
143
- end
144
- end
145
-
146
- # Sets the default attributes for {govuk_header}
147
- #
148
- # @param govuk_header_options [Hash] options that will be used in customising the HTML
149
- #
150
- # @option (see govuk_header)
151
-
152
- def determine_govuk_header_attributes(govuk_header_options)
153
- initialise_attributes_and_set_classes(govuk_header_options, 'govuk-header')
154
- set_data_module(govuk_header_options, 'govuk-header')
20
+ # @return (see CCS::Components::GovUK::Header#render)
155
21
 
156
- govuk_header_options[:attributes][:role] = 'banner'
22
+ def govuk_header(**options)
23
+ Components::GovUK::Header.new(context: self, **options).render
157
24
  end
158
25
  end
159
26
  end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_view'
4
-
5
- require_relative '../shared_methods'
3
+ require_relative '../../components/govuk/hint'
6
4
 
7
5
  module CCS
8
6
  module FrontendHelpers
@@ -12,25 +10,18 @@ module CCS
12
10
  # This helper is used for generating the hint text component from the Government Design Systems
13
11
 
14
12
  module Hint
15
- include SharedMethods
16
- include ActionView::Context
17
- include ActionView::Helpers::TagHelper
18
-
19
13
  # Generates the HTML for the GOV.UK Hint component
20
14
  #
21
- # @param hint_text [String] the hint text
22
- # @param govuk_hint_options [Hash] options that will be used in customising the HTML
15
+ # @param (see CCS::Components::GovUK::Hint#initialize)
23
16
  #
24
- # @option govuk_hint_options [String] :classes additional CSS classes for the hint HTML
25
- # @option govuk_hint_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
17
+ # @option (see CCS::Components::GovUK::Hint#initialize)
26
18
  #
27
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Hint
28
- # which can then be rendered on the page
29
-
30
- def govuk_hint(hint_text, **govuk_hint_options)
31
- initialise_attributes_and_set_classes(govuk_hint_options, 'govuk-hint')
19
+ # @yield (see CCS::Components::GovUK::Hint#render)
20
+ #
21
+ # @return (see CCS::Components::GovUK::Hint#render)
32
22
 
33
- tag.div(hint_text, **govuk_hint_options[:attributes])
23
+ def govuk_hint(text = nil, **options, &block)
24
+ Components::GovUK::Hint.new(context: self, text: text, **options).render(&block)
34
25
  end
35
26
  end
36
27
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../components/govuk/field/input/text_input'
4
+
5
+ module CCS
6
+ module FrontendHelpers
7
+ module GovUKFrontend
8
+ # = GOV.UK Input
9
+ #
10
+ # This helper is used for generating the input component from the
11
+ # {https://design-system.service.gov.uk/components/text-input GDS - Components - Text Input}
12
+
13
+ module Input
14
+ # Generates the HTML for the GOV.UK Text Input component
15
+ #
16
+ # @param (see CCS::Components::GovUK::Input::TextInput#initialize)
17
+ #
18
+ # @option (see CCS::Components::GovUK::Input::TextInput#initialize)
19
+ #
20
+ # @return (see CCS::Components::GovUK::Input::TextInput#render)
21
+
22
+ def govuk_input(attribute, **options)
23
+ Components::GovUK::Field::Input::TextInput.new(context: self, attribute: attribute, **options).render
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_view'
4
-
5
- require_relative '../shared_methods'
3
+ require_relative '../../components/govuk/inset_text'
6
4
 
7
5
  module CCS
8
6
  module FrontendHelpers
@@ -13,30 +11,18 @@ module CCS
13
11
  # {https://design-system.service.gov.uk/components/inset-text GDS - Components - Inset text}
14
12
 
15
13
  module InsetText
16
- include SharedMethods
17
- include ActionView::Context
18
- include ActionView::Helpers::TagHelper
19
- include ActionView::Helpers::TextHelper
20
-
21
14
  # Generates the HTML for the GOV.UK Inset text component
22
15
  #
23
- # @param inset_text [String] text to use within the inset text component
24
- # @param govuk_inset_text_options [Hash] options that will be used in customising the HTML
16
+ # @param (see CCS::Components::GovUK::InsetText#initialize)
25
17
  #
26
- # @option govuk_inset_text_options [String] :classes additional CSS classes for the inset text HTML
27
- # @option govuk_inset_text_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
18
+ # @option (see CCS::Components::GovUK::InsetText#initialize)
28
19
  #
29
- # @yield HTML that will be contained within the inset text div. Ignored if inset text is given
20
+ # @yield (see CCS::Components::GovUK::InsetText#render)
30
21
  #
31
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Inset text
32
- # which can then be rendered on the page
33
-
34
- def govuk_inset_text(inset_text = nil, **govuk_inset_text_options)
35
- initialise_attributes_and_set_classes(govuk_inset_text_options, 'govuk-inset-text')
22
+ # @return (see CCS::Components::GovUK::InsetText#render)
36
23
 
37
- tag.div(**govuk_inset_text_options[:attributes]) do
38
- inset_text || yield
39
- end
24
+ def govuk_inset_text(text = nil, **options, &block)
25
+ Components::GovUK::InsetText.new(context: self, text: text, **options).render(&block)
40
26
  end
41
27
  end
42
28
  end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_view'
4
-
5
- require_relative '../shared_methods'
3
+ require_relative '../../components/govuk/label'
6
4
 
7
5
  module CCS
8
6
  module FrontendHelpers
@@ -12,79 +10,18 @@ module CCS
12
10
  # This helper is used for generating the label component from the Government Design Systems
13
11
 
14
12
  module Label
15
- include SharedMethods
16
- include ActionView::Context
17
- include ActionView::Helpers::TagHelper
18
- include ActionView::Helpers::TextHelper
19
- include ActionView::Helpers::FormTagHelper
20
-
21
- # Generates the HTML for the GOV.UK label component
22
- #
23
- # @param attribute [String, Symbol] the attribute of the input that requires a label
24
- # @param label_text [String] the label text, it is ignored if a block is given
25
- # @param govuk_label_options [Hash] options that will be used in customising the HTML
26
- #
27
- # @option govuk_label_options [String] :classes additional CSS classes for the label HTML
28
- # @option govuk_label_options [Boolean] :is_page_heading (false) if the legend is also the heading it will rendered in a h1
29
- # @option govuk_label_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create the label
30
- # @option govuk_label_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
31
- #
32
- # @yield HTML that will be contained within the 'govuk-label' label. Ignored if label text is given
33
- #
34
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Label
35
- # which can then be rendered on the page
36
-
37
- def govuk_label(attribute, label_text = nil, **govuk_label_options, &block)
38
- initialise_attributes_and_set_classes(govuk_label_options, 'govuk-label')
39
-
40
- label_html = if govuk_label_options[:form]
41
- govuk_label_form(attribute, label_text, **govuk_label_options, &block)
42
- else
43
- govuk_label_tag(attribute, label_text, **govuk_label_options, &block)
44
- end
45
-
46
- if govuk_label_options[:is_page_heading]
47
- tag.h1(label_html, class: 'govuk-label-wrapper')
48
- else
49
- label_html
50
- end
51
- end
52
-
53
- private
54
-
55
- # Generates the HTML for the GOV.UK label component
56
- # using the inbuilt rails method +label+
57
- #
58
- # @param (see govuk_label)
59
- #
60
- # @option (see govuk_label)
61
- #
62
- # @yield (see govuk_label)
63
- #
64
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Label
65
- # which can then be rendered on the page
66
-
67
- def govuk_label_tag(attribute, label_text, **govuk_label_options)
68
- label_tag(attribute, **govuk_label_options[:attributes]) do
69
- label_text || yield
70
- end
71
- end
72
-
73
13
  # Generates the HTML for the GOV.UK label component
74
- # using the inbuilt rails ActionView::Helpers::FormBuilder
75
14
  #
76
- # @param (see govuk_label)
15
+ # @param (see CCS::Components::GovUK::Label#initialize)
77
16
  #
78
- # @option (see govuk_label)
17
+ # @option (see CCS::Components::GovUK::Label#initialize)
79
18
  #
80
- # @yield (see govuk_label)
19
+ # @yield (see CCS::Components::GovUK::Label#render)
81
20
  #
82
- # @return (see govuk_label_tag)
21
+ # @return (see CCS::Components::GovUK::Label#render)
83
22
 
84
- def govuk_label_form(attribute, label_text, **govuk_label_options)
85
- govuk_label_options[:form].label(attribute, **govuk_label_options[:attributes]) do
86
- label_text || yield
87
- end
23
+ def govuk_label(attribute, text = nil, **options, &block)
24
+ Components::GovUK::Label.new(context: self, attribute: attribute, text: text, **options).render(&block)
88
25
  end
89
26
  end
90
27
  end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'action_view'
4
-
5
- require_relative '../shared_methods'
3
+ require_relative '../../components/govuk/notification_banner'
6
4
 
7
5
  module CCS
8
6
  module FrontendHelpers
@@ -13,123 +11,19 @@ module CCS
13
11
  # {https://design-system.service.gov.uk/components/notification-banner GDS - Components - Notification banner}
14
12
 
15
13
  module NotificationBanner
16
- include SharedMethods
17
- include ActionView::Context
18
- include ActionView::Helpers::TagHelper
19
- include ActionView::Helpers::TextHelper
20
-
21
14
  # Generates the HTML for the GOV.UK Notification banner component
22
15
  #
23
- # @param text [String] the text that will be used for the heading in the content section of the banner.
24
- # It is ignored if a block is given
25
- # @param success_banner [Boolean] will use the success banner options if this is set to true
26
- # @param govuk_notification_banner_options [Hash] options that will be used in customising the HTML
27
- #
28
- # @option govuk_notification_banner_options [String] :classes additional CSS classes for the notification banner HTML
29
- # @option govuk_notification_banner_options [String] :title_text ('Important') the title text shown at the top of the banner
30
- # @option govuk_notification_banner_options [String] :title_id ('govuk-notification-banner-title') the ID for the title text
31
- # @option govuk_notification_banner_options [String] :role ('region') the role for the banner
32
- # @option govuk_notification_banner_options [String] :heading_level (2) the heading level for the title text
33
- # @option govuk_notification_banner_options [Hash] :attributes ({data: { module: 'govuk-notification-banner' }, aria: { labelledby: 'govuk-notification-banner-title' }})
34
- # any additional attributes that will added as part of the HTML
35
- #
36
- # @yield HTML that will be contained within the 'govuk-notification-banner__content' div
37
- #
38
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Notification banner
39
- # which can then be rendered on the page
40
-
41
- def govuk_notification_banner(text = nil, success_banner = false, **govuk_notification_banner_options)
42
- banner_options = fetch_banner_options(success_banner, govuk_notification_banner_options)
43
-
44
- set_banner_classes(banner_options, govuk_notification_banner_options)
45
- set_banner_attributes(banner_options, govuk_notification_banner_options)
46
-
47
- tag.div(**govuk_notification_banner_options[:attributes]) do
48
- concat(tag.div(class: 'govuk-notification-banner__header') do
49
- tag.send(:"h#{govuk_notification_banner_options[:heading_level] || 2}", banner_options[:title_text], class: 'govuk-notification-banner__title', id: banner_options[:title_id])
50
- end)
51
- concat(tag.div(class: 'govuk-notification-banner__content') do
52
- if block_given?
53
- yield
54
- else
55
- tag.p(text, class: 'govuk-notification-banner__heading')
56
- end
57
- end)
58
- end
59
- end
60
-
61
- private
62
-
63
- # Determines the banner options to be used for {#govuk_notification_banner}
64
- #
65
- # @param success_banner [Boolean] will use the success banner options if this is set to true
66
- # @param govuk_notification_banner_options [Hash] options that will be used in customising the HTML
67
- #
68
- # @option govuk_notification_banner_options [String] :title_text ('Important') the title text shown at the top of the banner
69
- # @option govuk_notification_banner_options [String] :title_id ('govuk-notification-banner-title') the ID for the title text
70
- # @option govuk_notification_banner_options [String] :role ('region') the role for the banner
71
- #
72
- # @return [Hash] contains the following options used in {#govuk_notification_banner}:
73
- # - +classes+
74
- # - +title_text+
75
- # - +title_id+
76
- # - +role+
77
-
78
- def fetch_banner_options(success_banner, govuk_notification_banner_options)
79
- banner_options = DEFAULT_OPTIONS.dup
80
-
81
- banner_options.merge!(SUCCESS_BANNER_OPTIONS) if success_banner
82
-
83
- govuk_notification_banner_options.each do |key, value|
84
- banner_options[key] = value if banner_options.key?(key)
85
- end
86
-
87
- banner_options
88
- end
89
-
90
- # Sets the banner classes to be used for {#govuk_notification_banner}
91
- #
92
- # @param banner_options [Hash] this is the return value from {#fetch_banner_options}
93
- # @param govuk_notification_banner_options [Hash] options that will be used in customising the HTML
16
+ # @param (see CCS::Components::GovUK::NotificationBanner#initialize)
94
17
  #
95
- # @option govuk_notification_banner_options [String] :classes additional CSS classes for the notification banner HTML
96
-
97
- def set_banner_classes(banner_options, govuk_notification_banner_options)
98
- initialise_attributes_and_set_classes(govuk_notification_banner_options, 'govuk-notification-banner')
99
-
100
- govuk_notification_banner_options[:attributes][:class] << banner_options[:classes].to_s
101
- end
102
-
103
- # Sets the HTML attributes for {#govuk_notification_banner}
18
+ # @option (see CCS::Components::GovUK::NotificationBanner#initialize)
104
19
  #
105
- # @param banner_options [Hash] this is the return value from {#fetch_banner_options}
106
- # @param govuk_notification_banner_options [Hash] options that will be used in customising the HTML
20
+ # @yield (see CCS::Components::GovUK::NotificationBanner#render)
107
21
  #
108
- # @option govuk_notification_banner_options [Hash] :attributes ({data: { module: 'govuk-notification-banner' }, aria: { labelledby: 'govuk-notification-banner-title' }})
109
- # any additional attributes that will added as part of the HTML
22
+ # @return (see CCS::Components::GovUK::NotificationBanner#render)
110
23
 
111
- def set_banner_attributes(banner_options, govuk_notification_banner_options)
112
- set_data_module(govuk_notification_banner_options, 'govuk-notification-banner')
113
-
114
- govuk_notification_banner_options[:attributes][:role] ||= banner_options[:role]
115
- (govuk_notification_banner_options[:attributes][:aria] ||= {})[:labelledby] = banner_options[:title_id]
24
+ def govuk_notification_banner(text = nil, success_banner = nil, **options, &block)
25
+ Components::GovUK::NotificationBanner.new(context: self, text: text, success_banner: success_banner, **options).render(&block)
116
26
  end
117
-
118
- # Default options used in normal versions of {#govuk_notification_banner}
119
-
120
- DEFAULT_OPTIONS = {
121
- title_text: 'Important',
122
- title_id: 'govuk-notification-banner-title',
123
- role: 'region'
124
- }.freeze
125
-
126
- # Options specific for the success version of {#govuk_notification_banner}
127
-
128
- SUCCESS_BANNER_OPTIONS = {
129
- classes: ' govuk-notification-banner--success',
130
- title_text: 'Success',
131
- role: 'alert'
132
- }.freeze
133
27
  end
134
28
  end
135
29
  end