form
7 years ago
scss
8 years ago
block.js
7 years ago
controls.js
7 years ago
inspector.js
7 years ago
inspector.js
96 lines
| 1 | /** |
| 2 | * Wordpress dependencies |
| 3 | */ |
| 4 | const { __ } = wp.i18n; |
| 5 | const { InspectorControls } = wp.editor; |
| 6 | const { PanelBody } = wp.components; |
| 7 | const { Component } = wp.element; |
| 8 | |
| 9 | /** |
| 10 | * Internal dependencies |
| 11 | */ |
| 12 | import GiveTextControl from '../../components/text-control'; |
| 13 | import GiveToggleControl from '../../components/toggle-control'; |
| 14 | import GiveSelectControl from '../../components/select-control'; |
| 15 | import giveFormOptions from '../data/options'; |
| 16 | |
| 17 | /** |
| 18 | * Render Inspector Controls |
| 19 | */ |
| 20 | |
| 21 | class Inspector extends Component { |
| 22 | constructor( props ) { |
| 23 | super( props ); |
| 24 | |
| 25 | this.state = { |
| 26 | continueButtonTitle: this.props.attributes.continueButtonTitle, |
| 27 | }; |
| 28 | |
| 29 | this.saveSetting = this.saveSetting.bind( this ); |
| 30 | this.saveState = this.saveState.bind( this ); |
| 31 | } |
| 32 | |
| 33 | saveSetting( event ) { |
| 34 | const name = event.target.name; |
| 35 | |
| 36 | this.props.setAttributes( |
| 37 | 'checkbox' === event.target.type ? |
| 38 | { [ name ]: ! this.props.attributes[ name ] } : |
| 39 | { [ name ]: event.target.value } |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | saveState( event ) { |
| 44 | this.setState( { [ event.target.name ]: event.target.value } ); |
| 45 | } |
| 46 | |
| 47 | render() { |
| 48 | return ( |
| 49 | <InspectorControls key="inspector"> |
| 50 | <PanelBody title={ __( 'Display' ) }> |
| 51 | <GiveSelectControl |
| 52 | label={ __( 'Form Format' ) } |
| 53 | name="displayStyle" |
| 54 | value={ this.props.attributes.displayStyle } |
| 55 | options={ giveFormOptions.displayStyles } |
| 56 | onChange={ this.saveSetting } /> |
| 57 | { |
| 58 | 'reveal' === this.props.attributes.displayStyle && ( |
| 59 | <GiveTextControl |
| 60 | name="continueButtonTitle" |
| 61 | label={ __( 'Continue Button Title' ) } |
| 62 | value={ this.state.continueButtonTitle } |
| 63 | onChange={ this.saveState } |
| 64 | onBlur={ this.saveSetting } /> |
| 65 | ) |
| 66 | } |
| 67 | </PanelBody> |
| 68 | <PanelBody title={ __( 'Settings' ) }> |
| 69 | <GiveToggleControl |
| 70 | label={ __( 'Goal' ) } |
| 71 | name="showGoal" |
| 72 | checked={ !! this.props.attributes.showGoal } |
| 73 | onChange={ this.saveSetting } /> |
| 74 | <GiveToggleControl |
| 75 | label={ __( 'Content' ) } |
| 76 | name="contentDisplay" |
| 77 | checked={ !! this.props.attributes.contentDisplay } |
| 78 | onChange={ this.saveSetting } /> |
| 79 | { |
| 80 | this.props.attributes.contentDisplay && ( |
| 81 | <GiveSelectControl |
| 82 | label={ __( 'Content Position' ) } |
| 83 | name="showContent" |
| 84 | value={ this.props.attributes.showContent } |
| 85 | options={ giveFormOptions.contentPosition } |
| 86 | onChange={ this.saveSetting } /> |
| 87 | ) |
| 88 | } |
| 89 | </PanelBody> |
| 90 | </InspectorControls> |
| 91 | ); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | export default Inspector; |
| 96 |