Last active
July 12, 2022 18:39
-
-
Save andyhite/d62bf84e25a02b075a4c1a525282b33b to your computer and use it in GitHub Desktop.
section
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
const Section = ({ icon, title, content, onClickTitle }) => ... | |
const accordionContext = React.createContext(); | |
const Accordion = ({ children }) => { | |
const [openSections, setOpenSection] = useState([]); | |
return ( | |
<div> | |
{children} | |
</div> | |
) | |
} | |
Accordion.Section = (props) => { | |
const styles = { | |
section: css({ | |
marginBottom: open ? 0 : "8px", | |
"&:last-child": { | |
marginBottom: 0, | |
} | |
}), | |
}; | |
return ( | |
<div className={styles.section}> | |
<Section {...props} onClickTitle={() => setOpen(!open)} icon={open ? <DownCaret /> : <UpCaret />} /> | |
</div> | |
) | |
} | |
<Accordion> | |
<form> | |
<div> | |
<Accordion.Section>...</Accordion.Section> | |
<Accordion.Section>...</Accordion.Section> | |
<Accordion.Section>...</Accordion.Section> | |
</div> | |
</form> | |
<Accordion.Section>...</Accordion.Section> | |
<Accordion.Section>...</Accordion.Section> | |
<Accordion.Section>...</Accordion.Section> | |
<form> | |
<Accordion.Section>...</Accordion.Section> | |
<Accordion.Section>...</Accordion.Section> | |
<Accordion.Section>...</Accordion.Section> | |
</form> | |
</Accordion> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment