-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEditableArea.js
More file actions
59 lines (52 loc) · 1.74 KB
/
EditableArea.js
File metadata and controls
59 lines (52 loc) · 1.74 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React, { Component } from 'react'
import CSSModules from 'react-css-modules'
import Select from 'fe-select'
import styles from './index.styl'
@CSSModules(styles)
export default class extends Component {
renderValue (value) {
return typeof value === 'object' ? JSON.stringify(value) : value
}
handleChange (e) {
if (e === '') {
return false
}
let map = this.props['data-map'].split('-')
this.props.onChange(map, e)
}
handleClickAction (v, a, e) {
e.preventDefault()
this.props.action[a](v)
}
render () {
let props = this.props
let data = props.data
let value = data.value
switch (data.type) {
case 'input':
return <input
data-map={props['data-map']}
type='text'
{...data.props}
disabled={this.props.loading}
value={value}
onChange={this.handleChange.bind(this)} />
case 'select':
return <Select
{...data}
style={Object.assign({}, {width: '100%'}, data.style)}
inputWidth={data.inputWidth || '100%'}
onChange={this.handleChange.bind(this)} />
case 'links':
return <span>
{data.value.map((v, i) => <span key={i}><a {...v.props} target={v.target || '_blank'} href={v.url}>{v.value}</a>{i < data.value.length - 1 ? <span> </span> : null}</span>)}
</span>
case 'action':
return <span>
{data.value.map((v, i) => <span key={i}><a {...v.props} onClick={this.handleClickAction.bind(this, v, v.action)} href='#'>{v.value}</a>{i < data.value.length - 1 ? <span> </span> : null}</span>)}
</span>
default:
return <span data-map={props['data-map']}>{this.renderValue(value)}</span>
}
}
}