Created
July 31, 2019 10:27
-
-
Save PaulieScanlon/cb6e092b72b0336415e81a4d157c1aa5 to your computer and use it in GitHub Desktop.
Gatsby Link activeClassName
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
<ClassNames> | |
{({ css }) => ( | |
<Styled.ul | |
sx={{ | |
padding: 0, | |
margin: 0, | |
}} | |
> | |
{data.allMdx.edges.map((item, index) => { | |
const { name } = item.node.parent | |
return ( | |
<Link | |
key={index} | |
to={`/${name === "index" ? "" : name}`} | |
sx={{ | |
color: "mutedText", | |
display: "flex", | |
paddingTop: 3, | |
paddingBottom: 3, | |
textDecoration: "none", | |
textTransform: "capitalize", | |
transition: ".2s linear all", | |
"::before": { | |
backgroundColor: "background", | |
content: `""`, | |
marginTop: -3, | |
marginBottom: -3, | |
marginRight: 3, | |
width: 2, | |
}, | |
":hover": { | |
color: "text", | |
backgroundColor: "mutedLight", | |
}, | |
}} | |
activeClassName={css` | |
color: ${context.theme.colors.text} !important; | |
&::before { | |
background-color: ${context.theme.colors.primary} !important; | |
} | |
`} | |
> | |
{name === "index" ? "dashboard" : name} | |
</Link> | |
) | |
})} | |
</Styled.ul> | |
)} | |
</ClassNames> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment