| 3 | import { HorizontalLayout } from 'core/layouts'; |
| 4 | |
| 5 | class Layout { |
| 6 | constructor(key, getObject, children) { |
| 7 | this.key = key; |
| 8 | this.getObject = getObject; |
| 9 | this.children = children.map(key => this.getObject(key)); |
| 10 | this.weights = children.map(() => 1); |
| 11 | this.ref = React.createRef(); |
| 12 | |
| 13 | this.handleChangeWeights = this.handleChangeWeights.bind(this); |
| 14 | } |
| 15 | |
| 16 | add(key, index = this.children.length) { |
| 17 | const child = this.getObject(key); |
| 18 | this.children.splice(index, 0, child); |
| 19 | this.weights.splice(index, 0, 1); |
| 20 | } |
| 21 | |
| 22 | remove(key) { |
| 23 | const child = this.getObject(key); |
| 24 | const index = this.children.indexOf(child); |
| 25 | if (~index) { |
| 26 | this.children.splice(index, 1); |
| 27 | this.weights.splice(index, 1); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | removeAll() { |
| 32 | this.children = []; |
| 33 | this.weights = []; |
| 34 | } |
| 35 | |
| 36 | handleChangeWeights(weights) { |
| 37 | this.weights.splice(0, this.weights.length, ...weights); |
| 38 | this.ref.current.forceUpdate(); |
| 39 | } |
| 40 | |
| 41 | render() { |
| 42 | const horizontal = this instanceof HorizontalLayout; |
| 43 | |
| 44 | return ( |
| 45 | <ResizableContainer key={this.key} ref={this.ref} weights={this.weights} horizontal={horizontal} |
| 46 | onChangeWeights={this.handleChangeWeights}> |
| 47 | { |
| 48 | this.children.map(tracer => tracer && tracer.render()) |
| 49 | } |
| 50 | </ResizableContainer> |
| 51 | ); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | export default Layout; |
nothing calls this directly
no outgoing calls
no test coverage detected