1 |
ed01528f
|
Dominik Poch
|
import { Col, Container, Row, Stack } from 'react-bootstrap';
|
2 |
|
|
import { TagInfo } from '../../api';
|
3 |
|
|
import { Button } from 'antd';
|
4 |
|
|
import { DownOutlined, TagOutlined } from '@ant-design/icons';
|
5 |
5593c10b
|
Dominik Poch
|
import { useContext, useState } from 'react';
|
6 |
ed01528f
|
Dominik Poch
|
import { SubTagItem } from './SubTagItem';
|
7 |
5593c10b
|
Dominik Poch
|
import { TagCategoryContext } from '../../contexts/TagCategoryContext';
|
8 |
ed01528f
|
Dominik Poch
|
|
9 |
|
|
/**
|
10 |
|
|
* Creates a single tag item in a tag panel.
|
11 |
|
|
* @param props Properties should contain the tag.
|
12 |
|
|
* @returns The item that represents the tag.
|
13 |
|
|
*/
|
14 |
|
|
export function TagItem(props: { tag: TagInfo }) {
|
15 |
|
|
/**
|
16 |
|
|
* Should sub tags be visible?
|
17 |
|
|
*/
|
18 |
|
|
const [visibleSubTags, setVisibleSubTags] = useState(false);
|
19 |
|
|
|
20 |
0441c314
|
Dominik Poch
|
/**
|
21 |
|
|
* Tag context.
|
22 |
|
|
*/
|
23 |
5593c10b
|
Dominik Poch
|
const { selectTag } = useContext(TagCategoryContext);
|
24 |
|
|
|
25 |
ed01528f
|
Dominik Poch
|
/**
|
26 |
|
|
* Changes visibility of sub tags.
|
27 |
|
|
*/
|
28 |
|
|
const changeSubTagsVisibility = () => {
|
29 |
|
|
setVisibleSubTags(!visibleSubTags);
|
30 |
|
|
};
|
31 |
|
|
|
32 |
|
|
/**
|
33 |
|
|
* Selects the tag.
|
34 |
|
|
*/
|
35 |
5593c10b
|
Dominik Poch
|
const onSelectTag = () => {
|
36 |
|
|
selectTag(props.tag, null);
|
37 |
|
|
};
|
38 |
ed01528f
|
Dominik Poch
|
|
39 |
|
|
return (
|
40 |
|
|
<Container>
|
41 |
|
|
<Row>
|
42 |
|
|
<Col>
|
43 |
|
|
{props.tag.subTags && (
|
44 |
|
|
<Button
|
45 |
|
|
type="text"
|
46 |
|
|
icon={<DownOutlined />}
|
47 |
|
|
onClick={changeSubTagsVisibility}
|
48 |
|
|
className="w-100 text-start"
|
49 |
|
|
>
|
50 |
|
|
{props.tag.name}
|
51 |
|
|
</Button>
|
52 |
|
|
)}
|
53 |
|
|
{!props.tag.subTags && (
|
54 |
|
|
<Button
|
55 |
|
|
type="text"
|
56 |
5593c10b
|
Dominik Poch
|
onClick={onSelectTag}
|
57 |
ed01528f
|
Dominik Poch
|
className="w-100 text-start"
|
58 |
|
|
>
|
59 |
|
|
{props.tag.name}
|
60 |
|
|
</Button>
|
61 |
|
|
)}
|
62 |
|
|
</Col>
|
63 |
|
|
<Col sm="auto">
|
64 |
|
|
<TagOutlined style={{ color: props.tag.color ?? 'black' }} />
|
65 |
|
|
</Col>
|
66 |
|
|
</Row>
|
67 |
|
|
{props.tag.subTags && visibleSubTags && (
|
68 |
|
|
<Stack>
|
69 |
|
|
{props.tag.subTags?.map((subTag, index) => (
|
70 |
5593c10b
|
Dominik Poch
|
<SubTagItem tag={props.tag} subTag={subTag} key={index} />
|
71 |
ed01528f
|
Dominik Poch
|
))}
|
72 |
|
|
</Stack>
|
73 |
|
|
)}
|
74 |
|
|
</Container>
|
75 |
|
|
);
|
76 |
|
|
}
|