2022-04-09 20:48:19 -04:00
|
|
|
import styles from "./button.module.css"
|
|
|
|
import { forwardRef, Ref } from "react"
|
2022-03-22 23:06:15 -04:00
|
|
|
|
|
|
|
type Props = React.HTMLProps<HTMLButtonElement> & {
|
2022-11-16 01:52:25 -05:00
|
|
|
children?: React.ReactNode
|
2022-04-09 20:48:19 -04:00
|
|
|
buttonType?: "primary" | "secondary"
|
|
|
|
className?: string
|
|
|
|
onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void
|
2022-11-08 03:23:28 -05:00
|
|
|
iconRight?: React.ReactNode
|
2022-11-15 23:50:54 -05:00
|
|
|
iconLeft?: React.ReactNode
|
2022-11-16 01:52:25 -05:00
|
|
|
height?: string | number
|
|
|
|
width?: string | number
|
|
|
|
padding?: string | number
|
|
|
|
margin?: string | number
|
2022-03-22 23:06:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line react/display-name
|
|
|
|
const Button = forwardRef<HTMLButtonElement, Props>(
|
2022-04-09 20:48:19 -04:00
|
|
|
(
|
|
|
|
{
|
|
|
|
children,
|
|
|
|
onClick,
|
|
|
|
className,
|
|
|
|
buttonType = "primary",
|
|
|
|
type = "button",
|
|
|
|
disabled = false,
|
2022-11-08 03:23:28 -05:00
|
|
|
iconRight,
|
2022-11-15 23:50:54 -05:00
|
|
|
iconLeft,
|
2022-11-16 01:52:25 -05:00
|
|
|
height,
|
|
|
|
width,
|
|
|
|
padding,
|
|
|
|
margin,
|
2022-04-09 20:48:19 -04:00
|
|
|
...props
|
|
|
|
},
|
|
|
|
ref
|
|
|
|
) => {
|
|
|
|
return (
|
|
|
|
<button
|
|
|
|
ref={ref}
|
2022-11-15 23:50:54 -05:00
|
|
|
className={`${styles.button} ${styles[type]} ${className || ""}`}
|
2022-04-09 20:48:19 -04:00
|
|
|
disabled={disabled}
|
|
|
|
onClick={onClick}
|
2022-11-16 01:52:25 -05:00
|
|
|
style={{ height, width, margin, padding }}
|
2022-04-09 20:48:19 -04:00
|
|
|
{...props}
|
|
|
|
>
|
2022-11-16 01:52:25 -05:00
|
|
|
{children && iconLeft && (
|
2022-11-15 23:50:54 -05:00
|
|
|
<span className={`${styles.icon} ${styles.iconLeft}`}>
|
|
|
|
{iconLeft}
|
|
|
|
</span>
|
|
|
|
)}
|
2022-11-16 01:52:25 -05:00
|
|
|
{children ? children : <span className={`${styles.icon}`}>{iconLeft || iconRight}</span>}
|
|
|
|
{children && iconRight && (
|
2022-11-08 03:23:28 -05:00
|
|
|
<span className={`${styles.icon} ${styles.iconRight}`}>
|
|
|
|
{iconRight}
|
|
|
|
</span>
|
|
|
|
)}
|
2022-04-09 20:48:19 -04:00
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|
2022-03-22 23:06:15 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
export default Button
|