Skip to content

Commit

Permalink
Add inverse option to metadata component
Browse files Browse the repository at this point in the history
- changes all text and links to white, for use on dark backgrounds
  • Loading branch information
andysellick committed Nov 22, 2018
1 parent b10e641 commit f4de2c2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,32 @@
@include core-16;
@include responsive-bottom-margin;
@extend %contain-floats;

a {
@include govuk-link-common;
@include govuk-link-style-default;
}
}

.gem-c-metadata.direction-rtl {
direction: rtl;
text-align: start;
}

.gem-c-metadata--inverse {
color: govuk-colour('white');

a:link,
a:active,
a:visited {
color: govuk-colour('white');
}

a:focus {
color: govuk-colour('black');
}
}

.gem-c-metadata__term {
margin-top: 0.5em;
line-height: normal;
Expand Down Expand Up @@ -43,14 +62,9 @@
float: left;
width: 70%;
}

a {
@extend %govuk-link;
}
}

.gem-c-metadata__definition-link {
@extend %govuk-link;
text-decoration: none;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
part_of = Array(part_of)

other ||= nil
inverse ||= false

direction_class = ""
direction_class = " direction-#{direction}" if local_assigns.include?(:direction)

classes = %w(gem-c-metadata)
classes << "direction-#{direction}" if local_assigns.include?(:direction)
classes << "gem-c-metadata--inverse" if inverse
%>
<div class="gem-c-metadata<%= direction_class %>" data-module="gem-toggle">
<%= content_tag :div, class: classes, data: { module: "gem-toggle" } do %>
<dl data-module="track-click">
<% if from.any? %>
<dt class="gem-c-metadata__term"><%= t("govuk_component.metadata.from", default: "From") %>:</dt>
Expand Down Expand Up @@ -60,4 +65,4 @@
<% end %>
<% end %>
</dl>
</div>
<% end %>
20 changes: 20 additions & 0 deletions app/views/govuk_publishing_components/components/docs/metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,23 @@ examples:
first_published: 14 June 2014
other:
Applies to: England, Scotland, and Wales (see detailed guidance for <a href="http://www.dardni.gov.uk/news-dard-pa022-a-13-new-procedure-for" rel="external">Northern Ireland</a>)
on_a_dark_background:
data:
inverse: true
from: [
"<a href='/government/organisations/ministry-of-defence'>Ministry of Defence</a>",
"<a href='/government/organisations/cabinet-office'>Cabinet Office</a>",
"<a href=\"/government/organisations/department-for-business-energy-and-industrial-strategy\">Department for Business, Energy &amp; Industrial Strategy</a>",
"<a href=\"/government/organisations/foreign-commonwealth-office\">Foreign &amp; Commonwealth Office</a>",
"<a href=\"/government/people/william-hague\">The Rt Hon William Hague</a>",
"<a href=\"/government/organisations/department-for-environment-food-rural-affairs\">Department for Environment, Food &amp; Rural Affairs</a>",
"<a href=\"/government/organisations/department-for-work-pensions\">Department for work and pensions</a>",
"<a href=\"/government/organisations/foreign-commonwealth-office\">Foreign and Commonwealth Office</a>"
]
first_published: 14 June 2014
last_updated: 10 September 2015
see_updates_link: true
other:
Applies to: England, Scotland, and Wales (see detailed guidance for <a href="http://www.dardni.gov.uk/news-dard-pa022-a-13-new-procedure-for" rel="external">Northern Ireland</a>)
context:
dark_background: true
6 changes: 6 additions & 0 deletions spec/components/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ def component_name
assert_no_truncation(links.length)
end

it "renders the component on a dark background" do
render_component(from: "<a href='/link'>Department</a>", inverse: true)

assert_select ".gem-c-metadata.gem-c-metadata--inverse"
end

def assert_truncation(length, limit)
assert_select "span", count: 1
assert_select "dd > a", count: limit
Expand Down

0 comments on commit f4de2c2

Please sign in to comment.