@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
42 lines (38 loc) • 935 B
JavaScript
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { CheckboxControl } from '@wordpress/components';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
/**
* Internal dependencies
*/
import PostStickyCheck from './check';
export function PostSticky( { onUpdateSticky, postSticky = false } ) {
return (
<PostStickyCheck>
<CheckboxControl
label={ __( 'Stick to the top of the blog' ) }
checked={ postSticky }
onChange={ () => onUpdateSticky( ! postSticky ) }
/>
</PostStickyCheck>
);
}
export default compose( [
withSelect( ( select ) => {
return {
postSticky: select( 'core/editor' ).getEditedPostAttribute(
'sticky'
),
};
} ),
withDispatch( ( dispatch ) => {
return {
onUpdateSticky( postSticky ) {
dispatch( 'core/editor' ).editPost( { sticky: postSticky } );
},
};
} ),
] )( PostSticky );