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