inspector.js
74 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 GiveToggleControl from '../../components/toggle-control/index'; |
| 13 | import GiveSelectControl from '../../components/select-control/index'; |
| 14 | import giveFormOptions from '../data/options'; |
| 15 | |
| 16 | /** |
| 17 | * Render Inspector Controls |
| 18 | */ |
| 19 | class Inspector extends Component { |
| 20 | constructor( props ) { |
| 21 | super( props ); |
| 22 | |
| 23 | this.saveSetting = this.saveSetting.bind( this ); |
| 24 | } |
| 25 | |
| 26 | saveSetting( event ) { |
| 27 | const name = event.target.name; |
| 28 | |
| 29 | this.props.setAttributes( |
| 30 | 'checkbox' === event.target.type ? |
| 31 | { [ name ]: ! this.props.attributes[ name ] } : |
| 32 | { [ name ]: event.target.value } |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | render() { |
| 37 | return ( |
| 38 | <InspectorControls key="inspector"> |
| 39 | <PanelBody title={ __( 'Settings' ) }> |
| 40 | <GiveSelectControl |
| 41 | label={ __( 'Columns' ) } |
| 42 | name="columns" |
| 43 | value={ this.props.attributes.columns } |
| 44 | options={ giveFormOptions.columns } |
| 45 | onChange={ this.saveSetting } /> |
| 46 | <GiveToggleControl |
| 47 | name="showExcerpt" |
| 48 | label={ __( 'Show Excerpt' ) } |
| 49 | checked={ !! this.props.attributes.showExcerpt } |
| 50 | onChange={ this.saveSetting } /> |
| 51 | <GiveToggleControl |
| 52 | name="showGoal" |
| 53 | label={ __( 'Show Goal' ) } |
| 54 | checked={ !! this.props.attributes.showGoal } |
| 55 | onChange={ this.saveSetting } /> |
| 56 | <GiveToggleControl |
| 57 | name="showFeaturedImage" |
| 58 | label={ __( 'Show Featured Image' ) } |
| 59 | checked={ !! this.props.attributes.showFeaturedImage } |
| 60 | onChange={ this.saveSetting } /> |
| 61 | <GiveSelectControl |
| 62 | label={ __( 'Display Type' ) } |
| 63 | name="displayType" |
| 64 | value={ this.props.attributes.displayType } |
| 65 | options={ giveFormOptions.displayType } |
| 66 | onChange={ this.saveSetting } /> |
| 67 | </PanelBody> |
| 68 | </InspectorControls> |
| 69 | ); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | export default Inspector; |
| 74 |