@bbc/psammead-caption
Version:
React styled components for a Caption
67 lines (42 loc) • 4.11 kB
Markdown
The `psammead-caption` component is a styled `figcaption` element.
`npm install @bbc/psammead-caption`
<!-- 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`' |
`psammead-caption` can be used together with the [`psammead-figure`](https://github.com/bbc/psammead/tree/latest/packages/components/psammead-figure) and [`psammead-visually-hidden-text`](https://github.com/bbc/psammead/tree/latest/packages/components/psammead-visually-hidden-text) components in this way. This visually hidden text is to give context to users of Assistive Technology.
```jsx
import Caption from '@bbc/psammead-caption';
import Figure from '@bbc/psammead-figure';
import VisuallyHiddenText from '@bbc/psammead-visually-hidden-text';
import { arabic } from '@bbc/gel-foundations/scripts';
const Wrapper = captionText => (
<Figure>
...
<Caption script={arabic} service="news">
<VisuallyHiddenText>Image caption, </VisuallyHiddenText>
{captionText}
</Caption>
</Figure>
);
```
The `Caption` component should be used only within a `figure` element. It is designed to be placed after an image or video component.
<!--
Since this is just a `<figcaption>` tag with associated styles, when you use this component, it has the same semantic meaning as a regular figcaption element.
The font and background-color choices meet WCAG AA colour contrast guidelines.
When this caption is used for scripts that do not support italic text, we can consider creating a prop that toggles the `font-style: italic`.
Psammead is completely open source. We are grateful for any contributions, whether they be new components, bug fixes or general improvements. Please see our primary contributing guide which can be found at [the root of the Psammead respository](https://github.com/bbc/psammead/blob/latest/CONTRIBUTING.md).
We welcome feedback and help on this work. By participating in this project, you agree to abide by the [code of conduct](https://github.com/bbc/psammead/blob/latest/CODE_OF_CONDUCT.md). Please take a moment to read it.
Psammead is [Apache 2.0 licensed](https://github.com/bbc/psammead/blob/latest/LICENSE).