ccs-frontend_helpers 0.1.0.rc.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -5
  3. data/CHANGELOG.md +2 -4
  4. data/Gemfile +1 -15
  5. data/Gemfile.lock +80 -81
  6. data/ccs-frontend_helpers.gemspec +10 -0
  7. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_panels.rb +79 -0
  8. data/lib/ccs/frontend_helpers/ccs_frontend/footer.rb +119 -6
  9. data/lib/ccs/frontend_helpers/ccs_frontend/header.rb +183 -6
  10. data/lib/ccs/{components/ccs → frontend_helpers/ccs_frontend}/logo.rb +12 -10
  11. data/lib/ccs/frontend_helpers/ccs_frontend.rb +4 -2
  12. data/lib/ccs/frontend_helpers/govuk_frontend/accordion.rb +95 -8
  13. data/lib/ccs/frontend_helpers/govuk_frontend/back_link.rb +17 -6
  14. data/lib/ccs/frontend_helpers/govuk_frontend/breadcrumbs.rb +54 -6
  15. data/lib/ccs/frontend_helpers/govuk_frontend/button.rb +105 -6
  16. data/lib/ccs/frontend_helpers/govuk_frontend/cookie_banner.rb +114 -6
  17. data/lib/ccs/frontend_helpers/govuk_frontend/details.rb +23 -7
  18. data/lib/ccs/frontend_helpers/govuk_frontend/error_message.rb +32 -11
  19. data/lib/ccs/frontend_helpers/govuk_frontend/error_summary.rb +65 -13
  20. data/lib/ccs/frontend_helpers/govuk_frontend/field/character_count.rb +165 -0
  21. data/lib/ccs/frontend_helpers/govuk_frontend/field/checkboxes.rb +200 -0
  22. data/lib/ccs/frontend_helpers/govuk_frontend/field/date_input.rb +153 -0
  23. data/lib/ccs/frontend_helpers/govuk_frontend/field/file_upload.rb +83 -0
  24. data/lib/ccs/frontend_helpers/govuk_frontend/field/input.rb +153 -0
  25. data/lib/ccs/frontend_helpers/govuk_frontend/field/radios.rb +201 -0
  26. data/lib/ccs/frontend_helpers/govuk_frontend/field/select.rb +124 -0
  27. data/lib/ccs/frontend_helpers/govuk_frontend/field/textarea.rb +106 -0
  28. data/lib/ccs/frontend_helpers/govuk_frontend/field.rb +213 -0
  29. data/lib/ccs/frontend_helpers/govuk_frontend/fieldset.rb +48 -7
  30. data/lib/ccs/frontend_helpers/govuk_frontend/footer.rb +161 -6
  31. data/lib/ccs/frontend_helpers/govuk_frontend/form_group.rb +24 -13
  32. data/lib/ccs/frontend_helpers/govuk_frontend/header.rb +139 -6
  33. data/lib/ccs/frontend_helpers/govuk_frontend/hint.rb +17 -8
  34. data/lib/ccs/frontend_helpers/govuk_frontend/inset_text.rb +21 -7
  35. data/lib/ccs/frontend_helpers/govuk_frontend/label.rb +70 -7
  36. data/lib/ccs/frontend_helpers/govuk_frontend/notification_banner.rb +113 -7
  37. data/lib/ccs/frontend_helpers/govuk_frontend/pagination.rb +314 -6
  38. data/lib/ccs/frontend_helpers/govuk_frontend/panel.rb +28 -7
  39. data/lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb +27 -8
  40. data/lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb +18 -6
  41. data/lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb +186 -7
  42. data/lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb +204 -6
  43. data/lib/ccs/frontend_helpers/govuk_frontend/table.rb +100 -11
  44. data/lib/ccs/frontend_helpers/govuk_frontend/tabs.rb +73 -6
  45. data/lib/ccs/frontend_helpers/govuk_frontend/tag.rb +21 -7
  46. data/lib/ccs/frontend_helpers/govuk_frontend/warning_text.rb +30 -7
  47. data/lib/ccs/frontend_helpers/govuk_frontend.rb +19 -17
  48. data/lib/ccs/frontend_helpers/shared_methods.rb +27 -0
  49. data/lib/ccs/frontend_helpers/version.rb +1 -1
  50. metadata +142 -112
  51. data/.ruby-version +0 -1
  52. data/lib/ccs/components/base.rb +0 -64
  53. data/lib/ccs/components/ccs/dashboard_section/panel.rb +0 -57
  54. data/lib/ccs/components/ccs/dashboard_section.rb +0 -71
  55. data/lib/ccs/components/ccs/footer/link.rb +0 -55
  56. data/lib/ccs/components/ccs/footer/meta.rb +0 -59
  57. data/lib/ccs/components/ccs/footer/navigation.rb +0 -60
  58. data/lib/ccs/components/ccs/footer.rb +0 -95
  59. data/lib/ccs/components/ccs/header/link.rb +0 -60
  60. data/lib/ccs/components/ccs/header/navigation.rb +0 -98
  61. data/lib/ccs/components/ccs/header/service_authentication.rb +0 -53
  62. data/lib/ccs/components/ccs/header.rb +0 -110
  63. data/lib/ccs/components/govuk/accordion/section/content.rb +0 -53
  64. data/lib/ccs/components/govuk/accordion/section/header.rb +0 -57
  65. data/lib/ccs/components/govuk/accordion/section.rb +0 -61
  66. data/lib/ccs/components/govuk/accordion.rb +0 -58
  67. data/lib/ccs/components/govuk/back_link.rb +0 -51
  68. data/lib/ccs/components/govuk/breadcrumbs/link.rb +0 -57
  69. data/lib/ccs/components/govuk/breadcrumbs.rb +0 -55
  70. data/lib/ccs/components/govuk/button.rb +0 -107
  71. data/lib/ccs/components/govuk/cookie_banner/action.rb +0 -60
  72. data/lib/ccs/components/govuk/cookie_banner/message.rb +0 -80
  73. data/lib/ccs/components/govuk/cookie_banner.rb +0 -55
  74. data/lib/ccs/components/govuk/details.rb +0 -53
  75. data/lib/ccs/components/govuk/error_message.rb +0 -60
  76. data/lib/ccs/components/govuk/error_summary/item.rb +0 -54
  77. data/lib/ccs/components/govuk/error_summary.rb +0 -70
  78. data/lib/ccs/components/govuk/field/input/character_count.rb +0 -129
  79. data/lib/ccs/components/govuk/field/input/file_upload.rb +0 -44
  80. data/lib/ccs/components/govuk/field/input/select.rb +0 -82
  81. data/lib/ccs/components/govuk/field/input/text_input/fix.rb +0 -55
  82. data/lib/ccs/components/govuk/field/input/text_input.rb +0 -97
  83. data/lib/ccs/components/govuk/field/input/textarea.rb +0 -59
  84. data/lib/ccs/components/govuk/field/input.rb +0 -62
  85. data/lib/ccs/components/govuk/field/inputs/checkboxes.rb +0 -69
  86. data/lib/ccs/components/govuk/field/inputs/date_input/item.rb +0 -65
  87. data/lib/ccs/components/govuk/field/inputs/date_input.rb +0 -89
  88. data/lib/ccs/components/govuk/field/inputs/item/checkbox/form.rb +0 -47
  89. data/lib/ccs/components/govuk/field/inputs/item/checkbox/tag.rb +0 -43
  90. data/lib/ccs/components/govuk/field/inputs/item/checkbox.rb +0 -50
  91. data/lib/ccs/components/govuk/field/inputs/item/divider.rb +0 -50
  92. data/lib/ccs/components/govuk/field/inputs/item/radio/form.rb +0 -44
  93. data/lib/ccs/components/govuk/field/inputs/item/radio/tag.rb +0 -43
  94. data/lib/ccs/components/govuk/field/inputs/item/radio.rb +0 -50
  95. data/lib/ccs/components/govuk/field/inputs/item.rb +0 -111
  96. data/lib/ccs/components/govuk/field/inputs/radios.rb +0 -69
  97. data/lib/ccs/components/govuk/field/inputs.rb +0 -57
  98. data/lib/ccs/components/govuk/field.rb +0 -108
  99. data/lib/ccs/components/govuk/fieldset/legend.rb +0 -65
  100. data/lib/ccs/components/govuk/fieldset.rb +0 -54
  101. data/lib/ccs/components/govuk/footer/link.rb +0 -55
  102. data/lib/ccs/components/govuk/footer/meta.rb +0 -59
  103. data/lib/ccs/components/govuk/footer/navigation.rb +0 -60
  104. data/lib/ccs/components/govuk/footer.rb +0 -131
  105. data/lib/ccs/components/govuk/form_group.rb +0 -60
  106. data/lib/ccs/components/govuk/header/link.rb +0 -56
  107. data/lib/ccs/components/govuk/header/navigation.rb +0 -71
  108. data/lib/ccs/components/govuk/header.rb +0 -107
  109. data/lib/ccs/components/govuk/hint.rb +0 -49
  110. data/lib/ccs/components/govuk/inset_text.rb +0 -52
  111. data/lib/ccs/components/govuk/label.rb +0 -85
  112. data/lib/ccs/components/govuk/notification_banner.rb +0 -107
  113. data/lib/ccs/components/govuk/pagination/increment/next.rb +0 -44
  114. data/lib/ccs/components/govuk/pagination/increment/previous.rb +0 -43
  115. data/lib/ccs/components/govuk/pagination/increment.rb +0 -98
  116. data/lib/ccs/components/govuk/pagination/item/ellipsis.rb +0 -28
  117. data/lib/ccs/components/govuk/pagination/item/form.rb +0 -49
  118. data/lib/ccs/components/govuk/pagination/item/tag.rb +0 -47
  119. data/lib/ccs/components/govuk/pagination/item.rb +0 -64
  120. data/lib/ccs/components/govuk/pagination.rb +0 -96
  121. data/lib/ccs/components/govuk/panel.rb +0 -62
  122. data/lib/ccs/components/govuk/phase_banner.rb +0 -69
  123. data/lib/ccs/components/govuk/skip_link.rb +0 -51
  124. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb +0 -53
  125. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb +0 -50
  126. data/lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb +0 -45
  127. data/lib/ccs/components/govuk/step_by_step_navigation/section/content.rb +0 -63
  128. data/lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb +0 -69
  129. data/lib/ccs/components/govuk/step_by_step_navigation/section.rb +0 -56
  130. data/lib/ccs/components/govuk/step_by_step_navigation.rb +0 -59
  131. data/lib/ccs/components/govuk/summary_list/action/link.rb +0 -59
  132. data/lib/ccs/components/govuk/summary_list/card/actions.rb +0 -59
  133. data/lib/ccs/components/govuk/summary_list/card/title.rb +0 -51
  134. data/lib/ccs/components/govuk/summary_list/card.rb +0 -63
  135. data/lib/ccs/components/govuk/summary_list/row/actions.rb +0 -59
  136. data/lib/ccs/components/govuk/summary_list/row/key.rb +0 -47
  137. data/lib/ccs/components/govuk/summary_list/row/value.rb +0 -47
  138. data/lib/ccs/components/govuk/summary_list/row.rb +0 -67
  139. data/lib/ccs/components/govuk/summary_list.rb +0 -74
  140. data/lib/ccs/components/govuk/table/body/data_cell.rb +0 -53
  141. data/lib/ccs/components/govuk/table/body/head_cell.rb +0 -52
  142. data/lib/ccs/components/govuk/table/header/head_cell.rb +0 -54
  143. data/lib/ccs/components/govuk/table.rb +0 -111
  144. data/lib/ccs/components/govuk/tabs/panel.rb +0 -58
  145. data/lib/ccs/components/govuk/tabs/tab.rb +0 -56
  146. data/lib/ccs/components/govuk/tabs.rb +0 -66
  147. data/lib/ccs/components/govuk/tag.rb +0 -51
  148. data/lib/ccs/components/govuk/warning_text.rb +0 -61
  149. data/lib/ccs/frontend_helpers/ccs_frontend/dashboard_section.rb +0 -27
  150. data/lib/ccs/frontend_helpers/govuk_frontend/character_count.rb +0 -28
  151. data/lib/ccs/frontend_helpers/govuk_frontend/checkboxes.rb +0 -28
  152. data/lib/ccs/frontend_helpers/govuk_frontend/date_input.rb +0 -28
  153. data/lib/ccs/frontend_helpers/govuk_frontend/file_upload.rb +0 -28
  154. data/lib/ccs/frontend_helpers/govuk_frontend/input.rb +0 -28
  155. data/lib/ccs/frontend_helpers/govuk_frontend/radios.rb +0 -28
  156. data/lib/ccs/frontend_helpers/govuk_frontend/select.rb +0 -28
  157. data/lib/ccs/frontend_helpers/govuk_frontend/textarea.rb +0 -28
@@ -1,43 +0,0 @@
1
- require_relative '../radio'
2
-
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
11
- #
12
- # This is used to generate an individual radio item using +radio_button_tag+
13
-
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)
18
-
19
- def initialize(attribute:, label:, **options)
20
- super(attribute: attribute, label: label, **options)
21
-
22
- @options[:attributes][:id] ||= "#{sanitize_to_id(@attribute)}_#{sanitize_to_id(@value)}"
23
-
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]
30
-
31
- def render
32
- super() do
33
- context.radio_button_tag(@attribute, @value, @options[:checked], **@options[:attributes])
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,50 +0,0 @@
1
- require_relative '../item'
2
-
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
10
- #
11
- # This is used to generate an individual radio item
12
-
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))
18
-
19
- def initialize(attribute:, label:, **options)
20
- super(attribute: attribute, **options)
21
-
22
- label[:classes] = "govuk-radios__label #{label[:classes]}".rstrip
23
- end
24
-
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
35
- end
36
-
37
- # The default attributes for the radio
38
-
39
- DEFAULT_ATTRIBUTES = { class: 'govuk-radios__input' }.freeze
40
-
41
- # The type of the input item
42
-
43
- ITEM_TYPE = 'radios'.freeze
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,111 +0,0 @@
1
- require_relative '../inputs'
2
- require_relative '../../label'
3
-
4
- module CCS
5
- module Components
6
- module GovUK
7
- class Field < Base
8
- class Inputs < Field
9
- # = GOV.UK Field Inputs Item
10
- #
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
17
- #
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
106
- end
107
- end
108
- end
109
- end
110
- end
111
- end
@@ -1,69 +0,0 @@
1
- require_relative '../input'
2
- require_relative 'item/divider'
3
- require_relative 'item/radio/form'
4
- require_relative 'item/radio/tag'
5
-
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
18
-
19
- class Radios < Inputs
20
- private
21
-
22
- attr_reader :radio_items
23
-
24
- public
25
-
26
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
27
-
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)
33
-
34
- def initialize(attribute:, radio_items:, **options)
35
- super(attribute: attribute, **options)
36
-
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
41
-
42
- radio_item_class = @options[:form] ? Item::Radio::Form : Inputs::Item::Radio::Tag
43
-
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
46
-
47
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
48
-
49
- # Generates the HTML for the GOV.UK Radios component
50
- #
51
- # @return [ActiveSupport::SafeBuffer]
52
-
53
- def render
54
- super() do
55
- tag.div(**options[:attributes]) do
56
- radio_items.each { |radio_item| concat(radio_item.render) }
57
- end
58
- end
59
- end
60
-
61
- # The default attributes for the radios
62
-
63
- DEFAULT_ATTRIBUTES = { class: 'govuk-radios', data: { module: 'govuk-radios' } }.freeze
64
- end
65
- end
66
- end
67
- end
68
- end
69
- end
@@ -1,57 +0,0 @@
1
- require_relative '../field'
2
- require_relative '../fieldset'
3
-
4
- module CCS
5
- module Components
6
- module GovUK
7
- class Field < Base
8
- # = GOV.UK Field Inputs
9
- #
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
17
-
18
- class Inputs < Field
19
- private
20
-
21
- attr_reader :fieldset
22
-
23
- public
24
-
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
51
- end
52
- end
53
- end
54
- end
55
- end
56
- end
57
- end
@@ -1,108 +0,0 @@
1
- require_relative '../base'
2
- require_relative 'form_group'
3
- require_relative 'hint'
4
-
5
- module CCS
6
- module Components
7
- module GovUK
8
- # = GOV.UK Field
9
- #
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.
12
- #
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
53
-
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]
61
-
62
- def render(&block)
63
- form_group.render(&block)
64
- end
65
-
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
82
- end
83
-
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
91
-
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
98
-
99
- return unless aria_described_by.any?
100
-
101
- ((field_options[:attributes] ||= {})[:aria] ||= {})[:describedby] = aria_described_by.join(' ')
102
- end
103
- end
104
- end
105
-
106
- ActionView::Base.field_error_proc = proc { |html_tag, _instance| html_tag }
107
- end
108
- end
@@ -1,65 +0,0 @@
1
- require_relative '../../base'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Fieldset < Base
7
- # = GOV.UK Fieldset Legend
8
- #
9
- # The legend for the fieldset
10
- #
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
17
-
18
- class Legend < Base
19
- private
20
-
21
- attr_reader :text, :is_page_heading, :caption
22
-
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
55
- end
56
- end
57
-
58
- # The default attributes for the fieldset legend
59
-
60
- DEFAULT_ATTRIBUTES = { class: 'govuk-fieldset__legend' }.freeze
61
- end
62
- end
63
- end
64
- end
65
- end
@@ -1,54 +0,0 @@
1
- require_relative '../base'
2
- require_relative 'fieldset/legend'
3
-
4
- module CCS
5
- module Components
6
- module GovUK
7
- # = GOV.UK Fieldset
8
- #
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
14
-
15
- class Fieldset < Base
16
- private
17
-
18
- attr_reader :legend
19
-
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
28
-
29
- def initialize(legend: nil, **options)
30
- super(**options)
31
-
32
- @legend = Legend.new(context: @context, **legend) if legend
33
- end
34
-
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
47
-
48
- # The default attributes for the fieldset
49
-
50
- DEFAULT_ATTRIBUTES = { class: 'govuk-fieldset' }.freeze
51
- end
52
- end
53
- end
54
- end
@@ -1,55 +0,0 @@
1
- require_relative '../../base'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Footer < Base
7
- # = GOV.UK Footer link
8
- #
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
17
-
18
- class Link < Base
19
- private
20
-
21
- attr_reader :text, :href, :li_class
22
-
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]
43
-
44
- def render
45
- tag.li(class: li_class) do
46
- options[:attributes][:class] = 'govuk-footer__link'
47
-
48
- link_to(text, href, **options[:attributes])
49
- end
50
- end
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,59 +0,0 @@
1
- require_relative 'link'
2
-
3
- module CCS
4
- module Components
5
- module GovUK
6
- class Footer < Base
7
- # = GOV.UK Footer Meta
8
- #
9
- # The footer meta section
10
- #
11
- # @!attribute [r] meta_links
12
- # @return [Array<Link>] An array of the initialised meta links
13
- # @!attribute [r] visually_hidden_title
14
- # @return [String] Title for the meta section
15
- # @!attribute [r] text
16
- # @return [String] Text to add to the meta section of the footer
17
-
18
- class Meta
19
- include ActionView::Context
20
- include ActionView::Helpers
21
-
22
- private
23
-
24
- attr_reader :meta_links, :visually_hidden_title, :text
25
-
26
- public
27
-
28
- # @param items [Array<Hash>] an array of links for the meta section.
29
- # See {Components::GovUK::Footer::Link#initialize Link#initialize} for details of the items in the array.
30
- # @param visually_hidden_title [String] ('Support links') title for the meta section
31
- # @param text [String] text to add to the meta section of the footer
32
- # @param context [ActionView::Base] the view context
33
-
34
- def initialize(context:, items: nil, visually_hidden_title: nil, text: nil)
35
- @meta_links = items&.map { |meta_link| Link.new(li_class: 'govuk-footer__inline-list-item', context: context, **meta_link) }
36
- @visually_hidden_title = visually_hidden_title || 'Support links'
37
- @text = text
38
- end
39
-
40
- # Generates the HTML for the GOV.UK Footer Meta sections
41
- #
42
- # @return [ActiveSupport::SafeBuffer]
43
-
44
- def render
45
- capture do
46
- concat(tag.h2(visually_hidden_title, class: 'govuk-visually-hidden'))
47
- if meta_links
48
- concat(tag.ul(class: 'govuk-footer__inline-list') do
49
- meta_links.each { |meta_link| concat(meta_link.render) }
50
- end)
51
- end
52
- concat(tag.div(text, class: 'govuk-footer__meta-custom')) if text
53
- end
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end