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,44 +1,46 @@
|
|
1
1
|
require 'action_view'
|
2
2
|
|
3
|
-
module CCS
|
4
|
-
module
|
5
|
-
|
6
|
-
class
|
7
|
-
class
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
# @!attribute [r] text
|
13
|
-
# @return [String] Text for the divider
|
14
|
-
# @!attribute [r] type
|
15
|
-
# @return [String] The type of the item
|
16
|
-
|
17
|
-
class Divider
|
18
|
-
include ActionView::Context
|
19
|
-
include ActionView::Helpers
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
attr_reader :text, :type
|
24
|
-
|
25
|
-
public
|
26
|
-
|
27
|
-
# @param divider [String] the text for the divider
|
28
|
-
# @param type [String] the type of the item divider.
|
29
|
-
# One of +'checkboxes'+ or +'radios'+
|
30
|
-
|
31
|
-
def initialize(divider:, type:)
|
32
|
-
@text = divider
|
33
|
-
@type = type
|
34
|
-
end
|
35
|
-
|
36
|
-
# Generates the HTML for an item divider
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
class Field < Base
|
7
|
+
class Inputs < Field
|
8
|
+
class Item < Base
|
9
|
+
# = GOV.UK Field Inputs item divider
|
10
|
+
#
|
11
|
+
# The divider for input items e.g. {CCS::Components::GovUK::Field::Inputs::Checkboxes Checkboxes} or {CCS::Components::GovUK::Field::Inputs::Radios Radios}
|
37
12
|
#
|
38
|
-
#
|
13
|
+
# @!attribute [r] text
|
14
|
+
# @return [String] Text for the divider
|
15
|
+
# @!attribute [r] type
|
16
|
+
# @return [String] The type of the item
|
17
|
+
|
18
|
+
class Divider
|
19
|
+
include ActionView::Context
|
20
|
+
include ActionView::Helpers
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :text, :type
|
25
|
+
|
26
|
+
public
|
27
|
+
|
28
|
+
# @param divider [String] the text for the divider
|
29
|
+
# @param type [String] the type of the item divider.
|
30
|
+
# One of +'checkboxes'+ or +'radios'+
|
31
|
+
|
32
|
+
def initialize(divider:, type:)
|
33
|
+
@text = divider
|
34
|
+
@type = type
|
35
|
+
end
|
36
|
+
|
37
|
+
# Generates the HTML for an item divider
|
38
|
+
#
|
39
|
+
# @return [ActiveSupport::SafeBuffer]
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
def render
|
42
|
+
tag.div(text, class: "govuk-#{type}__divider")
|
43
|
+
end
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
@@ -1,36 +1,38 @@
|
|
1
1
|
require_relative '../radio'
|
2
2
|
|
3
|
-
module CCS
|
4
|
-
module
|
5
|
-
|
6
|
-
class
|
7
|
-
class
|
8
|
-
class
|
9
|
-
|
10
|
-
|
11
|
-
# This is used to generate an individual radio item using +form.check_box+
|
12
|
-
|
13
|
-
class Form < Radio
|
14
|
-
# @param (see CCS::Components::GovUK::Field::Items::Item::Radio#initialize)
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
class Field < Base
|
7
|
+
class Inputs < Field
|
8
|
+
class Item < Base
|
9
|
+
class Radio < Item
|
10
|
+
# = GOV.UK Field Inputs Radio form tag
|
15
11
|
#
|
16
|
-
#
|
12
|
+
# This is used to generate an individual radio item using +form.check_box+
|
17
13
|
|
18
|
-
|
19
|
-
|
14
|
+
class Form < Radio
|
15
|
+
# @param (see CCS::Components::GovUK::Field::Items::Item::Radio#initialize)
|
16
|
+
#
|
17
|
+
# @option (see CCS::Components::GovUK::Field::Items::Item::Radio#initialize)
|
20
18
|
|
21
|
-
(label
|
22
|
-
|
19
|
+
def initialize(attribute:, label:, **options)
|
20
|
+
super(attribute: attribute, label: label, **options)
|
23
21
|
|
24
|
-
|
25
|
-
|
22
|
+
(label[:attributes] ||= {})[:value] = @value
|
23
|
+
label[:attributes][:for] = @options[:attributes][:id] if @options[:attributes][:id]
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
@label = Label.new(attribute: attribute, form: @options[:form], context: @context, **label)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Generates the HTML for the radio input
|
29
|
+
#
|
30
|
+
# @return [ActiveSupport::SafeBuffer]
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
def render
|
33
|
+
super() do
|
34
|
+
@options[:form].radio_button(@attribute, @value, **@options[:attributes])
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -1,35 +1,37 @@
|
|
1
1
|
require_relative '../radio'
|
2
2
|
|
3
|
-
module CCS
|
4
|
-
module
|
5
|
-
|
6
|
-
class
|
7
|
-
class
|
8
|
-
class
|
9
|
-
|
10
|
-
|
11
|
-
# This is used to generate an individual radio item using +radio_button_tag+
|
12
|
-
|
13
|
-
class Tag < Radio
|
14
|
-
# @param (see CCS::Components::GovUK::Field::Items::Item::Radio#initialize)
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
class Field < Base
|
7
|
+
class Inputs < Field
|
8
|
+
class Item < Base
|
9
|
+
class Radio < Item
|
10
|
+
# = GOV.UK Field Inputs Radio tag
|
15
11
|
#
|
16
|
-
#
|
12
|
+
# This is used to generate an individual radio item using +radio_button_tag+
|
17
13
|
|
18
|
-
|
19
|
-
|
14
|
+
class Tag < Radio
|
15
|
+
# @param (see CCS::Components::GovUK::Field::Items::Item::Radio#initialize)
|
16
|
+
#
|
17
|
+
# @option (see CCS::Components::GovUK::Field::Items::Item::Radio#initialize)
|
20
18
|
|
21
|
-
|
19
|
+
def initialize(attribute:, label:, **options)
|
20
|
+
super(attribute: attribute, label: label, **options)
|
22
21
|
|
23
|
-
|
24
|
-
end
|
22
|
+
@options[:attributes][:id] ||= "#{sanitize_to_id(@attribute)}_#{sanitize_to_id(@value)}"
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
@label = Label.new(attribute: @options[:attributes][:id], context: @context, **label)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Generates the HTML for the radio input
|
28
|
+
#
|
29
|
+
# @return [ActiveSupport::SafeBuffer]
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
def render
|
32
|
+
super() do
|
33
|
+
context.radio_button_tag(@attribute, @value, @options[:checked], **@options[:attributes])
|
34
|
+
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -1,45 +1,47 @@
|
|
1
1
|
require_relative '../item'
|
2
2
|
|
3
|
-
module CCS
|
4
|
-
module
|
5
|
-
|
6
|
-
class
|
7
|
-
class
|
8
|
-
|
9
|
-
|
10
|
-
# This is used to generate an individual radio item
|
11
|
-
|
12
|
-
class Radio < Item
|
13
|
-
# @param (see CCS::Components::GovUK::Field::Items::Item#initialize)
|
14
|
-
# label [Hash] attributes for the radio label, see {CCS::Components::GovUK::Label#initialize Label#initialize} for more details.
|
3
|
+
module CCS
|
4
|
+
module Components
|
5
|
+
module GovUK
|
6
|
+
class Field < Base
|
7
|
+
class Inputs < Field
|
8
|
+
class Item < Base
|
9
|
+
# = GOV.UK Field Inputs Radio
|
15
10
|
#
|
16
|
-
#
|
11
|
+
# This is used to generate an individual radio item
|
17
12
|
|
18
|
-
|
19
|
-
|
13
|
+
class Radio < Item
|
14
|
+
# @param (see CCS::Components::GovUK::Field::Items::Item#initialize)
|
15
|
+
# label [Hash] attributes for the radio label, see {CCS::Components::GovUK::Label#initialize Label#initialize} for more details.
|
16
|
+
#
|
17
|
+
# @option (see CCS::Components::GovUK::Field::Items::Item#initialize))
|
20
18
|
|
21
|
-
|
22
|
-
|
19
|
+
def initialize(attribute:, label:, **options)
|
20
|
+
super(attribute: attribute, **options)
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
# @yield the radio item input HTML
|
27
|
-
#
|
28
|
-
# @return [ActiveSupport::SafeBuffer]
|
22
|
+
label[:classes] = "govuk-radios__label #{label[:classes]}".rstrip
|
23
|
+
end
|
29
24
|
|
30
|
-
|
31
|
-
|
32
|
-
|
25
|
+
# Generates the HTML to wrap arround a radio input
|
26
|
+
#
|
27
|
+
# @yield the radio item input HTML
|
28
|
+
#
|
29
|
+
# @return [ActiveSupport::SafeBuffer]
|
30
|
+
|
31
|
+
def render(&block)
|
32
|
+
tag.div(class: 'govuk-radios__item') do
|
33
|
+
super(&block)
|
34
|
+
end
|
33
35
|
end
|
34
|
-
end
|
35
36
|
|
36
|
-
|
37
|
+
# The default attributes for the radio
|
37
38
|
|
38
|
-
|
39
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-radios__input' }.freeze
|
39
40
|
|
40
|
-
|
41
|
+
# The type of the input item
|
41
42
|
|
42
|
-
|
43
|
+
ITEM_TYPE = 'radios'.freeze
|
44
|
+
end
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
@@ -1,106 +1,108 @@
|
|
1
1
|
require_relative '../inputs'
|
2
2
|
require_relative '../../label'
|
3
3
|
|
4
|
-
module CCS
|
5
|
-
module
|
6
|
-
|
7
|
-
class
|
8
|
-
|
9
|
-
|
10
|
-
# This class is used to provided the shared HTML for a
|
11
|
-
# {Components::GovUK::Field::Inputs::Item::Checkbox checkbox item} or {Components::GovUK::Field::Inputs::Item::Radio radio item}.
|
12
|
-
# It wraps these items with the following:
|
13
|
-
# - Item label
|
14
|
-
# - Item hint
|
15
|
-
# - Item conditional content
|
16
|
-
#
|
17
|
-
# @!attribute [r] attribute
|
18
|
-
# @return [String,Symbol] The attribute of the item
|
19
|
-
# @!attribute [r] value
|
20
|
-
# @return [String] The value of the item
|
21
|
-
# @!attribute [r] label
|
22
|
-
# @return [Label] The initialised item label
|
23
|
-
# @!attribute [r] hint
|
24
|
-
# @return [Hint] The initialised item hint
|
25
|
-
# @!attribute [r] conditional_content
|
26
|
-
# @return [ActiveSupport::SafeBuffer] The conditional HTML
|
27
|
-
|
28
|
-
class Item < Base
|
29
|
-
private
|
30
|
-
|
31
|
-
attr_reader :attribute, :value, :label, :hint, :conditional_content
|
32
|
-
|
33
|
-
public
|
34
|
-
|
35
|
-
# @param attribute [String,Symbol] the attribute of the item
|
36
|
-
# @param value [String] the value of the item
|
37
|
-
# @param hint [Hash] options for an item hint see {CCS::Components::GovUK::Hint#initialize Hint#initialize} for more details.
|
38
|
-
# If no hint is given then no hint will be rendered
|
39
|
-
# @param conditional [Hash] content that will appear if the item is checked.
|
40
|
-
# If no conditional is given then no conditional content will be rendered
|
4
|
+
module CCS
|
5
|
+
module Components
|
6
|
+
module GovUK
|
7
|
+
class Field < Base
|
8
|
+
class Inputs < Field
|
9
|
+
# = GOV.UK Field Inputs Item
|
41
10
|
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
11
|
+
# This class is used to provided the shared HTML for a
|
12
|
+
# {Components::GovUK::Field::Inputs::Item::Checkbox checkbox item} or {Components::GovUK::Field::Inputs::Item::Radio radio item}.
|
13
|
+
# It wraps these items with the following:
|
14
|
+
# - Item label
|
15
|
+
# - Item hint
|
16
|
+
# - Item conditional content
|
46
17
|
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
18
|
+
# @!attribute [r] attribute
|
19
|
+
# @return [String,Symbol] The attribute of the item
|
20
|
+
# @!attribute [r] value
|
21
|
+
# @return [String] The value of the item
|
22
|
+
# @!attribute [r] label
|
23
|
+
# @return [Label] The initialised item label
|
24
|
+
# @!attribute [r] hint
|
25
|
+
# @return [Hint] The initialised item hint
|
26
|
+
# @!attribute [r] conditional_content
|
27
|
+
# @return [ActiveSupport::SafeBuffer] The conditional HTML
|
28
|
+
|
29
|
+
class Item < Base
|
30
|
+
private
|
31
|
+
|
32
|
+
attr_reader :attribute, :value, :label, :hint, :conditional_content
|
33
|
+
|
34
|
+
public
|
35
|
+
|
36
|
+
# @param attribute [String,Symbol] the attribute of the item
|
37
|
+
# @param value [String] the value of the item
|
38
|
+
# @param hint [Hash] options for an item hint see {CCS::Components::GovUK::Hint#initialize Hint#initialize} for more details.
|
39
|
+
# If no hint is given then no hint will be rendered
|
40
|
+
# @param conditional [Hash] content that will appear if the item is checked.
|
41
|
+
# If no conditional is given then no conditional content will be rendered
|
42
|
+
#
|
43
|
+
# @option options [String] :classes additional CSS classes for the item HTML
|
44
|
+
# @option options [Boolean] :checked flag to indicate if the item is checked
|
45
|
+
# @option options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create item HTML
|
46
|
+
# @option options [Hash] :attributes ({}) any additional attributes that will be added as part of the item HTML
|
47
|
+
#
|
48
|
+
# @option conditional [ActiveSupport::SafeBuffer] content the HTML content
|
49
|
+
# @option conditional [Hash] attributes[:id] the id of the conditional section
|
50
|
+
|
51
|
+
def initialize(attribute:, value:, hint: nil, conditional: nil, **options)
|
52
|
+
super(**options)
|
53
|
+
|
54
|
+
initialise_item_hint(attribute, value, hint) if hint
|
55
|
+
initialize_item_conditional(attribute, value, conditional) if conditional
|
56
|
+
@attribute = attribute
|
57
|
+
@value = value
|
58
|
+
end
|
59
|
+
|
60
|
+
# Generates the HTML to wrap arround a input
|
61
|
+
#
|
62
|
+
# @yield the item input HTML
|
63
|
+
#
|
64
|
+
# @return [ActiveSupport::SafeBuffer]
|
65
|
+
|
66
|
+
def render
|
67
|
+
concat(yield)
|
68
|
+
concat(label.render)
|
69
|
+
concat(hint.render) if hint
|
70
|
+
concat(conditional_content) if conditional_content
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
# Initialises the item hint and adds the aira-describedby attribute for the item
|
76
|
+
#
|
77
|
+
# @param attribute [String, Symbol] the attribute of the item
|
78
|
+
# @param value [String] the value of the item
|
79
|
+
# @param hint [Hash] the options for the hint
|
80
|
+
|
81
|
+
def initialise_item_hint(attribute, value, hint)
|
82
|
+
hint[:attributes] ||= {}
|
83
|
+
hint[:classes] = "govuk-#{self.class::ITEM_TYPE}__hint #{hint[:classes]}".rstrip
|
84
|
+
hint[:attributes][:id] ||= "#{attribute}_#{value}-item-hint"
|
85
|
+
|
86
|
+
(@options[:attributes][:aria] ||= {})[:describedby] = hint[:attributes][:id]
|
87
|
+
|
88
|
+
@hint = Hint.new(context: @context, **hint)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Generate the item conditional HTML and adds the data-aira-controls attribute for the item
|
92
|
+
#
|
93
|
+
# @param attribute [String, Symbol] the attribute of the item
|
94
|
+
# @param value [String] the value of the item
|
95
|
+
# @param conditional [Hash] the options for the conditional
|
96
|
+
|
97
|
+
def initialize_item_conditional(attribute, value, conditional)
|
98
|
+
conditional[:attributes] ||= {}
|
99
|
+
conditional[:attributes][:class] = "govuk-#{self.class::ITEM_TYPE}__conditional #{"govuk-#{self.class::ITEM_TYPE}__conditional--hidden" unless @options[:checked]}".rstrip
|
100
|
+
conditional[:attributes][:id] ||= sanitize_to_id("#{attribute}_#{value}_conditional")
|
101
|
+
|
102
|
+
(@options[:attributes][:data] ||= {})[:'aria-controls'] = conditional[:attributes][:id]
|
103
|
+
|
104
|
+
@conditional_content = tag.div(conditional[:content], class: conditional[:attributes][:class], id: conditional[:attributes][:id])
|
105
|
+
end
|
104
106
|
end
|
105
107
|
end
|
106
108
|
end
|
@@ -3,63 +3,65 @@ require_relative 'item/divider'
|
|
3
3
|
require_relative 'item/radio/form'
|
4
4
|
require_relative 'item/radio/tag'
|
5
5
|
|
6
|
-
module CCS
|
7
|
-
module
|
8
|
-
|
9
|
-
class
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
module CCS
|
7
|
+
module Components
|
8
|
+
module GovUK
|
9
|
+
class Field < Base
|
10
|
+
class Inputs < Field
|
11
|
+
# = GOV.UK Radios
|
12
|
+
#
|
13
|
+
# This is used for generating the radios component from the
|
14
|
+
# {https://design-system.service.gov.uk/components/radios GDS - Components - Radios}
|
15
|
+
#
|
16
|
+
# @!attribute [r] radio_items
|
17
|
+
# @return [Array<Item::Divider|Item::Radio|Item::Radio>] An array of the initialised radio items
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
class Radios < Inputs
|
20
|
+
private
|
20
21
|
|
21
|
-
|
22
|
+
attr_reader :radio_items
|
22
23
|
|
23
|
-
|
24
|
+
public
|
24
25
|
|
25
|
-
|
26
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
# @param (see CCS::Components::GovUK::Field::Inputs#initialize)
|
29
|
+
# @param radio_items [Array<Hash>] an array of options for the radios.
|
30
|
+
# See {Components::GovUK::Field::Inputs::Item::Radio#initialize Radio#initialize} for details of the items in the array.
|
31
|
+
#
|
32
|
+
# @option (see CCS::Components::GovUK::Field::Inputs#initialize)
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
def initialize(attribute:, radio_items:, **options)
|
35
|
+
super(attribute: attribute, **options)
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
if @options[:model] || @options[:form]
|
38
|
+
values = (@options[:model] || @options[:form].object).send(attribute) || []
|
39
|
+
radio_items.each { |radio_item| radio_item[:checked] = values.include?(radio_item[:value]) }
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
+
radio_item_class = @options[:form] ? Item::Radio::Form : Inputs::Item::Radio::Tag
|
42
43
|
|
43
|
-
|
44
|
-
|
44
|
+
@radio_items = radio_items.map { |radio_item| radio_item[:divider] ? Item::Divider.new(divider: radio_item[:divider], type: 'radios') : radio_item_class.new(attribute: attribute, form: @options[:form], context: @context, **radio_item) }
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
# Generates the HTML for the GOV.UK Radios component
|
50
|
+
#
|
51
|
+
# @return [ActiveSupport::SafeBuffer]
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
def render
|
54
|
+
super() do
|
55
|
+
tag.div(**options[:attributes]) do
|
56
|
+
radio_items.each { |radio_item| concat(radio_item.render) }
|
57
|
+
end
|
56
58
|
end
|
57
59
|
end
|
58
|
-
end
|
59
60
|
|
60
|
-
|
61
|
+
# The default attributes for the radios
|
61
62
|
|
62
|
-
|
63
|
+
DEFAULT_ATTRIBUTES = { class: 'govuk-radios', data: { module: 'govuk-radios' } }.freeze
|
64
|
+
end
|
63
65
|
end
|
64
66
|
end
|
65
67
|
end
|