mirror of
https://github.com/Buriburizaem0n/admin-frontend-domain.git
synced 2026-05-06 05:38:51 +00:00
improve: replace long line of words with clipboard button (#95)
* improve: replace long line of words with clipboard button * change module path
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { ButtonProps } from "@/components/ui/button"
|
||||
import { copyToClipboard } from "@/lib/utils"
|
||||
import { forwardRef } from "react"
|
||||
import { useState } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { IconButton } from "./xui/icon-button"
|
||||
|
||||
interface CopyButtonProps extends ButtonProps {
|
||||
text?: string
|
||||
}
|
||||
|
||||
export const CopyButton = forwardRef<HTMLButtonElement, CopyButtonProps>((props, ref) => {
|
||||
const { t } = useTranslation()
|
||||
const [copy, setCopy] = useState(false)
|
||||
|
||||
const switchState = async (text?: string) => {
|
||||
if (!text) {
|
||||
toast("Warning", {
|
||||
description: t("EmptyText"),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (!copy) {
|
||||
setCopy(true)
|
||||
await copyToClipboard(text)
|
||||
setTimeout(() => {
|
||||
setCopy(false)
|
||||
}, 2 * 1000)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<IconButton
|
||||
{...props}
|
||||
ref={ref}
|
||||
variant="outline"
|
||||
size="icon"
|
||||
icon={copy ? "check" : "clipboard"}
|
||||
onClick={() => switchState(props.text)}
|
||||
/>
|
||||
)
|
||||
})
|
||||
@@ -23,7 +23,7 @@ export const NoteMenu = forwardRef<HTMLButtonElement, NoteMenuProps>((props, ref
|
||||
const switchState = async (text?: string) => {
|
||||
if (!text) {
|
||||
toast("Warning", {
|
||||
description: "You didn't have any note.",
|
||||
description: t("EmptyNote"),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user