Created
August 29, 2019 10:24
-
-
Save dan-maximov/706bd673508e7f8812871157be2ebbec to your computer and use it in GitHub Desktop.
JS-less React Accordeon
This file contains hidden or 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
import React from 'react'; | |
import styled from 'styled-components'; | |
const Header = styled.label` | |
cursor: pointer; | |
`; | |
const Title = styled.p` | |
`; | |
const Content = styled.div` | |
display: none; | |
`; | |
const HiddenCheckbox = styled.input` | |
display: none; | |
&:checked + ${Header} + ${Content} { | |
display: block; | |
} | |
`; | |
const Accordeon = ({ title, children }) => ( | |
<> | |
<HiddenCheckbox type="checkbox" id={title} /> | |
<Header htmlFor={title}> | |
<Title>{title}</Title> | |
</Header> | |
<Content>{children}</Content> | |
</> | |
); | |
export default Accordeon; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment