|
1 | | -import React, {Component} from 'react' |
| 1 | +import React, { Component } from 'react' |
2 | 2 | import PropTypes from 'prop-types' |
3 | | -import {LaneTitle, NewLaneButtons, Section} from 'rt/styles/Base' |
4 | | -import {AddButton, CancelButton} from 'rt/styles/Elements' |
5 | | -import EditableLabel from 'rt/widgets/EditableLabel' |
| 3 | +import { LaneTitle, NewLaneButtons, Section } from 'rt/styles/Base' |
| 4 | +import { AddButton, CancelButton } from 'rt/styles/Elements' |
| 5 | +import NewLaneTitleEditor from 'rt/widgets/NewLaneTitleEditor' |
| 6 | +import ClickOutside from 'react-click-outside' |
6 | 7 |
|
7 | | -class NewLaneForm extends Component { |
8 | | - updateField = (field, value) => { |
9 | | - this.setState({[field]: value}) |
| 8 | +class NewLane extends Component { |
| 9 | + handleSubmit = () => { |
| 10 | + this.props.onAdd({ title: this.getValue() }) |
10 | 11 | } |
11 | 12 |
|
12 | | - handleAdd = () => { |
13 | | - this.props.onAdd(this.state) |
| 13 | + getValue = () => this.refInput.getValue() |
| 14 | + |
| 15 | + onClickOutside = (a,b,c) => { |
| 16 | + if (this.getValue().length > 0) { |
| 17 | + this.handleSubmit() |
| 18 | + } else { |
| 19 | + this.props.onCancel() |
| 20 | + } |
14 | 21 | } |
15 | 22 |
|
16 | 23 | render() { |
17 | | - const {onCancel, t} = this.props |
| 24 | + const { onCancel, t } = this.props |
18 | 25 | return ( |
| 26 | + <ClickOutside onClickOutside={this.onClickOutside}> |
19 | 27 | <Section> |
20 | 28 | <LaneTitle> |
21 | | - <EditableLabel placeholder={t('placeholder.title')} onChange={val => this.updateField('title', val)} autoFocus/> |
| 29 | + <NewLaneTitleEditor |
| 30 | + ref={ref => (this.refInput = ref)} |
| 31 | + placeholder={t('placeholder.title')} |
| 32 | + onCancel={this.props.onCancel} |
| 33 | + onSave={this.handleSubmit} |
| 34 | + resize='vertical' |
| 35 | + border |
| 36 | + autoFocus |
| 37 | + /> |
22 | 38 | </LaneTitle> |
23 | 39 | <NewLaneButtons> |
24 | | - <AddButton onClick={this.handleAdd}>{t('button.Add lane')}</AddButton> |
| 40 | + <AddButton onClick={this.handleSubmit}>{t('button.Add lane')}</AddButton> |
25 | 41 | <CancelButton onClick={onCancel}>{t('button.Cancel')}</CancelButton> |
26 | 42 | </NewLaneButtons> |
27 | 43 | </Section> |
| 44 | + </ClickOutside> |
28 | 45 | ) |
29 | 46 | } |
30 | 47 | } |
31 | 48 |
|
32 | | -NewLaneForm.propTypes = { |
| 49 | +NewLane.propTypes = { |
33 | 50 | onCancel: PropTypes.func.isRequired, |
34 | 51 | onAdd: PropTypes.func.isRequired, |
35 | | - t: PropTypes.func.isRequired |
| 52 | + t: PropTypes.func.isRequired, |
36 | 53 | } |
37 | | -NewLaneForm.defaultProps = {} |
38 | 54 |
|
39 | | -export default NewLaneForm |
| 55 | +NewLane.defaultProps = {} |
| 56 | + |
| 57 | +export default NewLane |
0 commit comments