-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make scroll position in sidebar stable between client side navig…
…ation (#4296) * fix: sidebar is scrolled on client side navigation * improve comment * more * upd * upd * upd * fixes * Update .changeset/silver-numbers-call.md * Update packages/nextra-theme-docs/src/components/sidebar.tsx * Update packages/nextra-theme-docs/src/components/sidebar.tsx * oops
- Loading branch information
1 parent
05a202d
commit fd4e6d1
Showing
11 changed files
with
83 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"nextra-theme-docs": patch | ||
--- | ||
|
||
fix: make scroll position in sidebar stable between client-side navigation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
'use no memo' | ||
'use client' | ||
|
||
import type { Heading } from 'nextra' | ||
import type { Dispatch } from 'react' | ||
import { create } from 'zustand' | ||
import type { ComponentProps } from 'react' | ||
import { createContext, createElement, useContext } from 'react' | ||
|
||
const useTocStore = create<{ | ||
toc: Heading[] | ||
}>(() => ({ | ||
toc: [] | ||
})) | ||
const TOCContext = createContext<Heading[]>([]) | ||
|
||
export const useToc = () => useTocStore(state => state.toc) | ||
export const useTOC = () => useContext(TOCContext) | ||
|
||
export const setToc: Dispatch<Heading[]> = toc => { | ||
useTocStore.setState({ toc }) | ||
} | ||
export const TOCProvider = ( | ||
props: ComponentProps<typeof TOCContext.Provider> | ||
) => createElement(TOCContext.Provider, props) |