Revize ed01528f
Přidáno uživatelem Dominik Poch před asi 3 roky(ů)
webapp/components/annotation/CategoryItem.tsx | ||
---|---|---|
1 |
import { Col, Container, Row, Stack } from 'react-bootstrap'; |
|
2 |
import { Button } from 'antd'; |
|
3 |
import { DownOutlined, TagOutlined } from '@ant-design/icons'; |
|
4 |
import { TagCategoryInfo } from '../../api'; |
|
5 |
import { 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 |
* Changes visibility of tags. |
|
21 |
*/ |
|
22 |
const changeTagsVisibility = () => { |
|
23 |
setVisibleTags(!visibleTags); |
|
24 |
}; |
|
25 |
|
|
26 |
return ( |
|
27 |
<Container> |
|
28 |
<Row> |
|
29 |
<Col> |
|
30 |
<Button |
|
31 |
type="text" |
|
32 |
icon={<DownOutlined />} |
|
33 |
onClick={changeTagsVisibility} |
|
34 |
className="w-100 text-start" |
|
35 |
> |
|
36 |
{props.category.name} |
|
37 |
</Button> |
|
38 |
</Col> |
|
39 |
<Col md="auto"> |
|
40 |
<TagOutlined style={{ color: props.category.color ?? 'black' }} /> |
|
41 |
</Col> |
|
42 |
</Row> |
|
43 |
{visibleTags && ( |
|
44 |
<Stack> |
|
45 |
{props.category.tags?.map((tag, index) => ( |
|
46 |
<TagItem tag={tag} key={index} /> |
|
47 |
))} |
|
48 |
</Stack> |
|
49 |
)} |
|
50 |
</Container> |
|
51 |
); |
|
52 |
} |
webapp/components/annotation/SubTagItem.tsx | ||
---|---|---|
1 |
import { SubTagInfo } from '../../api'; |
|
2 |
import { Container, Row } from 'react-bootstrap'; |
|
3 |
import { Button } from 'antd'; |
|
4 |
|
|
5 |
/** |
|
6 |
* Creates a single tag item in a tag panel. |
|
7 |
* @param props Properties should contain the tag. |
|
8 |
* @returns The item that represents the tag. |
|
9 |
*/ |
|
10 |
export function SubTagItem(props: { subTag: SubTagInfo }) { |
|
11 |
/** |
|
12 |
* Selects the sub tag. |
|
13 |
*/ |
|
14 |
const selectSubTag = () => {}; |
|
15 |
|
|
16 |
return ( |
|
17 |
<Container> |
|
18 |
<Row> |
|
19 |
<Button type="text" onClick={selectSubTag} className="w-100 text-start"> |
|
20 |
{props.subTag.name} |
|
21 |
</Button> |
|
22 |
</Row> |
|
23 |
</Container> |
|
24 |
); |
|
25 |
} |
webapp/components/annotation/TagItem.tsx | ||
---|---|---|
1 |
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 |
import { useState } from 'react'; |
|
6 |
import { SubTagItem } from './SubTagItem'; |
|
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 TagItem(props: { tag: TagInfo }) { |
|
14 |
/** |
|
15 |
* Should sub tags be visible? |
|
16 |
*/ |
|
17 |
const [visibleSubTags, setVisibleSubTags] = useState(false); |
|
18 |
|
|
19 |
/** |
|
20 |
* Changes visibility of sub tags. |
|
21 |
*/ |
|
22 |
const changeSubTagsVisibility = () => { |
|
23 |
setVisibleSubTags(!visibleSubTags); |
|
24 |
}; |
|
25 |
|
|
26 |
/** |
|
27 |
* Selects the tag. |
|
28 |
*/ |
|
29 |
const selectTag = () => {}; |
|
30 |
|
|
31 |
return ( |
|
32 |
<Container> |
|
33 |
<Row> |
|
34 |
<Col> |
|
35 |
{props.tag.subTags && ( |
|
36 |
<Button |
|
37 |
type="text" |
|
38 |
icon={<DownOutlined />} |
|
39 |
onClick={changeSubTagsVisibility} |
|
40 |
className="w-100 text-start" |
|
41 |
> |
|
42 |
{props.tag.name} |
|
43 |
</Button> |
|
44 |
)} |
|
45 |
{!props.tag.subTags && ( |
|
46 |
<Button |
|
47 |
type="text" |
|
48 |
onClick={selectTag} |
|
49 |
className="w-100 text-start" |
|
50 |
> |
|
51 |
{props.tag.name} |
|
52 |
</Button> |
|
53 |
)} |
|
54 |
</Col> |
|
55 |
<Col sm="auto"> |
|
56 |
<TagOutlined style={{ color: props.tag.color ?? 'black' }} /> |
|
57 |
</Col> |
|
58 |
</Row> |
|
59 |
{props.tag.subTags && visibleSubTags && ( |
|
60 |
<Stack> |
|
61 |
{props.tag.subTags?.map((subTag, index) => ( |
|
62 |
<SubTagItem subTag={subTag} key={index} /> |
|
63 |
))} |
|
64 |
</Stack> |
|
65 |
)} |
|
66 |
</Container> |
|
67 |
); |
|
68 |
} |
webapp/components/annotation/TagPanel.tsx | ||
---|---|---|
1 |
import { CategoryItem } from './CategoryItem'; |
|
2 |
import { TagCategoryInfo } from '../../api'; |
|
3 |
import { Stack } from 'react-bootstrap'; |
|
4 |
|
|
1 | 5 |
/** |
2 | 6 |
* Creates a panel in the annotation screen that contains a list of tag. |
3 | 7 |
* @returns Panel with a list of tags. |
4 | 8 |
*/ |
5 | 9 |
export function TagPanel() { |
10 |
const tags: TagCategoryInfo[] = [ |
|
11 |
{ |
|
12 |
name: 'kategorie 1', |
|
13 |
color: '#FF0000', |
|
14 |
tags: [ |
|
15 |
{ |
|
16 |
name: 'tag 1', |
|
17 |
color: '#CD5C5C', |
|
18 |
subTags: [{ name: 'subTag 1' }, { name: 'subTag 2' }], |
|
19 |
}, |
|
20 |
{ name: 'tag 2', color: '#F08080' }, |
|
21 |
], |
|
22 |
}, |
|
23 |
{ |
|
24 |
name: 'kategorie 2', |
|
25 |
color: '#0000FF', |
|
26 |
tags: [{ name: 'tag 3', color: '#3498DB' }], |
|
27 |
}, |
|
28 |
]; |
|
29 |
|
|
6 | 30 |
return ( |
7 | 31 |
<div> |
8 |
<p>Panel with a list of tags</p> |
|
32 |
<Stack> |
|
33 |
{tags.map((category, index) => ( |
|
34 |
<CategoryItem category={category} key={index} /> |
|
35 |
))} |
|
36 |
</Stack> |
|
9 | 37 |
</div> |
10 | 38 |
); |
11 | 39 |
} |
Také k dispozici: Unified diff
Implemented tag panel
Implemented tag panel and all its items