UNPKG

@itwin/itwinui-react

Version:

A react component library for iTwinUI

67 lines (66 loc) 1.91 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true, }); function _export(target, all) { for (var name in all) Object.defineProperty(target, name, { enumerable: true, get: all[name], }); } _export(exports, { useGlobals: function () { return useGlobals; }, useThemeProviderWarning: function () { return useThemeProviderWarning; }, }); const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard'); const _react = /*#__PURE__*/ _interop_require_wildcard._(require('react')); const _ThemeContext = require('../../core/ThemeProvider/ThemeContext.js'); const _dev = require('../functions/dev.js'); const didLogWarning = { fontSize: false, themeProvider: false, }; const useGlobals = () => { let themeContext = _react.useContext(_ThemeContext.ThemeContext); useThemeProviderWarning(themeContext); useRootFontSizeWarning(); return themeContext; }; const useThemeProviderWarning = (themeContext) => { _react.useEffect(() => { if ( 'development' === process.env.NODE_ENV && !_dev.isUnitTest && !didLogWarning.themeProvider && !themeContext ) { console.error( 'iTwinUI components must be used within a tree wrapped in a ThemeProvider.', ); didLogWarning.themeProvider = true; } }, [themeContext]); }; const useRootFontSizeWarning = () => { _react.useEffect(() => { if ( 'development' === process.env.NODE_ENV && !_dev.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; } }, []); };