ccs-frontend_helpers 0.1.0.rc.2 → 0.1.0.rc.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -1
  3. data/Gemfile.lock +1 -1
  4. data/lib/ccs/components/ccs/dashboard_section/panel.rb +43 -41
  5. data/lib/ccs/components/ccs/dashboard_section.rb +50 -48
  6. data/lib/ccs/components/ccs/footer/link.rb +41 -39
  7. data/lib/ccs/components/ccs/footer/meta.rb +49 -48
  8. data/lib/ccs/components/ccs/footer/navigation.rb +51 -50
  9. data/lib/ccs/components/ccs/footer.rb +69 -67
  10. data/lib/ccs/components/ccs/header/link.rb +47 -45
  11. data/lib/ccs/components/ccs/header/navigation.rb +85 -84
  12. data/lib/ccs/components/ccs/header/service_authentication.rb +35 -34
  13. data/lib/ccs/components/ccs/header.rb +87 -85
  14. data/lib/ccs/components/ccs/logo.rb +36 -34
  15. data/lib/ccs/components/govuk/accordion/section/content.rb +42 -42
  16. data/lib/ccs/components/govuk/accordion/section/header.rb +48 -48
  17. data/lib/ccs/components/govuk/accordion/section.rb +49 -48
  18. data/lib/ccs/components/govuk/accordion.rb +43 -41
  19. data/lib/ccs/components/govuk/back_link.rb +39 -37
  20. data/lib/ccs/components/govuk/breadcrumbs/link.rb +42 -40
  21. data/lib/ccs/components/govuk/breadcrumbs.rb +40 -38
  22. data/lib/ccs/components/govuk/button.rb +83 -81
  23. data/lib/ccs/components/govuk/cookie_banner/action.rb +45 -43
  24. data/lib/ccs/components/govuk/cookie_banner/message.rb +57 -55
  25. data/lib/ccs/components/govuk/cookie_banner.rb +40 -38
  26. data/lib/ccs/components/govuk/details.rb +38 -36
  27. data/lib/ccs/components/govuk/error_message.rb +46 -44
  28. data/lib/ccs/components/govuk/error_summary/item.rb +41 -39
  29. data/lib/ccs/components/govuk/error_summary.rb +49 -47
  30. data/lib/ccs/components/govuk/field/input/character_count.rb +101 -99
  31. data/lib/ccs/components/govuk/field/input/file_upload.rb +29 -27
  32. data/lib/ccs/components/govuk/field/input/select.rb +61 -59
  33. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +39 -37
  34. data/lib/ccs/components/govuk/field/input/text_input.rb +75 -73
  35. data/lib/ccs/components/govuk/field/input/textarea.rb +43 -41
  36. data/lib/ccs/components/govuk/field/input.rb +46 -44
  37. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +43 -41
  38. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +48 -46
  39. data/lib/ccs/components/govuk/field/inputs/date_input.rb +68 -66
  40. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +29 -27
  41. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +26 -24
  42. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +32 -30
  43. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +39 -37
  44. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +27 -25
  45. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +26 -24
  46. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +32 -30
  47. data/lib/ccs/components/govuk/field/inputs/item.rb +100 -98
  48. data/lib/ccs/components/govuk/field/inputs/radios.rb +43 -41
  49. data/lib/ccs/components/govuk/field/inputs.rb +42 -40
  50. data/lib/ccs/components/govuk/field.rb +90 -88
  51. data/lib/ccs/components/govuk/fieldset/legend.rb +50 -48
  52. data/lib/ccs/components/govuk/fieldset.rb +40 -38
  53. data/lib/ccs/components/govuk/footer/link.rb +41 -39
  54. data/lib/ccs/components/govuk/footer/meta.rb +49 -48
  55. data/lib/ccs/components/govuk/footer/navigation.rb +51 -50
  56. data/lib/ccs/components/govuk/footer.rb +105 -103
  57. data/lib/ccs/components/govuk/form_group.rb +45 -43
  58. data/lib/ccs/components/govuk/header/link.rb +41 -39
  59. data/lib/ccs/components/govuk/header/navigation.rb +54 -53
  60. data/lib/ccs/components/govuk/header.rb +84 -82
  61. data/lib/ccs/components/govuk/hint.rb +33 -31
  62. data/lib/ccs/components/govuk/inset_text.rb +39 -37
  63. data/lib/ccs/components/govuk/label.rb +61 -59
  64. data/lib/ccs/components/govuk/notification_banner.rb +83 -81
  65. data/lib/ccs/components/govuk/pagination/increment/next.rb +29 -27
  66. data/lib/ccs/components/govuk/pagination/increment/previous.rb +28 -26
  67. data/lib/ccs/components/govuk/pagination/increment.rb +78 -76
  68. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +17 -15
  69. data/lib/ccs/components/govuk/pagination/item/form.rb +34 -32
  70. data/lib/ccs/components/govuk/pagination/item/tag.rb +33 -31
  71. data/lib/ccs/components/govuk/pagination/item.rb +47 -45
  72. data/lib/ccs/components/govuk/pagination.rb +69 -67
  73. data/lib/ccs/components/govuk/panel.rb +49 -47
  74. data/lib/ccs/components/govuk/phase_banner.rb +50 -48
  75. data/lib/ccs/components/govuk/skip_link.rb +39 -37
  76. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +40 -38
  77. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +30 -28
  78. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +28 -26
  79. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +47 -45
  80. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +49 -47
  81. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +44 -42
  82. data/lib/ccs/components/govuk/step_by_step_navigation.rb +41 -39
  83. data/lib/ccs/components/govuk/summary_list/action/link.rb +46 -44
  84. data/lib/ccs/components/govuk/summary_list/card/actions.rb +38 -36
  85. data/lib/ccs/components/govuk/summary_list/card/title.rb +37 -35
  86. data/lib/ccs/components/govuk/summary_list/card.rb +48 -46
  87. data/lib/ccs/components/govuk/summary_list/row/actions.rb +38 -36
  88. data/lib/ccs/components/govuk/summary_list/row/key.rb +30 -28
  89. data/lib/ccs/components/govuk/summary_list/row/value.rb +30 -28
  90. data/lib/ccs/components/govuk/summary_list/row.rb +47 -45
  91. data/lib/ccs/components/govuk/summary_list.rb +48 -46
  92. data/lib/ccs/components/govuk/table/body/data_cell.rb +38 -36
  93. data/lib/ccs/components/govuk/table/body/head_cell.rb +37 -35
  94. data/lib/ccs/components/govuk/table/header/head_cell.rb +39 -37
  95. data/lib/ccs/components/govuk/table.rb +83 -81
  96. data/lib/ccs/components/govuk/tabs/panel.rb +47 -45
  97. data/lib/ccs/components/govuk/tabs/tab.rb +42 -40
  98. data/lib/ccs/components/govuk/tabs.rb +48 -46
  99. data/lib/ccs/components/govuk/tag.rb +39 -37
  100. data/lib/ccs/components/govuk/warning_text.rb +49 -47
  101. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +16 -14
  102. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +17 -15
  103. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +17 -15
  104. data/lib/ccs/frontend_helpers/ccs_frontend.rb +1 -1
  105. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +17 -15
  106. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -15
  107. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +17 -15
  108. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +17 -15
  109. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +17 -15
  110. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +17 -15
  111. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +17 -15
  112. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +17 -15
  113. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +19 -17
  114. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -30
  115. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +38 -36
  116. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +19 -17
  117. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +17 -15
  118. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +17 -15
  119. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +27 -25
  120. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +17 -15
  121. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +18 -16
  122. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +17 -15
  123. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +19 -17
  124. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +18 -16
  125. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +19 -17
  126. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +17 -15
  127. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +19 -17
  128. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +19 -17
  129. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +17 -15
  130. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +17 -15
  131. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +17 -15
  132. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +24 -22
  133. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +17 -15
  134. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +17 -15
  135. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +17 -15
  136. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +17 -15
  137. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +17 -15
  138. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +19 -17
  139. data/lib/ccs/frontend_helpers/version.rb +1 -1
  140. metadata +2 -2
@@ -3,105 +3,107 @@ require_relative 'table/body/data_cell'
3
3
  require_relative 'table/body/head_cell'
4
4
  require_relative 'table/header/head_cell'
5
5
 
6
- module CCS::Components
7
- module GovUK
8
- # = GOV.UK Table
9
- #
10
- # This is used to generate the table component from the
11
- # {https://design-system.service.gov.uk/components/table GDS - Components - Table}
12
- #
13
- # @!attribute [r] rows
14
- # @return [Array<Array<Body::HeadCell|Body::DataCell>>] Arrays of the initialised row cells
15
- # @!attribute [r] head_cells
16
- # @return [Array<Header::HeadCell>] an array of the initialised header cells
17
- # @!attribute [r] caption
18
- # @return [Hash] options for the caption
19
-
20
- class Table < Base
21
- private
22
-
23
- attr_reader :rows, :head_cells, :caption
24
-
25
- public
26
-
27
- # @param rows [Array<Array<Hash>>] array of table rows and cells.
28
- # See {Components::GovUK::Table::Body::HeadCell#initialize Body::HeadCell#initialize}
29
- # or {Components::GovUK::Table::Body::DataCell#initialize Body::DataCell#initialize} for details of the items in the array.
30
- # @param head_cells [NilClass,Array] array of table head cells.
31
- # See {Components::GovUK::Table::Header::HeadCell#initialize Header::HeadCell#initialize} for details of the items in the array.
32
- # @param caption [NilClass,Hash] options for a table caption
33
- # @param first_cell_is_header [Boolean] if set to true, first cell in table row will be a TH instead of a TD
34
- # @param options [Hash] options that will be used in customising the HTML
6
+ module CCS
7
+ module Components
8
+ module GovUK
9
+ # = GOV.UK Table
35
10
  #
36
- # @option caption [String] :text the caption text
37
- # @option caption [String] :classes additional CSS classes for the table caption
11
+ # This is used to generate the table component from the
12
+ # {https://design-system.service.gov.uk/components/table GDS - Components - Table}
38
13
  #
39
- # @option options [String] :classes additional CSS classes for the table HTML
40
- # @option options [Hash] :attributes ({}) any additional attributes that will be added as part of the HTML
41
-
42
- def initialize(rows:, head_cells: nil, caption: nil, first_cell_is_header: nil, **options)
43
- super(**options)
44
-
45
- @rows = rows.map do |row_cells|
46
- row_cells.map.with_index do |row_cell, index|
47
- if first_cell_is_header && index.zero?
48
- Body::HeadCell.new(context: @context, **row_cell)
49
- else
50
- Body::DataCell.new(context: @context, **row_cell)
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
51
53
  end
52
54
  end
55
+ @head_cells = head_cells&.map { |head_cell| Header::HeadCell.new(context: @context, **head_cell) }
56
+ @caption = caption
53
57
  end
54
- @head_cells = head_cells&.map { |head_cell| Header::HeadCell.new(context: @context, **head_cell) }
55
- @caption = caption
56
- end
57
58
 
58
- # Generates the HTML for the GOV.UK table component
59
- #
60
- # @return [ActiveSupport::SafeBuffer]
61
-
62
- def render
63
- tag.table(**options[:attributes]) do
64
- concat(table_caption) if caption
65
- concat(table_head) if head_cells
66
- concat(tag.tbody(class: 'govuk-table__body') do
67
- rows.each { |row_cells| concat(table_row(row_cells)) }
68
- end)
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
69
71
  end
70
- end
71
72
 
72
- # The default attributes for the table
73
+ # The default attributes for the table
73
74
 
74
- DEFAULT_ATTRIBUTES = { class: 'govuk-table' }.freeze
75
+ DEFAULT_ATTRIBUTES = { class: 'govuk-table' }.freeze
75
76
 
76
- private
77
+ private
77
78
 
78
- # Generates the HTML for the the table caption
79
- #
80
- # @return [ActiveSupport::SafeBuffer]
79
+ # Generates the HTML for the the table caption
80
+ #
81
+ # @return [ActiveSupport::SafeBuffer]
81
82
 
82
- def table_caption
83
- tag.caption(caption[:text], class: "govuk-table__caption #{caption[:classes]}".rstrip)
84
- end
83
+ def table_caption
84
+ tag.caption(caption[:text], class: "govuk-table__caption #{caption[:classes]}".rstrip)
85
+ end
85
86
 
86
- # Generates the HTML for the table head
87
- #
88
- # @return [ActiveSupport::SafeBuffer]
87
+ # Generates the HTML for the table head
88
+ #
89
+ # @return [ActiveSupport::SafeBuffer]
89
90
 
90
- def table_head
91
- tag.thead(class: 'govuk-table__head') do
92
- tag.tr(class: 'govuk-table__row') do
93
- head_cells.each { |head_cell| concat(head_cell.render) }
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
94
96
  end
95
97
  end
96
- end
97
98
 
98
- # Generates the HTML for a table row
99
- #
100
- # @return [ActiveSupport::SafeBuffer]
99
+ # Generates the HTML for a table row
100
+ #
101
+ # @return [ActiveSupport::SafeBuffer]
101
102
 
102
- def table_row(row_cells)
103
- tag.tr(class: 'govuk-table__row') do
104
- row_cells.each { |row_cell| concat(row_cell.render) }
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
105
107
  end
106
108
  end
107
109
  end
@@ -1,53 +1,55 @@
1
1
  require_relative '../../base'
2
2
 
3
- module CCS::Components
4
- module GovUK
5
- class Tabs < Base
6
- # = GOV.UK Tabs panel
7
- #
8
- # The individual tab panels
9
- #
10
- # @!attribute [r] index
11
- # @return [Integer] The index of the panel
12
- # @!attribute [r] id_prefix
13
- # @return [String] Prefix id for the panel
14
- # @!attribute [r] content
15
- # @return [ActiveSupport::SafeBuffer] HTML for the tab panel
16
- # @!attribute [r] text
17
- # @return [String] Text for the tabs panel
18
-
19
- class Panel < Base
20
- private
21
-
22
- attr_reader :index, :id_prefix, :content, :text
23
-
24
- public
25
-
26
- # @param index [Integer] the index of the tab panel
27
- # @param id_prefix [Integer] prefix used for the id of a panel if no id is specified
28
- # @param content [ActiveSupport::SafeBuffer] HTML to use as content for the tab panel
29
- # @param text [String] if +:content+ is blank then this is the text used for the tab panel
30
- # @param options [Hash] options that will be used in customising the HTML
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ class Tabs < Base
7
+ # = GOV.UK Tabs panel
31
8
  #
32
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
33
-
34
- def initialize(index:, id_prefix:, content: nil, text: nil, **options)
35
- super(**options)
36
- @options[:attributes][:class] = "govuk-tabs__panel #{'govuk-tabs__panel--hidden' if index > 1}".rstrip
37
- @options[:attributes][:id] ||= "#{id_prefix}-#{index}"
38
-
39
- @index = index
40
- @content = content
41
- @text = text
42
- end
43
-
44
- # Generates the HTML for the GOV.UK Tabs panel
9
+ # The individual tab panels
45
10
  #
46
- # @return [ActiveSupport::SafeBuffer]
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]
47
48
 
48
- def render
49
- tag.div(**options[:attributes]) do
50
- content || tag.p(text, class: 'govuk-body')
49
+ def render
50
+ tag.div(**options[:attributes]) do
51
+ content || tag.p(text, class: 'govuk-body')
52
+ end
51
53
  end
52
54
  end
53
55
  end
@@ -1,51 +1,53 @@
1
1
  require_relative '../../base'
2
2
 
3
- module CCS::Components
4
- module GovUK
5
- class Tabs < Base
6
- # = GOV.UK Tabs tab
7
- #
8
- # The individual tab
9
- #
10
- # @!attribute [r] index
11
- # @return [Integer] The index of the tab
12
- # @!attribute [r] label
13
- # @return [String] Text for the tab
14
- # @!attribute [r] href
15
- # @return [String] The href for the tab panel
16
-
17
- class Tab < Base
18
- private
19
-
20
- attr_reader :index, :label, :href
21
-
22
- public
23
-
24
- # @param index [Integer] the index of the tab
25
- # @param id_prefix [Integer] prefix used for the id of a panel if no id is specified
26
- # @param label [String] the text for the tab
27
- # @param panel [Hash] used to find the id of the panel. See {Components::GovUK::Tabs::Panel#initialize Panel#initialize} for more details
28
- # @param options [Hash] options that will be used in customising the HTML
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ class Tabs < Base
7
+ # = GOV.UK Tabs tab
29
8
  #
30
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
9
+ # The individual tab
10
+ #
11
+ # @!attribute [r] index
12
+ # @return [Integer] The index of the tab
13
+ # @!attribute [r] label
14
+ # @return [String] Text for the tab
15
+ # @!attribute [r] href
16
+ # @return [String] The href for the tab panel
31
17
 
32
- def initialize(index:, id_prefix:, label:, panel:, **options)
33
- super(**options)
18
+ class Tab < Base
19
+ private
34
20
 
35
- @options[:attributes][:class] = 'govuk-tabs__tab'
21
+ attr_reader :index, :label, :href
36
22
 
37
- @index = index
38
- @label = label
39
- @href = "##{panel.dig(:attributes, :id) || "#{id_prefix}-#{index}"}"
40
- end
23
+ public
41
24
 
42
- # Generates the HTML for the GOV.UK Tabs tab
43
- #
44
- # @return [ActiveSupport::SafeBuffer]
25
+ # @param index [Integer] the index of the tab
26
+ # @param id_prefix [Integer] prefix used for the id of a panel if no id is specified
27
+ # @param label [String] the text for the tab
28
+ # @param panel [Hash] used to find the id of the panel. See {Components::GovUK::Tabs::Panel#initialize Panel#initialize} for more details
29
+ # @param options [Hash] options that will be used in customising the HTML
30
+ #
31
+ # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
32
+
33
+ def initialize(index:, id_prefix:, label:, panel:, **options)
34
+ super(**options)
35
+
36
+ @options[:attributes][:class] = 'govuk-tabs__tab'
37
+
38
+ @index = index
39
+ @label = label
40
+ @href = "##{panel.dig(:attributes, :id) || "#{id_prefix}-#{index}"}"
41
+ end
42
+
43
+ # Generates the HTML for the GOV.UK Tabs tab
44
+ #
45
+ # @return [ActiveSupport::SafeBuffer]
45
46
 
46
- def render
47
- tag.li(class: "govuk-tabs__list-item #{'govuk-tabs__list-item--selected' if index == 1}".rstrip) do
48
- link_to(label, href, **options[:attributes])
47
+ def render
48
+ tag.li(class: "govuk-tabs__list-item #{'govuk-tabs__list-item--selected' if index == 1}".rstrip) do
49
+ link_to(label, href, **options[:attributes])
50
+ end
49
51
  end
50
52
  end
51
53
  end
@@ -2,63 +2,65 @@ require_relative '../base'
2
2
  require_relative 'tabs/tab'
3
3
  require_relative 'tabs/panel'
4
4
 
5
- module CCS::Components
6
- module GovUK
7
- # = GOV.UK Tabs
8
- #
9
- # This is used to generate the tabs component from the
10
- # {https://design-system.service.gov.uk/components/tabs GDS - Components - Tabs}
11
- #
12
- # @!attribute [r] title
13
- # @return [String] Title for the tabs table of contents
14
- # @!attribute [r] tabs
15
- # @return [Array<Tabs::Tab>] an array of initialised tabs
16
- # @!attribute [r] panels
17
- # @return [Array<Tabs::Panel>] an array of initialised panel
5
+ module CCS
6
+ module Components
7
+ module GovUK
8
+ # = GOV.UK Tabs
9
+ #
10
+ # This is used to generate the tabs component from the
11
+ # {https://design-system.service.gov.uk/components/tabs GDS - Components - Tabs}
12
+ #
13
+ # @!attribute [r] title
14
+ # @return [String] Title for the tabs table of contents
15
+ # @!attribute [r] tabs
16
+ # @return [Array<Tabs::Tab>] an array of initialised tabs
17
+ # @!attribute [r] panels
18
+ # @return [Array<Tabs::Panel>] an array of initialised panel
18
19
 
19
- class Tabs < Base
20
- private
20
+ class Tabs < Base
21
+ private
21
22
 
22
- attr_reader :title, :tabs, :panels
23
+ attr_reader :title, :tabs, :panels
23
24
 
24
- public
25
+ public
25
26
 
26
- # @param items [Array<Hash>] array of the tab items.
27
- # See {Components::GovUK::Tabs::Tab#initialize Tab#initialize}
28
- # and {Components::GovUK::Tabs::Panel#initialize Panel#initialize} for details of the items in the array.
29
- # @param title [NilClass,String] title for the tabs table of contents
30
- # @param id_prefix [String] prefix id for each tab item if no id is specified on each item
31
- # @param options [Hash] options that will be used in customising the HTML
32
- #
33
- # @option options [String] :classes additional CSS classes for the tabs HTML
34
- # @option options [Hash] :attributes ({}) any additional attributes that will be added as part of the HTML
27
+ # @param items [Array<Hash>] array of the tab items.
28
+ # See {Components::GovUK::Tabs::Tab#initialize Tab#initialize}
29
+ # and {Components::GovUK::Tabs::Panel#initialize Panel#initialize} for details of the items in the array.
30
+ # @param title [NilClass,String] title for the tabs table of contents
31
+ # @param id_prefix [String] prefix id for each tab item if no id is specified on each item
32
+ # @param options [Hash] options that will be used in customising the HTML
33
+ #
34
+ # @option options [String] :classes additional CSS classes for the tabs HTML
35
+ # @option options [Hash] :attributes ({}) any additional attributes that will be added as part of the HTML
35
36
 
36
- def initialize(items:, title: nil, id_prefix: nil, **options)
37
- super(**options)
37
+ def initialize(items:, title: nil, id_prefix: nil, **options)
38
+ super(**options)
38
39
 
39
- @title = title || 'Contents'
40
- id_prefix ||= sanitize_to_id(@title.downcase)
41
- @tabs = items.map.with_index(1) { |item, index| Tab.new(index: index, id_prefix: id_prefix, context: @context, **item) }
42
- @panels = items.map.with_index(1) { |item, index| Panel.new(index: index, id_prefix: id_prefix, context: @context, **item[:panel]) }
43
- end
40
+ @title = title || 'Contents'
41
+ id_prefix ||= sanitize_to_id(@title.downcase)
42
+ @tabs = items.map.with_index(1) { |item, index| Tab.new(index: index, id_prefix: id_prefix, context: @context, **item) }
43
+ @panels = items.map.with_index(1) { |item, index| Panel.new(index: index, id_prefix: id_prefix, context: @context, **item[:panel]) }
44
+ end
44
45
 
45
- # Generates the HTML for the GOV.UK Tabs component
46
- #
47
- # @return [ActiveSupport::SafeBuffer]
46
+ # Generates the HTML for the GOV.UK Tabs component
47
+ #
48
+ # @return [ActiveSupport::SafeBuffer]
48
49
 
49
- def render
50
- tag.div(**options[:attributes]) do
51
- concat(tag.h2(title, class: 'govuk-tabs__title'))
52
- concat(tag.ul(class: 'govuk-tabs__list') do
53
- @tabs.each { |tab| concat(tab.render) }
54
- end)
55
- @panels.each { |panel| concat(panel.render) }
50
+ def render
51
+ tag.div(**options[:attributes]) do
52
+ concat(tag.h2(title, class: 'govuk-tabs__title'))
53
+ concat(tag.ul(class: 'govuk-tabs__list') do
54
+ @tabs.each { |tab| concat(tab.render) }
55
+ end)
56
+ @panels.each { |panel| concat(panel.render) }
57
+ end
56
58
  end
57
- end
58
59
 
59
- # The default attributes for the tabs
60
+ # The default attributes for the tabs
60
61
 
61
- DEFAULT_ATTRIBUTES = { class: 'govuk-tabs', data: { module: 'govuk-tabs' } }.freeze
62
+ DEFAULT_ATTRIBUTES = { class: 'govuk-tabs', data: { module: 'govuk-tabs' } }.freeze
63
+ end
62
64
  end
63
65
  end
64
66
  end
@@ -1,49 +1,51 @@
1
1
  require_relative '../base'
2
2
 
3
- module CCS::Components
4
- module GovUK
5
- # = GOV.UK Tag
6
- #
7
- # This is used to generate the tag component from the
8
- # {https://design-system.service.gov.uk/components/tag GDS - Components - Tag}
9
- #
10
- # @!attribute [r] text
11
- # @return [String] Text for the tag
12
-
13
- class Tag < Base
14
- private
15
-
16
- attr_reader :text
17
-
18
- public
19
-
20
- # @param text [String] the text for the tag
21
- # @param colour [String] optional colour for the tag,
22
- # see {https://design-system.service.gov.uk/components/tag/#additional-colours Tag - Additional colours}
23
- # for available colours in GOV.UK Frontend
24
- # @param options [Hash] options that will be used in customising the HTML
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ # = GOV.UK Tag
25
7
  #
26
- # @option options [String] :classes additional CSS classes for the tag HTML
27
- # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
8
+ # This is used to generate the tag component from the
9
+ # {https://design-system.service.gov.uk/components/tag GDS - Components - Tag}
10
+ #
11
+ # @!attribute [r] text
12
+ # @return [String] Text for the tag
28
13
 
29
- def initialize(text:, colour: nil, **options)
30
- super(**options)
31
- @options[:attributes][:class][..8] = "govuk-tag govuk-tag--#{colour}" if colour
14
+ class Tag < Base
15
+ private
32
16
 
33
- @text = text
34
- end
17
+ attr_reader :text
35
18
 
36
- # Generates the HTML for the GOV.UK Tag component
37
- #
38
- # @return [ActiveSupport::SafeBuffer]
19
+ public
39
20
 
40
- def render
41
- tag.strong(text, **options[:attributes])
42
- end
21
+ # @param text [String] the text for the tag
22
+ # @param colour [String] optional colour for the tag,
23
+ # see {https://design-system.service.gov.uk/components/tag/#additional-colours Tag - Additional colours}
24
+ # for available colours in GOV.UK Frontend
25
+ # @param options [Hash] options that will be used in customising the HTML
26
+ #
27
+ # @option options [String] :classes additional CSS classes for the tag HTML
28
+ # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
29
+
30
+ def initialize(text:, colour: nil, **options)
31
+ super(**options)
32
+ @options[:attributes][:class][..8] = "govuk-tag govuk-tag--#{colour}" if colour
43
33
 
44
- # The default attributes for the tag
34
+ @text = text
35
+ end
45
36
 
46
- DEFAULT_ATTRIBUTES = { class: 'govuk-tag' }.freeze
37
+ # Generates the HTML for the GOV.UK Tag component
38
+ #
39
+ # @return [ActiveSupport::SafeBuffer]
40
+
41
+ def render
42
+ tag.strong(text, **options[:attributes])
43
+ end
44
+
45
+ # The default attributes for the tag
46
+
47
+ DEFAULT_ATTRIBUTES = { class: 'govuk-tag' }.freeze
48
+ end
47
49
  end
48
50
  end
49
51
  end