Created
April 30, 2020 15:44
-
-
Save Debdut/6dd4bf6dd32ea32a060edb90f9e21c38 to your computer and use it in GitHub Desktop.
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
.box { | |
background: #fff; | |
box-sizing: border-box; | |
border: 1px solid #999; | |
float: left; | |
} |
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
import React from 'react' | |
import Draggable from 'react-draggable' | |
import './DraggableRecursion.css' | |
class App extends React.Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
depth: 2 | |
} | |
} | |
addWindow = () => { | |
this.setState({ depth : this.state.depth + 1}) | |
} | |
render() { | |
return ( | |
<div> | |
<button onClick={this.addWindow}>Add Window</button> | |
<div style={{ width: '100vw', height: '100vh', position: 'absolute'}}> | |
<Box depth={this.state.depth} unitSize={100}/> | |
</div> | |
</div> | |
) | |
} | |
} | |
const Box = ({depth, unitSize}) => ( | |
<Draggable cancel={`#box-${depth - 1}`} bounds="parent"> | |
<div className="box" id={`box-${depth}`} style={{ height: unitSize * depth, width: unitSize * depth }}> | |
<span>{depth}</span> | |
{(depth > 1) ? <Box depth={depth - 1} unitSize={unitSize} /> : null} | |
</div> | |
</Draggable> | |
) | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment