Projekt

Obecné

Profil

Stáhnout (2.06 KB) Statistiky
| Větev: | Tag: | Revize:
1
import { Col, Container, Row, Stack } from 'react-bootstrap';
2
import { Button, Tooltip } from 'antd';
3
import {
4
    DownOutlined,
5
    QuestionCircleOutlined,
6
    TagOutlined,
7
    UpOutlined,
8
} from '@ant-design/icons';
9
import { TagCategoryInfo } from '../../api';
10
import React, { useState } from 'react';
11
import { TagItem } from './TagItem';
12

    
13
/**
14
 * Creates a single item for a category in a tag panel.
15
 * @param props Properties should contain a category.
16
 * @returns Item that represents the category.
17
 */
18
export function CategoryItem(props: { category: TagCategoryInfo }) {
19
    /**
20
     * Should tags in this category be visible?
21
     */
22
    const [visibleTags, setVisibleTags] = useState(false);
23

    
24
    /**
25
     * Button icon.
26
     */
27
    const [buttonIcon, setButtonIcon] = useState<React.ReactNode>(<DownOutlined />);
28

    
29
    /**
30
     * Changes visibility of tags.
31
     */
32
    const changeTagsVisibility = () => {
33
        setButtonIcon(visibleTags ? <DownOutlined /> : <UpOutlined />);
34
        setVisibleTags(!visibleTags);
35
    };
36

    
37
    return (
38
        <Container className="shadow-sm rounded">
39
            <Row>
40
                <Button
41
                    type="text"
42
                    icon={buttonIcon}
43
                    onClick={changeTagsVisibility}
44
                    className="w-100 text-start rounded"
45
                >
46
                    {props.category.name}
47
                    {props.category.description && props.category.description !== '' && (
48
                        <Tooltip
49
                            title={props.category.description}
50
                            key={props.category.description}
51
                        >
52
                            <QuestionCircleOutlined />
53
                        </Tooltip>
54
                    )}
55
                </Button>
56
            </Row>
57
            {visibleTags && (
58
                <Stack gap={2} className="mt-1 mb-2">
59
                    {props.category.tags?.map((tag, index) => (
60
                        <TagItem tag={tag} key={index} />
61
                    ))}
62
                </Stack>
63
            )}
64
        </Container>
65
    );
66
}
(3-3/7)