Skip to content

Commit 9b4f5ae

Browse files
authored
Merge pull request #78 from NHSDigital/feature/newTagComponent
NHS.UK 4 - Add New Tag Component
2 parents 2dd17ad + f1a57ed commit 9b4f5ae

File tree

8 files changed

+111
-0
lines changed

8 files changed

+111
-0
lines changed

.storybook/storybook.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
11
@import '../node_modules/nhsuk-frontend/dist/nhsuk.css';
2+
3+
.tag-wrapper {
4+
display: flex;
5+
flex-direction: column;
6+
7+
& > .nhsuk-tag {
8+
margin-bottom: 10px;
9+
10+
&:last-of-type {
11+
margin-bottom: 0;
12+
}
13+
}
14+
}

src/__tests__/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe('Index', () => {
5656
'SkipLink',
5757
'SummaryList',
5858
'Table',
59+
'Tag',
5960
'Textarea',
6061
'LedeText',
6162
'BodyText',

src/components/tag/Tag.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { HTMLProps } from 'react';
2+
import classNames from 'classnames';
3+
4+
interface TagProps extends HTMLProps<HTMLSpanElement> {
5+
color?:
6+
| 'white'
7+
| 'grey'
8+
| 'green'
9+
| 'aqua-green'
10+
| 'blue'
11+
| 'purple'
12+
| 'pink'
13+
| 'red'
14+
| 'orange'
15+
| 'yellow';
16+
}
17+
18+
const Tag: React.FC<TagProps> = ({ className, color, ...rest }) => (
19+
<strong
20+
className={classNames('nhsuk-tag', { [`nhsuk-tag--${color}`]: color }, className)}
21+
{...rest}
22+
/>
23+
);
24+
25+
export default Tag;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { shallow } from 'enzyme';
2+
import React, { ComponentProps } from 'react';
3+
import Tag from '../Tag';
4+
5+
describe('Tag', () => {
6+
it('matches snapshot', () => {
7+
const wrapper = shallow(<Tag>Active</Tag>);
8+
9+
expect(wrapper).toMatchSnapshot();
10+
11+
expect(wrapper.find('strong').props().className).toBe('nhsuk-tag');
12+
13+
wrapper.unmount();
14+
});
15+
16+
it.each<ComponentProps<typeof Tag>['color']>([
17+
'white',
18+
'grey',
19+
'green',
20+
'aqua-green',
21+
'blue',
22+
'purple',
23+
'pink',
24+
'red',
25+
'orange',
26+
'yellow',
27+
])('adds colour class %s ', colour => {
28+
const wrapper = shallow(<Tag color={colour} />);
29+
30+
expect(wrapper.find('strong').props().className).toBe(`nhsuk-tag nhsuk-tag--${colour}`);
31+
32+
wrapper.unmount();
33+
});
34+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Tag matches snapshot 1`] = `
4+
<strong
5+
className="nhsuk-tag"
6+
>
7+
Active
8+
</strong>
9+
`;

src/components/tag/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Tag from './Tag';
2+
3+
export default Tag;

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export { default as Select } from './components/select';
4848
export { default as SkipLink } from './components/skip-link';
4949
export { default as SummaryList } from './components/summary-list';
5050
export { default as Table } from './components/table';
51+
export { default as Tag } from './components/tag';
5152
export { default as Textarea } from './components/textarea';
5253
export { LedeText, BodyText } from './components/typography';
5354
export { default as WarningCallout } from './components/warning-callout';

stories/Tag.stories.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
import React from 'react';
3+
import { storiesOf } from '@storybook/react';
4+
import centered from '@storybook/addon-centered';
5+
import { Tag } from '../src';
6+
7+
const stories = storiesOf('Tag', module);
8+
9+
stories
10+
.addDecorator(centered)
11+
.add('Standard Tag', () => <Tag>Active</Tag>)
12+
.add('All Colours', () => (
13+
<div className="tag-wrapper">
14+
<Tag color="white">Started</Tag>
15+
<Tag color="grey">Not started</Tag>
16+
<Tag color="green">New</Tag>
17+
<Tag color="aqua-green">Active</Tag>
18+
<Tag color="blue">Pending</Tag>
19+
<Tag color="purple">Received</Tag>
20+
<Tag color="pink">Sent</Tag>
21+
<Tag color="red">Rejected</Tag>
22+
<Tag color="orange">Declined</Tag>
23+
<Tag color="yellow">Delayed</Tag>
24+
</div>
25+
));

0 commit comments

Comments
 (0)