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,67 @@
1
+ require 'action_view'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ class StepByStepNavigation < Base
6
+ class Section < Base
7
+ # = GOV.UK Step by step navigation section heading
8
+ #
9
+ # The heading for a navigation section
10
+ #
11
+ # @!attribute [r] text
12
+ # @return [String] Text for the section heading
13
+ # @!attribute [r] index
14
+ # @return [String] Index of the section
15
+ # @!attribute [r] logic
16
+ # @return [String] Optional text to show in the sidebar
17
+
18
+ class Heading
19
+ include ActionView::Context
20
+ include ActionView::Helpers
21
+
22
+ private
23
+
24
+ attr_reader :text, :index, :logic
25
+
26
+ public
27
+
28
+ # @param text [String] text for the section heading
29
+ # @param index [String] the index of the section
30
+ # @param logic [String] text to show instead of a number in the sidebar
31
+
32
+ def initialize(text:, index:, logic: nil)
33
+ @text = text
34
+ @index = index
35
+ @logic = logic
36
+ end
37
+
38
+ # rubocop:disable Metrics/AbcSize
39
+
40
+ # Generates the HTML for the GOV.UK Step by step navigation section heading
41
+ #
42
+ # @return [ActiveSupport::SafeBuffer]
43
+
44
+ def render
45
+ tag.div(class: 'gem-c-step-nav__header js-toggle-panel', data: { position: index }) do
46
+ tag.h2(class: 'gem-c-step-nav__title') do
47
+ concat(tag.span(class: "gem-c-step-nav__circle gem-c-step-nav__circle--#{logic ? 'logic' : 'number'}") do
48
+ tag.span(class: 'gem-c-step-nav__circle-inner') do
49
+ tag.span(class: 'gem-c-step-nav__circle-background') do
50
+ concat(tag.span('Step', class: 'govuk-visually-hidden'))
51
+ concat(logic || index)
52
+ end
53
+ end
54
+ end)
55
+ concat(tag.span(class: 'js-step-title') do
56
+ tag.span(text, class: 'js-step-title-text')
57
+ end)
58
+ end
59
+ end
60
+ end
61
+
62
+ # rubocop:enable Metrics/AbcSize
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,54 @@
1
+ require_relative '../../base'
2
+ require_relative 'section/heading'
3
+ require_relative 'section/content'
4
+
5
+ module CCS::Components
6
+ module GovUK
7
+ class StepByStepNavigation < Base
8
+ # = GOV.UK Step by step navigation section
9
+ #
10
+ # The individual section for the step by step navigation
11
+ #
12
+ # @!attribute [r] heading
13
+ # @return [Heading] Initialised heading for the section
14
+ # @!attribute [r] content
15
+ # @return [Content] Initialised content for the section
16
+
17
+ class Section < Base
18
+ private
19
+
20
+ attr_reader :heading, :content
21
+
22
+ public
23
+
24
+ # @param heading [Hash] options for the section heading.
25
+ # See {Components::GovUK::StepByStepNavigation::Section::Heading#initialize Heading#initialize} for details of the options.
26
+ # @param content [Hash] options for the section content.
27
+ # See {Components::GovUK::StepByStepNavigation::Section::Content#initialize Content#initialize} for details of the options.
28
+ # @param index [String] the index of the section
29
+ # @param context [ActionView::Base] the view context
30
+
31
+ def initialize(heading:, content:, index:, context:)
32
+ super(context: context)
33
+
34
+ @options[:attributes][:class] = 'gem-c-step-nav__step js-step'
35
+ @options[:attributes][:id] = heading[:text].downcase.gsub(' ', '-').gsub('(', '').gsub(')', '')
36
+
37
+ @heading = Heading.new(index: index, **heading)
38
+ @content = Content.new(content_items: content, index: index, id: @options[:attributes][:id])
39
+ end
40
+
41
+ # Generates the HTML for the GOV.UK Step by step navigation section
42
+ #
43
+ # @return [ActiveSupport::SafeBuffer]
44
+
45
+ def render
46
+ tag.li(class: @options[:attributes][:class], id: @options[:attributes][:id]) do
47
+ concat(heading.render)
48
+ concat(content.render)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,57 @@
1
+ require_relative '../base'
2
+ require_relative 'step_by_step_navigation/section'
3
+
4
+ module CCS::Components
5
+ module GovUK
6
+ # = GOV.UK Step by step navigation
7
+ #
8
+ # This is used for generating the Step by step navigation component from the
9
+ # {https://design-system.service.gov.uk/patterns/step-by-step-navigation/ GDS - Pages - Step by step navigation}
10
+ #
11
+ # @!attribute [r] step_by_step_navigation_sections
12
+ # @return [Array<Section>] An array of the initialised step by step navigation sections
13
+
14
+ class StepByStepNavigation < Base
15
+ private
16
+
17
+ attr_reader :step_by_step_navigation_sections
18
+
19
+ public
20
+
21
+ # @param step_by_step_navigation_sections [Array<Hash>] An array of options for the step by step navigation section.
22
+ # See {Components::GovUK::StepByStepNavigation::Section#initialize Section#initialize} for details of the items in the array.
23
+ # @param options [Hash] options that will be used in customising the HTML
24
+ #
25
+ # @option options [String] :classes additional CSS classes for the step by step navigation HTML
26
+ # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
27
+
28
+ def initialize(step_by_step_navigation_sections:, **options)
29
+ super(**options)
30
+
31
+ DEFAULT_SHOW_HIDE_TEXT.each { |key, value| @options[:attributes][:data][key] ||= value }
32
+
33
+ @step_by_step_navigation_sections = step_by_step_navigation_sections.map.with_index(1) { |step_by_step_section, index| Section.new(index: index.to_s, context: @context, **step_by_step_section) }
34
+ end
35
+
36
+ # Generates the HTML for the GOV.UK Step by step navigation component (experimental)
37
+ #
38
+ # @return [ActiveSupport::SafeBuffer]
39
+
40
+ def render
41
+ tag.div(**options[:attributes]) do
42
+ tag.ol(class: 'gem-c-step-nav__steps') do
43
+ step_by_step_navigation_sections.each { |step_by_step_navigation_section| concat(step_by_step_navigation_section.render) }
44
+ end
45
+ end
46
+ end
47
+
48
+ # The default attributes for the step byt step navigation
49
+
50
+ DEFAULT_ATTRIBUTES = { class: 'gem-c-step-nav gem-c-step-nav--large gem-c-step-nav--active', data: { module: 'govuk-step-by-step-navigation' } }.freeze
51
+
52
+ # Default text for the show and hide buttons which are part of each section
53
+
54
+ DEFAULT_SHOW_HIDE_TEXT = { 'show-text': 'Show', 'hide-text': 'Hide', 'show-all-text': 'Show all', 'hide-all-text': 'Hide all' }.freeze
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,57 @@
1
+ require_relative '../../../base'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ class SummaryList < Base
6
+ class Action
7
+ # = GOV.UK Summary list action link
8
+ #
9
+ # @!attribute [r] text
10
+ # @return [String] Text for the action link
11
+ # @!attribute [r] href
12
+ # @return [String] The href for the action link
13
+ # @!attribute [r] visually_hidden_text
14
+ # @return [String] Visually hidden text for the action link
15
+
16
+ class Link < Base
17
+ private
18
+
19
+ attr_reader :text, :href, :visually_hidden_text
20
+
21
+ public
22
+
23
+ # @param text [String] the text for the action link
24
+ # @param href [String] the href for the action link
25
+ # @param visually_hidden_text [String] optional visually hidden text for the action link
26
+ # @param options [Hash] options that will be used in customising the HTML
27
+ #
28
+ # @option options [String] :classes additional CSS classes for the summary list action link HTML
29
+ # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
30
+
31
+ def initialize(text:, href:, visually_hidden_text: nil, **options)
32
+ super(**options)
33
+
34
+ @text = text
35
+ @href = href
36
+ @visually_hidden_text = visually_hidden_text
37
+ end
38
+
39
+ # Generates the HTML for the GOV.UK Summary list action link
40
+ #
41
+ # @return [ActiveSupport::SafeBuffer]
42
+
43
+ def render
44
+ link_to(href, **@options[:attributes]) do
45
+ concat(text)
46
+ concat(tag.span(visually_hidden_text, class: 'govuk-visually-hidden')) if visually_hidden_text
47
+ end
48
+ end
49
+
50
+ # The default attributes for the summary list action link
51
+
52
+ DEFAULT_ATTRIBUTES = { class: 'govuk-link' }.freeze
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,57 @@
1
+ require_relative '../../../base'
2
+ require_relative '../action/link'
3
+
4
+ module CCS::Components
5
+ module GovUK
6
+ class SummaryList < Base
7
+ class Card < Base
8
+ # = GOV.UK Summary list card actions
9
+ #
10
+ # @!attribute [r] action_links
11
+ # @return [Array<Action::Link>] An array of the initialised aummary list card action links
12
+
13
+ class Actions < Base
14
+ private
15
+
16
+ attr_reader :action_links
17
+
18
+ public
19
+
20
+ # @param items [Array<Hash>] An array of attributes for the action links.
21
+ # See {Components::GovUK::SummaryList::Action::Link#initialize Action::Link#initialize} for details of the items in the array.
22
+ # @param options [Hash] options that will be used in customising the HTML
23
+ #
24
+ # @option options [String] :classes additional CSS classes for the summary list card actions HTML
25
+
26
+ def initialize(items:, **options)
27
+ super(**options)
28
+
29
+ @action_links = items.map { |item| Action::Link.new(context: @context, **item) }
30
+ end
31
+
32
+ # Generates the HTML for the GOV.UK Summary list card actions
33
+ #
34
+ # @return [ActiveSupport::SafeBuffer]
35
+
36
+ def render
37
+ if action_links.length == 1
38
+ tag.div(class: @options[:attributes][:class]) do
39
+ action_links.first.render
40
+ end
41
+ else
42
+ tag.ul(class: @options[:attributes][:class]) do
43
+ action_links.each do |action_link|
44
+ concat(tag.li(action_link.render, class: 'govuk-summary-card__action'))
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ # The default attributes for the summary list card actions
51
+
52
+ DEFAULT_ATTRIBUTES = { class: 'govuk-summary-card__actions' }.freeze
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,49 @@
1
+ require_relative '../../../base'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ class SummaryList < Base
6
+ class Card < Base
7
+ # = GOV.UK Summary list card title
8
+ #
9
+ # @!attribute [r] text
10
+ # @return [String] Text for the title
11
+ # @!attribute [r] heading_level
12
+ # @return [String] Heading level for the title
13
+
14
+ class Title < Base
15
+ private
16
+
17
+ attr_reader :text, :heading_level
18
+
19
+ public
20
+
21
+ # @param text [String] the text for the title
22
+ # @param heading_level [String] heading level, from 1 to 6
23
+ # @param options [Hash] options that will be used in customising the HTML
24
+ #
25
+ # @option options [String] :classes additional CSS classes for the summary list card title HTML
26
+
27
+ def initialize(text:, heading_level: '2', **options)
28
+ super(**options)
29
+
30
+ @text = text
31
+ @heading_level = heading_level
32
+ end
33
+
34
+ # Generates the HTML for the GOV.UK Summary list card title
35
+ #
36
+ # @return [ActiveSupport::SafeBuffer]
37
+
38
+ def render
39
+ tag.send("h#{heading_level}", text, class: @options[:attributes][:class])
40
+ end
41
+
42
+ # The default attributes for the summary list card title
43
+
44
+ DEFAULT_ATTRIBUTES = { class: 'govuk-summary-card__title' }.freeze
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,61 @@
1
+ require_relative '../../base'
2
+ require_relative 'card/title'
3
+ require_relative 'card/actions'
4
+
5
+ module CCS::Components
6
+ module GovUK
7
+ class SummaryList < Base
8
+ # = GOV.UK Summary card
9
+ #
10
+ # This is used for generating the summary cards component from the
11
+ # {https://design-system.service.gov.uk/components/summary-list/#summary-cards GDS - Components - Summary cards}
12
+ #
13
+ # @!attribute [r] title
14
+ # @return [Title] Initialised summary card title
15
+ # @!attribute [r] actions
16
+ # @return [Actions] Initialised summary card actions
17
+
18
+ class Card < Base
19
+ private
20
+
21
+ attr_reader :title, :actions
22
+
23
+ public
24
+
25
+ # @param title [Hash] attributes for the title, see {CCS::Components::GovUK::SummaryList::Card::Title#initialize Title#initialize} for more details.
26
+ # @param actions [Hash] attributes for the actions, see {CCS::Components::GovUK::SummaryList::Card::Actions#initialize Actions#initialize} for more details.
27
+ # @param options [Hash] options that will be used in customising the HTML
28
+ #
29
+ # @option options [String] :classes additional CSS classes for the summary card HTML
30
+ # @option options [Hash] :attributes any additional attributes that will be added as part of the HTML
31
+
32
+ def initialize(title: nil, actions: nil, **options)
33
+ super(**options)
34
+
35
+ @title = Title.new(context: @context, **title) if title
36
+ @actions = Actions.new(context: @context, **actions) if actions
37
+ end
38
+
39
+ # Generates the HTML for the GOV.UK Summary card
40
+ #
41
+ # @yield the HTML for the summary list
42
+ #
43
+ # @return [ActiveSupport::SafeBuffer]
44
+
45
+ def render(&block)
46
+ tag.div(**@options[:attributes]) do
47
+ concat(tag.div(class: 'govuk-summary-card__title-wrapper') do
48
+ concat(title.render) if title
49
+ concat(actions.render) if actions
50
+ end)
51
+ concat(tag.div(class: 'govuk-summary-card__content', &block))
52
+ end
53
+ end
54
+
55
+ # The default attributes for the summary card
56
+
57
+ DEFAULT_ATTRIBUTES = { class: 'govuk-summary-card' }.freeze
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,57 @@
1
+ require_relative '../../../base'
2
+ require_relative '../action/link'
3
+
4
+ module CCS::Components
5
+ module GovUK
6
+ class SummaryList < Base
7
+ class Row < Base
8
+ # = GOV.UK Summary list row actions
9
+ #
10
+ # @!attribute [r] action_links
11
+ # @return [Array<Action::Link>] An array of the initialised aummary list row action links
12
+
13
+ class Actions < Base
14
+ private
15
+
16
+ attr_reader :action_links
17
+
18
+ public
19
+
20
+ # @param items [Array<Hash>] An array of attributes for the action links.
21
+ # See {Components::GovUK::SummaryList::Action::Link#initialize Action::Link#initialize} for details of the items in the array.
22
+ # @param options [Hash] options that will be used in customising the HTML
23
+ #
24
+ # @option options [String] :classes additional CSS classes for the summary list row actions HTML
25
+
26
+ def initialize(items:, **options)
27
+ super(**options)
28
+
29
+ @action_links = items.map { |item| Action::Link.new(context: @context, **item) }
30
+ end
31
+
32
+ # Generates the HTML for the GOV.UK Summary list row actions
33
+ #
34
+ # @return [ActiveSupport::SafeBuffer]
35
+
36
+ def render
37
+ tag.dd(class: @options[:attributes][:class]) do
38
+ if action_links.length == 1
39
+ action_links.first.render
40
+ else
41
+ tag.ul(class: 'govuk-summary-list__actions-list') do
42
+ action_links.each do |action_link|
43
+ concat(tag.li(action_link.render, class: 'govuk-summary-list__actions-list-item'))
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ # The default attributes for the summary list row actions
51
+
52
+ DEFAULT_ATTRIBUTES = { class: 'govuk-summary-list__actions' }.freeze
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,45 @@
1
+ require_relative '../../../base'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ class SummaryList < Base
6
+ class Row < Base
7
+ # = GOV.UK Summary list row key
8
+ #
9
+ # @!attribute [r] text
10
+ # @return [String] Text for the summary list row key
11
+
12
+ class Key < Base
13
+ private
14
+
15
+ attr_reader :text
16
+
17
+ public
18
+
19
+ # @param text [String] Text for the summary list row key
20
+ # @param options [Hash] options that will be used in customising the HTML
21
+ #
22
+ # @option options [String] :classes additional CSS classes for the summary list row key HTML
23
+
24
+ def initialize(text:, **options)
25
+ super(**options)
26
+
27
+ @text = text
28
+ end
29
+
30
+ # Generates the HTML for the GOV.UK Summary list row key
31
+ #
32
+ # @return [ActiveSupport::SafeBuffer]
33
+
34
+ def render
35
+ tag.dt(text, class: @options[:attributes][:class])
36
+ end
37
+
38
+ # The default attributes for the summary list row key
39
+
40
+ DEFAULT_ATTRIBUTES = { class: 'govuk-summary-list__key' }.freeze
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ require_relative '../../../base'
2
+
3
+ module CCS::Components
4
+ module GovUK
5
+ class SummaryList < Base
6
+ class Row < Base
7
+ # = GOV.UK Summary list row value
8
+ #
9
+ # @!attribute [r] text
10
+ # @return [String] Text for the summary list row value
11
+
12
+ class Value < Base
13
+ private
14
+
15
+ attr_reader :text
16
+
17
+ public
18
+
19
+ # @param text [String] Text for the summary list row value
20
+ # @param options [Hash] options that will be used in customising the HTML
21
+ #
22
+ # @option options [String] :classes additional CSS classes for the summary list row value HTML
23
+
24
+ def initialize(text:, **options)
25
+ super(**options)
26
+
27
+ @text = text
28
+ end
29
+
30
+ # Generates the HTML for the GOV.UK Summary list row value
31
+ #
32
+ # @return [ActiveSupport::SafeBuffer]
33
+
34
+ def render
35
+ tag.dd(text, class: @options[:attributes][:class])
36
+ end
37
+
38
+ # The default attributes for the summary list row value
39
+
40
+ DEFAULT_ATTRIBUTES = { class: 'govuk-summary-list__value' }.freeze
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,63 @@
1
+ require_relative '../../base'
2
+ require_relative 'row/key'
3
+ require_relative 'row/value'
4
+ require_relative 'row/actions'
5
+
6
+ module CCS::Components
7
+ module GovUK
8
+ class SummaryList < Base
9
+ # = GOV.UK Summary list row
10
+ #
11
+ # Generates the HTML for a summary list row
12
+ #
13
+ # @!attribute [r] key
14
+ # @return [Key] Initialised summary list cell for the key
15
+ # @!attribute [r] value
16
+ # @return [Value] Initialised summary list cell for the value
17
+ # @!attribute [r] actions
18
+ # @return [Actions] Initialised summary list cell for the actions
19
+
20
+ class Row < Base
21
+ private
22
+
23
+ attr_reader :key, :value, :actions
24
+
25
+ public
26
+
27
+ # @param any_row_has_actions [Boolean] flag to indicate if any rows have actions
28
+ # @param key [Hash] attributes for the key, see {CCS::Components::GovUK::SummaryList::Row::Key#initialize Key#initialize} for more details.
29
+ # @param value [Hash] attributes for the value, see {CCS::Components::GovUK::SummaryList::Row::Value#initialize Value#initialize} for more details.
30
+ # @param actions [Hash] attributes for the actions, see {CCS::Components::GovUK::SummaryList::Row::Actions#initialize Actions#initialize} for more details.
31
+ # @param options [Hash] options that will be used in customising the HTML
32
+ #
33
+ # @option options [String] :classes additional CSS classes for the summary list row HTML
34
+
35
+ def initialize(any_row_has_actions:, key:, value:, actions: nil, **options)
36
+ super(**options)
37
+
38
+ @options[:attributes][:class] << ' govuk-summary-list__row--no-actions' if any_row_has_actions && !actions
39
+
40
+ @key = Key.new(context: @context, **key)
41
+ @value = Value.new(context: @context, **value)
42
+ @actions = Actions.new(context: @context, **actions) if actions
43
+ end
44
+
45
+ # Generates the HTML for the GOV.UK Summary list row
46
+ #
47
+ # @return [ActiveSupport::SafeBuffer]
48
+
49
+ def render
50
+ tag.div(class: options[:attributes][:class]) do
51
+ concat(key.render)
52
+ concat(value.render)
53
+ concat(actions.render) if actions
54
+ end
55
+ end
56
+
57
+ # The default attributes for the summary list row
58
+
59
+ DEFAULT_ATTRIBUTES = { class: 'govuk-summary-list__row' }.freeze
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,72 @@
1
+ require_relative '../base'
2
+ require_relative 'summary_list/row'
3
+ require_relative 'summary_list/card'
4
+
5
+ module CCS::Components
6
+ module GovUK
7
+ # = GOV.UK Summary list
8
+ #
9
+ # This is used for generating the summary list component from the
10
+ # {https://design-system.service.gov.uk/components/summary-list GDS - Components - Summary list}
11
+ #
12
+ # @!attribute [r] summary_list_rows
13
+ # @return [Array<Row>] An array of the initialised summary list rows
14
+ # @!attribute [r] card
15
+ # @return [Card] Initialised summary list card
16
+
17
+ class SummaryList < Base
18
+ private
19
+
20
+ attr_reader :summary_list_rows, :card
21
+
22
+ public
23
+
24
+ # @param summary_list_items [Array<Hash>] An array of options for the summary list rows.
25
+ # See {Components::GovUK::SummaryList::Row#initialize Row#initialize} for details of the items in the array.
26
+ # @param card [Hash] attributes for the card, see {CCS::Components::GovUK::SummaryList::Card#initialize Card#initialize} for more details.
27
+ # @param options [Hash] options that will be used in customising the HTML
28
+ #
29
+ # @option options [String] :classes additional CSS classes for the summary list HTML
30
+ # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
31
+
32
+ def initialize(summary_list_items:, card: nil, **options)
33
+ super(**options)
34
+
35
+ any_row_has_actions = summary_list_items.any? { |summary_list_item| summary_list_item[:actions].present? }
36
+
37
+ @summary_list_rows = summary_list_items.map { |summary_list_item| Row.new(any_row_has_actions: any_row_has_actions, context: @context, **summary_list_item) }
38
+ @card = Card.new(context: @context, **card) if card
39
+ end
40
+
41
+ # Generates the HTML for the GOV.UK Summary list component
42
+ #
43
+ # @return [ActiveSupport::SafeBuffer]
44
+
45
+ def render
46
+ if card
47
+ card.render do
48
+ render_summary_list
49
+ end
50
+ else
51
+ render_summary_list
52
+ end
53
+ end
54
+
55
+ # The default attributes for the summary list
56
+
57
+ DEFAULT_ATTRIBUTES = { class: 'govuk-summary-list' }.freeze
58
+
59
+ private
60
+
61
+ # Generates the HTML for the actual summary list
62
+ #
63
+ # @return [ActiveSupport::SafeBuffer]
64
+
65
+ def render_summary_list
66
+ tag.dl(**options[:attributes]) do
67
+ summary_list_rows.each { |summary_list_row| concat(summary_list_row.render) }
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end