mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
fix button
This commit is contained in:
parent
e2e2b22d94
commit
d8ef95cdfb
@ -3,54 +3,68 @@ import * as React from "react";
|
||||
import { cn } from "../../lib/cn";
|
||||
import { buttonVariants } from "../ui/button";
|
||||
|
||||
type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
|
||||
type BaseButtonProps = {
|
||||
color?: 'primary' | 'secondary' | 'outline' | 'ghost',
|
||||
size?: 'sm' | 'icon' | 'icon-sm',
|
||||
icon?: React.ReactNode,
|
||||
href?: string,
|
||||
children: React.ReactNode,
|
||||
}
|
||||
|
||||
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ className, color = 'secondary', size = 'sm', icon, href, children, ...props }, ref) => {
|
||||
const buttonContent = (
|
||||
<>
|
||||
{icon && <span className="inline-flex items-center justify-center w-3.5 h-3.5">{icon}</span>}
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
type ButtonAsButton = BaseButtonProps &
|
||||
React.ButtonHTMLAttributes<HTMLButtonElement> & {
|
||||
href?: never,
|
||||
};
|
||||
|
||||
const buttonClasses = cn(
|
||||
buttonVariants({
|
||||
color,
|
||||
size,
|
||||
className: 'gap-2 no-underline hover:no-underline'
|
||||
}),
|
||||
className
|
||||
);
|
||||
type ButtonAsLink = BaseButtonProps &
|
||||
React.AnchorHTMLAttributes<HTMLAnchorElement> & {
|
||||
href: string,
|
||||
};
|
||||
|
||||
if (href) {
|
||||
return (
|
||||
<a role="button"
|
||||
href={href}
|
||||
className={buttonClasses}
|
||||
{...(props as React.AnchorHTMLAttributes<HTMLAnchorElement>)}
|
||||
>
|
||||
{buttonContent}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
type ButtonProps = ButtonAsButton | ButtonAsLink;
|
||||
|
||||
export const Button = React.forwardRef<
|
||||
HTMLButtonElement | HTMLAnchorElement,
|
||||
ButtonProps
|
||||
>(({ className, color = 'secondary', size = 'sm', icon, href, children, ...props }, ref) => {
|
||||
const buttonContent = (
|
||||
<>
|
||||
{icon && <span className="inline-flex items-center justify-center w-3.5 h-3.5">{icon}</span>}
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
|
||||
const buttonClasses = cn(
|
||||
buttonVariants({
|
||||
color,
|
||||
size,
|
||||
className: 'gap-2 no-underline hover:no-underline'
|
||||
}),
|
||||
className
|
||||
);
|
||||
|
||||
if (href) {
|
||||
return (
|
||||
<button
|
||||
ref={ref}
|
||||
<a
|
||||
role="button"
|
||||
href={href}
|
||||
className={buttonClasses}
|
||||
{...props}
|
||||
ref={ref as React.Ref<HTMLAnchorElement>}
|
||||
{...(props as React.AnchorHTMLAttributes<HTMLAnchorElement>)}
|
||||
>
|
||||
{buttonContent}
|
||||
</button>
|
||||
</a>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
return (
|
||||
<button
|
||||
ref={ref as React.Ref<HTMLButtonElement>}
|
||||
className={buttonClasses}
|
||||
{...(props as React.ButtonHTMLAttributes<HTMLButtonElement>)}
|
||||
>
|
||||
{buttonContent}
|
||||
</button>
|
||||
);
|
||||
});
|
||||
|
||||
Button.displayName = "Button";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user