@itwin/itwinui-react
Version:
A react component library for iTwinUI
47 lines (46 loc) • 1.37 kB
JavaScript
import * as React from 'react';
import { ThemeContext } from '../../core/ThemeProvider/ThemeContext.js';
import { isUnitTest } from '../functions/dev.js';
let didLogWarning = {
fontSize: false,
themeProvider: false,
};
export const useGlobals = () => {
let themeContext = React.useContext(ThemeContext);
useThemeProviderWarning(themeContext);
useRootFontSizeWarning();
return themeContext;
};
export const useThemeProviderWarning = (themeContext) => {
React.useEffect(() => {
if (
'development' === process.env.NODE_ENV &&
!isUnitTest &&
!didLogWarning.themeProvider &&
!themeContext
) {
console.error(
'iTwinUI components must be used within a tree wrapped in a ThemeProvider.',
);
didLogWarning.themeProvider = true;
}
}, [themeContext]);
};
let useRootFontSizeWarning = () => {
React.useEffect(() => {
if (
'development' === process.env.NODE_ENV &&
!isUnitTest &&
!didLogWarning.fontSize
) {
let rootFontSize = parseInt(
getComputedStyle(document.documentElement).fontSize,
);
if (rootFontSize < 16)
console.error(
'Root font size must not be overridden. \nSee https://github.com/iTwin/iTwinUI/wiki/iTwinUI-react-v2-migration-guide#relative-font-size',
);
didLogWarning.fontSize = true;
}
}, []);
};