-
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
Change instances of FormToggle to use ToggleControl component #4996
Changes from 3 commits
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 |
---|---|---|
|
@@ -7,29 +7,26 @@ import { connect } from 'react-redux'; | |
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { FormToggle, withInstanceId } from '@wordpress/components'; | ||
import { ToggleControl } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal Dependencies | ||
*/ | ||
import { getEditedPostAttribute } from '../../store/selectors'; | ||
import { editPost } from '../../store/actions'; | ||
|
||
function PostComments( { commentStatus = 'open', instanceId, ...props } ) { | ||
function PostComments( { commentStatus = 'open', ...props } ) { | ||
const onToggleComments = () => props.editPost( { comment_status: commentStatus === 'open' ? 'closed' : 'open' } ); | ||
|
||
const commentsToggleId = 'allow-comments-toggle-' + instanceId; | ||
|
||
return [ | ||
<label key="label" htmlFor={ commentsToggleId }>{ __( 'Allow Comments' ) }</label>, | ||
<FormToggle | ||
return ( | ||
<ToggleControl | ||
key="toggle" | ||
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. This |
||
label={ __( 'Allow Comments' ) } | ||
checked={ commentStatus === 'open' } | ||
onChange={ onToggleComments } | ||
showHint={ false } | ||
id={ commentsToggleId } | ||
/>, | ||
]; | ||
/> | ||
); | ||
} | ||
|
||
export default connect( | ||
|
@@ -41,5 +38,5 @@ export default connect( | |
{ | ||
editPost, | ||
} | ||
)( withInstanceId( PostComments ) ); | ||
)( PostComments ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import { connect } from 'react-redux'; | |
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { FormToggle, withInstanceId } from '@wordpress/components'; | ||
import { ToggleControl } from '@wordpress/components'; | ||
import { compose } from '@wordpress/element'; | ||
|
||
/** | ||
|
@@ -17,18 +17,17 @@ import PostPendingStatusCheck from './check'; | |
import { getEditedPostAttribute } from '../../store/selectors'; | ||
import { editPost } from '../../store/actions'; | ||
|
||
export function PostPendingStatus( { instanceId, status, onUpdateStatus } ) { | ||
const pendingId = 'pending-toggle-' + instanceId; | ||
export function PostPendingStatus( { status, onUpdateStatus } ) { | ||
const togglePendingStatus = () => { | ||
const updatedStatus = status === 'pending' ? 'draft' : 'pending'; | ||
onUpdateStatus( updatedStatus ); | ||
}; | ||
|
||
return ( | ||
<PostPendingStatusCheck> | ||
<label htmlFor={ pendingId }>{ __( 'Pending Review' ) }</label> | ||
<FormToggle | ||
id={ pendingId } | ||
<ToggleControl | ||
key="toggle" | ||
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. This |
||
label={ __( 'Pending Review' ) } | ||
checked={ status === 'pending' } | ||
onChange={ togglePendingStatus } | ||
showHint={ false } | ||
|
@@ -50,5 +49,4 @@ const applyConnect = connect( | |
|
||
export default compose( | ||
applyConnect, | ||
withInstanceId | ||
)( PostPendingStatus ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,27 +7,24 @@ import { connect } from 'react-redux'; | |
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { FormToggle, withInstanceId } from '@wordpress/components'; | ||
import { ToggleControl } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal Dependencies | ||
*/ | ||
import { getEditedPostAttribute } from '../../store/selectors'; | ||
import { editPost } from '../../store/actions'; | ||
|
||
function PostPingbacks( { pingStatus = 'open', instanceId, ...props } ) { | ||
function PostPingbacks( { pingStatus = 'open', ...props } ) { | ||
const onTogglePingback = () => props.editPost( { ping_status: pingStatus === 'open' ? 'closed' : 'open' } ); | ||
|
||
const pingbacksToggleId = 'allow-pingbacks-toggle-' + instanceId; | ||
|
||
return [ | ||
<label key="label" htmlFor={ pingbacksToggleId }>{ __( 'Allow Pingbacks & Trackbacks' ) }</label>, | ||
<FormToggle | ||
<ToggleControl | ||
key="toggle" | ||
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. This |
||
label={ __( 'Allow Pingbacks & Trackbacks' ) } | ||
checked={ pingStatus === 'open' } | ||
onChange={ onTogglePingback } | ||
showHint={ false } | ||
id={ pingbacksToggleId } | ||
/>, | ||
]; | ||
} | ||
|
@@ -41,5 +38,4 @@ export default connect( | |
{ | ||
editPost, | ||
} | ||
)( withInstanceId( PostPingbacks ) ); | ||
|
||
)( PostPingbacks ); |
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.
I'm concerned how this is tying toggle control to panel components, and am wondering if the desired goal here could be generalized more.
Two thoughts of alternatives:
.blocks-base-control__label
withinPanelRow
have their bottom margin removed?ToggleControl
labels have their bottom margin removed? (applied intoggle-control/style.scss
)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.
The general problem (which #4997 also has) is that
.blocks-base-control
is forcing a margin at the bottom of each control. There isn't any utility class which removes that margin forcing it to be globally removed in this instance, where each control is stacked without any space between.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.
Right, but should it be that one or the other of
.blocks-base-control
and.blocks-base-control__label
applies a bottom margin, not both?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.
Removing the bottom margin from
.blocks-base-control__label
is due to their being no bottom margin on these controls as they exist currently (For these controls I'm changing). They have amargin-bottom: 5px
when used for block inspector controls, but to not change how they look in this case I removed the margin.It wouldn't make sense to remove that margin for all controls, as having some margin between the label and input/textarea controls makes sense.
Maybe opting to globally remove the label margin for toggle controls would be the best way forward?
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.
I think applying globally
.blocks-base-control:last-child { margin-bottom: 0 }
would make sense, as currently the last control in a series of controls does add some updates unnecessary whitespace.