Made Submit button use loading of button
This commit is contained in:
parent
0e5460c088
commit
9e6f3a064d
2 changed files with 20 additions and 24 deletions
|
|
@ -5,7 +5,7 @@ import { cn } from "../../utils/utils";
|
||||||
import ForwardedIconComponent from "../genericIconComponent";
|
import ForwardedIconComponent from "../genericIconComponent";
|
||||||
|
|
||||||
const buttonVariants = cva(
|
const buttonVariants = cva(
|
||||||
"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none ring-offset-background",
|
"inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none ring-offset-background",
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
|
|
@ -54,7 +54,16 @@ function toTitleCase(text: string) {
|
||||||
|
|
||||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||||
(
|
(
|
||||||
{ className, variant, size, loading, asChild = false, children, ...props },
|
{
|
||||||
|
className,
|
||||||
|
variant,
|
||||||
|
size,
|
||||||
|
loading,
|
||||||
|
disabled,
|
||||||
|
asChild = false,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
},
|
||||||
ref,
|
ref,
|
||||||
) => {
|
) => {
|
||||||
const Comp = asChild ? Slot : "button";
|
const Comp = asChild ? Slot : "button";
|
||||||
|
|
@ -66,6 +75,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||||
<>
|
<>
|
||||||
<Comp
|
<Comp
|
||||||
className={cn(buttonVariants({ variant, size, className }))}
|
className={cn(buttonVariants({ variant, size, className }))}
|
||||||
|
disabled={loading || disabled}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -86,24 +86,10 @@ const Footer: React.FC<{
|
||||||
<Button
|
<Button
|
||||||
data-testid={submit.dataTestId}
|
data-testid={submit.dataTestId}
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={submit.loading || submit.disabled}
|
loading={submit.loading}
|
||||||
className="relative"
|
|
||||||
>
|
>
|
||||||
<div
|
{submit.icon && submit.icon}
|
||||||
className={cn(
|
{submit.label}
|
||||||
submit.loading ? "opacity-100" : "opacity-0",
|
|
||||||
"absolute self-center"
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<ForwardedIconComponent
|
|
||||||
name={"Loader2"}
|
|
||||||
className={"animate-spin"}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className={cn(submit.loading ? "opacity-0" : "opacity-100")}>
|
|
||||||
{submit.icon && submit.icon}
|
|
||||||
{submit.label}
|
|
||||||
</div>
|
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -116,7 +102,7 @@ interface BaseModalProps {
|
||||||
React.ReactElement<ContentProps>,
|
React.ReactElement<ContentProps>,
|
||||||
React.ReactElement<HeaderProps>,
|
React.ReactElement<HeaderProps>,
|
||||||
React.ReactElement<TriggerProps>?,
|
React.ReactElement<TriggerProps>?,
|
||||||
React.ReactElement<FooterProps>?
|
React.ReactElement<FooterProps>?,
|
||||||
];
|
];
|
||||||
open?: boolean;
|
open?: boolean;
|
||||||
setOpen?: (open: boolean) => void;
|
setOpen?: (open: boolean) => void;
|
||||||
|
|
@ -150,16 +136,16 @@ function BaseModal({
|
||||||
onSubmit,
|
onSubmit,
|
||||||
}: BaseModalProps) {
|
}: BaseModalProps) {
|
||||||
const headerChild = React.Children.toArray(children).find(
|
const headerChild = React.Children.toArray(children).find(
|
||||||
(child) => (child as React.ReactElement).type === Header
|
(child) => (child as React.ReactElement).type === Header,
|
||||||
);
|
);
|
||||||
const triggerChild = React.Children.toArray(children).find(
|
const triggerChild = React.Children.toArray(children).find(
|
||||||
(child) => (child as React.ReactElement).type === Trigger
|
(child) => (child as React.ReactElement).type === Trigger,
|
||||||
);
|
);
|
||||||
const ContentChild = React.Children.toArray(children).find(
|
const ContentChild = React.Children.toArray(children).find(
|
||||||
(child) => (child as React.ReactElement).type === Content
|
(child) => (child as React.ReactElement).type === Content,
|
||||||
);
|
);
|
||||||
const ContentFooter = React.Children.toArray(children).find(
|
const ContentFooter = React.Children.toArray(children).find(
|
||||||
(child) => (child as React.ReactElement).type === Footer
|
(child) => (child as React.ReactElement).type === Footer,
|
||||||
);
|
);
|
||||||
|
|
||||||
let minWidth: string;
|
let minWidth: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue