You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
43 lines
1.2 KiB
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
import * as React from 'react';
|
|
export default (function (stretch) {
|
|
var _React$useState = React.useState({
|
|
width: 0,
|
|
height: 0
|
|
}),
|
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
targetSize = _React$useState2[0],
|
|
setTargetSize = _React$useState2[1];
|
|
|
|
function measureStretch(element) {
|
|
setTargetSize({
|
|
width: element.offsetWidth,
|
|
height: element.offsetHeight
|
|
});
|
|
} // Merge stretch style
|
|
|
|
|
|
var style = React.useMemo(function () {
|
|
var sizeStyle = {};
|
|
|
|
if (stretch) {
|
|
var width = targetSize.width,
|
|
height = targetSize.height; // Stretch with target
|
|
|
|
if (stretch.indexOf('height') !== -1 && height) {
|
|
sizeStyle.height = height;
|
|
} else if (stretch.indexOf('minHeight') !== -1 && height) {
|
|
sizeStyle.minHeight = height;
|
|
}
|
|
|
|
if (stretch.indexOf('width') !== -1 && width) {
|
|
sizeStyle.width = width;
|
|
} else if (stretch.indexOf('minWidth') !== -1 && width) {
|
|
sizeStyle.minWidth = width;
|
|
}
|
|
}
|
|
|
|
return sizeStyle;
|
|
}, [stretch, targetSize]);
|
|
return [style, measureStretch];
|
|
}); |