Compare commits
2 Commits
a873095099
...
0ead6bd969
Author | SHA1 | Date | |
---|---|---|---|
0ead6bd969 | |||
747cc1cdb4 |
112
src/components/ui/copy-button.tsx
Normal file
112
src/components/ui/copy-button.tsx
Normal file
@ -0,0 +1,112 @@
|
||||
"use client";
|
||||
import type { DropdownMenuTriggerProps } from "@radix-ui/react-dropdown-menu";
|
||||
import { CheckIcon, ClipboardIcon } from "lucide-react";
|
||||
|
||||
import { Button, type ButtonProps } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
interface CopyButtonProps extends ButtonProps {
|
||||
value: string;
|
||||
src?: string;
|
||||
event?: Event["NONE"];
|
||||
}
|
||||
|
||||
interface Value {
|
||||
data: string;
|
||||
title: string;
|
||||
}
|
||||
|
||||
export async function copyToClipboardWithMeta(value: string) {
|
||||
await window?.navigator.clipboard.writeText(value);
|
||||
}
|
||||
|
||||
export function CopyButton({
|
||||
value,
|
||||
className,
|
||||
src,
|
||||
variant = "ghost",
|
||||
event,
|
||||
...props
|
||||
}: CopyButtonProps) {
|
||||
const [hasCopied, setHasCopied] = useState(false);
|
||||
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
|
||||
useEffect(() => {
|
||||
setTimeout(() => {
|
||||
setHasCopied(false);
|
||||
}, 2000);
|
||||
}, [hasCopied]);
|
||||
|
||||
return (
|
||||
<Button
|
||||
size="icon"
|
||||
variant={variant}
|
||||
className={cn(
|
||||
"relative z-10 h-6 w-6 text-zinc-50 hover:bg-zinc-700 hover:text-zinc-50 [&_svg]:size-3",
|
||||
className,
|
||||
)}
|
||||
onClick={() => {
|
||||
copyToClipboardWithMeta(value).then(() => setHasCopied(true));
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
<span className="sr-only">Copy</span>
|
||||
{hasCopied ? <CheckIcon /> : <ClipboardIcon />}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
interface CopyMultipleChoiceButtonProps extends DropdownMenuTriggerProps {
|
||||
values: Value[];
|
||||
}
|
||||
|
||||
export function CopyMultipleChoiceButton({
|
||||
values,
|
||||
className,
|
||||
...props
|
||||
}: CopyMultipleChoiceButtonProps) {
|
||||
const [hasCopied, setHasCopied] = useState(false);
|
||||
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
|
||||
useEffect(() => {
|
||||
setTimeout(() => {
|
||||
setHasCopied(false);
|
||||
}, 2000);
|
||||
}, [hasCopied]);
|
||||
|
||||
const copyCommand = useCallback((value: string) => {
|
||||
copyToClipboardWithMeta(value).then(() => setHasCopied(true));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className={cn(
|
||||
"relative z-10 h-6 w-6 text-zinc-50 hover:bg-zinc-700 hover:text-zinc-50",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{hasCopied ? (
|
||||
<CheckIcon className="h-3 w-3" />
|
||||
) : (
|
||||
<ClipboardIcon className="h-3 w-3" />
|
||||
)}
|
||||
<span className="sr-only">Copy</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => copyCommand("npm")}>npm</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
export interface IUserWalletCryptos {
|
||||
Crypto?: ICryptoInWalletInfo;
|
||||
Crypto: ICryptoInWalletInfo;
|
||||
amount: number;
|
||||
}
|
||||
|
||||
export interface ICryptoInWalletInfo {
|
||||
@ -12,6 +13,10 @@ export interface ICryptoInWalletInfo {
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface ICryptoInUserWalletInfo extends ICryptoInWalletInfo {
|
||||
owned_amount: number;
|
||||
}
|
||||
|
||||
export type IAllTrades = ITrade[];
|
||||
|
||||
export interface ITrade {
|
||||
|
@ -1,3 +1,9 @@
|
||||
import {
|
||||
ICryptoInUserWalletInfo,
|
||||
type ICryptoInWalletInfo,
|
||||
IUserWalletCryptos,
|
||||
} from "@/interfaces/crypto.interface";
|
||||
|
||||
export interface IUserData {
|
||||
id: string;
|
||||
firstName: string;
|
||||
@ -11,4 +17,12 @@ export interface IUserData {
|
||||
age: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
//TODO get on register
|
||||
wallet: IUserWallet;
|
||||
}
|
||||
|
||||
export interface IUserWallet {
|
||||
uat: number;
|
||||
update_interval: number;
|
||||
owned_cryptos: ICryptoInUserWalletInfo[];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user