I am working on creating a draggable split panel for an editor, similar to the behavior of the Console
panel in CodeSandbox:
- Clicking on
Console
expands the panel and changes the arrow toArrowDown
to close it. - The border of the panel is draggable.
- If you click on
Console
when the panel is expanded, it will collapse and change the arrow toArrowUp
to expand it again.
I have found some code (https://codesandbox.io/s/reset-forked-ydhy97?file=/src/App.js:0-927) by https://github.com/johnwalley/allotment. However, I am facing an issue where the prop preferredSize
does not update according to this.state.toExpand
.
Can anyone help me understand why this is happening?
import React from "react";
import { Allotment } from "allotment";
import "allotment/dist/style.css";
import styles from "./App.module.css";
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
toExpand: true
};
}
render() {
return (
<div>
<div className={styles.container}>
<Allotment vertical>
<Allotment.Pane>Main Area</Allotment.Pane>
<Allotment.Pane preferredSize={this.state.toExpand ? "0%" : "50%"}>
<div
onClick={() => {
this.setState({ toExpand: !this.state.toExpand });
}}
>
Console
{this.state.toExpand ? "ArrowUp" : "ArrowDown"}
</div>
</Allotment.Pane>
</Allotment>
</div>
</div>
);
}
}