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,63 +0,0 @@
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
@@ -1,59 +0,0 @@
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
@@ -1,47 +0,0 @@
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
@@ -1,47 +0,0 @@
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
@@ -1,67 +0,0 @@
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
@@ -1,74 +0,0 @@
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
@@ -1,53 +0,0 @@
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
@@ -1,52 +0,0 @@
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
@@ -1,54 +0,0 @@
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
@@ -1,111 +0,0 @@
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
@@ -1,58 +0,0 @@
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