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