-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add department colours to components #296
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
20 changes: 20 additions & 0 deletions
20
...ets/stylesheets/govuk_publishing_components/components/helpers/_organisation-colours.scss
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,20 @@ | ||
@import "colours/organisation"; | ||
|
||
// this uses the colours from govuk_frontend_toolkit | ||
// https://github.com/alphagov/govuk_frontend_toolkit/blob/master/stylesheets/colours/_organisation.scss | ||
|
||
@mixin organisation-brand-colour() { | ||
@each $organisation in $all-organisation-brand-colours { | ||
.brand--#{nth($organisation, 1)} { | ||
.brand__color { | ||
color: nth($organisation, 3); | ||
} | ||
|
||
.brand__border-color { | ||
border-color: nth($organisation, 2); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@include organisation-brand-colour; |
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
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
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,47 @@ | ||
# Component branding | ||
|
||
## Overview | ||
|
||
Organisation pages in whitehall ([example](https://www.gov.uk/government/organisations/attorney-generals-office)) have department-specific branding on them. This includes specific colours for links and borders. These pages are being migrated out of whitehall and will use components for their frontend, which means some components need a sensible way of displaying these colours. | ||
|
||
This work follows [this RFC](https://github.com/alphagov/govuk_publishing_components/pull/287) to discuss the approach taken. | ||
|
||
## Adding to a component | ||
|
||
To add colours to a component, modify the component to follow the example below. | ||
|
||
``` | ||
<% | ||
brand ||= false | ||
brand_helper = GovukPublishingComponents::Presenters::BrandHelper.new(brand) | ||
%> | ||
|
||
<div class="gem-c-component <%= brand_helper.get_brand %>"> | ||
<div class="gem-c-component__title <%= brand_helper.get_brand_element("border-color") %>"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's worth it creating separate method for this and Perhaps something like: - <%= brand_helper.get_brand_element("border-color") %>">
+ <%= brand_helper.border_color_class %> - <%= brand_helper.get_brand_element("color") %>">
+ <%= brand_helper.color_class %> |
||
Example element that requires a coloured border | ||
</div> | ||
|
||
<a href="#" class="<%= brand_helper.get_brand_element("color") %>"> | ||
Example element that requires coloured text | ||
</a> | ||
</div> | ||
``` | ||
|
||
Note that the helper must be called for each element that needs a border or link colour applying. This allows for flexibility if one is required but not the other. | ||
|
||
For borders, the applied class only adds a `border-color` attribute. You will need to add the rest of the border style attributes to the component itself, for example: | ||
|
||
``` | ||
.gem-c-component__title { | ||
border-style: solid; | ||
border-width: 5px; | ||
} | ||
``` | ||
|
||
The component can then be passed a string matching the required brand, for example: | ||
|
||
``` | ||
<%= render "govuk_publishing_components/components/example-component", { | ||
brand: 'attorney-generals-office' | ||
} %> | ||
``` |
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
17 changes: 17 additions & 0 deletions
17
lib/govuk_publishing_components/presenters/brand_helper.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,17 @@ | ||
module GovukPublishingComponents | ||
module Presenters | ||
class BrandHelper | ||
def initialize(brand) | ||
@brand = brand if brand | ||
end | ||
|
||
def get_brand | ||
"brand--#{@brand}" if @brand | ||
end | ||
|
||
def get_brand_element(attribute) | ||
"brand__#{attribute}" if @brand | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We mostly avoid prefixing getters with
get_
(I'm not sure why Rubocop hasn't picked that up, I'll investigate).To me
get_brand
also implies that it'll return thebrand
passed in. Perhapsbrand_class
would reveal the intention more?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestions, thanks. See this PR -> #300