Projekt

Obecné

Profil

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

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

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

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

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