ccs-frontend_helpers 0.1.0.rc.1 → 0.1.0.rc.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -1
- data/.ruby-version +1 -0
- data/CHANGELOG.md +4 -1
- data/Gemfile.lock +71 -71
- data/lib/ccs/components/base.rb +64 -0
- data/lib/ccs/components/ccs/dashboard_section/panel.rb +55 -0
- data/lib/ccs/components/ccs/dashboard_section.rb +71 -0
- data/lib/ccs/components/ccs/footer/link.rb +53 -0
- data/lib/ccs/components/ccs/footer/meta.rb +58 -0
- data/lib/ccs/components/ccs/footer/navigation.rb +59 -0
- data/lib/ccs/components/ccs/footer.rb +93 -0
- data/lib/ccs/components/ccs/header/link.rb +58 -0
- data/lib/ccs/components/ccs/header/navigation.rb +97 -0
- data/lib/ccs/components/ccs/header/service_authentication.rb +52 -0
- data/lib/ccs/components/ccs/header.rb +108 -0
- data/lib/ccs/components/ccs/logo.rb +45 -0
- data/lib/ccs/components/govuk/accordion/section/content.rb +53 -0
- data/lib/ccs/components/govuk/accordion/section/header.rb +57 -0
- data/lib/ccs/components/govuk/accordion/section.rb +60 -0
- data/lib/ccs/components/govuk/accordion.rb +56 -0
- data/lib/ccs/components/govuk/back_link.rb +49 -0
- data/lib/ccs/components/govuk/breadcrumbs/link.rb +55 -0
- data/lib/ccs/components/govuk/breadcrumbs.rb +53 -0
- data/lib/ccs/components/govuk/button.rb +105 -0
- data/lib/ccs/components/govuk/cookie_banner/action.rb +58 -0
- data/lib/ccs/components/govuk/cookie_banner/message.rb +78 -0
- data/lib/ccs/components/govuk/cookie_banner.rb +53 -0
- data/lib/ccs/components/govuk/details.rb +51 -0
- data/lib/ccs/components/govuk/error_message.rb +58 -0
- data/lib/ccs/components/govuk/error_summary/item.rb +52 -0
- data/lib/ccs/components/govuk/error_summary.rb +68 -0
- data/lib/ccs/components/govuk/field/input/character_count.rb +127 -0
- data/lib/ccs/components/govuk/field/input/file_upload.rb +42 -0
- data/lib/ccs/components/govuk/field/input/select.rb +80 -0
- data/lib/ccs/components/govuk/field/input/text_input/fix.rb +53 -0
- data/lib/ccs/components/govuk/field/input/text_input.rb +95 -0
- data/lib/ccs/components/govuk/field/input/textarea.rb +57 -0
- data/lib/ccs/components/govuk/field/input.rb +60 -0
- data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +67 -0
- data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +63 -0
- data/lib/ccs/components/govuk/field/inputs/date_input.rb +87 -0
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +45 -0
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +41 -0
- data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +48 -0
- data/lib/ccs/components/govuk/field/inputs/item/divider.rb +48 -0
- data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +42 -0
- data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +41 -0
- data/lib/ccs/components/govuk/field/inputs/item/radio.rb +48 -0
- data/lib/ccs/components/govuk/field/inputs/item.rb +109 -0
- data/lib/ccs/components/govuk/field/inputs/radios.rb +67 -0
- data/lib/ccs/components/govuk/field/inputs.rb +55 -0
- data/lib/ccs/components/govuk/field.rb +106 -0
- data/lib/ccs/components/govuk/fieldset/legend.rb +63 -0
- data/lib/ccs/components/govuk/fieldset.rb +52 -0
- data/lib/ccs/components/govuk/footer/link.rb +53 -0
- data/lib/ccs/components/govuk/footer/meta.rb +58 -0
- data/lib/ccs/components/govuk/footer/navigation.rb +59 -0
- data/lib/ccs/components/govuk/footer.rb +129 -0
- data/lib/ccs/components/govuk/form_group.rb +58 -0
- data/lib/ccs/components/govuk/header/link.rb +54 -0
- data/lib/ccs/components/govuk/header/navigation.rb +70 -0
- data/lib/ccs/components/govuk/header.rb +105 -0
- data/lib/ccs/components/govuk/hint.rb +47 -0
- data/lib/ccs/components/govuk/inset_text.rb +50 -0
- data/lib/ccs/components/govuk/label.rb +83 -0
- data/lib/ccs/components/govuk/notification_banner.rb +105 -0
- data/lib/ccs/components/govuk/pagination/increment/next.rb +42 -0
- data/lib/ccs/components/govuk/pagination/increment/previous.rb +41 -0
- data/lib/ccs/components/govuk/pagination/increment.rb +96 -0
- data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +26 -0
- data/lib/ccs/components/govuk/pagination/item/form.rb +47 -0
- data/lib/ccs/components/govuk/pagination/item/tag.rb +45 -0
- data/lib/ccs/components/govuk/pagination/item.rb +62 -0
- data/lib/ccs/components/govuk/pagination.rb +94 -0
- data/lib/ccs/components/govuk/panel.rb +60 -0
- data/lib/ccs/components/govuk/phase_banner.rb +67 -0
- data/lib/ccs/components/govuk/skip_link.rb +49 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +51 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +48 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +43 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +61 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +67 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +54 -0
- data/lib/ccs/components/govuk/step_by_step_navigation.rb +57 -0
- data/lib/ccs/components/govuk/summary_list/action/link.rb +57 -0
- data/lib/ccs/components/govuk/summary_list/card/actions.rb +57 -0
- data/lib/ccs/components/govuk/summary_list/card/title.rb +49 -0
- data/lib/ccs/components/govuk/summary_list/card.rb +61 -0
- data/lib/ccs/components/govuk/summary_list/row/actions.rb +57 -0
- data/lib/ccs/components/govuk/summary_list/row/key.rb +45 -0
- data/lib/ccs/components/govuk/summary_list/row/value.rb +45 -0
- data/lib/ccs/components/govuk/summary_list/row.rb +63 -0
- data/lib/ccs/components/govuk/summary_list.rb +72 -0
- data/lib/ccs/components/govuk/table/body/data_cell.rb +51 -0
- data/lib/ccs/components/govuk/table/body/head_cell.rb +50 -0
- data/lib/ccs/components/govuk/table/header/head_cell.rb +52 -0
- data/lib/ccs/components/govuk/table.rb +109 -0
- data/lib/ccs/components/govuk/tabs/panel.rb +56 -0
- data/lib/ccs/components/govuk/tabs/tab.rb +54 -0
- data/lib/ccs/components/govuk/tabs.rb +64 -0
- data/lib/ccs/components/govuk/tag.rb +49 -0
- data/lib/ccs/components/govuk/warning_text.rb +59 -0
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +25 -0
- data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +16 -131
- data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +16 -195
- data/lib/ccs/frontend_helpers/ccs_frontend.rb +2 -4
- data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +16 -105
- data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +16 -29
- data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +16 -66
- data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +16 -117
- data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +26 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +26 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +16 -126
- data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +26 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +18 -36
- data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +31 -54
- data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +32 -86
- data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +18 -61
- data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +26 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +16 -173
- data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +26 -39
- data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +16 -151
- data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +17 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +26 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +18 -34
- data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +17 -82
- data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +18 -126
- data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +16 -326
- data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +18 -41
- data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +18 -39
- data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +26 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +26 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +16 -30
- data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +23 -204
- data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +16 -216
- data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +16 -114
- data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +16 -85
- data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +16 -32
- data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +26 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +18 -43
- data/lib/ccs/frontend_helpers/govuk_frontend.rb +17 -19
- data/lib/ccs/frontend_helpers/version.rb +1 -1
- metadata +110 -14
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +0 -79
- data/lib/ccs/frontend_helpers/ccs_frontend/logo.rb +0 -49
- data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +0 -165
- data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +0 -200
- data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +0 -153
- data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +0 -83
- data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +0 -153
- data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +0 -201
- data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +0 -124
- data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +0 -106
- data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +0 -213
- data/lib/ccs/frontend_helpers/shared_methods.rb +0 -27
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative '../../../base'
|
2
|
+
|
3
|
+
module CCS::Components
|
4
|
+
module GovUK
|
5
|
+
class Table < Base
|
6
|
+
class Body
|
7
|
+
# = GOV.UK Table Body data cell
|
8
|
+
#
|
9
|
+
# The individual table body data cell
|
10
|
+
#
|
11
|
+
# @!attribute [r] text
|
12
|
+
# @return [String] Text for the cell
|
13
|
+
|
14
|
+
class DataCell < Base
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :text
|
18
|
+
|
19
|
+
public
|
20
|
+
|
21
|
+
# @param text [String] the text of the cell
|
22
|
+
# @param options [Hash] options that will be used in customising the HTML
|
23
|
+
#
|
24
|
+
# @option options [String] :classes additional CSS classes for the cell
|
25
|
+
# @option options [String] :format specify format of a 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][:class] += " govuk-table__cell--#{@options[:format]}" if @options[:format]
|
32
|
+
|
33
|
+
@text = text
|
34
|
+
end
|
35
|
+
|
36
|
+
# Generates the HTML for the GOV.UK Table Body data cell
|
37
|
+
#
|
38
|
+
# @return [ActiveSupport::SafeBuffer]
|
39
|
+
|
40
|
+
def render
|
41
|
+
tag.td(text, **options[:attributes])
|
42
|
+
end
|
43
|
+
|
44
|
+
# The default attributes for the table body data cell
|
45
|
+
|
46
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-table__cell' }.freeze
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require_relative '../../../base'
|
2
|
+
|
3
|
+
module CCS::Components
|
4
|
+
module GovUK
|
5
|
+
class Table < Base
|
6
|
+
class Body
|
7
|
+
# = GOV.UK Table Body head cell
|
8
|
+
#
|
9
|
+
# The individual table body head cell
|
10
|
+
#
|
11
|
+
# @!attribute [r] text
|
12
|
+
# @return [String] Text for the cell
|
13
|
+
|
14
|
+
class HeadCell < Base
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :text
|
18
|
+
|
19
|
+
public
|
20
|
+
|
21
|
+
# @param text [String] the text of the cell
|
22
|
+
# @param options [Hash] options that will be used in customising the HTML
|
23
|
+
#
|
24
|
+
# @option options [String] :classes additional CSS classes for the cell
|
25
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will be added as part of the cell
|
26
|
+
|
27
|
+
def initialize(text:, **options)
|
28
|
+
super(**options)
|
29
|
+
|
30
|
+
@options[:attributes][:scope] = 'row'
|
31
|
+
|
32
|
+
@text = text
|
33
|
+
end
|
34
|
+
|
35
|
+
# Generates the HTML for the GOV.UK Table Body head cell
|
36
|
+
#
|
37
|
+
# @return [ActiveSupport::SafeBuffer]
|
38
|
+
|
39
|
+
def render
|
40
|
+
tag.th(text, **options[:attributes])
|
41
|
+
end
|
42
|
+
|
43
|
+
# The default attributes for the table body head cell
|
44
|
+
|
45
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-table__header' }.freeze
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative '../../../base'
|
2
|
+
|
3
|
+
module CCS::Components
|
4
|
+
module GovUK
|
5
|
+
class Table < Base
|
6
|
+
class Header
|
7
|
+
# = GOV.UK Table Header head cell
|
8
|
+
#
|
9
|
+
# The individual table header head cell
|
10
|
+
#
|
11
|
+
# @!attribute [r] text
|
12
|
+
# @return [String] Text for the cell
|
13
|
+
|
14
|
+
class HeadCell < Base
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :text
|
18
|
+
|
19
|
+
public
|
20
|
+
|
21
|
+
# @param text [String] the text of the cell
|
22
|
+
# @param options [Hash] options that will be used in customising the HTML
|
23
|
+
#
|
24
|
+
# @option options [String] :classes additional CSS classes for the cell
|
25
|
+
# @option options [String] :format specify format of a 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][:class] += " govuk-table__header--#{@options[:format]}" if @options[:format]
|
32
|
+
@options[:attributes][:scope] = 'col'
|
33
|
+
|
34
|
+
@text = text
|
35
|
+
end
|
36
|
+
|
37
|
+
# Generates the HTML for the GOV.UK Table Header head cell
|
38
|
+
#
|
39
|
+
# @return [ActiveSupport::SafeBuffer]
|
40
|
+
|
41
|
+
def render
|
42
|
+
tag.th(text, **options[:attributes])
|
43
|
+
end
|
44
|
+
|
45
|
+
# The default attributes for the table header head cell
|
46
|
+
|
47
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-table__header' }.freeze
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,109 @@
|
|
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::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
|
35
|
+
#
|
36
|
+
# @option caption [String] :text the caption text
|
37
|
+
# @option caption [String] :classes additional CSS classes for the table caption
|
38
|
+
#
|
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)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
@head_cells = head_cells&.map { |head_cell| Header::HeadCell.new(context: @context, **head_cell) }
|
55
|
+
@caption = caption
|
56
|
+
end
|
57
|
+
|
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)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# The default attributes for the table
|
73
|
+
|
74
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-table' }.freeze
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
# Generates the HTML for the the table caption
|
79
|
+
#
|
80
|
+
# @return [ActiveSupport::SafeBuffer]
|
81
|
+
|
82
|
+
def table_caption
|
83
|
+
tag.caption(caption[:text], class: "govuk-table__caption #{caption[:classes]}".rstrip)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Generates the HTML for the table head
|
87
|
+
#
|
88
|
+
# @return [ActiveSupport::SafeBuffer]
|
89
|
+
|
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) }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Generates the HTML for a table row
|
99
|
+
#
|
100
|
+
# @return [ActiveSupport::SafeBuffer]
|
101
|
+
|
102
|
+
def table_row(row_cells)
|
103
|
+
tag.tr(class: 'govuk-table__row') do
|
104
|
+
row_cells.each { |row_cell| concat(row_cell.render) }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative '../../base'
|
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
|
31
|
+
#
|
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
|
45
|
+
#
|
46
|
+
# @return [ActiveSupport::SafeBuffer]
|
47
|
+
|
48
|
+
def render
|
49
|
+
tag.div(**options[:attributes]) do
|
50
|
+
content || tag.p(text, class: 'govuk-body')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative '../../base'
|
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
|
29
|
+
#
|
30
|
+
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML
|
31
|
+
|
32
|
+
def initialize(index:, id_prefix:, label:, panel:, **options)
|
33
|
+
super(**options)
|
34
|
+
|
35
|
+
@options[:attributes][:class] = 'govuk-tabs__tab'
|
36
|
+
|
37
|
+
@index = index
|
38
|
+
@label = label
|
39
|
+
@href = "##{panel.dig(:attributes, :id) || "#{id_prefix}-#{index}"}"
|
40
|
+
end
|
41
|
+
|
42
|
+
# Generates the HTML for the GOV.UK Tabs tab
|
43
|
+
#
|
44
|
+
# @return [ActiveSupport::SafeBuffer]
|
45
|
+
|
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])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
require_relative 'tabs/tab'
|
3
|
+
require_relative 'tabs/panel'
|
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
|
18
|
+
|
19
|
+
class Tabs < Base
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :title, :tabs, :panels
|
23
|
+
|
24
|
+
public
|
25
|
+
|
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
|
35
|
+
|
36
|
+
def initialize(items:, title: nil, id_prefix: nil, **options)
|
37
|
+
super(**options)
|
38
|
+
|
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
|
44
|
+
|
45
|
+
# Generates the HTML for the GOV.UK Tabs component
|
46
|
+
#
|
47
|
+
# @return [ActiveSupport::SafeBuffer]
|
48
|
+
|
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) }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# The default attributes for the tabs
|
60
|
+
|
61
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-tabs', data: { module: 'govuk-tabs' } }.freeze
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative '../base'
|
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
|
25
|
+
#
|
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
|
28
|
+
|
29
|
+
def initialize(text:, colour: nil, **options)
|
30
|
+
super(**options)
|
31
|
+
@options[:attributes][:class][..8] = "govuk-tag govuk-tag--#{colour}" if colour
|
32
|
+
|
33
|
+
@text = text
|
34
|
+
end
|
35
|
+
|
36
|
+
# Generates the HTML for the GOV.UK Tag component
|
37
|
+
#
|
38
|
+
# @return [ActiveSupport::SafeBuffer]
|
39
|
+
|
40
|
+
def render
|
41
|
+
tag.strong(text, **options[:attributes])
|
42
|
+
end
|
43
|
+
|
44
|
+
# The default attributes for the tag
|
45
|
+
|
46
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-tag' }.freeze
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
|
3
|
+
module CCS::Components
|
4
|
+
module GovUK
|
5
|
+
# = GOV.UK Warning text
|
6
|
+
#
|
7
|
+
# This helper is used for generating the warning text component from the
|
8
|
+
# {https://design-system.service.gov.uk/components/warning-text GDS - Components - Warning text}
|
9
|
+
#
|
10
|
+
# @!attribute [r] text
|
11
|
+
# @return [String] Text for the warning text
|
12
|
+
|
13
|
+
class WarningText < Base
|
14
|
+
private
|
15
|
+
|
16
|
+
attr_reader :text
|
17
|
+
|
18
|
+
public
|
19
|
+
|
20
|
+
# @param text [String] (nil) the text for the warning
|
21
|
+
# If nil, then a block will be rendered
|
22
|
+
# @param options [Hash] options that will be used in customising the HTML
|
23
|
+
#
|
24
|
+
# @option options [String] :classes additional CSS classes for the tag HTML
|
25
|
+
# @option options [String] :icon_fallback_text the fallback text for the icon (default: +'Warning'+)
|
26
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
27
|
+
|
28
|
+
def initialize(text: nil, **options)
|
29
|
+
super(**options)
|
30
|
+
|
31
|
+
@text = text
|
32
|
+
end
|
33
|
+
|
34
|
+
# Generates the HTML for the GOV.UK Warning text component
|
35
|
+
#
|
36
|
+
# @yield HTML that will be used in the warning text. Ignored if text is passed.
|
37
|
+
#
|
38
|
+
# @return [ActiveSupport::SafeBuffer]
|
39
|
+
|
40
|
+
def render
|
41
|
+
tag.div(**options[:attributes]) do
|
42
|
+
concat(tag.span('!', class: 'govuk-warning-text__icon'))
|
43
|
+
concat(tag.strong(class: 'govuk-warning-text__text') do
|
44
|
+
concat(tag.span(options[:icon_fallback_text] || 'Warning', class: 'govuk-warning-text__assistive'))
|
45
|
+
if text
|
46
|
+
concat(text)
|
47
|
+
else
|
48
|
+
yield
|
49
|
+
end
|
50
|
+
end)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# The default attributes for the warning text
|
55
|
+
|
56
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-warning-text' }.freeze
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../components/ccs/dashboard_section'
|
4
|
+
|
5
|
+
module CCS
|
6
|
+
module FrontendHelpers::CCSFrontend
|
7
|
+
# = CCS Dashboard Section
|
8
|
+
#
|
9
|
+
# This helper is used for generating the dashboard section component
|
10
|
+
|
11
|
+
module DashboardSection
|
12
|
+
# Generates the HTML for the CCS Dashboard Section component
|
13
|
+
#
|
14
|
+
# @param (see CCS::Components::CCS::DashboardSection#initialize)
|
15
|
+
#
|
16
|
+
# @option (see CCS::Components::CCS::DashboardSection#initialize)
|
17
|
+
#
|
18
|
+
# @return (see CCS::Components::CCS::DashboardSection#render)
|
19
|
+
|
20
|
+
def ccs_dashboard_section(dashboard_section_panels, title_text = nil, **options)
|
21
|
+
Components::CCS::DashboardSection.new(context: self, dashboard_section_panels: dashboard_section_panels, title_text: title_text, **options).render
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|