Skip to content

Commit

Permalink
Refactor: move utility function before default export
Browse files Browse the repository at this point in the history
  • Loading branch information
hbhalodia committed Oct 29, 2024
1 parent 4bc666b commit a3d6c29
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions packages/block-editor/src/components/image-size-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ import useDimensionHandler from './use-dimension-handler';
const IMAGE_SIZE_PRESETS = [ 25, 50, 75, 100 ];
const noop = () => {};

/**
* Get scaled width and height for the given scale.
*
* @param {number} scale The scale to get the scaled width and height for.
* @param {number} imageWidth The image width.
* @param {number} imageHeight The image height.
*
* @return {Object} The scaled width and height.
*/
function getScaledWidthAndHeight( scale, imageWidth, imageHeight ) {
const scaledWidth = Math.round( imageWidth * ( scale / 100 ) );
const scaledHeight = Math.round( imageHeight * ( scale / 100 ) );

return {
scaledWidth,
scaledHeight,
};
}

export default function ImageSizeControl( {
imageSizeHelp,
imageWidth,
Expand Down Expand Up @@ -128,22 +147,3 @@ export default function ImageSizeControl( {
</>
);
}

/**
* Get scaled width and height for the given scale.
*
* @param {number} scale The scale to get the scaled width and height for.
* @param {number} imageWidth The image width.
* @param {number} imageHeight The image height.
*
* @return {Object} The scaled width and height.
*/
function getScaledWidthAndHeight( scale, imageWidth, imageHeight ) {
const scaledWidth = Math.round( imageWidth * ( scale / 100 ) );
const scaledHeight = Math.round( imageHeight * ( scale / 100 ) );

return {
scaledWidth,
scaledHeight,
};
}

0 comments on commit a3d6c29

Please sign in to comment.