ccs-frontend_helpers 0.1.0 → 0.1.1.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +11 -2
- data/.ruby-version +1 -0
- data/CHANGELOG.md +4 -1
- data/Gemfile +15 -1
- data/Gemfile.lock +153 -114
- data/ccs-frontend_helpers.gemspec +1 -11
- data/lib/ccs/components/base.rb +64 -0
- data/lib/ccs/components/ccs/dashboard_section/panel.rb +57 -0
- data/lib/ccs/components/ccs/dashboard_section.rb +71 -0
- data/lib/ccs/components/ccs/footer/link.rb +55 -0
- data/lib/ccs/components/ccs/footer/meta.rb +59 -0
- data/lib/ccs/components/ccs/footer/navigation.rb +60 -0
- data/lib/ccs/components/ccs/footer.rb +95 -0
- data/lib/ccs/components/ccs/header/link.rb +60 -0
- data/lib/ccs/components/ccs/header/navigation.rb +98 -0
- data/lib/ccs/components/ccs/header/service_authentication.rb +53 -0
- data/lib/ccs/components/ccs/header.rb +110 -0
- data/lib/ccs/{frontend_helpers/ccs_frontend → components/ccs}/logo.rb +10 -12
- 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 +61 -0
- data/lib/ccs/components/govuk/accordion.rb +58 -0
- data/lib/ccs/components/govuk/back_link.rb +51 -0
- data/lib/ccs/components/govuk/breadcrumbs/link.rb +57 -0
- data/lib/ccs/components/govuk/breadcrumbs.rb +55 -0
- data/lib/ccs/components/govuk/button.rb +107 -0
- data/lib/ccs/components/govuk/cookie_banner/action.rb +60 -0
- data/lib/ccs/components/govuk/cookie_banner/message.rb +80 -0
- data/lib/ccs/components/govuk/cookie_banner.rb +55 -0
- data/lib/ccs/components/govuk/details.rb +53 -0
- data/lib/ccs/components/govuk/error_message.rb +60 -0
- data/lib/ccs/components/govuk/error_summary/item.rb +54 -0
- data/lib/ccs/components/govuk/error_summary.rb +70 -0
- data/lib/ccs/components/govuk/field/input/character_count.rb +129 -0
- data/lib/ccs/components/govuk/field/input/file_upload.rb +44 -0
- data/lib/ccs/components/govuk/field/input/select.rb +82 -0
- data/lib/ccs/components/govuk/field/input/text_input/fix.rb +55 -0
- data/lib/ccs/components/govuk/field/input/text_input.rb +97 -0
- data/lib/ccs/components/govuk/field/input/textarea.rb +59 -0
- data/lib/ccs/components/govuk/field/input.rb +62 -0
- data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +69 -0
- data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +65 -0
- data/lib/ccs/components/govuk/field/inputs/date_input.rb +89 -0
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +47 -0
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +43 -0
- data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +50 -0
- data/lib/ccs/components/govuk/field/inputs/item/divider.rb +50 -0
- data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +44 -0
- data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +43 -0
- data/lib/ccs/components/govuk/field/inputs/item/radio.rb +50 -0
- data/lib/ccs/components/govuk/field/inputs/item.rb +111 -0
- data/lib/ccs/components/govuk/field/inputs/radios.rb +69 -0
- data/lib/ccs/components/govuk/field/inputs.rb +57 -0
- data/lib/ccs/components/govuk/field.rb +108 -0
- data/lib/ccs/components/govuk/fieldset/legend.rb +65 -0
- data/lib/ccs/components/govuk/fieldset.rb +54 -0
- data/lib/ccs/components/govuk/footer/link.rb +55 -0
- data/lib/ccs/components/govuk/footer/meta.rb +59 -0
- data/lib/ccs/components/govuk/footer/navigation.rb +60 -0
- data/lib/ccs/components/govuk/footer.rb +131 -0
- data/lib/ccs/components/govuk/form_group.rb +60 -0
- data/lib/ccs/components/govuk/header/link.rb +56 -0
- data/lib/ccs/components/govuk/header/navigation.rb +71 -0
- data/lib/ccs/components/govuk/header.rb +107 -0
- data/lib/ccs/components/govuk/hint.rb +49 -0
- data/lib/ccs/components/govuk/inset_text.rb +52 -0
- data/lib/ccs/components/govuk/label.rb +85 -0
- data/lib/ccs/components/govuk/notification_banner.rb +107 -0
- data/lib/ccs/components/govuk/pagination/increment/next.rb +44 -0
- data/lib/ccs/components/govuk/pagination/increment/previous.rb +43 -0
- data/lib/ccs/components/govuk/pagination/increment.rb +98 -0
- data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +28 -0
- data/lib/ccs/components/govuk/pagination/item/form.rb +49 -0
- data/lib/ccs/components/govuk/pagination/item/tag.rb +47 -0
- data/lib/ccs/components/govuk/pagination/item.rb +64 -0
- data/lib/ccs/components/govuk/pagination.rb +96 -0
- data/lib/ccs/components/govuk/panel.rb +62 -0
- data/lib/ccs/components/govuk/phase_banner.rb +69 -0
- data/lib/ccs/components/govuk/skip_link.rb +51 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +53 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +50 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +45 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +63 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +69 -0
- data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +56 -0
- data/lib/ccs/components/govuk/step_by_step_navigation.rb +59 -0
- data/lib/ccs/components/govuk/summary_list/action/link.rb +59 -0
- data/lib/ccs/components/govuk/summary_list/card/actions.rb +59 -0
- data/lib/ccs/components/govuk/summary_list/card/title.rb +51 -0
- data/lib/ccs/components/govuk/summary_list/card.rb +63 -0
- data/lib/ccs/components/govuk/summary_list/row/actions.rb +59 -0
- data/lib/ccs/components/govuk/summary_list/row/key.rb +47 -0
- data/lib/ccs/components/govuk/summary_list/row/value.rb +47 -0
- data/lib/ccs/components/govuk/summary_list/row.rb +67 -0
- data/lib/ccs/components/govuk/summary_list.rb +74 -0
- data/lib/ccs/components/govuk/table/body/data_cell.rb +53 -0
- data/lib/ccs/components/govuk/table/body/head_cell.rb +52 -0
- data/lib/ccs/components/govuk/table/header/head_cell.rb +54 -0
- data/lib/ccs/components/govuk/table.rb +111 -0
- data/lib/ccs/components/govuk/tabs/panel.rb +58 -0
- data/lib/ccs/components/govuk/tabs/tab.rb +56 -0
- data/lib/ccs/components/govuk/tabs.rb +66 -0
- data/lib/ccs/components/govuk/tag.rb +51 -0
- data/lib/ccs/components/govuk/warning_text.rb +61 -0
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +27 -0
- data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +6 -119
- data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +6 -183
- data/lib/ccs/frontend_helpers/ccs_frontend.rb +2 -4
- data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +8 -95
- data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +6 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +6 -54
- data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +6 -105
- data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +6 -114
- data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +7 -23
- data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +11 -32
- data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +13 -65
- data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +7 -48
- data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +6 -161
- data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +13 -24
- data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +6 -139
- data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +8 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +7 -21
- data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +7 -70
- data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +7 -113
- data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +6 -314
- data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +7 -28
- data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +8 -27
- data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +6 -18
- data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +7 -186
- data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +6 -204
- data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +11 -100
- data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +6 -73
- data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +7 -21
- data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +28 -0
- data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +7 -30
- data/lib/ccs/frontend_helpers/govuk_frontend.rb +17 -19
- data/lib/ccs/frontend_helpers/version.rb +1 -1
- metadata +117 -147
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +0 -79
- 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,60 @@
|
|
1
|
+
require_relative 'link'
|
2
|
+
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
class Footer < Base
|
7
|
+
# = GOV.UK Footer Navigation
|
8
|
+
#
|
9
|
+
# The individual footer navigation item
|
10
|
+
#
|
11
|
+
# @!attribute [r] title
|
12
|
+
# @return [String] Title for the navigation section
|
13
|
+
# @!attribute [r] navigation_links
|
14
|
+
# @return [Array<Link>] An array of the initialised navigation links
|
15
|
+
# @!attribute [r] width
|
16
|
+
# @return [String] Width of the navigation section
|
17
|
+
# @!attribute [r] columns
|
18
|
+
# @return [Integer] Number of columns to display the links in
|
19
|
+
|
20
|
+
class Navigation
|
21
|
+
include ActionView::Context
|
22
|
+
include ActionView::Helpers
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :title, :navigation_links, :width, :columns
|
27
|
+
|
28
|
+
public
|
29
|
+
|
30
|
+
# @param title [String] the title for the navigation section
|
31
|
+
# @param items [Array<Hash>] an array of links for the navigation section.
|
32
|
+
# See {Components::GovUK::Footer::Link#initialize Link#initialize} for details of the items in the array.
|
33
|
+
# @param width [String] ('full') width of each navigation section in the footer
|
34
|
+
# @param columns [Integer] (nil) number of columns to display the links
|
35
|
+
# @param context [ActionView::Base] the view context
|
36
|
+
|
37
|
+
def initialize(title:, items:, context:, width: nil, columns: nil)
|
38
|
+
@title = title
|
39
|
+
@navigation_links = items.map { |navigation_link| Link.new(li_class: 'govuk-footer__list-item', context: context, **navigation_link) }
|
40
|
+
@width = width || 'full'
|
41
|
+
@columns = columns
|
42
|
+
end
|
43
|
+
|
44
|
+
# Generates the HTML for the GOV.UK Footer Navigation sections
|
45
|
+
#
|
46
|
+
# @return [ActiveSupport::SafeBuffer]
|
47
|
+
|
48
|
+
def render
|
49
|
+
tag.div(class: "govuk-footer__section govuk-grid-column-#{width}") do
|
50
|
+
concat(tag.h2(title, class: 'govuk-footer__heading govuk-heading-m'))
|
51
|
+
concat(tag.ul(class: "govuk-footer__list #{"govuk-footer__list--columns-#{columns}" if columns}".rstrip) do
|
52
|
+
navigation_links.each { |navigation_link| concat(navigation_link.render) }
|
53
|
+
end)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
require_relative 'footer/navigation'
|
3
|
+
require_relative 'footer/meta'
|
4
|
+
|
5
|
+
module CCS
|
6
|
+
module Components
|
7
|
+
module GovUK
|
8
|
+
# = GOV.UK Footer
|
9
|
+
#
|
10
|
+
# This is used to generate the footer component from the
|
11
|
+
# {https://design-system.service.gov.uk/components/footer GDS - Components - Footer}
|
12
|
+
#
|
13
|
+
# @!attribute [r] navigation
|
14
|
+
# @return [Array<Navigation>] An array of the initialised navigation sections
|
15
|
+
# @!attribute [r] meta
|
16
|
+
# @return [Meta] The initialised meta section
|
17
|
+
|
18
|
+
class Footer < Base
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :navigation, :meta
|
22
|
+
|
23
|
+
public
|
24
|
+
|
25
|
+
# @param navigation [Array<Hash>] an array of sections for the footer navigation.
|
26
|
+
# See {Components::GovUK::Footer::Navigation#initialize Navigation#initialize} for details of the items in the array.
|
27
|
+
# @param meta [Hash] ptions for the meta section of the footer.
|
28
|
+
# See {Components::GovUK::Footer::Meta#initialize Meta#initialize} for details of the options.
|
29
|
+
# @param options [Hash] options that will be used in customising the HTML
|
30
|
+
#
|
31
|
+
# @option options [String] :classes additional CSS classes for the footer HTML
|
32
|
+
# @option options [String] :container_class classes that can be added to the inner container
|
33
|
+
# @option options [ActiveSupport::SafeBuffer,String] :content_licence The content licence information, see {CCS::Components::GovUK::Footer#footer_content_licence footer_content_licence} for default
|
34
|
+
# @option options [ActiveSupport::SafeBuffer,String] :copyright The copyright information, (default: '© Crown copyright')
|
35
|
+
# @option options [Hash] :attributes additional attributes that will added as part of the HTML
|
36
|
+
|
37
|
+
def initialize(navigation: nil, meta: nil, **options)
|
38
|
+
super(**options)
|
39
|
+
|
40
|
+
@options[:attributes][:role] = 'contentinfo'
|
41
|
+
@options[:copyright] ||= '© Crown copyright'
|
42
|
+
|
43
|
+
@navigation = navigation&.map { |navigation_item| Navigation.new(context: @context, **navigation_item) }
|
44
|
+
@meta = Meta.new(context: @context, **meta) if meta
|
45
|
+
end
|
46
|
+
|
47
|
+
# rubocop:disable Metrics/AbcSize
|
48
|
+
|
49
|
+
# Generates the HTML for the GOV.UK Footer component
|
50
|
+
#
|
51
|
+
# @return [ActiveSupport::SafeBuffer]
|
52
|
+
|
53
|
+
def render
|
54
|
+
tag.footer(**options[:attributes]) do
|
55
|
+
tag.div(class: "govuk-width-container #{options[:container_classes]}".rstrip) do
|
56
|
+
if navigation
|
57
|
+
concat(tag.div(class: 'govuk-footer__navigation') do
|
58
|
+
navigation.each { |navigation_item| concat(navigation_item.render) }
|
59
|
+
end)
|
60
|
+
concat(tag.hr(class: 'govuk-footer__section-break'))
|
61
|
+
end
|
62
|
+
concat(tag.div(class: 'govuk-footer__meta') do
|
63
|
+
concat(tag.div(class: 'govuk-footer__meta-item govuk-footer__meta-item--grow') do
|
64
|
+
concat(meta.render) if meta
|
65
|
+
concat(footer_logo)
|
66
|
+
concat(footer_content_licence)
|
67
|
+
end)
|
68
|
+
concat(footer_copyright)
|
69
|
+
end)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# rubocop:enable Metrics/AbcSize
|
75
|
+
|
76
|
+
# The default attributes for the breadcrumbs
|
77
|
+
|
78
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-footer' }.freeze
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
# Generates the logo used in the footer
|
83
|
+
#
|
84
|
+
# @return [ActiveSupport::SafeBuffer]
|
85
|
+
|
86
|
+
def footer_logo
|
87
|
+
tag.svg(
|
88
|
+
class: 'govuk-footer__licence-logo',
|
89
|
+
aria: { hidden: 'true' },
|
90
|
+
focusable: 'false',
|
91
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
92
|
+
viewBox: '0 0 483.2 195.7',
|
93
|
+
height: '17',
|
94
|
+
width: '41'
|
95
|
+
) do
|
96
|
+
tag.path(
|
97
|
+
fill: 'currentColor',
|
98
|
+
d: 'M421.5 142.8V.1l-50.7 32.3v161.1h112.4v-50.7zm-122.3-9.6A47.12 47.12 0 0 1 221 97.8c0-26 21.1-47.1 47.1-47.1 16.7 0 31.4 8.7 39.7 21.8l42.7-27.2A97.63 97.63 0 0 0 268.1 0c-36.5 0-68.3 20.1-85.1 49.7A98 98 0 0 0 97.8 0C43.9 0 0 43.9 0 97.8s43.9 97.8 97.8 97.8c36.5 0 68.3-20.1 85.1-49.7a97.76 97.76 0 0 0 149.6 25.4l19.4 22.2h3v-87.8h-80l24.3 27.5zM97.8 145c-26 0-47.1-21.1-47.1-47.1s21.1-47.1 47.1-47.1 47.2 21 47.2 47S123.8 145 97.8 145'
|
99
|
+
)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Generates the content licence for the footer
|
104
|
+
#
|
105
|
+
# @return [ActiveSupport::SafeBuffer]
|
106
|
+
|
107
|
+
def footer_content_licence
|
108
|
+
tag.span(class: 'govuk-footer__licence-description') do
|
109
|
+
if options[:content_licence]
|
110
|
+
concat(options[:content_licence])
|
111
|
+
else
|
112
|
+
concat('All content is available under the')
|
113
|
+
concat(link_to('Open Government Licence v3.0', 'https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/', class: 'govuk-footer__link', rel: 'license'))
|
114
|
+
concat(', except where otherwise stated')
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# Generates the copyright used in the footer
|
120
|
+
#
|
121
|
+
# @return [ActiveSupport::SafeBuffer]
|
122
|
+
|
123
|
+
def footer_copyright
|
124
|
+
tag.div(class: 'govuk-footer__meta-item') do
|
125
|
+
link_to(options[:copyright], 'https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/', class: 'govuk-footer__link govuk-footer__copyright-logo')
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
require_relative 'error_message'
|
3
|
+
|
4
|
+
module CCS
|
5
|
+
module Components
|
6
|
+
module GovUK
|
7
|
+
# = GOV.UK FormGroup
|
8
|
+
#
|
9
|
+
# This helper is used for generating the form group component from the Government Design Systems
|
10
|
+
#
|
11
|
+
# @!attribute [r] attribute
|
12
|
+
# @return [String,Symbol] Attribute that the form group is for
|
13
|
+
# @!attribute [r] error_message
|
14
|
+
# @return [String] Text for the error message
|
15
|
+
|
16
|
+
class FormGroup < Base
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :attribute, :error_message
|
20
|
+
|
21
|
+
public
|
22
|
+
|
23
|
+
# @param attribute [String,Symbol] the attribute that the form group is for
|
24
|
+
# @param error_message [String] (nil) the error message to be displayed
|
25
|
+
# @param options [Hash] options that will be used in customising the HTML
|
26
|
+
#
|
27
|
+
# @option options [String] :classes additional CSS classes for the form group HTML
|
28
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
29
|
+
|
30
|
+
def initialize(attribute:, error_message: nil, **options)
|
31
|
+
super(**options)
|
32
|
+
|
33
|
+
@options[:attributes][:id] ||= "#{attribute}-form-group"
|
34
|
+
@options[:attributes][:class][..15] = 'govuk-form-group govuk-form-group--error' if error_message
|
35
|
+
|
36
|
+
@attribute = attribute
|
37
|
+
@error_message = error_message
|
38
|
+
end
|
39
|
+
|
40
|
+
# Generates the HTML for the GOV.UK Form Group component
|
41
|
+
#
|
42
|
+
# @yield HTML that will be contained within the 'govuk-form-group' div
|
43
|
+
#
|
44
|
+
# @yieldparam displayed_error_message [ActiveSupport::SafeBuffer] the HTML for the error message (if there is one)
|
45
|
+
#
|
46
|
+
# @return [ActiveSupport::SafeBuffer]
|
47
|
+
|
48
|
+
def render
|
49
|
+
tag.div(**options[:attributes]) do
|
50
|
+
yield((ErrorMessage.new(message: error_message, attribute: attribute, context: context).render if error_message))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# The default attributes for the form group
|
55
|
+
|
56
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-form-group' }.freeze
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative '../../base'
|
2
|
+
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
class Header < Base
|
7
|
+
# = GOV.UK Header link
|
8
|
+
#
|
9
|
+
# The individual header link item
|
10
|
+
#
|
11
|
+
# @!attribute [r] text
|
12
|
+
# @return [String] Text for the header link
|
13
|
+
# @!attribute [r] href
|
14
|
+
# @return [String] The href for the header link
|
15
|
+
|
16
|
+
class Link < Base
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :text, :href
|
20
|
+
|
21
|
+
public
|
22
|
+
|
23
|
+
# @param text [String] the text for the header link
|
24
|
+
# @param href [String] the href for the header link
|
25
|
+
# @param options [Hash] options that will be used in customising the HTML
|
26
|
+
#
|
27
|
+
# @option options [Boolean] :active flag to mark the navigation item as active or not
|
28
|
+
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML
|
29
|
+
|
30
|
+
def initialize(text:, href: nil, **options)
|
31
|
+
super(**options)
|
32
|
+
|
33
|
+
@text = text
|
34
|
+
@href = href
|
35
|
+
end
|
36
|
+
|
37
|
+
# Generates the HTML for the GOV.UK Header link
|
38
|
+
#
|
39
|
+
# @return [ActiveSupport::SafeBuffer]
|
40
|
+
|
41
|
+
def render
|
42
|
+
tag.li(class: "govuk-header__navigation-item #{'govuk-header__navigation-item--active' if options[:active]}".rstrip) do
|
43
|
+
if href
|
44
|
+
options[:attributes][:class] = 'govuk-header__link'
|
45
|
+
|
46
|
+
link_to(text, href, **options[:attributes])
|
47
|
+
else
|
48
|
+
text
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require_relative 'link'
|
2
|
+
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
class Header < Base
|
7
|
+
# = GOV.UK Header navigation
|
8
|
+
#
|
9
|
+
# The header navigation section
|
10
|
+
#
|
11
|
+
# @!attribute [r] navigation_links
|
12
|
+
# @return [Array<Link>] An array of the initialised navigation links
|
13
|
+
# @!attribute [r] navigation_label
|
14
|
+
# @return [String] The aria label for the navigation
|
15
|
+
# @!attribute [r] navigation_classes
|
16
|
+
# @return [String] The classes for the navigation
|
17
|
+
# @!attribute [r] menu_button
|
18
|
+
# @return [Hash] The options for the menu button
|
19
|
+
|
20
|
+
class Navigation
|
21
|
+
include ActionView::Context
|
22
|
+
include ActionView::Helpers
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :navigation_links, :navigation_label, :navigation_classes, :menu_button
|
27
|
+
|
28
|
+
public
|
29
|
+
|
30
|
+
# @param navigation [Hash] options for the navigation
|
31
|
+
# @param context [ActionView::Base] the view context
|
32
|
+
# @param menu_button [Hash] options for the menu button
|
33
|
+
#
|
34
|
+
# @option navigation [Array] :items an array of links for the navigation section.
|
35
|
+
# See {Components::GovUK::Header::Link#initialize Link#initialize} for details of the items in the array.
|
36
|
+
# @option navigation [String] :classes additional CSS classes for the navigation HTML
|
37
|
+
# @option navigation [String] :label text for the aria-label attribute of the navigation. Defaults to the menu button text
|
38
|
+
#
|
39
|
+
# @option menu_button [String] :text text for the button that opens the mobile navigation menu.
|
40
|
+
# By default, this is set to +Menu+.
|
41
|
+
# @option menu_button [String] :label text for the aria-label attribute of the button that opens the mobile navigation.
|
42
|
+
# Defaults to +Show or hide menu+.
|
43
|
+
|
44
|
+
def initialize(navigation:, context:, menu_button: nil)
|
45
|
+
menu_button ||= {}
|
46
|
+
menu_button[:text] ||= 'Menu'
|
47
|
+
menu_button[:label] ||= 'Show or hide menu'
|
48
|
+
|
49
|
+
@menu_button = menu_button
|
50
|
+
@navigation_links = navigation[:items].map { |navigation_link| Link.new(context: context, **navigation_link) }
|
51
|
+
@navigation_label = navigation[:label] || menu_button[:text]
|
52
|
+
@navigation_classes = "govuk-header__navigation #{navigation[:classes]}".rstrip
|
53
|
+
end
|
54
|
+
|
55
|
+
# Generates the HTML for the GOV.UK Navigation
|
56
|
+
#
|
57
|
+
# @return [ActiveSupport::SafeBuffer]
|
58
|
+
|
59
|
+
def render
|
60
|
+
tag.nav(aria: { label: navigation_label }, class: navigation_classes) do
|
61
|
+
concat(button_tag(menu_button[:text], type: :button, class: 'govuk-header__menu-button govuk-js-header-toggle', aria: { controls: 'navigation', label: menu_button[:label] }, hidden: true))
|
62
|
+
concat(tag.ul(id: 'navigation', class: 'govuk-header__navigation-list') do
|
63
|
+
navigation_links.each { |navigation_link| concat(navigation_link.render) }
|
64
|
+
end)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
require_relative 'header/navigation'
|
3
|
+
|
4
|
+
module CCS
|
5
|
+
module Components
|
6
|
+
module GovUK
|
7
|
+
# = GOV.UK Header
|
8
|
+
#
|
9
|
+
# This is used to generate the header component from the
|
10
|
+
# {https://design-system.service.gov.uk/components/header GDS - Components - Header}
|
11
|
+
#
|
12
|
+
# @!attribute [r] navigation
|
13
|
+
# @return [Navigation] The initialised navigation section
|
14
|
+
# @!attribute [r] service
|
15
|
+
# @return [Hash] The options for the service section
|
16
|
+
|
17
|
+
class Header < Base
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :navigation, :service
|
21
|
+
|
22
|
+
public
|
23
|
+
|
24
|
+
# @param navigation [Hash] options for the navigation section of the header.
|
25
|
+
# See {Components::GovUK::Header::Navigation#initialize Navigation#initialize} for details of the options.
|
26
|
+
# @param menu_button [Hash] options for the menu button in the header.
|
27
|
+
# See {Components::GovUK::Header::Navigation#initialize Navigation#initialize} for details of the options.
|
28
|
+
# @param service [Hash] options for the service name
|
29
|
+
# @param options [Hash] options that will be used in customising the HTML
|
30
|
+
#
|
31
|
+
# @option service [String] :name the name of the service, included in the header
|
32
|
+
# @option service [String] :href URL for the service name anchor
|
33
|
+
#
|
34
|
+
# @option options [String] :classes additional CSS classes for the header HTML
|
35
|
+
# @option options [String] :container_classes classes for the container
|
36
|
+
# @option options [String] :homepage_url URL of the homepage. Defaults to +/+
|
37
|
+
# @option options [String] :product_name product name, used when the product name follows on directly from ‘GOV.UK
|
38
|
+
# @option options [Hash] :attributes additional attributes that will added as part of the header HTML
|
39
|
+
|
40
|
+
def initialize(navigation: nil, menu_button: nil, service: nil, **options)
|
41
|
+
super(**options)
|
42
|
+
|
43
|
+
@options[:attributes][:role] = 'banner'
|
44
|
+
@options[:container_classes] ||= 'govuk-width-container'
|
45
|
+
@options[:homepage_url] ||= '/'
|
46
|
+
|
47
|
+
@navigation = Navigation.new(navigation: navigation, menu_button: menu_button, context: @context) if navigation
|
48
|
+
@service = service
|
49
|
+
end
|
50
|
+
|
51
|
+
# Generates the HTML for the GOV.UK Header component
|
52
|
+
#
|
53
|
+
# @return [ActiveSupport::SafeBuffer]
|
54
|
+
|
55
|
+
def render
|
56
|
+
tag.header(**options[:attributes]) do
|
57
|
+
tag.div(class: "govuk-header__container #{options[:container_classes]}") do
|
58
|
+
concat(header_logo)
|
59
|
+
if service || navigation
|
60
|
+
concat(tag.div(class: 'govuk-header__content') do
|
61
|
+
concat(header_service_name) if service
|
62
|
+
concat(navigation.render) if navigation
|
63
|
+
end)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# The default attributes for the breadcrumbs
|
70
|
+
|
71
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-header', data: { module: 'govuk-header' } }.freeze
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
# Generates the logo for header
|
76
|
+
#
|
77
|
+
# @return [ActiveSupport::SafeBuffer]
|
78
|
+
|
79
|
+
def header_logo
|
80
|
+
tag.div(class: 'govuk-header__logo') do
|
81
|
+
link_to(options[:homepage_url], class: 'govuk-header__link govuk-header__link--homepage') do
|
82
|
+
concat(tag.span(class: 'govuk-header__logotype') do
|
83
|
+
concat(tag.svg(class: 'govuk-header__logotype-crown', xmlns: 'http://www.w3.org/2000/svg', height: '30', width: '36', aria: { hidden: 'true' }, focusable: 'false', viewBox: '0 0 132 97') do
|
84
|
+
tag.path(fill: 'currentColor', 'fill-rule': 'evenodd', d: 'M25 30.2c3.5 1.5 7.7-.2 9.1-3.7 1.5-3.6-.2-7.8-3.9-9.2-3.6-1.4-7.6.3-9.1 3.9-1.4 3.5.3 7.5 3.9 9zM9 39.5c3.6 1.5 7.8-.2 9.2-3.7 1.5-3.6-.2-7.8-3.9-9.1-3.6-1.5-7.6.2-9.1 3.8-1.4 3.5.3 7.5 3.8 9zM4.4 57.2c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.5-1.5-7.6.3-9.1 3.8-1.4 3.5.3 7.6 3.9 9.1zm38.3-21.4c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.6-1.5-7.6.3-9.1 3.8-1.3 3.6.4 7.7 3.9 9.1zm64.4-5.6c-3.6 1.5-7.8-.2-9.1-3.7-1.5-3.6.2-7.8 3.8-9.2 3.6-1.4 7.7.3 9.2 3.9 1.3 3.5-.4 7.5-3.9 9zm15.9 9.3c-3.6 1.5-7.7-.2-9.1-3.7-1.5-3.6.2-7.8 3.7-9.1 3.6-1.5 7.7.2 9.2 3.8 1.5 3.5-.3 7.5-3.8 9zm4.7 17.7c-3.6 1.5-7.8-.2-9.2-3.8-1.5-3.6.2-7.7 3.9-9.1 3.6-1.5 7.7.3 9.2 3.8 1.3 3.5-.4 7.6-3.9 9.1zM89.3 35.8c-3.6 1.5-7.8-.2-9.2-3.8-1.4-3.6.2-7.7 3.9-9.1 3.6-1.5 7.7.3 9.2 3.8 1.4 3.6-.3 7.7-3.9 9.1zM69.7 17.7l8.9 4.7V9.3l-8.9 2.8c-.2-.3-.5-.6-.9-.9L72.4 0H59.6l3.5 11.2c-.3.3-.6.5-.9.9l-8.8-2.8v13.1l8.8-4.7c.3.3.6.7.9.9l-5 15.4v.1c-.2.8-.4 1.6-.4 2.4 0 4.1 3.1 7.5 7 8.1h.2c.3 0 .7.1 1 .1.4 0 .7 0 1-.1h.2c4-.6 7.1-4.1 7.1-8.1 0-.8-.1-1.7-.4-2.4V34l-5.1-15.4c.4-.2.7-.6 1-.9zM66 92.8c16.9 0 32.8 1.1 47.1 3.2 4-16.9 8.9-26.7 14-33.5l-9.6-3.4c1 4.9 1.1 7.2 0 10.2-1.5-1.4-3-4.3-4.2-8.7L108.6 76c2.8-2 5-3.2 7.5-3.3-4.4 9.4-10 11.9-13.6 11.2-4.3-.8-6.3-4.6-5.6-7.9 1-4.7 5.7-5.9 8-.5 4.3-8.7-3-11.4-7.6-8.8 7.1-7.2 7.9-13.5 2.1-21.1-8 6.1-8.1 12.3-4.5 20.8-4.7-5.4-12.1-2.5-9.5 6.2 3.4-5.2 7.9-2 7.2 3.1-.6 4.3-6.4 7.8-13.5 7.2-10.3-.9-10.9-8-11.2-13.8 2.5-.5 7.1 1.8 11 7.3L80.2 60c-4.1 4.4-8 5.3-12.3 5.4 1.4-4.4 8-11.6 8-11.6H55.5s6.4 7.2 7.9 11.6c-4.2-.1-8-1-12.3-5.4l1.4 16.4c3.9-5.5 8.5-7.7 10.9-7.3-.3 5.8-.9 12.8-11.1 13.8-7.2.6-12.9-2.9-13.5-7.2-.7-5 3.8-8.3 7.1-3.1 2.7-8.7-4.6-11.6-9.4-6.2 3.7-8.5 3.6-14.7-4.6-20.8-5.8 7.6-5 13.9 2.2 21.1-4.7-2.6-11.9.1-7.7 8.8 2.3-5.5 7.1-4.2 8.1.5.7 3.3-1.3 7.1-5.7 7.9-3.5.7-9-1.8-13.5-11.2 2.5.1 4.7 1.3 7.5 3.3l-4.7-15.4c-1.2 4.4-2.7 7.2-4.3 8.7-1.1-3-.9-5.3 0-10.2l-9.5 3.4c5 6.9 9.9 16.7 14 33.5 14.8-2.1 30.8-3.2 47.7-3.2z')
|
85
|
+
end)
|
86
|
+
concat(tag.span('GOV.UK', class: 'govuk-header__logotype-text'))
|
87
|
+
end)
|
88
|
+
concat(tag.span(options[:product_name], class: 'govuk-header__product-name')) if options[:product_name]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Generates the service name section
|
94
|
+
#
|
95
|
+
# @return [ActiveSupport::SafeBuffer]
|
96
|
+
|
97
|
+
def header_service_name
|
98
|
+
if service[:href]
|
99
|
+
link_to(service[:name], service[:href], class: 'govuk-header__link govuk-header__service-name')
|
100
|
+
else
|
101
|
+
tag.span(service[:name], class: 'govuk-header__service-name')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
# = GOV.UK Hint
|
7
|
+
#
|
8
|
+
# This is used to generate the hint text component from the Government Design Systems
|
9
|
+
#
|
10
|
+
# @!attribute [r] text
|
11
|
+
# @return [String] Text for the hint
|
12
|
+
|
13
|
+
class Hint < Base
|
14
|
+
private
|
15
|
+
|
16
|
+
attr_reader :text
|
17
|
+
|
18
|
+
public
|
19
|
+
|
20
|
+
# @param text [String] the hint text.
|
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 hint HTML
|
25
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
26
|
+
|
27
|
+
def initialize(text: nil, **options)
|
28
|
+
super(**options)
|
29
|
+
|
30
|
+
@text = text
|
31
|
+
end
|
32
|
+
|
33
|
+
# Generates the HTML for the GOV.UK Hint component
|
34
|
+
#
|
35
|
+
# @return [ActiveSupport::SafeBuffer]
|
36
|
+
|
37
|
+
def render
|
38
|
+
tag.div(**options[:attributes]) do
|
39
|
+
text || yield
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# The default attributes for the hint
|
44
|
+
|
45
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-hint' }.freeze
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
# = GOV.UK Inset Text
|
7
|
+
#
|
8
|
+
# This is used to generate the inset text component from the
|
9
|
+
# {https://design-system.service.gov.uk/components/inset-text GDS - Components - Inset text}
|
10
|
+
#
|
11
|
+
# @!attribute [r] text
|
12
|
+
# @return [String] Text for the inset text
|
13
|
+
|
14
|
+
class InsetText < Base
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :text
|
18
|
+
|
19
|
+
public
|
20
|
+
|
21
|
+
# @param text [String] text to use within the inset text component.
|
22
|
+
# If nil, then a block will be rendered
|
23
|
+
# @param options [Hash] options that will be used in customising the HTML
|
24
|
+
#
|
25
|
+
# @option options [String] :classes additional CSS classes for the inset text HTML
|
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 Inset text component
|
35
|
+
#
|
36
|
+
# @yield HTML that will be contained within the inset text div. Ignored if inset text is given
|
37
|
+
#
|
38
|
+
# @return [ActiveSupport::SafeBuffer]
|
39
|
+
|
40
|
+
def render
|
41
|
+
tag.div(**options[:attributes]) do
|
42
|
+
text || yield
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# The default attributes for the inset text
|
47
|
+
|
48
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-inset-text' }.freeze
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
# = GOV.UK Label
|
7
|
+
#
|
8
|
+
# This is used to generate the label component from the Government Design Systems
|
9
|
+
#
|
10
|
+
# @!attribute [r] attribute
|
11
|
+
# @return [String, Symbol] Attribute of the input that requires a label
|
12
|
+
# @!attribute [r] text
|
13
|
+
# @return [String] Text for the label
|
14
|
+
# @!attribute [r] form
|
15
|
+
# @return [ActionView::Helpers::FormBuilder] Form builder used to create the label
|
16
|
+
|
17
|
+
class Label < Base
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :attribute, :text, :form
|
21
|
+
|
22
|
+
public
|
23
|
+
|
24
|
+
# @param attribute [String, Symbol] the attribute of the input that requires a label
|
25
|
+
# @param text [String] (nil) the text for the label
|
26
|
+
# If nil, then a block will be rendered
|
27
|
+
# @param form [ActionView::Helpers::FormBuilder] (nil) optional form builder used to create the label
|
28
|
+
# @param options [Hash] options that will be used in customising the HTML
|
29
|
+
#
|
30
|
+
# @option options [String] :classes additional CSS classes for the label HTML
|
31
|
+
# @option options [Boolean] :is_page_heading (false) if the label is also the heading it will rendered in a h1
|
32
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
33
|
+
|
34
|
+
def initialize(attribute:, text: nil, form: nil, **options)
|
35
|
+
super(**options)
|
36
|
+
|
37
|
+
@attribute = attribute
|
38
|
+
@text = text
|
39
|
+
@form = form
|
40
|
+
end
|
41
|
+
|
42
|
+
# Generates the HTML for the GOV.UK label component
|
43
|
+
#
|
44
|
+
# @yield HTML that will be generated for the label
|
45
|
+
#
|
46
|
+
# @return [ActiveSupport::SafeBuffer]
|
47
|
+
|
48
|
+
def render(&block)
|
49
|
+
if options[:is_page_heading]
|
50
|
+
tag.h1(class: 'govuk-label-wrapper') do
|
51
|
+
label_html(&block)
|
52
|
+
end
|
53
|
+
else
|
54
|
+
label_html(&block)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# The default attributes for the label
|
59
|
+
|
60
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-label' }.freeze
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
# Generates the HTML for the label.
|
65
|
+
# If +:form+ attribute is present, it will be used to generate the label tag
|
66
|
+
#
|
67
|
+
# @yield HTML that will be used in the label. Ignored if text is passed.
|
68
|
+
#
|
69
|
+
# @return [ActiveSupport::SafeBuffer]
|
70
|
+
|
71
|
+
def label_html
|
72
|
+
if form
|
73
|
+
form.label(attribute, **options[:attributes]) do
|
74
|
+
text || yield
|
75
|
+
end
|
76
|
+
else
|
77
|
+
label_tag(attribute, **options[:attributes]) do
|
78
|
+
text || yield
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|