Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 2c9bdf18

Přidáno uživatelem Dominik Poch před asi 2 roky(ů)

Upgraded visual of the tag tree

Zobrazit rozdíly:

webapp/components/annotation/TagItem.tsx
1
import { Col, Container, Row, Stack } from 'react-bootstrap';
1
import { Container, Row, Stack } from 'react-bootstrap';
2 2
import { TagInfo } from '../../api';
3 3
import { Button } from 'antd';
4
import { DownOutlined, TagOutlined } from '@ant-design/icons';
5
import { useContext, useState } from 'react';
4
import { DownOutlined, TagOutlined, UpOutlined } from '@ant-design/icons';
5
import React, { useContext, useState } from 'react';
6 6
import { SubTagItem } from './SubTagItem';
7 7
import { TagCategoryContext } from '../../contexts/TagCategoryContext';
8 8

  
......
22 22
     */
23 23
    const { selectTag } = useContext(TagCategoryContext);
24 24

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

  
25 30
    /**
26 31
     * Changes visibility of sub tags.
27 32
     */
28 33
    const changeSubTagsVisibility = () => {
34
        setButtonIcon(visibleSubTags ? <DownOutlined /> : <UpOutlined />);
29 35
        setVisibleSubTags(!visibleSubTags);
30 36
    };
31 37

  
......
36 42
        selectTag(props.tag, null);
37 43
    };
38 44

  
45
    /**
46
     * Does tag have sub tags?
47
     */
48
    const hasSubTags = (props.tag.subTags?.length ?? 0) > 0;
49

  
39 50
    return (
40 51
        <Container>
41 52
            <Row>
42
                <Col>
43
                    {props.tag.subTags && (
44
                        <Button
45
                            type="text"
46
                            icon={<DownOutlined />}
47
                            onClick={changeSubTagsVisibility}
48
                            className="w-100 text-start"
49
                        >
50
                            {props.tag.name}
51
                        </Button>
52
                    )}
53
                    {!props.tag.subTags && (
54
                        <Button
55
                            type="text"
56
                            onClick={onSelectTag}
57
                            className="w-100 text-start"
58
                        >
59
                            {props.tag.name}
60
                        </Button>
61
                    )}
62
                </Col>
63
                <Col sm="auto">
64
                    <TagOutlined style={{ color: props.tag.color ?? 'black' }} />
65
                </Col>
53
                {hasSubTags && (
54
                    <Button
55
                        icon={buttonIcon}
56
                        onClick={changeSubTagsVisibility}
57
                        className="w-100 text-start rounded"
58
                    >
59
                        {props.tag.name}
60
                        <TagOutlined style={{ color: props.tag.color ?? 'black' }} />
61
                    </Button>
62
                )}
63
                {!hasSubTags && (
64
                    <Button onClick={onSelectTag} className="w-100 text-start rounded">
65
                        {props.tag.name}
66
                        <TagOutlined style={{ color: props.tag.color ?? 'black' }} />
67
                    </Button>
68
                )}
66 69
            </Row>
67
            {props.tag.subTags && visibleSubTags && (
68
                <Stack>
70
            {visibleSubTags && (
71
                <Stack gap={2} className="mt-2">
69 72
                    {props.tag.subTags?.map((subTag, index) => (
70 73
                        <SubTagItem tag={props.tag} subTag={subTag} key={index} />
71 74
                    ))}

Také k dispozici: Unified diff