baseui
Version:
A React Component library implementing the Base design language
45 lines (42 loc) • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.handleAriaLiveUpdates = exports.formatBytes = exports.destructureStyleOverride = void 0;
var _constants = require("./constants");
/*
Copyright (c) Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
const destructureStyleOverride = (styleOverride, theme) => {
if (typeof styleOverride === 'function') {
return styleOverride({
$theme: theme
});
} else {
return styleOverride;
}
};
exports.destructureStyleOverride = destructureStyleOverride;
const formatBytes = bytes => {
if (bytes === 0) return '0 bytes';
const k = 1000;
const sizes = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
};
exports.formatBytes = formatBytes;
const handleAriaLiveUpdates = (elementId, updateMessage) => {
const liveRegion = document.getElementById(elementId);
if (liveRegion) {
liveRegion.textContent = updateMessage;
}
setTimeout(() => {
const liveRegion = document.getElementById(elementId);
if (liveRegion) {
liveRegion.textContent = null;
}
}, _constants.ARIA_LIVE_TIMEOUT_MS);
};
exports.handleAriaLiveUpdates = handleAriaLiveUpdates;