ccs-frontend_helpers 0.1.0 → 0.1.1.rc.1

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 +11 -2
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +4 -1
  5. data/Gemfile +15 -1
  6. data/Gemfile.lock +153 -114
  7. data/ccs-frontend_helpers.gemspec +1 -11
  8. data/lib/ccs/components/base.rb +64 -0
  9. data/lib/ccs/components/ccs/dashboard_section/panel.rb +57 -0
  10. data/lib/ccs/components/ccs/dashboard_section.rb +71 -0
  11. data/lib/ccs/components/ccs/footer/link.rb +55 -0
  12. data/lib/ccs/components/ccs/footer/meta.rb +59 -0
  13. data/lib/ccs/components/ccs/footer/navigation.rb +60 -0
  14. data/lib/ccs/components/ccs/footer.rb +95 -0
  15. data/lib/ccs/components/ccs/header/link.rb +60 -0
  16. data/lib/ccs/components/ccs/header/navigation.rb +98 -0
  17. data/lib/ccs/components/ccs/header/service_authentication.rb +53 -0
  18. data/lib/ccs/components/ccs/header.rb +110 -0
  19. data/lib/ccs/{frontend_helpers/ccs_frontend → components/ccs}/logo.rb +10 -12
  20. data/lib/ccs/components/govuk/accordion/section/content.rb +53 -0
  21. data/lib/ccs/components/govuk/accordion/section/header.rb +57 -0
  22. data/lib/ccs/components/govuk/accordion/section.rb +61 -0
  23. data/lib/ccs/components/govuk/accordion.rb +58 -0
  24. data/lib/ccs/components/govuk/back_link.rb +51 -0
  25. data/lib/ccs/components/govuk/breadcrumbs/link.rb +57 -0
  26. data/lib/ccs/components/govuk/breadcrumbs.rb +55 -0
  27. data/lib/ccs/components/govuk/button.rb +107 -0
  28. data/lib/ccs/components/govuk/cookie_banner/action.rb +60 -0
  29. data/lib/ccs/components/govuk/cookie_banner/message.rb +80 -0
  30. data/lib/ccs/components/govuk/cookie_banner.rb +55 -0
  31. data/lib/ccs/components/govuk/details.rb +53 -0
  32. data/lib/ccs/components/govuk/error_message.rb +60 -0
  33. data/lib/ccs/components/govuk/error_summary/item.rb +54 -0
  34. data/lib/ccs/components/govuk/error_summary.rb +70 -0
  35. data/lib/ccs/components/govuk/field/input/character_count.rb +129 -0
  36. data/lib/ccs/components/govuk/field/input/file_upload.rb +44 -0
  37. data/lib/ccs/components/govuk/field/input/select.rb +82 -0
  38. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +55 -0
  39. data/lib/ccs/components/govuk/field/input/text_input.rb +97 -0
  40. data/lib/ccs/components/govuk/field/input/textarea.rb +59 -0
  41. data/lib/ccs/components/govuk/field/input.rb +62 -0
  42. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +69 -0
  43. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +65 -0
  44. data/lib/ccs/components/govuk/field/inputs/date_input.rb +89 -0
  45. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +47 -0
  46. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +43 -0
  47. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +50 -0
  48. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +50 -0
  49. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +44 -0
  50. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +43 -0
  51. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +50 -0
  52. data/lib/ccs/components/govuk/field/inputs/item.rb +111 -0
  53. data/lib/ccs/components/govuk/field/inputs/radios.rb +69 -0
  54. data/lib/ccs/components/govuk/field/inputs.rb +57 -0
  55. data/lib/ccs/components/govuk/field.rb +108 -0
  56. data/lib/ccs/components/govuk/fieldset/legend.rb +65 -0
  57. data/lib/ccs/components/govuk/fieldset.rb +54 -0
  58. data/lib/ccs/components/govuk/footer/link.rb +55 -0
  59. data/lib/ccs/components/govuk/footer/meta.rb +59 -0
  60. data/lib/ccs/components/govuk/footer/navigation.rb +60 -0
  61. data/lib/ccs/components/govuk/footer.rb +131 -0
  62. data/lib/ccs/components/govuk/form_group.rb +60 -0
  63. data/lib/ccs/components/govuk/header/link.rb +56 -0
  64. data/lib/ccs/components/govuk/header/navigation.rb +71 -0
  65. data/lib/ccs/components/govuk/header.rb +107 -0
  66. data/lib/ccs/components/govuk/hint.rb +49 -0
  67. data/lib/ccs/components/govuk/inset_text.rb +52 -0
  68. data/lib/ccs/components/govuk/label.rb +85 -0
  69. data/lib/ccs/components/govuk/notification_banner.rb +107 -0
  70. data/lib/ccs/components/govuk/pagination/increment/next.rb +44 -0
  71. data/lib/ccs/components/govuk/pagination/increment/previous.rb +43 -0
  72. data/lib/ccs/components/govuk/pagination/increment.rb +98 -0
  73. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +28 -0
  74. data/lib/ccs/components/govuk/pagination/item/form.rb +49 -0
  75. data/lib/ccs/components/govuk/pagination/item/tag.rb +47 -0
  76. data/lib/ccs/components/govuk/pagination/item.rb +64 -0
  77. data/lib/ccs/components/govuk/pagination.rb +96 -0
  78. data/lib/ccs/components/govuk/panel.rb +62 -0
  79. data/lib/ccs/components/govuk/phase_banner.rb +69 -0
  80. data/lib/ccs/components/govuk/skip_link.rb +51 -0
  81. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +53 -0
  82. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +50 -0
  83. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +45 -0
  84. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +63 -0
  85. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +69 -0
  86. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +56 -0
  87. data/lib/ccs/components/govuk/step_by_step_navigation.rb +59 -0
  88. data/lib/ccs/components/govuk/summary_list/action/link.rb +59 -0
  89. data/lib/ccs/components/govuk/summary_list/card/actions.rb +59 -0
  90. data/lib/ccs/components/govuk/summary_list/card/title.rb +51 -0
  91. data/lib/ccs/components/govuk/summary_list/card.rb +63 -0
  92. data/lib/ccs/components/govuk/summary_list/row/actions.rb +59 -0
  93. data/lib/ccs/components/govuk/summary_list/row/key.rb +47 -0
  94. data/lib/ccs/components/govuk/summary_list/row/value.rb +47 -0
  95. data/lib/ccs/components/govuk/summary_list/row.rb +67 -0
  96. data/lib/ccs/components/govuk/summary_list.rb +74 -0
  97. data/lib/ccs/components/govuk/table/body/data_cell.rb +53 -0
  98. data/lib/ccs/components/govuk/table/body/head_cell.rb +52 -0
  99. data/lib/ccs/components/govuk/table/header/head_cell.rb +54 -0
  100. data/lib/ccs/components/govuk/table.rb +111 -0
  101. data/lib/ccs/components/govuk/tabs/panel.rb +58 -0
  102. data/lib/ccs/components/govuk/tabs/tab.rb +56 -0
  103. data/lib/ccs/components/govuk/tabs.rb +66 -0
  104. data/lib/ccs/components/govuk/tag.rb +51 -0
  105. data/lib/ccs/components/govuk/warning_text.rb +61 -0
  106. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +27 -0
  107. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +6 -119
  108. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +6 -183
  109. data/lib/ccs/frontend_helpers/ccs_frontend.rb +2 -4
  110. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +8 -95
  111. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +6 -17
  112. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +6 -54
  113. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +6 -105
  114. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +28 -0
  115. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +28 -0
  116. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +6 -114
  117. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +28 -0
  118. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +7 -23
  119. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +11 -32
  120. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +13 -65
  121. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +7 -48
  122. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +28 -0
  123. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +6 -161
  124. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +13 -24
  125. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +6 -139
  126. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +8 -17
  127. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +28 -0
  128. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +7 -21
  129. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +7 -70
  130. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +7 -113
  131. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +6 -314
  132. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +7 -28
  133. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +8 -27
  134. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +28 -0
  135. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +28 -0
  136. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +6 -18
  137. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +7 -186
  138. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +6 -204
  139. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +11 -100
  140. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +6 -73
  141. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +7 -21
  142. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +28 -0
  143. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +7 -30
  144. data/lib/ccs/frontend_helpers/govuk_frontend.rb +17 -19
  145. data/lib/ccs/frontend_helpers/version.rb +1 -1
  146. metadata +117 -147
  147. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +0 -79
  148. data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +0 -165
  149. data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +0 -200
  150. data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +0 -153
  151. data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +0 -83
  152. data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +0 -153
  153. data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +0 -201
  154. data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +0 -124
  155. data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +0 -106
  156. data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +0 -213
  157. data/lib/ccs/frontend_helpers/shared_methods.rb +0 -27
@@ -0,0 +1,63 @@
1
+ require_relative '../../base'
2
+ require_relative 'card/title'
3
+ require_relative 'card/actions'
4
+
5
+ module CCS
6
+ module Components
7
+ module GovUK
8
+ class SummaryList < Base
9
+ # = GOV.UK Summary card
10
+ #
11
+ # This is used for generating the summary cards component from the
12
+ # {https://design-system.service.gov.uk/components/summary-list/#summary-cards GDS - Components - Summary cards}
13
+ #
14
+ # @!attribute [r] title
15
+ # @return [Title] Initialised summary card title
16
+ # @!attribute [r] actions
17
+ # @return [Actions] Initialised summary card actions
18
+
19
+ class Card < Base
20
+ private
21
+
22
+ attr_reader :title, :actions
23
+
24
+ public
25
+
26
+ # @param title [Hash] attributes for the title, see {CCS::Components::GovUK::SummaryList::Card::Title#initialize Title#initialize} for more details.
27
+ # @param actions [Hash] attributes for the actions, see {CCS::Components::GovUK::SummaryList::Card::Actions#initialize Actions#initialize} for more details.
28
+ # @param options [Hash] options that will be used in customising the HTML
29
+ #
30
+ # @option options [String] :classes additional CSS classes for the summary card HTML
31
+ # @option options [Hash] :attributes any additional attributes that will be added as part of the HTML
32
+
33
+ def initialize(title: nil, actions: nil, **options)
34
+ super(**options)
35
+
36
+ @title = Title.new(context: @context, **title) if title
37
+ @actions = Actions.new(context: @context, **actions) if actions
38
+ end
39
+
40
+ # Generates the HTML for the GOV.UK Summary card
41
+ #
42
+ # @yield the HTML for the summary list
43
+ #
44
+ # @return [ActiveSupport::SafeBuffer]
45
+
46
+ def render(&block)
47
+ tag.div(**@options[:attributes]) do
48
+ concat(tag.div(class: 'govuk-summary-card__title-wrapper') do
49
+ concat(title.render) if title
50
+ concat(actions.render) if actions
51
+ end)
52
+ concat(tag.div(class: 'govuk-summary-card__content', &block))
53
+ end
54
+ end
55
+
56
+ # The default attributes for the summary card
57
+
58
+ DEFAULT_ATTRIBUTES = { class: 'govuk-summary-card' }.freeze
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,59 @@
1
+ require_relative '../../../base'
2
+ require_relative '../action/link'
3
+
4
+ module CCS
5
+ module Components
6
+ module GovUK
7
+ class SummaryList < Base
8
+ class Row < Base
9
+ # = GOV.UK Summary list row actions
10
+ #
11
+ # @!attribute [r] action_links
12
+ # @return [Array<Action::Link>] An array of the initialised aummary list row action links
13
+
14
+ class Actions < Base
15
+ private
16
+
17
+ attr_reader :action_links
18
+
19
+ public
20
+
21
+ # @param items [Array<Hash>] An array of attributes for the action links.
22
+ # See {Components::GovUK::SummaryList::Action::Link#initialize Action::Link#initialize} for details of the items in the array.
23
+ # @param options [Hash] options that will be used in customising the HTML
24
+ #
25
+ # @option options [String] :classes additional CSS classes for the summary list row actions HTML
26
+
27
+ def initialize(items:, **options)
28
+ super(**options)
29
+
30
+ @action_links = items.map { |item| Action::Link.new(context: @context, **item) }
31
+ end
32
+
33
+ # Generates the HTML for the GOV.UK Summary list row actions
34
+ #
35
+ # @return [ActiveSupport::SafeBuffer]
36
+
37
+ def render
38
+ tag.dd(class: @options[:attributes][:class]) do
39
+ if action_links.length == 1
40
+ action_links.first.render
41
+ else
42
+ tag.ul(class: 'govuk-summary-list__actions-list') do
43
+ action_links.each do |action_link|
44
+ concat(tag.li(action_link.render, class: 'govuk-summary-list__actions-list-item'))
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ # The default attributes for the summary list row actions
52
+
53
+ DEFAULT_ATTRIBUTES = { class: 'govuk-summary-list__actions' }.freeze
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,47 @@
1
+ require_relative '../../../base'
2
+
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ class SummaryList < Base
7
+ class Row < Base
8
+ # = GOV.UK Summary list row key
9
+ #
10
+ # @!attribute [r] text
11
+ # @return [String] Text for the summary list row key
12
+
13
+ class Key < Base
14
+ private
15
+
16
+ attr_reader :text
17
+
18
+ public
19
+
20
+ # @param text [String] Text for the summary list row key
21
+ # @param options [Hash] options that will be used in customising the HTML
22
+ #
23
+ # @option options [String] :classes additional CSS classes for the summary list row key HTML
24
+
25
+ def initialize(text:, **options)
26
+ super(**options)
27
+
28
+ @text = text
29
+ end
30
+
31
+ # Generates the HTML for the GOV.UK Summary list row key
32
+ #
33
+ # @return [ActiveSupport::SafeBuffer]
34
+
35
+ def render
36
+ tag.dt(text, class: @options[:attributes][:class])
37
+ end
38
+
39
+ # The default attributes for the summary list row key
40
+
41
+ DEFAULT_ATTRIBUTES = { class: 'govuk-summary-list__key' }.freeze
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,47 @@
1
+ require_relative '../../../base'
2
+
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ class SummaryList < Base
7
+ class Row < Base
8
+ # = GOV.UK Summary list row value
9
+ #
10
+ # @!attribute [r] text
11
+ # @return [String] Text for the summary list row value
12
+
13
+ class Value < Base
14
+ private
15
+
16
+ attr_reader :text
17
+
18
+ public
19
+
20
+ # @param text [String] Text for the summary list row value
21
+ # @param options [Hash] options that will be used in customising the HTML
22
+ #
23
+ # @option options [String] :classes additional CSS classes for the summary list row value HTML
24
+
25
+ def initialize(text:, **options)
26
+ super(**options)
27
+
28
+ @text = text
29
+ end
30
+
31
+ # Generates the HTML for the GOV.UK Summary list row value
32
+ #
33
+ # @return [ActiveSupport::SafeBuffer]
34
+
35
+ def render
36
+ tag.dd(text, class: @options[:attributes][:class])
37
+ end
38
+
39
+ # The default attributes for the summary list row value
40
+
41
+ DEFAULT_ATTRIBUTES = { class: 'govuk-summary-list__value' }.freeze
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,67 @@
1
+ require_relative '../../base'
2
+ require_relative 'row/key'
3
+ require_relative 'row/value'
4
+ require_relative 'row/actions'
5
+
6
+ module CCS
7
+ module Components
8
+ module GovUK
9
+ class SummaryList < Base
10
+ # = GOV.UK Summary list row
11
+ #
12
+ # Generates the HTML for a summary list row
13
+ #
14
+ # @!attribute [r] key
15
+ # @return [Key] Initialised summary list cell for the key
16
+ # @!attribute [r] value
17
+ # @return [Value] Initialised summary list cell for the value
18
+ # @!attribute [r] actions
19
+ # @return [Actions] Initialised summary list cell for the actions
20
+
21
+ class Row < Base
22
+ private
23
+
24
+ attr_reader :key, :value, :actions
25
+
26
+ public
27
+
28
+ # @param any_row_has_actions [Boolean] flag to indicate if any rows have actions
29
+ # @param key [Hash] attributes for the key, see {CCS::Components::GovUK::SummaryList::Row::Key#initialize Key#initialize} for more details.
30
+ # @param value [Hash] attributes for the value, see {CCS::Components::GovUK::SummaryList::Row::Value#initialize Value#initialize} for more details.
31
+ # @param actions [Hash] attributes for the actions, see {CCS::Components::GovUK::SummaryList::Row::Actions#initialize Actions#initialize} for more details.
32
+ # @param options [Hash] options that will be used in customising the HTML
33
+ #
34
+ # @option options [String] :classes additional CSS classes for the summary list row HTML
35
+
36
+ def initialize(any_row_has_actions:, key:, value:, actions: nil, **options)
37
+ super(**options)
38
+
39
+ actions_present = actions && actions[:items].present?
40
+
41
+ @options[:attributes][:class] << ' govuk-summary-list__row--no-actions' if any_row_has_actions && !actions_present
42
+
43
+ @key = Key.new(context: @context, **key)
44
+ @value = Value.new(context: @context, **value)
45
+ @actions = Actions.new(context: @context, **actions) if actions_present
46
+ end
47
+
48
+ # Generates the HTML for the GOV.UK Summary list row
49
+ #
50
+ # @return [ActiveSupport::SafeBuffer]
51
+
52
+ def render
53
+ tag.div(class: options[:attributes][:class]) do
54
+ concat(key.render)
55
+ concat(value.render)
56
+ concat(actions.render) if actions
57
+ end
58
+ end
59
+
60
+ # The default attributes for the summary list row
61
+
62
+ DEFAULT_ATTRIBUTES = { class: 'govuk-summary-list__row' }.freeze
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,74 @@
1
+ require_relative '../base'
2
+ require_relative 'summary_list/row'
3
+ require_relative 'summary_list/card'
4
+
5
+ module CCS
6
+ module Components
7
+ module GovUK
8
+ # = GOV.UK Summary list
9
+ #
10
+ # This is used for generating the summary list component from the
11
+ # {https://design-system.service.gov.uk/components/summary-list GDS - Components - Summary list}
12
+ #
13
+ # @!attribute [r] summary_list_rows
14
+ # @return [Array<Row>] An array of the initialised summary list rows
15
+ # @!attribute [r] card
16
+ # @return [Card] Initialised summary list card
17
+
18
+ class SummaryList < Base
19
+ private
20
+
21
+ attr_reader :summary_list_rows, :card
22
+
23
+ public
24
+
25
+ # @param summary_list_items [Array<Hash>] An array of options for the summary list rows.
26
+ # See {Components::GovUK::SummaryList::Row#initialize Row#initialize} for details of the items in the array.
27
+ # @param card [Hash] attributes for the card, see {CCS::Components::GovUK::SummaryList::Card#initialize Card#initialize} for more details.
28
+ # @param options [Hash] options that will be used in customising the HTML
29
+ #
30
+ # @option options [String] :classes additional CSS classes for the summary list HTML
31
+ # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
32
+
33
+ def initialize(summary_list_items:, card: nil, **options)
34
+ super(**options)
35
+
36
+ any_row_has_actions = summary_list_items.any? { |summary_list_item| summary_list_item.dig(:actions, :items).present? }
37
+
38
+ @summary_list_rows = summary_list_items.map { |summary_list_item| Row.new(any_row_has_actions: any_row_has_actions, context: @context, **summary_list_item) }
39
+ @card = Card.new(context: @context, **card) if card
40
+ end
41
+
42
+ # Generates the HTML for the GOV.UK Summary list component
43
+ #
44
+ # @return [ActiveSupport::SafeBuffer]
45
+
46
+ def render
47
+ if card
48
+ card.render do
49
+ render_summary_list
50
+ end
51
+ else
52
+ render_summary_list
53
+ end
54
+ end
55
+
56
+ # The default attributes for the summary list
57
+
58
+ DEFAULT_ATTRIBUTES = { class: 'govuk-summary-list' }.freeze
59
+
60
+ private
61
+
62
+ # Generates the HTML for the actual summary list
63
+ #
64
+ # @return [ActiveSupport::SafeBuffer]
65
+
66
+ def render_summary_list
67
+ tag.dl(**options[:attributes]) do
68
+ summary_list_rows.each { |summary_list_row| concat(summary_list_row.render) }
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,53 @@
1
+ require_relative '../../../base'
2
+
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ class Table < Base
7
+ class Body
8
+ # = GOV.UK Table Body data cell
9
+ #
10
+ # The individual table body data cell
11
+ #
12
+ # @!attribute [r] text
13
+ # @return [String] Text for the cell
14
+
15
+ class DataCell < Base
16
+ private
17
+
18
+ attr_reader :text
19
+
20
+ public
21
+
22
+ # @param text [String] the text of the cell
23
+ # @param options [Hash] options that will be used in customising the HTML
24
+ #
25
+ # @option options [String] :classes additional CSS classes for the cell
26
+ # @option options [String] :format specify format of a cell
27
+ # @option options [Hash] :attributes ({}) any additional attributes that will be added as part of the cell
28
+
29
+ def initialize(text:, **options)
30
+ super(**options)
31
+
32
+ @options[:attributes][:class] += " govuk-table__cell--#{@options[:format]}" if @options[:format]
33
+
34
+ @text = text
35
+ end
36
+
37
+ # Generates the HTML for the GOV.UK Table Body data cell
38
+ #
39
+ # @return [ActiveSupport::SafeBuffer]
40
+
41
+ def render
42
+ tag.td(text, **options[:attributes])
43
+ end
44
+
45
+ # The default attributes for the table body data cell
46
+
47
+ DEFAULT_ATTRIBUTES = { class: 'govuk-table__cell' }.freeze
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,52 @@
1
+ require_relative '../../../base'
2
+
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ class Table < Base
7
+ class Body
8
+ # = GOV.UK Table Body head cell
9
+ #
10
+ # The individual table body head cell
11
+ #
12
+ # @!attribute [r] text
13
+ # @return [String] Text for the cell
14
+
15
+ class HeadCell < Base
16
+ private
17
+
18
+ attr_reader :text
19
+
20
+ public
21
+
22
+ # @param text [String] the text of the cell
23
+ # @param options [Hash] options that will be used in customising the HTML
24
+ #
25
+ # @option options [String] :classes additional CSS classes for the cell
26
+ # @option options [Hash] :attributes ({}) any additional attributes that will be added as part of the cell
27
+
28
+ def initialize(text:, **options)
29
+ super(**options)
30
+
31
+ @options[:attributes][:scope] = 'row'
32
+
33
+ @text = text
34
+ end
35
+
36
+ # Generates the HTML for the GOV.UK Table Body head cell
37
+ #
38
+ # @return [ActiveSupport::SafeBuffer]
39
+
40
+ def render
41
+ tag.th(text, **options[:attributes])
42
+ end
43
+
44
+ # The default attributes for the table body head cell
45
+
46
+ DEFAULT_ATTRIBUTES = { class: 'govuk-table__header' }.freeze
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,54 @@
1
+ require_relative '../../../base'
2
+
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ class Table < Base
7
+ class Header
8
+ # = GOV.UK Table Header head cell
9
+ #
10
+ # The individual table header head cell
11
+ #
12
+ # @!attribute [r] text
13
+ # @return [String] Text for the cell
14
+
15
+ class HeadCell < Base
16
+ private
17
+
18
+ attr_reader :text
19
+
20
+ public
21
+
22
+ # @param text [String] the text of the cell
23
+ # @param options [Hash] options that will be used in customising the HTML
24
+ #
25
+ # @option options [String] :classes additional CSS classes for the cell
26
+ # @option options [String] :format specify format of a cell
27
+ # @option options [Hash] :attributes ({}) any additional attributes that will be added as part of the cell
28
+
29
+ def initialize(text:, **options)
30
+ super(**options)
31
+
32
+ @options[:attributes][:class] += " govuk-table__header--#{@options[:format]}" if @options[:format]
33
+ @options[:attributes][:scope] = 'col'
34
+
35
+ @text = text
36
+ end
37
+
38
+ # Generates the HTML for the GOV.UK Table Header head cell
39
+ #
40
+ # @return [ActiveSupport::SafeBuffer]
41
+
42
+ def render
43
+ tag.th(text, **options[:attributes])
44
+ end
45
+
46
+ # The default attributes for the table header head cell
47
+
48
+ DEFAULT_ATTRIBUTES = { class: 'govuk-table__header' }.freeze
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,111 @@
1
+ require_relative '../base'
2
+ require_relative 'table/body/data_cell'
3
+ require_relative 'table/body/head_cell'
4
+ require_relative 'table/header/head_cell'
5
+
6
+ module CCS
7
+ module Components
8
+ module GovUK
9
+ # = GOV.UK Table
10
+ #
11
+ # This is used to generate the table component from the
12
+ # {https://design-system.service.gov.uk/components/table GDS - Components - Table}
13
+ #
14
+ # @!attribute [r] rows
15
+ # @return [Array<Array<Body::HeadCell|Body::DataCell>>] Arrays of the initialised row cells
16
+ # @!attribute [r] head_cells
17
+ # @return [Array<Header::HeadCell>] an array of the initialised header cells
18
+ # @!attribute [r] caption
19
+ # @return [Hash] options for the caption
20
+
21
+ class Table < Base
22
+ private
23
+
24
+ attr_reader :rows, :head_cells, :caption
25
+
26
+ public
27
+
28
+ # @param rows [Array<Array<Hash>>] array of table rows and cells.
29
+ # See {Components::GovUK::Table::Body::HeadCell#initialize Body::HeadCell#initialize}
30
+ # or {Components::GovUK::Table::Body::DataCell#initialize Body::DataCell#initialize} for details of the items in the array.
31
+ # @param head_cells [NilClass,Array] array of table head cells.
32
+ # See {Components::GovUK::Table::Header::HeadCell#initialize Header::HeadCell#initialize} for details of the items in the array.
33
+ # @param caption [NilClass,Hash] options for a table caption
34
+ # @param first_cell_is_header [Boolean] if set to true, first cell in table row will be a TH instead of a TD
35
+ # @param options [Hash] options that will be used in customising the HTML
36
+ #
37
+ # @option caption [String] :text the caption text
38
+ # @option caption [String] :classes additional CSS classes for the table caption
39
+ #
40
+ # @option options [String] :classes additional CSS classes for the table HTML
41
+ # @option options [Hash] :attributes ({}) any additional attributes that will be added as part of the HTML
42
+
43
+ def initialize(rows:, head_cells: nil, caption: nil, first_cell_is_header: nil, **options)
44
+ super(**options)
45
+
46
+ @rows = rows.map do |row_cells|
47
+ row_cells.map.with_index do |row_cell, index|
48
+ if first_cell_is_header && index.zero?
49
+ Body::HeadCell.new(context: @context, **row_cell)
50
+ else
51
+ Body::DataCell.new(context: @context, **row_cell)
52
+ end
53
+ end
54
+ end
55
+ @head_cells = head_cells&.map { |head_cell| Header::HeadCell.new(context: @context, **head_cell) }
56
+ @caption = caption
57
+ end
58
+
59
+ # Generates the HTML for the GOV.UK table component
60
+ #
61
+ # @return [ActiveSupport::SafeBuffer]
62
+
63
+ def render
64
+ tag.table(**options[:attributes]) do
65
+ concat(table_caption) if caption
66
+ concat(table_head) if head_cells
67
+ concat(tag.tbody(class: 'govuk-table__body') do
68
+ rows.each { |row_cells| concat(table_row(row_cells)) }
69
+ end)
70
+ end
71
+ end
72
+
73
+ # The default attributes for the table
74
+
75
+ DEFAULT_ATTRIBUTES = { class: 'govuk-table' }.freeze
76
+
77
+ private
78
+
79
+ # Generates the HTML for the the table caption
80
+ #
81
+ # @return [ActiveSupport::SafeBuffer]
82
+
83
+ def table_caption
84
+ tag.caption(caption[:text], class: "govuk-table__caption #{caption[:classes]}".rstrip)
85
+ end
86
+
87
+ # Generates the HTML for the table head
88
+ #
89
+ # @return [ActiveSupport::SafeBuffer]
90
+
91
+ def table_head
92
+ tag.thead(class: 'govuk-table__head') do
93
+ tag.tr(class: 'govuk-table__row') do
94
+ head_cells.each { |head_cell| concat(head_cell.render) }
95
+ end
96
+ end
97
+ end
98
+
99
+ # Generates the HTML for a table row
100
+ #
101
+ # @return [ActiveSupport::SafeBuffer]
102
+
103
+ def table_row(row_cells)
104
+ tag.tr(class: 'govuk-table__row') do
105
+ row_cells.each { |row_cell| concat(row_cell.render) }
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,58 @@
1
+ require_relative '../../base'
2
+
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ class Tabs < Base
7
+ # = GOV.UK Tabs panel
8
+ #
9
+ # The individual tab panels
10
+ #
11
+ # @!attribute [r] index
12
+ # @return [Integer] The index of the panel
13
+ # @!attribute [r] id_prefix
14
+ # @return [String] Prefix id for the panel
15
+ # @!attribute [r] content
16
+ # @return [ActiveSupport::SafeBuffer] HTML for the tab panel
17
+ # @!attribute [r] text
18
+ # @return [String] Text for the tabs panel
19
+
20
+ class Panel < Base
21
+ private
22
+
23
+ attr_reader :index, :id_prefix, :content, :text
24
+
25
+ public
26
+
27
+ # @param index [Integer] the index of the tab panel
28
+ # @param id_prefix [Integer] prefix used for the id of a panel if no id is specified
29
+ # @param content [ActiveSupport::SafeBuffer] HTML to use as content for the tab panel
30
+ # @param text [String] if +:content+ is blank then this is the text used for the tab panel
31
+ # @param options [Hash] options that will be used in customising the HTML
32
+ #
33
+ # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
34
+
35
+ def initialize(index:, id_prefix:, content: nil, text: nil, **options)
36
+ super(**options)
37
+ @options[:attributes][:class] = "govuk-tabs__panel #{'govuk-tabs__panel--hidden' if index > 1}".rstrip
38
+ @options[:attributes][:id] ||= "#{id_prefix}-#{index}"
39
+
40
+ @index = index
41
+ @content = content
42
+ @text = text
43
+ end
44
+
45
+ # Generates the HTML for the GOV.UK Tabs panel
46
+ #
47
+ # @return [ActiveSupport::SafeBuffer]
48
+
49
+ def render
50
+ tag.div(**options[:attributes]) do
51
+ content || tag.p(text, class: 'govuk-body')
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end