ccs-frontend_helpers 0.1.0.rc.1 → 0.1.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -1
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +4 -1
  5. data/Gemfile.lock +71 -71
  6. data/lib/ccs/components/base.rb +64 -0
  7. data/lib/ccs/components/ccs/dashboard_section/panel.rb +55 -0
  8. data/lib/ccs/components/ccs/dashboard_section.rb +71 -0
  9. data/lib/ccs/components/ccs/footer/link.rb +53 -0
  10. data/lib/ccs/components/ccs/footer/meta.rb +58 -0
  11. data/lib/ccs/components/ccs/footer/navigation.rb +59 -0
  12. data/lib/ccs/components/ccs/footer.rb +93 -0
  13. data/lib/ccs/components/ccs/header/link.rb +58 -0
  14. data/lib/ccs/components/ccs/header/navigation.rb +97 -0
  15. data/lib/ccs/components/ccs/header/service_authentication.rb +52 -0
  16. data/lib/ccs/components/ccs/header.rb +108 -0
  17. data/lib/ccs/components/ccs/logo.rb +45 -0
  18. data/lib/ccs/components/govuk/accordion/section/content.rb +53 -0
  19. data/lib/ccs/components/govuk/accordion/section/header.rb +57 -0
  20. data/lib/ccs/components/govuk/accordion/section.rb +60 -0
  21. data/lib/ccs/components/govuk/accordion.rb +56 -0
  22. data/lib/ccs/components/govuk/back_link.rb +49 -0
  23. data/lib/ccs/components/govuk/breadcrumbs/link.rb +55 -0
  24. data/lib/ccs/components/govuk/breadcrumbs.rb +53 -0
  25. data/lib/ccs/components/govuk/button.rb +105 -0
  26. data/lib/ccs/components/govuk/cookie_banner/action.rb +58 -0
  27. data/lib/ccs/components/govuk/cookie_banner/message.rb +78 -0
  28. data/lib/ccs/components/govuk/cookie_banner.rb +53 -0
  29. data/lib/ccs/components/govuk/details.rb +51 -0
  30. data/lib/ccs/components/govuk/error_message.rb +58 -0
  31. data/lib/ccs/components/govuk/error_summary/item.rb +52 -0
  32. data/lib/ccs/components/govuk/error_summary.rb +68 -0
  33. data/lib/ccs/components/govuk/field/input/character_count.rb +127 -0
  34. data/lib/ccs/components/govuk/field/input/file_upload.rb +42 -0
  35. data/lib/ccs/components/govuk/field/input/select.rb +80 -0
  36. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +53 -0
  37. data/lib/ccs/components/govuk/field/input/text_input.rb +95 -0
  38. data/lib/ccs/components/govuk/field/input/textarea.rb +57 -0
  39. data/lib/ccs/components/govuk/field/input.rb +60 -0
  40. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +67 -0
  41. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +63 -0
  42. data/lib/ccs/components/govuk/field/inputs/date_input.rb +87 -0
  43. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +45 -0
  44. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +41 -0
  45. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +48 -0
  46. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +48 -0
  47. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +42 -0
  48. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +41 -0
  49. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +48 -0
  50. data/lib/ccs/components/govuk/field/inputs/item.rb +109 -0
  51. data/lib/ccs/components/govuk/field/inputs/radios.rb +67 -0
  52. data/lib/ccs/components/govuk/field/inputs.rb +55 -0
  53. data/lib/ccs/components/govuk/field.rb +106 -0
  54. data/lib/ccs/components/govuk/fieldset/legend.rb +63 -0
  55. data/lib/ccs/components/govuk/fieldset.rb +52 -0
  56. data/lib/ccs/components/govuk/footer/link.rb +53 -0
  57. data/lib/ccs/components/govuk/footer/meta.rb +58 -0
  58. data/lib/ccs/components/govuk/footer/navigation.rb +59 -0
  59. data/lib/ccs/components/govuk/footer.rb +129 -0
  60. data/lib/ccs/components/govuk/form_group.rb +58 -0
  61. data/lib/ccs/components/govuk/header/link.rb +54 -0
  62. data/lib/ccs/components/govuk/header/navigation.rb +70 -0
  63. data/lib/ccs/components/govuk/header.rb +105 -0
  64. data/lib/ccs/components/govuk/hint.rb +47 -0
  65. data/lib/ccs/components/govuk/inset_text.rb +50 -0
  66. data/lib/ccs/components/govuk/label.rb +83 -0
  67. data/lib/ccs/components/govuk/notification_banner.rb +105 -0
  68. data/lib/ccs/components/govuk/pagination/increment/next.rb +42 -0
  69. data/lib/ccs/components/govuk/pagination/increment/previous.rb +41 -0
  70. data/lib/ccs/components/govuk/pagination/increment.rb +96 -0
  71. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +26 -0
  72. data/lib/ccs/components/govuk/pagination/item/form.rb +47 -0
  73. data/lib/ccs/components/govuk/pagination/item/tag.rb +45 -0
  74. data/lib/ccs/components/govuk/pagination/item.rb +62 -0
  75. data/lib/ccs/components/govuk/pagination.rb +94 -0
  76. data/lib/ccs/components/govuk/panel.rb +60 -0
  77. data/lib/ccs/components/govuk/phase_banner.rb +67 -0
  78. data/lib/ccs/components/govuk/skip_link.rb +49 -0
  79. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +51 -0
  80. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +48 -0
  81. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +43 -0
  82. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +61 -0
  83. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +67 -0
  84. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +54 -0
  85. data/lib/ccs/components/govuk/step_by_step_navigation.rb +57 -0
  86. data/lib/ccs/components/govuk/summary_list/action/link.rb +57 -0
  87. data/lib/ccs/components/govuk/summary_list/card/actions.rb +57 -0
  88. data/lib/ccs/components/govuk/summary_list/card/title.rb +49 -0
  89. data/lib/ccs/components/govuk/summary_list/card.rb +61 -0
  90. data/lib/ccs/components/govuk/summary_list/row/actions.rb +57 -0
  91. data/lib/ccs/components/govuk/summary_list/row/key.rb +45 -0
  92. data/lib/ccs/components/govuk/summary_list/row/value.rb +45 -0
  93. data/lib/ccs/components/govuk/summary_list/row.rb +63 -0
  94. data/lib/ccs/components/govuk/summary_list.rb +72 -0
  95. data/lib/ccs/components/govuk/table/body/data_cell.rb +51 -0
  96. data/lib/ccs/components/govuk/table/body/head_cell.rb +50 -0
  97. data/lib/ccs/components/govuk/table/header/head_cell.rb +52 -0
  98. data/lib/ccs/components/govuk/table.rb +109 -0
  99. data/lib/ccs/components/govuk/tabs/panel.rb +56 -0
  100. data/lib/ccs/components/govuk/tabs/tab.rb +54 -0
  101. data/lib/ccs/components/govuk/tabs.rb +64 -0
  102. data/lib/ccs/components/govuk/tag.rb +49 -0
  103. data/lib/ccs/components/govuk/warning_text.rb +59 -0
  104. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +25 -0
  105. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +16 -131
  106. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +16 -195
  107. data/lib/ccs/frontend_helpers/ccs_frontend.rb +2 -4
  108. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +16 -105
  109. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +16 -29
  110. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +16 -66
  111. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +16 -117
  112. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +26 -0
  113. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +26 -0
  114. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +16 -126
  115. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +26 -0
  116. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +18 -36
  117. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +31 -54
  118. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +32 -86
  119. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +18 -61
  120. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +26 -0
  121. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +16 -173
  122. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +26 -39
  123. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +16 -151
  124. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +17 -28
  125. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +26 -0
  126. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +18 -34
  127. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +17 -82
  128. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +18 -126
  129. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +16 -326
  130. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +18 -41
  131. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +18 -39
  132. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +26 -0
  133. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +26 -0
  134. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +16 -30
  135. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +23 -204
  136. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +16 -216
  137. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +16 -114
  138. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +16 -85
  139. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +16 -32
  140. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +26 -0
  141. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +18 -43
  142. data/lib/ccs/frontend_helpers/govuk_frontend.rb +17 -19
  143. data/lib/ccs/frontend_helpers/version.rb +1 -1
  144. metadata +110 -14
  145. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +0 -79
  146. data/lib/ccs/frontend_helpers/ccs_frontend/logo.rb +0 -49
  147. data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +0 -165
  148. data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +0 -200
  149. data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +0 -153
  150. data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +0 -83
  151. data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +0 -153
  152. data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +0 -201
  153. data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +0 -124
  154. data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +0 -106
  155. data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +0 -213
  156. data/lib/ccs/frontend_helpers/shared_methods.rb +0 -27
@@ -0,0 +1,70 @@
1
+ require_relative '../../base'
2
+ require_relative 'link'
3
+
4
+ module CCS::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
@@ -0,0 +1,105 @@
1
+ require_relative '../base'
2
+ require_relative 'header/navigation'
3
+
4
+ module CCS::Components
5
+ module GovUK
6
+ # = GOV.UK Header
7
+ #
8
+ # This is used to generate the header component from the
9
+ # {https://design-system.service.gov.uk/components/header GDS - Components - Header}
10
+ #
11
+ # @!attribute [r] navigation
12
+ # @return [Navigation] The initialised navigation section
13
+ # @!attribute [r] service
14
+ # @return [Hash] The options for the service section
15
+
16
+ class Header < Base
17
+ private
18
+
19
+ attr_reader :navigation, :service
20
+
21
+ public
22
+
23
+ # @param navigation [Hash] options for the navigation section of the header.
24
+ # See {Components::GovUK::Header::Navigation#initialize Navigation#initialize} for details of the options.
25
+ # @param menu_button [Hash] options for the menu button in the header.
26
+ # See {Components::GovUK::Header::Navigation#initialize Navigation#initialize} for details of the options.
27
+ # @param service [Hash] options for the service name
28
+ # @param options [Hash] options that will be used in customising the HTML
29
+ #
30
+ # @option service [String] :name the name of the service, included in the header
31
+ # @option service [String] :href URL for the service name anchor
32
+ #
33
+ # @option options [String] :classes additional CSS classes for the header HTML
34
+ # @option options [String] :container_classes classes for the container
35
+ # @option options [String] :homepage_url URL of the homepage. Defaults to +/+
36
+ # @option options [String] :product_name product name, used when the product name follows on directly from ‘GOV.UK
37
+ # @option options [Hash] :attributes additional attributes that will added as part of the header HTML
38
+
39
+ def initialize(navigation: nil, menu_button: nil, service: nil, **options)
40
+ super(**options)
41
+
42
+ @options[:attributes][:role] = 'banner'
43
+ @options[:container_classes] ||= 'govuk-width-container'
44
+ @options[:homepage_url] ||= '/'
45
+
46
+ @navigation = Navigation.new(navigation: navigation, menu_button: menu_button, context: @context) if navigation
47
+ @service = service
48
+ end
49
+
50
+ # Generates the HTML for the GOV.UK Header component
51
+ #
52
+ # @return [ActiveSupport::SafeBuffer]
53
+
54
+ def render
55
+ tag.header(**options[:attributes]) do
56
+ tag.div(class: "govuk-header__container #{options[:container_classes]}") do
57
+ concat(header_logo)
58
+ if service || navigation
59
+ concat(tag.div(class: 'govuk-header__content') do
60
+ concat(header_service_name) if service
61
+ concat(navigation.render) if navigation
62
+ end)
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ # The default attributes for the breadcrumbs
69
+
70
+ DEFAULT_ATTRIBUTES = { class: 'govuk-header', data: { module: 'govuk-header' } }.freeze
71
+
72
+ private
73
+
74
+ # Generates the logo for header
75
+ #
76
+ # @return [ActiveSupport::SafeBuffer]
77
+
78
+ def header_logo
79
+ tag.div(class: 'govuk-header__logo') do
80
+ link_to(options[:homepage_url], class: 'govuk-header__link govuk-header__link--homepage') do
81
+ concat(tag.span(class: 'govuk-header__logotype') do
82
+ 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
83
+ 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')
84
+ end)
85
+ concat(tag.span('GOV.UK', class: 'govuk-header__logotype-text'))
86
+ end)
87
+ concat(tag.span(options[:product_name], class: 'govuk-header__product-name')) if options[:product_name]
88
+ end
89
+ end
90
+ end
91
+
92
+ # Generates the service name section
93
+ #
94
+ # @return [ActiveSupport::SafeBuffer]
95
+
96
+ def header_service_name
97
+ if service[:href]
98
+ link_to(service[:name], service[:href], class: 'govuk-header__link govuk-header__service-name')
99
+ else
100
+ tag.span(service[:name], class: 'govuk-header__service-name')
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,47 @@
1
+ require_relative '../base'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ # = GOV.UK Hint
6
+ #
7
+ # This is used to generate the hint text component from the Government Design Systems
8
+ #
9
+ # @!attribute [r] text
10
+ # @return [String] Text for the hint
11
+
12
+ class Hint < Base
13
+ private
14
+
15
+ attr_reader :text
16
+
17
+ public
18
+
19
+ # @param text [String] the hint text.
20
+ # If nil, then a block will be rendered
21
+ # @param options [Hash] options that will be used in customising the HTML
22
+ #
23
+ # @option options [String] :classes additional CSS classes for the hint HTML
24
+ # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
25
+
26
+ def initialize(text: nil, **options)
27
+ super(**options)
28
+
29
+ @text = text
30
+ end
31
+
32
+ # Generates the HTML for the GOV.UK Hint component
33
+ #
34
+ # @return [ActiveSupport::SafeBuffer]
35
+
36
+ def render
37
+ tag.div(**options[:attributes]) do
38
+ text || yield
39
+ end
40
+ end
41
+
42
+ # The default attributes for the hint
43
+
44
+ DEFAULT_ATTRIBUTES = { class: 'govuk-hint' }.freeze
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,50 @@
1
+ require_relative '../base'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ # = GOV.UK Inset Text
6
+ #
7
+ # This is used to generate the inset text component from the
8
+ # {https://design-system.service.gov.uk/components/inset-text GDS - Components - Inset text}
9
+ #
10
+ # @!attribute [r] text
11
+ # @return [String] Text for the inset text
12
+
13
+ class InsetText < Base
14
+ private
15
+
16
+ attr_reader :text
17
+
18
+ public
19
+
20
+ # @param text [String] text to use within the inset text component.
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 inset text 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 Inset text component
34
+ #
35
+ # @yield HTML that will be contained within the inset text div. Ignored if inset text is given
36
+ #
37
+ # @return [ActiveSupport::SafeBuffer]
38
+
39
+ def render
40
+ tag.div(**options[:attributes]) do
41
+ text || yield
42
+ end
43
+ end
44
+
45
+ # The default attributes for the inset text
46
+
47
+ DEFAULT_ATTRIBUTES = { class: 'govuk-inset-text' }.freeze
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,83 @@
1
+ require_relative '../base'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ # = GOV.UK Label
6
+ #
7
+ # This is used to generate the label component from the Government Design Systems
8
+ #
9
+ # @!attribute [r] attribute
10
+ # @return [String, Symbol] Attribute of the input that requires a label
11
+ # @!attribute [r] text
12
+ # @return [String] Text for the label
13
+ # @!attribute [r] form
14
+ # @return [ActionView::Helpers::FormBuilder] Form builder used to create the label
15
+
16
+ class Label < Base
17
+ private
18
+
19
+ attr_reader :attribute, :text, :form
20
+
21
+ public
22
+
23
+ # @param attribute [String, Symbol] the attribute of the input that requires a label
24
+ # @param text [String] (nil) the text for the label
25
+ # If nil, then a block will be rendered
26
+ # @param form [ActionView::Helpers::FormBuilder] (nil) optional form builder used to create the label
27
+ # @param options [Hash] options that will be used in customising the HTML
28
+ #
29
+ # @option options [String] :classes additional CSS classes for the label HTML
30
+ # @option options [Boolean] :is_page_heading (false) if the label is also the heading it will rendered in a h1
31
+ # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
32
+
33
+ def initialize(attribute:, text: nil, form: nil, **options)
34
+ super(**options)
35
+
36
+ @attribute = attribute
37
+ @text = text
38
+ @form = form
39
+ end
40
+
41
+ # Generates the HTML for the GOV.UK label component
42
+ #
43
+ # @yield HTML that will be generated for the label
44
+ #
45
+ # @return [ActiveSupport::SafeBuffer]
46
+
47
+ def render(&block)
48
+ if options[:is_page_heading]
49
+ tag.h1(class: 'govuk-label-wrapper') do
50
+ label_html(&block)
51
+ end
52
+ else
53
+ label_html(&block)
54
+ end
55
+ end
56
+
57
+ # The default attributes for the label
58
+
59
+ DEFAULT_ATTRIBUTES = { class: 'govuk-label' }.freeze
60
+
61
+ private
62
+
63
+ # Generates the HTML for the label.
64
+ # If +:form+ attribute is present, it will be used to generate the label tag
65
+ #
66
+ # @yield HTML that will be used in the label. Ignored if text is passed.
67
+ #
68
+ # @return [ActiveSupport::SafeBuffer]
69
+
70
+ def label_html
71
+ if form
72
+ form.label(attribute, **options[:attributes]) do
73
+ text || yield
74
+ end
75
+ else
76
+ label_tag(attribute, **options[:attributes]) do
77
+ text || yield
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,105 @@
1
+ require_relative '../base'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ # = GOV.UK Notification Banner
6
+ #
7
+ # This helper is used for generating the notification banner component from the
8
+ # {https://design-system.service.gov.uk/components/notification-banner GDS - Components - Notification banner}
9
+ #
10
+ # @!attribute [r] text
11
+ # @return [String] Text for the notification banner
12
+ # @!attribute [r] success_banner
13
+ # @return [Boolean] Indicates if this is a success banner
14
+
15
+ class NotificationBanner < Base
16
+ private
17
+
18
+ attr_reader :text, :success_banner
19
+
20
+ public
21
+
22
+ # @param text [String] the text that will be used for the heading in the content section of the banner.
23
+ # It is ignored if a block is given
24
+ # @param success_banner [Boolean] will use the success banner options if this is set to true
25
+ # @param options [Hash] options that will be used in customising the HTML
26
+ #
27
+ # @option options [String] :classes additional CSS classes for the notification banner HTML
28
+ # @option options [String] :title_text ('Important') the title text shown at the top of the banner
29
+ # @option options [String] :title_id ('govuk-notification-banner-title') the ID for the title text
30
+ # @option options [String] :role ('region') the role for the banner
31
+ # @option options [String] :heading_level (2) the heading level for the title text
32
+ # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
33
+
34
+ def initialize(text: nil, success_banner: nil, **options)
35
+ super(**options)
36
+
37
+ @text = text
38
+ @success_banner = success_banner || false
39
+
40
+ set_additional_options_for_banner
41
+ end
42
+
43
+ # Generates the HTML for the GOV.UK Notification banner component
44
+ #
45
+ # @yield HTML that will be contained within the 'govuk-notification-banner__content' div
46
+ #
47
+ # @return [ActiveSupport::SafeBuffer]
48
+
49
+ def render
50
+ tag.div(**options[:attributes]) do
51
+ concat(tag.div(class: 'govuk-notification-banner__header') do
52
+ tag.send(:"h#{options[:heading_level] || 2}", options[:title_text], class: 'govuk-notification-banner__title', id: options[:title_id])
53
+ end)
54
+ concat(tag.div(class: 'govuk-notification-banner__content') do
55
+ if block_given?
56
+ yield
57
+ else
58
+ tag.p(text, class: 'govuk-notification-banner__heading')
59
+ end
60
+ end)
61
+ end
62
+ end
63
+
64
+ # The default attributes for the notifaction banner
65
+
66
+ DEFAULT_ATTRIBUTES = { class: 'govuk-notification-banner', data: { module: 'govuk-notification-banner' } }.freeze
67
+
68
+ # Default options used in normal versions of the notification banner
69
+
70
+ DEFAULT_OPTIONS = {
71
+ title_text: 'Important',
72
+ title_id: 'govuk-notification-banner-title',
73
+ role: 'region'
74
+ }.freeze
75
+
76
+ # Specific options for the success version of the notification banner
77
+
78
+ SUCCESS_BANNER_OPTIONS = {
79
+ classes: ' govuk-notification-banner--success',
80
+ title_text: 'Success',
81
+ role: 'alert'
82
+ }.freeze
83
+
84
+ private
85
+
86
+ # rubocop:disable Metrics/AbcSize
87
+
88
+ # Determines the banner options to be used for the notification banner
89
+
90
+ def set_additional_options_for_banner
91
+ banner_options = DEFAULT_OPTIONS.dup
92
+
93
+ banner_options.merge!(SUCCESS_BANNER_OPTIONS) if success_banner
94
+
95
+ options[:title_text] ||= banner_options[:title_text]
96
+ options[:title_id] ||= banner_options[:title_id]
97
+ options[:attributes][:role] ||= banner_options[:role]
98
+ options[:attributes][:class] << banner_options[:classes].to_s
99
+ (options[:attributes][:aria] ||= {})[:labelledby] = options[:title_id]
100
+ end
101
+
102
+ # rubocop:enable Metrics/AbcSize
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,42 @@
1
+ require_relative '../increment'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ class Pagination < Base
6
+ class Increment < Base
7
+ # = GOV.UK Pagination Next
8
+ #
9
+ # This generates the HTML for the pagination next link
10
+
11
+ class Next < Increment
12
+ # @param (see Increment#initialize)
13
+ #
14
+ # @option (see Increment#initialize)
15
+
16
+ def initialize(text: 'Next', **options)
17
+ super(type: :next, text: text, **options)
18
+ end
19
+
20
+ # Generates the HTML for the next link in the pagination
21
+ #
22
+ # @return [ActiveSupport::SafeBuffer]
23
+
24
+ def render
25
+ tag.div(class: 'govuk-pagination__next') do
26
+ super() do
27
+ concat(pagination_icon) if block_is_level
28
+ concat(tag.span(text, class: pagination_text_classes))
29
+ pagination_icon_label_text
30
+ concat(pagination_icon) unless block_is_level
31
+ end
32
+ end
33
+ end
34
+
35
+ # The path for the pagination next icon
36
+
37
+ PAGINATION_ICON_PATH = 'm8.107-0.0078125-1.4136 1.414 4.2926 4.293h-12.986v2h12.896l-4.1855 3.9766 1.377 1.4492 6.7441-6.4062-6.7246-6.7266z'.freeze
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,41 @@
1
+ require_relative '../increment'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ class Pagination < Base
6
+ class Increment < Base
7
+ # = GOV.UK Pagination Previous
8
+ #
9
+ # This generates the HTML for the pagination previous link
10
+
11
+ class Previous < Increment
12
+ # @param (see Increment#initialize)
13
+ #
14
+ # @option (see Increment#initialize)
15
+
16
+ def initialize(text: 'Previous', **options)
17
+ super(type: :prev, text: text, **options)
18
+ end
19
+
20
+ # Generates the HTML for the previous link in the pagination
21
+ #
22
+ # @return [ActiveSupport::SafeBuffer]
23
+
24
+ def render
25
+ tag.div(class: 'govuk-pagination__prev') do
26
+ super() do
27
+ concat(pagination_icon)
28
+ concat(tag.span(text, class: pagination_text_classes))
29
+ pagination_icon_label_text
30
+ end
31
+ end
32
+ end
33
+
34
+ # The path for the pagination previous icon
35
+
36
+ PAGINATION_ICON_PATH = 'm6.5938-0.0078125-6.7266 6.7266 6.7441 6.4062 1.377-1.449-4.1856-3.9768h12.896v-2h-12.984l4.2931-4.293-1.414-1.414z'.freeze
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,96 @@
1
+ require_relative '../../base'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ class Pagination < Base
6
+ # = GOV.UK Pagination Increment
7
+ #
8
+ # This generates the HTML for a pagination increment, that is {Previous} and {Next}
9
+ #
10
+ # @!attribute [r] type
11
+ # @return [Symbol] The type of pagination increment
12
+ # @!attribute [r] text
13
+ # @return [String] Text for the pagination increment
14
+ # @!attribute [r] block_is_level
15
+ # @return [Boolean] Flag to indicate if previous and next blocks are level
16
+ # @!attribute [r] label_text
17
+ # @return [Boolean] Additional label text for when +block_is_level == true+
18
+
19
+ class Increment < Base
20
+ private
21
+
22
+ attr_reader :type, :text, :block_is_level, :label_text
23
+
24
+ public
25
+
26
+ # @param type [Symbol] the type of increment, either +:prev+ or +:next+
27
+ # @param text [String] the text for the pagination increment
28
+ # @param block_is_level [Boolean] when there are no items, this will be true and will add extra classes
29
+ # to the link to make the next and previous pagination links level
30
+ # @param label_text [String] additional text for the link when the pagination block is level
31
+ # @param options [Hash] options that will be used in customising the HTML
32
+ #
33
+ # @option options [String] :href the URL for the link
34
+ # @option options [ActionView::Helpers::FormBuilder] :form optional form builder used to create the button
35
+ # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
36
+
37
+ def initialize(type:, text:, block_is_level:, label_text: nil, **options)
38
+ super(**options)
39
+
40
+ @options[:attributes][:class] = "govuk-link govuk-pagination__link #{'pagination--button_as_link' if @options[:form]}".rstrip
41
+ @options[:attributes][:rel] = type.to_s
42
+
43
+ @type = type
44
+ @text = text
45
+ @block_is_level = block_is_level
46
+ @label_text = label_text
47
+ end
48
+
49
+ # Generates the HTML for the pagination increment link/button
50
+ #
51
+ # @yield the HTML for the increment button/link
52
+ #
53
+ # @return [ActiveSupport::SafeBuffer]
54
+
55
+ def render(&block)
56
+ if options[:form]
57
+ options[:form].button(**options[:attributes], &block)
58
+ else
59
+ link_to(options[:href], **options[:attributes], &block)
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ # Returns the classes for the link/button label
66
+ #
67
+ # @return [String]
68
+
69
+ def pagination_text_classes
70
+ "govuk-pagination__link-title #{'govuk-pagination__link-title--decorated' if block_is_level && !label_text}".rstrip
71
+ end
72
+
73
+ # Generates the icon for the pagination increment
74
+ #
75
+ # @return [ActiveSupport::SafeBuffer]
76
+
77
+ def pagination_icon
78
+ tag.svg(class: "govuk-pagination__icon govuk-pagination__icon--#{type}", xmlns: 'http://www.w3.org/2000/svg', height: '13', width: '15', aria: { hidden: 'true' }, focusable: 'false', viewBox: '0 0 15 13') do
79
+ tag.path(d: self.class::PAGINATION_ICON_PATH)
80
+ end
81
+ end
82
+
83
+ # Generates the label text for when the block is level
84
+ #
85
+ # @return [ActiveSupport::SafeBuffer]
86
+
87
+ def pagination_icon_label_text
88
+ return unless block_is_level && label_text
89
+
90
+ concat(tag.span(':', class: 'govuk-visually-hidden'))
91
+ concat(tag.span(label_text, class: 'govuk-pagination__link-label'))
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,26 @@
1
+ require 'action_view'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ class Pagination < Base
6
+ class Item < Base
7
+ # = GOV.UK Pagination Item ellipsis
8
+ #
9
+ # This generates the HTML for a pagination ellipsis
10
+
11
+ class Ellipsis
12
+ extend ActionView::Context
13
+ extend ActionView::Helpers
14
+
15
+ # Generates the HTML for the GOV.UK Pagination Item ellipsis
16
+ #
17
+ # @return [ActiveSupport::SafeBuffer]
18
+
19
+ def self.render
20
+ tag.li('⋯', class: 'govuk-pagination__item govuk-pagination__item--ellipses')
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end