Projekt

Obecné

Profil

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