Projekt

Obecné

Profil

Stáhnout (2.46 KB) Statistiky
| Větev: | Tag: | Revize:
1 ed01528f Dominik Poch
import { Col, Container, Row, Stack } from 'react-bootstrap';
2 a44aa67e Jaroslav Hrubý
import { Button, Tooltip } from 'antd';
3 ed01528f Dominik Poch
import { TagCategoryInfo } from '../../api';
4 2c9bdf18 Dominik Poch
import React, { useState } from 'react';
5 ed01528f Dominik Poch
import { TagItem } from './TagItem';
6
7 fa93df26 Dominik Poch
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 ed01528f Dominik Poch
/**
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 2c9bdf18 Dominik Poch
    /**
23
     * Button icon.
24
     */
25 fa93df26 Dominik Poch
    const [buttonIcon, setButtonIcon] = useState<React.ReactNode>(
26
        <FontAwesomeIcon icon={faAngleDown} className={styles.iconLeft} />
27
    );
28 2c9bdf18 Dominik Poch
29 ed01528f Dominik Poch
    /**
30
     * Changes visibility of tags.
31
     */
32
    const changeTagsVisibility = () => {
33 fa93df26 Dominik Poch
        setButtonIcon(
34
            visibleTags ? (
35
                <FontAwesomeIcon icon={faAngleDown} className={styles.iconLeft} />
36
            ) : (
37
                <FontAwesomeIcon icon={faAngleUp} className={styles.iconLeft} />
38
            )
39
        );
40 ed01528f Dominik Poch
        setVisibleTags(!visibleTags);
41
    };
42
43
    return (
44 2c9bdf18 Dominik Poch
        <Container className="shadow-sm rounded">
45 ed01528f Dominik Poch
            <Row>
46 2c9bdf18 Dominik Poch
                <Button
47
                    type="text"
48
                    icon={buttonIcon}
49
                    onClick={changeTagsVisibility}
50
                    className="w-100 text-start rounded"
51
                >
52
                    {props.category.name}
53 a44aa67e Jaroslav Hrubý
                    {props.category.description && props.category.description !== '' && (
54
                        <Tooltip
55
                            title={props.category.description}
56
                            key={props.category.description}
57
                        >
58 fa93df26 Dominik Poch
                            <FontAwesomeIcon icon={faCircleQuestion} />
59 a44aa67e Jaroslav Hrubý
                        </Tooltip>
60
                    )}
61 2c9bdf18 Dominik Poch
                </Button>
62 ed01528f Dominik Poch
            </Row>
63
            {visibleTags && (
64 2c9bdf18 Dominik Poch
                <Stack gap={2} className="mt-1 mb-2">
65 ed01528f Dominik Poch
                    {props.category.tags?.map((tag, index) => (
66
                        <TagItem tag={tag} key={index} />
67
                    ))}
68
                </Stack>
69
            )}
70
        </Container>
71
    );
72
}