import * as Icons from '@heroicons/react/24/outline' import { useMemo } from 'react' export interface StyledButtonProps extends React.HTMLAttributes { children: React.ReactNode // icon should be one of the HeroIcon names, e.g. ArrowTopRightOnSquareIcon icon?: keyof typeof Icons disabled?: boolean variant?: 'primary' | 'secondary' | 'danger' | 'action' loading?: boolean } const StyledButton: React.FC = ({ children, icon, variant = 'primary', loading = false, ...props }) => { const isDisabled = useMemo(() => { return props.disabled || loading }, [props.disabled, loading]) const IconComponent = () => { if (!icon) return null const Icon = Icons[icon] return Icon ? : null } const getBgColors = () => { // if primary, use desert-green if (variant === 'primary') { return 'bg-desert-green hover:bg-desert-green-light text-white' } // if secondary, use outlined styles if (variant === 'secondary') { return 'bg-transparent border border-desert-green text-desert-green hover:bg-desert-green-light' } // if danger, use red styles if (variant === 'danger') { return 'bg-red-600 hover:bg-red-700 text-white' } // if action, use orange styles if (variant === 'action') { return 'bg-desert-orange hover:bg-desert-orange-light text-white' } } const onClickHandler = (e: React.MouseEvent) => { if (isDisabled) { e.preventDefault() return } props.onClick?.(e) } return ( ) } export default StyledButton