Refactoring ul/li

This commit is contained in:
jos 2017-01-05 10:48:32 +01:00
parent 0e490fdeee
commit 9f81dfb2f6
1 changed files with 40 additions and 37 deletions

View File

@ -1,6 +1,7 @@
// @flow weak // @flow weak
import { createElement as h, Component } from 'react' import { createElement as h, Component } from 'react'
import { Element as ScrollElement } from 'react-scroll'
import ActionButton from './menu/ActionButton' import ActionButton from './menu/ActionButton'
import AppendActionButton from './menu/AppendActionButton' import AppendActionButton from './menu/AppendActionButton'
@ -53,26 +54,29 @@ export default class JSONNode extends Component {
if (data.expanded) { if (data.expanded) {
if (data.props.length > 0) { if (data.props.length > 0) {
const props = data.props.map(prop => { const props = data.props.map(prop => {
return h(this.constructor, { return h('li', {key : prop.name},
key: prop.name, h(this.constructor, {
parent: this, parent: this,
prop: prop, prop: prop,
data: prop.value, data: prop.value,
options, options,
events events
}) })
)
}) })
contents.push(h('ul', {key: 'props', className: 'jsoneditor-list'}, props)) contents.push(h('ul', {key: 'props', className: 'jsoneditor-list'}, props))
} }
else { else {
contents.push(h('ul', {key: 'append', className: 'jsoneditor-list'}, contents.push(h('ul', {key: 'append', className: 'jsoneditor-list'},
h('li', {},
this.renderAppend('(empty object)') this.renderAppend('(empty object)')
)
)) ))
} }
} }
return h('li', {}, contents) return h('div', {}, contents)
} }
renderJSONArray ({prop, index, data, options, events}) { renderJSONArray ({prop, index, data, options, events}) {
@ -90,30 +94,32 @@ export default class JSONNode extends Component {
if (data.expanded) { if (data.expanded) {
if (data.items.length > 0) { if (data.items.length > 0) {
const items = data.items.map((child, index) => { const items = data.items.map((child, index) => {
return h(this.constructor, { return h('li', {key : index},
key: index, h(this.constructor, {
parent: this, parent: this,
index, index,
data: child, data: child,
options, options,
events events
}) })
)
}) })
contents.push(h('ul', {key: 'items', className: 'jsoneditor-list'}, items)) contents.push(h('ul', {key: 'items', className: 'jsoneditor-list'}, items))
} }
else { else {
contents.push(h('ul', {key: 'append', className: 'jsoneditor-list'}, contents.push(h('ul', {key: 'append', className: 'jsoneditor-list'},
h('li', {},
this.renderAppend('(empty array)') this.renderAppend('(empty array)')
)
)) ))
} }
} }
return h('li', {}, contents) return h('div', {}, contents)
} }
renderJSONValue ({prop, index, data, options}) { renderJSONValue ({prop, index, data, options}) {
return h('li', {}, return h('div', {className: 'jsoneditor-node'}, [
h('div', {className: 'jsoneditor-node'}, [
this.renderPlaceholder(), this.renderPlaceholder(),
this.renderActionMenuButton(), this.renderActionMenuButton(),
this.renderProperty(prop, index, data, options), this.renderProperty(prop, index, data, options),
@ -121,7 +127,6 @@ export default class JSONNode extends Component {
this.renderValue(data.value, data.searchResult, options), this.renderValue(data.value, data.searchResult, options),
this.renderError(data.error) this.renderError(data.error)
]) ])
)
} }
/** /**
@ -130,13 +135,11 @@ export default class JSONNode extends Component {
* @return {*} * @return {*}
*/ */
renderAppend (text) { renderAppend (text) {
return h('li', {key: 'append'}, return h('div', {className: 'jsoneditor-node'}, [
h('div', {className: 'jsoneditor-node'}, [
this.renderPlaceholder(), this.renderPlaceholder(),
this.renderAppendMenuButton(), this.renderAppendMenuButton(),
this.renderReadonly(text) this.renderReadonly(text)
]) ])
)
} }
renderPlaceholder () { renderPlaceholder () {