I am attempting to develop a straightforward collapsible div using styled-components within a react project.
While I have successfully managed to toggle the div's open and close state based on certain conditions, I am facing difficulties in implementing a smooth transition effect. Currently, it abruptly switches between open and closed states without any animation.
Below is the code for the Styled Component:
const Details = styled.div`
transition: 0.3s ease-out;
&.open {
height: auto;
padding: 25px 0;
}
&.closed {
height: 0;
overflow: hidden;
}
`;
And here is the JSX code snippet:
<Details className={this.state.detailsOpen ? 'open' : 'closed'}>
{stuff}
</Details>