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