-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathButton.jsx
More file actions
114 lines (103 loc) · 2.49 KB
/
Copy pathButton.jsx
File metadata and controls
114 lines (103 loc) · 2.49 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import React from "react";
import { confirmAlert } from "react-confirm-alert";
import "react-confirm-alert/src/react-confirm-alert.css";
import { Link } from "react-router-dom";
import classNames from "classnames";
import "../../assets/stylesheets/Button.scss";
import { useTranslation } from "react-i18next";
const Button = (props) => {
const {
className,
onClickHandler,
ButtonIcon,
buttonImage,
buttonImageAltText,
buttonText,
buttonOuter,
buttonOuterClassName,
buttonRef,
disabled,
confirmText,
href,
text,
title,
label,
buttonIconPosition = "left",
} = props;
const { t } = useTranslation();
const buttonClass = classNames("btn", className, {
"btn--svg-only": !buttonText,
});
const onButtonClick = (e) => {
if (!confirmText) {
onClickHandler(e);
return;
}
confirmAlert({
message: confirmText,
buttons: [
{
label: t("button.yes"),
onClick: () => onClickHandler(e),
},
{
label: t("button.no"),
},
],
});
};
const onKeyDown = (e) => {
e.stopPropagation();
};
const button = href ? (
<Link
ref={buttonRef}
className={buttonClass}
disabled={disabled}
aria-label={label}
title={title}
to={href}
onClick={buttonOuter ? null : onButtonClick}
onKeyDown={onKeyDown}
>
{buttonImage && (
<img src={buttonImage} alt={buttonImageAltText} crossOrigin="true" />
)}
{ButtonIcon && buttonIconPosition === "left" && <ButtonIcon />}
{text && <span>{text}</span>}
{ButtonIcon && buttonIconPosition === "right" && <ButtonIcon />}
</Link>
) : (
<button
ref={buttonRef}
className={buttonClass}
disabled={disabled}
aria-label={label}
title={title}
text={text}
onClick={buttonOuter ? null : onButtonClick}
onKeyDown={onKeyDown}
>
{buttonImage && (
<img src={buttonImage} alt={buttonImageAltText} crossOrigin="true" />
)}
{ButtonIcon && buttonIconPosition === "left" && <ButtonIcon />}
{buttonText && <span>{buttonText}</span>}
{ButtonIcon && buttonIconPosition === "right" && <ButtonIcon />}
</button>
);
if (buttonOuter) {
return (
<div
className={classNames("btn-outer", {
buttonOuterClassName,
})}
onClick={onButtonClick}
>
{button}
</div>
);
}
return button;
};
export default Button;