@base-ui-components/react
Version:
Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.
14 lines (13 loc) • 518 B
JavaScript
export function getOffset(element, prop, axis) {
if (!element) {
return 0;
}
const styles = getComputedStyle(element);
const propAxis = axis === 'x' ? 'Inline' : 'Block';
// Safari misreports `marginInlineEnd` in RTL.
// We have to assume the start/end values are symmetrical, which is likely.
if (axis === 'x' && prop === 'margin') {
return parseFloat(styles[`${prop}InlineStart`]) * 2;
}
return parseFloat(styles[`${prop}${propAxis}Start`]) + parseFloat(styles[`${prop}${propAxis}End`]);
}