index.tsx
54 lines
| 1 | import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; |
| 2 | import cx from 'classnames'; |
| 3 | |
| 4 | import './style.scss'; |
| 5 | |
| 6 | type ButtonProps = { |
| 7 | classnames?: string; |
| 8 | icon?: any; |
| 9 | children: React.ReactNode; |
| 10 | onClick?: () => void; |
| 11 | href?: string; |
| 12 | type?: 'button' | 'submit' | 'reset'; |
| 13 | variant?: boolean; |
| 14 | disabled?: boolean; |
| 15 | }; |
| 16 | |
| 17 | const Button = ({icon, children, onClick, href, type, variant,classnames, ...rest}: ButtonProps) => { |
| 18 | const handleHrefClick = (e) => { |
| 19 | e.preventDefault(); |
| 20 | window.parent.location = href; |
| 21 | }; |
| 22 | |
| 23 | if (href) { |
| 24 | return ( |
| 25 | <a |
| 26 | className="give-donor-dashboard-button give-donor-dashboard-button--primary" |
| 27 | onClick={(e) => handleHrefClick(e)} |
| 28 | href={href} |
| 29 | {...rest} |
| 30 | > |
| 31 | <span> |
| 32 | {children} |
| 33 | {icon && <FontAwesomeIcon icon={icon} />} |
| 34 | </span> |
| 35 | </a> |
| 36 | ); |
| 37 | } |
| 38 | return ( |
| 39 | <button |
| 40 | className={cx('give-donor-dashboard-button', classnames, { |
| 41 | ['give-donor-dashboard-button--primary']: !variant, |
| 42 | ['give-donor-dashboard-button--variant']: variant, |
| 43 | })} |
| 44 | onClick={onClick ? () => onClick() : null} |
| 45 | type={type} |
| 46 | {...rest} |
| 47 | > |
| 48 | <span>{children}</span> |
| 49 | {icon && <FontAwesomeIcon icon={icon} />} |
| 50 | </button> |
| 51 | ); |
| 52 | }; |
| 53 | export default Button; |
| 54 |