Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(suspensive.org): add npm install copy-button on landing page #1417

Merged
merged 5 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/suspensive.org/public/img/icons/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/suspensive.org/public/img/icons/content_copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 7 additions & 18 deletions docs/suspensive.org/src/components/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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
Expand Down Expand Up @@ -60,26 +60,15 @@ export const HomePage = ({
/>
</div>
<div className="flex flex-col items-center gap-4">
<div className="break-keep px-4 text-4xl font-bold leading-tight md:text-6xl">
<span>{description}</span>
<div className="break-keep bg-gradient-to-r from-white via-white/80 to-white/60 bg-clip-text px-4 text-4xl font-bold leading-tight text-transparent md:text-6xl">
<span>{title}</span>
</div>
<motion.p
initial={{ opacity: 0 }}
animate={{
opacity: 0.6,
transition: { delay: 0.1, duration: 1 },
}}
className="rounded-full text-lg text-white md:text-xl"
>
npm i @suspensive/react
</motion.p>
</div>
<NpmInstallCopyButton />
</div>
<Link href={`/${router.locale}/docs/react/motivation`}>
<motion.button
whileHover={{
scale: 1.05,
}}
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.95 }}
initial={{ opacity: 0 }}
animate={{
Expand All @@ -92,7 +81,7 @@ export const HomePage = ({
'drop-shadow(0 0 1px rgba(255, 255, 255, 0.5)) drop-shadow(0 0 3px rgba(255, 255, 255, 0.5)) drop-shadow(0 0 10px rgba(255, 255, 255, 0.5))',
}}
type="button"
className="rounded-xl bg-white px-8 py-3 text-lg font-bold text-[#111111] md:px-10 md:py-3 md:text-xl"
className="rounded-xl bg-white px-7 py-2 text-lg font-bold text-[#111111] md:px-9 md:py-3 md:text-xl"
>
{buttonText}
</motion.button>
Expand Down
46 changes: 46 additions & 0 deletions docs/suspensive.org/src/components/NpmInstallCopyButton.tsx
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>
)
}
2 changes: 1 addition & 1 deletion docs/suspensive.org/src/pages/en/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@/components'

<HomePage
description="All in one for React Suspense"
title="All in one for React Suspense"
buttonText="Get Started"
items={[
{
Expand Down
2 changes: 1 addition & 1 deletion docs/suspensive.org/src/pages/ko/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@/components'

<HomePage
description="React Suspense를 위한 모든 것"
title="React Suspense를 위한 모든 것"
buttonText="시작하기"
items={[
{
Expand Down
1 change: 1 addition & 0 deletions docs/suspensive.org/svg.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '*.svg'
1 change: 1 addition & 0 deletions docs/suspensive.org/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"include": [
"next-env.d.ts",
"svg.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
Expand Down
Loading