-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Tree.js
45 lines (39 loc) · 1.09 KB
/
Tree.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { BenchmarkType } from '../app/Benchmark'
import { number, object } from 'prop-types'
import React, { Component } from 'react'
class Tree extends Component {
static displayName = 'Tree'
static benchmarkType = BenchmarkType.MOUNT
static propTypes = {
breadth: number.isRequired,
components: object,
depth: number.isRequired,
id: number.isRequired,
wrap: number.isRequired
}
render() {
const { breadth, components, depth, id, wrap } = this.props
const { Box } = components
let result = (
<Box color={id % 3} layout={depth % 2 === 0 ? 'column' : 'row'} outer>
{depth === 0 && <Box color={(id % 3) + 3} fixed />}
{depth !== 0 &&
Array.from({ length: breadth }).map((el, i) => (
<Tree
breadth={breadth}
components={components}
depth={depth - 1}
id={i}
key={i}
wrap={wrap}
/>
))}
</Box>
)
for (let i = 0; i < wrap; i++) {
result = <Box>{result}</Box>
}
return result
}
}
export default Tree