forked from EcrituresNumeriques/stylo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(toc): affiche la table des matières au clique sur l'icone à gauc…
…he du titre resolves EcrituresNumeriques#1088
- Loading branch information
1 parent
b0465af
commit 6cbff3e
Showing
7 changed files
with
98 additions
and
58 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
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,47 @@ | ||
import { Link as GeistLink, Popover } from '@geist-ui/core' | ||
import clsx from 'clsx' | ||
import React, { useCallback } from 'react' | ||
import { AlignLeft } from 'react-feather' | ||
import { useTranslation } from 'react-i18next' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
import { useRouteMatch } from 'react-router-dom' | ||
import { usePandocAnchoring } from '../../hooks/pandoc.js' | ||
import styles from './tableOfContents.module.scss' | ||
|
||
export default function TableOfContents () { | ||
const dispatch = useDispatch() | ||
const { t } = useTranslation() | ||
const articleStructure = useSelector(state => state.articleStructure) | ||
const routeMatch = useRouteMatch() | ||
const getAnchor = usePandocAnchoring() | ||
const hasHtmlAnchors = routeMatch.path === '/article/:id/preview' | ||
const handleTableEntryClick = useCallback(({ target }) => { | ||
hasHtmlAnchors | ||
? document.querySelector(`#${target.dataset.headingAnchor}`)?.scrollIntoView() | ||
: dispatch({ type: 'UPDATE_EDITOR_CURSOR_POSITION', lineNumber: parseInt(target.dataset.index, 10), column: 0 }) | ||
}, [hasHtmlAnchors]) | ||
|
||
const content = () => { | ||
if (articleStructure.length === 0) { | ||
return <></> | ||
} | ||
return <> | ||
<Popover.Item title> | ||
<span>{t('toc.title')}</span> | ||
</Popover.Item> | ||
{articleStructure.map((item) => ( | ||
<Popover.Item key={`line-${item.index}-${item.line}`} tabIndex={0} data-index={item.index} | ||
data-heading-anchor={getAnchor(item.line)}> | ||
<GeistLink href="#" data-index={item.index} onClick={handleTableEntryClick}>{item.title}</GeistLink> | ||
</Popover.Item> | ||
))} | ||
</> | ||
} | ||
|
||
return ( | ||
<Popover className={clsx(styles.tocTooltip, articleStructure.length === 0 && styles.empty)} | ||
placement="bottomStart" | ||
content={content} hideArrow={articleStructure.length === 0}> | ||
<AlignLeft/> | ||
</Popover>) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.tocTooltip.empty { | ||
cursor: not-allowed; | ||
} | ||
|
||
.tocTooltip { | ||
cursor: pointer; | ||
} | ||
|
||
.tocTooltip > svg { | ||
display: flex; | ||
} |
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