ccs-frontend_helpers 0.1.0.rc.6 → 0.1.0

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 +1 -5
  3. data/CHANGELOG.md +1 -4
  4. data/Gemfile.lock +77 -75
  5. data/ccs-frontend_helpers.gemspec +1 -1
  6. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +79 -0
  7. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +119 -6
  8. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +183 -6
  9. data/lib/ccs/{components/ccs → frontend_helpers/ccs_frontend}/logo.rb +12 -10
  10. data/lib/ccs/frontend_helpers/ccs_frontend.rb +4 -2
  11. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +95 -8
  12. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -6
  13. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +54 -6
  14. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +105 -6
  15. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +114 -6
  16. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +23 -7
  17. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -11
  18. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +65 -13
  19. data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +165 -0
  20. data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +200 -0
  21. data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +153 -0
  22. data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +83 -0
  23. data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +153 -0
  24. data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +201 -0
  25. data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +124 -0
  26. data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +106 -0
  27. data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +213 -0
  28. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +48 -7
  29. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +161 -6
  30. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +24 -13
  31. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +139 -6
  32. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +17 -8
  33. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +21 -7
  34. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +70 -7
  35. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +113 -7
  36. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +314 -6
  37. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +28 -7
  38. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +27 -8
  39. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +18 -6
  40. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +186 -7
  41. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +204 -6
  42. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +102 -6
  43. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +73 -6
  44. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +21 -7
  45. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +30 -7
  46. data/lib/ccs/frontend_helpers/govuk_frontend.rb +19 -17
  47. data/lib/ccs/frontend_helpers/shared_methods.rb +27 -0
  48. data/lib/ccs/frontend_helpers/version.rb +1 -1
  49. metadata +18 -114
  50. data/.ruby-version +0 -1
  51. data/lib/ccs/components/base.rb +0 -64
  52. data/lib/ccs/components/ccs/dashboard_section/panel.rb +0 -57
  53. data/lib/ccs/components/ccs/dashboard_section.rb +0 -71
  54. data/lib/ccs/components/ccs/footer/link.rb +0 -55
  55. data/lib/ccs/components/ccs/footer/meta.rb +0 -59
  56. data/lib/ccs/components/ccs/footer/navigation.rb +0 -60
  57. data/lib/ccs/components/ccs/footer.rb +0 -95
  58. data/lib/ccs/components/ccs/header/link.rb +0 -60
  59. data/lib/ccs/components/ccs/header/navigation.rb +0 -98
  60. data/lib/ccs/components/ccs/header/service_authentication.rb +0 -53
  61. data/lib/ccs/components/ccs/header.rb +0 -110
  62. data/lib/ccs/components/govuk/accordion/section/content.rb +0 -53
  63. data/lib/ccs/components/govuk/accordion/section/header.rb +0 -57
  64. data/lib/ccs/components/govuk/accordion/section.rb +0 -61
  65. data/lib/ccs/components/govuk/accordion.rb +0 -58
  66. data/lib/ccs/components/govuk/back_link.rb +0 -51
  67. data/lib/ccs/components/govuk/breadcrumbs/link.rb +0 -57
  68. data/lib/ccs/components/govuk/breadcrumbs.rb +0 -55
  69. data/lib/ccs/components/govuk/button.rb +0 -107
  70. data/lib/ccs/components/govuk/cookie_banner/action.rb +0 -60
  71. data/lib/ccs/components/govuk/cookie_banner/message.rb +0 -80
  72. data/lib/ccs/components/govuk/cookie_banner.rb +0 -55
  73. data/lib/ccs/components/govuk/details.rb +0 -53
  74. data/lib/ccs/components/govuk/error_message.rb +0 -60
  75. data/lib/ccs/components/govuk/error_summary/item.rb +0 -54
  76. data/lib/ccs/components/govuk/error_summary.rb +0 -70
  77. data/lib/ccs/components/govuk/field/input/character_count.rb +0 -129
  78. data/lib/ccs/components/govuk/field/input/file_upload.rb +0 -44
  79. data/lib/ccs/components/govuk/field/input/select.rb +0 -82
  80. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +0 -55
  81. data/lib/ccs/components/govuk/field/input/text_input.rb +0 -97
  82. data/lib/ccs/components/govuk/field/input/textarea.rb +0 -59
  83. data/lib/ccs/components/govuk/field/input.rb +0 -62
  84. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +0 -69
  85. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +0 -65
  86. data/lib/ccs/components/govuk/field/inputs/date_input.rb +0 -89
  87. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +0 -47
  88. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +0 -43
  89. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +0 -50
  90. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +0 -50
  91. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +0 -44
  92. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +0 -43
  93. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +0 -50
  94. data/lib/ccs/components/govuk/field/inputs/item.rb +0 -111
  95. data/lib/ccs/components/govuk/field/inputs/radios.rb +0 -69
  96. data/lib/ccs/components/govuk/field/inputs.rb +0 -57
  97. data/lib/ccs/components/govuk/field.rb +0 -108
  98. data/lib/ccs/components/govuk/fieldset/legend.rb +0 -65
  99. data/lib/ccs/components/govuk/fieldset.rb +0 -54
  100. data/lib/ccs/components/govuk/footer/link.rb +0 -55
  101. data/lib/ccs/components/govuk/footer/meta.rb +0 -59
  102. data/lib/ccs/components/govuk/footer/navigation.rb +0 -60
  103. data/lib/ccs/components/govuk/footer.rb +0 -131
  104. data/lib/ccs/components/govuk/form_group.rb +0 -60
  105. data/lib/ccs/components/govuk/header/link.rb +0 -56
  106. data/lib/ccs/components/govuk/header/navigation.rb +0 -71
  107. data/lib/ccs/components/govuk/header.rb +0 -107
  108. data/lib/ccs/components/govuk/hint.rb +0 -49
  109. data/lib/ccs/components/govuk/inset_text.rb +0 -52
  110. data/lib/ccs/components/govuk/label.rb +0 -85
  111. data/lib/ccs/components/govuk/notification_banner.rb +0 -107
  112. data/lib/ccs/components/govuk/pagination/increment/next.rb +0 -44
  113. data/lib/ccs/components/govuk/pagination/increment/previous.rb +0 -43
  114. data/lib/ccs/components/govuk/pagination/increment.rb +0 -98
  115. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +0 -28
  116. data/lib/ccs/components/govuk/pagination/item/form.rb +0 -49
  117. data/lib/ccs/components/govuk/pagination/item/tag.rb +0 -47
  118. data/lib/ccs/components/govuk/pagination/item.rb +0 -64
  119. data/lib/ccs/components/govuk/pagination.rb +0 -96
  120. data/lib/ccs/components/govuk/panel.rb +0 -62
  121. data/lib/ccs/components/govuk/phase_banner.rb +0 -69
  122. data/lib/ccs/components/govuk/skip_link.rb +0 -51
  123. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +0 -53
  124. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +0 -50
  125. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +0 -45
  126. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +0 -63
  127. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +0 -69
  128. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +0 -56
  129. data/lib/ccs/components/govuk/step_by_step_navigation.rb +0 -59
  130. data/lib/ccs/components/govuk/summary_list/action/link.rb +0 -59
  131. data/lib/ccs/components/govuk/summary_list/card/actions.rb +0 -59
  132. data/lib/ccs/components/govuk/summary_list/card/title.rb +0 -51
  133. data/lib/ccs/components/govuk/summary_list/card.rb +0 -63
  134. data/lib/ccs/components/govuk/summary_list/row/actions.rb +0 -59
  135. data/lib/ccs/components/govuk/summary_list/row/key.rb +0 -47
  136. data/lib/ccs/components/govuk/summary_list/row/value.rb +0 -47
  137. data/lib/ccs/components/govuk/summary_list/row.rb +0 -67
  138. data/lib/ccs/components/govuk/summary_list.rb +0 -74
  139. data/lib/ccs/components/govuk/table/body/data_cell.rb +0 -53
  140. data/lib/ccs/components/govuk/table/body/head_cell.rb +0 -52
  141. data/lib/ccs/components/govuk/table/header/head_cell.rb +0 -54
  142. data/lib/ccs/components/govuk/table.rb +0 -111
  143. data/lib/ccs/components/govuk/tabs/panel.rb +0 -58
  144. data/lib/ccs/components/govuk/tabs/tab.rb +0 -56
  145. data/lib/ccs/components/govuk/tabs.rb +0 -66
  146. data/lib/ccs/components/govuk/tag.rb +0 -51
  147. data/lib/ccs/components/govuk/warning_text.rb +0 -61
  148. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +0 -27
  149. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +0 -28
  150. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +0 -28
  151. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +0 -28
  152. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +0 -28
  153. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +0 -28
  154. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +0 -28
  155. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +0 -28
  156. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +0 -28
@@ -1,53 +0,0 @@
1
- module CCS
2
- module Components
3
- module GovUK
4
- class Accordion < Base
5
- class Section
6
- # = GOV.UK Accordion Section Content
7
- #
8
- # The individual accordion section content
9
- #
10
- # @!attribute [r] section
11
- # @return [Hash] Attributes for the accordion section
12
- # @!attribute [r] accordion_id
13
- # @return [String] ID of the accordion
14
- # @!attribute [r] index
15
- # @return [Integer] Index of the accordion section
16
-
17
- class Content
18
- include ActionView::Context
19
- include ActionView::Helpers
20
-
21
- private
22
-
23
- attr_reader :section, :accordion_id, :index
24
-
25
- public
26
-
27
- # @param section [Hash] attributes for the accordion section
28
- # @param accordion_id [String] ID of the accordion
29
- # @param index [Integer] the index of the accordion section
30
- #
31
- # @option (see CCS::Components::GovUK::Accordion::Section)
32
-
33
- def initialize(section:, accordion_id:, index:)
34
- @section = section
35
- @accordion_id = accordion_id
36
- @index = index
37
- end
38
-
39
- # Generates the HTML for the GOV.UK Accordion Section Content
40
- #
41
- # @return [ActiveSupport::SafeBuffer]
42
-
43
- def render
44
- tag.div(class: 'govuk-accordion__section-content', id: "#{accordion_id}-content-#{index}", aria: { labelledby: "#{accordion_id}-heading-#{index}" }) do
45
- section[:content] || tag.p(section[:text], class: 'govuk-body')
46
- end
47
- end
48
- end
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,57 +0,0 @@
1
- module CCS
2
- module Components
3
- module GovUK
4
- class Accordion < Base
5
- class Section
6
- # = GOV.UK Accordion Section Header
7
- #
8
- # The individual accordion section header
9
- #
10
- # @!attribute [r] section
11
- # @return [Hash] Attributes for the accordion section
12
- # @!attribute [r] accordion_id
13
- # @return [String] ID of the accordion
14
- # @!attribute [r] index
15
- # @return [Integer] Index of the accordion section
16
- # @!attribute [r] heading_level
17
- # @return [Integer] The heading level for the accordion section
18
-
19
- class Header
20
- include ActionView::Context
21
- include ActionView::Helpers
22
-
23
- private
24
-
25
- attr_reader :section, :accordion_id, :index, :heading_level
26
-
27
- public
28
-
29
- # @param (see CCS::Components::GovUK::Accordion::Section)
30
- #
31
- # @option (see CCS::Components::GovUK::Accordion::Section)
32
-
33
- def initialize(section:, accordion_id:, index:, heading_level:)
34
- @section = section
35
- @accordion_id = accordion_id
36
- @index = index
37
- @heading_level = heading_level
38
- end
39
-
40
- # Generates the HTML for the GOV.UK Accordion Section Header
41
- #
42
- # @return [ActiveSupport::SafeBuffer]
43
-
44
- def render
45
- tag.div(class: 'govuk-accordion__section-header') do
46
- concat(tag.send("h#{heading_level}", class: 'govuk-accordion__section-heading') do
47
- tag.span(section[:heading], class: 'govuk-accordion__section-button', id: "#{accordion_id}-heading-#{index}")
48
- end)
49
- concat(tag.div(section[:summary], class: 'govuk-accordion__section-summary govuk-body', id: "#{accordion_id}-summary-#{index}")) if section[:summary]
50
- end
51
- end
52
- end
53
- end
54
- end
55
- end
56
- end
57
- end
@@ -1,61 +0,0 @@
1
- require_relative 'section/header'
2
- require_relative 'section/content'
3
-
4
- module CCS
5
- module Components
6
- module GovUK
7
- class Accordion < Base
8
- # = GOV.UK Accordion Section
9
- #
10
- # The individual accordion section
11
- #
12
- # @!attribute [r] header
13
- # @return [Header] Initialised accordion section header
14
- # @!attribute [r] content
15
- # @return [Content] Initialised accordion section content
16
- # @!attribute [r] section_is_expanded
17
- # @return [Boolean] flag to indicate of the section should be expanded
18
-
19
- class Section
20
- include ActionView::Context
21
- include ActionView::Helpers
22
-
23
- private
24
-
25
- attr_reader :header, :content, :section_is_expanded
26
-
27
- public
28
-
29
- # @param section [Hash] attributes for the accordion section
30
- # @param accordion_id [String] ID of the accordion
31
- # @param index [Integer] the index of the accordion section
32
- # @param heading_level [Integer] heading level, from 1 to 6
33
- #
34
- # @option section [Boolean] :expanded sets whether the section should be expanded
35
- # when the page loads for the first time.
36
- # @option section [String] :heading the heading text for the accordion
37
- # @option section [String] :summary (nil) optional summary text for the accordion header
38
- # @option section [ActiveSupport::SafeBuffer] :content the content within the accordion section
39
- # @option section [String] : text if +:content+ is +nil+ then the text will be rendered
40
-
41
- def initialize(section:, accordion_id:, index:, heading_level:)
42
- @section_is_expanded = section[:expanded]
43
- @header = Header.new(section: section, accordion_id: accordion_id, index: index, heading_level: heading_level)
44
- @content = Content.new(section: section, accordion_id: accordion_id, index: index)
45
- end
46
-
47
- # Generates the HTML for the GOV.UK Accordion Section
48
- #
49
- # @return [ActiveSupport::SafeBuffer]
50
-
51
- def render
52
- tag.div(class: "govuk-accordion__section #{'govuk-accordion__section--expanded' if section_is_expanded}".rstrip) do
53
- concat(header.render)
54
- concat(content.render)
55
- end
56
- end
57
- end
58
- end
59
- end
60
- end
61
- end
@@ -1,58 +0,0 @@
1
- require_relative '../base'
2
- require_relative 'accordion/section'
3
-
4
- module CCS
5
- module Components
6
- module GovUK
7
- # = GOV.UK Accordion
8
- #
9
- # This is used for generating the accordion component from the
10
- # {https://design-system.service.gov.uk/accordion/back-link GDS - Components - Accordion}
11
- #
12
- # @!attribute [r] accordion_sections
13
- # @return [Array<Section>] An array of the initialised accordion sections
14
-
15
- class Accordion < Base
16
- private
17
-
18
- attr_reader :accordion_sections
19
-
20
- public
21
-
22
- # @param accordion_id [String] used as an id in the HTML for the accordion as a whole,
23
- # and also as a prefix for the ids of the section contents
24
- # and the buttons that open them
25
- # @param accordion_sections [Array<Hash>] an array of accordion section attributes.
26
- # See {Components::GovUK::Accordion::Section#initialize Section#initialize} for details of the items in the array.
27
- # @param options [Hash] options that will be used in customising the HTML
28
- #
29
- # @option options [String] :classes additional CSS classes for the accordion HTML
30
- # @option options [Integer] :heading_level (2) heading level, from 1 to 6
31
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
32
-
33
- def initialize(accordion_id:, accordion_sections:, **options)
34
- super(**options)
35
-
36
- @options[:attributes][:id] = accordion_id
37
- @options[:heading_level] ||= 2
38
-
39
- @accordion_sections = accordion_sections.map.with_index(1) { |accordion_section, index| Section.new(section: accordion_section, accordion_id: accordion_id, index: index, heading_level: @options[:heading_level]) }
40
- end
41
-
42
- # Generates the HTML for the GOV.UK Accordion component
43
- #
44
- # @return [ActiveSupport::SafeBuffer]
45
-
46
- def render
47
- tag.div(**options[:attributes]) do
48
- accordion_sections.each { |accordion_section| concat(accordion_section.render) }
49
- end
50
- end
51
-
52
- # The default attributes for the accordion
53
-
54
- DEFAULT_ATTRIBUTES = { class: 'govuk-accordion', data: { module: 'govuk-accordion' } }.freeze
55
- end
56
- end
57
- end
58
- end
@@ -1,51 +0,0 @@
1
- require_relative '../base'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- # = GOV.UK Back Link
7
- #
8
- # This is used to generate the back link component from the
9
- # {https://design-system.service.gov.uk/components/back-link GDS - Components - Back link}
10
- #
11
- # @!attribute [r] text
12
- # @return [String] Text for the back link
13
- # @!attribute [r] href
14
- # @return [String] The href for the back link
15
-
16
- class BackLink < Base
17
- private
18
-
19
- attr_reader :text, :href
20
-
21
- public
22
-
23
- # @param text [String] the text for the back link
24
- # @param href [String] the href for the back link
25
- # @param options [Hash] options that will be used in customising the HTML
26
- #
27
- # @option options [String] :classes additional CSS classes for the back link HTML
28
- # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
29
-
30
- def initialize(text:, href:, **options)
31
- super(**options)
32
-
33
- @text = text
34
- @href = href
35
- end
36
-
37
- # Generates the HTML for the GOV.UK Back link component
38
- #
39
- # @return [ActiveSupport::SafeBuffer]
40
-
41
- def render
42
- link_to(text, href, **options[:attributes])
43
- end
44
-
45
- # The default attributes for the back link
46
-
47
- DEFAULT_ATTRIBUTES = { class: 'govuk-back-link' }.freeze
48
- end
49
- end
50
- end
51
- end
@@ -1,57 +0,0 @@
1
- require_relative '../../base'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Breadcrumbs < Base
7
- # = GOV.UK Breadcrumbs Link
8
- #
9
- # The individual list item for the breadcrumbs
10
- #
11
- # @!attribute [r] text
12
- # @return [String] Text for the breadcrumb link
13
- # @!attribute [r] href
14
- # @return [String] The href for the breadcrumb link
15
-
16
- class Link < Base
17
- private
18
-
19
- attr_reader :text, :href
20
-
21
- public
22
-
23
- # @param text [String] the text for the breadcrumb link
24
- # @param href [String] the href for the breadcrumb link.
25
- # If blank it is assumed that this item relates to current page
26
- # @param options [Hash] options that will be used in customising the HTML
27
- #
28
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML.
29
- # If the link is blank then it defaults to +{ aria: { current: 'page' } }+
30
-
31
- def initialize(text:, href: nil, **options)
32
- super(**options)
33
-
34
- @text = text
35
- @href = href
36
- end
37
-
38
- # Generates the HTML for the GOV.UK Breadcrumbs link
39
- #
40
- # @return [ActiveSupport::SafeBuffer]
41
-
42
- def render
43
- if href.present?
44
- options[:attributes][:class] = 'govuk-breadcrumbs__link'
45
-
46
- tag.li(class: 'govuk-breadcrumbs__list-item') do
47
- link_to(text, href, **options[:attributes])
48
- end
49
- else
50
- tag.li(text, class: 'govuk-breadcrumbs__list-item', aria: { current: 'page' })
51
- end
52
- end
53
- end
54
- end
55
- end
56
- end
57
- end
@@ -1,55 +0,0 @@
1
- require_relative '../base'
2
- require_relative 'breadcrumbs/link'
3
-
4
- module CCS
5
- module Components
6
- module GovUK
7
- # = GOV.UK Breadcrumbs
8
- #
9
- # This is used to generate the breadcrumbs component from the
10
- # {https://design-system.service.gov.uk/components/breadcrumbs GDS - Components - Breadcrumbs}
11
- #
12
- # @!attribute [r] breadcrumb_links
13
- # @return [Array<Link>] An array of the initialised breadcrumb links
14
-
15
- class Breadcrumbs < Base
16
- private
17
-
18
- attr_reader :breadcrumb_links
19
-
20
- public
21
-
22
- # @param breadcrumb_links [Array<Hash>] An array of links for the breadcrumbs list.
23
- # See {Components::GovUK::Breadcrumbs::Link#initialize Link#initialize} for details of the items in the array.
24
- # @param options [Hash] options that will be used in customising the HTML
25
- #
26
- # @option options [String] :classes additional CSS classes for the breadcrumbs HTML
27
- # @option options [Boolean] :collapse_on_mobile indicates if it is to colapse breadcrumbs on mobile
28
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
29
-
30
- def initialize(breadcrumb_links:, **options)
31
- super(**options)
32
- @options[:attributes][:class] << ' govuk-breadcrumbs--collapse-on-mobile' if @options[:collapse_on_mobile]
33
-
34
- @breadcrumb_links = breadcrumb_links.map { |breadcrumb_link| Link.new(context: @context, **breadcrumb_link) }
35
- end
36
-
37
- # Generates the HTML for the GOV.UK breadcrumbs component
38
- #
39
- # @return [ActiveSupport::SafeBuffer]
40
-
41
- def render
42
- tag.div(**options[:attributes]) do
43
- tag.ol(class: 'govuk-breadcrumbs__list') do
44
- breadcrumb_links.each { |breadcrumb_link| concat(breadcrumb_link.render) }
45
- end
46
- end
47
- end
48
-
49
- # The default attributes for the breadcrumbs
50
-
51
- DEFAULT_ATTRIBUTES = { class: 'govuk-breadcrumbs' }.freeze
52
- end
53
- end
54
- end
55
- end
@@ -1,107 +0,0 @@
1
- require_relative '../base'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- # = GOV.UK Button
7
- #
8
- # This is used to generate the button component from the
9
- # {https://design-system.service.gov.uk/components/button GDS - Components - Button}
10
- #
11
- # @!attribute [r] text
12
- # @return [String] Text for the button
13
- # @!attribute [r] render_method
14
- # @return [String] The method that will be used to render the button
15
-
16
- class Button < Base
17
- private
18
-
19
- attr_reader :text, :render_method
20
-
21
- public
22
-
23
- # @param text [String] the text that will be shown in the button
24
- # @param options [Hash] options that will be used in customising the HTML
25
- #
26
- # @option options [String] :classes additional CSS classes for the button HTML
27
- # @option options [Boolean] :is_start_button indicates if it is a start button
28
- # @option options [String] :href the URI that will be used in anchor tag
29
- # @option options [ActionView::Helpers::FormBuilder] :form the form builder used to create the submit button
30
- # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
31
-
32
- def initialize(text:, **options)
33
- super(**options)
34
-
35
- @options[:attributes][:class] << ' govuk-button--disabled' if @options[:attributes][:disabled]
36
- @options[:attributes][:class] << ' govuk-button--start' if @options[:is_start_button]
37
-
38
- @text = text
39
- @render_method = :"render_#{if @options[:href]
40
- :link
41
- elsif @options[:form]
42
- :submit
43
- else
44
- :button
45
- end}"
46
- end
47
-
48
- # Generates the HTML for the GOV.UK Back link component
49
- #
50
- # @return [ActiveSupport::SafeBuffer]
51
-
52
- def render
53
- send(@render_method)
54
- end
55
-
56
- # The default attributes for the button
57
-
58
- DEFAULT_ATTRIBUTES = { class: 'govuk-button', data: { module: 'govuk-button' } }.freeze
59
-
60
- private
61
-
62
- # Generates the HTML for the GOV.UK button component as an anchor tag.
63
- #
64
- # @return [ActiveSupport::SafeBuffer]
65
-
66
- def render_link
67
- @options[:attributes][:role] = :button
68
- @options[:attributes][:draggable] = false
69
-
70
- link_to(@options[:href], **@options[:attributes]) do
71
- concat(text)
72
- concat(start_button_icon) if @options[:is_start_button]
73
- end
74
- end
75
-
76
- # Generates the HTML for the GOV.UK button component as a button.
77
- #
78
- # @return [ActiveSupport::SafeBuffer]
79
-
80
- def render_button
81
- button_tag(**@options[:attributes]) do
82
- concat(text)
83
- concat(start_button_icon) if @options[:is_start_button]
84
- end
85
- end
86
-
87
- # Generates the HTML for the GOV.UK button component as an input.
88
- #
89
- # @return [ActiveSupport::SafeBuffer]
90
-
91
- def render_submit
92
- @options[:form].submit(text, **@options[:attributes])
93
- end
94
-
95
- # Generates the arrow if the button is a start button
96
- #
97
- # @return [ActiveSupport::SafeBuffer]
98
-
99
- def start_button_icon
100
- tag.svg(class: 'govuk-button__start-icon', xmlns: 'http://www.w3.org/2000/svg', width: 17.5, height: 19, viewBox: '0 0 33 40', aria: { hidden: true }, focusable: false) do
101
- tag.path(fill: 'currentColor', d: 'M0 0h13l20 20-20 20H0l20-20z')
102
- end
103
- end
104
- end
105
- end
106
- end
107
- end
@@ -1,60 +0,0 @@
1
- require_relative '../../base'
2
- require_relative '../button'
3
-
4
- module CCS
5
- module Components
6
- module GovUK
7
- class CookieBanner < Base
8
- # = GOV.UK Cookie Banner Action
9
- #
10
- # The individual cookie banner action.
11
- # It defaults to creating button unless a +href+ is set which will create a link
12
- #
13
- # @!attribute [r] text
14
- # @return [String] Text for the action
15
- # @!attribute [r] href
16
- # @return [String] The href for the action
17
-
18
- class Action < Base
19
- private
20
-
21
- attr_reader :text, :href
22
-
23
- public
24
-
25
- # @param text [String] the button or link text
26
- # @param href [String] the href for a link
27
- # @param options [Hash] options that will be used in customising the HTML
28
- #
29
- # @option options [String] : classes additional CSS classes for the cookie action button or link
30
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML.
31
- # If the +:type+ key is present with a value of +:button+,
32
- # the action will be rendered as a button
33
-
34
- def initialize(text:, href: nil, **options)
35
- super(**options)
36
-
37
- @text = text
38
- @href = href
39
- end
40
-
41
- # Generates the HTML for a cookie banner message action
42
- #
43
- # @return [ActiveSupport::SafeBuffer]
44
-
45
- def render
46
- if href && options[:attributes][:type] != :button
47
- link_to(text, href, **options[:attributes])
48
- else
49
- Button.new(text: text, href: href, context: context, **options).render
50
- end
51
- end
52
-
53
- # The default attributes for the cookie banner action
54
-
55
- DEFAULT_ATTRIBUTES = { class: 'govuk-link' }.freeze
56
- end
57
- end
58
- end
59
- end
60
- end
@@ -1,80 +0,0 @@
1
- require_relative '../../base'
2
- require_relative 'action'
3
-
4
- module CCS
5
- module Components
6
- module GovUK
7
- class CookieBanner < Base
8
- # = GOV.UK Cookie Banner Message
9
- #
10
- # The individual cookie banner message
11
- #
12
- # @!attribute [r] heading_text
13
- # @return [String] Heading text for the message
14
- # @!attribute [r] content
15
- # @return [ActiveSupport::SafeBuffer] HTML for the message
16
- # @!attribute [r] text
17
- # @return [String] Text for the message
18
- # @!attribute [r] actions
19
- # @return [Array<Action>] Array of initialised cookie banner actions
20
-
21
- class Message < Base
22
- private
23
-
24
- attr_reader :heading_text, :content, :text, :actions
25
-
26
- public
27
-
28
- # @param heading_text [String] the heading text that displays in the message
29
- # @param content [ActiveSupport::SafeBuffer] HTML to use as content for the message
30
- # @param text [String] if +:content+ is blank then this is the text used for the message
31
- # @param actions [Array<Hash>] the buttons and/or links that you want to display in the message.
32
- # See {Components::GovUK::CookieBanner::Action#initialize Action#initialize} for details of the items in the array.
33
- # @param options [Hash] options that will be used in customising the HTML
34
- #
35
- # @option options [String] :classes additional CSS classes for the cookie message HTML
36
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
37
-
38
- def initialize(heading_text: nil, content: nil, text: nil, actions: nil, **options)
39
- super(**options)
40
-
41
- @heading_text = heading_text
42
- @content = content
43
- @text = text
44
- @actions = actions.map { |action| Action.new(context: @context, **action) } if actions
45
- end
46
-
47
- # rubocop:disable Metrics/AbcSize
48
-
49
- # Generates the HTML for the GOV.UK Cookie Banner Message
50
- #
51
- # @return [ActiveSupport::SafeBuffer]
52
-
53
- def render
54
- tag.div(**options[:attributes]) do
55
- concat(tag.div(class: 'govuk-grid-row') do
56
- tag.div(class: 'govuk-grid-column-two-thirds') do
57
- concat(tag.h2(heading_text, class: 'govuk-cookie-banner__heading govuk-heading-m')) if heading_text
58
- concat(tag.div(class: 'govuk-cookie-banner__content') do
59
- content || tag.p(text, class: 'govuk-body')
60
- end)
61
- end
62
- end)
63
- if actions
64
- concat(tag.div(class: 'govuk-button-group') do
65
- actions.each { |action| concat(action.render) }
66
- end)
67
- end
68
- end
69
- end
70
-
71
- # rubocop:enable Metrics/AbcSize
72
-
73
- # The default attributes for the cookie banner message
74
-
75
- DEFAULT_ATTRIBUTES = { class: 'govuk-cookie-banner__message govuk-width-container' }.freeze
76
- end
77
- end
78
- end
79
- end
80
- end