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/CategoryItem.tsx
1 1
import { Col, Container, Row, Stack } from 'react-bootstrap';
2 2
import { Button } from 'antd';
3
import { DownOutlined, TagOutlined } from '@ant-design/icons';
3
import { DownOutlined, TagOutlined, UpOutlined } from '@ant-design/icons';
4 4
import { TagCategoryInfo } from '../../api';
5
import { useState } from 'react';
5
import React, { useState } from 'react';
6 6
import { TagItem } from './TagItem';
7 7

  
8 8
/**
......
16 16
     */
17 17
    const [visibleTags, setVisibleTags] = useState(false);
18 18

  
19
    /**
20
     * Button icon.
21
     */
22
    const [buttonIcon, setButtonIcon] = useState<React.ReactNode>(<DownOutlined />);
23

  
19 24
    /**
20 25
     * Changes visibility of tags.
21 26
     */
22 27
    const changeTagsVisibility = () => {
28
        setButtonIcon(visibleTags ? <DownOutlined /> : <UpOutlined />);
23 29
        setVisibleTags(!visibleTags);
24 30
    };
25 31

  
26 32
    return (
27
        <Container>
33
        <Container className="shadow-sm rounded">
28 34
            <Row>
29
                <Col>
30
                    <Button
31
                        type="text"
32
                        icon={<DownOutlined />}
33
                        onClick={changeTagsVisibility}
34
                        className="w-100 text-start"
35
                    >
36
                        {props.category.name}
37
                    </Button>
38
                </Col>
39
                <Col md="auto">
40
                    <TagOutlined style={{ color: props.category.color ?? 'black' }} />
41
                </Col>
35
                <Button
36
                    type="text"
37
                    icon={buttonIcon}
38
                    onClick={changeTagsVisibility}
39
                    className="w-100 text-start rounded"
40
                >
41
                    {props.category.name}
42
                </Button>
42 43
            </Row>
43 44
            {visibleTags && (
44
                <Stack>
45
                <Stack gap={2} className="mt-1 mb-2">
45 46
                    {props.category.tags?.map((tag, index) => (
46 47
                        <TagItem tag={tag} key={index} />
47 48
                    ))}
webapp/components/annotation/SubTagItem.tsx
25 25
    return (
26 26
        <Container>
27 27
            <Row>
28
                <Button type="text" onClick={onSelectSubTag} className="w-100 text-start">
28
                <Button onClick={onSelectSubTag} className="w-100 text-start rounded">
29 29
                    {props.subTag.name}
30 30
                </Button>
31 31
            </Row>
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
                    ))}
webapp/components/annotation/TagPanel.tsx
13 13

  
14 14
    return (
15 15
        <div>
16
            <Stack>
16
            <Stack gap={1}>
17 17
                {tagCategories?.map((category, index) => (
18 18
                    <CategoryItem category={category} key={index} />
19 19
                ))}
webapp/styles/Annotation.module.scss
3 3

  
4 4
    grid:
5 5
        [main-start] 'tags document annotations' [main-end]
6
        / 1fr 3fr 1fr;
6
        / max-content 3fr minmax(250px, 1fr);
7 7

  
8 8
    width:100%;
9 9
    height:100%;

Také k dispozici: Unified diff