govuk-design-system-rails 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/app/helpers/govuk_design_system/accordion_helper.rb +7 -0
- data/app/helpers/govuk_design_system/back_link_helper.rb +13 -0
- data/app/helpers/govuk_design_system/breadcrumbs_helper.rb +7 -0
- data/app/helpers/govuk_design_system/button_helper.rb +71 -0
- data/app/helpers/govuk_design_system/checkboxes_helper.rb +8 -0
- data/app/helpers/govuk_design_system/components_helper.rb +13 -0
- data/app/helpers/govuk_design_system/cookie_banner_helper.rb +7 -0
- data/app/helpers/govuk_design_system/date_input_helper.rb +8 -0
- data/app/helpers/govuk_design_system/details_helper.rb +32 -0
- data/app/helpers/govuk_design_system/error_message_helper.rb +7 -0
- data/app/helpers/govuk_design_system/error_summary_helper.rb +20 -0
- data/app/helpers/govuk_design_system/fieldset_helper.rb +9 -0
- data/app/helpers/govuk_design_system/file_upload_helper.rb +59 -0
- data/app/helpers/govuk_design_system/header_helper.rb +7 -0
- data/app/helpers/govuk_design_system/hint_helper.rb +7 -0
- data/app/helpers/govuk_design_system/hmcts_badge_helper.rb +7 -0
- data/app/helpers/govuk_design_system/hmcts_banner_helper.rb +7 -0
- data/app/helpers/govuk_design_system/input_helper.rb +8 -0
- data/app/helpers/govuk_design_system/inset_text_helper.rb +9 -0
- data/app/helpers/govuk_design_system/label_helper.rb +7 -0
- data/app/helpers/govuk_design_system/notification_banner_helper.rb +8 -0
- data/app/helpers/govuk_design_system/phase_banner_helper.rb +21 -0
- data/app/helpers/govuk_design_system/radios_helper.rb +8 -0
- data/app/helpers/govuk_design_system/select_helper.rb +8 -0
- data/app/helpers/govuk_design_system/skip_link_helper.rb +13 -0
- data/app/helpers/govuk_design_system/summary_list_helper.rb +7 -0
- data/app/helpers/govuk_design_system/tabs_helper.rb +7 -0
- data/app/helpers/govuk_design_system/tag_helper.rb +8 -0
- data/app/helpers/govuk_design_system/textarea_helper.rb +8 -0
- data/app/helpers/govuk_design_system/warning_text_helper.rb +20 -0
- data/app/views/components/_govuk_accordion.html.erb +44 -0
- data/app/views/components/_govuk_action_link.html.erb +12 -0
- data/app/views/components/_govuk_breadcrumbs.html.erb +25 -0
- data/app/views/components/_govuk_checkboxes.html.erb +125 -0
- data/app/views/components/_govuk_cookie_banner.html.erb +75 -0
- data/app/views/components/_govuk_date_input.html.erb +94 -0
- data/app/views/components/_govuk_error_message.html.erb +13 -0
- data/app/views/components/_govuk_error_summary.html.erb +32 -0
- data/app/views/components/_govuk_fieldset.html.erb +21 -0
- data/app/views/components/_govuk_header.html.erb +64 -0
- data/app/views/components/_govuk_hint.html.erb +7 -0
- data/app/views/components/_govuk_hr.html.erb +1 -0
- data/app/views/components/_govuk_input.html.erb +97 -0
- data/app/views/components/_govuk_inset_text.html.erb +10 -0
- data/app/views/components/_govuk_label.html.erb +18 -0
- data/app/views/components/_govuk_notification_banner.html.erb +68 -0
- data/app/views/components/_govuk_radios.html.erb +141 -0
- data/app/views/components/_govuk_select.html.erb +105 -0
- data/app/views/components/_govuk_summary_list.html.erb +39 -0
- data/app/views/components/_govuk_tabs.html.erb +46 -0
- data/app/views/components/_govuk_textarea.html.erb +70 -0
- data/app/views/components/_hmcts_banner.html.erb +33 -0
- data/app/views/form_components/_govuk_checkboxes.html.erb +21 -0
- data/app/views/form_components/_govuk_date_input.html.erb +32 -0
- data/app/views/form_components/_govuk_input.html.erb +11 -0
- data/app/views/form_components/_govuk_radios.html.erb +24 -0
- data/app/views/form_components/_govuk_select.html.erb +25 -0
- data/app/views/form_components/_govuk_textarea.html.erb +11 -0
- data/lib/govuk-design-system-rails.rb +1 -0
- data/lib/govuk_design_system/engine.rb +50 -0
- data/lib/govuk_design_system.rb +4 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/javascript/packs/application.js +15 -0
- data/spec/dummy/app/jobs/application_job.rb +7 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +33 -0
- data/spec/dummy/config/application.rb +38 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +76 -0
- data/spec/dummy/config/environments/production.rb +120 -0
- data/spec/dummy/config/environments/test.rb +59 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/assets.rb +12 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +8 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/permissions_policy.rb +11 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +43 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/config.ru +6 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/development_secret.txt +1 -0
- data/spec/helpers/govuk_design_system/accordion_helper_spec.rb +353 -0
- data/spec/helpers/govuk_design_system/breadcrumbs_helper_spec.rb +90 -0
- data/spec/helpers/govuk_design_system/button_helper_spec.rb +34 -0
- data/spec/helpers/govuk_design_system/checkboxes_helper_spec.rb +146 -0
- data/spec/helpers/govuk_design_system/cookie_banner_helper_spec.rb +65 -0
- data/spec/helpers/govuk_design_system/date_input_helper_spec.rb +63 -0
- data/spec/helpers/govuk_design_system/details_helper_spec.rb +42 -0
- data/spec/helpers/govuk_design_system/error_message_helper_spec.rb +18 -0
- data/spec/helpers/govuk_design_system/error_summary_helper_spec.rb +39 -0
- data/spec/helpers/govuk_design_system/header_helper_spec.rb +138 -0
- data/spec/helpers/govuk_design_system/hint_helper_spec.rb +20 -0
- data/spec/helpers/govuk_design_system/hmcts_badge_helper_spec.rb +16 -0
- data/spec/helpers/govuk_design_system/hmcts_banner_helper_spec.rb +59 -0
- data/spec/helpers/govuk_design_system/input_helper_spec.rb +157 -0
- data/spec/helpers/govuk_design_system/inset_text_helper_spec.rb +58 -0
- data/spec/helpers/govuk_design_system/label_helper_spec.rb +21 -0
- data/spec/helpers/govuk_design_system/notification_banner_helper_spec.rb +98 -0
- data/spec/helpers/govuk_design_system/radios_helper_spec.rb +270 -0
- data/spec/helpers/govuk_design_system/select_helper_spec.rb +85 -0
- data/spec/helpers/govuk_design_system/summary_list_helper_spec.rb +138 -0
- data/spec/helpers/govuk_design_system/tabs_helper_spec.rb +129 -0
- data/spec/helpers/govuk_design_system/tag_helper_spec.rb +17 -0
- data/spec/helpers/govuk_design_system/textarea_helper_spec.rb +67 -0
- data/spec/rails_helper.rb +64 -0
- data/spec/spec_helper.rb +116 -0
- metadata +401 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e76e9057f3d50ef6e64379373d685d310d8da0ebd530a8398c90bded0c43540b
|
4
|
+
data.tar.gz: 0fcc31f7dd8d80495fbb1b585777c55436b98b0cc7e548743d6a3bfadee211d2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6f92bc3beb2e702f03352c0ebb691b35635ebe2b5f2fa68d21b8fd0a251207ce2e5119a23e5da36312917bf35c691cfeda81a497d8e98a6e8f46e0e7c1d0cbf4
|
7
|
+
data.tar.gz: 7568abab4de1c9a796b58d839548de467069c4ab5911e5399b831a2ad53ffe584a6c546dd33df68d98ff1f9e6d4084c0699ac50b0e178b85dbfd1a3b7debdfb9
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module GovukDesignSystem
|
2
|
+
module BackLinkHelper
|
3
|
+
# Use the [back link component](https://design-system.service.gov.uk/components/back-link/)
|
4
|
+
# to help users go back to the previous page in a multi-page transaction.
|
5
|
+
#
|
6
|
+
# Code based upon [nunjucks template](https://github.com/alphagov/govuk-frontend/blob/master/src/govuk/components/back-link/template.njk)
|
7
|
+
def govukBackLink(href:, text: nil, html: nil, classes: "", attributes: {})
|
8
|
+
attributes[:class] = "govuk-back-link #{classes}"
|
9
|
+
|
10
|
+
link_to (html || text), href, attributes
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module GovukDesignSystem
|
2
|
+
module ButtonHelper
|
3
|
+
# Based on https://github.com/alphagov/govuk-frontend/blob/master/src/govuk/components/button/template.njk
|
4
|
+
def govukButton(element: nil, text: nil, html: nil, name: nil, type: nil, value: nil, disabled: nil, href: nil, classes: "", attributes: {}, preventDoubleClick: nil, isStartButton: nil)
|
5
|
+
# Set classes for this component
|
6
|
+
attributes[:class] = class_names("govuk-button", classes, { "govuk-button--disabled" => disabled })
|
7
|
+
attributes[:data] ||= {}
|
8
|
+
attributes[:data][:module] ||= "govuk-button"
|
9
|
+
|
10
|
+
# Element should be lower-case if set
|
11
|
+
element&.downcase!
|
12
|
+
|
13
|
+
# Determine type of element to use, if not explicitly set
|
14
|
+
element ||= (href ? "a" : "button")
|
15
|
+
|
16
|
+
if isStartButton
|
17
|
+
iconHtml = '<svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" aria-hidden="true" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"/></svg>'.html_safe
|
18
|
+
attributes[:class] += " govuk-button--start"
|
19
|
+
end
|
20
|
+
|
21
|
+
# Define common attributes we can use for both button and input types
|
22
|
+
|
23
|
+
button_attributes = {}
|
24
|
+
|
25
|
+
if name
|
26
|
+
button_attributes[:name] = name
|
27
|
+
end
|
28
|
+
|
29
|
+
if disabled
|
30
|
+
button_attributes[:disabled] = "disabled"
|
31
|
+
button_attributes["aria-disabled"] = "true"
|
32
|
+
end
|
33
|
+
|
34
|
+
if preventDoubleClick
|
35
|
+
button_attributes["data-prevent-double-click"] = "true"
|
36
|
+
end
|
37
|
+
|
38
|
+
# Actually create a button... or a link!
|
39
|
+
case element
|
40
|
+
when "a"
|
41
|
+
|
42
|
+
attributes[:role] = "button"
|
43
|
+
attributes[:draggable] = "false"
|
44
|
+
|
45
|
+
link_to (href || "#"), attributes do
|
46
|
+
concat(html || text)
|
47
|
+
concat iconHtml.to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
when "button"
|
51
|
+
attributes[:value] = value if value
|
52
|
+
attributes[:type] = type if type
|
53
|
+
|
54
|
+
attributes.merge!(button_attributes)
|
55
|
+
|
56
|
+
tag.button(**attributes) do
|
57
|
+
concat(html || text)
|
58
|
+
concat iconHtml.to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
when "input"
|
62
|
+
attributes[:value] = text
|
63
|
+
attributes[:type] = type || "submit"
|
64
|
+
|
65
|
+
attributes.merge!(button_attributes)
|
66
|
+
|
67
|
+
content_tag "input", attributes
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module GovukDesignSystem
|
2
|
+
module ComponentsHelper
|
3
|
+
# Patterns for names and ids can be found in examples here: https://guides.rubyonrails.org/form_helpers.html
|
4
|
+
def get_attribute_name(form, attribute)
|
5
|
+
form.object_name.present? ? "#{form.object_name}[#{attribute}]" : attribute.to_s
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_attribute_id_prefix(form, attribute)
|
9
|
+
initial_name = form.object_name.present? ? "#{form.object_name}_#{attribute}" : attribute.to_s
|
10
|
+
initial_name.gsub(/[\[\]_]+/, "_")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module GovukDesignSystem
|
2
|
+
module DetailsHelper
|
3
|
+
# Generates the HTML for the
|
4
|
+
# [Details component](https://design-system.service.gov.uk/components/details/)
|
5
|
+
# from the GOV.UK Design System.
|
6
|
+
#
|
7
|
+
# The method name and parameters are camelCased to follow the convention of
|
8
|
+
# the Nunjucks macros from the GOV.UK Design System, to make it easier to
|
9
|
+
# copy and paste templates from the Prototyping Kit.
|
10
|
+
#
|
11
|
+
#
|
12
|
+
# Implementation based on https://github.com/alphagov/govuk-frontend/blob/master/src/govuk/components/details/
|
13
|
+
#
|
14
|
+
def govukDetails(summaryText: nil, summaryHtml: nil, text: nil, html: nil, id: nil, open: nil, classes: "", attributes: {})
|
15
|
+
attributes.merge!("class" => class_names("govuk-details", classes), id: id, "data-module" => "govuk-details")
|
16
|
+
attributes["open"] = "open" if open
|
17
|
+
|
18
|
+
content_tag("details", attributes) do
|
19
|
+
summary = content_tag("summary", class: "govuk-details__summary") do
|
20
|
+
content_tag("span", class: "govuk-details__summary-text") do
|
21
|
+
summaryHtml || summaryText
|
22
|
+
end
|
23
|
+
end
|
24
|
+
content = content_tag("div", class: "govuk-details__text") do
|
25
|
+
html || text || yield
|
26
|
+
end
|
27
|
+
|
28
|
+
summary + content
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module GovukDesignSystem
|
2
|
+
module ErrorSummaryHelper
|
3
|
+
def govukErrorSummary(kwargs = {})
|
4
|
+
form = kwargs[:form]
|
5
|
+
|
6
|
+
if form.present?
|
7
|
+
errors = kwargs[:errors] || form.object.errors
|
8
|
+
return unless errors.try(:any?)
|
9
|
+
|
10
|
+
kwargs[:titleText] = "There is a problem"
|
11
|
+
kwargs[:errorList] = errors.details.keys.flat_map do |attribute|
|
12
|
+
prefix = get_attribute_id_prefix(form, attribute)
|
13
|
+
errors.full_messages_for(attribute).map { |m| { text: m, href: "##{prefix}-error" } }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
render "components/govuk_error_summary", **kwargs
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module GovukDesignSystem
|
2
|
+
# Based on https://github.com/alphagov/govuk-frontend/blob/master/src/govuk/components/fieldset/template.njk
|
3
|
+
module FieldsetHelper
|
4
|
+
def govukFieldset(kwargs = {}, &block)
|
5
|
+
kwargs[:block] = block
|
6
|
+
render "components/govuk_fieldset", **kwargs
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module GovukDesignSystem
|
2
|
+
module FileUploadHelper
|
3
|
+
# Use the [file upload component](https://design-system.service.gov.uk/components/file-upload/)
|
4
|
+
# to help users select and upload a file.
|
5
|
+
#
|
6
|
+
# Code based upon [nunjucks template](https://github.com/alphagov/govuk-frontend/blob/master/src/govuk/components/file-upload/template.njk)
|
7
|
+
def govukFileUpload(id:, name:, label:, value: nil, hint: nil, errorMessage: nil, formGroup: {}, classes: "", attributes: {}, described_by: nil)
|
8
|
+
form_group_classes = "govuk-form-group"
|
9
|
+
form_group_classes += " govuk-form-group--error" if errorMessage
|
10
|
+
form_group_classes += " #{formGroup[:classes]}" if formGroup[:classes]
|
11
|
+
|
12
|
+
# a record of other elements that we need to associate with the input using
|
13
|
+
# aria-describedby – for example hints or error messages
|
14
|
+
described_by ||= ""
|
15
|
+
|
16
|
+
content_tag("div", class: form_group_classes) do
|
17
|
+
concat govukLabel(html: label[:html], text: label[:text], classes: label[:classes], isPageHeading: label[:isPageHeading], attributes: (label[:attributes] || {}), for: id)
|
18
|
+
|
19
|
+
if hint
|
20
|
+
hint_id = "#{id}-hint"
|
21
|
+
described_by += " #{hint_id}"
|
22
|
+
|
23
|
+
concat govukHint(
|
24
|
+
id: hint_id,
|
25
|
+
classes: hint[:classes],
|
26
|
+
attributes: hint[:attributes],
|
27
|
+
html: hint[:html],
|
28
|
+
text: hint[:text]
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
if errorMessage
|
33
|
+
error_id = "#{id}-error"
|
34
|
+
described_by += " #{error_id}"
|
35
|
+
|
36
|
+
concat govukErrorMessage(
|
37
|
+
id: error_id,
|
38
|
+
classes: errorMessage[:classes],
|
39
|
+
attributes: errorMessage[:attributes],
|
40
|
+
html: errorMessage[:html],
|
41
|
+
text: errorMessage[:text],
|
42
|
+
visuallyHiddenText: errorMessage[:visuallyHiddenText]
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
attributes[:class] = "govuk-file-upload"
|
47
|
+
attributes[:class] += " govuk-file-upload--error" if errorMessage
|
48
|
+
attributes[:class] += " #{classes}" if classes
|
49
|
+
attributes[:id] = id
|
50
|
+
attributes[:name] = name
|
51
|
+
attributes[:type] = "file"
|
52
|
+
attributes[:value] = value if value
|
53
|
+
attributes["aria-describedby"] = described_by if described_by
|
54
|
+
|
55
|
+
concat content_tag("input", nil, attributes)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module GovukDesignSystem
|
2
|
+
# Based on https://github.com/alphagov/govuk-frontend/blob/main/src/govuk/components/inset-text/template.njk
|
3
|
+
module InsetTextHelper
|
4
|
+
def govukInsetText(kwargs = {}, &block)
|
5
|
+
kwargs[:block] = block
|
6
|
+
render "components/govuk_inset_text", **kwargs
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module GovukDesignSystem
|
2
|
+
module PhaseBannerHelper
|
3
|
+
# Generates the HTML for the
|
4
|
+
# [Phase banner component](https://design-system.service.gov.uk/components/phase-banner/)
|
5
|
+
# from the GOV.UK Design System.
|
6
|
+
#
|
7
|
+
# Use the phase banner component to show users your service is still being worked on.
|
8
|
+
#
|
9
|
+
# Implementation based on https://github.com/alphagov/govuk-frontend/blob/master/src/govuk/components/details/
|
10
|
+
def govukPhaseBanner(text: nil, html: nil, tag: nil, classes: "", attributes: {})
|
11
|
+
attributes["class"] = "govuk-phase-banner #{classes}"
|
12
|
+
|
13
|
+
content_tag("div", attributes) do
|
14
|
+
content_tag("p", { class: "govuk-phase-banner__content" }) do
|
15
|
+
concat govukTag(text: tag[:text], html: tag[:html], classes: "govuk-phase-banner__content__tag #{tag[:classes]}")
|
16
|
+
concat content_tag("span", (html || text), { class: "govuk-phase-banner__text" })
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module GovukDesignSystem
|
2
|
+
module SkipLinkHelper
|
3
|
+
# Based on https://github.com/alphagov/govuk-frontend/blob/master/src/govuk/components/skip-link/template.njk
|
4
|
+
def govukSkipLink(text: nil, html: nil, href: "#content", classes: "", attributes: {})
|
5
|
+
attributes["class"] = "govuk-skip-link #{classes}"
|
6
|
+
attributes["href"] = href
|
7
|
+
|
8
|
+
content_tag("a", attributes) do
|
9
|
+
html || text
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module GovukDesignSystem
|
2
|
+
module WarningTextHelper
|
3
|
+
# Use the [warning text component](https://design-system.service.gov.uk/components/warning-text/)
|
4
|
+
# when you need to warn users about something important, such as legal consequences of an action,
|
5
|
+
# or lack of action, that they might take.
|
6
|
+
#
|
7
|
+
# Implementation based on https://github.com/alphagov/govuk-frontend/tree/master/src/govuk/components/warning-text
|
8
|
+
def govukWarningText(iconFallbackText:, text: nil, html: nil, classes: "", attributes: {})
|
9
|
+
attributes[:class] = "govuk-warning-text #{classes}"
|
10
|
+
|
11
|
+
content_tag("div", attributes) do
|
12
|
+
content_tag("span", "!", class: "govuk-warning-text__icon", "aria-hidden" => "true") +
|
13
|
+
content_tag("strong", class: "govuk-warning-text__text") do
|
14
|
+
content_tag("span", iconFallbackText, class: "govuk-warning-text__assistive") +
|
15
|
+
(html || text)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<%
|
2
|
+
id = local_assigns[:id]
|
3
|
+
heading_level = local_assigns[:headingLevel].presence || 2
|
4
|
+
div_attributes = {
|
5
|
+
id: id,
|
6
|
+
class: class_names("govuk-accordion", local_assigns[:classes]),
|
7
|
+
data: { module: "govuk-accordion" },
|
8
|
+
"data-i18n" => {}
|
9
|
+
}
|
10
|
+
div_attributes["data-i18n"]["hide-all-sections"] = local_assigns[:hideAllSectionsText] if local_assigns[:hideAllSectionsText].present?
|
11
|
+
div_attributes["data-i18n"]["hide-section"] = local_assigns[:hideSectionText] if local_assigns[:hideSectionText].present?
|
12
|
+
div_attributes["data-i18n"]["hide-section-aria-label"] = local_assigns[:hideSectionAriaLabelText] if local_assigns[:hideSectionAriaLabelText].present?
|
13
|
+
div_attributes["data-i18n"]["show-all-sections"] = local_assigns[:showAllSectionsText] if local_assigns[:showAllSectionsText].present?
|
14
|
+
div_attributes["data-i18n"]["show-section"] = local_assigns[:showSectionText] if local_assigns[:showSectionText].present?
|
15
|
+
div_attributes["data-i18n"]["show-section-aria-label"] = local_assigns[:showSectionAriaLabelText] if local_assigns[:showSectionAriaLabelText].present?
|
16
|
+
div_attributes.merge!(local_assigns[:attributes]) if local_assigns[:attributes].present?
|
17
|
+
div_attributes.delete("data-i18n") if div_attributes["data-i18n"] == {}
|
18
|
+
%>
|
19
|
+
<%= tag.div(**div_attributes) do %>
|
20
|
+
<% local_assigns[:items].each.with_index(1) do |item, index| %>
|
21
|
+
<% next unless item.present? %>
|
22
|
+
<div class="<%= class_names "govuk-accordion__section", { "govuk-accordion__section--expanded" => item[:expanded] } %>">
|
23
|
+
<div class="govuk-accordion__section-header">
|
24
|
+
<h<%= heading_level %> class="govuk-accordion__section-heading">
|
25
|
+
<span class="govuk-accordion__section-button" id="<%= id %>-heading-<%= index %>">
|
26
|
+
<%= item.dig(:heading, :html).presence || item.dig(:heading, :text) %>
|
27
|
+
</span>
|
28
|
+
</h<%= heading_level %>>
|
29
|
+
<% if item.dig(:summary, :html).present? || item.dig(:summary, :text).present? %>
|
30
|
+
<div class="govuk-accordion__section-summary govuk-body" id="<%= id %>-summary-<%= index %>">
|
31
|
+
<%= item.dig(:summary, :html).presence || item.dig(:summary, :text) %>
|
32
|
+
</div>
|
33
|
+
<% end %>
|
34
|
+
</div>
|
35
|
+
<div id="<%= id %>-content-<%= index %>" class="govuk-accordion__section-content" aria-labelledby="<%= id %>-heading-<%= index %>">
|
36
|
+
<% if item.dig(:content, :html).present? %>
|
37
|
+
<%= item.dig(:content, :html) %>
|
38
|
+
<% elsif item.dig(:content, :text).present? %>
|
39
|
+
<p class="govuk-body"><%= item.dig(:content, :text) %></p>
|
40
|
+
<% end %>
|
41
|
+
</div>
|
42
|
+
</div>
|
43
|
+
<% end %>
|
44
|
+
<% end %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%
|
2
|
+
link_attributes = {
|
3
|
+
class: class_names("govuk-link", local_assigns[:classes]),
|
4
|
+
href: local_assigns[:href]
|
5
|
+
}.merge!(local_assigns[:attributes] || {})
|
6
|
+
%>
|
7
|
+
<%= tag.a **link_attributes do %>
|
8
|
+
<%= local_assigns[:html].presence || local_assigns[:text] %>
|
9
|
+
<% if local_assigns[:visuallyHiddenText].present? %>
|
10
|
+
<span class="govuk-visually-hidden"> <%= local_assigns[:visuallyHiddenText] %></span>
|
11
|
+
<% end %>
|
12
|
+
<% end %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<%
|
2
|
+
div_classes = class_names(
|
3
|
+
"govuk-breadcrumbs",
|
4
|
+
{ "govuk-breadcrumbs--collapse-on-mobile" => local_assigns[:collapseOnMobile] },
|
5
|
+
local_assigns[:classes]
|
6
|
+
)
|
7
|
+
div_attributes = {
|
8
|
+
class: div_classes,
|
9
|
+
}.merge!(local_assigns[:attributes].presence || {})
|
10
|
+
items = local_assigns[:items].presence || []
|
11
|
+
%>
|
12
|
+
<%= tag.div(**div_attributes) do %>
|
13
|
+
<ol class="govuk-breadcrumbs__list">
|
14
|
+
<% items.each do |item| %>
|
15
|
+
<% item_content = item[:html].presence || item[:text] %>
|
16
|
+
<% if item[:href].present? %>
|
17
|
+
<li class="govuk-breadcrumbs__list-item">
|
18
|
+
<%= link_to item_content, item[:href], class: "govuk-breadcrumbs__link", **(item[:attributes] || {}) %>
|
19
|
+
</li>
|
20
|
+
<% else %>
|
21
|
+
<li class="govuk-breadcrumbs__list-item" aria-current="page"><%= item_content %></li>
|
22
|
+
<% end %>
|
23
|
+
<% end %>
|
24
|
+
</ol>
|
25
|
+
<% end %>
|