Skip to content

Commit d7b0ad3

Browse files
Merge pull request #360 from jilliankeenan/PDS-566
(PDS-566) Add prop to Tag component to show/hide button
2 parents c14effb + 2a14fdc commit d7b0ad3

File tree

3 files changed

+55
-15
lines changed

3 files changed

+55
-15
lines changed

packages/react-components/source/react/library/tag/Tag.js

+26-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { func, string, oneOf } from 'prop-types';
2+
import { func, string, oneOf, bool } from 'prop-types';
33
import classNames from 'classnames';
44
import Button from '../button';
55
import Text from '../text';
@@ -15,16 +15,26 @@ const propTypes = {
1515
emphasis: oneOf(['bold', 'subtle']),
1616
/** Optional additional classnames */
1717
className: string,
18+
/** Boolean to hide/show close button */
19+
hideRemoveButton: bool,
1820
};
1921

2022
const defaultProps = {
2123
onClick: () => {},
2224
type: 'primary',
2325
className: '',
2426
emphasis: 'bold',
27+
hideRemoveButton: false,
2528
};
2629

27-
const Tag = ({ label, onClick, type, emphasis, className }) => {
30+
const Tag = ({
31+
label,
32+
onClick,
33+
type,
34+
emphasis,
35+
className,
36+
hideRemoveButton,
37+
}) => {
2838
return (
2939
<div
3040
className={classNames(
@@ -34,16 +44,22 @@ const Tag = ({ label, onClick, type, emphasis, className }) => {
3444
className,
3545
)}
3646
>
37-
<div className="rc-tag-label-background">
47+
<div
48+
className={classNames('rc-tag-label-background', {
49+
'rc-tag-border': !hideRemoveButton,
50+
})}
51+
>
3852
<Text className="rc-tag-text">{label}</Text>
3953
</div>
40-
<Button
41-
className="rc-tag-remove-button"
42-
onClick={() => onClick()}
43-
icon="close"
44-
iconSize="small"
45-
aria-label={`${label} Remove tag`}
46-
/>
54+
{!hideRemoveButton && (
55+
<Button
56+
className="rc-tag-remove-button"
57+
onClick={() => onClick()}
58+
icon="close"
59+
iconSize="small"
60+
aria-label={`${label} Remove tag`}
61+
/>
62+
)}
4763
</div>
4864
);
4965
};

packages/react-components/source/react/library/tag/Tag.md

+22
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,28 @@ const onTagClick = () => {
3939
</div>;
4040
```
4141

42+
### Static Tag
43+
44+
By adding `hideRemoveButton` to the tag component you can create a static tag in cases where you may want to disable the user from being able to remove it from a list.
45+
46+
```jsx
47+
const onTagClick = () => {
48+
console.log('The X was clicked');
49+
};
50+
51+
<div>
52+
<div>
53+
<Tag
54+
label="OS = 'Windows'"
55+
onClick={onTagClick}
56+
type="neutral"
57+
emphasis="subtle"
58+
hideRemoveButton
59+
/>
60+
</div>
61+
</div>;
62+
```
63+
4264
## Related
4365

4466
- [Badge](#/React%20Components/Badge)

packages/react-components/source/scss/library/components/_tag.scss

+7-5
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,24 @@
1616
.rc-tag-text {
1717
@include puppet-type-button();
1818
color: $puppet-white;
19-
height: fit-content;
19+
height: 24px;
20+
padding-bottom: 4px;
2021
padding-left: 8px;
2122
padding-right: 8px;
23+
padding-top: 4px;
2224
}
2325
}
2426

2527
.rc-tag-neutral.rc-tag-subtle {
2628
background-color: $puppet-white;
2729
border: $puppet-common-border;
2830

29-
.rc-tag-label-background {
31+
.rc-tag-border {
3032
border-right: $puppet-common-border;
33+
}
3134

32-
.rc-tag-text {
33-
color: $puppet-n700;
34-
}
35+
.rc-tag-text {
36+
color: $puppet-n700;
3537
}
3638

3739
.rc-tag-remove-button {

0 commit comments

Comments
 (0)