Skip to content

Commit

Permalink
fix styles and animation
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Aug 22, 2022
1 parent 8152abc commit 6c58a89
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/nextra-theme-docs/src/components/breadcrumb.tsx
Expand Up @@ -10,7 +10,7 @@ export function Breadcrumb({
activePath: Item[]
}): ReactElement {
return (
<div className="nextra-breadcrumb mt-2.5 flex gap-1 overflow-hidden text-sm text-gray-500 contrast-more:text-current">
<div className="nextra-breadcrumb mt-2.5 flex items-center gap-1 overflow-hidden text-sm text-gray-500 contrast-more:text-current">
{activePath.map((item, index) => {
const isLink = !item.children || item.withIndexPage
const isActive = index === activePath.length - 1
Expand Down
2 changes: 1 addition & 1 deletion packages/nextra-theme-docs/src/components/collapse.tsx
Expand Up @@ -51,7 +51,7 @@ export function Collapse({
if (container) {
container.style.maxHeight = '0px'
}
})
}, 0)
}
}
}, [open])
Expand Down
2 changes: 1 addition & 1 deletion packages/nextra-theme-docs/src/components/search.tsx
Expand Up @@ -139,7 +139,7 @@ export function Search({
>
<kbd
className={cn(
'absolute ltr:right-1.5 rtl:left-1.5 my-1.5 select-none',
'absolute ltr:right-1.5 rtl:left-1.5 top-0 my-1.5 select-none',
'rounded bg-white px-1.5 h-5 font-mono font-medium text-gray-500 text-[10px]',
'border dark:bg-dark/50 dark:border-gray-100/20',
'contrast-more:border-current contrast-more:text-current contrast-more:dark:border-current',
Expand Down
13 changes: 12 additions & 1 deletion packages/nextra-theme-docs/src/mdx-components.tsx
Expand Up @@ -164,11 +164,22 @@ const Details = ({
const [openState, setOpen] = useState(!!open)
const [summary, restChildren] = findSummary(children)

// To animate the close animation we have to delay the DOM node state here.
const [delayedOpenState, setDelayedOpenState] = useState(openState)
useEffect(() => {
if (openState) {
setDelayedOpenState(true)
} else {
const timeout = setTimeout(() => setDelayedOpenState(openState), 500)
return () => clearTimeout(timeout)
}
}, [openState])

return (
<details
className="my-4 rounded border border-gray-200 bg-white p-2 shadow-sm dark:border-neutral-800 dark:bg-neutral-900 first:mt-0 last:mb-0"
{...props}
{...(openState && { open: true })}
{...(delayedOpenState && { open: true })}
>
<DetailsProvider value={setOpen}>{summary}</DetailsProvider>
<Collapse open={openState}>{restChildren}</Collapse>
Expand Down

1 comment on commit 6c58a89

@shuding
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small UI issues on Safari:

CleanShot 2022-08-22 at 02 02 08@2x

And also fixes the <details> close animation.

Please sign in to comment.