Skip to content

Instantly share code, notes, and snippets.

@dan-maximov
Created August 29, 2019 10:24
Show Gist options
  • Save dan-maximov/706bd673508e7f8812871157be2ebbec to your computer and use it in GitHub Desktop.
Save dan-maximov/706bd673508e7f8812871157be2ebbec to your computer and use it in GitHub Desktop.
JS-less React Accordeon
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