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.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -1
  3. data/Gemfile.lock +1 -1
  4. data/lib/ccs/components/ccs/dashboard_section/panel.rb +43 -41
  5. data/lib/ccs/components/ccs/dashboard_section.rb +50 -48
  6. data/lib/ccs/components/ccs/footer/link.rb +41 -39
  7. data/lib/ccs/components/ccs/footer/meta.rb +49 -48
  8. data/lib/ccs/components/ccs/footer/navigation.rb +51 -50
  9. data/lib/ccs/components/ccs/footer.rb +69 -67
  10. data/lib/ccs/components/ccs/header/link.rb +47 -45
  11. data/lib/ccs/components/ccs/header/navigation.rb +85 -84
  12. data/lib/ccs/components/ccs/header/service_authentication.rb +35 -34
  13. data/lib/ccs/components/ccs/header.rb +87 -85
  14. data/lib/ccs/components/ccs/logo.rb +36 -34
  15. data/lib/ccs/components/govuk/accordion/section/content.rb +42 -42
  16. data/lib/ccs/components/govuk/accordion/section/header.rb +48 -48
  17. data/lib/ccs/components/govuk/accordion/section.rb +49 -48
  18. data/lib/ccs/components/govuk/accordion.rb +43 -41
  19. data/lib/ccs/components/govuk/back_link.rb +39 -37
  20. data/lib/ccs/components/govuk/breadcrumbs/link.rb +42 -40
  21. data/lib/ccs/components/govuk/breadcrumbs.rb +40 -38
  22. data/lib/ccs/components/govuk/button.rb +83 -81
  23. data/lib/ccs/components/govuk/cookie_banner/action.rb +45 -43
  24. data/lib/ccs/components/govuk/cookie_banner/message.rb +57 -55
  25. data/lib/ccs/components/govuk/cookie_banner.rb +40 -38
  26. data/lib/ccs/components/govuk/details.rb +38 -36
  27. data/lib/ccs/components/govuk/error_message.rb +46 -44
  28. data/lib/ccs/components/govuk/error_summary/item.rb +41 -39
  29. data/lib/ccs/components/govuk/error_summary.rb +49 -47
  30. data/lib/ccs/components/govuk/field/input/character_count.rb +101 -99
  31. data/lib/ccs/components/govuk/field/input/file_upload.rb +29 -27
  32. data/lib/ccs/components/govuk/field/input/select.rb +61 -59
  33. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +39 -37
  34. data/lib/ccs/components/govuk/field/input/text_input.rb +75 -73
  35. data/lib/ccs/components/govuk/field/input/textarea.rb +43 -41
  36. data/lib/ccs/components/govuk/field/input.rb +46 -44
  37. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +43 -41
  38. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +48 -46
  39. data/lib/ccs/components/govuk/field/inputs/date_input.rb +68 -66
  40. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +29 -27
  41. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +26 -24
  42. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +32 -30
  43. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +39 -37
  44. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +27 -25
  45. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +26 -24
  46. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +32 -30
  47. data/lib/ccs/components/govuk/field/inputs/item.rb +100 -98
  48. data/lib/ccs/components/govuk/field/inputs/radios.rb +43 -41
  49. data/lib/ccs/components/govuk/field/inputs.rb +42 -40
  50. data/lib/ccs/components/govuk/field.rb +90 -88
  51. data/lib/ccs/components/govuk/fieldset/legend.rb +50 -48
  52. data/lib/ccs/components/govuk/fieldset.rb +40 -38
  53. data/lib/ccs/components/govuk/footer/link.rb +41 -39
  54. data/lib/ccs/components/govuk/footer/meta.rb +49 -48
  55. data/lib/ccs/components/govuk/footer/navigation.rb +51 -50
  56. data/lib/ccs/components/govuk/footer.rb +105 -103
  57. data/lib/ccs/components/govuk/form_group.rb +45 -43
  58. data/lib/ccs/components/govuk/header/link.rb +41 -39
  59. data/lib/ccs/components/govuk/header/navigation.rb +54 -53
  60. data/lib/ccs/components/govuk/header.rb +84 -82
  61. data/lib/ccs/components/govuk/hint.rb +33 -31
  62. data/lib/ccs/components/govuk/inset_text.rb +39 -37
  63. data/lib/ccs/components/govuk/label.rb +61 -59
  64. data/lib/ccs/components/govuk/notification_banner.rb +83 -81
  65. data/lib/ccs/components/govuk/pagination/increment/next.rb +29 -27
  66. data/lib/ccs/components/govuk/pagination/increment/previous.rb +28 -26
  67. data/lib/ccs/components/govuk/pagination/increment.rb +78 -76
  68. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +17 -15
  69. data/lib/ccs/components/govuk/pagination/item/form.rb +34 -32
  70. data/lib/ccs/components/govuk/pagination/item/tag.rb +33 -31
  71. data/lib/ccs/components/govuk/pagination/item.rb +47 -45
  72. data/lib/ccs/components/govuk/pagination.rb +69 -67
  73. data/lib/ccs/components/govuk/panel.rb +49 -47
  74. data/lib/ccs/components/govuk/phase_banner.rb +50 -48
  75. data/lib/ccs/components/govuk/skip_link.rb +39 -37
  76. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +40 -38
  77. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +30 -28
  78. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +28 -26
  79. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +47 -45
  80. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +49 -47
  81. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +44 -42
  82. data/lib/ccs/components/govuk/step_by_step_navigation.rb +41 -39
  83. data/lib/ccs/components/govuk/summary_list/action/link.rb +46 -44
  84. data/lib/ccs/components/govuk/summary_list/card/actions.rb +38 -36
  85. data/lib/ccs/components/govuk/summary_list/card/title.rb +37 -35
  86. data/lib/ccs/components/govuk/summary_list/card.rb +48 -46
  87. data/lib/ccs/components/govuk/summary_list/row/actions.rb +38 -36
  88. data/lib/ccs/components/govuk/summary_list/row/key.rb +30 -28
  89. data/lib/ccs/components/govuk/summary_list/row/value.rb +30 -28
  90. data/lib/ccs/components/govuk/summary_list/row.rb +47 -45
  91. data/lib/ccs/components/govuk/summary_list.rb +48 -46
  92. data/lib/ccs/components/govuk/table/body/data_cell.rb +38 -36
  93. data/lib/ccs/components/govuk/table/body/head_cell.rb +37 -35
  94. data/lib/ccs/components/govuk/table/header/head_cell.rb +39 -37
  95. data/lib/ccs/components/govuk/table.rb +83 -81
  96. data/lib/ccs/components/govuk/tabs/panel.rb +47 -45
  97. data/lib/ccs/components/govuk/tabs/tab.rb +42 -40
  98. data/lib/ccs/components/govuk/tabs.rb +48 -46
  99. data/lib/ccs/components/govuk/tag.rb +39 -37
  100. data/lib/ccs/components/govuk/warning_text.rb +49 -47
  101. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +16 -14
  102. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +17 -15
  103. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +17 -15
  104. data/lib/ccs/frontend_helpers/ccs_frontend.rb +1 -1
  105. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +17 -15
  106. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -15
  107. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +17 -15
  108. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +17 -15
  109. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +17 -15
  110. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +17 -15
  111. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +17 -15
  112. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +17 -15
  113. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +19 -17
  114. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -30
  115. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +38 -36
  116. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +19 -17
  117. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +17 -15
  118. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +17 -15
  119. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +27 -25
  120. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +17 -15
  121. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +18 -16
  122. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +17 -15
  123. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +19 -17
  124. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +18 -16
  125. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +19 -17
  126. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +17 -15
  127. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +19 -17
  128. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +19 -17
  129. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +17 -15
  130. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +17 -15
  131. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +17 -15
  132. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +24 -22
  133. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +17 -15
  134. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +17 -15
  135. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +17 -15
  136. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +17 -15
  137. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +17 -15
  138. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +19 -17
  139. data/lib/ccs/frontend_helpers/version.rb +1 -1
  140. metadata +2 -2
@@ -1,44 +1,46 @@
1
1
  require 'action_view'
2
2
 
3
- module CCS::Components
4
- module GovUK
5
- class Field < Base
6
- class Inputs < Field
7
- class Item < Base
8
- # = GOV.UK Field Inputs item divider
9
- #
10
- # The divider for input items e.g. {CCS::Components::GovUK::Field::Inputs::Checkboxes Checkboxes} or {CCS::Components::GovUK::Field::Inputs::Radios Radios}
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
- # @return [ActiveSupport::SafeBuffer]
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
- def render
41
- tag.div(text, class: "govuk-#{type}__divider")
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::Components
4
- module GovUK
5
- class Field < Base
6
- class Inputs < Field
7
- class Item < Base
8
- class Radio < Item
9
- # = GOV.UK Field Inputs Radio form tag
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
- # @option (see CCS::Components::GovUK::Field::Items::Item::Radio#initialize)
12
+ # This is used to generate an individual radio item using +form.check_box+
17
13
 
18
- def initialize(attribute:, label:, **options)
19
- super(attribute: attribute, label: label, **options)
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[:attributes] ||= {})[:value] = @value
22
- label[:attributes][:for] = @options[:attributes][:id] if @options[:attributes][:id]
19
+ def initialize(attribute:, label:, **options)
20
+ super(attribute: attribute, label: label, **options)
23
21
 
24
- @label = Label.new(attribute: attribute, form: @options[:form], context: @context, **label)
25
- end
22
+ (label[:attributes] ||= {})[:value] = @value
23
+ label[:attributes][:for] = @options[:attributes][:id] if @options[:attributes][:id]
26
24
 
27
- # Generates the HTML for the radio input
28
- #
29
- # @return [ActiveSupport::SafeBuffer]
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
- def render
32
- super() do
33
- @options[:form].radio_button(@attribute, @value, **@options[:attributes])
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::Components
4
- module GovUK
5
- class Field < Base
6
- class Inputs < Field
7
- class Item < Base
8
- class Radio < Item
9
- # = GOV.UK Field Inputs Radio tag
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
- # @option (see CCS::Components::GovUK::Field::Items::Item::Radio#initialize)
12
+ # This is used to generate an individual radio item using +radio_button_tag+
17
13
 
18
- def initialize(attribute:, label:, **options)
19
- super(attribute: attribute, label: label, **options)
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
- @options[:attributes][:id] ||= "#{sanitize_to_id(@attribute)}_#{sanitize_to_id(@value)}"
19
+ def initialize(attribute:, label:, **options)
20
+ super(attribute: attribute, label: label, **options)
22
21
 
23
- @label = Label.new(attribute: @options[:attributes][:id], context: @context, **label)
24
- end
22
+ @options[:attributes][:id] ||= "#{sanitize_to_id(@attribute)}_#{sanitize_to_id(@value)}"
25
23
 
26
- # Generates the HTML for the radio input
27
- #
28
- # @return [ActiveSupport::SafeBuffer]
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
- def render
31
- super() do
32
- context.radio_button_tag(@attribute, @value, @options[:checked], **@options[:attributes])
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::Components
4
- module GovUK
5
- class Field < Base
6
- class Inputs < Field
7
- class Item < Base
8
- # = GOV.UK Field Inputs Radio
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
- # @option (see CCS::Components::GovUK::Field::Items::Item#initialize))
11
+ # This is used to generate an individual radio item
17
12
 
18
- def initialize(attribute:, label:, **options)
19
- super(attribute: attribute, **options)
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
- label[:classes] = "govuk-radios__label #{label[:classes]}".rstrip
22
- end
19
+ def initialize(attribute:, label:, **options)
20
+ super(attribute: attribute, **options)
23
21
 
24
- # Generates the HTML to wrap arround a radio input
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
- def render(&block)
31
- tag.div(class: 'govuk-radios__item') do
32
- super(&block)
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
- # The default attributes for the radio
37
+ # The default attributes for the radio
37
38
 
38
- DEFAULT_ATTRIBUTES = { class: 'govuk-radios__input' }.freeze
39
+ DEFAULT_ATTRIBUTES = { class: 'govuk-radios__input' }.freeze
39
40
 
40
- # The type of the input item
41
+ # The type of the input item
41
42
 
42
- ITEM_TYPE = 'radios'.freeze
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::Components
5
- module GovUK
6
- class Field < Base
7
- class Inputs < Field
8
- # = GOV.UK Field Inputs Item
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
- # @option options [String] :classes additional CSS classes for the item HTML
43
- # @option options [Boolean] :checked flag to indicate if the item is checked
44
- # @option options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create item HTML
45
- # @option options [Hash] :attributes ({}) any additional attributes that will be added as part of the item HTML
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
- # @option conditional [ActiveSupport::SafeBuffer] content the HTML content
48
- # @option conditional [Hash] attributes[:id] the id of the conditional section
49
-
50
- def initialize(attribute:, value:, hint: nil, conditional: nil, **options)
51
- super(**options)
52
-
53
- initialise_item_hint(attribute, value, hint) if hint
54
- initialize_item_conditional(attribute, value, conditional) if conditional
55
- @attribute = attribute
56
- @value = value
57
- end
58
-
59
- # Generates the HTML to wrap arround a input
60
- #
61
- # @yield the item input HTML
62
- #
63
- # @return [ActiveSupport::SafeBuffer]
64
-
65
- def render
66
- concat(yield)
67
- concat(label.render)
68
- concat(hint.render) if hint
69
- concat(conditional_content) if conditional_content
70
- end
71
-
72
- private
73
-
74
- # Initialises the item hint and adds the aira-describedby attribute for the item
75
- #
76
- # @param attribute [String, Symbol] the attribute of the item
77
- # @param value [String] the value of the item
78
- # @param hint [Hash] the options for the hint
79
-
80
- def initialise_item_hint(attribute, value, hint)
81
- hint[:attributes] ||= {}
82
- hint[:classes] = "govuk-#{self.class::ITEM_TYPE}__hint #{hint[:classes]}".rstrip
83
- hint[:attributes][:id] ||= "#{attribute}_#{value}-item-hint"
84
-
85
- (@options[:attributes][:aria] ||= {})[:describedby] = hint[:attributes][:id]
86
-
87
- @hint = Hint.new(context: @context, **hint)
88
- end
89
-
90
- # Generate the item conditional HTML and adds the data-aira-controls attribute for the item
91
- #
92
- # @param attribute [String, Symbol] the attribute of the item
93
- # @param value [String] the value of the item
94
- # @param conditional [Hash] the options for the conditional
95
-
96
- def initialize_item_conditional(attribute, value, conditional)
97
- conditional[:attributes] ||= {}
98
- conditional[:attributes][:class] = "govuk-#{self.class::ITEM_TYPE}__conditional #{"govuk-#{self.class::ITEM_TYPE}__conditional--hidden" unless @options[:checked]}".rstrip
99
- conditional[:attributes][:id] ||= sanitize_to_id("#{attribute}_#{value}_conditional")
100
-
101
- (@options[:attributes][:data] ||= {})[:'aria-controls'] = conditional[:attributes][:id]
102
-
103
- @conditional_content = tag.div(conditional[:content], class: conditional[:attributes][:class], id: conditional[:attributes][:id])
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::Components
7
- module GovUK
8
- class Field < Base
9
- class Inputs < Field
10
- # = GOV.UK Radios
11
- #
12
- # This is used for generating the radios component from the
13
- # {https://design-system.service.gov.uk/components/radios GDS - Components - Radios}
14
- #
15
- # @!attribute [r] radio_items
16
- # @return [Array<Item::Divider|Item::Radio|Item::Radio>] An array of the initialised radio items
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
- class Radios < Inputs
19
- private
19
+ class Radios < Inputs
20
+ private
20
21
 
21
- attr_reader :radio_items
22
+ attr_reader :radio_items
22
23
 
23
- public
24
+ public
24
25
 
25
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
26
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
26
27
 
27
- # @param (see CCS::Components::GovUK::Field::Inputs#initialize)
28
- # @param radio_items [Array<Hash>] an array of options for the radios.
29
- # See {Components::GovUK::Field::Inputs::Item::Radio#initialize Radio#initialize} for details of the items in the array.
30
- #
31
- # @option (see CCS::Components::GovUK::Field::Inputs#initialize)
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
- def initialize(attribute:, radio_items:, **options)
34
- super(attribute: attribute, **options)
34
+ def initialize(attribute:, radio_items:, **options)
35
+ super(attribute: attribute, **options)
35
36
 
36
- if @options[:model] || @options[:form]
37
- values = (@options[:model] || @options[:form].object).send(attribute) || []
38
- radio_items.each { |radio_item| radio_item[:checked] = values.include?(radio_item[:value]) }
39
- end
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
- radio_item_class = @options[:form] ? Item::Radio::Form : Inputs::Item::Radio::Tag
42
+ radio_item_class = @options[:form] ? Item::Radio::Form : Inputs::Item::Radio::Tag
42
43
 
43
- @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) }
44
- end
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
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
47
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
47
48
 
48
- # Generates the HTML for the GOV.UK Radios component
49
- #
50
- # @return [ActiveSupport::SafeBuffer]
49
+ # Generates the HTML for the GOV.UK Radios component
50
+ #
51
+ # @return [ActiveSupport::SafeBuffer]
51
52
 
52
- def render
53
- super() do
54
- tag.div(**options[:attributes]) do
55
- radio_items.each { |radio_item| concat(radio_item.render) }
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
- # The default attributes for the radios
61
+ # The default attributes for the radios
61
62
 
62
- DEFAULT_ATTRIBUTES = { class: 'govuk-radios', data: { module: 'govuk-radios' } }.freeze
63
+ DEFAULT_ATTRIBUTES = { class: 'govuk-radios', data: { module: 'govuk-radios' } }.freeze
64
+ end
63
65
  end
64
66
  end
65
67
  end