forked from rcdexta/react-trello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewLaneForm.js
58 lines (51 loc) · 1.48 KB
/
NewLaneForm.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
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { LaneTitle, NewLaneButtons, Section } from 'rt/styles/Base'
import { AddButton, CancelButton } from 'rt/styles/Elements'
import NewLaneTitleEditor from 'rt/widgets/NewLaneTitleEditor'
import uuidv1 from 'uuid/v1'
class NewLane extends Component {
handleSubmit = () => {
this.props.onAdd({
id: uuidv1(),
title: this.getValue()
})
}
getValue = () => this.refInput.getValue()
onClickOutside = (a,b,c) => {
if (this.getValue().length > 0) {
this.handleSubmit()
} else {
this.props.onCancel()
}
}
render() {
const { onCancel, t } = this.props
return (
<Section>
<LaneTitle>
<NewLaneTitleEditor
ref={ref => (this.refInput = ref)}
placeholder={t('placeholder.title')}
onCancel={this.props.onCancel}
onSave={this.handleSubmit}
resize='vertical'
border
autoFocus
/>
</LaneTitle>
<NewLaneButtons>
<AddButton onClick={this.handleSubmit}>{t('button.Add lane')}</AddButton>
<CancelButton onClick={onCancel}>{t('button.Cancel')}</CancelButton>
</NewLaneButtons>
</Section>
)
}
}
NewLane.propTypes = {
onCancel: PropTypes.func.isRequired,
onAdd: PropTypes.func.isRequired,
t: PropTypes.func.isRequired,
}
NewLane.defaultProps = {}
export default NewLane