Skip to content

Commit

Permalink
Add toggle for post sticky status on editor WordPress#1313
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonagnew committed Jun 22, 2017
1 parent 401e683 commit 68de066
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions editor/sidebar/post-status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import './style.scss';
import PostVisibility from '../post-visibility';
import PostTrash from '../post-trash';
import PostSchedule from '../post-schedule';
import PostSticky from '../post-sticky';
import {
getEditedPostAttribute,
getSuggestedPostFormat,
Expand Down Expand Up @@ -67,6 +68,9 @@ class PostStatus extends Component {
<span>{ __( 'Post Format' ) }</span>
<span>{ format }</span>
</div>

<PostSticky />

<div className="editor-post-status__row">
<PostTrash />
</div>
Expand Down
43 changes: 43 additions & 0 deletions editor/sidebar/post-sticky/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* External dependencies
*/
import { connect } from 'react-redux';

/**
* WordPress dependencies
*/
import { __ } from 'i18n';
import { FormToggle, withInstanceId } from 'components';

/**
* Internal dependencies
*/
import { getEditedPostAttribute } from '../../selectors';
import { editPost } from '../../actions';

function PostSticky( { postSticky = false, instanceId, ...props } ) {
const stickyToggleId = 'post-sticky-toggle-' + instanceId;

const onTogglePostSticky = () => props.editPost( { sticky: !postSticky } );

return (
<div className="editor-post-status__row">
<label htmlFor={ stickyToggleId }>{ __( 'Stick to the front page' ) }</label>
<FormToggle
checked={ postSticky }
onChange={ onTogglePostSticky }
showHint={ false }
id={ stickyToggleId }
/>
</div>
);
}

export default connect(
( state ) => {
return {
postSticky: getEditedPostAttribute( state, 'sticky' ),
};
},
{ editPost }
)( withInstanceId( PostSticky ) );

0 comments on commit 68de066

Please sign in to comment.