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/accordion'
6
4
 
7
5
  module CCS
8
6
  module FrontendHelpers
@@ -10,104 +8,19 @@ module CCS
10
8
  # = GOV.UK Accordion
11
9
  #
12
10
  # This helper is used for generating the accordion component from the
13
- # {https://design-system.service.gov.uk/accordion/back-link GDS - Components - Accordion}
11
+ # {https://design-system.service.gov.uk/components/accordion GDS - Components - Accordion}
14
12
 
15
13
  module Accordion
16
- include SharedMethods
17
- include ActionView::Context
18
- include ActionView::Helpers::TagHelper
19
- include ActionView::Helpers::TextHelper
20
-
21
- # Generates the HTML for the GOV.UK accordion component
22
- #
23
- # @param accordion_id [String] used as an id in the HTML for the accordion as a whole,
24
- # and also as a prefix for the ids of the section contents
25
- # and the buttons that open them
26
- # @param accordion_items [Array<Hash>] an array of accordion items.
27
- # See {#govuk_accordion_section} for details of the items in the array.
28
- # @param govuk_accordion_options [Hash] options that will be used in customising the HTML
29
- #
30
- # @option govuk_accordion_options [String] :classes additional CSS classes for the accordion HTML
31
- # @option govuk_accordion_options [Integer] :heading_level (2) heading level, from 1 to 6
32
- # @option govuk_accordion_options [Hash] :attributes ({ data: { module: 'govuk-accordion' } }) any additional
33
- # attributes that will added as part of the HTML
34
- #
35
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Accordion
36
- # which can then be rendered on the page
37
-
38
- def govuk_accordion(accordion_id, accordion_items, **govuk_accordion_options)
39
- initialise_attributes_and_set_classes(govuk_accordion_options, 'govuk-accordion')
40
- set_data_module(govuk_accordion_options, 'govuk-accordion')
41
-
42
- govuk_accordion_options[:attributes][:id] = accordion_id
43
- govuk_accordion_options[:heading_level] ||= 2
44
-
45
- tag.div(**govuk_accordion_options[:attributes]) do
46
- accordion_items.each.with_index(1) { |accordion_item, index| concat(govuk_accordion_section(accordion_id, accordion_item, index, govuk_accordion_options[:heading_level])) }
47
- end
48
- end
49
-
50
- private
51
-
52
- # Generates the HTML for an accordion section, used by {govuk_accordion}
53
- #
54
- # @param accordion_id [String] used as an id in the HTML for the accordion
55
- # @param index [Integer] the index of the accordion item
56
- # @param heading_level [Integer] heading level, from 1 to 6
57
- #
58
- # @option accordion_item [Boolean] :expanded sets whether the section should be expanded
59
- # when the page loads for the first time.
60
- # @option accordion_item [String] :heading_level (2) Heading level, from 1 to 6
61
- # @option accordion_item [String] :heading the heading text for the accordion
62
- # @option accordion_item [String] :summary (nil) optional summary text for the accordion header
63
- # @option accordion_item [String, ActiveSupport::SafeBuffer] the content within the accordion section
64
- #
65
- # @return [ActiveSupport::SafeBuffer] the HTML for an accordion section
66
- # which is used in {govuk_accordion}
67
-
68
- def govuk_accordion_section(accordion_id, accordion_item, index, heading_level)
69
- tag.div(class: "govuk-accordion__section #{'govuk-accordion__section--expanded' if accordion_item[:expanded]}".rstrip) do
70
- concat(govuk_accordion_section_header(accordion_id, accordion_item, index, heading_level))
71
- concat(govuk_accordion_section_content(accordion_id, accordion_item, index))
72
- end
73
- end
74
-
75
- # Generates the HTML for an accordion section heading, used by {govuk_accordion_section}
76
- #
77
- # @param (see govuk_accordion_section)
78
- #
79
- # @option (see govuk_accordion_section)
80
- #
81
- # @return [ActiveSupport::SafeBuffer] the HTML for an accordion section heading
82
- # which is used in {govuk_accordion_section}
83
-
84
- def govuk_accordion_section_header(accordion_id, accordion_item, index, heading_level)
85
- tag.div(class: 'govuk-accordion__section-header') do
86
- concat(tag.send("h#{heading_level}", class: 'govuk-accordion__section-heading') do
87
- tag.span(accordion_item[:heading], class: 'govuk-accordion__section-button', id: "#{accordion_id}-heading-#{index}")
88
- end)
89
- concat(tag.div(accordion_item[:summary], class: 'govuk-accordion__section-summary govuk-body', id: "#{accordion_id}-summary-#{index}")) if accordion_item[:summary]
90
- end
91
- end
92
-
93
- # Generates the HTML for an accordion sections content, used by {govuk_accordion_section}
14
+ # Generates the HTML for the GOV.UK Accordion component
94
15
  #
95
- # @param accordion_id [String] used as an id in the HTML for the accordion
96
- # @param index [Integer] the index of the accordion item
16
+ # @param (see CCS::Components::GovUK::Accordion#initialize)
97
17
  #
98
- # @option (see govuk_accordion_section)
18
+ # @option (see CCS::Components::GovUK::Accordion#initialize)
99
19
  #
100
- # @return [ActiveSupport::SafeBuffer] the HTML for an accordion sections content
101
- # which is used in {govuk_accordion_section}
20
+ # @return (see CCS::Components::GovUK::Accordion#render)
102
21
 
103
- def govuk_accordion_section_content(accordion_id, accordion_item, index)
104
- tag.div(class: 'govuk-accordion__section-content', id: "#{accordion_id}-content-#{index}", aria: { labelledby: "#{accordion_id}-heading-#{index}" }) do
105
- if accordion_item[:content].is_a? ActiveSupport::SafeBuffer
106
- accordion_item[:content]
107
- else
108
- tag.p(accordion_item[:content], class: 'govuk-body')
109
- end
110
- end
22
+ def govuk_accordion(accordion_id, accordion_sections, **options)
23
+ Components::GovUK::Accordion.new(context: self, accordion_id: accordion_id, accordion_sections: accordion_sections, **options).render
111
24
  end
112
25
  end
113
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/back_link'
6
4
 
7
5
  module CCS
8
6
  module FrontendHelpers
@@ -13,25 +11,16 @@ module CCS
13
11
  # {https://design-system.service.gov.uk/components/back-link GDS - Components - Back link}
14
12
 
15
13
  module BackLink
16
- include SharedMethods
17
- include ActionView::Helpers::UrlHelper
18
-
19
14
  # Generates the HTML for the GOV.UK Back link component
20
15
  #
21
- # @param text [String] the text for the back link
22
- # @param href [String] the href for the back link
23
- # @param govuk_back_link_options [Hash] options that will be used in customising the HTML
16
+ # @param (see CCS::Components::GovUK::BackLink#initialize)
24
17
  #
25
- # @option govuk_back_link_options [String] :classes additional CSS classes for the back link HTML
26
- # @option govuk_back_link_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
18
+ # @option (see CCS::Components::GovUK::BackLink#initialize)
27
19
  #
28
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Back link
29
- # which can then be rendered on the page
30
-
31
- def govuk_back_link(text, href, **govuk_back_link_options)
32
- initialise_attributes_and_set_classes(govuk_back_link_options, 'govuk-back-link')
20
+ # @return (see CCS::Components::GovUK::BackLink#render)
33
21
 
34
- link_to(text, href, **govuk_back_link_options[:attributes])
22
+ def govuk_back_link(text, href, **options)
23
+ Components::GovUK::BackLink.new(context: self, text: text, href: href, **options).render
35
24
  end
36
25
  end
37
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/breadcrumbs'
6
4
 
7
5
  module CCS
8
6
  module FrontendHelpers
@@ -13,62 +11,16 @@ module CCS
13
11
  # {https://design-system.service.gov.uk/components/breadcrumbs GDS - Components - Breadcrumbs}
14
12
 
15
13
  module Breadcrumbs
16
- include SharedMethods
17
- include ActionView::Context
18
- include ActionView::Helpers::TagHelper
19
- include ActionView::Helpers::TextHelper
20
- include ActionView::Helpers::UrlHelper
21
-
22
14
  # Generates the HTML for the GOV.UK breadcrumbs component
23
15
  #
24
- # @param govuk_breadcrumb_items [Array<Hash>] An array of links for the breadcrumbs list. See {#govuk_breadcrumb_link} for details of the items in the array.
25
- # @param govuk_breadcrumbs_options [Hash] options that will be used in customising the HTML
26
- #
27
- # @option govuk_breadcrumbs_options [String] :classes additional CSS classes for the breadcrumbs HTML
28
- # @option govuk_breadcrumbs_options [Boolean] :collapse_on_mobile indicates if it is to colapse breadcrumbs on mobile
29
- # @option govuk_breadcrumbs_options [Hash] :attributes any additional attributes that will added as part of the HTML
30
- #
31
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Breadcrumbs
32
- # which can then be rendered on the page
33
-
34
- def govuk_breadcrumbs(govuk_breadcrumb_items, **govuk_breadcrumbs_options)
35
- initialise_attributes_and_set_classes(govuk_breadcrumbs_options, 'govuk-breadcrumbs')
36
-
37
- govuk_breadcrumbs_options[:attributes][:class] << ' govuk-breadcrumbs--collapse-on-mobile' if govuk_breadcrumbs_options[:collapse_on_mobile]
38
-
39
- tag.div(**govuk_breadcrumbs_options[:attributes]) do
40
- tag.ol(class: 'govuk-breadcrumbs__list') do
41
- govuk_breadcrumb_items.each { |govuk_breadcrumb_item| concat(govuk_breadcrumb_link(govuk_breadcrumb_item)) }
42
- end
43
- end
44
- end
45
-
46
- private
47
-
48
- # Generates the HTML for each link in the breadcrumbs.
49
- # It is called by {#govuk_breadcrumbs} which will pass in the breadcrum item.
50
- #
51
- # @param govuk_breadcrumb_item [Hash] a hash containg options for the breadcrumb item
16
+ # @param (see CCS::Components::GovUK::Breadcrumbs#initialize)
52
17
  #
53
- # @option govuk_breadcrumb_item [String] :text the text for the link
54
- # @option govuk_breadcrumb_item [String] :href the URI for the link. If blank it is assumed that this item relates to current page
55
- # @option govuk_breadcrumb_item [Hash] :attributes any additional attributes that will added as part of the HTML.
56
- # If the link is blank then it defaults to +{ aria: { current: 'page' } }+
18
+ # @option (see CCS::Components::GovUK::Breadcrumbs#initialize)
57
19
  #
58
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Breadcrumb list item
59
-
60
- def govuk_breadcrumb_link(govuk_breadcrumb_item)
61
- if govuk_breadcrumb_item[:href].present?
62
- (govuk_breadcrumb_item[:attributes] ||= {})[:class] = 'govuk-breadcrumbs__link'
20
+ # @return (see CCS::Components::GovUK::Breadcrumbs#render)
63
21
 
64
- tag.li(class: 'govuk-breadcrumbs__list-item') do
65
- link_to(govuk_breadcrumb_item[:text], govuk_breadcrumb_item[:href], **govuk_breadcrumb_item[:attributes])
66
- end
67
- else
68
- tag.li(class: 'govuk-breadcrumbs__list-item', aria: { current: 'page' }) do
69
- govuk_breadcrumb_item[:text]
70
- end
71
- end
22
+ def govuk_breadcrumbs(breadcrumb_links, **options)
23
+ Components::GovUK::Breadcrumbs.new(context: self, breadcrumb_links: breadcrumb_links, **options).render
72
24
  end
73
25
  end
74
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/button'
6
4
 
7
5
  module CCS
8
6
  module FrontendHelpers
@@ -13,113 +11,16 @@ module CCS
13
11
  # {https://design-system.service.gov.uk/components/button GDS - Components - Button}
14
12
 
15
13
  module Button
16
- include SharedMethods
17
- include ActionView::Context
18
- include ActionView::Helpers::TagHelper
19
- include ActionView::Helpers::TextHelper
20
- include ActionView::Helpers::UrlHelper
21
- include ActionView::Helpers::FormTagHelper
22
-
23
14
  # Generates the HTML for the GOV.UK button component
24
15
  #
25
- # @param text [String] the text that will be shown in the button
26
- # @param govuk_button_options [Hash] options that will be used in customising the HTML
16
+ # @param (see CCS::Components::GovUK::Button#initialize)
27
17
  #
28
- # @option govuk_button_options [String] :classes additional CSS classes for the button HTML
29
- # @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
30
- # @option govuk_button_options [String] :href the URI that will be used in anchor tag
31
- # @option govuk_button_options [ActionView::Helpers::FormBuilder] :form the form builder used to create the submit button
32
- # @option govuk_button_options [Hash] :attributes ({ data: { module: 'govuk-button' } }) any additional attributes that will added as part of the HTML
33
- #
34
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button
35
- # which can then be rendered on the page
36
-
37
- def govuk_button(text, **govuk_button_options)
38
- initialise_attributes_and_set_classes(govuk_button_options, 'govuk-button')
39
- set_data_module(govuk_button_options, 'govuk-button')
40
-
41
- govuk_button_options[:attributes][:class] << ' govuk-button--disabled' if govuk_button_options[:attributes][:disabled]
42
- govuk_button_options[:attributes][:class] << ' govuk-button--start' if govuk_button_options[:is_start_button]
43
-
44
- button_method = if govuk_button_options[:href]
45
- :govuk_button_link
46
- elsif govuk_button_options[:form]
47
- :govuk_button_submit
48
- else
49
- :govuk_button_button
50
- end
51
-
52
- send(button_method, text, **govuk_button_options)
53
- end
54
-
55
- private
56
-
57
- # Generates the HTML for the GOV.UK button component as an anchor tag.
58
- # It is called by {#govuk_button} which will pass in the parameters, including any defaults.
59
- #
60
- # @param text [String] the text that will be shown in the button
61
- # @param govuk_button_options [Hash] options that will be used in customising the HTML
62
- #
63
- # @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
64
- # @option govuk_button_options [String] :href the URI that will be used in anchor tag
65
- # @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
66
- #
67
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as an anchor element
68
- # which can then be rendered on the page
69
-
70
- def govuk_button_link(text, **govuk_button_options)
71
- govuk_button_options[:attributes][:role] = :button
72
- govuk_button_options[:attributes][:draggable] = false
73
-
74
- link_to(govuk_button_options[:href], **govuk_button_options[:attributes]) do
75
- concat(text)
76
- concat(govuk_start_button_icon) if govuk_button_options[:is_start_button]
77
- end
78
- end
79
-
80
- # Generates the HTML for the GOV.UK button component as a button.
81
- # It is called by {#govuk_button} which will pass in the parameters, including any defaults.
82
- #
83
- # @param text [String] the text that will be shown in the button
84
- # @param govuk_button_options [Hash] options that will be used in customising the HTML
85
- #
86
- # @option govuk_button_options [Boolean] :is_start_button indicates if it is a start button
87
- # @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
88
- #
89
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as a button element
90
- # which can then be rendered on the page
91
-
92
- def govuk_button_button(text, **govuk_button_options)
93
- button_tag(**govuk_button_options[:attributes]) do
94
- concat(text)
95
- concat(govuk_start_button_icon) if govuk_button_options[:is_start_button]
96
- end
97
- end
98
-
99
- # Generates the HTML for the GOV.UK button component as an input.
100
- # It is called by {#govuk_button} which will pass in the parameters, including any defaults.
101
- #
102
- # @param text [String] the text that will be shown in the input
103
- # @param govuk_button_options [Hash] options that will be used in customising the HTML
104
- #
105
- # @option govuk_button_options [ActionView::Helpers::FormBuilder] :form the form builder used to create the submit button
106
- # @option govuk_button_options [Hash] :attributes any additional attributes that will added as part of the HTML
107
- #
108
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Button as an input element
109
- # which can then be rendered on the page
110
-
111
- def govuk_button_submit(text, **govuk_button_options)
112
- govuk_button_options[:form].submit(text, **govuk_button_options[:attributes])
113
- end
114
-
115
- # Generates the arrow for the start button option as part of {#govuk_button}
18
+ # @option (see CCS::Components::GovUK::Button#initialize)
116
19
  #
117
- # @return [ActiveSupport::SafeBuffer] the HTML for the arrow for the start button
20
+ # @return (see CCS::Components::GovUK::Button#render)
118
21
 
119
- def govuk_start_button_icon
120
- tag.svg(class: 'govuk-button__start-icon', xmlns: 'http://www.w3.org/2000/svg', width: 17.5, height: 19, viewBox: '0 0 33 40', aria: { hidden: true }, focusable: false) do
121
- tag.path(fill: 'currentColor', d: 'M0 0h13l20 20-20 20H0l20-20z')
122
- end
22
+ def govuk_button(text, **options)
23
+ Components::GovUK::Button.new(context: self, text: text, **options).render
123
24
  end
124
25
  end
125
26
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../components/govuk/field/input/character_count'
4
+
5
+ module CCS
6
+ module FrontendHelpers
7
+ module GovUKFrontend
8
+ # = GOV.UK Character count
9
+ #
10
+ # This helper is used for generating the character count component from the
11
+ # {https://design-system.service.gov.uk/components/character-count GDS - Components - Character count}
12
+
13
+ module CharacterCount
14
+ # Generates the HTML for the GOV.UK Character count component
15
+ #
16
+ # @param (see CCS::Components::GovUK::Input::CharacterCount#initialize)
17
+ #
18
+ # @option (see CCS::Components::GovUK::Input::CharacterCount#initialize)
19
+ #
20
+ # @return (see CCS::Components::GovUK::Input::CharacterCount#render)
21
+
22
+ def govuk_character_count(attribute, character_count_options, **options)
23
+ Components::GovUK::Field::Input::CharacterCount.new(context: self, attribute: attribute, character_count_options: character_count_options, **options).render
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../components/govuk/field/inputs/checkboxes'
4
+
5
+ module CCS
6
+ module FrontendHelpers
7
+ module GovUKFrontend
8
+ # = GOV.UK Checkboxes
9
+ #
10
+ # This helper is used for generating the checkboxes component from the
11
+ # {https://design-system.service.gov.uk/components/checkboxes GDS - Components - Checkboxes}
12
+
13
+ module Checkboxes
14
+ # Generates the HTML for the GOV.UK Checkboxes component
15
+ #
16
+ # @param (see CCS::Components::GovUK::Inputs::Checkboxes#initialize)
17
+ #
18
+ # @option (see CCS::Components::GovUK::Inputs::Checkboxes#initialize)
19
+ #
20
+ # @return (see CCS::Components::GovUK::Inputs::Checkboxes#render)
21
+
22
+ def govuk_checkboxes(attribute, checkbox_items, **options)
23
+ Components::GovUK::Field::Inputs::Checkboxes.new(context: self, attribute: attribute, checkbox_items: checkbox_items, **options).render
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'button'
3
+ require_relative '../../components/govuk/cookie_banner'
4
4
 
5
5
  module CCS
6
6
  module FrontendHelpers
@@ -11,124 +11,16 @@ module CCS
11
11
  # {https://design-system.service.gov.uk/components/cookie-banner GDS - Components - Cookie banner}
12
12
 
13
13
  module CookieBanner
14
- include ActionView::Context
15
- include ActionView::Helpers::TagHelper
16
- include ActionView::Helpers::TextHelper
17
- include Button
18
-
19
14
  # Generates the HTML for the GOV.UK Cookie banner component
20
15
  #
21
- # @param messages [Array] the different messages you can pass into the cookie banner. See {govuk_cookie_banner_message_content}
22
- # @param govuk_cookie_banner_options [Hash] options that will be used in customising the HTML
23
- #
24
- # @option govuk_cookie_banner_options [String] :classes additional CSS classes for the cookie banner HTML
25
- # @option govuk_cookie_banner_options [Hash] :attributes any additional attributes that will added as part of the HTML
26
- #
27
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Cookie banner
28
- # which can then be rendered on the page
29
-
30
- def govuk_cookie_banner(messages, **govuk_cookie_banner_options)
31
- determine_govuk_cookie_banner_attributes(govuk_cookie_banner_options)
32
-
33
- tag.div(**govuk_cookie_banner_options[:attributes]) do
34
- messages.each do |message|
35
- initialise_attributes_and_set_classes(message, 'govuk-cookie-banner__message govuk-width-container')
36
-
37
- concat(tag.div(**message[:attributes]) do
38
- concat(govuk_cookie_banner_message_content(message))
39
- concat(govuk_cookie_banner_message_actions(message[:actions])) if message[:actions]
40
- end)
41
- end
42
- end
43
- end
44
-
45
- private
46
-
47
- # Generates the HTML for a cookie banner message content used in {govuk_cookie_banner}
48
- #
49
- # @param message [Hash] the options for the cookie banner message
50
- #
51
- # @option message [String] :heading_text the heading text that displays in the message
52
- # @option message [ActiveSupport::SafeBuffer] :content HTML to use as content for the message
53
- # @option message [String] :text if +:content+ is blank then this is the text used for the message
54
- # @option message [Array] :actions the buttons and links that you want to display in the message. See {govuk_cookie_banner_message_actions}
55
- # @option message [String] :classes additional CSS classes for the cookie message HTML
56
- # @option message [Hash] :attributes any additional attributes that will added as part of the HTML
57
- #
58
- # @return [ActiveSupport::SafeBuffer] the HTML for a cookie banner message content used in {govuk_cookie_banner}
59
-
60
- def govuk_cookie_banner_message_content(message)
61
- tag.div(class: 'govuk-grid-row') do
62
- tag.div(class: 'govuk-grid-column-two-thirds') do
63
- concat(tag.h2(message[:heading_text], class: 'govuk-cookie-banner__heading govuk-heading-m')) if message[:heading_text]
64
- concat(tag.div(class: 'govuk-cookie-banner__content') do
65
- message[:content] || tag.p(message[:text], class: 'govuk-body')
66
- end)
67
- end
68
- end
69
- end
70
-
71
- # rubocop:disable Metrics/AbcSize
72
-
73
- # Generates the HTML for the cookie banner message actions used in {govuk_cookie_banner}
74
- # It defaults to creating button unless a +href+ is set which will create a link
75
- #
76
- # @param message_actions [Hash] the options for the cookie banner message actions
16
+ # @param (see CCS::Components::GovUK::CookieBanner#initialize)
77
17
  #
78
- # @option message_actions [String] :text the button or link text
79
- # @option message_actions [String] :href the href for a link
80
- # @option message_actions [String] :classes additional CSS classes for the cookie action button or link
81
- # @option message_actions [Hash] :attributes any additional attributes that will added as part of the HTML.
82
- # If the +:type+ key is present with a value of +:button+,
83
- # the action will be rendered as a button
18
+ # @option (see CCS::Components::GovUK::CookieBanner#initialize)
84
19
  #
85
- # @return [ActiveSupport::SafeBuffer] the HTML for the cookie banner message actions used in {govuk_cookie_banner}
86
-
87
- def govuk_cookie_banner_message_actions(message_actions)
88
- tag.div(class: 'govuk-button-group') do
89
- message_actions.each do |message_action|
90
- message_action[:attributes] ||= {}
91
-
92
- concat(
93
- if message_action[:href]
94
- if message_action[:attributes][:type] == :button
95
- govuk_button(
96
- message_action[:text],
97
- href: message_action[:href],
98
- classes: message_action[:classes],
99
- attributes: message_action[:attributes]
100
- )
101
- else
102
- message_action[:attributes][:class] = "govuk-link #{message_action[:classes]}".rstrip
103
-
104
- link_to(message_action[:text], message_action[:href], **message_action[:attributes])
105
- end
106
- else
107
- govuk_button(
108
- message_action[:text],
109
- classes: message_action[:classes],
110
- attributes: message_action[:attributes]
111
- )
112
- end
113
- )
114
- end
115
- end
116
- end
117
-
118
- # rubocop:enable Metrics/AbcSize
119
-
120
- # Sets the default attributes for {govuk_cookie_banner}
121
- #
122
- # @param govuk_cookie_banner_options [Hash] options that will be used in customising the HTML
123
- #
124
- # @option (see govuk_cookie_banner)
125
-
126
- def determine_govuk_cookie_banner_attributes(govuk_cookie_banner_options)
127
- initialise_attributes_and_set_classes(govuk_cookie_banner_options, 'govuk-cookie-banner')
20
+ # @return (see CCS::Components::GovUK::CookieBanner#render)
128
21
 
129
- (govuk_cookie_banner_options[:attributes][:data] ||= {})[:nosnippet] = 'true'
130
- govuk_cookie_banner_options[:attributes][:role] = 'region'
131
- (govuk_cookie_banner_options[:attributes][:aria] ||= {})[:label] ||= 'Cookie banner'
22
+ def govuk_cookie_banner(messages, **options)
23
+ Components::GovUK::CookieBanner.new(context: self, messages: messages, **options).render
132
24
  end
133
25
  end
134
26
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../components/govuk/field/inputs/date_input'
4
+
5
+ module CCS
6
+ module FrontendHelpers
7
+ module GovUKFrontend
8
+ # = GOV.UK Date Input
9
+ #
10
+ # This helper is used for generating the date input component from the
11
+ # {https://design-system.service.gov.uk/components/date-input GDS - Components - Date Input}
12
+
13
+ module DateInput
14
+ # Generates the HTML for the GOV.UK Date Input component
15
+ #
16
+ # @param (see CCS::Components::GovUK::Inputs::DateInput#initialize)
17
+ #
18
+ # @option (see CCS::Components::GovUK::Inputs::DateInput#initialize)
19
+ #
20
+ # @return (see CCS::Components::GovUK::Inputs::DateInput#render)
21
+
22
+ def govuk_date_input(attribute, **options)
23
+ Components::GovUK::Field::Inputs::DateInput.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/details'
6
4
 
7
5
  module CCS
8
6
  module FrontendHelpers
@@ -13,32 +11,18 @@ module CCS
13
11
  # {https://design-system.service.gov.uk/components/details GDS - Components - Details}
14
12
 
15
13
  module Details
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 Details component
22
15
  #
23
- # @param summary_text [String] the summary text for the details element
24
- # @param govuk_details_options [Hash] options that will be used in customising the HTML
16
+ # @param (see CCS::Components::GovUK::Details#initialize)
25
17
  #
26
- # @option govuk_details_options [String] :classes additional CSS classes for the details HTML
27
- # @option govuk_details_options [Hash] :attributes ({ data: { module: 'govuk-details' } }) any additional attributes that will added as part of the HTML
18
+ # @option (see CCS::Components::GovUK::Details#initialize)
28
19
  #
29
- # @yield HTML that will be contained within the 'govuk-details__text' div
20
+ # @yield (see CCS::Components::GovUK::Details#render)
30
21
  #
31
- # @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK Details
32
- # which can then be rendered on the page
33
-
34
- def govuk_details(summary_text, **govuk_details_options, &block)
35
- initialise_attributes_and_set_classes(govuk_details_options, 'govuk-details')
36
- set_data_module(govuk_details_options, 'govuk-details')
22
+ # @return (see CCS::Components::GovUK::Details#render)
37
23
 
38
- tag.details(**govuk_details_options[:attributes]) do
39
- concat(tag.summary(tag.span(summary_text, class: 'govuk-details__summary-text'), class: 'govuk-details__summary'))
40
- concat(tag.div(class: 'govuk-details__text', &block))
41
- end
24
+ def govuk_details(summary_text, **options, &block)
25
+ Components::GovUK::Details.new(context: self, summary_text: summary_text, **options).render(&block)
42
26
  end
43
27
  end
44
28
  end