Skip to content

Commit

Permalink
Merge pull request #296 from alphagov/add-department-colours-to-compo…
Browse files Browse the repository at this point in the history
…nents

Add department colours to components
  • Loading branch information
andysellick authored May 4, 2018
2 parents 0d0c244 + db727b8 commit 3dd8505
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unreleased

* Add department colours to components (PR #296)

# 7.1.0

* Add subscription links component (PR #290)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
@import "typography";
@import "colours";

@import "components/helpers/organisation-colours";

@import "components/back-link";
@import "components/button";
@import "components/document-list";
Expand Down
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;
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
items ||= []
margin_top_class = " gem-c-document-list--top-margin" if local_assigns[:margin_top]
margin_bottom_class = " gem-c-document-list--bottom-margin" if local_assigns[:margin_bottom]

brand ||= false
brand_helper = GovukPublishingComponents::Presenters::BrandHelper.new(brand)
%>
<% if items.any? %>
<ol class="gem-c-document-list<%= margin_bottom_class %><%= margin_top_class %>">
<ol class="gem-c-document-list<%= margin_bottom_class %><%= margin_top_class %> <%= brand_helper.get_brand %>">
<% items.each do |item| %>
<li class="gem-c-document-list__item">
<h3 class="gem-c-document-list__item-title">
<%=
link_to(
item[:link][:text],
item[:link][:path],
data: item[:link][:data_attributes]
data: item[:link][:data_attributes],
class: brand_helper.get_brand_element("color")
)
%>
</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,20 @@ examples:
text: 'Become an apprentice'
path: '/become-an-apprentice'
description: 'Becoming an apprentice - what to expect, apprenticeship levels, pay and training, making an application, complaining about an apprenticeship.'
with_branding:
description: Where this component could be used on an organisation page (such as the [Attorney General's Office](https://www.gov.uk/government/organisations/attorney-generals-office)) branding can be applied for link colours and border colours. See the [branding documentation](https://github.com/alphagov/govuk_publishing_components/blob/master/docs/component_branding.md) for more details.
data:
brand: 'attorney-generals-office'
items:
- link:
text: 'School behaviour and attendance: parental responsibility measures'
path: '/government/publications/parental-responsibility-measures-for-behaviour-and-attendance'
metadata:
public_updated_at: 2017-01-05 14:50:33
document_type: 'Statutory guidance'
- link:
text: 'School exclusion'
path: '/government/publications/school-exclusion'
metadata:
public_updated_at: 2017-07-19 15:01:48
document_type: 'Statutory guidance'
47 changes: 47 additions & 0 deletions docs/component_branding.md
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'
} %>
```
1 change: 1 addition & 0 deletions lib/govuk_publishing_components.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "govuk_publishing_components/config"
require "govuk_publishing_components/engine"
require "govuk_publishing_components/presenters/brand_helper"
require "govuk_publishing_components/presenters/contextual_navigation"
require "govuk_publishing_components/presenters/related_navigation_helper"
require "govuk_publishing_components/presenters/step_by_step_nav_helper"
Expand Down
17 changes: 17 additions & 0 deletions lib/govuk_publishing_components/presenters/brand_helper.rb
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

0 comments on commit 3dd8505

Please sign in to comment.