Skip to content

Commit

Permalink
Docs: Improve examples
Browse files Browse the repository at this point in the history
  • Loading branch information
fuma-nama committed Sep 18, 2024
1 parent 7447c75 commit 6759b26
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
1 change: 0 additions & 1 deletion apps/docs/app/layout.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export const docsOptions: DocsLayoutProps = {
nav: {
...baseOptions.nav,
transparentMode: 'none',
children: undefined,
},
links: baseOptions.links?.slice(1),
sidebar: {
Expand Down
9 changes: 3 additions & 6 deletions packages/ui/src/utils/use-toc-thumb.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { type RefObject, useState } from 'react';
import { type RefObject, useEffect, useState } from 'react';
import * as Primitive from 'fumadocs-core/toc';
import { useOnChange } from 'fumadocs-core/utils/use-on-change';

export type TOCThumb = [top: number, height: number];

export function useTocThumb(containerRef: RefObject<HTMLElement>): TOCThumb {
const active = Primitive.useActiveAnchors();
const [pos, setPos] = useState<TOCThumb>([0, 0]);

useOnChange(active, () => {
useEffect(() => {
const container = containerRef.current;
if (active.length === 0 || !container || container.clientHeight === 0) {
setPos([0, 0]);
Expand Down Expand Up @@ -36,9 +35,7 @@ export function useTocThumb(containerRef: RefObject<HTMLElement>): TOCThumb {
parseFloat(styles.paddingBottom),
);
}

setPos([upper, lower - upper]);
});
}, [active, containerRef]);

return pos;
}

0 comments on commit 6759b26

Please sign in to comment.