Skip to content

Commit

Permalink
Add Back Link component
Browse files Browse the repository at this point in the history
Moved from government-frontend for use in email-alert-frontend

Also renames the namespace to `gem`

Originally implemented in alphagov/government-frontend#568
  • Loading branch information
tuzz committed Jan 5, 2018
1 parent 155cd85 commit ec8fac1
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 0 deletions.
33 changes: 33 additions & 0 deletions app/assets/stylesheets/components/_back-link.scss
@@ -0,0 +1,33 @@
@import "helpers/variables";

.gem-c-back-link {
position: relative;
display: inline-block;
margin-top: $gem-spacing-scale-3;
margin-bottom: $gem-spacing-scale-3;
font-size: 16px;
line-height: 1.25;

text-decoration: none;
border-bottom: 1px solid currentColor;

&:link,
&:link:focus,
&:visited,
&:active {
color: currentColor;
}

&:hover {
color: $link-colour;
}

&::before {
content: "";
display: inline-block;
margin-right: .3em;
border-top: 0.3125em solid transparent;
border-right: 0.375em solid currentColor;
border-bottom: 0.3125em solid transparent;
}
}
Expand Up @@ -4,6 +4,7 @@
@import "typography";
@import "colours";

@import "../components/back-link";
@import "../components/fieldset";
@import "../components/label";
@import "../components/radio";
Expand Down
6 changes: 6 additions & 0 deletions app/views/components/_back_link.html.erb
@@ -0,0 +1,6 @@
<a
class="gem-c-back-link"
href="<%= href %>"
>
<%= t('components.back_link.back') %>
</a>
10 changes: 10 additions & 0 deletions app/views/components/docs/back_link.yml
@@ -0,0 +1,10 @@
name: Back link
description: A link used to help users get back, useful when not using other navigation such as breadcrumbs
accessibility_criteria: |
- has a touch area easy for users to touch
shared_accessibility_criteria:
- link
examples:
default:
data:
href: '#'
2 changes: 2 additions & 0 deletions config/locales/cy.yml
Expand Up @@ -2,3 +2,5 @@ cy:
components:
radio:
or: 'neu'
back_link:
back: "Yn ôl"
2 changes: 2 additions & 0 deletions config/locales/en.yml
Expand Up @@ -23,3 +23,5 @@ en:
components:
radio:
or: 'or'
back_link:
back: 'Back'
23 changes: 23 additions & 0 deletions spec/components/back_link_spec.rb
@@ -0,0 +1,23 @@
require 'rails_helper'

describe "Back Link", type: :view do
def render_component(locals)
render file: "components/_back_link", locals: locals
end

it "fails to render a back link when no href is given" do
assert_raises do
render_component({})
end
end

it "renders a back link correctly" do
render_component(href: '/back-me')
assert_select ".gem-c-back-link[href=\"/back-me\"]", text: "Back"
end

it "can render in welsh" do
I18n.with_locale(:cy) { render_component(href: '/back-me') }
assert_select ".gem-c-back-link[href=\"/back-me\"]", text: "Yn ôl"
end
end

0 comments on commit ec8fac1

Please sign in to comment.