File size: 1,056 Bytes
1982de5
 
 
 
 
 
 
 
 
 
603afa9
1982de5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
603afa9
1982de5
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import {ComponentChildren, JSX} from 'preact';
import cn from 'classnames';
import style from "./style.module.scss";

export function Button(props: {

    loading?: boolean;

    onClick?: () => void;

    className?: string;

    secondary?: boolean;

    disabled?: boolean;

    title?: string;

    children: ComponentChildren;

}) {
    const disabled = props.disabled || props.loading;
    const buttonClass = cn(style.btn, {[style.secondary]: props.secondary}, 'button', props.className, {[style.disabled]:disabled});

    let spinner: JSX.Element = undefined;

    if (props.loading) {
        spinner = <span className={style.spinner}/>
    }

    return (
        <button

            type="button"

            onClick={() => {

                if (!disabled) {

                    props.onClick()

                }

            }}

            className={buttonClass}

            disabled={disabled}

            title={props.title}

        >

            {spinner}

            {props.children}

        </button>
    );
}