From 1feeafc99783c2d96d20b71192721a1167ea1fcb Mon Sep 17 00:00:00 2001 From: Gwansik Kim Date: Fri, 24 Jan 2025 00:07:57 +0900 Subject: [PATCH] docs(suspensive.org): add npm install copy-button on landing page (#1417) Co-authored-by: Jonghyeon Ko --- .../suspensive.org/public/img/icons/check.svg | 1 + .../public/img/icons/content_copy.svg | 1 + .../src/components/HomePage.tsx | 25 +++------- .../src/components/NpmInstallCopyButton.tsx | 46 +++++++++++++++++++ docs/suspensive.org/src/pages/en/index.mdx | 2 +- docs/suspensive.org/src/pages/ko/index.mdx | 2 +- docs/suspensive.org/svg.d.ts | 1 + docs/suspensive.org/tsconfig.json | 1 + 8 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 docs/suspensive.org/public/img/icons/check.svg create mode 100644 docs/suspensive.org/public/img/icons/content_copy.svg create mode 100644 docs/suspensive.org/src/components/NpmInstallCopyButton.tsx create mode 100644 docs/suspensive.org/svg.d.ts diff --git a/docs/suspensive.org/public/img/icons/check.svg b/docs/suspensive.org/public/img/icons/check.svg new file mode 100644 index 000000000..18db27621 --- /dev/null +++ b/docs/suspensive.org/public/img/icons/check.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/suspensive.org/public/img/icons/content_copy.svg b/docs/suspensive.org/public/img/icons/content_copy.svg new file mode 100644 index 000000000..026cbf17c --- /dev/null +++ b/docs/suspensive.org/public/img/icons/content_copy.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/suspensive.org/src/components/HomePage.tsx b/docs/suspensive.org/src/components/HomePage.tsx index 56b3ad9b7..d31231680 100644 --- a/docs/suspensive.org/src/components/HomePage.tsx +++ b/docs/suspensive.org/src/components/HomePage.tsx @@ -4,6 +4,7 @@ import Image from 'next/image' import Link from 'next/link' import { useRouter } from 'nextra/hooks' import { useEffect, useRef } from 'react' +import { NpmInstallCopyButton } from './NpmInstallCopyButton' const CodeBlockClassName = 'nextra-code' @@ -16,13 +17,12 @@ const backtickToCodeBlock = (text: string) => const formatCodeBlocks = (desc: string) => backtickToCodeBlock(escapeHtml(desc)) export const HomePage = ({ - description, + title, buttonText, items, children, }: { title: string - description: string buttonText: string items: { title: string; desc: string }[] version: number @@ -60,26 +60,15 @@ export const HomePage = ({ />
-
- {description} +
+ {title}
- - npm i @suspensive/react -
+
{buttonText} diff --git a/docs/suspensive.org/src/components/NpmInstallCopyButton.tsx b/docs/suspensive.org/src/components/NpmInstallCopyButton.tsx new file mode 100644 index 000000000..d3f3cd78e --- /dev/null +++ b/docs/suspensive.org/src/components/NpmInstallCopyButton.tsx @@ -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 ( + 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} + + + {isHovered ? ( + + + + ) : null} + + + + ) +} diff --git a/docs/suspensive.org/src/pages/en/index.mdx b/docs/suspensive.org/src/pages/en/index.mdx index a043186f1..61ab08d60 100644 --- a/docs/suspensive.org/src/pages/en/index.mdx +++ b/docs/suspensive.org/src/pages/en/index.mdx @@ -6,7 +6,7 @@ import { } from '@/components'