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,47 @@
1
+ require_relative '../item'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ class Pagination < Base
6
+ class Item < Base
7
+ # = GOV.UK Pagination Item form
8
+ #
9
+ # This generates the HTML for the pagination item using a button tag
10
+ #
11
+ # @!attribute [r] form
12
+ # @return [ActionView::Helpers::FormBuilder] Form builder used to create the button
13
+
14
+ class Form < Item
15
+ private
16
+
17
+ attr_reader :form
18
+
19
+ public
20
+
21
+ # @param (see CCS::Components::GovUK::Pagination::Item)
22
+ # @param form [ActionView::Helpers::FormBuilder] form builder used to create the button
23
+ #
24
+ # @option (see CCS::Components::GovUK::Pagination::Item)
25
+
26
+ def initialize(form:, **options)
27
+ super(**options)
28
+
29
+ @options[:attributes][:class] << ' pagination-number--button_as_link'
30
+
31
+ @form = form
32
+ end
33
+
34
+ # Generates the HTML for the GOV.UK Pagination item button
35
+ #
36
+ # @return [ActiveSupport::SafeBuffer]
37
+
38
+ def render
39
+ super() do
40
+ form.button(number, **@options[:attributes])
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,45 @@
1
+ require_relative '../item'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ class Pagination < Base
6
+ class Item < Base
7
+ # = GOV.UK Pagination Item tag
8
+ #
9
+ # This generates the HTML for the pagination item using a link tag
10
+ #
11
+ # @!attribute [r] href
12
+ # @return [String] URL for the pagination item
13
+
14
+ class Tag < Item
15
+ private
16
+
17
+ attr_reader :href
18
+
19
+ public
20
+
21
+ # @param (see CCS::Components::GovUK::Pagination::Item)
22
+ # @param href [String] the URL for the pagination item
23
+ #
24
+ # @option (see CCS::Components::GovUK::Pagination::Item)
25
+
26
+ def initialize(href:, **options)
27
+ super(**options)
28
+
29
+ @href = href
30
+ end
31
+
32
+ # Generates the HTML for the GOV.UK Pagination item link
33
+ #
34
+ # @return [ActiveSupport::SafeBuffer]
35
+
36
+ def render
37
+ super() do
38
+ link_to(number, href, **@options[:attributes])
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,62 @@
1
+ require_relative '../../base'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ class Pagination < Base
6
+ # = GOV.UK Pagination Item
7
+ #
8
+ # This generates the HTML for the pagination item
9
+ #
10
+ # @!attribute [r] number
11
+ # @return [String] The number for the item
12
+ # @!attribute [r] li_classes
13
+ # @return [String] HTML classes for pagination item +li+ element
14
+
15
+ class Item < Base
16
+ private
17
+
18
+ attr_reader :number, :li_classes
19
+
20
+ public
21
+
22
+ # @param number [String] the number for the item
23
+ # @param current [Boolean] flag to indicate if this item is the current page
24
+ #
25
+ # @option options [String] :classes additional CSS classes for the item HTML
26
+ # @option options [Symbol] :type the type of item. If the value is +:ellipsis+ then an ellipsis will be rendered
27
+ # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
28
+
29
+ def initialize(number:, current: false, **options)
30
+ super(**options)
31
+
32
+ @number = number
33
+
34
+ (@options[:attributes][:aria] ||= {})[:label] ||= "Page #{@number}"
35
+
36
+ li_classes = 'govuk-pagination__item'
37
+
38
+ if current
39
+ li_classes << ' govuk-pagination__item--current'
40
+ @options[:attributes][:aria][:current] = 'page'
41
+ end
42
+
43
+ @li_classes = li_classes
44
+ end
45
+
46
+ # Generates the HTML for the GOV.UK Pagination item
47
+ #
48
+ # @yield the HTML for the pagination item link/button
49
+ #
50
+ # @return [ActiveSupport::SafeBuffer]
51
+
52
+ def render(&block)
53
+ tag.li(class: li_classes, &block)
54
+ end
55
+
56
+ # The default attributes for the pagination link
57
+
58
+ DEFAULT_ATTRIBUTES = { class: 'govuk-link govuk-pagination__link' }.freeze
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,94 @@
1
+ require_relative '../base'
2
+ require_relative 'pagination/increment/previous'
3
+ require_relative 'pagination/increment/next'
4
+ require_relative 'pagination/item/ellipsis'
5
+ require_relative 'pagination/item/tag'
6
+ require_relative 'pagination/item/form'
7
+
8
+ module CCS::Components
9
+ module GovUK
10
+ # = GOV.UK Pagination
11
+ #
12
+ # This helper is used for generating the pagination component from the
13
+ # {https://design-system.service.gov.uk/components/pagination GDS - Components - Pagination}
14
+ #
15
+ # @!attribute [r] pagination_previous
16
+ # @return [Increment::Previous] Initialised pagination previous
17
+ # @!attribute [r] pagination_items
18
+ # @return [Array<Item::Ellipsis|Item::Tag|Item::Form>] An array of the initialised pagination items
19
+ # @!attribute [r] pagination_next
20
+ # @return [Increment::Next] Initialised pagination next
21
+
22
+ class Pagination < Base
23
+ private
24
+
25
+ attr_reader :pagination_previous, :pagination_items, :pagination_next
26
+
27
+ public
28
+
29
+ # rubocop:disable Metrics/CyclomaticComplexity
30
+
31
+ # @param pagination_previous [Hash] attributes for the pagination previous, see {CCS::Components::GovUK::Pagination::Increment::Previous#initialize Previous#initialize} for more details.
32
+ # @param pagination_items [Array<Hash>] An array of options for the pagination items.
33
+ # See {CCS::Components::GovUK::Pagination::Item::Tag#initialize Item::Tag#initialize} and
34
+ # {CCS::Components::GovUK::Pagination::Item::Form#initialize Item::Form#initialize} for details of the items in the array.
35
+ # @param pagination_next [Hash] attributes for the pagination next, see {CCS::Components::GovUK::Pagination::Increment::Next#initialize Next#initialize} for more details.
36
+ # @param options [Hash] options that will be used in customising the HTML
37
+ #
38
+ # @option options [String] :classes additional CSS classes for the pagination HTML
39
+ # @option options [ActionView::Helpers::FormBuilder] :form form builder used to create pagination buttons
40
+ # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
41
+
42
+ def initialize(pagination_previous: nil, pagination_items: nil, pagination_next: nil, **options)
43
+ super(**options)
44
+
45
+ block_is_level = pagination_items.blank? && (pagination_previous.present? || pagination_next.present?)
46
+
47
+ @options[:attributes][:class] << ' govuk-pagination--block' if block_is_level
48
+ @options[:attributes][:role] = 'navigation'
49
+ (@options[:attributes][:aria] ||= {})[:label] ||= 'results'
50
+
51
+ @pagination_previous = Increment::Previous.new(block_is_level: block_is_level, form: @options[:form], context: @context, **pagination_previous) if pagination_previous
52
+ @pagination_next = Increment::Next.new(block_is_level: block_is_level, form: @options[:form], context: @context, **pagination_next) if pagination_next
53
+ initialize_pagination_items(pagination_items, @options[:form])
54
+ end
55
+
56
+ # rubocop:enable Metrics/CyclomaticComplexity
57
+
58
+ # Generates the HTML for the GOV.UK pagination component
59
+ #
60
+ # @return [ActiveSupport::SafeBuffer]
61
+
62
+ def render
63
+ tag.nav(**options[:attributes]) do
64
+ concat(pagination_previous.render) if pagination_previous
65
+ if pagination_items
66
+ concat(tag.ul(class: 'govuk-pagination__list') do
67
+ pagination_items.each { |pagination_item| concat(pagination_item.render) }
68
+ end)
69
+ end
70
+ concat(pagination_next.render) if pagination_next
71
+ end
72
+ end
73
+
74
+ # The default attributes for the pagination
75
+
76
+ DEFAULT_ATTRIBUTES = { class: 'govuk-pagination' }.freeze
77
+
78
+ private
79
+
80
+ # Initialises the pagination items
81
+ #
82
+ # @param pagination_items [Array<Hash>] An array of options for the pagination items
83
+ # @param form [ActionView::Helpers::FormBuilder] form builder used to create pagination buttons
84
+
85
+ def initialize_pagination_items(pagination_items, form)
86
+ return unless pagination_items
87
+
88
+ pagination_item_class = form ? Item::Form : Item::Tag
89
+
90
+ @pagination_items = pagination_items.map { |pagination_item| pagination_item[:type] == :ellipsis ? Item::Ellipsis : pagination_item_class.new(form: form, context: context, **pagination_item) }
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,60 @@
1
+ require_relative '../base'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ # = GOV.UK Panel
6
+ #
7
+ # This is used to generate the panel component from the
8
+ # {https://design-system.service.gov.uk/components/panel GDS - Components - Panel}
9
+ #
10
+ # @!attribute [r] title_text
11
+ # @return [String] Text for the panel title
12
+ # @!attribute [r] panel_text
13
+ # @return [String] Text that will be used for the panel content
14
+
15
+ class Panel < Base
16
+ private
17
+
18
+ attr_reader :title_text, :panel_text
19
+
20
+ public
21
+
22
+ # @param title_text [String] title text for the panel which will be contained in haeding tags
23
+ # @param panel_text [String] text to use within the panel component.
24
+ # If nil, then a block will be rendered
25
+ # @param options [Hash] options that will be used in customising the HTML
26
+ #
27
+ # @option options [String] :classes additional CSS classes for the panel HTML
28
+ # @option options [Integer,String] :heading_level (default: 1) heading level for the panel title text
29
+ # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
30
+
31
+ def initialize(title_text:, panel_text: nil, **options)
32
+ super(**options)
33
+
34
+ @title_text = title_text
35
+ @panel_text = panel_text
36
+ end
37
+
38
+ # Generates the HTML for the GOV.UK Panel component
39
+ #
40
+ # @yield HTML that will be contained within the panel body. Ignored if panel text is given
41
+ #
42
+ # @return [ActiveSupport::SafeBuffer]
43
+
44
+ def render
45
+ tag.div(**options[:attributes]) do
46
+ concat(tag.send(:"h#{options[:heading_level] || 1}", title_text, class: 'govuk-panel__title'))
47
+ if panel_text || block_given?
48
+ concat(tag.div(class: 'govuk-panel__body') do
49
+ panel_text || yield
50
+ end)
51
+ end
52
+ end
53
+ end
54
+
55
+ # The default attributes for the panel
56
+
57
+ DEFAULT_ATTRIBUTES = { class: 'govuk-panel govuk-panel--confirmation' }.freeze
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,67 @@
1
+ require_relative '../base'
2
+ require_relative 'tag'
3
+
4
+ module CCS::Components
5
+ module GovUK
6
+ # = GOV.UK Phase banner
7
+ #
8
+ # This is used to generate the phase banner component from the
9
+ # {https://design-system.service.gov.uk/components/phase-banner GDS - Components - Phase banner}
10
+ #
11
+ # @!attribute [r] text
12
+ # @return [String] Text for the phase banner
13
+ # @!attribute [r] tag_options
14
+ # @return [Hash] Options for the phase banner tag
15
+
16
+ class PhaseBanner < Base
17
+ private
18
+
19
+ attr_reader :text, :tag_options
20
+
21
+ public
22
+
23
+ # @param tag_options [Hash] paramters for the govuk tag (see {Components::GovUK::Tag Tag}).
24
+ # options are:
25
+ # - +text+
26
+ # - +colour+
27
+ # - +options+
28
+ # @param text [String] the text for the phase banner.
29
+ # If nil, then a block will be rendered
30
+ # @param options [Hash] options that will be used in customising the HTML
31
+ #
32
+ # @option options [String] :classes additional CSS classes for the phase banner HTML
33
+ # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
34
+
35
+ def initialize(tag_options:, text: nil, **options)
36
+ super(**options)
37
+
38
+ tag_options[:classes] = "govuk-phase-banner__content__tag #{tag_options[:classes]}".rstrip
39
+ tag_options[:context] = @context
40
+
41
+ @text = text
42
+ @tag_options = tag_options
43
+ end
44
+
45
+ # Generates the HTML for the GOV.UK Phase banner component
46
+ #
47
+ # @yield HTML that will be used in the phase banner. Ignored if text is passed.
48
+ #
49
+ # @return [ActiveSupport::SafeBuffer]
50
+
51
+ def render
52
+ tag.div(**options[:attributes]) do
53
+ tag.p(class: 'govuk-phase-banner__content') do
54
+ concat(Tag.new(**tag_options).render)
55
+ concat(tag.span(class: 'govuk-phase-banner__text') do
56
+ text || yield
57
+ end)
58
+ end
59
+ end
60
+ end
61
+
62
+ # The default attributes for the phase banner
63
+
64
+ DEFAULT_ATTRIBUTES = { class: 'govuk-phase-banner' }.freeze
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,49 @@
1
+ require_relative '../base'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ # = GOV.UK Skip Link
6
+ #
7
+ # This is used to generate the skip link component from the
8
+ # {https://design-system.service.gov.uk/components/skip-link GDS - Components - Skip link}
9
+ #
10
+ # @!attribute [r] text
11
+ # @return [String] Text for the skip link
12
+ # @!attribute [r] href
13
+ # @return [String] The href for the skip link
14
+
15
+ class SkipLink < Base
16
+ private
17
+
18
+ attr_reader :text, :href
19
+
20
+ public
21
+
22
+ # @param text [String] the text for the skip link
23
+ # @param href [String] the href for the skip link
24
+ # @param options [Hash] options that will be used in customising the HTML
25
+ #
26
+ # @option options [String] :classes additional CSS classes for the skip link HTML
27
+ # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
28
+
29
+ def initialize(text:, href: nil, **options)
30
+ super(**options)
31
+
32
+ @text = text
33
+ @href = href || '#content'
34
+ end
35
+
36
+ # Generates the HTML for the GOV.UK Skip link component
37
+ #
38
+ # @return [ActiveSupport::SafeBuffer]
39
+
40
+ def render
41
+ link_to(text, href, **options[:attributes])
42
+ end
43
+
44
+ # The default attributes for the skip link
45
+
46
+ DEFAULT_ATTRIBUTES = { class: 'govuk-skip-link', data: { module: 'govuk-skip-link' } }.freeze
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,51 @@
1
+ require 'action_view'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ class StepByStepNavigation < Base
6
+ class Section < Base
7
+ class Content
8
+ class List
9
+ # = GOV.UK Step by step navigation section content list item
10
+ #
11
+ # Generates the list item HTML for the step by step navigation section content
12
+ #
13
+ # @!attribute [r] text
14
+ # @return [String] Text for the list item
15
+ # @!attribute [r] classes
16
+ # @return [String] HTML classes for the list item
17
+
18
+ class Item
19
+ include ActionView::Context
20
+ include ActionView::Helpers
21
+
22
+ private
23
+
24
+ attr_reader :text, :classes
25
+
26
+ public
27
+
28
+ # @param text [String] the text for the list item
29
+ # @param no_marker [Boolean] flag to hide the bullet marker
30
+
31
+ def initialize(text:, no_marker: nil)
32
+ @text = text
33
+ @classes = "gem-c-step-nav__list-item js-list-item #{'gem-c-step-nav__list--no-marker' if no_marker}".rstrip
34
+ end
35
+
36
+ # Generates the HTML for an individual the GOV.UK Step by step navigation list item
37
+ #
38
+ # @return [ActiveSupport::SafeBuffer]
39
+
40
+ def render
41
+ tag.li(class: classes) do
42
+ tag.span(text)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,48 @@
1
+ require 'action_view'
2
+
3
+ require_relative 'list/item'
4
+
5
+ module CCS::Components
6
+ module GovUK
7
+ class StepByStepNavigation < Base
8
+ class Section < Base
9
+ class Content
10
+ # = GOV.UK Step by step navigation section content list
11
+ #
12
+ # Generates the list HTML for the step by step navigation section content
13
+ #
14
+ # @!attribute [r] items
15
+ # @return [Item] Array of initialised list items
16
+
17
+ class List
18
+ include ActionView::Context
19
+ include ActionView::Helpers
20
+
21
+ private
22
+
23
+ attr_reader :items
24
+
25
+ public
26
+
27
+ # @param items [Array<Hash>] An array of options for the list items
28
+ # See {Components::GovUK::StepByStepNavigation::Section::Content::List::Item#initialize Item#initialize} for details of the items in the array.
29
+
30
+ def initialize(items:)
31
+ @items = items.map { |item| Item.new(**item) }
32
+ end
33
+
34
+ # Generates the HTML for the GOV.UK Step by step navigation section content list
35
+ #
36
+ # @return [ActiveSupport::SafeBuffer]
37
+
38
+ def render
39
+ tag.ul(class: 'gem-c-step-nav__list gem-c-step-nav__list--choice', data: { length: items.length.to_s }) do
40
+ items.each { |item| concat(item.render) }
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,43 @@
1
+ require 'action_view'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ class StepByStepNavigation < Base
6
+ class Section < Base
7
+ class Content
8
+ # = GOV.UK Step by step navigation section content paragraph
9
+ #
10
+ # Generates the paragraph HTML for the step by step navigation section content
11
+ #
12
+ # @!attribute [r] text
13
+ # @return [String] Text for the paragraph
14
+
15
+ class Paragraph
16
+ include ActionView::Context
17
+ include ActionView::Helpers
18
+
19
+ private
20
+
21
+ attr_reader :text
22
+
23
+ public
24
+
25
+ # @param text [String] the text for the paragraph
26
+
27
+ def initialize(text:)
28
+ @text = text
29
+ end
30
+
31
+ # Generates the HTML for the GOV.UK Step by step navigation section content paragraph
32
+ #
33
+ # @return [ActiveSupport::SafeBuffer]
34
+
35
+ def render
36
+ tag.p(text, class: 'gem-c-step-nav__paragraph')
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,61 @@
1
+ require 'action_view'
2
+
3
+ require_relative 'content/list'
4
+ require_relative 'content/paragraph'
5
+
6
+ module CCS::Components
7
+ module GovUK
8
+ class StepByStepNavigation < Base
9
+ class Section < Base
10
+ # = GOV.UK Step by step navigation section content
11
+ #
12
+ # The content for a navigation section
13
+ #
14
+ # @!attribute [r] section_id
15
+ # @return [String] ID for the section content
16
+ # @!attribute [r] content_items
17
+ # @return [Array<Paragraph|List>] An array of the initialised content items
18
+
19
+ class Content
20
+ include ActionView::Context
21
+ include ActionView::Helpers
22
+
23
+ private
24
+
25
+ attr_reader :section_id, :content_items
26
+
27
+ public
28
+
29
+ # @param content_items [Array<Hash>] array of content items.
30
+ # If the type is +:paragraph+, see {Components::GovUK::StepByStepNavigation::Section::Content::Paragraph#initialize Paragraph#initialize}.
31
+ # If the type is +:list+, see {Components::GovUK::StepByStepNavigation::Section::Content::List#initialize List#initialize}.
32
+ # @param index [String] the index of the section
33
+ # @param id [String] the id of the section
34
+
35
+ def initialize(content_items:, index:, id:)
36
+ @section_id = "step-panel-#{id}-#{index}"
37
+
38
+ @content_items = content_items.map do |content_item|
39
+ case content_item[:type]
40
+ when :paragraph
41
+ Paragraph.new(text: content_item[:text])
42
+ when :list
43
+ List.new(items: content_item[:items])
44
+ end
45
+ end
46
+ end
47
+
48
+ # Generates the HTML for the GOV.UK Step by step navigation section content
49
+ #
50
+ # @return [ActiveSupport::SafeBuffer]
51
+
52
+ def render
53
+ tag.div(class: 'gem-c-step-nav__panel js-panel', id: section_id) do
54
+ content_items.each { |content_item| concat(content_item.render) }
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end