How to use the dom-helpers/query/offset function in dom-helpers

To help you get started, we’ve selected a few dom-helpers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github felixgirault / rea11y / src / Modal.js View on Github external
function makeDefaultStyle(modal, backdrop) {
	const modalRect = offset(modal);
	const backdropRect = offset(backdrop);
	const margin = (backdropRect.height - modalRect.height) / 2;

	return {
		marginTop: `${margin}px`
	};
}
github felixgirault / rea11y / src / RangeSlider.js View on Github external
handleClick(event) {
		const {lower, upper} = this.refs;

		const lowerRect = offset(findDOMNode(lower));
		const upperRect = offset(findDOMNode(upper));

		const lowerDistance = this.distance(lowerRect, event);
		const upperDistance = this.distance(upperRect, event);

		if (lowerDistance < upperDistance) {
			this.lowerTrackEventListener(event);
		} else {
			this.upperTrackEventListener(event);
		}
	}
github react-bootstrap / react-overlays / src / AutoAffix.js View on Github external
onUpdate = () => {
    if (!this._isMounted) {
      return
    }

    const { top: offsetTop, width } = getOffset(this.positioner)

    const container = getContainer(this.props.container)
    let offsetBottom
    if (container) {
      const documentHeight = getDocumentHeight(ownerDocument(this))
      const { top, height } = getOffset(container)
      offsetBottom = documentHeight - top - height
    } else {
      offsetBottom = null
    }

    this.updateState(offsetTop, offsetBottom, width)
  }
github aruberto / react-foundation-components / src / util / overlay-trigger / index.js View on Github external
function adjustPosition(
  elem,
  getOverlayTarget,
  getOverlayContainer,
  position,
  alignment
) {
  const target = getOverlayTarget();
  const container = getOverlayContainer();
  const targetPosition =
    container.tagName === 'BODY'
      ? getOffset(target)
      : getPosition(target, container);

  if (position === 'top') {
    css(
      elem,
      'top',
      `${targetPosition.top - parseInt(css(elem, 'height'), 10)}px`
    );
  } else if (position === 'bottom') {
    css(elem, 'top', `${targetPosition.top + targetPosition.height}px`);
  } else if (position === 'left') {
    css(
      elem,
      'left',
      `${targetPosition.left - parseInt(css(elem, 'width'), 10)}px`
    );
github react-bootstrap / react-overlays / src / utils / calculatePosition.js View on Github external
function getContainerDimensions(containerNode) {
  let width, height, scroll;

  if (containerNode.tagName === 'BODY') {
    width = window.innerWidth;
    height = window.innerHeight;

    scroll =
      getScrollTop(ownerDocument(containerNode).documentElement) ||
      getScrollTop(containerNode);
  } else {
    ({ width, height } = getOffset(containerNode));
    scroll = getScrollTop(containerNode);
  }

  return { width, height, scroll};
}
github felixgirault / rea11y / src / Slider.js View on Github external
moveTowardsPoint(index, point) {
		const {orientation, min, max} = this.props;
		const rect = offset(findDOMNode(this.refs.track));
		const ratio = (orientation === 'horizontal')
			? percentage(point.pageX - rect.left, rect.width)
			: percentage(point.pageY - rect.top, rect.height);

		const value = min + (((max - min) / 100) * ratio);
		const snapped = this.snapped(
			bound(
				value,
				this.lowerBound(index),
				this.upperBound(index)
			)
		);

		this.handleChange(index, snapped);
	}
github felixgirault / rea11y / src / Modal.js View on Github external
function makeDefaultStyle(modal, backdrop) {
	const modalRect = offset(modal);
	const backdropRect = offset(backdrop);
	const margin = (backdropRect.height - modalRect.height) / 2;

	return {
		marginTop: `${margin}px`
	};
}
github react-bootstrap / react-overlays / src / utils / calculatePosition.js View on Github external
export default function calculatePosition(
  placement, overlayNode, target, container, padding
) {
  const childOffset = container.tagName === 'BODY' ?
    getOffset(target) : getPosition(target, container);

  const { height: overlayHeight, width: overlayWidth } =
    getOffset(overlayNode);

  let positionLeft, positionTop, arrowOffsetLeft, arrowOffsetTop;

  if (placement === 'left' || placement === 'right') {
    positionTop = childOffset.top + (childOffset.height - overlayHeight) / 2;

    if (placement === 'left') {
      positionLeft = childOffset.left - overlayWidth;
    } else {
      positionLeft = childOffset.left + childOffset.width;
    }

    const topDelta = getTopDelta(
github react-bootstrap / react-overlays / src / Affix.js View on Github external
updateStateAtBottom = () => {
    const positionTopMax = this.getPositionTopMax()
    const offsetParent = getOffsetParent(ReactDOM.findDOMNode(this))
    const parentTop = getOffset(offsetParent).top

    this.updateState('bottom', 'absolute', positionTopMax - parentTop)
  }