feat(toc): add scroll active item
This commit is contained in:
@@ -16,8 +16,8 @@ import {
|
|||||||
getContentByAsyncBlocks,
|
getContentByAsyncBlocks,
|
||||||
getPageTOC,
|
getPageTOC,
|
||||||
} from './toc-util';
|
} from './toc-util';
|
||||||
|
import './toc.css';
|
||||||
import type { ListenerMap, TOCType } from './types';
|
import type { ListenerMap, TOCType } from './types';
|
||||||
|
|
||||||
const StyledTOCItem = styled('a')<{ type?: string; isActive?: boolean }>(
|
const StyledTOCItem = styled('a')<{ type?: string; isActive?: boolean }>(
|
||||||
({ type, isActive }) => {
|
({ type, isActive }) => {
|
||||||
const common = {
|
const common = {
|
||||||
@@ -168,6 +168,11 @@ export const TOC = () => {
|
|||||||
|
|
||||||
const onClick = async (blockId?: string) => {
|
const onClick = async (blockId?: string) => {
|
||||||
setActiveBlockId(blockId);
|
setActiveBlockId(blockId);
|
||||||
|
const block = await editor.getBlockById(blockId);
|
||||||
|
block.dom.classList.add('toc-scroll-item');
|
||||||
|
setTimeout(() => {
|
||||||
|
block.dom.classList.remove('toc-scroll-item');
|
||||||
|
}, 1000);
|
||||||
await editor.scrollManager.scrollIntoViewByBlockId(blockId);
|
await editor.scrollManager.scrollIntoViewByBlockId(blockId);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
.toc-scroll-item {
|
||||||
|
animation: blinker 1s linear;
|
||||||
|
animation-delay: 1s;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes blinker {
|
||||||
|
0% {
|
||||||
|
background: rgba(152, 172, 189, 0.1);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
background: rgba(152, 172, 189, 0.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user