Projekt

Obecné

Profil

Stáhnout (1.03 KB) Statistiky
| Větev: | Tag: | Revize:
1
import { ReactNode } from 'react';
2
import {
3
    BORDER_RADIUS,
4
    COLOR_ERROR,
5
    COLOR_GENERAL,
6
    COLOR_SUCCESS,
7
    COLOR_WARNING,
8
} from '../../constants';
9

    
10
export enum BadgeStyle {
11
    GENERAL,
12
    SUCCESS,
13
    WARNING,
14
    ERROR,
15
}
16

    
17
export interface BadgeProps {
18
    style: BadgeStyle;
19
    children: ReactNode | ReactNode[];
20
}
21

    
22
export function ABadge(props: BadgeProps) {
23
    function getBackgroundColor() {
24
        switch (props.style) {
25
            case BadgeStyle.GENERAL:
26
                return COLOR_GENERAL;
27
            case BadgeStyle.ERROR:
28
                return COLOR_ERROR;
29
            case BadgeStyle.SUCCESS:
30
                return COLOR_SUCCESS;
31
            case BadgeStyle.WARNING:
32
                return COLOR_WARNING;
33
        }
34
    }
35

    
36
    return (
37
        <span
38
            style={{
39
                backgroundColor: getBackgroundColor(),
40
                color: 'white',
41
                padding: '5px',
42
                borderRadius: BORDER_RADIUS,
43
            }}
44
        >
45
            {props.children}
46
        </span>
47
    );
48
}
(1-1/2)