1
|
import { SubTagInfo, TagInfo } from '../../api';
|
2
|
import { Container, Row } from 'react-bootstrap';
|
3
|
import { Button } from 'antd';
|
4
|
import { useContext } from 'react';
|
5
|
import { TagCategoryContext } from '../../contexts/TagCategoryContext';
|
6
|
import { AnnotationContext } from '../../contexts/AnnotationContext';
|
7
|
|
8
|
/**
|
9
|
* Creates a single tag item in a tag panel.
|
10
|
* @param props Properties should contain the tag.
|
11
|
* @returns The item that represents the tag.
|
12
|
*/
|
13
|
export function SubTagItem(props: { tag: TagInfo; subTag: SubTagInfo }) {
|
14
|
/**
|
15
|
* Tag context.
|
16
|
*/
|
17
|
const { selectTag } = useContext(TagCategoryContext);
|
18
|
|
19
|
/**
|
20
|
* Annotation context
|
21
|
*/
|
22
|
const { submitting } = useContext(AnnotationContext);
|
23
|
|
24
|
/**
|
25
|
* Selects the sub tag.
|
26
|
*/
|
27
|
const onSelectSubTag = () => {
|
28
|
selectTag(props.tag, props.subTag);
|
29
|
};
|
30
|
|
31
|
return (
|
32
|
<Container>
|
33
|
<Row>
|
34
|
<Button
|
35
|
onClick={onSelectSubTag}
|
36
|
className="w-100 text-start rounded"
|
37
|
disabled={submitting}
|
38
|
>
|
39
|
{props.subTag.name}
|
40
|
</Button>
|
41
|
</Row>
|
42
|
</Container>
|
43
|
);
|
44
|
}
|