-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite the cookie banner with slots
This now works in a very similar fashion to the Nunjucks macros. Instead of passing in actions with arguments it supports the passing in of any arbitrary HTML, the intention is for developers to pass in an array of buttons or links generated by `govuk_link_to` or similar. These will then automatically be wrapped in a `govuk-button-group`.
- Loading branch information
1 parent
be928a5
commit 682eaae
Showing
4 changed files
with
186 additions
and
69 deletions.
There are no files selected for viewing
17 changes: 0 additions & 17 deletions
17
app/components/govuk_component/cookie_banner_component.html.erb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
app/components/govuk_component/cookie_banner_component/message_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class GovukComponent::CookieBannerComponent::MessageComponent < GovukComponent::Base | ||
attr_reader :heading_text, :text, :hidden, :role | ||
|
||
renders_many :actions | ||
renders_one :heading_html | ||
|
||
def initialize(heading_text: nil, text: nil, hidden: false, role: nil, classes: [], html_attributes: {}) | ||
super(classes: classes, html_attributes: html_attributes) | ||
|
||
@heading_text = heading_text | ||
@text = text | ||
@hidden = hidden | ||
@role = role | ||
end | ||
|
||
def call | ||
tag.div(class: classes, role: role, hidden: hidden, **html_attributes) do | ||
tag.div(class: "govuk-grid-row") do | ||
tag.div(class: "govuk-grid-column-two-thirds") do | ||
safe_join([heading_element, message_element, actions_element]) | ||
end | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def default_classes | ||
%w(govuk-cookie-banner__message govuk-width-container) | ||
end | ||
|
||
def heading_element | ||
tag.h2(heading_content, class: "govuk-cookie-banner__heading") | ||
end | ||
|
||
def heading_content | ||
heading_html || heading_text || fail(ArgumentError, "no heading_text or heading_html") | ||
end | ||
|
||
def message_element | ||
tag.div(message_content, class: "govuk-cookie-banner__content") | ||
end | ||
|
||
def message_content | ||
content || text || fail(ArgumentError, "no text or content") | ||
end | ||
|
||
def actions_element | ||
return if actions.none? | ||
|
||
tag.div(class: "govuk-button-group") { safe_join(actions) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters