-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from primer/rezrah/add-mdx-overrides
add mdx overrides and heading anchors
- Loading branch information
Showing
8 changed files
with
112 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
--- | ||
'@primer/doctocat-nextjs': patch | ||
'doctocat-nextjs-site': patch | ||
--- | ||
|
||
Wrap links with Next's Link component |
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,6 @@ | ||
--- | ||
'@primer/doctocat-nextjs': patch | ||
--- | ||
|
||
- Add MDX to HTML overrides mechanism and apply to headings and anchors | ||
- Added anchor links to headings to match current functionality on primer.style |
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
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
14 changes: 14 additions & 0 deletions
14
packages/theme/components/mdx-components/mdx-components.module.css
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,14 @@ | ||
.Heading__anchor { | ||
color: var(--brand-color-text-default) !important; | ||
text-decoration: none !important; | ||
} | ||
|
||
.Heading__anchorIcon { | ||
visibility: hidden; | ||
margin-left: var(--base-size-8); | ||
vertical-align: middle !important; | ||
} | ||
|
||
.Heading__anchor:hover .Heading__anchorIcon { | ||
visibility: visible; | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/theme/components/mdx-components/mdx-components.tsx
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,43 @@ | ||
import React from 'react' | ||
import type {ComponentProps, ReactElement} from 'react' | ||
import clsx from 'clsx' | ||
import type {Components} from 'nextra/mdx' | ||
|
||
import {LinkIcon} from '@primer/octicons-react' | ||
import NextLink from 'next/link' | ||
|
||
import styles from './mdx-components.module.css' | ||
|
||
// Anchor links for Headings | ||
function HeadingLink({ | ||
tag: Tag, | ||
context, | ||
children, | ||
id, | ||
className, | ||
...props | ||
}: ComponentProps<'h2'> & { | ||
tag: `h${2 | 3 | 4 | 5 | 6}` | ||
context: {index: number} | ||
}): ReactElement { | ||
return ( | ||
<Tag {...props} id={id} className={clsx(className)}> | ||
<NextLink href={`#${id}`} className={styles.Heading__anchor}> | ||
{children} <LinkIcon className={styles.Heading__anchorIcon} size={16} /> | ||
</NextLink> | ||
</Tag> | ||
) | ||
} | ||
|
||
export const Link = ({href = '', className, ...props}) => <NextLink href={href} {...props} /> | ||
export const getComponents = (): Components => { | ||
const context = {index: 0} | ||
return { | ||
h2: props => <HeadingLink tag="h2" context={context} {...props} />, | ||
h3: props => <HeadingLink tag="h3" context={context} {...props} />, | ||
h4: props => <HeadingLink tag="h4" context={context} {...props} />, | ||
h5: props => <HeadingLink tag="h5" context={context} {...props} />, | ||
h6: props => <HeadingLink tag="h6" context={context} {...props} />, | ||
a: Link, | ||
} | ||
} |