-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtag.tsx
44 lines (39 loc) · 1.14 KB
/
tag.tsx
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
36
37
38
39
40
41
42
43
44
import React, { useState } from "react";
import { Space, Tag } from "antd";
const { CheckableTag } = Tag;
interface Props {
Data: string[];
onClick?: (tag: string) => void;
}
const App = ({ Data, onClick }: Props) => {
const [selectedTags, setSelectedTags] = useState<string[]>([]);
// const tagsData = ["V1", "V2", "V3", "V4"];
const handleChange = (tag: string, checked: boolean) => {
if (!checked) return;
const nextSelectedTags = checked
? [...selectedTags, tag]
: selectedTags.filter((t) => t !== tag);
console.log("You are interested in: ", nextSelectedTags);
onClick && onClick(tag);
setSelectedTags(nextSelectedTags);
};
return (
<>
<Space className="ml-5" size={16} wrap>
{Data.map((tag) => (
<CheckableTag
className={
selectedTags.includes(tag) ? "bg-neutral-700" : "bg-neutral-200"
}
key={tag}
checked={selectedTags.includes(tag)}
onChange={(checked) => handleChange(tag, checked)}
>
{tag}
</CheckableTag>
))}
</Space>
</>
);
};
export default App;