diff --git a/edit-post/assets/stylesheets/_mixins.scss b/edit-post/assets/stylesheets/_mixins.scss index 5018da99fc5096..9e14930dad1c49 100644 --- a/edit-post/assets/stylesheets/_mixins.scss +++ b/edit-post/assets/stylesheets/_mixins.scss @@ -326,29 +326,3 @@ // icon standards. margin-right: 2px; } - - -/** - * Styles for resize handles - */ - -@mixin resize-handler__container() { - display: none; - - // The handle itself is a pseudo element, and will sit inside this larger - // container size. - width: $resize-handler-container-size; - height: $resize-handler-container-size; - padding: $grid-size-small; -} - -@mixin resize-handler__visible-handle() { - display: block; - content: ""; - width: $resize-handler-size; - height: $resize-handler-size; - border: 2px solid $white; - border-radius: 50%; - background: theme(primary); - cursor: inherit; -} diff --git a/packages/block-library/package.json b/packages/block-library/package.json index e5bdacddb267f9..044c490565d70f 100644 --- a/packages/block-library/package.json +++ b/packages/block-library/package.json @@ -41,7 +41,6 @@ "moment": "^2.22.1", "querystring": "^0.2.0", "querystringify": "^1.0.0", - "re-resizable": "^4.7.1", "url": "^0.11.0" }, "devDependencies": { diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index 87db1d3ab08469..be1764d5f5c8c9 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -2,7 +2,6 @@ * External dependencies */ import classnames from 'classnames'; -import ResizableBox from 're-resizable'; import { get, isEmpty, @@ -22,6 +21,7 @@ import { ButtonGroup, IconButton, PanelBody, + ResizableBox, SelectControl, TextControl, TextareaControl, @@ -446,21 +446,10 @@ class ImageEdit extends Component { } /* eslint-enable no-lonely-if */ - // Removes the inline styles in the drag handles. - const handleStylesOverrides = { - width: null, - height: null, - top: null, - right: null, - bottom: null, - left: null, - }; - return ( { getInspectorControls( imageWidth, imageHeight ) } { + const { + attributes: { + height, + width, + }, + setAttributes, + toggleSelection, + } = props; + + return ( + { + setAttributes( { + height: parseInt( height + delta.height, 10 ), + width: parseInt( width + delta.width, 10 ), + } ); + toggleSelection( true ); + } } + onResizeStart={ () => { + toggleSelection( false ); + } } + /> + ); +} +``` diff --git a/packages/components/src/resizable-box/index.js b/packages/components/src/resizable-box/index.js new file mode 100644 index 00000000000000..c13129207645c8 --- /dev/null +++ b/packages/components/src/resizable-box/index.js @@ -0,0 +1,55 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; +import ReResizableBox from 're-resizable'; + +function ResizableBox( { className, ...props } ) { + // Removes the inline styles in the drag handles. + const handleStylesOverrides = { + width: null, + height: null, + top: null, + right: null, + bottom: null, + left: null, + }; + + const handleClassName = 'components-resizable-box__handle'; + + return ( + + ); +} + +export default ResizableBox; diff --git a/packages/components/src/resizable-box/style.scss b/packages/components/src/resizable-box/style.scss new file mode 100644 index 00000000000000..5032d78dc1efbd --- /dev/null +++ b/packages/components/src/resizable-box/style.scss @@ -0,0 +1,43 @@ +.components-resizable-box__handle { + display: none; + + // Show the resize handle when selected. + .components-resizable-box__container.is-selected & { + display: block; + } + + // The handle is a pseudo-element and will sit inside this larger + // container size. + width: $resize-handler-container-size; + height: $resize-handler-container-size; + padding: $grid-size-small; +} + +// This is the "visible" resize handle. +.components-resizable-box__handle::before { + display: block; + content: ""; + width: $resize-handler-size; + height: $resize-handler-size; + border: 2px solid $white; + border-radius: 50%; + background: theme(primary); + cursor: inherit; +} + +/*!rtl:begin:ignore*/ +.components-resizable-box__handle-right { + top: calc(50% - #{$resize-handler-container-size / 2}); + right: calc(#{$resize-handler-container-size / 2} * -1); +} + +.components-resizable-box__handle-bottom { + bottom: calc(#{$resize-handler-container-size / 2} * -1); + left: calc(50% - #{$resize-handler-container-size / 2}); +} + +.components-resizable-box__handle-left { + top: calc(50% - #{$resize-handler-container-size / 2}); + left: calc(#{$resize-handler-container-size / 2} * -1); +} +/*!rtl:end:ignore*/ diff --git a/packages/components/src/style.scss b/packages/components/src/style.scss index 37c379d3819221..3a2bb018ac41c2 100644 --- a/packages/components/src/style.scss +++ b/packages/components/src/style.scss @@ -27,6 +27,7 @@ @import "./popover/style.scss"; @import "./radio-control/style.scss"; @import "./range-control/style.scss"; +@import "./resizable-box/style.scss"; @import "./responsive-wrapper/style.scss"; @import "./sandbox/style.scss"; @import "./scroll-lock/style.scss";