Skip to content

Commit

Permalink
fix: scroll into view margin css
Browse files Browse the repository at this point in the history
  • Loading branch information
fbuireu committed Sep 23, 2024
1 parent b072bdb commit d07996d
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Link as LinkIcon } from "@assets/images/svg-components/link";
import { BLOCKS } from "@contentful/rich-text-types";
import type { Block, Text } from "@contentful/rich-text-types";
import { slugify } from "@modules/core/utils/slugify";
import ReactDOMServer from "react-dom/server";

const HEADING_LEVELS = [1, 2, 3, 4, 5, 6];

Expand All @@ -14,15 +12,13 @@ export function parseHeadings() {
BLOCKS[`HEADING_${level}` as keyof typeof BLOCKS],
(node: HeadingBlock) => {
const text = node.content.map((child: Text) => child.value).join("");
const linkIcon = ReactDOMServer.renderToStaticMarkup(<LinkIcon />);
const id = slugify(text);

return `
<h${level} id="${id}"class="article__heading flex flex-start align-baseline">
<a href="#${id}" onclick="window.location.hash='${id}'">
<h${level} id="${id}" class="article__heading flex flex-start align-baseline">
<a href="#${id}">
${text}
</a>
${linkIcon}
</h${level}>
`;
},
Expand Down
1 change: 1 addition & 0 deletions src/pages/articles/_article.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
}

.article__heading {
scroll-margin-block-start: var(--header-height);
gap: 0 0.5rem;

svg {
Expand Down
31 changes: 0 additions & 31 deletions src/ui/assets/images/svg-components/link/Link.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/ui/assets/images/svg-components/link/index.ts

This file was deleted.

0 comments on commit d07996d

Please sign in to comment.