Skip to content
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

Properly associate the spacer height input label. #6922

Merged
merged 3 commits into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core-blocks/spacer/editor.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
.editor-block-list__block[data-type="core/spacer"].is-selected .editor-block-list__block-edit {
background: $light-gray-200;

.wp-block-spacer__resize-handler-top,
.wp-block-spacer__resize-handler-bottom {
.block-spacer__resize-handler-top,
.block-spacer__resize-handler-bottom {
display: block;
}
}

.wp-block-spacer__resize-handler-top,
.wp-block-spacer__resize-handler-bottom {
.block-spacer__resize-handler-top,
.block-spacer__resize-handler-bottom {
display: none;
border-radius: 50%;
border: 2px solid white;
Expand Down
113 changes: 58 additions & 55 deletions core-blocks/spacer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ResizableBox from 're-resizable';
import { Fragment } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { InspectorControls } from '@wordpress/editor';
import { BaseControl, PanelBody } from '@wordpress/components';
import { BaseControl, PanelBody, withInstanceId } from '@wordpress/components';

/**
* Internal dependencies
Expand All @@ -34,61 +34,64 @@ export const settings = {
},
},

edit( { attributes, setAttributes, toggleSelection } ) {
const { height } = attributes;
edit: withInstanceId(
( { attributes, setAttributes, toggleSelection, instanceId } ) => {
const { height } = attributes;
const id = `block-spacer-height-input-${ instanceId }`;

return (
<Fragment>
<ResizableBox
size={ {
height,
} }
minHeight="20"
handleClasses={ {
top: 'wp-block-spacer__resize-handler-top',
bottom: 'wp-block-spacer__resize-handler-bottom',
} }
enable={ {
top: true,
right: false,
bottom: true,
left: false,
topRight: false,
bottomRight: false,
bottomLeft: false,
topLeft: false,
} }
onResizeStop={ ( event, direction, elt, delta ) => {
setAttributes( {
height: parseInt( height + delta.height, 10 ),
} );
toggleSelection( true );
} }
onResizeStart={ () => {
toggleSelection( false );
} }
/>
<InspectorControls>
<PanelBody title={ __( 'Spacer Settings' ) }>
<BaseControl label={ __( 'Height in pixels' ) }>
<input
type="number"
onChange={ ( event ) => {
setAttributes( {
height: parseInt( event.target.value, 10 ),
} );
} }
aria-label={ __( 'Height for the spacer element in pixels.' ) }
value={ height }
min="20"
step="10"
/>
</BaseControl>
</PanelBody>
</InspectorControls>
</Fragment>
);
},
return (
<Fragment>
<ResizableBox
size={ {
height,
} }
minHeight="20"
handleClasses={ {
top: 'block-spacer__resize-handler-top',
bottom: 'block-spacer__resize-handler-bottom',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess these should be core-blocks-spacer__* instead

} }
enable={ {
top: true,
right: false,
bottom: true,
left: false,
topRight: false,
bottomRight: false,
bottomLeft: false,
topLeft: false,
} }
onResizeStop={ ( event, direction, elt, delta ) => {
setAttributes( {
height: parseInt( height + delta.height, 10 ),
} );
toggleSelection( true );
} }
onResizeStart={ () => {
toggleSelection( false );
} }
/>
<InspectorControls>
<PanelBody title={ __( 'Spacer Settings' ) }>
<BaseControl label={ __( 'Height in pixels' ) } id={ id }>
<input
type="number"
id={ id }
onChange={ ( event ) => {
setAttributes( {
height: parseInt( event.target.value, 10 ),
} );
} }
value={ height }
min="20"
step="10"
/>
</BaseControl>
</PanelBody>
</InspectorControls>
</Fragment>
);
}
),

save( { attributes } ) {
return <div style={ { height: attributes.height } } aria-hidden />;
Expand Down