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,55 @@
|
|
1
|
+
require_relative '../field'
|
2
|
+
require_relative '../fieldset'
|
3
|
+
|
4
|
+
module CCS::Components
|
5
|
+
module GovUK
|
6
|
+
class Field < Base
|
7
|
+
# = GOV.UK Field Inputs
|
8
|
+
#
|
9
|
+
# This class is used to create a form for a list of fields, e.g. radios or checkboxes.
|
10
|
+
# It will wrap the inputs in the form group and then the fieldset and:
|
11
|
+
# - display the hint (if there is one)
|
12
|
+
# - find and display the error message (if there is one)
|
13
|
+
#
|
14
|
+
# @!attribute [r] fieldset
|
15
|
+
# @return [Fieldset] The initialised fieldset
|
16
|
+
|
17
|
+
class Inputs < Field
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :fieldset
|
21
|
+
|
22
|
+
public
|
23
|
+
|
24
|
+
# @param (see CCS::Components::GovUK::Field#initialize)
|
25
|
+
# @param fieldset [Hash] attributes for the fieldset, see {CCS::Components::GovUK::Fieldset#initialize Fieldset#initialize} for more details.
|
26
|
+
#
|
27
|
+
# @option (see CCS::Components::GovUK::Field#initialize)
|
28
|
+
|
29
|
+
def initialize(attribute:, fieldset:, **options)
|
30
|
+
super(attribute: attribute, **options)
|
31
|
+
|
32
|
+
set_described_by(fieldset, @attribute, @error_message, options[:hint])
|
33
|
+
|
34
|
+
@fieldset = Fieldset.new(context: @context, **fieldset)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Generates the HTML to wrap arround a GDS form component
|
38
|
+
#
|
39
|
+
# @yield (see CCS::Components::GovUK::Field#render)
|
40
|
+
#
|
41
|
+
# @return [ActiveSupport::SafeBuffer]
|
42
|
+
|
43
|
+
def render
|
44
|
+
super() do |display_error_message|
|
45
|
+
fieldset.render do
|
46
|
+
concat(hint.render) if hint
|
47
|
+
concat(display_error_message)
|
48
|
+
concat(yield)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
require_relative 'form_group'
|
3
|
+
require_relative 'hint'
|
4
|
+
|
5
|
+
module CCS::Components
|
6
|
+
module GovUK
|
7
|
+
# = GOV.UK Field
|
8
|
+
#
|
9
|
+
# This class is used to create a form using the structure of a GDS input field components, e.g. text input.
|
10
|
+
# It will wrap the input within the form group as well as find if there are any error messages to display.
|
11
|
+
#
|
12
|
+
# @!attribute [r] attribute
|
13
|
+
# @return [String,Symbol] The attribute of the field
|
14
|
+
# @!attribute [r] error_message
|
15
|
+
# @return [String] The error message for the field
|
16
|
+
# @!attribute [r] form_group
|
17
|
+
# @return [FormGroup] The initialised form group
|
18
|
+
# @!attribute [r] hint
|
19
|
+
# @return [Hint] The initialised hint
|
20
|
+
|
21
|
+
class Field < Base
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :attribute, :error_message, :form_group, :hint
|
25
|
+
|
26
|
+
public
|
27
|
+
|
28
|
+
# @param attribute [String, Symbol] the attribute of the field
|
29
|
+
# @param hint [Hash] attributes for the hint, see {CCS::Components::GovUK::Hint#initialize Hint#initialize} for more details.
|
30
|
+
# If no hint is given then no hint will be rendered
|
31
|
+
# @param form_group [Hash] attributes for the form group, see {CCS::Components::GovUK::FormGroup#initialize FormGroup#initialize} for more details.
|
32
|
+
# @param options [Hash] options that will be used for the parts of the field
|
33
|
+
#
|
34
|
+
# @option options [String] :error_message (nil) the error message to be displayed
|
35
|
+
# @option options [ActiveModel] :model (nil) optional model that can be used to find an error message
|
36
|
+
# @option options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
|
37
|
+
# the field and find the error message
|
38
|
+
# @option options [String] :classes additional CSS classes for the field HTML
|
39
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
40
|
+
|
41
|
+
def initialize(attribute:, form_group: nil, hint: nil, **options)
|
42
|
+
super(**options)
|
43
|
+
|
44
|
+
(hint[:attributes] ||= {})[:id] = "#{attribute}-hint" if hint && !hint.dig(:attributes, :id)
|
45
|
+
|
46
|
+
@attribute = attribute
|
47
|
+
@error_message = find_error_message(attribute)
|
48
|
+
|
49
|
+
@form_group = FormGroup.new(attribute: attribute, error_message: @error_message, context: @context, **(form_group || {}))
|
50
|
+
@hint = Hint.new(context: @context, **hint) if hint
|
51
|
+
end
|
52
|
+
|
53
|
+
# Generates the HTML to wrap arround a GDS form input component
|
54
|
+
#
|
55
|
+
# @yield the field HTML
|
56
|
+
#
|
57
|
+
# @yieldparam displayed_error_message [ActiveSupport::SafeBuffer] the error message HTML to display
|
58
|
+
#
|
59
|
+
# @return [ActiveSupport::SafeBuffer]
|
60
|
+
|
61
|
+
def render(&block)
|
62
|
+
form_group.render(&block)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
# If one is present it will find the error message text for the field
|
68
|
+
#
|
69
|
+
# @param attribute [String, Symbol] the attribute of the field
|
70
|
+
#
|
71
|
+
# @return [String]
|
72
|
+
|
73
|
+
def find_error_message(attribute)
|
74
|
+
if @options[:model]
|
75
|
+
@options[:model].errors[attribute].first
|
76
|
+
elsif options[:form]
|
77
|
+
@options[:form].object.errors[attribute].first
|
78
|
+
else
|
79
|
+
@options[:error_message]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Adds the aira-describedby attribute for the field
|
84
|
+
# if there is a hint or an error message
|
85
|
+
#
|
86
|
+
# @param field_options [Hash] the hash with the options to add the aria described by to
|
87
|
+
# @param attribute [String, Symbol] the attribute of the field
|
88
|
+
# @param error_message [String] used to indicate if there is an error
|
89
|
+
# @param hint [Hash] the hint attributes
|
90
|
+
|
91
|
+
def set_described_by(field_options, attribute, error_message, hint)
|
92
|
+
aria_described_by = [
|
93
|
+
field_options.dig(:attributes, :aria, :describedby),
|
94
|
+
(hint[:attributes][:id] if hint),
|
95
|
+
("#{attribute}-error" if error_message)
|
96
|
+
].compact
|
97
|
+
|
98
|
+
return unless aria_described_by.any?
|
99
|
+
|
100
|
+
((field_options[:attributes] ||= {})[:aria] ||= {})[:describedby] = aria_described_by.join(' ')
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
ActionView::Base.field_error_proc = proc { |html_tag, _instance| html_tag }
|
106
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative '../../base'
|
2
|
+
|
3
|
+
module CCS::Components
|
4
|
+
module GovUK
|
5
|
+
class Fieldset < Base
|
6
|
+
# = GOV.UK Fieldset Legend
|
7
|
+
#
|
8
|
+
# The legend for the fieldset
|
9
|
+
#
|
10
|
+
# @!attribute [r] text
|
11
|
+
# @return [String] Text for the fieldset legend
|
12
|
+
# @!attribute [r] is_page_heading
|
13
|
+
# @return [Boolean] Flag to indicate of the legend is a the page heading
|
14
|
+
# @!attribute [r] caption
|
15
|
+
# @return [Hash] The class for the li elements
|
16
|
+
|
17
|
+
class Legend < Base
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :text, :is_page_heading, :caption
|
21
|
+
|
22
|
+
public
|
23
|
+
|
24
|
+
# @param text [String] the text for the fieldset legend
|
25
|
+
# @param is_page_heading [Boolean] if the legend is also the heading it will rendered in a h1
|
26
|
+
# @param caption [String] options for the caption to be rendered above the heading if +:is_page_heading+ is true
|
27
|
+
# @param options [Hash] options that will be used in customising the HTML
|
28
|
+
#
|
29
|
+
# @option options [String] :classes additional CSS classes for the legend HTML
|
30
|
+
#
|
31
|
+
# @option caption [String] :text text for the caption
|
32
|
+
# @option caption [String] :classes additional CSS classes for the caption HTML
|
33
|
+
|
34
|
+
def initialize(text:, is_page_heading: nil, caption: nil, **options)
|
35
|
+
super(**options)
|
36
|
+
|
37
|
+
@text = text
|
38
|
+
@is_page_heading = is_page_heading
|
39
|
+
@caption = caption
|
40
|
+
end
|
41
|
+
|
42
|
+
# Generates the HTML for the GOV.UK Fieldset legend
|
43
|
+
#
|
44
|
+
# @return [ActiveSupport::SafeBuffer]
|
45
|
+
|
46
|
+
def render
|
47
|
+
tag.legend(class: options[:attributes][:class]) do
|
48
|
+
if is_page_heading
|
49
|
+
concat(tag.span(caption[:text], class: caption[:classes])) if caption
|
50
|
+
concat(tag.h1(text, class: 'govuk-fieldset__heading'))
|
51
|
+
else
|
52
|
+
text
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# The default attributes for the fieldset legend
|
58
|
+
|
59
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-fieldset__legend' }.freeze
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
require_relative 'fieldset/legend'
|
3
|
+
|
4
|
+
module CCS::Components
|
5
|
+
module GovUK
|
6
|
+
# = GOV.UK Fieldset
|
7
|
+
#
|
8
|
+
# This is used to generate the fieldset component from the
|
9
|
+
# {https://design-system.service.gov.uk/components/fieldset GDS - Components - Fieldset}
|
10
|
+
#
|
11
|
+
# @!attribute [r] legend
|
12
|
+
# @return [Legend] Initialised fieldset legend
|
13
|
+
|
14
|
+
class Fieldset < Base
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :legend
|
18
|
+
|
19
|
+
public
|
20
|
+
|
21
|
+
# @param legend [Hash] options for the fieldset legend.
|
22
|
+
# See {Components::GovUK::Fieldset::Legend#initialize Legend#initialize} for details of the options.
|
23
|
+
# @param options [Hash] options that will be used in customising the HTML
|
24
|
+
#
|
25
|
+
# @option options [String] :classes additional CSS classes for the fieldset HTML
|
26
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
27
|
+
|
28
|
+
def initialize(legend: nil, **options)
|
29
|
+
super(**options)
|
30
|
+
|
31
|
+
@legend = Legend.new(context: @context, **legend) if legend
|
32
|
+
end
|
33
|
+
|
34
|
+
# Generates the HTML for the GOV.UK Fieldset component
|
35
|
+
#
|
36
|
+
# @yield HTML that will be contained within the 'govuk-fieldset' div and under the legend
|
37
|
+
#
|
38
|
+
# @return [ActiveSupport::SafeBuffer]
|
39
|
+
|
40
|
+
def render
|
41
|
+
tag.fieldset(**options[:attributes]) do
|
42
|
+
concat(legend.render) if legend
|
43
|
+
yield
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# The default attributes for the fieldset
|
48
|
+
|
49
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-fieldset' }.freeze
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require_relative '../../base'
|
2
|
+
|
3
|
+
module CCS::Components
|
4
|
+
module GovUK
|
5
|
+
class Footer < Base
|
6
|
+
# = GOV.UK Footer link
|
7
|
+
#
|
8
|
+
# The individual footer footer link item
|
9
|
+
#
|
10
|
+
# @!attribute [r] text
|
11
|
+
# @return [String] Text for the footer link
|
12
|
+
# @!attribute [r] href
|
13
|
+
# @return [String] The href for the footer link
|
14
|
+
# @!attribute [r] li_class
|
15
|
+
# @return [String] The class for the li elements
|
16
|
+
|
17
|
+
class Link < Base
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :text, :href, :li_class
|
21
|
+
|
22
|
+
public
|
23
|
+
|
24
|
+
# @param text [String] the text for the footer link
|
25
|
+
# @param href [String] the href for the footer link
|
26
|
+
# @param li_class [String] class for the li elements
|
27
|
+
# @param options [Hash] options that will be used in customising the HTML
|
28
|
+
#
|
29
|
+
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML
|
30
|
+
|
31
|
+
def initialize(text:, href:, li_class:, **options)
|
32
|
+
super(**options)
|
33
|
+
|
34
|
+
@text = text
|
35
|
+
@href = href
|
36
|
+
@li_class = li_class
|
37
|
+
end
|
38
|
+
|
39
|
+
# Generates the HTML for the GOV.UK Footer link
|
40
|
+
#
|
41
|
+
# @return [ActiveSupport::SafeBuffer]
|
42
|
+
|
43
|
+
def render
|
44
|
+
tag.li(class: li_class) do
|
45
|
+
options[:attributes][:class] = 'govuk-footer__link'
|
46
|
+
|
47
|
+
link_to(text, href, **options[:attributes])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative '../../base'
|
2
|
+
require_relative 'link'
|
3
|
+
|
4
|
+
module CCS::Components
|
5
|
+
module GovUK
|
6
|
+
class Footer < Base
|
7
|
+
# = GOV.UK Footer Meta
|
8
|
+
#
|
9
|
+
# The footer meta section
|
10
|
+
#
|
11
|
+
# @!attribute [r] meta_links
|
12
|
+
# @return [Array<Link>] An array of the initialised meta links
|
13
|
+
# @!attribute [r] visually_hidden_title
|
14
|
+
# @return [String] Title for the meta section
|
15
|
+
# @!attribute [r] text
|
16
|
+
# @return [String] Text to add to the meta section of the footer
|
17
|
+
|
18
|
+
class Meta
|
19
|
+
include ActionView::Context
|
20
|
+
include ActionView::Helpers
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :meta_links, :visually_hidden_title, :text
|
25
|
+
|
26
|
+
public
|
27
|
+
|
28
|
+
# @param items [Array<Hash>] an array of links for the meta section.
|
29
|
+
# See {Components::GovUK::Footer::Link#initialize Link#initialize} for details of the items in the array.
|
30
|
+
# @param visually_hidden_title [String] ('Support links') title for the meta section
|
31
|
+
# @param text [String] text to add to the meta section of the footer
|
32
|
+
# @param context [ActionView::Base] the view context
|
33
|
+
|
34
|
+
def initialize(context:, items: nil, visually_hidden_title: nil, text: nil)
|
35
|
+
@meta_links = items&.map { |meta_link| Link.new(li_class: 'govuk-footer__inline-list-item', context: context, **meta_link) }
|
36
|
+
@visually_hidden_title = visually_hidden_title || 'Support links'
|
37
|
+
@text = text
|
38
|
+
end
|
39
|
+
|
40
|
+
# Generates the HTML for the GOV.UK Footer Meta sections
|
41
|
+
#
|
42
|
+
# @return [ActiveSupport::SafeBuffer]
|
43
|
+
|
44
|
+
def render
|
45
|
+
capture do
|
46
|
+
concat(tag.h2(visually_hidden_title, class: 'govuk-visually-hidden'))
|
47
|
+
if meta_links
|
48
|
+
concat(tag.ul(class: 'govuk-footer__inline-list') do
|
49
|
+
meta_links.each { |meta_link| concat(meta_link.render) }
|
50
|
+
end)
|
51
|
+
end
|
52
|
+
concat(tag.div(text, class: 'govuk-footer__meta-custom')) if text
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative '../../base'
|
2
|
+
require_relative 'link'
|
3
|
+
|
4
|
+
module CCS::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
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
require_relative 'footer/navigation'
|
3
|
+
require_relative 'footer/meta'
|
4
|
+
|
5
|
+
module CCS::Components
|
6
|
+
module GovUK
|
7
|
+
# = GOV.UK Footer
|
8
|
+
#
|
9
|
+
# This is used to generate the footer component from the
|
10
|
+
# {https://design-system.service.gov.uk/components/footer GDS - Components - Footer}
|
11
|
+
#
|
12
|
+
# @!attribute [r] navigation
|
13
|
+
# @return [Array<Navigation>] An array of the initialised navigation sections
|
14
|
+
# @!attribute [r] meta
|
15
|
+
# @return [Meta] The initialised meta section
|
16
|
+
|
17
|
+
class Footer < Base
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :navigation, :meta
|
21
|
+
|
22
|
+
public
|
23
|
+
|
24
|
+
# @param navigation [Array<Hash>] an array of sections for the footer navigation.
|
25
|
+
# See {Components::GovUK::Footer::Navigation#initialize Navigation#initialize} for details of the items in the array.
|
26
|
+
# @param meta [Hash] ptions for the meta section of the footer.
|
27
|
+
# See {Components::GovUK::Footer::Meta#initialize Meta#initialize} for details of the options.
|
28
|
+
# @param options [Hash] options that will be used in customising the HTML
|
29
|
+
#
|
30
|
+
# @option options [String] :classes additional CSS classes for the footer HTML
|
31
|
+
# @option options [String] :container_class classes that can be added to the inner container
|
32
|
+
# @option options [ActiveSupport::SafeBuffer,String] :content_licence The content licence information, see {CCS::Components::GovUK::Footer#footer_content_licence footer_content_licence} for default
|
33
|
+
# @option options [ActiveSupport::SafeBuffer,String] :copyright The copyright information, (default: '© Crown copyright')
|
34
|
+
# @option options [Hash] :attributes additional attributes that will added as part of the HTML
|
35
|
+
|
36
|
+
def initialize(navigation: nil, meta: nil, **options)
|
37
|
+
super(**options)
|
38
|
+
|
39
|
+
@options[:attributes][:role] = 'contentinfo'
|
40
|
+
@options[:copyright] ||= '© Crown copyright'
|
41
|
+
|
42
|
+
@navigation = navigation&.map { |navigation_item| Navigation.new(context: @context, **navigation_item) }
|
43
|
+
@meta = Meta.new(context: @context, **meta) if meta
|
44
|
+
end
|
45
|
+
|
46
|
+
# rubocop:disable Metrics/AbcSize
|
47
|
+
|
48
|
+
# Generates the HTML for the GOV.UK Footer component
|
49
|
+
#
|
50
|
+
# @return [ActiveSupport::SafeBuffer]
|
51
|
+
|
52
|
+
def render
|
53
|
+
tag.footer(**options[:attributes]) do
|
54
|
+
tag.div(class: "govuk-width-container #{options[:container_classes]}".rstrip) do
|
55
|
+
if navigation
|
56
|
+
concat(tag.div(class: 'govuk-footer__navigation') do
|
57
|
+
navigation.each { |navigation_item| concat(navigation_item.render) }
|
58
|
+
end)
|
59
|
+
concat(tag.hr(class: 'govuk-footer__section-break'))
|
60
|
+
end
|
61
|
+
concat(tag.div(class: 'govuk-footer__meta') do
|
62
|
+
concat(tag.div(class: 'govuk-footer__meta-item govuk-footer__meta-item--grow') do
|
63
|
+
concat(meta.render) if meta
|
64
|
+
concat(footer_logo)
|
65
|
+
concat(footer_content_licence)
|
66
|
+
end)
|
67
|
+
concat(footer_copyright)
|
68
|
+
end)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# rubocop:enable Metrics/AbcSize
|
74
|
+
|
75
|
+
# The default attributes for the breadcrumbs
|
76
|
+
|
77
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-footer' }.freeze
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
# Generates the logo used in the footer
|
82
|
+
#
|
83
|
+
# @return [ActiveSupport::SafeBuffer]
|
84
|
+
|
85
|
+
def footer_logo
|
86
|
+
tag.svg(
|
87
|
+
class: 'govuk-footer__licence-logo',
|
88
|
+
aria: { hidden: 'true' },
|
89
|
+
focusable: 'false',
|
90
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
91
|
+
viewBox: '0 0 483.2 195.7',
|
92
|
+
height: '17',
|
93
|
+
width: '41'
|
94
|
+
) do
|
95
|
+
tag.path(
|
96
|
+
fill: 'currentColor',
|
97
|
+
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'
|
98
|
+
)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Generates the content licence for the footer
|
103
|
+
#
|
104
|
+
# @return [ActiveSupport::SafeBuffer]
|
105
|
+
|
106
|
+
def footer_content_licence
|
107
|
+
tag.span(class: 'govuk-footer__licence-description') do
|
108
|
+
if options[:content_licence]
|
109
|
+
concat(options[:content_licence])
|
110
|
+
else
|
111
|
+
concat('All content is available under the')
|
112
|
+
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'))
|
113
|
+
concat(', except where otherwise stated')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# Generates the copyright used in the footer
|
119
|
+
#
|
120
|
+
# @return [ActiveSupport::SafeBuffer]
|
121
|
+
|
122
|
+
def footer_copyright
|
123
|
+
tag.div(class: 'govuk-footer__meta-item') do
|
124
|
+
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')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative '../base'
|
2
|
+
require_relative 'error_message'
|
3
|
+
|
4
|
+
module CCS::Components
|
5
|
+
module GovUK
|
6
|
+
# = GOV.UK FormGroup
|
7
|
+
#
|
8
|
+
# This helper is used for generating the form group component from the Government Design Systems
|
9
|
+
#
|
10
|
+
# @!attribute [r] attribute
|
11
|
+
# @return [String,Symbol] Attribute that the form group is for
|
12
|
+
# @!attribute [r] error_message
|
13
|
+
# @return [String] Text for the error message
|
14
|
+
|
15
|
+
class FormGroup < Base
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :attribute, :error_message
|
19
|
+
|
20
|
+
public
|
21
|
+
|
22
|
+
# @param attribute [String,Symbol] the attribute that the form group is for
|
23
|
+
# @param error_message [String] (nil) the error message to be displayed
|
24
|
+
# @param options [Hash] options that will be used in customising the HTML
|
25
|
+
#
|
26
|
+
# @option options [String] :classes additional CSS classes for the form group HTML
|
27
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
28
|
+
|
29
|
+
def initialize(attribute:, error_message: nil, **options)
|
30
|
+
super(**options)
|
31
|
+
|
32
|
+
@options[:attributes][:id] ||= "#{attribute}-form-group"
|
33
|
+
@options[:attributes][:class][..15] = 'govuk-form-group govuk-form-group--error' if error_message
|
34
|
+
|
35
|
+
@attribute = attribute
|
36
|
+
@error_message = error_message
|
37
|
+
end
|
38
|
+
|
39
|
+
# Generates the HTML for the GOV.UK Form Group component
|
40
|
+
#
|
41
|
+
# @yield HTML that will be contained within the 'govuk-form-group' div
|
42
|
+
#
|
43
|
+
# @yieldparam displayed_error_message [ActiveSupport::SafeBuffer] the HTML for the error message (if there is one)
|
44
|
+
#
|
45
|
+
# @return [ActiveSupport::SafeBuffer]
|
46
|
+
|
47
|
+
def render
|
48
|
+
tag.div(**options[:attributes]) do
|
49
|
+
yield((ErrorMessage.new(message: error_message, attribute: attribute, context: context).render if error_message))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# The default attributes for the form group
|
54
|
+
|
55
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-form-group' }.freeze
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative '../../base'
|
2
|
+
|
3
|
+
module CCS::Components
|
4
|
+
module GovUK
|
5
|
+
class Header < Base
|
6
|
+
# = GOV.UK Header link
|
7
|
+
#
|
8
|
+
# The individual header link item
|
9
|
+
#
|
10
|
+
# @!attribute [r] text
|
11
|
+
# @return [String] Text for the header link
|
12
|
+
# @!attribute [r] href
|
13
|
+
# @return [String] The href for the header link
|
14
|
+
|
15
|
+
class Link < Base
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :text, :href
|
19
|
+
|
20
|
+
public
|
21
|
+
|
22
|
+
# @param text [String] the text for the header link
|
23
|
+
# @param href [String] the href for the header link
|
24
|
+
# @param options [Hash] options that will be used in customising the HTML
|
25
|
+
#
|
26
|
+
# @option options [Boolean] :active flag to mark the navigation item as active or not
|
27
|
+
# @option options [Hash] :attributes any additional attributes that will added as part of the HTML
|
28
|
+
|
29
|
+
def initialize(text:, href: nil, **options)
|
30
|
+
super(**options)
|
31
|
+
|
32
|
+
@text = text
|
33
|
+
@href = href
|
34
|
+
end
|
35
|
+
|
36
|
+
# Generates the HTML for the GOV.UK Header link
|
37
|
+
#
|
38
|
+
# @return [ActiveSupport::SafeBuffer]
|
39
|
+
|
40
|
+
def render
|
41
|
+
tag.li(class: "govuk-header__navigation-item #{'govuk-header__navigation-item--active' if options[:active]}".rstrip) do
|
42
|
+
if href
|
43
|
+
options[:attributes][:class] = 'govuk-header__link'
|
44
|
+
|
45
|
+
link_to(text, href, **options[:attributes])
|
46
|
+
else
|
47
|
+
text
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|