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

Update title component to meet chosen conventions #1117

Merged
merged 2 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions app/assets/stylesheets/govuk-component/_title-print.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.govuk-title {
.context {
margin: 0;
}
// scss-lint:disable SelectorFormat
.pub-c-title__context {
margin: 0;
}

h1 {
margin-top: 0;
}
.pub-c-title__text {
margin-top: 0;
}
// scss-lint:enable SelectorFormat
24 changes: 13 additions & 11 deletions app/assets/stylesheets/govuk-component/_title.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
.govuk-title {
// scss-lint:disable SelectorFormat
.pub-c-title {
@include responsive-vertical-margins;
}

.context {
@include core-24;
color: $secondary-text-colour;
}
.pub-c-title__context {
@include core-24;
color: $secondary-text-colour;
}

h1 {
@include bold-48;
}
.pub-c-title__text {
@include bold-48;
}

&.length-long h1 {
@include bold-36;
}
.pub-c-title__text--long {
@include bold-36;
}
// scss-lint:enable SelectorFormat
6 changes: 6 additions & 0 deletions app/views/govuk_component/docs/title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ body: |

On average the titles on government bits of content are 50 characters. The
average for bits of general guidance are nearer 27 characters long.
accessibility_criteria:
The page title must:

- be part of a correct heading structure for a page
- be semantically represented as a heading
- convey the heading level
fixtures:
default:
title: My page title
Expand Down
10 changes: 6 additions & 4 deletions app/views/govuk_component/title.raw.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<%
average_title_length ||= :average
average_title_length ||= false
context ||= false
%>
<div class="govuk-title length-<%= average_title_length %>">
<div class="pub-c-title">
<% if context %>
<p class="context"><%= context %></p>
<p class="pub-c-title__context"><%= context %></p>
<% end %>
<h1><%= title %></h1>
<h1 class="pub-c-title__text <% if average_title_length %>pub-c-title__text--<%= average_title_length %><% end %>">
<%= title %>
</h1>
</div>
9 changes: 7 additions & 2 deletions test/govuk_component/title_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ def component_name

test "title text appears" do
render_component(title: "Hello World")
assert_select ".govuk-title", text: "Hello World"
assert_select ".pub-c-title__text", text: "Hello World"
end

test "title context appears" do
render_component(title: "Hello World", context: "Format")
assert_select ".govuk-title .context", text: "Format"
assert_select ".pub-c-title__context", text: "Format"
end

test "applies title length if supplied" do
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Nice

render_component(title: "Hello World", context: "format", average_title_length: 'long')
assert_select ".pub-c-title .pub-c-title__text--long", text: "Hello World"
end
end