index.js
50 lines
| 1 | /** |
| 2 | * Internal dependencies |
| 3 | */ |
| 4 | |
| 5 | const {Component} = wp.element, |
| 6 | {BaseControl} = wp.components, |
| 7 | {withInstanceId} = wp.compose; |
| 8 | |
| 9 | class GiveTextControl extends Component { |
| 10 | constructor(props){ |
| 11 | super( ...props ); |
| 12 | |
| 13 | this.onChangeHandler = this.onChangeHandler.bind( this ); |
| 14 | } |
| 15 | |
| 16 | onChangeHandler(event){ |
| 17 | if ( this.props.onChange ) { |
| 18 | this.props.onChange(event); |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | onBlurHandler(event){ |
| 23 | if ( this.props.onBlur ) { |
| 24 | this.props.onBlur(event); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | render(){ |
| 29 | const { label, name, value, help, instanceId, type = 'text', ...props } = this.props, |
| 30 | id = `inspector-text-control-${ instanceId }`; |
| 31 | |
| 32 | return ( |
| 33 | <BaseControl label={ label } id={ id } help={ help }> |
| 34 | <input className="blocks-text-control__input" |
| 35 | type={ type } |
| 36 | name={ name } |
| 37 | id={ id } |
| 38 | value={ value } |
| 39 | onChange={ this.onChangeHandler } |
| 40 | onBlur={ this.onBlurHandler } |
| 41 | aria-describedby={ !! help ? id + '__help' : undefined } |
| 42 | { ...props } |
| 43 | /> |
| 44 | </BaseControl> |
| 45 | ); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | export default withInstanceId( GiveTextControl ); |
| 50 |