Skip to content
This repository has been archived by the owner on Aug 13, 2023. It is now read-only.

Add Link to Story Promo #513

Merged
merged 19 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from 18 commits
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
1 change: 1 addition & 0 deletions packages/components/psammead-story-promo/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- prettier-ignore -->
| Version | Description |
| ------- | ----------- |
| 0.2.0-alpha.1 | [PR#513](https://github.com/bbc/psammead/pull/513) Add Link with hover, focus and visited states |
| 0.1.4 | [PR#489](https://github.com/BBC-News/psammead/pull/489) Add grid fallback. |
| 0.1.3 | [PR#498](https://github.com/bbc/psammead/pull/498) Update stories to use new input provider |
| 0.1.2 | [PR#488](https://github.com/BBC-News/psammead/pull/488) Hide story summary on device width lower than 600px. |
Expand Down
16 changes: 13 additions & 3 deletions packages/components/psammead-story-promo/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ⛔️ This is an alpha component ⛔️

This component is currently tagged as alpha and is not suitable for production use. Following the passing of an accessibility review this component will be marked as ready for production and the alpha tag removed.

# psammead-story-promo - [![Known Vulnerabilities](https://snyk.io/test/github/bbc/psammead/badge.svg?targetFile=packages%2Fcomponents%2Fpsammead-story-promo%2Fpackage.json)](https://snyk.io/test/github/bbc/psammead?targetFile=packages%2Fcomponents%2Fpsammead-story-promo%2Fpackage.json) [![Storybook](https://raw.githubusercontent.com/storybooks/story-promo/master/badge/badge-storybook.svg?sanitize=true)](https://bbc.github.io/psammead/?path=/story/story-promo--default) [![GitHub license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/bbc/psammead/blob/latest/LICENSE) [![npm version](https://img.shields.io/npm/v/@bbc/psammead-story-promo.svg)](https://www.npmjs.com/package/@bbc/psammead-story-promo) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/bbc/psammead/blob/latest/CONTRIBUTING.md)

## Description
Expand Down Expand Up @@ -33,7 +37,7 @@ The typical use-case of this component is as displayed below. A Image sits on th

```jsx
import React, { Fragment } from 'react';
import StoryPromo, { Headline, Summary } from '@bbc/psammead-story-promo';
import StoryPromo, { Headline, Summary, Link } from '@bbc/psammead-story-promo';
import { latin } from '@bbc/gel-foundations/scripts';

const Image = (
Expand All @@ -42,7 +46,9 @@ const Image = (

const Info = (
<Fragment>
<Headline script={latin}>The headline of the promo</Headline>
<Headline script={latin}>
<Link href="https://www.bbc.co.uk/news">The headline of the promo</Link>
</Headline>
<Summary script={latin}>The summary of the promo</Summary>
<time>12 March 2019</time>
</Fragment>
Expand All @@ -62,7 +68,11 @@ The `StoryPromo` component is designed to be used within a link element to allow

### Accessibility notes

This component uses full semantic markup for the `Headline` and `Summary`, using `h3` and `p` respectively. Other accessibility factors such as image alt text and time elements are passed in as props and aren't explicitly set in this component.
This component uses full semantic markup for the `Headline`, `Summary`, and `Link`, using `h3`, `p` and `a` respectively. Other accessibility factors such as image alt text and time elements are passed in as props and aren't explicitly set in this component.

The link is nested inside the `h3` for better support with VoiceOver Mac and Safari. We use the `faux block link` pattern which makes the entire block clickable, whilst also enabling links nested within in that block to also be clickable.

We haven't yet thoroughly looked at cross device browser AT testing yet, this is in-progress. We will update with a11y notes when carrying out a proper release.

## Roadmap

Expand Down
2 changes: 1 addition & 1 deletion packages/components/psammead-story-promo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/components/psammead-story-promo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bbc/psammead-story-promo",
"version": "0.1.4",
"version": "0.2.0-alpha.1",
"main": "dist/index.js",
"description": "A story promo for use on index pages",
"repository": {
Expand Down Expand Up @@ -37,5 +37,8 @@
"bbc",
"story",
"promo"
]
],
"publishConfig": {
"tag": "alpha"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`StoryPromo should render correctly 1`] = `
.c0 {
position: relative;
}

.c1 {
display: inline-block;
vertical-align: top;
Expand All @@ -24,7 +28,7 @@ exports[`StoryPromo should render correctly 1`] = `
font-weight: 700;
}

.c4 {
.c5 {
font-size: 0.9375rem;
line-height: 1.125rem;
color: #3F3F42;
Expand All @@ -33,6 +37,31 @@ exports[`StoryPromo should render correctly 1`] = `
padding-bottom: 0.5rem;
}

.c4 {
position: static;
color: #3F3F42;
-webkit-text-decoration: none;
text-decoration: none;
}

.c4:before {
bottom: 0;
content: '';
left: 0;
overflow: hidden;
position: absolute;
right: 0;
top: 0;
white-space: nowrap;
z-index: 1;
}

.c4:hover,
.c4:focus {
-webkit-text-decoration: underline;
text-decoration: underline;
}

@supports (display:grid) {
.c0 {
display: grid;
Expand Down Expand Up @@ -91,21 +120,21 @@ exports[`StoryPromo should render correctly 1`] = `
}

@media (min-width:20rem) and (max-width:37.4375rem) {
.c4 {
.c5 {
font-size: 0.9375rem;
line-height: 1.125rem;
}
}

@media (min-width:37.5rem) {
.c4 {
.c5 {
font-size: 0.875rem;
line-height: 1.125rem;
}
}

@media (max-width:37.4375rem) {
.c4 {
.c5 {
display: none;
}
}
Expand All @@ -127,10 +156,15 @@ exports[`StoryPromo should render correctly 1`] = `
<h3
className="c3"
>
The headline of the promo
<a
className="c4"
href="https://www.bbc.co.uk/news"
>
The headline of the promo
</a>
</h3>
<p
className="c4"
className="c5"
>
The summary of the promo
</p>
Expand Down
31 changes: 30 additions & 1 deletion packages/components/psammead-story-promo/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
GEL_FF_REITH_SERIF,
GEL_FF_REITH_SANS,
} from '@bbc/gel-foundations/typography';
import { C_SHADOW } from '@bbc/psammead-styles/colours';
import { C_SHADOW, C_METAL } from '@bbc/psammead-styles/colours';

const twoOfSixColumnsMaxWidthScaleable = `33.33%`;
// (2 / 6) * 100 = 0.3333333333 = 33.33%
Expand All @@ -33,6 +33,8 @@ const eightOfTwelveColumnsMaxScaleable = `66.67%`;
// (8 / 12) * 100 = 66.6666666667 = 66.67%

const StoryPromoWrapper = styled.div`
position: relative;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason this is needed for?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahhh is it part of faux block link?

Copy link
Contributor Author

@DenisHdz DenisHdz May 17, 2019

Choose a reason for hiding this comment

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

That is used to make the faux block link pattern work. If you don't apply it the clickable area is everything and not just the StoryPromoWrapper.


@supports (display: grid) {
display: grid;
grid-template-columns: repeat(6, 1fr);
Expand Down Expand Up @@ -114,6 +116,33 @@ export const Summary = styled.p`
}
`;

export const Link = styled.a`
position: static;
color: ${C_SHADOW};
text-decoration: none;

&:before {
bottom: 0;
content: '';
left: 0;
overflow: hidden;
position: absolute;
right: 0;
top: 0;
white-space: nowrap;
z-index: 1;
}

&:hover,
&:focus {
text-decoration: underline;
DenisHdz marked this conversation as resolved.
Show resolved Hide resolved
}

&:visited {
color: ${C_METAL};
}
`;

const StoryPromo = ({ image, info }) => (
<StoryPromoWrapper>
<ImageGridItem>{image}</ImageGridItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { inputProvider } from '@bbc/psammead-storybook-helpers';
import Image from '@bbc/psammead-image';
import Timestamp from '@bbc/psammead-timestamp';
import notes from '../README.md';
import StoryPromo, { Headline, Summary } from './index';
import StoryPromo, { Headline, Summary, Link } from './index';

const ImageComponent = (
<Image
alt={text('Image alt text', '2019-03-01T14:00+00:00')}
alt={text('Image alt text', 'Robert Downey Junior in Iron Man')}
src={text(
'Image src',
'https://ichef.bbci.co.uk/news/660/cpsprodpb/11897/production/_106613817_999_al_.jpg',
Expand All @@ -21,7 +21,9 @@ const ImageComponent = (
// eslint-disable-next-line react/prop-types
const InfoComponent = ({ headlineText, summaryText, script }) => (
<Fragment>
<Headline script={script}>{headlineText}</Headline>
<Headline script={script}>
<Link href="https://www.bbc.co.uk/news">{headlineText}</Link>
</Headline>
<Summary script={script}>{summaryText}</Summary>
<Timestamp
datetime={text('Timestamp datetime', '2019-03-01T14:00+00:00')}
Expand Down
6 changes: 4 additions & 2 deletions packages/components/psammead-story-promo/src/index.test.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React, { Fragment } from 'react';
import { shouldMatchSnapshot } from '@bbc/psammead-test-helpers';
import { latin } from '@bbc/gel-foundations/scripts';
import StoryPromo, { Headline, Summary } from './index';
import StoryPromo, { Headline, Summary, Link } from './index';

const Image = <img src="https://foobar.com/image.png" alt="Alt text" />;

const Info = (
<Fragment>
<Headline script={latin}>The headline of the promo</Headline>
<Headline script={latin}>
<Link href="https://www.bbc.co.uk/news">The headline of the promo</Link>
</Headline>
<Summary script={latin}>The summary of the promo</Summary>
<time>12 March 2019</time>
</Fragment>
Expand Down