1 |
2c9bdf18
|
Dominik Poch
|
import { Container, Row, Stack } from 'react-bootstrap';
|
2 |
ed01528f
|
Dominik Poch
|
import { TagInfo } from '../../api';
|
3 |
a44aa67e
|
Jaroslav Hrubý
|
import { Button, Tooltip } from 'antd';
|
4 |
fa93df26
|
Dominik Poch
|
import { DownOutlined, QuestionCircleOutlined, TagOutlined } from '@ant-design/icons';
|
5 |
2c9bdf18
|
Dominik Poch
|
import React, { useContext, useState } from 'react';
|
6 |
ed01528f
|
Dominik Poch
|
import { SubTagItem } from './SubTagItem';
|
7 |
5593c10b
|
Dominik Poch
|
import { TagCategoryContext } from '../../contexts/TagCategoryContext';
|
8 |
dee53692
|
Jaroslav Hrubý
|
import { AnnotationContext } from '../../contexts/AnnotationContext';
|
9 |
ed01528f
|
Dominik Poch
|
|
10 |
fa93df26
|
Dominik Poch
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
11 |
|
|
import { faAngleDown, faAngleUp, faTag } from '@fortawesome/free-solid-svg-icons';
|
12 |
|
|
import { faCircleQuestion } from '@fortawesome/free-regular-svg-icons';
|
13 |
|
|
import styles from '/styles/Icon.module.scss';
|
14 |
|
|
|
15 |
ed01528f
|
Dominik Poch
|
/**
|
16 |
|
|
* Creates a single tag item in a tag panel.
|
17 |
|
|
* @param props Properties should contain the tag.
|
18 |
|
|
* @returns The item that represents the tag.
|
19 |
|
|
*/
|
20 |
|
|
export function TagItem(props: { tag: TagInfo }) {
|
21 |
|
|
/**
|
22 |
|
|
* Should sub tags be visible?
|
23 |
|
|
*/
|
24 |
|
|
const [visibleSubTags, setVisibleSubTags] = useState(false);
|
25 |
|
|
|
26 |
0441c314
|
Dominik Poch
|
/**
|
27 |
|
|
* Tag context.
|
28 |
|
|
*/
|
29 |
5593c10b
|
Dominik Poch
|
const { selectTag } = useContext(TagCategoryContext);
|
30 |
|
|
|
31 |
dee53692
|
Jaroslav Hrubý
|
/**
|
32 |
|
|
* Annotation context
|
33 |
|
|
*/
|
34 |
|
|
const { submitting } = useContext(AnnotationContext);
|
35 |
|
|
|
36 |
2c9bdf18
|
Dominik Poch
|
/**
|
37 |
|
|
* Button icon.
|
38 |
|
|
*/
|
39 |
|
|
const [buttonIcon, setButtonIcon] = useState<React.ReactNode>(<DownOutlined />);
|
40 |
|
|
|
41 |
ed01528f
|
Dominik Poch
|
/**
|
42 |
|
|
* Changes visibility of sub tags.
|
43 |
|
|
*/
|
44 |
|
|
const changeSubTagsVisibility = () => {
|
45 |
fa93df26
|
Dominik Poch
|
setButtonIcon(
|
46 |
|
|
visibleSubTags ? (
|
47 |
|
|
<FontAwesomeIcon icon={faAngleDown} className={styles.iconLeft} />
|
48 |
|
|
) : (
|
49 |
|
|
<FontAwesomeIcon icon={faAngleUp} className={styles.iconLeft} />
|
50 |
|
|
)
|
51 |
|
|
);
|
52 |
ed01528f
|
Dominik Poch
|
setVisibleSubTags(!visibleSubTags);
|
53 |
|
|
};
|
54 |
|
|
|
55 |
|
|
/**
|
56 |
|
|
* Selects the tag.
|
57 |
|
|
*/
|
58 |
5593c10b
|
Dominik Poch
|
const onSelectTag = () => {
|
59 |
|
|
selectTag(props.tag, null);
|
60 |
|
|
};
|
61 |
ed01528f
|
Dominik Poch
|
|
62 |
2c9bdf18
|
Dominik Poch
|
/**
|
63 |
|
|
* Does tag have sub tags?
|
64 |
|
|
*/
|
65 |
|
|
const hasSubTags = (props.tag.subTags?.length ?? 0) > 0;
|
66 |
|
|
|
67 |
ed01528f
|
Dominik Poch
|
return (
|
68 |
|
|
<Container>
|
69 |
|
|
<Row>
|
70 |
2c9bdf18
|
Dominik Poch
|
{hasSubTags && (
|
71 |
|
|
<Button
|
72 |
|
|
onClick={changeSubTagsVisibility}
|
73 |
|
|
className="w-100 text-start rounded"
|
74 |
dee53692
|
Jaroslav Hrubý
|
disabled={submitting}
|
75 |
2c9bdf18
|
Dominik Poch
|
>
|
76 |
fa93df26
|
Dominik Poch
|
<div className=" align-middle">
|
77 |
|
|
{buttonIcon}
|
78 |
|
|
<FontAwesomeIcon
|
79 |
|
|
icon={faTag}
|
80 |
|
|
style={{ color: props.tag.color ?? 'black' }}
|
81 |
|
|
className={styles.iconMiddle}
|
82 |
|
|
/>
|
83 |
|
|
{props.tag.name}
|
84 |
|
|
{props.tag.description && props.tag.description !== '' && (
|
85 |
|
|
<Tooltip
|
86 |
|
|
title={props.tag.description}
|
87 |
|
|
key={props.tag.description}
|
88 |
|
|
>
|
89 |
|
|
<FontAwesomeIcon
|
90 |
|
|
icon={faCircleQuestion}
|
91 |
|
|
className={styles.iconRight}
|
92 |
|
|
/>
|
93 |
|
|
</Tooltip>
|
94 |
|
|
)}
|
95 |
|
|
</div>
|
96 |
2c9bdf18
|
Dominik Poch
|
</Button>
|
97 |
|
|
)}
|
98 |
|
|
{!hasSubTags && (
|
99 |
dee53692
|
Jaroslav Hrubý
|
<Button
|
100 |
|
|
onClick={onSelectTag}
|
101 |
|
|
className="w-100 text-start rounded"
|
102 |
|
|
disabled={submitting}
|
103 |
|
|
>
|
104 |
fa93df26
|
Dominik Poch
|
<div className=" align-middle">
|
105 |
|
|
<FontAwesomeIcon
|
106 |
|
|
icon={faTag}
|
107 |
|
|
style={{ color: props.tag.color ?? 'black' }}
|
108 |
|
|
className={styles.iconLeft}
|
109 |
|
|
/>
|
110 |
|
|
{props.tag.name}
|
111 |
|
|
{props.tag.description && props.tag.description !== '' && (
|
112 |
|
|
<Tooltip
|
113 |
|
|
title={props.tag.description}
|
114 |
|
|
key={props.tag.description}
|
115 |
|
|
>
|
116 |
|
|
<FontAwesomeIcon
|
117 |
|
|
icon={faCircleQuestion}
|
118 |
|
|
className={styles.iconRight}
|
119 |
|
|
/>
|
120 |
|
|
</Tooltip>
|
121 |
|
|
)}
|
122 |
|
|
</div>
|
123 |
2c9bdf18
|
Dominik Poch
|
</Button>
|
124 |
|
|
)}
|
125 |
ed01528f
|
Dominik Poch
|
</Row>
|
126 |
2c9bdf18
|
Dominik Poch
|
{visibleSubTags && (
|
127 |
|
|
<Stack gap={2} className="mt-2">
|
128 |
ed01528f
|
Dominik Poch
|
{props.tag.subTags?.map((subTag, index) => (
|
129 |
5593c10b
|
Dominik Poch
|
<SubTagItem tag={props.tag} subTag={subTag} key={index} />
|
130 |
ed01528f
|
Dominik Poch
|
))}
|
131 |
|
|
</Stack>
|
132 |
|
|
)}
|
133 |
|
|
</Container>
|
134 |
|
|
);
|
135 |
|
|
}
|