-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.js
35 lines (32 loc) · 852 Bytes
/
tag.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import React from "react";
import PropTypes from "prop-types";
const Tag = ({ tagList, handleTagRemove }) => {
if (!tagList || tagList.length === 0) {
return <span data-test="empty-tag-list" />;
}
const tags = tagList.map((item, index) => {
return (
<div data-test="tag-list" key={index} className="tag-sel-item">
{item.label}
<span
data-test="tag-delete"
className="tag-close-btn"
onClick={(e) => {
handleTagRemove(item.value);
}}
/>
</div>
);
});
return <div data-test="component-Tag">{tags}</div>;
};
Tag.propTypes = {
tagList: PropTypes.arrayOf(
PropTypes.shape({
label: PropTypes.string.isRequired,
value: PropTypes.string.isRequired,
})
).isRequired,
handleTagRemove: PropTypes.func,
};
export default Tag;