Now using Tippy for Tooltips + prettier integration #11

Merged
DrMint merged 9 commits from develop into main 2022-03-13 15:26:56 +00:00
4 changed files with 33 additions and 5 deletions
Showing only changes of commit f89dbb36e9 - Show all commits

View File

@ -21,6 +21,30 @@ export default function Markdawn(props: ScenBreakProps): JSX.Element {
options={{
slugify: slugify,
overrides: {
h2: {
component: (props: { id: string; children: React.ReactNode }) => {
return (
<div className="flex flex-row place-items-center place-content-center gap-3 hover:[--anchor-opacity:100] [--anchor-opacity:0]">
<h2 id={props.id}>{props.children}</h2>
<abbr title="Copy anchor link">
<span
className="material-icons opacity-[var(--anchor-opacity)] transition-all hover:text-dark cursor-pointer"
onClick={() => {
navigator.clipboard.writeText(
process.env.NEXT_PUBLIC_URL_SELF +
window.location.pathname +
"#" +
props.id
);
}}
>
link
</span>
</abbr>
</div>
);
},
},
Sep: {
component: () => {
return <div className="my-24"></div>;

View File

@ -1,20 +1,23 @@
import { NextRouter } from "next/router";
import { slugify } from "queries/helpers";
import { preprocessMarkDawn } from "./Markdawn";
type TOCProps = {
text: string;
title?: string;
router: NextRouter;
};
export default function TOC(props: TOCProps): JSX.Element {
const toc = getTocFromMarkdawn(preprocessMarkDawn(props.text), props.title);
const { router, text, title } = props;
const toc = getTocFromMarkdawn(preprocessMarkDawn(text), title);
return (
<div>
<h3 className="text-xl">Table of content</h3>
<ol className="text-left">
<li className="my-2 overflow-x-hidden w-full text-ellipsis whitespace-nowrap">
<a className="" href={`#${toc.slug}`}>
<a className="" onClick={() => router.replace(`#${toc.slug}`)}>
{<abbr title={toc.title}>{toc.title}</abbr>}
</a>
</li>
@ -25,7 +28,7 @@ export default function TOC(props: TOCProps): JSX.Element {
className="my-2 overflow-x-hidden w-full text-ellipsis whitespace-nowrap"
>
<span className="text-dark">{`${h2Index + 1}. `}</span>
<a href={`#${h2.slug}`}>
<a onClick={() => router.replace(`#${h2.slug}`)}>
{<abbr title={h2.title}>{h2.title}</abbr>}
</a>
</li>
@ -38,7 +41,7 @@ export default function TOC(props: TOCProps): JSX.Element {
<span className="text-dark">{`${h2Index + 1}.${
h3Index + 1
}. `}</span>
<a href={`#${h3.slug}`}>
<a onClick={() => router.replace(`#${h3.slug}`)}>
{<abbr title={h3.title}>{h3.title}</abbr>}
</a>
</li>

View File

@ -148,6 +148,7 @@ export default function ContentRead(props: ContentReadProps): JSX.Element {
<HorizontalLine />
<TOC
text={content.text_set[0].text}
router={router}
title={
content.titles.length > 0
? prettyinlineTitle(

View File

@ -17,7 +17,7 @@
}
a {
@apply transition-colors underline-offset-2 decoration-dotted underline decoration-dark hover:text-dark;
@apply transition-colors underline-offset-2 decoration-dotted underline decoration-dark hover:text-dark cursor-pointer;
}
*::selection {