mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
migration
This commit is contained in:
@@ -1,36 +1,35 @@
|
||||
"use client"
|
||||
"use client";
|
||||
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {useState} from "react";
|
||||
import {Loader2} from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useState } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
|
||||
export type VariantButton = {
|
||||
secondary: string
|
||||
default: string
|
||||
outline: string
|
||||
ghost: string
|
||||
link: string
|
||||
destructive: string
|
||||
}
|
||||
secondary: string;
|
||||
default: string;
|
||||
outline: string;
|
||||
ghost: string;
|
||||
link: string;
|
||||
destructive: string;
|
||||
};
|
||||
|
||||
export type ButtonWithConfirmProps = {
|
||||
icon?: any,
|
||||
text: string,
|
||||
variant?: keyof VariantButton,
|
||||
className?: string,
|
||||
onClick?: () => void,
|
||||
isPending?: boolean
|
||||
icon?: any;
|
||||
text: string;
|
||||
variant?: keyof VariantButton;
|
||||
className?: string;
|
||||
onClick?: () => void;
|
||||
isPending?: boolean;
|
||||
};
|
||||
|
||||
export const ButtonWithConfirm = (props: ButtonWithConfirmProps) => {
|
||||
|
||||
const [isConfirming, setIsConfirming] = useState(false)
|
||||
const [isConfirming, setIsConfirming] = useState(false);
|
||||
|
||||
return (
|
||||
<Button
|
||||
onClick={() => {
|
||||
if (isConfirming) {
|
||||
props.onClick()
|
||||
if (isConfirming && props.onClick) {
|
||||
props.onClick();
|
||||
} else {
|
||||
setIsConfirming(true);
|
||||
}
|
||||
@@ -38,12 +37,9 @@ export const ButtonWithConfirm = (props: ButtonWithConfirmProps) => {
|
||||
variant={props.variant ? props.variant : "default"}
|
||||
className={props.className}
|
||||
>
|
||||
{props.isPending && <Loader2 className="animate-spin mr-4" size={16}/>}
|
||||
{props.isPending && <Loader2 className="animate-spin mr-4" size={16} />}
|
||||
{isConfirming ? "Are you sure ?" : `${props.text}`}
|
||||
<>
|
||||
{props.icon ? props.icon : null}
|
||||
</>
|
||||
<>{props.icon ? props.icon : null}</>
|
||||
</Button>
|
||||
)
|
||||
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,60 +1,57 @@
|
||||
"use client"
|
||||
"use client";
|
||||
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {ButtonHTMLAttributes} from "react";
|
||||
import {Loader2} from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ButtonHTMLAttributes } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
|
||||
export type VariantButton = {
|
||||
secondary: string
|
||||
default: string
|
||||
outline: string
|
||||
ghost: string
|
||||
link: string
|
||||
destructive: string
|
||||
}
|
||||
secondary: string;
|
||||
default: string;
|
||||
outline: string;
|
||||
ghost: string;
|
||||
link: string;
|
||||
destructive: string;
|
||||
};
|
||||
export type sizeButton = {
|
||||
default :string,
|
||||
icon: string
|
||||
sm: string
|
||||
lg: string
|
||||
}
|
||||
default: string;
|
||||
icon: string;
|
||||
sm: string;
|
||||
lg: string;
|
||||
};
|
||||
|
||||
export type ButtonWithConfirmProps = {
|
||||
icon?: any,
|
||||
text: string,
|
||||
variant?: keyof VariantButton,
|
||||
className?: string,
|
||||
onClick: () => void,
|
||||
isPending?: boolean
|
||||
size: keyof sizeButton
|
||||
icon?: any;
|
||||
text: string;
|
||||
variant?: keyof VariantButton;
|
||||
className?: string;
|
||||
onClick: () => void;
|
||||
isPending?: boolean;
|
||||
size: keyof sizeButton;
|
||||
};
|
||||
|
||||
export const ButtonWithLoading = ({
|
||||
icon,
|
||||
text,
|
||||
variant,
|
||||
className,
|
||||
onClick,
|
||||
isPending,
|
||||
size,
|
||||
...props // catch all remaining props
|
||||
}: ButtonWithConfirmProps & ButtonHTMLAttributes<HTMLButtonElement>) => {
|
||||
icon,
|
||||
text,
|
||||
variant,
|
||||
className,
|
||||
onClick,
|
||||
isPending,
|
||||
size,
|
||||
...props // catch all remaining props
|
||||
}: ButtonWithConfirmProps & ButtonHTMLAttributes<HTMLButtonElement>) => {
|
||||
return (
|
||||
<Button
|
||||
onClick={() => {
|
||||
onClick()
|
||||
onClick();
|
||||
}}
|
||||
variant={variant ? variant : "default"}
|
||||
className={className}
|
||||
{...props} // forward the remaining props to the Button component
|
||||
size={size || "default"}
|
||||
|
||||
>
|
||||
{isPending && <Loader2 className="animate-spin mr-4" size={16}/>}
|
||||
{isPending && <Loader2 className="animate-spin mr-4" size={16} />}
|
||||
{text}
|
||||
<>
|
||||
{icon ? icon : null}
|
||||
</>
|
||||
<>{icon ? icon : null}</>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,46 +1,40 @@
|
||||
"use client"
|
||||
|
||||
import {useEffect, useState} from "react";
|
||||
import {CheckIcon, ClipboardIcon, Copy} from "lucide-react";
|
||||
import {Button, buttonVariants} from "@/components/ui/button";
|
||||
import {cn} from "@/lib/utils";
|
||||
import {useTranslations} from "use-intl";
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { CheckIcon, Copy } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export async function copyToClipboardWithMeta(value: string) {
|
||||
navigator.clipboard.writeText(value)
|
||||
navigator.clipboard.writeText(value);
|
||||
}
|
||||
|
||||
|
||||
export type CopyButtonProps = {
|
||||
value: string,
|
||||
className: string
|
||||
}
|
||||
|
||||
value: string;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
export const CopyButton = (props: CopyButtonProps) => {
|
||||
const { value } = props;
|
||||
|
||||
const {value} = props
|
||||
|
||||
const [hasCopied, setHasCopied] = useState(false)
|
||||
const [hasCopied, setHasCopied] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setTimeout(() => {
|
||||
setHasCopied(false)
|
||||
}, 2000)
|
||||
}, [hasCopied])
|
||||
setHasCopied(false);
|
||||
}, 2000);
|
||||
}, [hasCopied]);
|
||||
|
||||
return (
|
||||
<Button
|
||||
// className={cn(buttonVariants({size: "sm"}))}
|
||||
onClick={() => {
|
||||
copyToClipboardWithMeta(value)
|
||||
setHasCopied(true)
|
||||
copyToClipboardWithMeta(value);
|
||||
setHasCopied(true);
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
<span className="mr-2">Copy</span>
|
||||
{hasCopied ? <CheckIcon/> : <Copy size="18"/>}
|
||||
{hasCopied ? <CheckIcon /> : <Copy size="18" />}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user