2022-11-25 20:25:03 +00:00
|
|
|
import { forwardRef } from 'react';
|
2022-06-05 18:56:42 +00:00
|
|
|
import classNames from 'classnames';
|
2022-12-21 21:27:50 +00:00
|
|
|
|
|
|
|
import type { ButtonProps } from '@/components/elements/button/types';
|
|
|
|
import { Options } from '@/components/elements/button/types';
|
2022-06-05 18:56:42 +00:00
|
|
|
import styles from './style.module.css';
|
|
|
|
|
|
|
|
const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
2022-06-20 16:38:23 +00:00
|
|
|
({ children, shape, size, variant, className, ...rest }, ref) => {
|
2022-06-05 18:56:42 +00:00
|
|
|
return (
|
|
|
|
<button
|
|
|
|
ref={ref}
|
2022-06-20 16:38:23 +00:00
|
|
|
className={classNames(
|
|
|
|
styles.button,
|
|
|
|
styles.primary,
|
|
|
|
{
|
|
|
|
[styles.secondary]: variant === Options.Variant.Secondary,
|
|
|
|
[styles.square]: shape === Options.Shape.IconSquare,
|
|
|
|
[styles.small]: size === Options.Size.Small,
|
|
|
|
[styles.large]: size === Options.Size.Large,
|
|
|
|
},
|
2022-11-25 20:25:03 +00:00
|
|
|
className,
|
2022-06-20 16:38:23 +00:00
|
|
|
)}
|
2022-06-05 18:56:42 +00:00
|
|
|
{...rest}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</button>
|
|
|
|
);
|
2022-11-25 20:25:03 +00:00
|
|
|
},
|
2022-06-05 18:56:42 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const TextButton = forwardRef<HTMLButtonElement, ButtonProps>(({ className, ...props }, ref) => (
|
2022-06-26 19:30:05 +00:00
|
|
|
// @ts-expect-error not sure how to get this correct
|
2022-06-05 18:56:42 +00:00
|
|
|
<Button ref={ref} className={classNames(styles.text, className)} {...props} />
|
|
|
|
));
|
|
|
|
|
|
|
|
const DangerButton = forwardRef<HTMLButtonElement, ButtonProps>(({ className, ...props }, ref) => (
|
2022-06-26 19:30:05 +00:00
|
|
|
// @ts-expect-error not sure how to get this correct
|
2022-06-05 18:56:42 +00:00
|
|
|
<Button ref={ref} className={classNames(styles.danger, className)} {...props} />
|
|
|
|
));
|
|
|
|
|
2022-06-20 16:38:23 +00:00
|
|
|
const _Button = Object.assign(Button, {
|
|
|
|
Sizes: Options.Size,
|
|
|
|
Shapes: Options.Shape,
|
|
|
|
Variants: Options.Variant,
|
|
|
|
Text: TextButton,
|
|
|
|
Danger: DangerButton,
|
|
|
|
});
|
2022-06-05 18:56:42 +00:00
|
|
|
|
|
|
|
export default _Button;
|