Last active
January 29, 2020 02:35
-
-
Save Sensiblemnd/ba70e27d6ea3f1c5273a42c37d1b35b2 to your computer and use it in GitHub Desktop.
accordion.tsx
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"; | |
type AccordionType = { | |
children: React.ReactNode[] | React.ReactNode; | |
}; | |
const Accordion = (props: AccordionType) => { | |
return <div className="accordion">{props.children}</div>; | |
}; | |
//Yay, namespacing! | |
Accordion.Button = (props: AccordionType) => { | |
return <h3 className="accordion__title">{props.children}</h3>; | |
}; | |
Accordion.Panel = (props: AccordionType) => { | |
return <div>{props.children}</div>; | |
}; | |
Accordion.Trigger = (props: AccordionType) => { | |
return <div>{props.children}</div>; | |
}; | |
//You can give your subcomponents any name that you want, and it is what shows up in the dev tools. | |
// @ts-ignore | |
Accordion.Button.displayName = "Accordion.Trigger"; | |
// @ts-ignore | |
Accordion.Panel.displayName = "Accordion.Panel"; | |
export default Accordion; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment