Skip to content

Commit

Permalink
Media & Text: Add media width control
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Apr 20, 2021
1 parent b3fe0be commit 3064bd9
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 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,21 @@ const TEMPLATE = [
},
],
];

const WIDTH_SCALE_MARKS = [
{
value: 25,
label: '25%',
},
{
value: 50,
label: '50%',
},
{
value: 75,
label: '75%',
},
];
// 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 +292,16 @@ function MediaTextEdit( { attributes, isSelected, setAttributes } ) {
isResizable={ false }
/>
) }
{ mediaUrl && (
<RangeControl
label={ __( 'Media width' ) }
value={ temporaryMediaWidth || mediaWidth }
marks={ WIDTH_SCALE_MARKS }
onChange={ commitWidthChange }
min={ WIDTH_CONSTRAINT_PERCENTAGE }
max={ 100 - WIDTH_CONSTRAINT_PERCENTAGE }
/>
) }
</PanelBody>
);

Expand Down

0 comments on commit 3064bd9

Please sign in to comment.