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

Apply font based on service: Paragraph #941

Merged
merged 4 commits into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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-paragraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- prettier-ignore -->
| Version | Description |
|---------|-------------|
| 2.0.0 | [PR#941](https://github.com/bbc/psammead/pull/941) Apply font based on service prop |
| 1.0.9 | [PR#783](https://github.com/bbc/psammead/pull/783) Update to latest psammead-test-helpers. Update snapshots. |
| 1.0.8 | [PR#769](https://github.com/bbc/psammead/pull/769) Fix stories not appearing in storybook when using `install:packages:link` |
| 1.0.7 | [PR#746](https://github.com/bbc/psammead/pull/746) Use `@bbc/psammead-inline-link@1.1.1` and add a 'with inline link' story |
Expand Down
9 changes: 7 additions & 2 deletions packages/components/psammead-paragraph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@ It uses `@bbc/psammead-styles` for colours and font family and `@bbc/gel-foundat

## Props

<!-- prettier-ignore -->
| Argument | Type | Required | Default | Example |
| --------- | ---- | -------- | ------- | ------- |
| Script | object | yes | latin | { canon: { groupA: { fontSize: '28', lineHeight: '32',}, groupB: { fontSize: '32', lineHeight: '36', }, groupD: { fontSize: '44', lineHeight: '48', }, }, trafalgar: { groupA: { fontSize: '20', lineHeight: '24', }, groupB: { fontSize: '24', lineHeight: '28', }, groupD: { fontSize: '32', lineHeight: '36', }, }, }|

| service | string | yes | N/A | `'news'` |

## Usage

```jsx
import Paragraph from '@bbc/psammead-paragraph';
import { latin } from '@bbc/gel-foundations/scripts';

const WrappingComponent = () => <Paragraph script={latin}>Text here</Paragraph>;
const WrappingComponent = () => (
<Paragraph script={latin} service="news">
Text here
</Paragraph>
);
```

### When to use this component
Expand Down
8 changes: 4 additions & 4 deletions packages/components/psammead-paragraph/package-lock.json

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

6 changes: 3 additions & 3 deletions packages/components/psammead-paragraph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bbc/psammead-paragraph",
"version": "1.0.9",
"version": "2.0.0",
"description": "React styled component for a Paragraph",
"main": "dist/index.js",
"repository": {
Expand All @@ -23,10 +23,10 @@
"homepage": "https://github.com/bbc/psammead/blob/latest/packages/components/psammead-paragraph/README.md",
"dependencies": {
"@bbc/gel-foundations": "^3.0.0",
"@bbc/psammead-styles": "^0.3.2"
"@bbc/psammead-styles": "^1.1.0"
},
"devDependencies": {
"@bbc/psammead-storybook-helpers": "^3.0.0",
"@bbc/psammead-storybook-helpers": "^3.1.0",
"@bbc/psammead-inline-link": "1.1.1",
"@bbc/psammead-test-helpers": "^1.0.1",
"react": "^16.8.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ exports[`Paragraph should render a correctly 1`] = `
line-height: 1.25rem;
color: #3F3F42;
font-family: ReithSans,Helvetica,Arial,sans-serif;
font-weight: 400;
font-style: normal;
padding-bottom: 1.5rem;
margin: 0;
}
Expand Down Expand Up @@ -36,7 +38,9 @@ exports[`Paragraph should render correctly with arabic script typography values
font-size: 1.125rem;
line-height: 1.75rem;
color: #3F3F42;
font-family: ReithSans,Helvetica,Arial,sans-serif;
font-family: NassimPersian,Arial,Verdana,Geneva,Helvetica,sans serif;
font-weight: 400;
font-style: normal;
padding-bottom: 1.5rem;
margin: 0;
}
Expand Down
11 changes: 5 additions & 6 deletions packages/components/psammead-paragraph/src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import styled from 'styled-components';
import { shape } from 'prop-types';
import { shape, string } from 'prop-types';
import { C_SHADOW } from '@bbc/psammead-styles/colours';
import { GEL_SPACING_TRPL } from '@bbc/gel-foundations/spacings';
import {
getBodyCopy,
GEL_FF_REITH_SANS,
} from '@bbc/gel-foundations/typography';
import { getBodyCopy } from '@bbc/gel-foundations/typography';
import { scriptPropType } from '@bbc/gel-foundations/prop-types';
import { getSansRegular } from '@bbc/psammead-styles/font-styles';

const Paragraph = styled.p`
${props => (props.script ? getBodyCopy(props.script) : '')};
color: ${C_SHADOW};
font-family: ${GEL_FF_REITH_SANS};
${({ service }) => getSansRegular(service)}
padding-bottom: ${GEL_SPACING_TRPL};
margin: 0; /* Reset */
`;

Paragraph.propTypes = {
script: shape(scriptPropType).isRequired,
service: string.isRequired,
};

export default Paragraph;
10 changes: 6 additions & 4 deletions packages/components/psammead-paragraph/src/index.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ storiesOf('Components|Paragraph', module)
'default',
inputProvider(
[{ name: 'Paragraph' }],
({ slotTexts: [paragraph], script }) => (
<Paragraph script={script}>{paragraph}</Paragraph>
({ slotTexts: [paragraph], script, service }) => (
<Paragraph script={script} service={service}>
{paragraph}
</Paragraph>
),
),
{ notes, knobs: { escapeHTML: false } },
Expand All @@ -22,8 +24,8 @@ storiesOf('Components|Paragraph', module)
'containing an inline link',
inputProvider(
[{ name: 'Paragraph' }, { name: 'Inline link' }],
({ slotTexts: [paragraph, linkText], script }) => (
<Paragraph script={script}>
({ slotTexts: [paragraph, linkText], script, service }) => (
<Paragraph script={script} service={service}>
{`${paragraph} `}
<InlineLink href="https://www.bbc.com">{linkText}</InlineLink>
{` ${paragraph}`}
Expand Down
8 changes: 6 additions & 2 deletions packages/components/psammead-paragraph/src/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import Paragraph from './index';
describe('Paragraph', () => {
shouldMatchSnapshot(
'should render a correctly',
<Paragraph script={latin}>This is text in a paragraph.</Paragraph>,
<Paragraph script={latin} service="news">
This is text in a paragraph.
</Paragraph>,
);

shouldMatchSnapshot(
'should render correctly with arabic script typography values',
<Paragraph script={arabic}>بعض محتوى النص</Paragraph>,
<Paragraph script={arabic} service="persian">
بعض محتوى النص
</Paragraph>,
);
});