ccs-frontend_helpers 0.1.0.rc.2 → 0.1.0.rc.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/ccs/components/ccs/dashboard_section/panel.rb +43 -41
  4. data/lib/ccs/components/ccs/dashboard_section.rb +50 -48
  5. data/lib/ccs/components/ccs/footer/link.rb +41 -39
  6. data/lib/ccs/components/ccs/footer/meta.rb +49 -48
  7. data/lib/ccs/components/ccs/footer/navigation.rb +51 -50
  8. data/lib/ccs/components/ccs/footer.rb +69 -67
  9. data/lib/ccs/components/ccs/header/link.rb +47 -45
  10. data/lib/ccs/components/ccs/header/navigation.rb +85 -84
  11. data/lib/ccs/components/ccs/header/service_authentication.rb +35 -34
  12. data/lib/ccs/components/ccs/header.rb +87 -85
  13. data/lib/ccs/components/ccs/logo.rb +36 -34
  14. data/lib/ccs/components/govuk/accordion/section/content.rb +42 -42
  15. data/lib/ccs/components/govuk/accordion/section/header.rb +48 -48
  16. data/lib/ccs/components/govuk/accordion/section.rb +49 -48
  17. data/lib/ccs/components/govuk/accordion.rb +43 -41
  18. data/lib/ccs/components/govuk/back_link.rb +39 -37
  19. data/lib/ccs/components/govuk/breadcrumbs/link.rb +42 -40
  20. data/lib/ccs/components/govuk/breadcrumbs.rb +40 -38
  21. data/lib/ccs/components/govuk/button.rb +83 -81
  22. data/lib/ccs/components/govuk/cookie_banner/action.rb +45 -43
  23. data/lib/ccs/components/govuk/cookie_banner/message.rb +57 -55
  24. data/lib/ccs/components/govuk/cookie_banner.rb +40 -38
  25. data/lib/ccs/components/govuk/details.rb +38 -36
  26. data/lib/ccs/components/govuk/error_message.rb +46 -44
  27. data/lib/ccs/components/govuk/error_summary/item.rb +41 -39
  28. data/lib/ccs/components/govuk/error_summary.rb +49 -47
  29. data/lib/ccs/components/govuk/field/input/character_count.rb +101 -99
  30. data/lib/ccs/components/govuk/field/input/file_upload.rb +29 -27
  31. data/lib/ccs/components/govuk/field/input/select.rb +61 -59
  32. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +39 -37
  33. data/lib/ccs/components/govuk/field/input/text_input.rb +75 -73
  34. data/lib/ccs/components/govuk/field/input/textarea.rb +43 -41
  35. data/lib/ccs/components/govuk/field/input.rb +46 -44
  36. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +43 -41
  37. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +48 -46
  38. data/lib/ccs/components/govuk/field/inputs/date_input.rb +68 -66
  39. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +29 -27
  40. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +26 -24
  41. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +32 -30
  42. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +39 -37
  43. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +27 -25
  44. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +26 -24
  45. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +32 -30
  46. data/lib/ccs/components/govuk/field/inputs/item.rb +100 -98
  47. data/lib/ccs/components/govuk/field/inputs/radios.rb +43 -41
  48. data/lib/ccs/components/govuk/field/inputs.rb +42 -40
  49. data/lib/ccs/components/govuk/field.rb +90 -88
  50. data/lib/ccs/components/govuk/fieldset/legend.rb +50 -48
  51. data/lib/ccs/components/govuk/fieldset.rb +40 -38
  52. data/lib/ccs/components/govuk/footer/link.rb +41 -39
  53. data/lib/ccs/components/govuk/footer/meta.rb +49 -48
  54. data/lib/ccs/components/govuk/footer/navigation.rb +51 -50
  55. data/lib/ccs/components/govuk/footer.rb +105 -103
  56. data/lib/ccs/components/govuk/form_group.rb +45 -43
  57. data/lib/ccs/components/govuk/header/link.rb +41 -39
  58. data/lib/ccs/components/govuk/header/navigation.rb +54 -53
  59. data/lib/ccs/components/govuk/header.rb +84 -82
  60. data/lib/ccs/components/govuk/hint.rb +33 -31
  61. data/lib/ccs/components/govuk/inset_text.rb +39 -37
  62. data/lib/ccs/components/govuk/label.rb +61 -59
  63. data/lib/ccs/components/govuk/notification_banner.rb +83 -81
  64. data/lib/ccs/components/govuk/pagination/increment/next.rb +29 -27
  65. data/lib/ccs/components/govuk/pagination/increment/previous.rb +28 -26
  66. data/lib/ccs/components/govuk/pagination/increment.rb +78 -76
  67. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +17 -15
  68. data/lib/ccs/components/govuk/pagination/item/form.rb +34 -32
  69. data/lib/ccs/components/govuk/pagination/item/tag.rb +33 -31
  70. data/lib/ccs/components/govuk/pagination/item.rb +47 -45
  71. data/lib/ccs/components/govuk/pagination.rb +69 -67
  72. data/lib/ccs/components/govuk/panel.rb +49 -47
  73. data/lib/ccs/components/govuk/phase_banner.rb +50 -48
  74. data/lib/ccs/components/govuk/skip_link.rb +39 -37
  75. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +40 -38
  76. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +30 -28
  77. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +28 -26
  78. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +47 -45
  79. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +49 -47
  80. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +44 -42
  81. data/lib/ccs/components/govuk/step_by_step_navigation.rb +41 -39
  82. data/lib/ccs/components/govuk/summary_list/action/link.rb +46 -44
  83. data/lib/ccs/components/govuk/summary_list/card/actions.rb +38 -36
  84. data/lib/ccs/components/govuk/summary_list/card/title.rb +37 -35
  85. data/lib/ccs/components/govuk/summary_list/card.rb +48 -46
  86. data/lib/ccs/components/govuk/summary_list/row/actions.rb +38 -36
  87. data/lib/ccs/components/govuk/summary_list/row/key.rb +30 -28
  88. data/lib/ccs/components/govuk/summary_list/row/value.rb +30 -28
  89. data/lib/ccs/components/govuk/summary_list/row.rb +49 -45
  90. data/lib/ccs/components/govuk/summary_list.rb +48 -46
  91. data/lib/ccs/components/govuk/table/body/data_cell.rb +38 -36
  92. data/lib/ccs/components/govuk/table/body/head_cell.rb +37 -35
  93. data/lib/ccs/components/govuk/table/header/head_cell.rb +39 -37
  94. data/lib/ccs/components/govuk/table.rb +83 -81
  95. data/lib/ccs/components/govuk/tabs/panel.rb +47 -45
  96. data/lib/ccs/components/govuk/tabs/tab.rb +42 -40
  97. data/lib/ccs/components/govuk/tabs.rb +48 -46
  98. data/lib/ccs/components/govuk/tag.rb +39 -37
  99. data/lib/ccs/components/govuk/warning_text.rb +49 -47
  100. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +16 -14
  101. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +17 -15
  102. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +17 -15
  103. data/lib/ccs/frontend_helpers/ccs_frontend.rb +1 -1
  104. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +17 -15
  105. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -15
  106. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +17 -15
  107. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +17 -15
  108. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +17 -15
  109. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +17 -15
  110. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +17 -15
  111. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +17 -15
  112. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +19 -17
  113. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -30
  114. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +38 -36
  115. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +19 -17
  116. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +17 -15
  117. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +17 -15
  118. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +27 -25
  119. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +17 -15
  120. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +18 -16
  121. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +17 -15
  122. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +19 -17
  123. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +18 -16
  124. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +19 -17
  125. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +17 -15
  126. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +19 -17
  127. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +19 -17
  128. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +17 -15
  129. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +17 -15
  130. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +17 -15
  131. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +24 -22
  132. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +17 -15
  133. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +17 -15
  134. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +17 -15
  135. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +17 -15
  136. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +17 -15
  137. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +19 -17
  138. data/lib/ccs/frontend_helpers/version.rb +1 -1
  139. metadata +2 -2
@@ -1,51 +1,53 @@
1
1
  require_relative '../field'
2
2
  require_relative '../fieldset'
3
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.
4
+ module CCS
5
+ module Components
6
+ module GovUK
7
+ class Field < Base
8
+ # = GOV.UK Field Inputs
26
9
  #
27
- # @option (see CCS::Components::GovUK::Field#initialize)
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
- def initialize(attribute:, fieldset:, **options)
30
- super(attribute: attribute, **options)
18
+ class Inputs < Field
19
+ private
31
20
 
32
- set_described_by(fieldset, @attribute, @error_message, options[:hint])
21
+ attr_reader :fieldset
33
22
 
34
- @fieldset = Fieldset.new(context: @context, **fieldset)
35
- end
23
+ public
36
24
 
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)
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::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
5
+ module CCS
6
+ module Components
7
+ module GovUK
8
+ # = GOV.UK Field
33
9
  #
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
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
- # @yieldparam displayed_error_message [ActiveSupport::SafeBuffer] the error message HTML to display
58
- #
59
- # @return [ActiveSupport::SafeBuffer]
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
- def render(&block)
62
- form_group.render(&block)
63
- end
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
- private
62
+ def render(&block)
63
+ form_group.render(&block)
64
+ end
66
65
 
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]
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
- # 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
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
- 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
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
- return unless aria_described_by.any?
99
+ return unless aria_described_by.any?
99
100
 
100
- ((field_options[:attributes] ||= {})[:aria] ||= {})[:describedby] = aria_described_by.join(' ')
101
+ ((field_options[:attributes] ||= {})[:aria] ||= {})[:describedby] = aria_described_by.join(' ')
102
+ end
101
103
  end
102
104
  end
103
- end
104
105
 
105
- ActionView::Base.field_error_proc = proc { |html_tag, _instance| html_tag }
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::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
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ class Fieldset < Base
7
+ # = GOV.UK Fieldset Legend
28
8
  #
29
- # @option options [String] :classes additional CSS classes for the legend HTML
9
+ # The legend for the fieldset
30
10
  #
31
- # @option caption [String] :text text for the caption
32
- # @option caption [String] :classes additional CSS classes for the caption HTML
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
- def initialize(text:, is_page_heading: nil, caption: nil, **options)
35
- super(**options)
18
+ class Legend < Base
19
+ private
36
20
 
37
- @text = text
38
- @is_page_heading = is_page_heading
39
- @caption = caption
40
- end
21
+ attr_reader :text, :is_page_heading, :caption
41
22
 
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
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
- # The default attributes for the fieldset legend
58
+ # The default attributes for the fieldset legend
58
59
 
59
- DEFAULT_ATTRIBUTES = { class: 'govuk-fieldset__legend' }.freeze
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::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
4
+ module CCS
5
+ module Components
6
+ module GovUK
7
+ # = GOV.UK Fieldset
24
8
  #
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
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
- def initialize(legend: nil, **options)
29
- super(**options)
15
+ class Fieldset < Base
16
+ private
30
17
 
31
- @legend = Legend.new(context: @context, **legend) if legend
32
- end
18
+ attr_reader :legend
33
19
 
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]
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
- def render
41
- tag.fieldset(**options[:attributes]) do
42
- concat(legend.render) if legend
43
- yield
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
- # The default attributes for the fieldset
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
- DEFAULT_ATTRIBUTES = { class: 'govuk-fieldset' }.freeze
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::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
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ class Footer < Base
7
+ # = GOV.UK Footer link
28
8
  #
29
- # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
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
- def initialize(text:, href:, li_class:, **options)
32
- super(**options)
18
+ class Link < Base
19
+ private
33
20
 
34
- @text = text
35
- @href = href
36
- @li_class = li_class
37
- end
21
+ attr_reader :text, :href, :li_class
38
22
 
39
- # Generates the HTML for the GOV.UK Footer link
40
- #
41
- # @return [ActiveSupport::SafeBuffer]
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
- def render
44
- tag.li(class: li_class) do
45
- options[:attributes][:class] = 'govuk-footer__link'
44
+ def render
45
+ tag.li(class: li_class) do
46
+ options[:attributes][:class] = 'govuk-footer__link'
46
47
 
47
- link_to(text, href, **options[:attributes])
48
+ link_to(text, href, **options[:attributes])
49
+ end
48
50
  end
49
51
  end
50
52
  end