1
|
import { Col, Container, Row, Stack } from 'react-bootstrap';
|
2
|
import { Button } from 'antd';
|
3
|
import { DownOutlined, TagOutlined, UpOutlined } from '@ant-design/icons';
|
4
|
import { TagCategoryInfo } from '../../api';
|
5
|
import React, { 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
|
* Button icon.
|
21
|
*/
|
22
|
const [buttonIcon, setButtonIcon] = useState<React.ReactNode>(<DownOutlined />);
|
23
|
|
24
|
/**
|
25
|
* Changes visibility of tags.
|
26
|
*/
|
27
|
const changeTagsVisibility = () => {
|
28
|
setButtonIcon(visibleTags ? <DownOutlined /> : <UpOutlined />);
|
29
|
setVisibleTags(!visibleTags);
|
30
|
};
|
31
|
|
32
|
return (
|
33
|
<Container className="shadow-sm rounded">
|
34
|
<Row>
|
35
|
<Button
|
36
|
type="text"
|
37
|
icon={buttonIcon}
|
38
|
onClick={changeTagsVisibility}
|
39
|
className="w-100 text-start rounded"
|
40
|
>
|
41
|
{props.category.name}
|
42
|
</Button>
|
43
|
</Row>
|
44
|
{visibleTags && (
|
45
|
<Stack gap={2} className="mt-1 mb-2">
|
46
|
{props.category.tags?.map((tag, index) => (
|
47
|
<TagItem tag={tag} key={index} />
|
48
|
))}
|
49
|
</Stack>
|
50
|
)}
|
51
|
</Container>
|
52
|
);
|
53
|
}
|