-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathControlButton.tsx
More file actions
72 lines (66 loc) · 1.55 KB
/
ControlButton.tsx
File metadata and controls
72 lines (66 loc) · 1.55 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
import {
AnchorButton,
Button,
Icon,
Intent,
type IconName
} from '@blueprintjs/core';
import React from 'react';
type ButtonOptions = {
className: string;
fullWidth: boolean;
iconColor?: string;
iconOnRight: boolean;
intent: Intent;
minimal: boolean;
type?: 'button' | 'reset' | 'submit';
};
type ControlButtonProps = {
label?: string;
icon?: IconName;
onClick?: () => void;
options?: Partial<ButtonOptions>;
isDisabled?: boolean;
};
const defaultOptions = {
className: '',
fullWidth: false,
iconOnRight: false,
intent: Intent.NONE,
minimal: true
};
const ControlButton: React.FC<ControlButtonProps> = ({
label = '',
icon,
onClick,
options = {},
isDisabled = false
}) => {
const buttonOptions: ButtonOptions = {
...defaultOptions,
...options
};
const iconElement = icon && (
<Icon icon={icon} color={buttonOptions.iconColor} />
);
// Refer to #2417 and #2422 for why we conditionally
// set the button component. See also:
// https://blueprintjs.com/docs/#core/components/button
const ButtonComponent = isDisabled ? AnchorButton : Button;
return (
<ButtonComponent
disabled={isDisabled}
fill={buttonOptions.fullWidth}
intent={buttonOptions.intent}
minimal={buttonOptions.minimal}
className={buttonOptions.className}
type={buttonOptions.type}
onClick={onClick}
icon={!buttonOptions.iconOnRight && iconElement}
rightIcon={buttonOptions.iconOnRight && iconElement}
>
{label}
</ButtonComponent>
);
};
export default ControlButton;