ccs-frontend_helpers 0.1.0.rc.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -5
  3. data/CHANGELOG.md +2 -4
  4. data/Gemfile +1 -15
  5. data/Gemfile.lock +80 -81
  6. data/ccs-frontend_helpers.gemspec +10 -0
  7. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +79 -0
  8. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +119 -6
  9. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +183 -6
  10. data/lib/ccs/{components/ccs → frontend_helpers/ccs_frontend}/logo.rb +12 -10
  11. data/lib/ccs/frontend_helpers/ccs_frontend.rb +4 -2
  12. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +95 -8
  13. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -6
  14. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +54 -6
  15. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +105 -6
  16. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +114 -6
  17. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +23 -7
  18. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -11
  19. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +65 -13
  20. data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +165 -0
  21. data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +200 -0
  22. data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +153 -0
  23. data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +83 -0
  24. data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +153 -0
  25. data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +201 -0
  26. data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +124 -0
  27. data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +106 -0
  28. data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +213 -0
  29. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +48 -7
  30. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +161 -6
  31. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +24 -13
  32. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +139 -6
  33. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +17 -8
  34. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +21 -7
  35. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +70 -7
  36. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +113 -7
  37. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +314 -6
  38. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +28 -7
  39. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +27 -8
  40. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +18 -6
  41. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +186 -7
  42. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +204 -6
  43. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +100 -11
  44. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +73 -6
  45. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +21 -7
  46. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +30 -7
  47. data/lib/ccs/frontend_helpers/govuk_frontend.rb +19 -17
  48. data/lib/ccs/frontend_helpers/shared_methods.rb +27 -0
  49. data/lib/ccs/frontend_helpers/version.rb +1 -1
  50. metadata +142 -112
  51. data/.ruby-version +0 -1
  52. data/lib/ccs/components/base.rb +0 -64
  53. data/lib/ccs/components/ccs/dashboard_section/panel.rb +0 -57
  54. data/lib/ccs/components/ccs/dashboard_section.rb +0 -71
  55. data/lib/ccs/components/ccs/footer/link.rb +0 -55
  56. data/lib/ccs/components/ccs/footer/meta.rb +0 -59
  57. data/lib/ccs/components/ccs/footer/navigation.rb +0 -60
  58. data/lib/ccs/components/ccs/footer.rb +0 -95
  59. data/lib/ccs/components/ccs/header/link.rb +0 -60
  60. data/lib/ccs/components/ccs/header/navigation.rb +0 -98
  61. data/lib/ccs/components/ccs/header/service_authentication.rb +0 -53
  62. data/lib/ccs/components/ccs/header.rb +0 -110
  63. data/lib/ccs/components/govuk/accordion/section/content.rb +0 -53
  64. data/lib/ccs/components/govuk/accordion/section/header.rb +0 -57
  65. data/lib/ccs/components/govuk/accordion/section.rb +0 -61
  66. data/lib/ccs/components/govuk/accordion.rb +0 -58
  67. data/lib/ccs/components/govuk/back_link.rb +0 -51
  68. data/lib/ccs/components/govuk/breadcrumbs/link.rb +0 -57
  69. data/lib/ccs/components/govuk/breadcrumbs.rb +0 -55
  70. data/lib/ccs/components/govuk/button.rb +0 -107
  71. data/lib/ccs/components/govuk/cookie_banner/action.rb +0 -60
  72. data/lib/ccs/components/govuk/cookie_banner/message.rb +0 -80
  73. data/lib/ccs/components/govuk/cookie_banner.rb +0 -55
  74. data/lib/ccs/components/govuk/details.rb +0 -53
  75. data/lib/ccs/components/govuk/error_message.rb +0 -60
  76. data/lib/ccs/components/govuk/error_summary/item.rb +0 -54
  77. data/lib/ccs/components/govuk/error_summary.rb +0 -70
  78. data/lib/ccs/components/govuk/field/input/character_count.rb +0 -129
  79. data/lib/ccs/components/govuk/field/input/file_upload.rb +0 -44
  80. data/lib/ccs/components/govuk/field/input/select.rb +0 -82
  81. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +0 -55
  82. data/lib/ccs/components/govuk/field/input/text_input.rb +0 -97
  83. data/lib/ccs/components/govuk/field/input/textarea.rb +0 -59
  84. data/lib/ccs/components/govuk/field/input.rb +0 -62
  85. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +0 -69
  86. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +0 -65
  87. data/lib/ccs/components/govuk/field/inputs/date_input.rb +0 -89
  88. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +0 -47
  89. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +0 -43
  90. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +0 -50
  91. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +0 -50
  92. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +0 -44
  93. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +0 -43
  94. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +0 -50
  95. data/lib/ccs/components/govuk/field/inputs/item.rb +0 -111
  96. data/lib/ccs/components/govuk/field/inputs/radios.rb +0 -69
  97. data/lib/ccs/components/govuk/field/inputs.rb +0 -57
  98. data/lib/ccs/components/govuk/field.rb +0 -108
  99. data/lib/ccs/components/govuk/fieldset/legend.rb +0 -65
  100. data/lib/ccs/components/govuk/fieldset.rb +0 -54
  101. data/lib/ccs/components/govuk/footer/link.rb +0 -55
  102. data/lib/ccs/components/govuk/footer/meta.rb +0 -59
  103. data/lib/ccs/components/govuk/footer/navigation.rb +0 -60
  104. data/lib/ccs/components/govuk/footer.rb +0 -131
  105. data/lib/ccs/components/govuk/form_group.rb +0 -60
  106. data/lib/ccs/components/govuk/header/link.rb +0 -56
  107. data/lib/ccs/components/govuk/header/navigation.rb +0 -71
  108. data/lib/ccs/components/govuk/header.rb +0 -107
  109. data/lib/ccs/components/govuk/hint.rb +0 -49
  110. data/lib/ccs/components/govuk/inset_text.rb +0 -52
  111. data/lib/ccs/components/govuk/label.rb +0 -85
  112. data/lib/ccs/components/govuk/notification_banner.rb +0 -107
  113. data/lib/ccs/components/govuk/pagination/increment/next.rb +0 -44
  114. data/lib/ccs/components/govuk/pagination/increment/previous.rb +0 -43
  115. data/lib/ccs/components/govuk/pagination/increment.rb +0 -98
  116. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +0 -28
  117. data/lib/ccs/components/govuk/pagination/item/form.rb +0 -49
  118. data/lib/ccs/components/govuk/pagination/item/tag.rb +0 -47
  119. data/lib/ccs/components/govuk/pagination/item.rb +0 -64
  120. data/lib/ccs/components/govuk/pagination.rb +0 -96
  121. data/lib/ccs/components/govuk/panel.rb +0 -62
  122. data/lib/ccs/components/govuk/phase_banner.rb +0 -69
  123. data/lib/ccs/components/govuk/skip_link.rb +0 -51
  124. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +0 -53
  125. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +0 -50
  126. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +0 -45
  127. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +0 -63
  128. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +0 -69
  129. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +0 -56
  130. data/lib/ccs/components/govuk/step_by_step_navigation.rb +0 -59
  131. data/lib/ccs/components/govuk/summary_list/action/link.rb +0 -59
  132. data/lib/ccs/components/govuk/summary_list/card/actions.rb +0 -59
  133. data/lib/ccs/components/govuk/summary_list/card/title.rb +0 -51
  134. data/lib/ccs/components/govuk/summary_list/card.rb +0 -63
  135. data/lib/ccs/components/govuk/summary_list/row/actions.rb +0 -59
  136. data/lib/ccs/components/govuk/summary_list/row/key.rb +0 -47
  137. data/lib/ccs/components/govuk/summary_list/row/value.rb +0 -47
  138. data/lib/ccs/components/govuk/summary_list/row.rb +0 -67
  139. data/lib/ccs/components/govuk/summary_list.rb +0 -74
  140. data/lib/ccs/components/govuk/table/body/data_cell.rb +0 -53
  141. data/lib/ccs/components/govuk/table/body/head_cell.rb +0 -52
  142. data/lib/ccs/components/govuk/table/header/head_cell.rb +0 -54
  143. data/lib/ccs/components/govuk/table.rb +0 -111
  144. data/lib/ccs/components/govuk/tabs/panel.rb +0 -58
  145. data/lib/ccs/components/govuk/tabs/tab.rb +0 -56
  146. data/lib/ccs/components/govuk/tabs.rb +0 -66
  147. data/lib/ccs/components/govuk/tag.rb +0 -51
  148. data/lib/ccs/components/govuk/warning_text.rb +0 -61
  149. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +0 -27
  150. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +0 -28
  151. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +0 -28
  152. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +0 -28
  153. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +0 -28
  154. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +0 -28
  155. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +0 -28
  156. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +0 -28
  157. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +0 -28
@@ -1,110 +0,0 @@
1
- require_relative '../base'
2
- require_relative 'logo'
3
- require_relative 'header/service_authentication'
4
- require_relative 'header/navigation'
5
-
6
- module CCS
7
- module Components
8
- module CCS
9
- # = CCS Header
10
- #
11
- # This is used for generating the header component from the
12
- # {https://github.com/tim-s-ccs/ts-ccs-frontend/tree/main/src/ccs/components/header CCS - Components - Header}
13
- #
14
- # @!attribute [r] service_authentication
15
- # @return [ServiceAuthentication] The initialised service authentication section
16
- # @!attribute [r] navigation
17
- # @return [Navigation] The initialised navigation section
18
- # @!attribute [r] service
19
- # @return [Hash] The options for the service section
20
-
21
- class Header < Base
22
- private
23
-
24
- attr_reader :service_authentication, :navigation, :service
25
-
26
- public
27
-
28
- # @param service_authentication_items [Array<Hash>] An array of links for the service authentication section of the header.
29
- # See {Components::CCS::Header::ServiceAuthentication#initialize ServiceAuthentication#initialize} for details of the items in the array.
30
- # @param navigation [Hash] options for the navigation section of the header.
31
- # See {Components::CCS::Header::Navigation#initialize Navigation#initialize} for details of the options.
32
- # @param menu_button [Hash] options for the menu button in the header.
33
- # See {Components::CCS::Header::Navigation#initialize Navigation#initialize} for details of the options.
34
- # @param service [Hash] options for the service name
35
- # @param options [Hash] options that will be used in customising the HTML
36
- #
37
- # @option service [String] :name the name of the service, included in the header
38
- # @option service [String] :href URL for the service name anchor
39
- #
40
- # @option options [String] :classes additional CSS classes for the header HTML
41
- # @option options [String] :container_classes classes for the container
42
- # @option options [String] :homepage_url URL of the homepage. Defaults to +/https://www.crowncommercial.gov.uk+
43
- # @option options [Hash] :attributes additional attributes that will added as part of the header HTML
44
-
45
- def initialize(service_authentication_items: nil, navigation: nil, menu_button: nil, service: nil, **options)
46
- super(**options)
47
-
48
- @options[:attributes][:role] = 'banner'
49
- @options[:container_classes] ||= 'govuk-width-container'
50
- @options[:homepage_url] ||= 'https://www.crowncommercial.gov.uk'
51
-
52
- @service_authentication = ServiceAuthentication.new(service_authentication_items: service_authentication_items, container_classes: @options[:container_classes], context: @context) if service_authentication_items
53
- @navigation = Navigation.new(navigation: navigation, serivce_name_present: service, menu_button: menu_button, context: @context) if navigation
54
- @service = service
55
- end
56
-
57
- # rubocop:disable Metrics/AbcSize
58
-
59
- # Generates the HTML for the CCS Header component
60
- #
61
- # @return [ActiveSupport::SafeBuffer]
62
-
63
- def render
64
- tag.header(**options[:attributes]) do
65
- concat(service_authentication.render) if service_authentication
66
- concat(tag.div(class: "ccs-header__container #{options[:container_classes]}".rstrip) do
67
- concat(header_logo)
68
- if service || navigation
69
- concat(tag.div(class: 'ccs-header__content') do
70
- concat(header_service_name) if service
71
- concat(navigation.render) if navigation
72
- end)
73
- end
74
- end)
75
- end
76
- end
77
-
78
- # rubocop:enable Metrics/AbcSize
79
-
80
- # The default attributes for the breadcrumbs
81
-
82
- DEFAULT_ATTRIBUTES = { class: 'ccs-header', data: { module: 'ccs-header' } }.freeze
83
-
84
- private
85
-
86
- # Generates the logo for header
87
- #
88
- # @return [ActiveSupport::SafeBuffer]
89
-
90
- def header_logo
91
- tag.div(class: 'ccs-header__logo') do
92
- link_to(Logo.render, options[:homepage_url], class: 'ccs-header__link ccs-header__link--homepage', aria: { label: 'Crown Commercial Service' })
93
- end
94
- end
95
-
96
- # Generates the service name section
97
- #
98
- # @return [ActiveSupport::SafeBuffer]
99
-
100
- def header_service_name
101
- if service[:href]
102
- link_to(service[:name], service[:href], class: 'ccs-header__link ccs-header__link--service-name')
103
- else
104
- tag.span(service[:name], class: 'ccs-header__link--service-name')
105
- end
106
- end
107
- end
108
- end
109
- end
110
- end
@@ -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