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

Migrate from TextControl to NumberControl to remove margin overrides #47160

Merged
merged 2 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 10 additions & 12 deletions packages/block-editor/src/components/image-size-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
Button,
ButtonGroup,
SelectControl,
TextControl,
__experimentalNumberControl as NumberControl,
__experimentalHStack as HStack,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';

Expand Down Expand Up @@ -46,12 +47,10 @@ export default function ImageSizeControl( {
) }
{ isResizable && (
<div className="block-editor-image-size-control">
<p className="block-editor-image-size-control__row">
{ __( 'Image dimensions' ) }
</p>
<div className="block-editor-image-size-control__row">
<TextControl
type="number"
<p>{ __( 'Image dimensions' ) }</p>

<HStack align="baseline" spacing="3">
Copy link
Member

Choose a reason for hiding this comment

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

What is the align baseline for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To keep the height input aligned. Otherwise, it looks like this:

Screenshot 2023-01-26 at 9 54 01 PM

Copy link
Member

Choose a reason for hiding this comment

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

So it isn't needed now that we dealt with the bottom margin problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mirka, can you clarify what you mean by 'it' in your question? I'm not sure I understand so I just wanted to confirm if I need to remove anything before merging. 🙂

Copy link
Member

Choose a reason for hiding this comment

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

Ah sorry, I meant the align="baseline".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries! It is needed, from what I can tell, so it doesn't end up looking like the screenshot above.

<NumberControl
className="block-editor-image-size-control__width"
label={ __( 'Width' ) }
value={ currentWidth }
Expand All @@ -60,8 +59,7 @@ export default function ImageSizeControl( {
updateDimension( 'width', value )
}
/>
<TextControl
type="number"
<NumberControl
className="block-editor-image-size-control__height"
label={ __( 'Height' ) }
value={ currentHeight }
Expand All @@ -70,8 +68,8 @@ export default function ImageSizeControl( {
updateDimension( 'height', value )
}
/>
</div>
<div className="block-editor-image-size-control__row">
</HStack>
<HStack>
<ButtonGroup aria-label={ __( 'Image size presets' ) }>
{ IMAGE_SIZE_PRESETS.map( ( scale ) => {
const scaledWidth = Math.round(
Expand Down Expand Up @@ -108,7 +106,7 @@ export default function ImageSizeControl( {
<Button isSmall onClick={ () => updateDimensions() }>
{ __( 'Reset' ) }
</Button>
</div>
</HStack>
</div>
) }
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
.block-editor-image-size-control {
margin-bottom: 1em;

.block-editor-image-size-control__row {
display: flex;
justify-content: space-between;

.block-editor-image-size-control__width,
.block-editor-image-size-control__height {
margin-bottom: 0.5em;
brookewp marked this conversation as resolved.
Show resolved Hide resolved

// Fix the text and placeholder text being misaligned in Safari
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed CSS that was added three years ago for a Safari fix, but when testing Safari with the removed code, it looked the same as other browsers.

input {
line-height: 1.25;
}
}

.block-editor-image-size-control__width {
margin-right: 5px;
}

.block-editor-image-size-control__height {
margin-left: 5px;
}
.block-editor-image-size-control__width,
.block-editor-image-size-control__height {
margin-bottom: 1.115em;
}
}
30 changes: 18 additions & 12 deletions packages/editor/src/components/page-attributes/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { TextControl } from '@wordpress/components';
import {
Flex,
FlexBlock,
__experimentalNumberControl as NumberControl,
} from '@wordpress/components';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { useState } from '@wordpress/element';
Expand All @@ -25,17 +29,19 @@ export const PageAttributesOrder = ( { onUpdateOrder, order = 0 } ) => {
};
const value = orderInput === null ? order : orderInput;
return (
<TextControl
className="editor-page-attributes__order"
type="number"
label={ __( 'Order' ) }
value={ value }
onChange={ setUpdatedOrder }
size={ 6 }
onBlur={ () => {
setOrderInput( null );
} }
/>
<Flex>
<FlexBlock>
<NumberControl
label={ __( 'Order' ) }
value={ value }
onChange={ setUpdatedOrder }
labelPosition="side"
onBlur={ () => {
setOrderInput( null );
} }
/>
</FlexBlock>
</Flex>
);
};

Expand Down
12 changes: 0 additions & 12 deletions packages/editor/src/components/page-attributes/style.scss

This file was deleted.

1 change: 0 additions & 1 deletion packages/editor/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
@import "./components/editor-notices/style.scss";
@import "./components/entities-saved-states/style.scss";
@import "./components/error-boundary/style.scss";
@import "./components/page-attributes/style.scss";
@import "./components/post-excerpt/style.scss";
@import "./components/post-featured-image/style.scss";
@import "./components/post-format/style.scss";
Expand Down
37 changes: 23 additions & 14 deletions packages/format-library/src/image/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
/**
* WordPress dependencies
*/
import { Path, SVG, TextControl, Popover, Button } from '@wordpress/components';
import {
Path,
SVG,
Popover,
Button,
__experimentalNumberControl as NumberControl,
__experimentalHStack as HStack,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
import { insertObject, useAnchor } from '@wordpress/rich-text';
Expand Down Expand Up @@ -70,19 +77,21 @@ function InlineUI( { value, onChange, activeObjectAttributes, contentRef } ) {
event.preventDefault();
} }
>
<TextControl
className="block-editor-format-toolbar__image-container-value"
type="number"
label={ __( 'Width' ) }
value={ width }
min={ 1 }
onChange={ ( newWidth ) => setWidth( newWidth ) }
/>
<Button
icon={ keyboardReturn }
label={ __( 'Apply' ) }
type="submit"
/>
<HStack alignment="bottom" spacing="0">
<NumberControl
className="block-editor-format-toolbar__image-container-value"
label={ __( 'Width' ) }
value={ width }
min={ 1 }
onChange={ ( newWidth ) => setWidth( newWidth ) }
/>
<Button
className="block-editor-format-toolbar__image-container-button"
icon={ keyboardReturn }
label={ __( 'Apply' ) }
type="submit"
/>
</HStack>
</form>
</Popover>
);
Expand Down
31 changes: 6 additions & 25 deletions packages/format-library/src/image/style.scss
Original file line number Diff line number Diff line change
@@ -1,34 +1,15 @@
.block-editor-format-toolbar__image-popover {
z-index: z-index(".block-editor-format-toolbar__image-popover");
}

.block-editor-format-toolbar__image-container-content {
display: flex;
.block-editor-format-toolbar__image-container-value {
margin: $grid-unit-10 - $border-width;
min-width: 150px;
max-width: 500px;
}

.components-button {
align-self: flex-end;
.block-editor-format-toolbar__image-container-button {
height: $grid-unit-10 * 4 - ($border-width * 2);
margin-bottom: $grid-unit-10;
margin-right: $grid-unit-10;
padding: 0 6px;
}
}

.block-editor-format-toolbar__image-container-value {
margin: $grid-unit-10 - $border-width;
flex-grow: 1;
flex-shrink: 1;
white-space: nowrap;
min-width: 150px;
max-width: 500px;

&.components-base-control {
.components-base-control__field {
margin-bottom: 0;
}

.components-base-control__label {
display: block;
}
}
}