-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: heading hash link with hash router config
- Loading branch information
1 parent
ef6de9d
commit 7d7f557
Showing
6 changed files
with
29 additions
and
40 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 |
---|---|---|
@@ -1,29 +1,12 @@ | ||
import matter from 'remark-frontmatter' | ||
import slug from 'rehype-slug' | ||
import headings from 'rehype-autolink-headings' | ||
import remarkDocz from 'remark-docz' | ||
import rehypeDocz from 'rehype-docz' | ||
|
||
export const config = { | ||
type: 'yaml', | ||
marker: '-', | ||
properties: { | ||
'aria-hidden': true, | ||
}, | ||
content: { | ||
type: 'element', | ||
tagName: 'span', | ||
properties: { | ||
className: ['icon-link'], | ||
}, | ||
children: [ | ||
{ | ||
type: 'text', | ||
value: '#', | ||
}, | ||
], | ||
}, | ||
} | ||
|
||
export const remarkPlugins = [matter, remarkDocz] | ||
export const rehypePlugins = [rehypeDocz, slug, headings] | ||
export const rehypePlugins = [rehypeDocz, slug] |
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,20 +1,34 @@ | ||
import * as React from 'react' | ||
import { SFC } from 'react' | ||
import styled from 'react-emotion' | ||
import Hash from 'react-feather/dist/icons/hash' | ||
import { Link } from 'docz' | ||
|
||
export const H2 = styled('h2')` | ||
const Icon = styled(Hash)` | ||
position: absolute; | ||
display: inline-block; | ||
top: 11px; | ||
left: -28px; | ||
opacity: 0; | ||
transition: opacity 0.2s; | ||
color: ${p => p.theme.docz.colors.primary}; | ||
` | ||
|
||
const Heading = styled('h2')` | ||
position: relative; | ||
margin: 50px 0 20px; | ||
${p => p.theme.docz.mq(p.theme.docz.styles.h2)}; | ||
.icon-link { | ||
position: absolute; | ||
display: inline-block; | ||
top: 0; | ||
left: -25px; | ||
opacity: 0; | ||
transition: opacity 0.2s; | ||
} | ||
&:hover .icon-link { | ||
&:hover ${Icon.toString()} { | ||
opacity: 1; | ||
} | ||
` | ||
|
||
export const H2: SFC<React.HTMLAttributes<any>> = ({ children, ...props }) => ( | ||
<Heading {...props}> | ||
<Link aria-hidden to={{ hash: `#${props.id}` }}> | ||
<Icon height={20} /> | ||
</Link> | ||
{children} | ||
</Heading> | ||
) |
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