-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharray.jsx
More file actions
33 lines (23 loc) · 1.09 KB
/
array.jsx
File metadata and controls
33 lines (23 loc) · 1.09 KB
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
import React from 'react';
import { StyleSheet, css } from 'aphrodite';
import Value from '../';
export default function ArrayValue ({ value, theme, referenceTracker, path }) {
// pre-register our children at their depth
value.forEach((v, index) => referenceTracker.addReference(v, path.push(index)));
const array = Array.isArray(value) ? value : Array.from(value);
const arrayType = value.constructor.name;
const style = StyleSheet.create(theme.array);
return <div className={ css(style.arrayContainer) }>
<div className={ css(style.arrayLabel) }>{ arrayType }</div>
<div className={ css(style.arrayItems) }>
{ array.map((x, i) =>
<div key={ i } className={ css(style.arrayItem) }>
<div className={ css(style.arrayIndex) }>{ i }</div>
<div className={ css(style.arrayValue) }>
<Value value={ x } theme={ theme } referenceTracker={ referenceTracker } path={ path.push(i) } />
</div>
</div>
) }
</div>
</div>;
}