File tree Expand file tree Collapse file tree 8 files changed +111
-0
lines changed
Expand file tree Collapse file tree 8 files changed +111
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ describe('Index', () => {
5656 'SkipLink' ,
5757 'SummaryList' ,
5858 'Table' ,
59+ 'Tag' ,
5960 'Textarea' ,
6061 'LedeText' ,
6162 'BodyText' ,
Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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+ ` ;
Original file line number Diff line number Diff line change 1+ import Tag from './Tag' ;
2+
3+ export default Tag ;
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ export { default as Select } from './components/select';
4848export { default as SkipLink } from './components/skip-link' ;
4949export { default as SummaryList } from './components/summary-list' ;
5050export { default as Table } from './components/table' ;
51+ export { default as Tag } from './components/tag' ;
5152export { default as Textarea } from './components/textarea' ;
5253export { LedeText , BodyText } from './components/typography' ;
5354export { default as WarningCallout } from './components/warning-callout' ;
Original file line number Diff line number Diff line change 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+ ) ) ;
You can’t perform that action at this time.
0 commit comments