-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #296 from alphagov/add-department-colours-to-compo…
…nents Add department colours to components
- Loading branch information
Showing
8 changed files
with
114 additions
and
2 deletions.
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") %>"> | ||
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 |