Skip to content

Commit 0f0b699

Browse files
authored
feature/UIDS-251 update pill sizing (#268)
* default font-type-20 + update padding * add Pill with link * add PILL_COLORS constant * remove Large pill variant * update documentation * update snapshots * fix Pill prop issue in failing test * update Pill to accept children, adjust props * keep text and children props for backwards compatibility * update docs * update to use FontAwesome for close icon + blue color update
1 parent 9096c89 commit 0f0b699

File tree

8 files changed

+144
-92
lines changed

8 files changed

+144
-92
lines changed

spec/__snapshots__/Storyshots.test.js.snap

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,21 +2446,6 @@ exports[`Storyshots Design System/Pill Default 1`] = `
24462446
>
24472447
Text
24482448
</span>
2449-
<h4
2450-
style={
2451-
Object {
2452-
"marginBottom": "2rem",
2453-
"marginTop": "2rem",
2454-
}
2455-
}
2456-
>
2457-
Large
2458-
</h4>
2459-
<span
2460-
className="Pill Pill--blue Pill--large"
2461-
>
2462-
Text
2463-
</span>
24642449
<h4
24652450
style={
24662451
Object {
@@ -2522,7 +2507,23 @@ exports[`Storyshots Design System/Pill With Close 1`] = `
25222507
onClick={[Function]}
25232508
type="button"
25242509
>
2525-
×
2510+
<svg
2511+
aria-hidden="true"
2512+
className="svg-inline--fa fa-times fa-w-11 "
2513+
data-icon="times"
2514+
data-prefix="fas"
2515+
focusable="false"
2516+
role="img"
2517+
style={Object {}}
2518+
viewBox="0 0 352 512"
2519+
xmlns="http://www.w3.org/2000/svg"
2520+
>
2521+
<path
2522+
d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"
2523+
fill="currentColor"
2524+
style={Object {}}
2525+
/>
2526+
</svg>
25262527
</button>
25272528
</span>
25282529
</div>
@@ -2561,6 +2562,28 @@ exports[`Storyshots Design System/Pill With Leading Icon 1`] = `
25612562
</div>
25622563
`;
25632564

2565+
exports[`Storyshots Design System/Pill With Link 1`] = `
2566+
<div
2567+
style={
2568+
Object {
2569+
"padding": "1rem",
2570+
}
2571+
}
2572+
>
2573+
<span
2574+
className="Pill Pill--blue"
2575+
>
2576+
<a
2577+
href="https://www.userinterviews.com/"
2578+
rel="noreferrer"
2579+
target="_blank"
2580+
>
2581+
Visit our site
2582+
</a>
2583+
</span>
2584+
</div>
2585+
`;
2586+
25642587
exports[`Storyshots Design System/Popper Dark 1`] = `
25652588
<div
25662589
style={

src/Pill/Pill.jsx

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,60 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import classNames from 'classnames';
44
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
5+
import { faTimes } from '@fortawesome/free-solid-svg-icons';
56

67
import './Pill.scss';
78

8-
const colors = ['blue', 'orange', 'yellow', 'green', 'gray', 'silver'];
9+
export const PILL_COLORS = {
10+
BLUE: 'blue', ORANGE: 'orange', YELLOW: 'yellow', GREEN: 'green', GRAY: 'gray', SILVER: 'silver',
11+
};
912

1013
const Pill = ({
14+
children,
1115
color,
1216
icon,
1317
id,
14-
large,
1518
onClose,
1619
text,
20+
...props
1721
}) => (
1822
<span
1923
className={
20-
classNames(
21-
'Pill',
22-
{ [`Pill--${color}`]: !!color },
23-
{ [`Pill--large`]: !!large },
24-
)
25-
}
24+
classNames(
25+
'Pill',
26+
{ [`Pill--${color}`]: !!color },
27+
)
28+
}
29+
{...props}
2630
>
2731
{ icon && (
28-
<FontAwesomeIcon className="Pill__icon--lead" icon={icon} />
29-
)}
30-
{text}
31-
{ onClose && (
32-
<button className="Pill__button--close" type="button" onClick={() => onClose(id)}> &times;</button>
32+
<FontAwesomeIcon className="Pill__icon--lead" icon={icon} />
3333
)}
34+
{ children }
35+
{ text }
36+
{ onClose && (
37+
<button className="Pill__button--close" type="button" onClick={() => onClose(id)}>
38+
<FontAwesomeIcon icon={faTimes} />
39+
</button>
40+
)}
3441
</span>
35-
);
42+
);
3643

3744
Pill.propTypes = {
38-
color: PropTypes.oneOf(colors),
45+
children: PropTypes.node,
46+
color: PropTypes.oneOf(Object.values(PILL_COLORS)),
3947
icon: PropTypes.any,
4048
id: PropTypes.string,
41-
large: PropTypes.bool,
42-
text: PropTypes.node.isRequired,
49+
text: PropTypes.node,
4350
onClose: PropTypes.func,
4451
};
4552

4653
Pill.defaultProps = {
47-
color: 'blue',
54+
children: undefined,
55+
color: PILL_COLORS.BLUE,
4856
icon: undefined,
4957
id: undefined,
50-
large: undefined,
58+
text: undefined,
5159
onClose: undefined,
5260
};
5361

src/Pill/Pill.mdx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ArgsTable, Story, Preview } from '@storybook/addon-docs/blocks';
22
import Pill from './Pill';
33

44
# Pill
5-
Represents an object that can be viewed with or without an icon
5+
Represents an object that can be viewed with or without an icon. Useful when describing or categorizing a property.
66

77
<Preview>
88
<Story id="design-system-pill--default" />
@@ -12,17 +12,24 @@ Represents an object that can be viewed with or without an icon
1212

1313
## Anatomy
1414

15-
- **Text: ** main descriptor of the pill
16-
- **Icon: ** relevant icon that makes it easier for users to identify (always placed left of the Text)
15+
- **Content: ** main content area of the Pill. Can be provided plain text or a link (`<a>`) as `children`
16+
- **Icon: ** relevant icon that makes it easier for users to identify (always placed left of the Content)
1717
- **Close: ** users have the option to clear the pill (provided by default with the presence of the `onClose` function)
1818

1919
## Best practices
2020

21-
- TBD
21+
- Use to label, categorize, or organize items using keywords that describe them
22+
- Help users search for and find related content quickly and easily
23+
- Use to highlight an item's status for quick recognition
24+
- Ideal to indicate meanings that users can learn and recognize across the app
2225

2326
## Stories
2427

2528
### Default
29+
- The default Pill and available colors
30+
- Use the `PILL_COLORS` constant when setting the `color` prop
31+
- Can use either the `text` prop or provide an element via `children` for content. (Note: the `text` prop is planned to be retired in favor of `children` in a future release)
32+
- If using plain text or an element as the content via `children`, do not wrap in block-level elements (e.g. `<p>` or `div`)
2633

2734
<Preview>
2835
<Story id="design-system-pill--default" />
@@ -41,3 +48,11 @@ Represents an object that can be viewed with or without an icon
4148
<Preview>
4249
<Story id="design-system-pill--with-close" />
4350
</Preview>
51+
52+
### With Link
53+
- For Pills that link to more information
54+
- The Pill accepts an `<a>` tag as a child
55+
56+
<Preview>
57+
<Story id="design-system-pill--with-link" />
58+
</Preview>

src/Pill/Pill.scss

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
@import '../../scss/theme';
33

44
.Pill {
5-
@include font-type-30;
5+
@include font-type-20;
66
font-weight: $font-weight-normal;
77
display: inline;
88
background-color: $ux-blue-100;
99
color: $ux-blue-700;
1010
border: 0.06rem solid $ux-blue-300;
1111
border-radius: $ux-border-radius;
12-
padding: $ux-spacing-10 $ux-spacing-20;
12+
padding: $ux-spacing-10 $ux-spacing-30;
1313

1414
&--blue {
1515
background-color: $ux-blue-100;
@@ -24,7 +24,7 @@
2424
.Pill__button--close {
2525
background-color: unset;
2626
border: none;
27-
color: $ux-blue;
27+
color: $ux-blue-300;
2828
margin-left: $ux-spacing-20;
2929
margin-right: 0;
3030
padding: 0;
@@ -129,10 +129,4 @@
129129
padding: 0;
130130
}
131131
}
132-
133-
&--large {
134-
@include font-type-40;
135-
border-radius: 0.5rem;
136-
padding: $ux-spacing-10 $ux-spacing-20;
137-
}
138132
}

src/Pill/Pill.stories.jsx

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import {
44
withKnobs,
55
text,
66
select,
7-
boolean,
87
} from '@storybook/addon-knobs';
98
import { faUsers } from '@fortawesome/free-solid-svg-icons';
109

11-
import Pill from 'src/Pill';
10+
import { Pill, PILL_COLORS } from 'src/Pill';
1211
import mdx from './Pill.mdx';
1312

1413
export default {
@@ -22,8 +21,6 @@ export default {
2221
},
2322
};
2423

25-
const colors = ['blue', 'orange', 'yellow', 'green', 'gray', 'silver'];
26-
2724
const handleClose = (id) => {
2825
action('handle close')(id);
2926
};
@@ -32,61 +29,70 @@ export const Default = () => (
3229
<div>
3330
<h4 style={{ marginBottom: '2rem' }}>Test Pill</h4>
3431
<Pill
35-
color={select('Color', colors, 'blue')}
32+
color={select('Color', Object.values(PILL_COLORS), PILL_COLORS.BLUE)}
3633
id="1"
37-
large={boolean('Large', false)}
38-
text={text('Text', 'Text')}
39-
/>
40-
<h4 style={{ marginBottom: '2rem', marginTop: '2rem' }}>Large</h4>
41-
<Pill
42-
color="blue"
43-
large
44-
text="Text"
45-
/>
34+
>
35+
{text('Text', 'Text')}
36+
</Pill>
4637
<h4 style={{ marginBottom: '2rem', marginTop: '2rem' }}>Colors</h4>
4738
<Pill
48-
color="blue"
49-
text="blue"
50-
/>
39+
color={PILL_COLORS.BLUE}
40+
>
41+
blue
42+
</Pill>
5143
<Pill
52-
color="orange"
53-
text="orange"
54-
/>
44+
color={PILL_COLORS.ORANGE}
45+
>
46+
orange
47+
</Pill>
5548
<Pill
56-
color="yellow"
57-
text="yellow"
58-
/>
49+
color={PILL_COLORS.YELLOW}
50+
>
51+
yellow
52+
</Pill>
5953
<Pill
60-
color="green"
61-
text="green"
62-
/>
54+
color={PILL_COLORS.GREEN}
55+
>
56+
green
57+
</Pill>
6358
<Pill
64-
color="gray"
65-
text="gray"
66-
/>
59+
color={PILL_COLORS.GRAY}
60+
>
61+
gray
62+
</Pill>
6763
<Pill
68-
color="silver"
69-
text="silver"
70-
/>
64+
color={PILL_COLORS.SILVER}
65+
>
66+
silver
67+
</Pill>
7168
</div>
7269
);
7370

7471
export const WithLeadingIcon = () => (
7572
<Pill
76-
color={select('Color', colors, 'blue')}
73+
color={select('Color', Object.values(PILL_COLORS), PILL_COLORS.BLUE)}
7774
icon={faUsers}
7875
id="2"
79-
large={boolean('Large', false)}
80-
text={text('Text', 'Text')}
81-
/>
76+
>
77+
{text('Text', 'Text')}
78+
</Pill>
8279
);
8380

8481
export const WithClose = () => (
8582
<Pill
86-
color={select('Color', colors, 'blue')}
83+
color={select('Color', Object.values(PILL_COLORS), PILL_COLORS.BLUE)}
8784
id="3"
88-
large={boolean('Large', false)}
89-
text={text('Text', 'Text')}
9085
onClose={handleClose}
91-
/>
86+
>
87+
{text('Text', 'Text')}
88+
</Pill>
89+
);
90+
91+
export const WithLink = () => (
92+
<Pill
93+
color={select('Color', Object.values(PILL_COLORS), PILL_COLORS.BLUE)}
94+
id="3"
95+
>
96+
<a href="https://www.userinterviews.com/" rel="noreferrer" target="_blank">{text('Link text', 'Visit our site')}</a>
97+
</Pill>
9298
);

src/Pill/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
export { default } from './Pill';
1+
import Pill, { PILL_COLORS } from './Pill';
2+
3+
export {
4+
Pill,
5+
PILL_COLORS,
6+
};

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
ModalFooter,
1919
ModalHeader,
2020
} from 'src/Modal';
21-
import Pill from 'src/Pill';
21+
import { Pill, PILL_COLORS } from 'src/Pill';
2222
import Popper from 'src/Popper';
2323
import ProfileCell from 'src/ProfileCell';
2424
import RadioButton from 'src/RadioButton';
@@ -68,6 +68,7 @@ export {
6868
ModalFooter,
6969
ModalHeader,
7070
Pill,
71+
PILL_COLORS,
7172
Popper,
7273
ProfileCell,
7374
RadioButton,

0 commit comments

Comments
 (0)