ccs-frontend_helpers 0.1.0.rc.2 → 0.1.0.rc.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/Gemfile.lock +1 -1
- data/lib/ccs/components/ccs/dashboard_section/panel.rb +43 -41
- data/lib/ccs/components/ccs/dashboard_section.rb +50 -48
- data/lib/ccs/components/ccs/footer/link.rb +41 -39
- data/lib/ccs/components/ccs/footer/meta.rb +49 -48
- data/lib/ccs/components/ccs/footer/navigation.rb +51 -50
- data/lib/ccs/components/ccs/footer.rb +69 -67
- data/lib/ccs/components/ccs/header/link.rb +47 -45
- data/lib/ccs/components/ccs/header/navigation.rb +85 -84
- data/lib/ccs/components/ccs/header/service_authentication.rb +35 -34
- data/lib/ccs/components/ccs/header.rb +87 -85
- data/lib/ccs/components/ccs/logo.rb +36 -34
- data/lib/ccs/components/govuk/accordion/section/content.rb +42 -42
- data/lib/ccs/components/govuk/accordion/section/header.rb +48 -48
- data/lib/ccs/components/govuk/accordion/section.rb +49 -48
- data/lib/ccs/components/govuk/accordion.rb +43 -41
- data/lib/ccs/components/govuk/back_link.rb +39 -37
- data/lib/ccs/components/govuk/breadcrumbs/link.rb +42 -40
- data/lib/ccs/components/govuk/breadcrumbs.rb +40 -38
- data/lib/ccs/components/govuk/button.rb +83 -81
- data/lib/ccs/components/govuk/cookie_banner/action.rb +45 -43
- data/lib/ccs/components/govuk/cookie_banner/message.rb +57 -55
- data/lib/ccs/components/govuk/cookie_banner.rb +40 -38
- data/lib/ccs/components/govuk/details.rb +38 -36
- data/lib/ccs/components/govuk/error_message.rb +46 -44
- data/lib/ccs/components/govuk/error_summary/item.rb +41 -39
- data/lib/ccs/components/govuk/error_summary.rb +49 -47
- data/lib/ccs/components/govuk/field/input/character_count.rb +101 -99
- data/lib/ccs/components/govuk/field/input/file_upload.rb +29 -27
- data/lib/ccs/components/govuk/field/input/select.rb +61 -59
- data/lib/ccs/components/govuk/field/input/text_input/fix.rb +39 -37
- data/lib/ccs/components/govuk/field/input/text_input.rb +75 -73
- data/lib/ccs/components/govuk/field/input/textarea.rb +43 -41
- data/lib/ccs/components/govuk/field/input.rb +46 -44
- data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +43 -41
- data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +48 -46
- data/lib/ccs/components/govuk/field/inputs/date_input.rb +68 -66
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +29 -27
- data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +26 -24
- data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +32 -30
- data/lib/ccs/components/govuk/field/inputs/item/divider.rb +39 -37
- data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +27 -25
- data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +26 -24
- data/lib/ccs/components/govuk/field/inputs/item/radio.rb +32 -30
- data/lib/ccs/components/govuk/field/inputs/item.rb +100 -98
- data/lib/ccs/components/govuk/field/inputs/radios.rb +43 -41
- data/lib/ccs/components/govuk/field/inputs.rb +42 -40
- data/lib/ccs/components/govuk/field.rb +90 -88
- data/lib/ccs/components/govuk/fieldset/legend.rb +50 -48
- data/lib/ccs/components/govuk/fieldset.rb +40 -38
- data/lib/ccs/components/govuk/footer/link.rb +41 -39
- data/lib/ccs/components/govuk/footer/meta.rb +49 -48
- data/lib/ccs/components/govuk/footer/navigation.rb +51 -50
- data/lib/ccs/components/govuk/footer.rb +105 -103
- data/lib/ccs/components/govuk/form_group.rb +45 -43
- data/lib/ccs/components/govuk/header/link.rb +41 -39
- data/lib/ccs/components/govuk/header/navigation.rb +54 -53
- data/lib/ccs/components/govuk/header.rb +84 -82
- data/lib/ccs/components/govuk/hint.rb +33 -31
- data/lib/ccs/components/govuk/inset_text.rb +39 -37
- data/lib/ccs/components/govuk/label.rb +61 -59
- data/lib/ccs/components/govuk/notification_banner.rb +83 -81
- data/lib/ccs/components/govuk/pagination/increment/next.rb +29 -27
- data/lib/ccs/components/govuk/pagination/increment/previous.rb +28 -26
- data/lib/ccs/components/govuk/pagination/increment.rb +78 -76
- data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +17 -15
- data/lib/ccs/components/govuk/pagination/item/form.rb +34 -32
- data/lib/ccs/components/govuk/pagination/item/tag.rb +33 -31
- data/lib/ccs/components/govuk/pagination/item.rb +47 -45
- data/lib/ccs/components/govuk/pagination.rb +69 -67
- data/lib/ccs/components/govuk/panel.rb +49 -47
- data/lib/ccs/components/govuk/phase_banner.rb +50 -48
- data/lib/ccs/components/govuk/skip_link.rb +39 -37
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +40 -38
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +30 -28
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +28 -26
- data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +47 -45
- data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +49 -47
- data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +44 -42
- data/lib/ccs/components/govuk/step_by_step_navigation.rb +41 -39
- data/lib/ccs/components/govuk/summary_list/action/link.rb +46 -44
- data/lib/ccs/components/govuk/summary_list/card/actions.rb +38 -36
- data/lib/ccs/components/govuk/summary_list/card/title.rb +37 -35
- data/lib/ccs/components/govuk/summary_list/card.rb +48 -46
- data/lib/ccs/components/govuk/summary_list/row/actions.rb +38 -36
- data/lib/ccs/components/govuk/summary_list/row/key.rb +30 -28
- data/lib/ccs/components/govuk/summary_list/row/value.rb +30 -28
- data/lib/ccs/components/govuk/summary_list/row.rb +47 -45
- data/lib/ccs/components/govuk/summary_list.rb +48 -46
- data/lib/ccs/components/govuk/table/body/data_cell.rb +38 -36
- data/lib/ccs/components/govuk/table/body/head_cell.rb +37 -35
- data/lib/ccs/components/govuk/table/header/head_cell.rb +39 -37
- data/lib/ccs/components/govuk/table.rb +83 -81
- data/lib/ccs/components/govuk/tabs/panel.rb +47 -45
- data/lib/ccs/components/govuk/tabs/tab.rb +42 -40
- data/lib/ccs/components/govuk/tabs.rb +48 -46
- data/lib/ccs/components/govuk/tag.rb +39 -37
- data/lib/ccs/components/govuk/warning_text.rb +49 -47
- data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +16 -14
- data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +17 -15
- data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +17 -15
- data/lib/ccs/frontend_helpers/ccs_frontend.rb +1 -1
- data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -30
- data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +38 -36
- data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +27 -25
- data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +18 -16
- data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +18 -16
- data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +19 -17
- data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +24 -22
- data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +17 -15
- data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +19 -17
- data/lib/ccs/frontend_helpers/version.rb +1 -1
- metadata +2 -2
@@ -1,51 +1,53 @@
|
|
1
1
|
require_relative '../field'
|
2
2
|
require_relative '../fieldset'
|
3
3
|
|
4
|
-
module CCS
|
5
|
-
module
|
6
|
-
|
7
|
-
|
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.
|
4
|
+
module CCS
|
5
|
+
module Components
|
6
|
+
module GovUK
|
7
|
+
class Field < Base
|
8
|
+
# = GOV.UK Field Inputs
|
26
9
|
#
|
27
|
-
#
|
10
|
+
# This class is used to create a form for a list of fields, e.g. radios or checkboxes.
|
11
|
+
# It will wrap the inputs in the form group and then the fieldset and:
|
12
|
+
# - display the hint (if there is one)
|
13
|
+
# - find and display the error message (if there is one)
|
14
|
+
#
|
15
|
+
# @!attribute [r] fieldset
|
16
|
+
# @return [Fieldset] The initialised fieldset
|
28
17
|
|
29
|
-
|
30
|
-
|
18
|
+
class Inputs < Field
|
19
|
+
private
|
31
20
|
|
32
|
-
|
21
|
+
attr_reader :fieldset
|
33
22
|
|
34
|
-
|
35
|
-
end
|
23
|
+
public
|
36
24
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
fieldset
|
46
|
-
|
47
|
-
|
48
|
-
|
25
|
+
# @param (see CCS::Components::GovUK::Field#initialize)
|
26
|
+
# @param fieldset [Hash] attributes for the fieldset, see {CCS::Components::GovUK::Fieldset#initialize Fieldset#initialize} for more details.
|
27
|
+
#
|
28
|
+
# @option (see CCS::Components::GovUK::Field#initialize)
|
29
|
+
|
30
|
+
def initialize(attribute:, fieldset:, **options)
|
31
|
+
super(attribute: attribute, **options)
|
32
|
+
|
33
|
+
set_described_by(fieldset, @attribute, @error_message, options[:hint])
|
34
|
+
|
35
|
+
@fieldset = Fieldset.new(context: @context, **fieldset)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Generates the HTML to wrap arround a GDS form component
|
39
|
+
#
|
40
|
+
# @yield (see CCS::Components::GovUK::Field#render)
|
41
|
+
#
|
42
|
+
# @return [ActiveSupport::SafeBuffer]
|
43
|
+
|
44
|
+
def render
|
45
|
+
super() do |display_error_message|
|
46
|
+
fieldset.render do
|
47
|
+
concat(hint.render) if hint
|
48
|
+
concat(display_error_message)
|
49
|
+
concat(yield)
|
50
|
+
end
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
@@ -2,105 +2,107 @@ require_relative '../base'
|
|
2
2
|
require_relative 'form_group'
|
3
3
|
require_relative 'hint'
|
4
4
|
|
5
|
-
module CCS
|
6
|
-
module
|
7
|
-
|
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
|
5
|
+
module CCS
|
6
|
+
module Components
|
7
|
+
module GovUK
|
8
|
+
# = GOV.UK Field
|
33
9
|
#
|
34
|
-
#
|
35
|
-
#
|
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
|
10
|
+
# This class is used to create a form using the structure of a GDS input field components, e.g. text input.
|
11
|
+
# It will wrap the input within the form group as well as find if there are any error messages to display.
|
56
12
|
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
13
|
+
# @!attribute [r] attribute
|
14
|
+
# @return [String,Symbol] The attribute of the field
|
15
|
+
# @!attribute [r] error_message
|
16
|
+
# @return [String] The error message for the field
|
17
|
+
# @!attribute [r] form_group
|
18
|
+
# @return [FormGroup] The initialised form group
|
19
|
+
# @!attribute [r] hint
|
20
|
+
# @return [Hint] The initialised hint
|
21
|
+
|
22
|
+
class Field < Base
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :attribute, :error_message, :form_group, :hint
|
26
|
+
|
27
|
+
public
|
28
|
+
|
29
|
+
# @param attribute [String, Symbol] the attribute of the field
|
30
|
+
# @param hint [Hash] attributes for the hint, see {CCS::Components::GovUK::Hint#initialize Hint#initialize} for more details.
|
31
|
+
# If no hint is given then no hint will be rendered
|
32
|
+
# @param form_group [Hash] attributes for the form group, see {CCS::Components::GovUK::FormGroup#initialize FormGroup#initialize} for more details.
|
33
|
+
# @param options [Hash] options that will be used for the parts of the field
|
34
|
+
#
|
35
|
+
# @option options [String] :error_message (nil) the error message to be displayed
|
36
|
+
# @option options [ActiveModel] :model (nil) optional model that can be used to find an error message
|
37
|
+
# @option options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
|
38
|
+
# the field and find the error message
|
39
|
+
# @option options [String] :classes additional CSS classes for the field HTML
|
40
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
41
|
+
|
42
|
+
def initialize(attribute:, form_group: nil, hint: nil, **options)
|
43
|
+
super(**options)
|
44
|
+
|
45
|
+
(hint[:attributes] ||= {})[:id] = "#{attribute}-hint" if hint && !hint.dig(:attributes, :id)
|
46
|
+
|
47
|
+
@attribute = attribute
|
48
|
+
@error_message = find_error_message(attribute)
|
49
|
+
|
50
|
+
@form_group = FormGroup.new(attribute: attribute, error_message: @error_message, context: @context, **(form_group || {}))
|
51
|
+
@hint = Hint.new(context: @context, **hint) if hint
|
52
|
+
end
|
60
53
|
|
61
|
-
|
62
|
-
|
63
|
-
|
54
|
+
# Generates the HTML to wrap arround a GDS form input component
|
55
|
+
#
|
56
|
+
# @yield the field HTML
|
57
|
+
#
|
58
|
+
# @yieldparam displayed_error_message [ActiveSupport::SafeBuffer] the error message HTML to display
|
59
|
+
#
|
60
|
+
# @return [ActiveSupport::SafeBuffer]
|
64
61
|
|
65
|
-
|
62
|
+
def render(&block)
|
63
|
+
form_group.render(&block)
|
64
|
+
end
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
66
|
+
private
|
67
|
+
|
68
|
+
# If one is present it will find the error message text for the field
|
69
|
+
#
|
70
|
+
# @param attribute [String, Symbol] the attribute of the field
|
71
|
+
#
|
72
|
+
# @return [String]
|
73
|
+
|
74
|
+
def find_error_message(attribute)
|
75
|
+
if @options[:model]
|
76
|
+
@options[:model].errors[attribute].first
|
77
|
+
elsif options[:form]
|
78
|
+
@options[:form].object.errors[attribute].first
|
79
|
+
else
|
80
|
+
@options[:error_message]
|
81
|
+
end
|
80
82
|
end
|
81
|
-
end
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
84
|
+
# Adds the aira-describedby attribute for the field
|
85
|
+
# if there is a hint or an error message
|
86
|
+
#
|
87
|
+
# @param field_options [Hash] the hash with the options to add the aria described by to
|
88
|
+
# @param attribute [String, Symbol] the attribute of the field
|
89
|
+
# @param error_message [String] used to indicate if there is an error
|
90
|
+
# @param hint [Hash] the hint attributes
|
90
91
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
92
|
+
def set_described_by(field_options, attribute, error_message, hint)
|
93
|
+
aria_described_by = [
|
94
|
+
field_options.dig(:attributes, :aria, :describedby),
|
95
|
+
(hint[:attributes][:id] if hint),
|
96
|
+
("#{attribute}-error" if error_message)
|
97
|
+
].compact
|
97
98
|
|
98
|
-
|
99
|
+
return unless aria_described_by.any?
|
99
100
|
|
100
|
-
|
101
|
+
((field_options[:attributes] ||= {})[:aria] ||= {})[:describedby] = aria_described_by.join(' ')
|
102
|
+
end
|
101
103
|
end
|
102
104
|
end
|
103
|
-
end
|
104
105
|
|
105
|
-
|
106
|
+
ActionView::Base.field_error_proc = proc { |html_tag, _instance| html_tag }
|
107
|
+
end
|
106
108
|
end
|
@@ -1,62 +1,64 @@
|
|
1
1
|
require_relative '../../base'
|
2
2
|
|
3
|
-
module CCS
|
4
|
-
module
|
5
|
-
|
6
|
-
|
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
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
class Fieldset < Base
|
7
|
+
# = GOV.UK Fieldset Legend
|
28
8
|
#
|
29
|
-
#
|
9
|
+
# The legend for the fieldset
|
30
10
|
#
|
31
|
-
#
|
32
|
-
#
|
11
|
+
# @!attribute [r] text
|
12
|
+
# @return [String] Text for the fieldset legend
|
13
|
+
# @!attribute [r] is_page_heading
|
14
|
+
# @return [Boolean] Flag to indicate of the legend is a the page heading
|
15
|
+
# @!attribute [r] caption
|
16
|
+
# @return [Hash] The class for the li elements
|
33
17
|
|
34
|
-
|
35
|
-
|
18
|
+
class Legend < Base
|
19
|
+
private
|
36
20
|
|
37
|
-
|
38
|
-
@is_page_heading = is_page_heading
|
39
|
-
@caption = caption
|
40
|
-
end
|
21
|
+
attr_reader :text, :is_page_heading, :caption
|
41
22
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
23
|
+
public
|
24
|
+
|
25
|
+
# @param text [String] the text for the fieldset legend
|
26
|
+
# @param is_page_heading [Boolean] if the legend is also the heading it will rendered in a h1
|
27
|
+
# @param caption [String] options for the caption to be rendered above the heading if +:is_page_heading+ is true
|
28
|
+
# @param options [Hash] options that will be used in customising the HTML
|
29
|
+
#
|
30
|
+
# @option options [String] :classes additional CSS classes for the legend HTML
|
31
|
+
#
|
32
|
+
# @option caption [String] :text text for the caption
|
33
|
+
# @option caption [String] :classes additional CSS classes for the caption HTML
|
34
|
+
|
35
|
+
def initialize(text:, is_page_heading: nil, caption: nil, **options)
|
36
|
+
super(**options)
|
37
|
+
|
38
|
+
@text = text
|
39
|
+
@is_page_heading = is_page_heading
|
40
|
+
@caption = caption
|
41
|
+
end
|
42
|
+
|
43
|
+
# Generates the HTML for the GOV.UK Fieldset legend
|
44
|
+
#
|
45
|
+
# @return [ActiveSupport::SafeBuffer]
|
46
|
+
|
47
|
+
def render
|
48
|
+
tag.legend(class: options[:attributes][:class]) do
|
49
|
+
if is_page_heading
|
50
|
+
concat(tag.span(caption[:text], class: caption[:classes])) if caption
|
51
|
+
concat(tag.h1(text, class: 'govuk-fieldset__heading'))
|
52
|
+
else
|
53
|
+
text
|
54
|
+
end
|
53
55
|
end
|
54
56
|
end
|
55
|
-
end
|
56
57
|
|
57
|
-
|
58
|
+
# The default attributes for the fieldset legend
|
58
59
|
|
59
|
-
|
60
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-fieldset__legend' }.freeze
|
61
|
+
end
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
@@ -1,52 +1,54 @@
|
|
1
1
|
require_relative '../base'
|
2
2
|
require_relative 'fieldset/legend'
|
3
3
|
|
4
|
-
module CCS
|
5
|
-
module
|
6
|
-
|
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
|
4
|
+
module CCS
|
5
|
+
module Components
|
6
|
+
module GovUK
|
7
|
+
# = GOV.UK Fieldset
|
24
8
|
#
|
25
|
-
#
|
26
|
-
#
|
9
|
+
# This is used to generate the fieldset component from the
|
10
|
+
# {https://design-system.service.gov.uk/components/fieldset GDS - Components - Fieldset}
|
11
|
+
#
|
12
|
+
# @!attribute [r] legend
|
13
|
+
# @return [Legend] Initialised fieldset legend
|
27
14
|
|
28
|
-
|
29
|
-
|
15
|
+
class Fieldset < Base
|
16
|
+
private
|
30
17
|
|
31
|
-
|
32
|
-
end
|
18
|
+
attr_reader :legend
|
33
19
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
20
|
+
public
|
21
|
+
|
22
|
+
# @param legend [Hash] options for the fieldset legend.
|
23
|
+
# See {Components::GovUK::Fieldset::Legend#initialize Legend#initialize} for details of the options.
|
24
|
+
# @param options [Hash] options that will be used in customising the HTML
|
25
|
+
#
|
26
|
+
# @option options [String] :classes additional CSS classes for the fieldset HTML
|
27
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
39
28
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
29
|
+
def initialize(legend: nil, **options)
|
30
|
+
super(**options)
|
31
|
+
|
32
|
+
@legend = Legend.new(context: @context, **legend) if legend
|
44
33
|
end
|
45
|
-
end
|
46
34
|
|
47
|
-
|
35
|
+
# Generates the HTML for the GOV.UK Fieldset component
|
36
|
+
#
|
37
|
+
# @yield HTML that will be contained within the 'govuk-fieldset' div and under the legend
|
38
|
+
#
|
39
|
+
# @return [ActiveSupport::SafeBuffer]
|
40
|
+
|
41
|
+
def render
|
42
|
+
tag.fieldset(**options[:attributes]) do
|
43
|
+
concat(legend.render) if legend
|
44
|
+
yield
|
45
|
+
end
|
46
|
+
end
|
48
47
|
|
49
|
-
|
48
|
+
# The default attributes for the fieldset
|
49
|
+
|
50
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-fieldset' }.freeze
|
51
|
+
end
|
50
52
|
end
|
51
53
|
end
|
52
54
|
end
|
@@ -1,50 +1,52 @@
|
|
1
1
|
require_relative '../../base'
|
2
2
|
|
3
|
-
module CCS
|
4
|
-
module
|
5
|
-
|
6
|
-
|
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
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
class Footer < Base
|
7
|
+
# = GOV.UK Footer link
|
28
8
|
#
|
29
|
-
#
|
9
|
+
# The individual footer footer link item
|
10
|
+
#
|
11
|
+
# @!attribute [r] text
|
12
|
+
# @return [String] Text for the footer link
|
13
|
+
# @!attribute [r] href
|
14
|
+
# @return [String] The href for the footer link
|
15
|
+
# @!attribute [r] li_class
|
16
|
+
# @return [String] The class for the li elements
|
30
17
|
|
31
|
-
|
32
|
-
|
18
|
+
class Link < Base
|
19
|
+
private
|
33
20
|
|
34
|
-
|
35
|
-
@href = href
|
36
|
-
@li_class = li_class
|
37
|
-
end
|
21
|
+
attr_reader :text, :href, :li_class
|
38
22
|
|
39
|
-
|
40
|
-
|
41
|
-
|
23
|
+
public
|
24
|
+
|
25
|
+
# @param text [String] the text for the footer link
|
26
|
+
# @param href [String] the href for the footer link
|
27
|
+
# @param li_class [String] class for the li elements
|
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(text:, href:, li_class:, **options)
|
33
|
+
super(**options)
|
34
|
+
|
35
|
+
@text = text
|
36
|
+
@href = href
|
37
|
+
@li_class = li_class
|
38
|
+
end
|
39
|
+
|
40
|
+
# Generates the HTML for the GOV.UK Footer link
|
41
|
+
#
|
42
|
+
# @return [ActiveSupport::SafeBuffer]
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
def render
|
45
|
+
tag.li(class: li_class) do
|
46
|
+
options[:attributes][:class] = 'govuk-footer__link'
|
46
47
|
|
47
|
-
|
48
|
+
link_to(text, href, **options[:attributes])
|
49
|
+
end
|
48
50
|
end
|
49
51
|
end
|
50
52
|
end
|