Add helpText and fix onInput() in LargeTextArea
This commit is contained in:
parent
d9467cfe82
commit
647ba8d114
|
@ -10,6 +10,11 @@ export class LargeTextArea extends Component {
|
||||||
|
|
||||||
PropTypes.checkPropTypes({
|
PropTypes.checkPropTypes({
|
||||||
label: PropTypes.string.isRequired,
|
label: PropTypes.string.isRequired,
|
||||||
|
helpText: PropTypes.oneOfType([
|
||||||
|
PropTypes.string,
|
||||||
|
PropTypes.object,
|
||||||
|
PropTypes.array,
|
||||||
|
]),
|
||||||
value: PropTypes.string.isRequired,
|
value: PropTypes.string.isRequired,
|
||||||
placeholder: PropTypes.string,
|
placeholder: PropTypes.string,
|
||||||
isValid: PropTypes.bool,
|
isValid: PropTypes.bool,
|
||||||
|
@ -45,19 +50,19 @@ export class LargeTextArea extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
onInput (event) {
|
onInput (event) {
|
||||||
const val = event.currentTarget.value;
|
const val = event.target.value;
|
||||||
|
|
||||||
if (val !== this.state.value) {
|
if (val !== this.state.value) {
|
||||||
this.setState({ value: val }, () => {
|
this.setState({ value: val }, () => {
|
||||||
if (this.props.onInput) {
|
if (this.props.onInput) {
|
||||||
this.props.onInput(this.state.value);
|
this.props.onInput(event);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderTextarea () {
|
renderTextarea () {
|
||||||
const { placeholder, isValid, onChange } = this.props;
|
const { placeholder, isValid = true, onChange } = this.props;
|
||||||
return (
|
return (
|
||||||
<textarea className={ `textarea ${(!isValid) ? 'is-danger' : ''}` }
|
<textarea className={ `textarea ${(!isValid) ? 'is-danger' : ''}` }
|
||||||
placeholder={ placeholder || '' }
|
placeholder={ placeholder || '' }
|
||||||
|
@ -71,43 +76,32 @@ export class LargeTextArea extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { label, isValid, invalidText } = this.props;
|
const { label, helpText, isValid = true, invalidText } = this.props;
|
||||||
|
|
||||||
// if (this.state.isMaximized) {
|
|
||||||
// return (
|
|
||||||
// <div className='large-modal is-active'>
|
|
||||||
// <div className='modal-background' onClick={ this.minimize.bind(this) } />
|
|
||||||
// <div className='large-modal-card'>
|
|
||||||
// <header className='modal-card-head'>
|
|
||||||
// <span className='modal-card-title'>
|
|
||||||
// { label }
|
|
||||||
// </span>
|
|
||||||
// <button className='delete'
|
|
||||||
// aria-label='close'
|
|
||||||
// onClick={ this.minimize.bind(this) }
|
|
||||||
// />
|
|
||||||
// </header>
|
|
||||||
// { this.renderTextarea() }
|
|
||||||
// <footer className='modal-card-foot is-small' />
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='field'>
|
<div className='field'>
|
||||||
<label className='label'>
|
<label className='label'>
|
||||||
{ label }
|
{ label }
|
||||||
<a className='button is-small is-pulled-right is-inline' onClick={ this.maximize.bind(this) }>
|
<a className='button is-small is-pulled-right is-inline'
|
||||||
|
title='Maximize'
|
||||||
|
aria-label={`Maximize ${label}`}
|
||||||
|
onClick={ this.maximize.bind(this) }>
|
||||||
<span className='icon'><i className='fa fa-expand' /></span>
|
<span className='icon'><i className='fa fa-expand' /></span>
|
||||||
</a>
|
</a>
|
||||||
</label>
|
</label>
|
||||||
|
{helpText
|
||||||
|
&& (
|
||||||
|
<div className='help'>
|
||||||
|
{ helpText }
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
<div className='control'>
|
<div className='control'>
|
||||||
{ this.renderTextarea() }
|
{ this.renderTextarea() }
|
||||||
{(!isValid)
|
{(!isValid)
|
||||||
? (
|
? (
|
||||||
<span className='help is-danger'>
|
<span className='help is-danger'>
|
||||||
{ invalidText }
|
{ invalidText || 'Invalid' }
|
||||||
</span>
|
</span>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
@ -121,7 +115,7 @@ export class LargeTextArea extends Component {
|
||||||
{ label }
|
{ label }
|
||||||
</span>
|
</span>
|
||||||
<button className='delete'
|
<button className='delete'
|
||||||
aria-label='close'
|
aria-label={`Minimize ${label}`}
|
||||||
onClick={ this.minimize.bind(this) }
|
onClick={ this.minimize.bind(this) }
|
||||||
/>
|
/>
|
||||||
</header>
|
</header>
|
||||||
|
|
Loading…
Reference in New Issue