Returned loader to default, fixed buttons not working with asChild

This commit is contained in:
Lucas Oliveira 2024-06-04 11:17:17 -03:00
commit 5b83bde64e

View file

@ -60,14 +60,6 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
if (typeof children === "string") {
newChildren = toTitleCase(children);
}
const [width, setWidth] = React.useState<number | null>(null);
const hiddenRef = React.useRef<HTMLDivElement>(null);
React.useEffect(() => {
if (hiddenRef.current) {
setWidth(hiddenRef.current.offsetWidth);
}
}, [children, hiddenRef]);
return (
<>
<Comp
@ -75,29 +67,15 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
ref={ref}
{...props}
>
<>
{loading ? (
<div style={{ width: loading && width ? `${width}px` : "auto" }}>
<ForwardedIconComponent
name={"Loader2"}
className={"animate-spin"}
/>
</div>
) : (
children
)}
</>
{loading ? (
<ForwardedIconComponent
name={"Loader2"}
className={"animate-spin"}
/>
) : (
newChildren
)}
</Comp>
<div
ref={hiddenRef}
style={{
visibility: "hidden",
position: "absolute",
whiteSpace: "nowrap",
}}
>
{children}
</div>
</>
);
},