update util

pull/1150/head
tangjinzhou 2019-08-28 22:56:51 +08:00
parent da0f17d1b6
commit 154e24687c
2 changed files with 58 additions and 5 deletions

View File

@ -0,0 +1,20 @@
import getScrollBarSize from './getScrollBarSize';
export default (close) => {
const bodyIsOverflowing = document.body.scrollHeight >
(window.innerHeight || document.documentElement.clientHeight) &&
window.innerWidth > document.body.offsetWidth;
if (!bodyIsOverflowing) {
return;
}
if (close) {
document.body.style.position = '';
document.body.style.width = '';
return;
}
const scrollBarSize = getScrollBarSize();
if (scrollBarSize) {
document.body.style.position = 'relative';
document.body.style.width = `calc(100% - ${scrollBarSize}px)`;
}
};

View File

@ -1,9 +1,42 @@
import warning from 'warning';
/* eslint-disable no-console */
let warned = {};
const warned = {};
export default (valid, message) => {
export function warning(valid, message) {
// Support uglify
if (process.env.NODE_ENV !== 'production' && !valid && console !== undefined) {
console.error(`Warning: ${message}`);
}
}
export function note(valid, message) {
// Support uglify
if (process.env.NODE_ENV !== 'production' && !valid && console !== undefined) {
console.warn(`Note: ${message}`);
}
}
export function resetWarned() {
warned = {};
}
export function call(
method,
valid,
message,
) {
if (!valid && !warned[message]) {
warning(false, message);
method(false, message);
warned[message] = true;
}
};
}
export function warningOnce(valid, message) {
call(warning, valid, message);
}
export function noteOnce(valid, message) {
call(note, valid, message);
}
export default warningOnce;
/* eslint-enable */