UNPKG

react-timekeeper

Version:

Time picker based on the style of the Google Keep app

29 lines (26 loc) 915 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.calcOffset = calcOffset; exports.getScrollBarWidth = getScrollBarWidth; function getScrollBarWidth() { const scrollDiv = document.createElement('div'); scrollDiv.className = 'react-timekeeper-scrollbar-measure'; document.body.appendChild(scrollDiv); const width = scrollDiv.offsetWidth - scrollDiv.clientWidth; document.body.removeChild(scrollDiv); return width; } function calcOffset(el) { const style = window.getComputedStyle(el, null); return function memoizedCalcOffset(clientX, clientY) { const borderLeftWidth = parseInt(style.borderLeftWidth, 10) || 0; const borderTopWidth = parseInt(style.borderTopWidth, 10) || 0; const rect = el.getBoundingClientRect(); return { offsetX: clientX - borderLeftWidth - rect.left, offsetY: clientY - borderTopWidth - rect.top }; }; }