Files
modeling-app/src/components/ActionButton.tsx

51 lines
1.3 KiB
TypeScript
Raw Normal View History

import { Link } from 'react-router-dom'
import { ActionIcon, ActionIconProps } from './ActionIcon'
2023-07-27 18:59:40 -04:00
import React from 'react'
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>>
}
export const ActionButton = ({
icon,
className,
onClick,
to = '/',
2023-07-27 18:59:40 -04:00
Element = 'button',
children,
}: ActionButtonProps) => {
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 dark:hover:bg-chalkboard-90 p-[3px] ${
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>
)
}
}