Skip to content

Commit

Permalink
feat(post): create Spoiler component
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusfg7 committed Mar 7, 2024
1 parent d5fa132 commit 9204f88
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/app/blog/post/[slug]/_components/spoiler.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use client'

import { EyeSlash } from '@phosphor-icons/react/dist/ssr'
import { ComponentProps, useState } from 'react'

export function Spoiler({ children, ...rest }: ComponentProps<'div'>) {
const [hide, setHide] = useState(true)

return (
<div {...rest} className="relative w-full">
<div data-hide={hide} className="w-full data-[hide='true']:blur-lg">
{children}
</div>
<div
data-hide={hide}
className="absolute inset-0 flex items-center justify-center data-[hide='false']:hidden"
>
<div className="divide-y divide-neutral-200 text-center dark:divide-neutral-500">
<div className="flex justify-center py-2 text-3xl">
<EyeSlash size="1em" />
</div>
<button
className="py-2 hover:underline"
onClick={() => setHide(false)}
>
Show content
</button>
</div>
</div>
</div>
)
}
4 changes: 3 additions & 1 deletion src/app/blog/post/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { MDXContent } from '~/components/mdx-content'
import { TopButton } from './_components/top-button'
import { Anchor } from './_components/anchor'
import { PrettyCodeElement } from './_components/pretty-code-element'
import { Spoiler } from './_components/spoiler'

import 'katex/dist/katex.min.css'

Expand Down Expand Up @@ -112,7 +113,8 @@ const mdxComponents = {
</span>
{children}
</blockquote>
)
),
Spoiler
}

const exampleToc = posts[0].toc[0]
Expand Down

0 comments on commit 9204f88

Please sign in to comment.