forked from DhanushNehru/ToolJet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppButton.jsx
More file actions
94 lines (88 loc) · 2.48 KB
/
Copy pathAppButton.jsx
File metadata and controls
94 lines (88 loc) · 2.48 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React from 'react';
import './AppButton.scss';
import SolidIcon from '../Icon/solidIcons/index';
import { Spinner } from 'react-bootstrap';
export const ButtonBase = function ButtonBase(props) {
const mapBaseSize = {
lg: 'tj-large-btn',
md: 'tj-medium-btn',
sm: 'tj-small-btn',
xs: 'tj-extra-small-btn',
};
const {
className,
size = 'lg', // specify size otherwise large button dimesnions will be applied with min width
as = 'button', // render it as a button or an anchor.
children,
disabled,
leftIcon,
rightIcon,
backgroundColor,
type,
isLoading,
fill,
iconCustomClass,
iconWidth,
customStyles = {},
iconViewBox,
...restProps
} = props;
const isAnchor = (!!restProps.href || as === 'a') && !disabled;
const Element = as ? as : isAnchor ? 'a' : 'button';
return (
<Element
{...restProps}
className={`tj-base-btn ${mapBaseSize[size]} ${className}`}
disabled={disabled}
style={
({
backgroundColor: backgroundColor && backgroundColor,
},
{ ...restProps.style, ...customStyles })
}
type={isAnchor ? undefined : type || 'button'}
>
{!isLoading && leftIcon && (
<span className="tj-btn-left-icon">
{
<SolidIcon
fill={fill}
className={iconCustomClass}
name={leftIcon}
width={iconWidth}
viewBox={iconViewBox}
/>
}
</span>
)}
{isLoading ? (
<div className="spinner">
<Spinner />
</div>
) : (
children
)}
{!isLoading && rightIcon && (
<span className="tj-btn-right-icon">
{<SolidIcon className={iconCustomClass} fill={fill} name={rightIcon} width={iconWidth} />}
</span>
)}
</Element>
);
};
export const ButtonSolid = function ButtonSolid(props) {
const mapVariant = {
primary: 'tj-primary-btn',
ghostBlue: 'tj-ghost-blue-btn',
ghostBlack: 'tj-ghost-black-btn',
secondary: 'tj-secondary-btn',
tertiary: 'tj-tertiary-btn',
dangerPrimary: 'tj-primary-danger-btn',
dangerSecondary: 'tj-secondary-danger-btn',
dangerTertiary: 'tj-tertiary-danger-btn',
dangerGhost: 'tj-ghost-danger-btn',
zBlack: 'tj-zBlack-btn',
};
const { variant = 'primary', className, ...restProps } = props;
return <ButtonBase {...restProps} className={`${mapVariant[variant]} ${className && className}`} />;
};