Skip to content

(PDS-566) Add prop to Tag component to show/hide button #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions packages/react-components/source/react/library/tag/Tag.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { func, string, oneOf } from 'prop-types';
import { func, string, oneOf, bool } from 'prop-types';
import classNames from 'classnames';
import Button from '../button';
import Text from '../text';
Expand All @@ -15,16 +15,26 @@ const propTypes = {
emphasis: oneOf(['bold', 'subtle']),
/** Optional additional classnames */
className: string,
/** Boolean to hide/show close button */
hideRemoveButton: bool,
};

const defaultProps = {
onClick: () => {},
type: 'primary',
className: '',
emphasis: 'bold',
hideRemoveButton: false,
};

const Tag = ({ label, onClick, type, emphasis, className }) => {
const Tag = ({
label,
onClick,
type,
emphasis,
className,
hideRemoveButton,
}) => {
return (
<div
className={classNames(
Expand All @@ -34,16 +44,22 @@ const Tag = ({ label, onClick, type, emphasis, className }) => {
className,
)}
>
<div className="rc-tag-label-background">
<div
className={classNames('rc-tag-label-background', {
'rc-tag-border': !hideRemoveButton,
})}
>
<Text className="rc-tag-text">{label}</Text>
</div>
<Button
className="rc-tag-remove-button"
onClick={() => onClick()}
icon="close"
iconSize="small"
aria-label={`${label} Remove tag`}
/>
{!hideRemoveButton && (
<Button
className="rc-tag-remove-button"
onClick={() => onClick()}
icon="close"
iconSize="small"
aria-label={`${label} Remove tag`}
/>
)}
</div>
);
};
Expand Down
22 changes: 22 additions & 0 deletions packages/react-components/source/react/library/tag/Tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,28 @@ const onTagClick = () => {
</div>;
```

### Static Tag

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.

```jsx
const onTagClick = () => {
console.log('The X was clicked');
};

<div>
<div>
<Tag
label="OS = 'Windows'"
onClick={onTagClick}
type="neutral"
emphasis="subtle"
hideRemoveButton
/>
</div>
</div>;
```

## Related

- [Badge](#/React%20Components/Badge)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@
.rc-tag-text {
@include puppet-type-button();
color: $puppet-white;
height: fit-content;
height: 24px;
padding-bottom: 4px;
padding-left: 8px;
padding-right: 8px;
padding-top: 4px;
}
}

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

.rc-tag-label-background {
.rc-tag-border {
border-right: $puppet-common-border;
}

.rc-tag-text {
color: $puppet-n700;
}
.rc-tag-text {
color: $puppet-n700;
}

.rc-tag-remove-button {
Expand Down