summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/extensions/blocks/sharing/sharing-checkbox.js')
-rw-r--r--plugins/jetpack/extensions/blocks/sharing/sharing-checkbox.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/plugins/jetpack/extensions/blocks/sharing/sharing-checkbox.js b/plugins/jetpack/extensions/blocks/sharing/sharing-checkbox.js
new file mode 100644
index 00000000..dfe1e6c5
--- /dev/null
+++ b/plugins/jetpack/extensions/blocks/sharing/sharing-checkbox.js
@@ -0,0 +1,45 @@
+/**
+ * External dependencies
+ */
+import { __ } from '@wordpress/i18n';
+import { CheckboxControl } from '@wordpress/components';
+import { compose } from '@wordpress/compose';
+import { PostTypeSupportCheck } from '@wordpress/editor';
+import { withDispatch, withSelect } from '@wordpress/data';
+
+/**
+ * Internal dependencies
+ */
+import JetpackLikesAndSharingPanel from '../../shared/jetpack-likes-and-sharing-panel';
+
+const SharingCheckbox = ( { isSharingEnabled, editPost } ) => (
+ <PostTypeSupportCheck supportKeys="jetpack-sharing-buttons">
+ <JetpackLikesAndSharingPanel>
+ <CheckboxControl
+ label={ __( 'Show sharing buttons.', 'jetpack' ) }
+ checked={ isSharingEnabled }
+ onChange={ value => {
+ editPost( { jetpack_sharing_enabled: value } );
+ } }
+ />
+ </JetpackLikesAndSharingPanel>
+ </PostTypeSupportCheck>
+);
+
+// Fetch the post meta.
+const applyWithSelect = withSelect( select => {
+ const { getEditedPostAttribute } = select( 'core/editor' );
+ const isSharingEnabled = getEditedPostAttribute( 'jetpack_sharing_enabled' );
+
+ return { isSharingEnabled };
+} );
+
+// Provide method to update post meta.
+const applyWithDispatch = withDispatch( dispatch => {
+ const { editPost } = dispatch( 'core/editor' );
+
+ return { editPost };
+} );
+
+// Combine the higher-order components.
+export default compose( [ applyWithSelect, applyWithDispatch ] )( SharingCheckbox );