2022-01-07 21:21:38 +01:00
|
|
|
import { forwardRef } from 'react'
|
2021-10-24 05:48:06 +02:00
|
|
|
import classNames from 'classnames'
|
|
|
|
|
2022-01-07 21:21:38 +01:00
|
|
|
const className =
|
2022-03-05 18:22:30 +01:00
|
|
|
'py-2 px-6 font-paragraph rounded-lg bg-transparent border hover:text-white dark:hover:text-black fill-current stroke-current transform transition-colors duration-300 ease-in-out focus:outline-none focus:text-white dark:focus:text-black'
|
2022-01-07 21:21:38 +01:00
|
|
|
|
2022-03-05 18:22:30 +01:00
|
|
|
const classNameGreen =
|
|
|
|
'border-green-800 dark:border-green-400 text-green-800 dark:text-green-400 hover:bg-green-800 focus:bg-green-800 dark:focus:bg-green-400 dark:hover:bg-green-400'
|
|
|
|
|
|
|
|
const classNameRed =
|
|
|
|
'border-red-800 dark:border-red-400 text-red-800 dark:text-red-400 hover:bg-red-800 focus:bg-red-800 dark:focus:bg-red-400 dark:hover:bg-red-400'
|
|
|
|
|
|
|
|
export type ButtonColor = 'green' | 'red'
|
|
|
|
|
|
|
|
export interface ButtonLinkProps extends React.ComponentPropsWithRef<'a'> {
|
|
|
|
color?: ButtonColor
|
|
|
|
}
|
2022-01-07 21:21:38 +01:00
|
|
|
|
|
|
|
export const ButtonLink = forwardRef<HTMLAnchorElement, ButtonLinkProps>(
|
|
|
|
(props, reference) => {
|
2022-03-05 18:22:30 +01:00
|
|
|
const {
|
|
|
|
children,
|
|
|
|
className: givenClassName,
|
|
|
|
color = 'green',
|
|
|
|
...rest
|
|
|
|
} = props
|
2022-01-07 21:21:38 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<a
|
|
|
|
ref={reference}
|
2022-03-05 18:22:30 +01:00
|
|
|
className={classNames(
|
|
|
|
className,
|
|
|
|
{
|
|
|
|
[classNameGreen]: color === 'green',
|
|
|
|
[classNameRed]: color === 'red'
|
|
|
|
},
|
|
|
|
givenClassName
|
|
|
|
)}
|
2022-01-07 21:21:38 +01:00
|
|
|
{...rest}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</a>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
ButtonLink.displayName = 'ButtonLink'
|
|
|
|
|
2022-03-05 18:22:30 +01:00
|
|
|
export interface ButtonProps extends React.ComponentPropsWithoutRef<'button'> {
|
|
|
|
color?: ButtonColor
|
|
|
|
}
|
2021-10-24 05:48:06 +02:00
|
|
|
|
|
|
|
export const Button: React.FC<ButtonProps> = (props) => {
|
2022-03-05 18:22:30 +01:00
|
|
|
const {
|
|
|
|
children,
|
|
|
|
className: givenClassName,
|
|
|
|
color = 'green',
|
|
|
|
...rest
|
|
|
|
} = props
|
2021-10-24 05:48:06 +02:00
|
|
|
|
|
|
|
return (
|
2022-03-05 18:22:30 +01:00
|
|
|
<button
|
|
|
|
className={classNames(
|
|
|
|
className,
|
|
|
|
{
|
|
|
|
[classNameGreen]: color === 'green',
|
|
|
|
[classNameRed]: color === 'red'
|
|
|
|
},
|
|
|
|
givenClassName
|
|
|
|
)}
|
|
|
|
{...rest}
|
|
|
|
>
|
2021-10-24 05:48:06 +02:00
|
|
|
{children}
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|