-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Changes from 1 commit
2c44fcb
9e2ad76
dcebfc1
3883e71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { connect } from 'react-redux'; | ||
import clickOutside from 'react-click-outside'; | ||
|
||
/** | ||
* 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 visibilityLabels = { | ||
'public': __( 'Public' ), | ||
'private': __( 'Private' ), | ||
password: __( 'Password Protected' ), | ||
}; | ||
|
||
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 ); | ||
|
||
// 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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe 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 Explicitness seems good in these cases 👍 |
||
<a href="" onClick={ this.toggleDialog }>{ visibilityLabels[ visibility ] }</a> | ||
|
||
{ 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> | ||
<label className="editor-post-visibility__dialog-label"> | ||
<input type="radio" value="public" onChange={ setPublic } checked={ 'public' === visibility } /> | ||
<span>{ visibilityLabels.public }</span> | ||
</label> | ||
<label className="editor-post-visibility__dialog-label"> | ||
<input type="radio" value="private" onChange={ setPrivate } checked={ 'private' === visibility } /> | ||
<span>{ visibilityLabels.private }</span> | ||
</label> | ||
<label className="editor-post-visibility__dialog-label"> | ||
<input type="radio" value="password" onChange={ setPasswordProtected } checked={ 'password' === visibility } /> | ||
<span>{ visibilityLabels.password }</span> | ||
</label> | ||
{ visibility === '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 ) ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
.editor-post-visibility { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
width: 100%; | ||
position: relative; | ||
} | ||
|
||
.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; | ||
} |
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.
Can we get rid of this rule?
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.
you mean completely disable it from the
.eslintrc
?