Skip to content

Commit 793d4f0

Browse files
committed
fix: modal close animation
1 parent 563c3c1 commit 793d4f0

File tree

7 files changed

+51
-134
lines changed

7 files changed

+51
-134
lines changed
Lines changed: 14 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,38 @@
11
import cn from 'clsx'
22
import { useConfig } from '@/contexts'
3-
import { useMounted } from '@/nextra/hooks'
4-
import type { PageTheme } from '@/nextra/normalize-pages'
5-
import type { ReactNode, ReactElement } from 'react'
6-
import { renderComponent } from '@/utils'
3+
import type { ReactElement } from 'react'
74
import { MDXRemote } from 'next-mdx-remote'
85
import { getComponents } from '@/mdx-components'
96
import { useMarkdownEditor } from '@/contexts/markdown-editor'
107

11-
interface MarkdownPreviewProps {
12-
themeContext: PageTheme
13-
breadcrumb: ReactNode
14-
timestamp?: number
15-
navigation: ReactNode
16-
children?: ReactNode
17-
}
18-
19-
const classes = {
20-
toc: cn('nextra-toc nx-order-last nx-hidden nx-w-64 nx-shrink-0 xl:nx-block print:nx-hidden'),
21-
main: cn('nextra-scrollbar nx-break-words nx-h-screen nx-overflow-y-auto'),
22-
}
8+
interface MarkdownPreviewProps {}
239

24-
export const MarkdownPreview = ({
25-
themeContext,
26-
navigation,
27-
children,
28-
}: MarkdownPreviewProps): ReactElement => {
10+
export const MarkdownPreview = ({}: MarkdownPreviewProps): ReactElement => {
2911
const config = useConfig()
30-
const isMount = useMounted()
3112
const { mdxSource } = useMarkdownEditor()
3213

33-
if (themeContext.layout === 'raw') {
34-
return <div className={classes.main}>{children}</div>
35-
}
36-
37-
const date = new Date()
38-
39-
const gitTimestampEl =
40-
// Because a user's time zone may be different from the server page
41-
isMount && date ? (
42-
<div className="nx-mb-8 nx-mt-12 nx-block nx-text-xs nx-text-gray-500 dark:nx-text-gray-400 ltr:nx-text-right rtl:nx-text-left">
43-
{renderComponent(config.gitTimestamp, { timestamp: date })}
44-
</div>
45-
) : (
46-
<div className="nx-mt-16" />
47-
)
48-
4914
if (!mdxSource) {
5015
return <div>Mdx source Loading...</div>
5116
}
5217

5318
const content = (
54-
<>
55-
<MDXRemote
56-
compiledSource={mdxSource.compiledSource}
57-
frontmatter={mdxSource.frontmatter}
58-
scope={mdxSource.scope}
59-
components={getComponents({
60-
isRawLayout: false,
61-
components: config.components,
62-
})}
63-
/>
64-
{gitTimestampEl}
65-
{navigation}
66-
</>
19+
<MDXRemote
20+
compiledSource={mdxSource.compiledSource}
21+
frontmatter={mdxSource.frontmatter}
22+
scope={mdxSource.scope}
23+
components={getComponents({
24+
isRawLayout: false,
25+
components: config.components,
26+
})}
27+
/>
6728
)
6829

6930
const body = config.main?.({ children: content }) || content
70-
71-
// if (themeContext.layout === 'full') {
72-
// return (
73-
// <article
74-
// className={cn(
75-
// classes.main,
76-
// 'nextra-content nx-min-h-[calc(100vh-var(--nextra-navbar-height))] nx-pl-[max(env(safe-area-inset-left),1.5rem)] nx-pr-[max(env(safe-area-inset-right),1.5rem)]',
77-
// )}
78-
// >
79-
// {body}
80-
// </article>
81-
// )
82-
// }
83-
8431
return (
8532
<article
86-
className={cn(
87-
classes.main,
88-
// 'nextra-content nx-flex nx-min-h-[calc(100vh-var(--nextra-navbar-height))] nx-min-w-0 nx-justify-center nx-pb-8 nx-pr-[calc(env(safe-area-inset-right)-1.5rem)]',
89-
// themeContext.typesetting === 'article' && 'nextra-body-typesetting-article',
90-
// 'nextra-content nx-max-h-[calc(100vh-var(--nextra-navbar-height))]',
91-
)}
92-
style={{ marginTop: '-24px' }}
33+
className={cn('nextra-scrollbar nx-mt-[-24px] nx-h-screen nx-overflow-y-auto nx-break-words')}
9334
>
94-
<main
95-
className="nx-w-full nx-min-w-0 nx-max-w-6xl nx-px-6"
96-
style={{ marginTop: '24px', paddingTop: '24px' }}
97-
>
98-
{/* {breadcrumb} */}
99-
{body}
100-
</main>
35+
<main className="nx-mt-6 nx-w-full nx-min-w-0 nx-max-w-6xl nx-px-6 nx-pt-6">{body}</main>
10136
</article>
10237
)
10338
}

packages/markdown-editor/src/components/modal/modal-wrapper.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useCallback, useEffect, useRef, useState } from 'react'
22
import cn from 'clsx'
3-
import { useModal } from '@/contexts/modal'
43

54
type Props = {
65
children: React.ReactNode
@@ -15,7 +14,6 @@ const style = {
1514
}
1615

1716
export function ModalWrapper({ children, isVisible, onOverlayClick }: Props) {
18-
const { mode } = useModal()
1917
const [isClosed, setIsClosed] = useState(false)
2018
const backdropRef = useRef<HTMLDivElement>(null)
2119
const timeoutId = useRef<NodeJS.Timeout | null>(null)
@@ -29,7 +27,6 @@ export function ModalWrapper({ children, isVisible, onOverlayClick }: Props) {
2927
[onOverlayClick],
3028
)
3129

32-
// TODO: Using React.Potal
3330
useEffect(() => {
3431
if (isVisible) {
3532
setIsClosed(false)
@@ -45,7 +42,6 @@ export function ModalWrapper({ children, isVisible, onOverlayClick }: Props) {
4542
}
4643
}, [isVisible])
4744

48-
if (!mode) return
4945
if (!isVisible && isClosed) return null
5046
return (
5147
<div

packages/markdown-editor/src/components/sidebar/sortable-tree/sortable-item.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const SortableItem = forwardRef<HTMLDivElement, SortableItemProps>((props
7373
setOverItem({ ...item, transform })
7474
}, [isOver, isGhost])
7575

76-
// deleteItem
76+
// deleteItem confirm
7777
useEffect(() => {
7878
if (!isConfirm) return
7979
if (mode !== 'deleteSortableItem') return
@@ -154,7 +154,6 @@ export const SortableItem = forwardRef<HTMLDivElement, SortableItemProps>((props
154154
}
155155

156156
const { ref: menuRef } = useOutsideClick<HTMLDivElement>(onCloseMenu)
157-
158157
return (
159158
<li
160159
{...handleProps}

packages/markdown-editor/src/contexts/modal.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createContext, type ReactNode, useContext, useState } from 'react'
1+
import { createContext, type ReactNode, useContext, useEffect, useRef, useState } from 'react'
22

33
export type ModalMode = 'deleteSortableItem'
44

@@ -32,16 +32,27 @@ export const ModalProvider = ({ children }: { children: ReactNode }) => {
3232
const [isOpen, setIsOpen] = useState<boolean>(false)
3333
const [mode, setMode] = useState<ModalMode | null>(null)
3434
const [isConfirm, setIsConfirm] = useState<boolean>(false)
35+
const timer = useRef<NodeJS.Timeout | null>(null)
3536

37+
useEffect(
38+
() => () => {
39+
if (timer.current) {
40+
clearTimeout(timer.current)
41+
}
42+
},
43+
[],
44+
)
3645
const onOpen = (mode: ModalMode) => {
3746
setIsOpen(true)
3847
setMode(mode)
3948
}
4049

4150
const onClose = () => {
42-
setIsOpen(false)
43-
setMode(null)
44-
setIsConfirm(false)
51+
timer.current = setTimeout(() => {
52+
setIsOpen(false)
53+
setMode(null)
54+
setIsConfirm(false)
55+
}, 100)
4556
}
4657

4758
const value: Modal = {

packages/markdown-editor/src/layouts/layout.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ type NextraDocLayoutProps = NextraThemeLayoutProps & {
1414
export function Layout({ children, editorValue, ...context }: NextraDocLayoutProps): ReactElement {
1515
return (
1616
<ConfigProvider value={context}>
17-
<MarkdownEditorProvider value={{ editorValue }}>
18-
<ModalProvider>
19-
<SidebarProvider>
17+
<ModalProvider>
18+
<SidebarProvider>
19+
<MarkdownEditorProvider value={{ editorValue }}>
2020
<Potals />
2121
<InnerLayout {...context.pageOpts}>{children}</InnerLayout>
22-
</SidebarProvider>
23-
</ModalProvider>
24-
</MarkdownEditorProvider>
22+
</MarkdownEditorProvider>
23+
</SidebarProvider>
24+
</ModalProvider>
2525
</ConfigProvider>
2626
)
2727
}

packages/markdown-editor/src/layouts/lnner-layout.tsx

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useFSRoute } from '@/nextra/hooks'
55
import { normalizePages } from '@/nextra/normalize-pages'
66
import type { PageOpts } from '@/nextra/types'
77
import { useMemo, type ReactElement, type ReactNode } from 'react'
8-
import { Banner, Breadcrumb, Head, Header, NavLinks, Sidebar } from '@/components'
8+
import { Banner, Head, Header, Sidebar } from '@/components'
99
import { MarkdownPreview } from '@/components/markdown-preview'
1010
import { MarkdownEditor } from '@/components/markdown-editor'
1111

@@ -16,26 +16,17 @@ type InnerLayoutProps = PageOpts & {
1616
export const InnerLayout = ({ frontMatter, headings, pageMap }: InnerLayoutProps): ReactElement => {
1717
const fsPath = useFSRoute()
1818

19-
const {
20-
activeType,
21-
activeIndex,
22-
activeThemeContext,
23-
activePath,
24-
docsDirectories,
25-
flatDirectories,
26-
flatDocsDirectories,
27-
directories,
28-
topLevelNavbarItems,
29-
} = useMemo(
30-
() =>
31-
normalizePages({
32-
list: pageMap,
33-
locale: DEFAULT_LOCALE,
34-
defaultLocale: DEFAULT_LOCALE,
35-
route: '/',
36-
}),
37-
[pageMap, fsPath],
38-
)
19+
const { activeThemeContext, docsDirectories, flatDirectories, directories, topLevelNavbarItems } =
20+
useMemo(
21+
() =>
22+
normalizePages({
23+
list: pageMap,
24+
locale: DEFAULT_LOCALE,
25+
defaultLocale: DEFAULT_LOCALE,
26+
route: '/',
27+
}),
28+
[pageMap, fsPath],
29+
)
3930

4031
const themeContext = { ...activeThemeContext, ...frontMatter }
4132
const direction = 'ltr'
@@ -50,13 +41,7 @@ export const InnerLayout = ({ frontMatter, headings, pageMap }: InnerLayoutProps
5041
<Head />
5142
<Banner />
5243
<Header flatDirectories={flatDirectories} items={topLevelNavbarItems} />
53-
<div
54-
className={cn(
55-
'nextra-main',
56-
'nx-mx-auto nx-flex nx-w-full',
57-
themeContext.layout === 'raw' && 'nx-max-w-[90rem] nx-flex-row',
58-
)}
59-
>
44+
<div className={cn('nextra-main', 'nx-mx-auto nx-flex nx-w-full')}>
6045
<ActiveAnchorProvider>
6146
<Sidebar
6247
docsDirectories={docsDirectories}
@@ -71,16 +56,7 @@ export const InnerLayout = ({ frontMatter, headings, pageMap }: InnerLayoutProps
7156
<MarkdownEditor />
7257
</div>
7358
<div className={cn('nextra-preview-container nx-w-1/2')}>
74-
<MarkdownPreview
75-
themeContext={themeContext}
76-
breadcrumb={<Breadcrumb activePath={activePath} />}
77-
timestamp={new Date().getTime()}
78-
navigation={
79-
activeType !== 'page' && themeContext.pagination ? (
80-
<NavLinks flatDirectories={flatDocsDirectories} currentIndex={activeIndex} />
81-
) : null
82-
}
83-
></MarkdownPreview>
59+
<MarkdownPreview />
8460
</div>
8561
</div>
8662
</ActiveAnchorProvider>

packages/markdown-editor/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)