2023-07-13 07:22:08 -04:00
|
|
|
import { Link } from 'react-router-dom'
|
|
|
|
import { ActionIcon, ActionIconProps } from './ActionIcon'
|
2023-07-27 18:59:40 -04:00
|
|
|
import React from 'react'
|
2023-07-13 07:22:08 -04:00
|
|
|
|
|
|
|
interface ActionButtonProps extends React.PropsWithChildren {
|
|
|
|
icon?: ActionIconProps
|
|
|
|
className?: string
|
|
|
|
onClick?: () => void
|
|
|
|
to?: string
|
2023-07-27 18:59:40 -04:00
|
|
|
Element?:
|
|
|
|
| 'button'
|
|
|
|
| 'link'
|
|
|
|
| React.ComponentType<React.HTMLAttributes<HTMLButtonElement>>
|
2023-07-13 07:22:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export const ActionButton = ({
|
|
|
|
icon,
|
|
|
|
className,
|
|
|
|
onClick,
|
|
|
|
to = '/',
|
2023-07-27 18:59:40 -04:00
|
|
|
Element = 'button',
|
2023-07-13 07:22:08 -04:00
|
|
|
children,
|
|
|
|
}: ActionButtonProps) => {
|
2023-07-31 06:33:10 -04:00
|
|
|
const classNames = `group mono text-base flex items-center gap-2 rounded-sm border border-chalkboard-40 dark:border-chalkboard-60 hover:border-liquid-40 p-[3px] ${
|
2023-07-13 07:22:08 -04:00
|
|
|
icon ? 'pr-2' : 'px-2'
|
|
|
|
} ${className}`
|
|
|
|
|
2023-07-27 18:59:40 -04:00
|
|
|
if (Element === 'button') {
|
|
|
|
return (
|
|
|
|
<button onClick={onClick} className={classNames}>
|
|
|
|
{icon && <ActionIcon {...icon} />}
|
|
|
|
{children}
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
} else if (Element === 'link') {
|
|
|
|
return (
|
|
|
|
<Link to={to} className={classNames}>
|
|
|
|
{icon && <ActionIcon {...icon} />}
|
|
|
|
{children}
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<Element onClick={onClick} className={classNames}>
|
|
|
|
{icon && <ActionIcon {...icon} />}
|
|
|
|
{children}
|
|
|
|
</Element>
|
|
|
|
)
|
|
|
|
}
|
2023-07-13 07:22:08 -04:00
|
|
|
}
|