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