Skip to content

Commit

Permalink
Media & Text: Add media width control (#31002)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka authored May 12, 2021
1 parent d3ba19b commit 84ff6d4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/block-library/src/media-text/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '@wordpress/block-editor';
import {
PanelBody,
RangeControl,
TextareaControl,
ToggleControl,
ToolbarButton,
Expand Down Expand Up @@ -49,6 +50,7 @@ const TEMPLATE = [
},
],
];

// this limits the resize to a safe zone to avoid making broken layouts
const WIDTH_CONSTRAINT_PERCENTAGE = 15;
const applyWidthConstraints = ( width ) =>
Expand Down Expand Up @@ -276,6 +278,15 @@ function MediaTextEdit( { attributes, isSelected, setAttributes } ) {
isResizable={ false }
/>
) }
{ mediaUrl && (
<RangeControl
label={ __( 'Media width' ) }
value={ temporaryMediaWidth || mediaWidth }
onChange={ commitWidthChange }
min={ WIDTH_CONSTRAINT_PERCENTAGE }
max={ 100 - WIDTH_CONSTRAINT_PERCENTAGE }
/>
) }
</PanelBody>
);

Expand Down

0 comments on commit 84ff6d4

Please sign in to comment.