Skip to content

Instantly share code, notes, and snippets.

@vanaf1979
Last active September 22, 2019 14:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save vanaf1979/b5326c02f9cdc56204838490e280cc48 to your computer and use it in GitHub Desktop.
Gist for my tutorial: Building a Gutenberg sidebar plugin Part 4: Adding form components. https://vanaf1979.nl/building-a-gutenberg-sidebar-plugin-part-4-adding-form-components/
/**
* External dependencies.
*/
import React from 'react'
/**
* WordPress dependencies.
*/
const { __ } = wp.i18n;
const { compose } = wp.compose;
const { withDispatch, withSelect } = wp.data;
const { TextareaControl } = wp.components;
/**
* Meta description input component.
*
* @since 1.0.0
*/
class MetaDescriptionField extends React.Component {
constructor() {
super()
}
render() {
return (
<div className="metatags-browser-title-field">
<TextareaControl
label={__("Meta description", "metatags")}
value={this.props.metaFieldValue}
onChange={this.props.setMetaFieldValue}
/>
</div>
)
}
}
export default compose([
withDispatch(( dispatch , props ) => {
return {
setMetaFieldValue: function( value ) {
dispatch( 'core/editor' ).editPost( { meta: { metatags_description_field: value } } );
}
}
}),
withSelect(( select , props ) => {
return {
metaFieldValue: select( 'core/editor' ).getEditedPostAttribute( 'meta' )[ 'metatags_description_field' ],
};
}),
])( MetaDescriptionField );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment