-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chrome: Adding the visibility selector #832
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2c44fcb
Chrome: Adding the visibility selector
youknowriad 9e2ad76
Chrome: Adding visibility information
youknowriad dcebfc1
Chrome: Drop the Post visibility info toggle
youknowriad 3883e71
Chrome: Transform the visibility selector link to a button
youknowriad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding-top: 10px; | ||
padding-top: 20px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { connect } from 'react-redux'; | ||
import clickOutside from 'react-click-outside'; | ||
import { find } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from 'i18n'; | ||
import { Component } from 'element'; | ||
|
||
/** | ||
* Internal Dependencies | ||
*/ | ||
import './style.scss'; | ||
import { | ||
getEditedPostAttribute, | ||
getEditedPostStatus, | ||
getEditedPostVisibility, | ||
} from '../../selectors'; | ||
import { editPost } from '../../actions'; | ||
|
||
class PostVisibility extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
this.state = { | ||
opened: false, | ||
}; | ||
this.toggleDialog = this.toggleDialog.bind( this ); | ||
} | ||
|
||
toggleDialog( event ) { | ||
event.preventDefault(); | ||
this.setState( { opened: ! this.state.opened } ); | ||
} | ||
|
||
handleClickOutside() { | ||
this.setState( { opened: false } ); | ||
} | ||
|
||
render() { | ||
const { status, visibility, password, onUpdateVisibility } = this.props; | ||
|
||
const setPublic = () => onUpdateVisibility( visibility === 'private' ? 'draft' : status ); | ||
const setPrivate = () => onUpdateVisibility( 'private' ); | ||
const setPasswordProtected = () => onUpdateVisibility( visibility === 'private' ? 'draft' : status, password || '' ); | ||
const updatePassword = ( event ) => onUpdateVisibility( status, event.target.value ); | ||
|
||
const visibilityOptions = [ | ||
{ | ||
value: 'public', | ||
label: __( 'Public' ), | ||
info: __( 'Visible to everyone.' ), | ||
changeHandler: setPublic, | ||
}, | ||
{ | ||
value: 'private', | ||
label: __( 'Private' ), | ||
info: __( 'Only visible to site admins and editors.' ), | ||
changeHandler: setPrivate, | ||
}, | ||
{ | ||
value: 'password', | ||
label: __( 'Password Protected' ), | ||
info: __( 'Protected with a password you choose. Only those with the password can view this post.' ), | ||
changeHandler: setPasswordProtected, | ||
}, | ||
]; | ||
const getVisibilityLabel = () => find( visibilityOptions, { value: visibility } ).label; | ||
|
||
// Disable Reason: The input is inside the label, we shouldn't need the htmlFor | ||
/* eslint-disable jsx-a11y/label-has-for */ | ||
return ( | ||
<div className="editor-post-visibility"> | ||
<span>{ __( 'Visibility' ) }</span> | ||
<button className="editor-post-visibility__toggle button-link" onClick={ this.toggleDialog }> | ||
{ getVisibilityLabel( visibility ) } | ||
</button> | ||
|
||
{ this.state.opened && | ||
<div className="editor-post-visibility__dialog"> | ||
<div className="editor-post-visibility__dialog-arrow" /> | ||
<div className="editor-post-visibility__dialog-legend"> | ||
{ __( 'Post Visibility' ) } | ||
</div> | ||
{ visibilityOptions.map( ( { value, label, info, changeHandler } ) => ( | ||
<label key={ value } className="editor-post-visibility__dialog-label"> | ||
<input type="radio" value={ value } onChange={ changeHandler } checked={ value === visibility } /> | ||
{ label } | ||
{ <div className="editor-post-visibility__dialog-info">{ info }</div> } | ||
</label> | ||
) ) } | ||
{ visibility === 'password' && | ||
<input | ||
className="editor-post-visibility__dialog-password-input" | ||
type="text" | ||
onChange={ updatePassword } | ||
value={ password } | ||
placeholder={ __( 'Create password' ) } | ||
/> | ||
} | ||
</div> | ||
} | ||
</div> | ||
); | ||
/* eslint-enable jsx-a11y/label-has-for */ | ||
} | ||
} | ||
|
||
export default connect( | ||
( state ) => ( { | ||
status: getEditedPostStatus( state ), | ||
visibility: getEditedPostVisibility( state ), | ||
password: getEditedPostAttribute( state, 'password' ), | ||
} ), | ||
( dispatch ) => { | ||
return { | ||
onUpdateVisibility( status, password = null ) { | ||
dispatch( editPost( { status, password } ) ); | ||
}, | ||
}; | ||
} | ||
)( clickOutside( PostVisibility ) ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
.editor-post-visibility { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
width: 100%; | ||
position: relative; | ||
} | ||
|
||
.editor-post-visibility__toggle.button-link { | ||
text-decoration: underline; | ||
color: $blue-wordpress; | ||
|
||
&:focus { | ||
box-shadow: none; | ||
outline: none; | ||
} | ||
|
||
&:hover { | ||
color: $blue-medium; | ||
} | ||
} | ||
|
||
.editor-post-visibility__dialog { | ||
position: absolute; | ||
top: 30px; | ||
right: 0; | ||
box-shadow: $shadow-popover; | ||
border: 1px solid $light-gray-500; | ||
background: $white; | ||
padding: 10px; | ||
min-width: 240px; | ||
} | ||
|
||
.editor-post-visibility__dialog-arrow { | ||
position: absolute; | ||
border: 10px dashed $light-gray-500; | ||
height: 0; | ||
width: 0; | ||
line-height: 0; | ||
top: -10px; | ||
right: 5px; | ||
margin-left: -10px; | ||
border-bottom-style: solid; | ||
border-top: none; | ||
border-left-color: transparent; | ||
border-right-color: transparent; | ||
|
||
&:before { | ||
top: 2px; | ||
border: 10px solid $white; | ||
content: " "; | ||
position: absolute; | ||
left: 50%; | ||
margin-left: -10px; | ||
border-bottom-style: solid; | ||
border-top: none; | ||
border-left-color: transparent; | ||
border-right-color: transparent; | ||
} | ||
} | ||
|
||
.editor-post-visibility__dialog-legend { | ||
font-weight: 600; | ||
font-size: 0.9em; | ||
|
||
} | ||
|
||
.editor-post-visibility__dialog-label { | ||
display: block; | ||
margin: 10px 0; | ||
} | ||
|
||
.editor-post-visibility__dialog-password-input { | ||
width: calc( 100% - 20px ); | ||
margin-left: 20px; | ||
} | ||
|
||
.editor-post-visibility__dialog-info { | ||
color: $dark-gray-200; | ||
padding-left: 20px; | ||
font-style: italic; | ||
margin-top: 4px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the
<span>
necessary? Both here and in the<label>
below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's is not required here, but since the parent is "flex", I like the explicitness of having flex children. It's useless though for the label.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, now I'm curious what is the default flex behavior for handling text nodes. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to work properly though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to handle them independently only when they're broken up by other elements (notably not by
react-text
comments):Explicitness seems good in these cases 👍