index.js
36 lines
| 1 | import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; |
| 2 | import './style.scss'; |
| 3 | |
| 4 | const Button = ({icon, children, onClick, href, type, ...rest}) => { |
| 5 | const handleHrefClick = (e) => { |
| 6 | e.preventDefault(); |
| 7 | window.parent.location = href; |
| 8 | }; |
| 9 | |
| 10 | if (href) { |
| 11 | return ( |
| 12 | <a |
| 13 | className="give-donor-dashboard-button give-donor-dashboard-button--primary" |
| 14 | onClick={(e) => handleHrefClick(e)} |
| 15 | href={href} |
| 16 | {...rest} |
| 17 | > |
| 18 | {children} |
| 19 | {icon && <FontAwesomeIcon icon={icon} />} |
| 20 | </a> |
| 21 | ); |
| 22 | } |
| 23 | return ( |
| 24 | <button |
| 25 | className="give-donor-dashboard-button give-donor-dashboard-button--primary" |
| 26 | onClick={onClick ? () => onClick() : null} |
| 27 | type={type} |
| 28 | {...rest} |
| 29 | > |
| 30 | {children} |
| 31 | {icon && <FontAwesomeIcon icon={icon} />} |
| 32 | </button> |
| 33 | ); |
| 34 | }; |
| 35 | export default Button; |
| 36 |