/
button.tsx
53 lines (48 loc) · 1.22 KB
/
button.tsx
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
/*
* Wazuh app - React component for base button that wraps the EuiButton components
* Copyright (C) 2015-2022 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import React from 'react';
import {
EuiButton,
EuiButtonEmpty,
EuiButtonIcon,
EuiLink,
EuiToolTip,
EuiSwitch,
} from '@elastic/eui';
enum WzButtonType {
default = 'default',
empty = 'empty',
icon = 'icon',
link = 'link',
switch = 'switch',
}
interface WzButtonProps {
buttonType?: WzButtonType;
tooltip?: any;
rest?: any;
}
const WzButtons: { [key in WzButtonType]: React.FunctionComponent } = {
default: EuiButton,
empty: EuiButtonEmpty,
icon: EuiButtonIcon,
link: EuiLink,
switch: EuiSwitch,
};
export const WzButton = ({
buttonType = WzButtonType.default,
tooltip,
...rest
}: WzButtonProps) => {
const Button = WzButtons[buttonType];
const button = <Button {...rest} />;
return tooltip ? <EuiToolTip {...tooltip}>{button}</EuiToolTip> : button;
};