-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(docs): update copy button simply
- Loading branch information
Showing
7 changed files
with
71 additions
and
76 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
docs/suspensive.org/src/components/NpmInstallCopyButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { AnimatePresence, motion } from 'motion/react' | ||
import '../styles/globals.css' | ||
import Image from 'next/image' | ||
import { useState } from 'react' | ||
import checkSVG from '../../public/img/icons/check.svg' | ||
import content_copySVG from '../../public/img/icons/content_copy.svg' | ||
|
||
const npmInstallScript = 'npm i @suspensive/react' | ||
export const NpmInstallCopyButton = () => { | ||
const [isHovered, setIsHovered] = useState(false) | ||
const [isClicked, setIsClicked] = useState(false) | ||
|
||
return ( | ||
<motion.button | ||
className="relative mt-4 flex cursor-copy" | ||
type="button" | ||
onHoverStart={() => setIsHovered(true)} | ||
onHoverEnd={() => { | ||
setIsHovered(false) | ||
setIsClicked(false) | ||
}} | ||
whileHover={{ opacity: 1 }} | ||
initial={{ opacity: 0 }} | ||
animate={{ opacity: 0.5 }} | ||
onClick={() => { | ||
navigator.clipboard.writeText(npmInstallScript) | ||
setIsClicked(true) | ||
}} | ||
> | ||
~ {npmInstallScript} | ||
<motion.div className="absolute -right-8 flex items-center justify-center"> | ||
<AnimatePresence> | ||
{isHovered ? ( | ||
<motion.span | ||
initial={{ opacity: 0 }} | ||
animate={{ opacity: 1 }} | ||
exit={{ opacity: 0 }} | ||
> | ||
<Image src={isClicked ? checkSVG : content_copySVG} alt="" /> | ||
</motion.span> | ||
) : null} | ||
</AnimatePresence> | ||
</motion.div> | ||
</motion.button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters