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,107 +0,0 @@
1
- require_relative '../base'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- # = GOV.UK Notification Banner
7
- #
8
- # This helper is used for generating the notification banner component from the
9
- # {https://design-system.service.gov.uk/components/notification-banner GDS - Components - Notification banner}
10
- #
11
- # @!attribute [r] text
12
- # @return [String] Text for the notification banner
13
- # @!attribute [r] success_banner
14
- # @return [Boolean] Indicates if this is a success banner
15
-
16
- class NotificationBanner < Base
17
- private
18
-
19
- attr_reader :text, :success_banner
20
-
21
- public
22
-
23
- # @param text [String] the text that will be used for the heading in the content section of the banner.
24
- # It is ignored if a block is given
25
- # @param success_banner [Boolean] will use the success banner options if this is set to true
26
- # @param options [Hash] options that will be used in customising the HTML
27
- #
28
- # @option options [String] :classes additional CSS classes for the notification banner HTML
29
- # @option options [String] :title_text ('Important') the title text shown at the top of the banner
30
- # @option options [String] :title_id ('govuk-notification-banner-title') the ID for the title text
31
- # @option options [String] :role ('region') the role for the banner
32
- # @option options [String] :heading_level (2) the heading level for the title text
33
- # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
34
-
35
- def initialize(text: nil, success_banner: nil, **options)
36
- super(**options)
37
-
38
- @text = text
39
- @success_banner = success_banner || false
40
-
41
- set_additional_options_for_banner
42
- end
43
-
44
- # Generates the HTML for the GOV.UK Notification banner component
45
- #
46
- # @yield HTML that will be contained within the 'govuk-notification-banner__content' div
47
- #
48
- # @return [ActiveSupport::SafeBuffer]
49
-
50
- def render
51
- tag.div(**options[:attributes]) do
52
- concat(tag.div(class: 'govuk-notification-banner__header') do
53
- tag.send(:"h#{options[:heading_level] || 2}", options[:title_text], class: 'govuk-notification-banner__title', id: options[:title_id])
54
- end)
55
- concat(tag.div(class: 'govuk-notification-banner__content') do
56
- if block_given?
57
- yield
58
- else
59
- tag.p(text, class: 'govuk-notification-banner__heading')
60
- end
61
- end)
62
- end
63
- end
64
-
65
- # The default attributes for the notifaction banner
66
-
67
- DEFAULT_ATTRIBUTES = { class: 'govuk-notification-banner', data: { module: 'govuk-notification-banner' } }.freeze
68
-
69
- # Default options used in normal versions of the notification banner
70
-
71
- DEFAULT_OPTIONS = {
72
- title_text: 'Important',
73
- title_id: 'govuk-notification-banner-title',
74
- role: 'region'
75
- }.freeze
76
-
77
- # Specific options for the success version of the notification banner
78
-
79
- SUCCESS_BANNER_OPTIONS = {
80
- classes: ' govuk-notification-banner--success',
81
- title_text: 'Success',
82
- role: 'alert'
83
- }.freeze
84
-
85
- private
86
-
87
- # rubocop:disable Metrics/AbcSize
88
-
89
- # Determines the banner options to be used for the notification banner
90
-
91
- def set_additional_options_for_banner
92
- banner_options = DEFAULT_OPTIONS.dup
93
-
94
- banner_options.merge!(SUCCESS_BANNER_OPTIONS) if success_banner
95
-
96
- options[:title_text] ||= banner_options[:title_text]
97
- options[:title_id] ||= banner_options[:title_id]
98
- options[:attributes][:role] ||= banner_options[:role]
99
- options[:attributes][:class] << banner_options[:classes].to_s
100
- (options[:attributes][:aria] ||= {})[:labelledby] = options[:title_id]
101
- end
102
-
103
- # rubocop:enable Metrics/AbcSize
104
- end
105
- end
106
- end
107
- end
@@ -1,44 +0,0 @@
1
- require_relative '../increment'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Pagination < Base
7
- class Increment < Base
8
- # = GOV.UK Pagination Next
9
- #
10
- # This generates the HTML for the pagination next link
11
-
12
- class Next < Increment
13
- # @param (see Increment#initialize)
14
- #
15
- # @option (see Increment#initialize)
16
-
17
- def initialize(text: 'Next', **options)
18
- super(type: :next, text: text, **options)
19
- end
20
-
21
- # Generates the HTML for the next link in the pagination
22
- #
23
- # @return [ActiveSupport::SafeBuffer]
24
-
25
- def render
26
- tag.div(class: 'govuk-pagination__next') do
27
- super() do
28
- concat(pagination_icon) if block_is_level
29
- concat(tag.span(text, class: pagination_text_classes))
30
- pagination_icon_label_text
31
- concat(pagination_icon) unless block_is_level
32
- end
33
- end
34
- end
35
-
36
- # The path for the pagination next icon
37
-
38
- PAGINATION_ICON_PATH = 'm8.107-0.0078125-1.4136 1.414 4.2926 4.293h-12.986v2h12.896l-4.1855 3.9766 1.377 1.4492 6.7441-6.4062-6.7246-6.7266z'.freeze
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
@@ -1,43 +0,0 @@
1
- require_relative '../increment'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Pagination < Base
7
- class Increment < Base
8
- # = GOV.UK Pagination Previous
9
- #
10
- # This generates the HTML for the pagination previous link
11
-
12
- class Previous < Increment
13
- # @param (see Increment#initialize)
14
- #
15
- # @option (see Increment#initialize)
16
-
17
- def initialize(text: 'Previous', **options)
18
- super(type: :prev, text: text, **options)
19
- end
20
-
21
- # Generates the HTML for the previous link in the pagination
22
- #
23
- # @return [ActiveSupport::SafeBuffer]
24
-
25
- def render
26
- tag.div(class: 'govuk-pagination__prev') do
27
- super() do
28
- concat(pagination_icon)
29
- concat(tag.span(text, class: pagination_text_classes))
30
- pagination_icon_label_text
31
- end
32
- end
33
- end
34
-
35
- # The path for the pagination previous icon
36
-
37
- PAGINATION_ICON_PATH = 'm6.5938-0.0078125-6.7266 6.7266 6.7441 6.4062 1.377-1.449-4.1856-3.9768h12.896v-2h-12.984l4.2931-4.293-1.414-1.414z'.freeze
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,98 +0,0 @@
1
- require_relative '../../base'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Pagination < Base
7
- # = GOV.UK Pagination Increment
8
- #
9
- # This generates the HTML for a pagination increment, that is {Previous} and {Next}
10
- #
11
- # @!attribute [r] type
12
- # @return [Symbol] The type of pagination increment
13
- # @!attribute [r] text
14
- # @return [String] Text for the pagination increment
15
- # @!attribute [r] block_is_level
16
- # @return [Boolean] Flag to indicate if previous and next blocks are level
17
- # @!attribute [r] label_text
18
- # @return [Boolean] Additional label text for when +block_is_level == true+
19
-
20
- class Increment < Base
21
- private
22
-
23
- attr_reader :type, :text, :block_is_level, :label_text
24
-
25
- public
26
-
27
- # @param type [Symbol] the type of increment, either +:prev+ or +:next+
28
- # @param text [String] the text for the pagination increment
29
- # @param block_is_level [Boolean] when there are no items, this will be true and will add extra classes
30
- # to the link to make the next and previous pagination links level
31
- # @param label_text [String] additional text for the link when the pagination block is level
32
- # @param options [Hash] options that will be used in customising the HTML
33
- #
34
- # @option options [String] :href the URL for the link
35
- # @option options [ActionView::Helpers::FormBuilder] :form optional form builder used to create the button
36
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
37
-
38
- def initialize(type:, text:, block_is_level:, label_text: nil, **options)
39
- super(**options)
40
-
41
- @options[:attributes][:class] = "govuk-link govuk-pagination__link #{'pagination--button_as_link' if @options[:form]}".rstrip
42
- @options[:attributes][:rel] = type.to_s
43
-
44
- @type = type
45
- @text = text
46
- @block_is_level = block_is_level
47
- @label_text = label_text
48
- end
49
-
50
- # Generates the HTML for the pagination increment link/button
51
- #
52
- # @yield the HTML for the increment button/link
53
- #
54
- # @return [ActiveSupport::SafeBuffer]
55
-
56
- def render(&block)
57
- if options[:form]
58
- options[:form].button(**options[:attributes], &block)
59
- else
60
- link_to(options[:href], **options[:attributes], &block)
61
- end
62
- end
63
-
64
- private
65
-
66
- # Returns the classes for the link/button label
67
- #
68
- # @return [String]
69
-
70
- def pagination_text_classes
71
- "govuk-pagination__link-title #{'govuk-pagination__link-title--decorated' if block_is_level && !label_text}".rstrip
72
- end
73
-
74
- # Generates the icon for the pagination increment
75
- #
76
- # @return [ActiveSupport::SafeBuffer]
77
-
78
- def pagination_icon
79
- tag.svg(class: "govuk-pagination__icon govuk-pagination__icon--#{type}", xmlns: 'http://www.w3.org/2000/svg', height: '13', width: '15', aria: { hidden: 'true' }, focusable: 'false', viewBox: '0 0 15 13') do
80
- tag.path(d: self.class::PAGINATION_ICON_PATH)
81
- end
82
- end
83
-
84
- # Generates the label text for when the block is level
85
- #
86
- # @return [ActiveSupport::SafeBuffer]
87
-
88
- def pagination_icon_label_text
89
- return unless block_is_level && label_text
90
-
91
- concat(tag.span(':', class: 'govuk-visually-hidden'))
92
- concat(tag.span(label_text, class: 'govuk-pagination__link-label'))
93
- end
94
- end
95
- end
96
- end
97
- end
98
- end
@@ -1,28 +0,0 @@
1
- require 'action_view'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Pagination < Base
7
- class Item < Base
8
- # = GOV.UK Pagination Item ellipsis
9
- #
10
- # This generates the HTML for a pagination ellipsis
11
-
12
- class Ellipsis
13
- extend ActionView::Context
14
- extend ActionView::Helpers
15
-
16
- # Generates the HTML for the GOV.UK Pagination Item ellipsis
17
- #
18
- # @return [ActiveSupport::SafeBuffer]
19
-
20
- def self.render
21
- tag.li('⋯', class: 'govuk-pagination__item govuk-pagination__item--ellipses')
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,49 +0,0 @@
1
- require_relative '../item'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Pagination < Base
7
- class Item < Base
8
- # = GOV.UK Pagination Item form
9
- #
10
- # This generates the HTML for the pagination item using a button tag
11
- #
12
- # @!attribute [r] form
13
- # @return [ActionView::Helpers::FormBuilder] Form builder used to create the button
14
-
15
- class Form < Item
16
- private
17
-
18
- attr_reader :form
19
-
20
- public
21
-
22
- # @param (see CCS::Components::GovUK::Pagination::Item)
23
- # @param form [ActionView::Helpers::FormBuilder] form builder used to create the button
24
- #
25
- # @option (see CCS::Components::GovUK::Pagination::Item)
26
-
27
- def initialize(form:, **options)
28
- super(**options)
29
-
30
- @options[:attributes][:class] << ' pagination-number--button_as_link'
31
-
32
- @form = form
33
- end
34
-
35
- # Generates the HTML for the GOV.UK Pagination item button
36
- #
37
- # @return [ActiveSupport::SafeBuffer]
38
-
39
- def render
40
- super() do
41
- form.button(number, **@options[:attributes])
42
- end
43
- end
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,47 +0,0 @@
1
- require_relative '../item'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Pagination < Base
7
- class Item < Base
8
- # = GOV.UK Pagination Item tag
9
- #
10
- # This generates the HTML for the pagination item using a link tag
11
- #
12
- # @!attribute [r] href
13
- # @return [String] URL for the pagination item
14
-
15
- class Tag < Item
16
- private
17
-
18
- attr_reader :href
19
-
20
- public
21
-
22
- # @param (see CCS::Components::GovUK::Pagination::Item)
23
- # @param href [String] the URL for the pagination item
24
- #
25
- # @option (see CCS::Components::GovUK::Pagination::Item)
26
-
27
- def initialize(href:, **options)
28
- super(**options)
29
-
30
- @href = href
31
- end
32
-
33
- # Generates the HTML for the GOV.UK Pagination item link
34
- #
35
- # @return [ActiveSupport::SafeBuffer]
36
-
37
- def render
38
- super() do
39
- link_to(number, href, **@options[:attributes])
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,64 +0,0 @@
1
- require_relative '../../base'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Pagination < Base
7
- # = GOV.UK Pagination Item
8
- #
9
- # This generates the HTML for the pagination item
10
- #
11
- # @!attribute [r] number
12
- # @return [String] The number for the item
13
- # @!attribute [r] li_classes
14
- # @return [String] HTML classes for pagination item +li+ element
15
-
16
- class Item < Base
17
- private
18
-
19
- attr_reader :number, :li_classes
20
-
21
- public
22
-
23
- # @param number [String] the number for the item
24
- # @param current [Boolean] flag to indicate if this item is the current page
25
- #
26
- # @option options [String] :classes additional CSS classes for the item HTML
27
- # @option options [Symbol] :type the type of item. If the value is +:ellipsis+ then an ellipsis will be rendered
28
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
29
-
30
- def initialize(number:, current: false, **options)
31
- super(**options)
32
-
33
- @number = number
34
-
35
- (@options[:attributes][:aria] ||= {})[:label] ||= "Page #{@number}"
36
-
37
- li_classes = 'govuk-pagination__item'
38
-
39
- if current
40
- li_classes << ' govuk-pagination__item--current'
41
- @options[:attributes][:aria][:current] = 'page'
42
- end
43
-
44
- @li_classes = li_classes
45
- end
46
-
47
- # Generates the HTML for the GOV.UK Pagination item
48
- #
49
- # @yield the HTML for the pagination item link/button
50
- #
51
- # @return [ActiveSupport::SafeBuffer]
52
-
53
- def render(&block)
54
- tag.li(class: li_classes, &block)
55
- end
56
-
57
- # The default attributes for the pagination link
58
-
59
- DEFAULT_ATTRIBUTES = { class: 'govuk-link govuk-pagination__link' }.freeze
60
- end
61
- end
62
- end
63
- end
64
- end
@@ -1,96 +0,0 @@
1
- require_relative '../base'
2
- require_relative 'pagination/increment/previous'
3
- require_relative 'pagination/increment/next'
4
- require_relative 'pagination/item/ellipsis'
5
- require_relative 'pagination/item/tag'
6
- require_relative 'pagination/item/form'
7
-
8
- module CCS
9
- module Components
10
- module GovUK
11
- # = GOV.UK Pagination
12
- #
13
- # This helper is used for generating the pagination component from the
14
- # {https://design-system.service.gov.uk/components/pagination GDS - Components - Pagination}
15
- #
16
- # @!attribute [r] pagination_previous
17
- # @return [Increment::Previous] Initialised pagination previous
18
- # @!attribute [r] pagination_items
19
- # @return [Array<Item::Ellipsis|Item::Tag|Item::Form>] An array of the initialised pagination items
20
- # @!attribute [r] pagination_next
21
- # @return [Increment::Next] Initialised pagination next
22
-
23
- class Pagination < Base
24
- private
25
-
26
- attr_reader :pagination_previous, :pagination_items, :pagination_next
27
-
28
- public
29
-
30
- # rubocop:disable Metrics/CyclomaticComplexity
31
-
32
- # @param pagination_previous [Hash] attributes for the pagination previous, see {CCS::Components::GovUK::Pagination::Increment::Previous#initialize Previous#initialize} for more details.
33
- # @param pagination_items [Array<Hash>] An array of options for the pagination items.
34
- # See {CCS::Components::GovUK::Pagination::Item::Tag#initialize Item::Tag#initialize} and
35
- # {CCS::Components::GovUK::Pagination::Item::Form#initialize Item::Form#initialize} for details of the items in the array.
36
- # @param pagination_next [Hash] attributes for the pagination next, see {CCS::Components::GovUK::Pagination::Increment::Next#initialize Next#initialize} for more details.
37
- # @param options [Hash] options that will be used in customising the HTML
38
- #
39
- # @option options [String] :classes additional CSS classes for the pagination HTML
40
- # @option options [ActionView::Helpers::FormBuilder] :form form builder used to create pagination buttons
41
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
42
-
43
- def initialize(pagination_previous: nil, pagination_items: nil, pagination_next: nil, **options)
44
- super(**options)
45
-
46
- block_is_level = pagination_items.blank? && (pagination_previous.present? || pagination_next.present?)
47
-
48
- @options[:attributes][:class] << ' govuk-pagination--block' if block_is_level
49
- @options[:attributes][:role] = 'navigation'
50
- (@options[:attributes][:aria] ||= {})[:label] ||= 'results'
51
-
52
- @pagination_previous = Increment::Previous.new(block_is_level: block_is_level, form: @options[:form], context: @context, **pagination_previous) if pagination_previous
53
- @pagination_next = Increment::Next.new(block_is_level: block_is_level, form: @options[:form], context: @context, **pagination_next) if pagination_next
54
- initialize_pagination_items(pagination_items, @options[:form])
55
- end
56
-
57
- # rubocop:enable Metrics/CyclomaticComplexity
58
-
59
- # Generates the HTML for the GOV.UK pagination component
60
- #
61
- # @return [ActiveSupport::SafeBuffer]
62
-
63
- def render
64
- tag.nav(**options[:attributes]) do
65
- concat(pagination_previous.render) if pagination_previous
66
- if pagination_items
67
- concat(tag.ul(class: 'govuk-pagination__list') do
68
- pagination_items.each { |pagination_item| concat(pagination_item.render) }
69
- end)
70
- end
71
- concat(pagination_next.render) if pagination_next
72
- end
73
- end
74
-
75
- # The default attributes for the pagination
76
-
77
- DEFAULT_ATTRIBUTES = { class: 'govuk-pagination' }.freeze
78
-
79
- private
80
-
81
- # Initialises the pagination items
82
- #
83
- # @param pagination_items [Array<Hash>] An array of options for the pagination items
84
- # @param form [ActionView::Helpers::FormBuilder] form builder used to create pagination buttons
85
-
86
- def initialize_pagination_items(pagination_items, form)
87
- return unless pagination_items
88
-
89
- pagination_item_class = form ? Item::Form : Item::Tag
90
-
91
- @pagination_items = pagination_items.map { |pagination_item| pagination_item[:type] == :ellipsis ? Item::Ellipsis : pagination_item_class.new(form: form, context: context, **pagination_item) }
92
- end
93
- end
94
- end
95
- end
96
- end
@@ -1,62 +0,0 @@
1
- require_relative '../base'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- # = GOV.UK Panel
7
- #
8
- # This is used to generate the panel component from the
9
- # {https://design-system.service.gov.uk/components/panel GDS - Components - Panel}
10
- #
11
- # @!attribute [r] title_text
12
- # @return [String] Text for the panel title
13
- # @!attribute [r] panel_text
14
- # @return [String] Text that will be used for the panel content
15
-
16
- class Panel < Base
17
- private
18
-
19
- attr_reader :title_text, :panel_text
20
-
21
- public
22
-
23
- # @param title_text [String] title text for the panel which will be contained in haeding tags
24
- # @param panel_text [String] text to use within the panel component.
25
- # If nil, then a block will be rendered
26
- # @param options [Hash] options that will be used in customising the HTML
27
- #
28
- # @option options [String] :classes additional CSS classes for the panel HTML
29
- # @option options [Integer,String] :heading_level (default: 1) heading level for the panel title text
30
- # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
31
-
32
- def initialize(title_text:, panel_text: nil, **options)
33
- super(**options)
34
-
35
- @title_text = title_text
36
- @panel_text = panel_text
37
- end
38
-
39
- # Generates the HTML for the GOV.UK Panel component
40
- #
41
- # @yield HTML that will be contained within the panel body. Ignored if panel text is given
42
- #
43
- # @return [ActiveSupport::SafeBuffer]
44
-
45
- def render
46
- tag.div(**options[:attributes]) do
47
- concat(tag.send(:"h#{options[:heading_level] || 1}", title_text, class: 'govuk-panel__title'))
48
- if panel_text || block_given?
49
- concat(tag.div(class: 'govuk-panel__body') do
50
- panel_text || yield
51
- end)
52
- end
53
- end
54
- end
55
-
56
- # The default attributes for the panel
57
-
58
- DEFAULT_ATTRIBUTES = { class: 'govuk-panel govuk-panel--confirmation' }.freeze
59
- end
60
- end
61
- end
62
- end