Projekt

Obecné

Profil

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

    
8
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
9
import { faAngleDown, faAngleUp } from '@fortawesome/free-solid-svg-icons';
10
import { faCircleQuestion } from '@fortawesome/free-regular-svg-icons';
11
import styles from '/styles/Icon.module.scss';
12
/**
13
 * Creates a single item for a category in a tag panel.
14
 * @param props Properties should contain a category.
15
 * @returns Item that represents the category.
16
 */
17
export function CategoryItem(props: { category: TagCategoryInfo }) {
18
    /**
19
     * Should tags in this category be visible?
20
     */
21
    const [visibleTags, setVisibleTags] = useState(false);
22

    
23
    /**
24
     * Button icon.
25
     */
26
    const [buttonIcon, setButtonIcon] = useState<React.ReactNode>(
27
        <FontAwesomeIcon icon={faAngleDown} className={styles.iconLeft} />
28
    );
29

    
30
    /**
31
     * Changes visibility of tags.
32
     */
33
    const changeTagsVisibility = () => {
34
        setButtonIcon(
35
            visibleTags ? (
36
                <FontAwesomeIcon icon={faAngleDown} className={styles.iconLeft} />
37
            ) : (
38
                <FontAwesomeIcon icon={faAngleUp} className={styles.iconLeft} />
39
            )
40
        );
41
        setVisibleTags(!visibleTags);
42
    };
43

    
44
    return (
45
        <Container className="shadow-sm rounded">
46
            <Row>
47
                <Button
48
                    type="text"
49
                    icon={buttonIcon}
50
                    onClick={changeTagsVisibility}
51
                    className="w-100 text-start rounded"
52
                >
53
                    {props.category.name}
54
                    {props.category.description && props.category.description !== '' && (
55
                        <Tooltip
56
                            title={props.category.description}
57
                            key={props.category.description}
58
                        >
59
                            <FontAwesomeIcon icon={faCircleQuestion} />
60
                        </Tooltip>
61
                    )}
62
                </Button>
63
            </Row>
64
            {visibleTags && (
65
                <Stack gap={2} className="mt-1 mb-2">
66
                    {props.category.tags?.map((tag, index) => (
67
                        <TagItem tag={tag} key={index} />
68
                    ))}
69
                </Stack>
70
            )}
71
        </Container>
72
    );
73
}
(4-4/8)