1
|
import { Col, Container, Row, Stack } from 'react-bootstrap';
|
2
|
import { Button } from 'antd';
|
3
|
import { DownOutlined, TagOutlined } from '@ant-design/icons';
|
4
|
import { TagCategoryInfo } from '../../api';
|
5
|
import { useState } from 'react';
|
6
|
import { TagItem } from './TagItem';
|
7
|
|
8
|
/**
|
9
|
* Creates a single item for a category in a tag panel.
|
10
|
* @param props Properties should contain a category.
|
11
|
* @returns Item that represents the category.
|
12
|
*/
|
13
|
export function CategoryItem(props: { category: TagCategoryInfo }) {
|
14
|
/**
|
15
|
* Should tags in this category be visible?
|
16
|
*/
|
17
|
const [visibleTags, setVisibleTags] = useState(false);
|
18
|
|
19
|
/**
|
20
|
* Changes visibility of tags.
|
21
|
*/
|
22
|
const changeTagsVisibility = () => {
|
23
|
setVisibleTags(!visibleTags);
|
24
|
};
|
25
|
|
26
|
return (
|
27
|
<Container>
|
28
|
<Row>
|
29
|
<Col>
|
30
|
<Button
|
31
|
type="text"
|
32
|
icon={<DownOutlined />}
|
33
|
onClick={changeTagsVisibility}
|
34
|
className="w-100 text-start"
|
35
|
>
|
36
|
{props.category.name}
|
37
|
</Button>
|
38
|
</Col>
|
39
|
<Col md="auto">
|
40
|
<TagOutlined style={{ color: props.category.color ?? 'black' }} />
|
41
|
</Col>
|
42
|
</Row>
|
43
|
{visibleTags && (
|
44
|
<Stack>
|
45
|
{props.category.tags?.map((tag, index) => (
|
46
|
<TagItem tag={tag} key={index} />
|
47
|
))}
|
48
|
</Stack>
|
49
|
)}
|
50
|
</Container>
|
51
|
);
|
52
|
}
|