@rc-component/trigger
Version:
base abstract trigger component for react
35 lines (34 loc) • 948 B
JavaScript
export default function useOffsetStyle(isMobile, ready, open, align, offsetR, offsetB, offsetX, offsetY) {
// >>>>> Offset
const AUTO = 'auto';
const offsetStyle = isMobile ? {} : {
left: '-1000vw',
top: '-1000vh',
right: AUTO,
bottom: AUTO
};
// Set align style
if (!isMobile && (ready || !open)) {
const {
points
} = align;
const dynamicInset = align.dynamicInset || align._experimental?.dynamicInset;
const alignRight = dynamicInset && points[0][1] === 'r';
const alignBottom = dynamicInset && points[0][0] === 'b';
if (alignRight) {
offsetStyle.right = offsetR;
offsetStyle.left = AUTO;
} else {
offsetStyle.left = offsetX;
offsetStyle.right = AUTO;
}
if (alignBottom) {
offsetStyle.bottom = offsetB;
offsetStyle.top = AUTO;
} else {
offsetStyle.top = offsetY;
offsetStyle.bottom = AUTO;
}
}
return offsetStyle;
}