Skip to content
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 2 commits into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 %>">
Copy link
Contributor

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 the brand passed in. Perhaps brand_class would reveal the intention more?

Copy link
Contributor Author

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

<div class="gem-c-component__title <%= brand_helper.get_brand_element("border-color") %>">
Copy link
Contributor

@tijmenb tijmenb May 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth it creating separate method for this and color to avoid typos.

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'
} %>
```
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