Last active
April 10, 2025 15:01
-
-
Save FOLLGAD/67291464aa739667eb8442f14974119a to your computer and use it in GitHub Desktop.
Antd simple headless collapse without the header
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 { HeadlessCollapse } from "./HeadlessCollapse"; | |
| export const Example = () => { | |
| const [expand, setExpand] = useState(false); | |
| return ( | |
| <> | |
| <HeadlessCollapse expanded={expand}> | |
| <p>This is some text! | |
| <button onClick={() => setExpand(false)}>Close</button> | |
| </HeadlessCollapse> | |
| <p>Press this button to open a collapse:</p> | |
| <button onClick={() => setExpand(t => !t)}>Toggle</button> | |
| </> | |
| ) | |
| } |
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 { Collapse } from "antd"; | |
| import React, { FC, PropsWithChildren } from "react"; | |
| import styles from "./styles.module.scss"; | |
| interface Props { | |
| expanded: boolean; | |
| } | |
| export const HeadlessCollapse: FC<PropsWithChildren<Props>> = ({ | |
| expanded, | |
| children, | |
| }) => { | |
| return ( | |
| <Collapse | |
| activeKey={expanded ? ["1"] : []} | |
| bordered={false} | |
| className={styles.collapse} | |
| > | |
| <Collapse.Panel header="" key="1"> | |
| {children} | |
| </Collapse.Panel> | |
| </Collapse> | |
| ); | |
| }; |
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
| .collapse { | |
| transition: background 0.3s ease-in-out; | |
| border-radius: 5px; | |
| padding: 8px; | |
| margin: 0 -8px; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment