chore: add per-level indentation to super note table of contents list

This commit is contained in:
Aman Harwara
2023-10-19 13:39:15 +05:30
parent c3aa5cf9f9
commit 2d4cf6af92
2 changed files with 33 additions and 19 deletions

View File

@@ -50,6 +50,7 @@ import Popover from '@/Components/Popover/Popover'
import LexicalTableOfContents from '@lexical/react/LexicalTableOfContents' import LexicalTableOfContents from '@lexical/react/LexicalTableOfContents'
import Menu from '@/Components/Menu/Menu' import Menu from '@/Components/Menu/Menu'
import MenuItem from '@/Components/Menu/MenuItem' import MenuItem from '@/Components/Menu/MenuItem'
import { remToPx } from '@/Utils'
const TOGGLE_LINK_AND_EDIT_COMMAND = createCommand<string | null>('TOGGLE_LINK_AND_EDIT_COMMAND') const TOGGLE_LINK_AND_EDIT_COMMAND = createCommand<string | null>('TOGGLE_LINK_AND_EDIT_COMMAND')
@@ -693,7 +694,12 @@ const ToolbarPlugin = () => {
return ( return (
<Menu a11yLabel="Table of contents" isOpen className="!px-0"> <Menu a11yLabel="Table of contents" isOpen className="!px-0">
{tableOfContents.map(([key, text, tag]) => ( {tableOfContents.map(([key, text, tag]) => {
const level = parseInt(tag.slice(1)) || 1
if (level > 3) {
return null
}
return (
<MenuItem <MenuItem
key={key} key={key}
className="overflow-hidden md:py-2" className="overflow-hidden md:py-2"
@@ -707,11 +713,15 @@ const ToolbarPlugin = () => {
setIsTOCOpen(false) setIsTOCOpen(false)
}) })
}} }}
style={{
paddingLeft: `${(level - 1) * remToPx(1) + remToPx(0.75)}px`,
}}
> >
<Icon type={tag} className="-mt-px mr-2.5 flex-shrink-0" /> <Icon type={tag} className="-mt-px mr-2.5 flex-shrink-0" />
<span className="overflow-hidden text-ellipsis whitespace-nowrap">{text}</span> <span className="overflow-hidden text-ellipsis whitespace-nowrap">{text}</span>
</MenuItem> </MenuItem>
))} )
})}
</Menu> </Menu>
) )
}} }}

View File

@@ -255,3 +255,7 @@ export function getScrollParent(node: HTMLElement | null): HTMLElement | null {
return getScrollParent(node.parentElement) return getScrollParent(node.parentElement)
} }
} }
export function remToPx(rem: number) {
return rem * parseFloat(getComputedStyle(document.documentElement).fontSize)
}