Debian Codegraph @

packages/popper/src/utils/setStyles.js

raw
1 import isNumeric from './isNumeric';
2
3 /**
4 * Set the style to the given popper
5 * @method
6 * @memberof Popper.Utils
7 * @argument {Element} element - Element to apply the style to
8 * @argument {Object} styles
9 * Object with a list of properties and values which will be applied to the element
10 */
11 export default function setStyles(element, styles) {
12 Object.keys(styles).forEach(prop => {
13 let unit = '';
14 // add unit if the value is numeric and is one of the following
15 if (
16 ['width', 'height', 'top', 'right', 'bottom', 'left'].indexOf(prop) !==
17 -1 &&
18 isNumeric(styles[prop])
19 ) {
20 unit = 'px';
21 }
22 element.style[prop] = styles[prop] + unit;
23 });
24 }