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

Commit

Permalink
Merge pull request #609 from bbc/add-lang-attribute-to-brand-component
Browse files Browse the repository at this point in the history
Add lang attribute to brand component
  • Loading branch information
sadickisaac authored Jun 17, 2019
2 parents f25dc1c + c941ab7 commit a42d662
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 39 deletions.
1 change: 1 addition & 0 deletions packages/components/psammead-brand/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- prettier-ignore -->
| Version | Description |
| ------- | ----------- |
| 4.0.0 | [PR#609](https://github.com/bbc/psammead/pull/609) Add lang attribute to brand component |
| 3.0.0 | [PR#528](https://github.com/bbc/psammead/pull/528) Add link prop to allow dynamic link |
| 2.0.0 | [PR#480](https://github.com/bbc/psammead/pull/480) Allow the SVG to dynamically scale between the minimum and maximum widths passed in as props, also bump psammead-assets@0.1.9. Also reduce banner height and left-right padding under 600px. |
| 1.0.2 | [PR#515](https://github.com/bbc/psammead/pull/515) Update story to use dirDecorator |
Expand Down
14 changes: 9 additions & 5 deletions packages/components/psammead-brand/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

The `Brand` component provides the BBC service logo (as SVG), nested inside a styled link and div. The link is currently hardcoded to "https://www.bbc.co.uk/news".

`Brand` takes a `brandName`, `svgHeight`, `minWidth`, `maxWidth`, `url` and `svg` as props.
`Brand` takes a `product`, `svgHeight`, `minWidth`, `maxWidth`, `url`, `serviceLocalisedName` and `svg` as props.

The `brandName` is passed to a [VisuallyHiddenText](https://github.com/bbc/psammead/tree/latest/packages/components/VisuallyHiddenText) component, nested inside Brand.
The `product` is passed to a [VisuallyHiddenText](https://github.com/bbc/psammead/tree/latest/packages/components/VisuallyHiddenText) component, nested inside Brand.

The `serviceLocalisedName` is an optional prop referring to the local name of a service eg `Yoruba`. It is also passed to [VisuallyHiddenText](https://github.com/bbc/psammead/tree/latest/packages/components/VisuallyHiddenText) inside the Brand component.

The `svg` prop must contain a `group`, `viewbox` values and a `ratio`, which is used within an `svg` element. Examples of the `svg` object can be found in [@bbc/psammead-assets](https://github.com/bbc/psammead/blob/latest/packages/utilities/psammead-assets/README.md#service-svgs).

Expand All @@ -25,12 +27,13 @@ The `url` value is the link that points to the frontpage of the service associat
<!-- prettier-ignore -->
| Argument | Type | Required | Default | Example |
| --------- | ------ | -------- | ------- | ------------ |
| brandName | String | yes | N/A | `'BBC News'` |
| product | String | yes | N/A | `'BBC News'` |
| svgHeight | Number | yes | N/A | `24` |
| minWidth | Number | yes | N/A | `240` |
| maxWidth | Number | yes | N/A | `380` |
| svg | Object | yes | N/A | { group: `(<g fillrule="evenodd"><path d="M84.32" /></g>)`, viewbox: { height: 24, width: 167.95 }, ratio: 6.9979 } |
| url | String | no | N/A | `https://www.bbc.co.uk/news` |
| serviceLocalisedName | String | no | N/A | `'Yoruba'` |

## Usage

Expand All @@ -40,10 +43,11 @@ The typical use-case of this component is at the top of pages in a [`header` ele
import Brand from '@bbc/psammead-brand';
import { igbo } from '@bbc/psammead-assets/svgs';

const Header = brandName => (
const Header = (product, serviceName) => (
<header role="banner">
<Brand
brandName={brandName}
product={product}
serviceLocalisedName={serviceName}
svgHeight={24}
maxWidth={280}
minWidth={180}
Expand Down
2 changes: 1 addition & 1 deletion packages/components/psammead-brand/package-lock.json

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

2 changes: 1 addition & 1 deletion packages/components/psammead-brand/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bbc/psammead-brand",
"version": "3.0.0",
"version": "4.0.0",
"main": "dist/index.js",
"description": "Provides the BBC News logo (as SVG), nested a hardcoded link to https://www.bbc.co.uk/news",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ exports[`Brand should render correctly with link not provided 1`] = `
<span
className="c2"
>
Default Brand Name
<span
lang="en-GB"
>
Default Brand Name
</span>
,
Service
</span>
</div>
`;
Expand Down Expand Up @@ -172,8 +178,97 @@ exports[`Brand should render correctly with link provided 1`] = `
<span
className="c4"
>
Default Brand Name
<span
lang="en-GB"
>
Default Brand Name
</span>
,
Service
</span>
</a>
</div>
`;

exports[`Brand should render correctly with no service Localised Name 1`] = `
.c2 {
-webkit-clip-path: inset(100%);
clip-path: inset(100%);
-webkit-clip: rect(1px,1px,1px,1px);
clip: rect(1px,1px,1px,1px);
height: 1px;
overflow: hidden;
position: absolute;
width: 1px;
}
.c0 {
background-color: #B80000;
height: 3.5rem;
width: 100%;
padding: 0 0.5rem;
}
.c1 {
box-sizing: content-box;
fill: #FFFFFF;
padding-top: 1rem;
padding-bottom: 0.75rem;
width: 100%;
max-width: 17.5rem;
min-width: 11.25rem;
}
.c3:hover .c1,
.c3:focus .c1 {
-webkit-text-decoration: none;
text-decoration: none;
border-bottom: 0.25rem solid #FFFFFF;
}
@media (min-width:37.5rem) {
.c0 {
height: 5rem;
padding: 0 1rem;
}
}
@media (min-width:37.5rem) {
.c1 {
padding-top: 1.75rem;
padding-bottom: 1.5rem;
}
}
@media screen and (-ms-high-contrast:active),print {
.c1 {
fill: windowText;
}
}
<div
className="c0"
>
<svg
aria-hidden="true"
className="c1"
focusable="false"
height={24}
viewBox="0 0 167.95 24"
xmlns="http://www.w3.org/2000/svg"
>
<g
fillrule="evenodd"
>
<path
d="M84.32"
/>
</g>
</svg>
<span
className="c2"
>
BBC News
</span>
</div>
`;
96 changes: 70 additions & 26 deletions packages/components/psammead-brand/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,32 @@ const BrandSvg = styled.svg`
/* stylelint-enable */
`;

const StyledBrand = ({ brandName, svgHeight, svg, maxWidth, minWidth }) => (
const LocalisedBrandName = ({ product, serviceLocalisedName }) =>
serviceLocalisedName ? (
<Fragment>
<span lang="en-GB">{product}</span>, {serviceLocalisedName}
</Fragment>
) : (
product
);

LocalisedBrandName.propTypes = {
product: string.isRequired,
serviceLocalisedName: string,
};

LocalisedBrandName.defaultProps = {
serviceLocalisedName: null,
};

const StyledBrand = ({
product,
serviceLocalisedName,
svgHeight,
svg,
maxWidth,
minWidth,
}) => (
<Fragment>
{svg && (
<Fragment>
Expand All @@ -87,14 +112,20 @@ const StyledBrand = ({ brandName, svgHeight, svg, maxWidth, minWidth }) => (
>
{svg.group}
</BrandSvg>
<VisuallyHiddenText>{brandName}</VisuallyHiddenText>
<VisuallyHiddenText>
<LocalisedBrandName
product={product}
serviceLocalisedName={serviceLocalisedName}
/>
</VisuallyHiddenText>
</Fragment>
)}
</Fragment>
);

const brandProps = {
brandName: string.isRequired,
product: string.isRequired,
serviceLocalisedName: string,
maxWidth: number.isRequired,
minWidth: number.isRequired,
svgHeight: number.isRequired,
Expand All @@ -110,37 +141,50 @@ const brandProps = {

StyledBrand.propTypes = brandProps;

const Brand = ({ brandName, svgHeight, minWidth, maxWidth, svg, url }) => (
<Banner svgHeight={svgHeight}>
{url ? (
<StyledLink href={url} maxWidth={maxWidth} minWidth={minWidth}>
<StyledBrand
brandName={brandName}
svg={svg}
maxWidth={maxWidth}
minWidth={minWidth}
svgHeight={svgHeight}
/>
</StyledLink>
) : (
<StyledBrand
brandName={brandName}
svg={svg}
svgHeight={svgHeight}
minWidth={minWidth}
maxWidth={maxWidth}
/>
)}
</Banner>
);
StyledBrand.defaultProps = {
serviceLocalisedName: null,
};

const Brand = ({
product,
serviceLocalisedName,
svgHeight,
minWidth,
maxWidth,
svg,
url,
}) => {
const styledBrandProps = {
product,
serviceLocalisedName,
svgHeight,
minWidth,
maxWidth,
svg,
};

return (
<Banner svgHeight={svgHeight}>
{url ? (
<StyledLink href={url} maxWidth={maxWidth} minWidth={minWidth}>
<StyledBrand {...styledBrandProps} />
</StyledLink>
) : (
<StyledBrand {...styledBrandProps} />
)}
</Banner>
);
};

Brand.defaultProps = {
url: null,
serviceLocalisedName: null,
};

Brand.propTypes = {
...brandProps,
url: string,
serviceLocalisedName: string,
};

export default Brand;
6 changes: 4 additions & 2 deletions packages/components/psammead-brand/src/index.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ storiesOf('Components|Brand', module)

return (
<Brand
brandName="Default Brand Name"
product="Default Brand Name"
serviceLocalisedName="Service"
svgHeight={svgHeightInput}
minWidth={minWidthInput}
maxWidth={maxWidthInput}
Expand All @@ -60,7 +61,8 @@ storiesOf('Components|Brand', module)

return (
<Brand
brandName="Default Brand Name"
product="Default Brand Name"
serviceLocalisedName="Service"
svgHeight={svgHeightInput}
minWidth={minWidthInput}
maxWidth={maxWidthInput}
Expand Down
17 changes: 15 additions & 2 deletions packages/components/psammead-brand/src/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ describe('Brand', () => {
shouldMatchSnapshot(
'should render correctly with link provided',
<Brand
brandName="Default Brand Name"
product="Default Brand Name"
serviceLocalisedName="Service"
svgHeight={24}
maxWidth={280}
minWidth={180}
Expand All @@ -31,7 +32,19 @@ describe('Brand', () => {
shouldMatchSnapshot(
'should render correctly with link not provided',
<Brand
brandName="Default Brand Name"
product="Default Brand Name"
serviceLocalisedName="Service"
svg={svg}
svgHeight={24}
maxWidth={280}
minWidth={180}
/>,
);

shouldMatchSnapshot(
'should render correctly with no service Localised Name',
<Brand
product="BBC News"
svg={svg}
svgHeight={24}
maxWidth={280}
Expand Down

0 comments on commit a42d662

Please sign in to comment.