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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/Gemfile.lock +1 -1
- data/lib/ccs/components/ccs/dashboard_section/panel.rb +43 -41
- data/lib/ccs/components/ccs/dashboard_section.rb +50 -48
- data/lib/ccs/components/ccs/footer/link.rb +41 -39
- data/lib/ccs/components/ccs/footer/meta.rb +49 -48
- data/lib/ccs/components/ccs/footer/navigation.rb +51 -50
- data/lib/ccs/components/ccs/footer.rb +69 -67
- data/lib/ccs/components/ccs/header/link.rb +47 -45
- data/lib/ccs/components/ccs/header/navigation.rb +85 -84
- data/lib/ccs/components/ccs/header/service_authentication.rb +35 -34
- data/lib/ccs/components/ccs/header.rb +87 -85
- data/lib/ccs/components/ccs/logo.rb +36 -34
- data/lib/ccs/components/govuk/accordion/section/content.rb +42 -42
- data/lib/ccs/components/govuk/accordion/section/header.rb +48 -48
- data/lib/ccs/components/govuk/accordion/section.rb +49 -48
- data/lib/ccs/components/govuk/accordion.rb +43 -41
- data/lib/ccs/components/govuk/back_link.rb +39 -37
- data/lib/ccs/components/govuk/breadcrumbs/link.rb +42 -40
- data/lib/ccs/components/govuk/breadcrumbs.rb +40 -38
- data/lib/ccs/components/govuk/button.rb +83 -81
- data/lib/ccs/components/govuk/cookie_banner/action.rb +45 -43
- data/lib/ccs/components/govuk/cookie_banner/message.rb +57 -55
- data/lib/ccs/components/govuk/cookie_banner.rb +40 -38
- data/lib/ccs/components/govuk/details.rb +38 -36
- data/lib/ccs/components/govuk/error_message.rb +46 -44
- data/lib/ccs/components/govuk/error_summary/item.rb +41 -39
- data/lib/ccs/components/govuk/error_summary.rb +49 -47
- data/lib/ccs/components/govuk/field/input/character_count.rb +101 -99
- data/lib/ccs/components/govuk/field/input/file_upload.rb +29 -27
- data/lib/ccs/components/govuk/field/input/select.rb +61 -59
- data/lib/ccs/components/govuk/field/input/text_input/fix.rb +39 -37
- data/lib/ccs/components/govuk/field/input/text_input.rb +75 -73
- data/lib/ccs/components/govuk/field/input/textarea.rb +43 -41
- data/lib/ccs/components/govuk/field/input.rb +46 -44
- data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +43 -41
- data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +48 -46
- data/lib/ccs/components/govuk/field/inputs/date_input.rb +68 -66
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +29 -27
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +26 -24
- data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +32 -30
- data/lib/ccs/components/govuk/field/inputs/item/divider.rb +39 -37
- data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +27 -25
- data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +26 -24
- data/lib/ccs/components/govuk/field/inputs/item/radio.rb +32 -30
- data/lib/ccs/components/govuk/field/inputs/item.rb +100 -98
- data/lib/ccs/components/govuk/field/inputs/radios.rb +43 -41
- data/lib/ccs/components/govuk/field/inputs.rb +42 -40
- data/lib/ccs/components/govuk/field.rb +90 -88
- data/lib/ccs/components/govuk/fieldset/legend.rb +50 -48
- data/lib/ccs/components/govuk/fieldset.rb +40 -38
- data/lib/ccs/components/govuk/footer/link.rb +41 -39
- data/lib/ccs/components/govuk/footer/meta.rb +49 -48
- data/lib/ccs/components/govuk/footer/navigation.rb +51 -50
- data/lib/ccs/components/govuk/footer.rb +105 -103
- data/lib/ccs/components/govuk/form_group.rb +45 -43
- data/lib/ccs/components/govuk/header/link.rb +41 -39
- data/lib/ccs/components/govuk/header/navigation.rb +54 -53
- data/lib/ccs/components/govuk/header.rb +84 -82
- data/lib/ccs/components/govuk/hint.rb +33 -31
- data/lib/ccs/components/govuk/inset_text.rb +39 -37
- data/lib/ccs/components/govuk/label.rb +61 -59
- data/lib/ccs/components/govuk/notification_banner.rb +83 -81
- data/lib/ccs/components/govuk/pagination/increment/next.rb +29 -27
- data/lib/ccs/components/govuk/pagination/increment/previous.rb +28 -26
- data/lib/ccs/components/govuk/pagination/increment.rb +78 -76
- data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +17 -15
- data/lib/ccs/components/govuk/pagination/item/form.rb +34 -32
- data/lib/ccs/components/govuk/pagination/item/tag.rb +33 -31
- data/lib/ccs/components/govuk/pagination/item.rb +47 -45
- data/lib/ccs/components/govuk/pagination.rb +69 -67
- data/lib/ccs/components/govuk/panel.rb +49 -47
- data/lib/ccs/components/govuk/phase_banner.rb +50 -48
- data/lib/ccs/components/govuk/skip_link.rb +39 -37
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +40 -38
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +30 -28
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +28 -26
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +47 -45
- data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +49 -47
- data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +44 -42
- data/lib/ccs/components/govuk/step_by_step_navigation.rb +41 -39
- data/lib/ccs/components/govuk/summary_list/action/link.rb +46 -44
- data/lib/ccs/components/govuk/summary_list/card/actions.rb +38 -36
- data/lib/ccs/components/govuk/summary_list/card/title.rb +37 -35
- data/lib/ccs/components/govuk/summary_list/card.rb +48 -46
- data/lib/ccs/components/govuk/summary_list/row/actions.rb +38 -36
- data/lib/ccs/components/govuk/summary_list/row/key.rb +30 -28
- data/lib/ccs/components/govuk/summary_list/row/value.rb +30 -28
- data/lib/ccs/components/govuk/summary_list/row.rb +47 -45
- data/lib/ccs/components/govuk/summary_list.rb +48 -46
- data/lib/ccs/components/govuk/table/body/data_cell.rb +38 -36
- data/lib/ccs/components/govuk/table/body/head_cell.rb +37 -35
- data/lib/ccs/components/govuk/table/header/head_cell.rb +39 -37
- data/lib/ccs/components/govuk/table.rb +83 -81
- data/lib/ccs/components/govuk/tabs/panel.rb +47 -45
- data/lib/ccs/components/govuk/tabs/tab.rb +42 -40
- data/lib/ccs/components/govuk/tabs.rb +48 -46
- data/lib/ccs/components/govuk/tag.rb +39 -37
- data/lib/ccs/components/govuk/warning_text.rb +49 -47
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +16 -14
- data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +17 -15
- data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +17 -15
- data/lib/ccs/frontend_helpers/ccs_frontend.rb +1 -1
- data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -30
- data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +38 -36
- data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +27 -25
- data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +18 -16
- data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +18 -16
- data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +24 -22
- data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +19 -17
- data/lib/ccs/frontend_helpers/version.rb +1 -1
- 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
|
7
|
-
module
|
8
|
-
|
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
|
-
#
|
37
|
-
#
|
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
|
-
#
|
40
|
-
#
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
73
|
+
# The default attributes for the table
|
73
74
|
|
74
|
-
|
75
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-table' }.freeze
|
75
76
|
|
76
|
-
|
77
|
+
private
|
77
78
|
|
78
|
-
|
79
|
-
|
80
|
-
|
79
|
+
# Generates the HTML for the the table caption
|
80
|
+
#
|
81
|
+
# @return [ActiveSupport::SafeBuffer]
|
81
82
|
|
82
|
-
|
83
|
-
|
84
|
-
|
83
|
+
def table_caption
|
84
|
+
tag.caption(caption[:text], class: "govuk-table__caption #{caption[:classes]}".rstrip)
|
85
|
+
end
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
87
|
+
# Generates the HTML for the table head
|
88
|
+
#
|
89
|
+
# @return [ActiveSupport::SafeBuffer]
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
99
|
-
|
100
|
-
|
99
|
+
# Generates the HTML for a table row
|
100
|
+
#
|
101
|
+
# @return [ActiveSupport::SafeBuffer]
|
101
102
|
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
4
|
-
module
|
5
|
-
|
6
|
-
|
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
|
-
#
|
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
|
-
#
|
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
|
-
|
49
|
-
|
50
|
-
|
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
|
4
|
-
module
|
5
|
-
|
6
|
-
|
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
|
-
#
|
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
|
-
|
33
|
-
|
18
|
+
class Tab < Base
|
19
|
+
private
|
34
20
|
|
35
|
-
|
21
|
+
attr_reader :index, :label, :href
|
36
22
|
|
37
|
-
|
38
|
-
@label = label
|
39
|
-
@href = "##{panel.dig(:attributes, :id) || "#{id_prefix}-#{index}"}"
|
40
|
-
end
|
23
|
+
public
|
41
24
|
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
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
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
20
|
-
|
20
|
+
class Tabs < Base
|
21
|
+
private
|
21
22
|
|
22
|
-
|
23
|
+
attr_reader :title, :tabs, :panels
|
23
24
|
|
24
|
-
|
25
|
+
public
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
37
|
-
|
37
|
+
def initialize(items:, title: nil, id_prefix: nil, **options)
|
38
|
+
super(**options)
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
46
|
+
# Generates the HTML for the GOV.UK Tabs component
|
47
|
+
#
|
48
|
+
# @return [ActiveSupport::SafeBuffer]
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
60
|
+
# The default attributes for the tabs
|
60
61
|
|
61
|
-
|
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
|
4
|
-
module
|
5
|
-
|
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
|
-
#
|
27
|
-
#
|
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
|
-
|
30
|
-
|
31
|
-
@options[:attributes][:class][..8] = "govuk-tag govuk-tag--#{colour}" if colour
|
14
|
+
class Tag < Base
|
15
|
+
private
|
32
16
|
|
33
|
-
|
34
|
-
end
|
17
|
+
attr_reader :text
|
35
18
|
|
36
|
-
|
37
|
-
#
|
38
|
-
# @return [ActiveSupport::SafeBuffer]
|
19
|
+
public
|
39
20
|
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
34
|
+
@text = text
|
35
|
+
end
|
45
36
|
|
46
|
-
|
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
|