30 lines
846 B
TypeScript
Raw Normal View History

import { LucideIcon } from "lucide-react";
2024-08-16 01:23:55 +07:00
import { ComponentPropsWithoutRef, forwardRef } from "react";
import { Button as BaseButton } from "react-daisyui";
import { Link } from "react-router-dom";
type ButtonProps = ComponentPropsWithoutRef<typeof BaseButton> & {
href?: string;
target?: "_blank" | "_self" | "_parent" | "_top";
icon?: LucideIcon;
2024-08-16 01:23:55 +07:00
};
const Button = forwardRef<HTMLButtonElement, ButtonProps>(
({ href, children, icon: Icon, shape, ...props }, ref) => {
2024-08-16 01:23:55 +07:00
return (
<BaseButton
ref={ref}
tag={href ? Link : undefined}
shape={Icon && !children ? "circle" : shape}
2024-08-16 01:23:55 +07:00
{...props}
{...(href ? { to: href } : {})}
>
{Icon ? <Icon size={18} className={children ? "-ml-1" : ""} /> : null}
{children}
</BaseButton>
2024-08-16 01:23:55 +07:00
);
}
);
export default Button;