Skip to content

Commit

Permalink
Merge pull request #290 from alphagov/add-subscription-links-component
Browse files Browse the repository at this point in the history
Add subscription links component
  • Loading branch information
andysellick committed May 1, 2018
2 parents c852ab1 + 639a0d9 commit 90adcda
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
# Unreleased

* Add subscription links component (PR #290)

# 7.0.0

* Add an optional meta tag to signal dates should be stripped from
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -21,6 +21,7 @@
@import "components/step-by-step-nav";
@import "components/step-by-step-nav-header";
@import "components/step-by-step-nav-related";
@import "components/subscription-links";
@import "components/feedback";
@import "components/inverse-header";
@import "components/success-alert";
Expand Down
@@ -0,0 +1,40 @@
.gem-c-subscription-links {
@include bold-19;

.gem-c-subscription-links__list {
list-style: none;
margin-left: -$gutter-half / 2;
margin-right: -$gutter-half / 2;
}

.gem-c-subscription-links__list-item {
display: inline-block;
margin-left: $gutter-half / 2;
margin-right: $gutter-half / 2;
margin-bottom: $gutter-half;
}

.gem-c-subscription-links__link {
text-decoration: none;
padding-left: 28px;
background-repeat: no-repeat;
background-position: 0 20%;

@include media(tablet) {
background-position: 0 35%;
}
}

.gem-c-subscription-links__link--feed {
background-image: image-url("govuk_publishing_components/feed-icon-black.png");
}

.gem-c-subscription-links__link--email-alerts {
background-image: image-url("govuk_publishing_components/mail-icon.png");

@include device-pixel-ratio() {
background-image: image-url("govuk_publishing_components/mail-icon-x2.png");
background-size: 20px 14px;
}
}
}
@@ -0,0 +1,21 @@
<%
email_signup_link ||= false
feed_link ||= false
%>
<% if email_signup_link || feed_link %>
<section class="gem-c-subscription-links">
<h2 class="visuallyhidden">Subscriptions</h2>
<ul class="gem-c-subscription-links__list">
<% if email_signup_link.present? %>
<li class="gem-c-subscription-links__list-item">
<%= link_to "Get email alerts", email_signup_link, class: "gem-c-subscription-links__link gem-c-subscription-links__link--email-alerts" %>
</li>
<% end %>
<% if feed_link.present? %>
<li class="gem-c-subscription-links__list-item">
<%= link_to "Subscribe to feed", feed_link, class: "gem-c-subscription-links__link gem-c-subscription-links__link--feed" %>
</li>
<% end %>
</ul>
</section>
<% end %>
@@ -0,0 +1,17 @@
name: Subscription links
description: Links to ‘Get email alerts’ and ‘Subscribe to feed’
accessibility_criteria: |
Icons in subscription links must be presentational and ignored by screen readers.
shared_accessibility_criteria:
- link
examples:
default:
data:
email_signup_link: '/foreign-travel-advice/singapore/email-signup'
feed_link: '/foreign-travel-advice/singapore.atom'
with_only_email_signup_link:
data:
email_signup_link: '/foreign-travel-advice/singapore/email-signup'
with_only_feed_link:
data:
feed_link: '/foreign-travel-advice/singapore.atom'
5 changes: 4 additions & 1 deletion config/initializers/assets.rb
@@ -1,6 +1,9 @@
Rails.application.config.assets.precompile += %w(
govuk_publishing_components/component_guide.css
component_guide/all_components.css
component_guide/all_components_print
component_guide/all_components_print.css
govuk_publishing_components/search-button.png
govuk_publishing_components/feed-icon-black.png
govuk_publishing_components/mail-icon-x2.png
govuk_publishing_components/mail-icon.png
)
27 changes: 27 additions & 0 deletions spec/components/subscription_links_spec.rb
@@ -0,0 +1,27 @@
require 'rails_helper'

describe "subscription links", type: :view do
def component_name
"subscription-links"
end

it "renders nothing when no parameters are given" do
assert_empty render_component({})
end

it "renders an email signup link" do
render_component(email_signup_link: '/email-signup')
assert_select ".gem-c-subscription-links__link--email-alerts[href=\"/email-signup\"]", text: "Get email alerts"
end

it "renders a feed link" do
render_component(feed_link: 'singapore.atom')
assert_select ".gem-c-subscription-links__link--feed[href=\"singapore.atom\"]", text: "Subscribe to feed"
end

it "renders both email signup and feed links" do
render_component(email_signup_link: 'email-signup', feed_link: 'singapore.atom')
assert_select ".gem-c-subscription-links__link--email-alerts[href=\"email-signup\"]", text: "Get email alerts"
assert_select ".gem-c-subscription-links__link--feed[href=\"singapore.atom\"]", text: "Subscribe to feed"
end
end

0 comments on commit 90adcda

Please sign in to comment.