Skip to content

Commit e6ff448

Browse files
committed
Added emToPx utility function
1 parent 2114f82 commit e6ff448

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/utils/dom.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,18 @@ export const createNativeNotification = (options, onclick) => {
253253

254254
return Promise.reject('Unsupported');
255255
};
256+
257+
/**
258+
* Calculates pixel size from em
259+
* @param {number} em Em size
260+
* @param {DOMElement} [root=document.body] Optional root element
261+
* @return {number} Size in pixels
262+
*/
263+
export const emToPx = (em, root = document.body) => {
264+
const px = parseInt(
265+
getComputedStyle(root).fontSize,
266+
10
267+
);
268+
269+
return Math.round(px * em);
270+
};

0 commit comments

Comments
 (0)