Projekt

Obecné

Profil

Stáhnout (2.08 KB) Statistiky
| Větev: | Tag: | Revize:
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
}
(6-6/7)