@rc-component/trigger
Version:
base abstract trigger component for react
62 lines (59 loc) • 1.92 kB
JavaScript
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React from 'react';
import useOffsetStyle from "../hooks/useOffsetStyle";
import classNames from 'classnames';
import CSSMotion from '@rc-component/motion';
const FloatBg = props => {
const {
prefixCls,
isMobile,
ready,
open,
align,
offsetR,
offsetB,
offsetX,
offsetY,
popupSize,
motion
} = props;
const floatBgCls = `${prefixCls}-float-bg`;
const [motionVisible, setMotionVisible] = React.useState(false);
// ========================= Styles =========================
const offsetStyle = useOffsetStyle(isMobile, ready, open, align, offsetR, offsetB, offsetX, offsetY);
// Apply popup size if available
const sizeStyle = {};
if (popupSize) {
sizeStyle.width = popupSize.width;
sizeStyle.height = popupSize.height;
}
// ========================= Render =========================
return /*#__PURE__*/React.createElement(CSSMotion, _extends({
motionAppear: true,
motionEnter: true,
motionLeave: true,
removeOnLeave: false,
leavedClassName: `${floatBgCls}-hidden`
}, motion, {
visible: open,
onVisibleChanged: nextVisible => {
setMotionVisible(nextVisible);
}
}), ({
className: motionClassName,
style: motionStyle
}) => {
const cls = classNames(floatBgCls, motionClassName, {
[`${floatBgCls}-visible`]: motionVisible
});
return /*#__PURE__*/React.createElement("div", {
className: cls,
style: {
...offsetStyle,
...sizeStyle,
...motionStyle
}
});
});
};
export default FloatBg;