inspector.js
76 lines
| 1 | /** |
| 2 | * Block dependencies |
| 3 | */ |
| 4 | import GiveToggleControl from '../../components/toggle-control/index'; |
| 5 | import GiveSelectControl from '../../components/select-control/index'; |
| 6 | import giveFormOptions from "../data/options"; |
| 7 | |
| 8 | |
| 9 | /** |
| 10 | * Internal dependencies |
| 11 | */ |
| 12 | const { __ } = wp.i18n; |
| 13 | const {InspectorControls,} = wp.blocks; |
| 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.saveSetting = this.saveSetting.bind(this); |
| 26 | } |
| 27 | |
| 28 | saveSetting(event) { |
| 29 | const name = event.target.name; |
| 30 | |
| 31 | this.props.setAttributes( |
| 32 | 'checkbox' === event.target.type ? |
| 33 | { [name]: ! this.props.attributes[name] } : |
| 34 | { [name]: event.target.value } |
| 35 | ); |
| 36 | } |
| 37 | |
| 38 | render(){ |
| 39 | return ( |
| 40 | <InspectorControls key="inspector"> |
| 41 | <PanelBody title={ __( 'Settings' ) }> |
| 42 | <GiveSelectControl |
| 43 | label={ __( 'Columns' ) } |
| 44 | name='columns' |
| 45 | value={ this.props.attributes.columns } |
| 46 | options={ giveFormOptions.columns } |
| 47 | onChange={ this.saveSetting } /> |
| 48 | <GiveToggleControl |
| 49 | name='showExcerpt' |
| 50 | label={ __( 'Show Excerpt' ) } |
| 51 | checked={ !! this.props.attributes.showExcerpt } |
| 52 | onChange={ this.saveSetting } /> |
| 53 | <GiveToggleControl |
| 54 | name='showGoal' |
| 55 | label={ __( 'Show Goal' ) } |
| 56 | checked={ !! this.props.attributes.showGoal } |
| 57 | onChange={ this.saveSetting } /> |
| 58 | <GiveToggleControl |
| 59 | name='showFeaturedImage' |
| 60 | label={ __( 'Show Featured Image' ) } |
| 61 | checked={ !! this.props.attributes.showFeaturedImage } |
| 62 | onChange={ this.saveSetting } /> |
| 63 | <GiveSelectControl |
| 64 | label={ __( 'Display Type' ) } |
| 65 | name='displayType' |
| 66 | value={ this.props.attributes.displayType } |
| 67 | options={ giveFormOptions.displayType } |
| 68 | onChange={ this.saveSetting } /> |
| 69 | </PanelBody> |
| 70 | </InspectorControls> |
| 71 | ); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | export default Inspector; |
| 76 |