mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
34 lines
659 B
TypeScript
34 lines
659 B
TypeScript
'use client'
|
|
|
|
import Link, { type LinkProps } from 'next/link'
|
|
import { useState } from 'react'
|
|
|
|
export function LinkAccordion({
|
|
href,
|
|
children,
|
|
prefetch,
|
|
}: {
|
|
href: string
|
|
children: React.ReactNode
|
|
prefetch?: LinkProps['prefetch']
|
|
}) {
|
|
const [isVisible, setIsVisible] = useState(false)
|
|
return (
|
|
<>
|
|
<input
|
|
type="checkbox"
|
|
checked={isVisible}
|
|
onChange={() => setIsVisible(!isVisible)}
|
|
data-link-accordion={href}
|
|
/>
|
|
{isVisible ? (
|
|
<Link href={href} prefetch={prefetch}>
|
|
{children}
|
|
</Link>
|
|
) : (
|
|
<>{children} (link is hidden)</>
|
|
)}
|
|
</>
|
|
)
|
|
}
|