From 1708533f7952a79ff99a6f2ae55b080926b81093 Mon Sep 17 00:00:00 2001 From: Innei Date: Fri, 30 Aug 2024 15:29:00 +0800 Subject: [PATCH] fix: toc item rounded corner when range is small Signed-off-by: Innei --- .../components/ui/markdown/components/Toc.tsx | 10 ++++++---- .../ui/markdown/components/TocItem.tsx | 17 +++++++++-------- .../src/modules/entry-content/index.tsx | 7 ++++++- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/renderer/src/components/ui/markdown/components/Toc.tsx b/src/renderer/src/components/ui/markdown/components/Toc.tsx index 8339dba06..f17aea1a0 100644 --- a/src/renderer/src/components/ui/markdown/components/Toc.tsx +++ b/src/renderer/src/components/ui/markdown/components/Toc.tsx @@ -134,7 +134,7 @@ export const Toc: Component = ({ className }) => { const [start, end] = currentRange // current top is this range, the precent is ? - const precent = ((actualTop - start) / (end - start)) + const precent = (actualTop - start) / (end - start) // console.log("currentRange", currentRange, precent) // position , precent @@ -174,7 +174,7 @@ export const Toc: Component = ({ className }) => { open={hoverShow} onOpenChange={setHoverShow} > - +
    { {toc.map((heading, index) => ( { animate={{ opacity: 1, x: 100 }} exit={{ opacity: 0, x: 110, transition: { duration: 0.1 } }} transition={{ duration: 0.5, type: "spring" }} - className="relative z-10 -mt-1 rounded-xl border bg-white px-3 py-1 text-xs drop-shadow-xl dark:bg-neutral-950" + className={cn( + "relative z-10 -mt-1 rounded-xl border bg-white px-3 py-1 text-xs drop-shadow-xl dark:bg-neutral-950", + "max-h-[calc(100svh-4rem)] overflow-auto scrollbar-none", + )} > {toc.map((heading, index) => (
  • = memo((props) => { isScrollOut && "dark:bg-zinc-700", !!range && "!bg-zinc-400/50 data-[active=true]:group-hover:!bg-zinc-500 dark:!bg-zinc-600", + "overflow-hidden", )} > @@ -72,12 +73,12 @@ export const TocItem: FC = memo((props) => { }) const widthMap = { - 1: 72, - 2: 60, - 3: 48, - 4: 36, - 5: 24, - 6: 12, + 1: 72 - 6, + 2: 60 - 6, + 3: 48 - 6, + 4: 36 - 6, + 5: 24 - 6, + 6: 12 - 6, } TocItem.displayName = "TocItem" diff --git a/src/renderer/src/modules/entry-content/index.tsx b/src/renderer/src/modules/entry-content/index.tsx index 5d0316231..c900a05a3 100644 --- a/src/renderer/src/modules/entry-content/index.tsx +++ b/src/renderer/src/modules/entry-content/index.tsx @@ -443,7 +443,12 @@ const ContainerToc: FC = () => {
    - +