-
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
RFC 1: Add government department colours to components #287
Closed
Closed
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# Add government department brand colours to gem for use by components | ||
|
||
## Problem and background | ||
|
||
Organisation pages ([example](https://www.gov.uk/government/organisations/attorney-generals-office)) have their own brand, which includes specific colours applied to links and borders. These colours are pulled in from [govuk_frontend_toolkit](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/stylesheets/colours/_organisation.scss) using a [mixin](https://github.com/alphagov/whitehall/blob/master/app/assets/stylesheets/frontend/views/_organisations.scss#L855-L858) to generate a range of classes. | ||
|
||
Most organisations have one colour for borders and one for links, even if they are broadly the same colour. These are applied to the existing structure of the frontend of whitehall. | ||
|
||
The structure of the new organisation pages (to be built in collections) uses components, which are individual and isolated. To reproduce this approach in the same way would mean adding all of the CSS for all of the colour options to all of the components, dramatically increasing the size of the CSS involved and introducing much duplication. | ||
|
||
## Proposed solution | ||
|
||
### In the gem | ||
|
||
All colour classes are included in a helper Sass file in the gem. | ||
|
||
Sass in the gem looks like this: | ||
|
||
``` | ||
@import "colours/organisation"; | ||
|
||
@mixin organisation-brand-colour($selector, $property, $websafe: false) { | ||
@each $organisation in $all-organisation-brand-colours { | ||
.color-#{$selector}--#{nth($organisation, 1)} .color-#{$selector} { | ||
@if $websafe { | ||
#{$property}: nth($organisation, 3); | ||
} | ||
@else { | ||
#{$property}: nth($organisation, 2); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@include organisation-brand-colour("link", color, true); | ||
@include organisation-brand-colour("border", border-color); | ||
``` | ||
|
||
This is included in the `_all_components.scss` file. | ||
|
||
CSS in the gem looks like this: | ||
|
||
``` | ||
.color-link--department-for-work-and-pensions .color-link { | ||
border-color: #8f1111; | ||
} | ||
|
||
.color-border--department-for-work-and-pensions .color-border { | ||
border-color: #9f1888; | ||
} | ||
``` | ||
|
||
etc. | ||
|
||
### In the component | ||
|
||
Pass component parameters for link_colour and border_color as required, as strings that match the pre-defined list e.g. 'department-for-work-and-pensions'. | ||
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. Do we need to be specific about the intention of the passed in variables? So instead of: <%= render 'govuk_publishing_components/components/title', link_colour: 'department-for-education', border_color: 'department-for-education' %> Do this: <%= render 'govuk_publishing_components/components/title', brand: 'department-for-education' %> 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. Yeah, that's simpler. |
||
|
||
Component takes the link parameter and adds a class e.g. 'color-link--department-for-work-and-pensions' to the component and 'color-link' to the relevant elements. | ||
|
||
Component looks like this: | ||
|
||
``` | ||
<div class="app-c-component color-link--department-for-work-and-pensions"> | ||
<a href="#" class="color-link"> | ||
a link | ||
</a> | ||
</div> | ||
``` | ||
|
||
Component takes border colour and adds the class e.g. 'color-border--department-for-joy' to the component and 'color-border' to the relevant elements. | ||
|
||
Component looks like this: | ||
|
||
``` | ||
<div class="app-c-component color-border--department-for-joy"> | ||
<span class="app-c-component__title color-border"> | ||
an element | ||
</span> | ||
</div> | ||
``` | ||
|
||
Sass in the component looks like this: | ||
|
||
``` | ||
.app-c-component__title { | ||
border-style: none none none solid; | ||
border-width: 2px; | ||
} | ||
``` | ||
|
||
The border-color attribute is set in the gem. This way the component retains control over the border position and size and the generic classes can be as non-specific as possible. | ||
|
||
## Other approaches considered | ||
|
||
Pass through the hex code of the desired colour and it gets inserted as an inline style attribute | ||
|
||
- no absolutely not. | ||
- also we don't have the hex code in the content item, would require more work to add it and would mix styles and backend, undesirable | ||
|
||
Pass through the name of the colour and the component will add the style that matches | ||
|
||
- would add approx 2KB of CSS to every component where we need this (there are nearly 60 colours) | ||
|
||
Generate needed styles inline as a style tag within the template | ||
|
||
- given the parameter 'department-for-education' generate a style tag in the template like `app-c-component--<%= link_colour %> { color: <%= get_colour(link_colour) %>}` | ||
- we don't do inline styles | ||
- would need a helper method that already contained all the hex codes associated with their department names, again mixing styles and backend, which is undesirable | ||
|
||
## Decisions explained | ||
|
||
- originally wanted a flatter class structure e.g. `.color-link--department-for-agriculture { }` but this is overridden by the default styles for :visited etc. so either we have to write all those out explicitly or add an extra class (the extra class seemed a shorter way of doing it and allows more flexibility in future e.g. if a component suddenly required one link that wasn't that colour, you could just omit the class on that link) | ||
- want to avoid any generic rules like `.color--no-10 a {}` as this could cause problems for developers later | ||
- writing general classes for colour like this avoids having to write component specific classes, even though this goes against the component principle of them being isolated (although most components rely on some external CSS already, e.g. reset) | ||
|
||
## Assumptions made (may not be true) | ||
|
||
- specific class for border or link can be applied to all elements, this may not be the case if the component is simply passed a block of HTML, in which case we might have to go back and modify this approach to the undesirable `.color-no-10 a {}` approach | ||
|
||
## Likely problems | ||
|
||
- can we have any components using this that aren't in the gem? Due to the tight coupling it seems like they should be in the same place as the colours CSS but that would mean promoting more components to the gem, more work, less time | ||
|
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.
Could consider
theme
orbrand
, for the namespace, to be consistent with @tijmenb 's suggestion.