diff --git a/app/assets/stylesheets/components/_back-link.scss b/app/assets/stylesheets/components/_back-link.scss new file mode 100644 index 0000000000..9a54f967ab --- /dev/null +++ b/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; + } +} diff --git a/app/views/components/_back_link.html.erb b/app/views/components/_back_link.html.erb new file mode 100644 index 0000000000..965f377c80 --- /dev/null +++ b/app/views/components/_back_link.html.erb @@ -0,0 +1,6 @@ + + <%= t('components.back_link.back') %> + diff --git a/app/views/components/docs/back_link.yml b/app/views/components/docs/back_link.yml new file mode 100644 index 0000000000..84d9c00be1 --- /dev/null +++ b/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: '#' diff --git a/config/locales/cy.yml b/config/locales/cy.yml index 3809978bfa..656934650d 100644 --- a/config/locales/cy.yml +++ b/config/locales/cy.yml @@ -2,3 +2,5 @@ cy: components: radio: or: 'neu' + back_link: + back: "Yn ôl" diff --git a/config/locales/en.yml b/config/locales/en.yml index b63b08415b..240748327e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -23,3 +23,5 @@ en: components: radio: or: 'or' + back_link: + back: 'Back' diff --git a/spec/components/back_link_spec.rb b/spec/components/back_link_spec.rb new file mode 100644 index 0000000000..1b37fa33ef --- /dev/null +++ b/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