Skip to content

Commit

Permalink
fix: collapsible animations
Browse files Browse the repository at this point in the history
  • Loading branch information
abernier committed Sep 2, 2024
1 parent 4202ddc commit 578c7c1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
10 changes: 8 additions & 2 deletions src/components/Nav/NavCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Doc } from '@/app/[...slug]/DocsContext'
import cn from '@/lib/cn'
import * as Collapsible from '@radix-ui/react-collapsible'
import Link from 'next/link'
import { ComponentProps, useState } from 'react'
import { ComponentProps, useEffect, useState } from 'react'
import { IoIosArrowDown } from 'react-icons/io'

const INDEX_PAGE = 'introduction'
Expand All @@ -25,6 +25,12 @@ export function NavCategory({

const [open, setOpen] = useState(docsEntries.some(([, doc]) => doc.url === `/${asPath}`))

useEffect(() => {
const dur = '.2s'
document.documentElement.style.setProperty('--collapsible-down-duration', dur)
document.documentElement.style.setProperty('--collapsible-up-duration', dur)
}, [])

return (
<Collapsible.Root
className={cn(
Expand Down Expand Up @@ -52,7 +58,7 @@ export function NavCategory({
</Collapsible.Trigger>
</div>

<Collapsible.Content className="data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down overflow-hidden">
<Collapsible.Content className="overflow-hidden data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down">
<ul>
{docsEntries
.filter(([page]) => page !== INDEX_PAGE)
Expand Down
28 changes: 14 additions & 14 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ const config: Config = {
fontFamily: {
mono: ['"Inconsolata"', ...defaultTheme.fontFamily.mono],
},
// keyframes: {
// 'collapsible-down': {
// from: { height: '0' },
// to: { height: 'var(--radix-collapsible-content-height)' },
// },
// 'collapsible-up': {
// from: { height: 'var(--radix-collapsible-content-height)' },
// to: { height: '0' },
// },
// },
// animation: {
// 'collapsible-down': 'collapsible-down 0.2s ease-out',
// 'collapsible-up': 'collapsible-up 0.2s ease-out',
// },
keyframes: {
'collapsible-down': {
from: { height: '0' },
to: { height: 'var(--radix-collapsible-content-height)' },
},
'collapsible-up': {
from: { height: 'var(--radix-collapsible-content-height)' },
to: { height: '0' },
},
},
animation: {
'collapsible-down': 'collapsible-down var(--collapsible-down-duration, 0s) ease-out',
'collapsible-up': 'collapsible-up var(--collapsible-up-duration, 0s) ease-out',
},
},
},
}
Expand Down

0 comments on commit 578c7c1

Please sign in to comment.