Skip to content

Commit

Permalink
Animation Modal: checkbox on copy
Browse files Browse the repository at this point in the history
  • Loading branch information
nirnejak committed May 15, 2024
1 parent d01b5c6 commit 01d351d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
23 changes: 19 additions & 4 deletions components/AnimationDetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ const AnimationDetailsModal: React.FC<Props> = ({
: animation.animationClass
}, [animation, modifiers])

const [isClassCopied, setIsClassCopied] = React.useState(false)
const [isConfigCopied, setIsConfigCopied] = React.useState(false)

const handleCardClick = (e) => {
e.stopPropagation()
}
Expand Down Expand Up @@ -175,9 +178,15 @@ const AnimationDetailsModal: React.FC<Props> = ({
</pre>
<button
className="rounded p-2 absolute top-2 right-2 text-zinc-300 hover:bg-zinc-950 hover:text-zinc-200 focus:bg-zinc-950 focus:outline-none"
onClick={() => copyToClipboard(animation.animationClass)}
onClick={() => {
copyToClipboard(code)
setIsConfigCopied(true)
setTimeout(() => {
setIsConfigCopied(false)
}, 3000)
}}
>
<Copy size={16} />
{isConfigCopied ? <Check size={16} /> : <Copy size={16} />}
</button>
</div>
</div>
Expand All @@ -188,9 +197,15 @@ const AnimationDetailsModal: React.FC<Props> = ({
{animationClassName}
<button
className="rounded p-2 text-zinc-300 hover:bg-zinc-950 hover:text-zinc-200 focus:bg-zinc-950 focus:outline-none"
onClick={() => copyToClipboard(animationClassName)}
onClick={() => {
copyToClipboard(animationClassName)
setIsClassCopied(true)
setTimeout(() => {
setIsClassCopied(false)
}, 3000)
}}
>
<Copy size={16} />
{isClassCopied ? <Check size={16} /> : <Copy size={16} />}
</button>
</code>
</div>
Expand Down
4 changes: 1 addition & 3 deletions utils/copyToClipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { toast } from "sonner"
const copyToClipboard = (link): void => {
navigator.clipboard
.writeText(link)
.then(() => {
toast("Copied to clipboard")
})
.then(() => {})
.catch((error) => {
toast.error("Unable to copy")
console.log(error)
Expand Down

0 comments on commit 01d351d

Please sign in to comment.