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

Add lang attribute to brand component #609

Merged
25 commits merged into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1d00d38
Add lang attribute to the brand component
EinsteinNjoroge Jun 11, 2019
09b4473
Update tests and snapshot
EinsteinNjoroge Jun 11, 2019
ca1e93c
Use `product` and `serviceLocalisedName` in-place of `brandName`
EinsteinNjoroge Jun 12, 2019
b6bfca5
Merge branch 'latest' into add-lang-attribute-to-brand-component
Jun 12, 2019
ce25980
Bump up version and update changelog and readme
EinsteinNjoroge Jun 12, 2019
6a2fd68
pull latest
EinsteinNjoroge Jun 12, 2019
b219a2a
fix comma
EinsteinNjoroge Jun 12, 2019
b01825e
Update snapshot
EinsteinNjoroge Jun 12, 2019
5893075
Update packages/components/psammead-brand/README.md
EinsteinNjoroge Jun 12, 2019
3a49291
Update packages/components/psammead-brand/README.md
EinsteinNjoroge Jun 12, 2019
0e4bce1
Update packages/components/psammead-brand/README.md
EinsteinNjoroge Jun 12, 2019
9fda77b
Update version to 4.0.0
EinsteinNjoroge Jun 12, 2019
5c9804d
Merge branch 'latest' into add-lang-attribute-to-brand-component
Jun 12, 2019
c6fa2de
exclude package-lock.json
EinsteinNjoroge Jun 12, 2019
2345985
exclude package-lock.json
EinsteinNjoroge Jun 12, 2019
6b33cd3
update brand's package-lock.json version number
EinsteinNjoroge Jun 12, 2019
6e6831b
Merge branch 'latest' into add-lang-attribute-to-brand-component
Jun 12, 2019
8fdb301
Fix typo in serviceLocalizedName
EinsteinNjoroge Jun 13, 2019
c185806
Fix typo in readme
EinsteinNjoroge Jun 13, 2019
47082ca
Merge branch 'latest' into add-lang-attribute-to-brand-component
EinsteinNjoroge Jun 13, 2019
5615696
Merge branch 'latest' into add-lang-attribute-to-brand-component
Jun 13, 2019
3d692f7
update readme
EinsteinNjoroge Jun 13, 2019
9715b2c
Update packages/components/psammead-brand/README.md
EinsteinNjoroge Jun 13, 2019
ec1bda2
Merge branch 'latest' into add-lang-attribute-to-brand-component
12 Jun 13, 2019
c941ab7
Merge branch 'latest' into add-lang-attribute-to-brand-component
EinsteinNjoroge Jun 17, 2019
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
208 changes: 156 additions & 52 deletions package-lock.json

Large diffs are not rendered by default.

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 |
| ------- | ----------- |
| 3.0.1 | [PR#609](https://github.com/bbc/psammead/pull/609) Add lang attribute to brand component |
EinsteinNjoroge marked this conversation as resolved.
Show resolved Hide resolved
| 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,9 @@

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`, `serviceLocalizedName` 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.
EinsteinNjoroge marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -16,6 +16,8 @@ The `svgHeight` value acts as a placeholder for the `svg` element meaning the ov

The `url` value is the link that points to the frontpage of the service associated with the `svg`.

The `serviceLocalizedName` is an optional props referring to the local name of a service eg `Yoruba`.
EinsteinNjoroge marked this conversation as resolved.
Show resolved Hide resolved

## Installation

`npm install @bbc/psammead-brand`
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'` |
EinsteinNjoroge marked this conversation as resolved.
Show resolved Hide resolved
| 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` |
| serviceLocalizedName | String | no | N/A | `'Yoruba'` |
EinsteinNjoroge marked this conversation as resolved.
Show resolved Hide resolved

## 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}
serviceLocalizedName={serviceName}
svgHeight={24}
maxWidth={280}
minWidth={180}
Expand Down
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": "3.0.1",
"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 Localized 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, serviceLocalizedName }) =>
serviceLocalizedName ? (
<Fragment>
<span lang="en-GB">{product}</span>, {serviceLocalizedName}
</Fragment>
) : (
product
);

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

LocalisedBrandName.defaultProps = {
serviceLocalizedName: null,
};

const StyledBrand = ({
product,
serviceLocalizedName,
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}
serviceLocalizedName={serviceLocalizedName}
/>
</VisuallyHiddenText>
</Fragment>
)}
</Fragment>
);

const brandProps = {
brandName: string.isRequired,
product: string.isRequired,
serviceLocalizedName: 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 = {
serviceLocalizedName: null,
};

const Brand = ({
product,
serviceLocalizedName,
svgHeight,
minWidth,
maxWidth,
svg,
url,
}) => {
const styledBrandProps = {
product,
serviceLocalizedName,
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,
serviceLocalizedName: null,
};

Brand.propTypes = {
...brandProps,
url: string,
serviceLocalizedName: 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"
serviceLocalizedName="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"
serviceLocalizedName="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"
serviceLocalizedName="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"
serviceLocalizedName="Service"
svg={svg}
svgHeight={24}
maxWidth={280}
minWidth={180}
/>,
);

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