UNPKG

1.51 kBJavaScriptView Raw
1import { Stylesheet } from '@uifabric/merge-styles';
2import { memoizeFunction } from '@uifabric/utilities';
3/**
4 * Internal memoized function which simply takes in the class map and the
5 * disable boolean. These immutable values can be memoized.
6 */
7var _getGlobalClassNames = memoizeFunction(function (classNames, disableGlobalClassNames) {
8 var styleSheet = Stylesheet.getInstance();
9 if (disableGlobalClassNames) {
10 // disable global classnames
11 return Object.keys(classNames).reduce(function (acc, className) {
12 acc[className] = styleSheet.getClassName(classNames[className]);
13 return acc;
14 }, {});
15 }
16 // use global classnames
17 return classNames;
18});
19/**
20 * Checks for the `disableGlobalClassNames` property on the `theme` to determine if it should return `classNames`
21 * Note that calls to this function are memoized.
22 *
23 * @param classNames - The collection of global class names that apply when the flag is false. Make sure to pass in
24 * the same instance on each call to benefit from memoization.
25 * @param theme - The theme to check the flag on
26 * @param disableGlobalClassNames - Optional. Explicitly opt in/out of disabling global classnames. Defaults to false.
27 */
28export function getGlobalClassNames(classNames, theme, disableGlobalClassNames) {
29 return _getGlobalClassNames(classNames, disableGlobalClassNames !== undefined ? disableGlobalClassNames : theme.disableGlobalClassNames);
30}
31//# sourceMappingURL=getGlobalClassNames.js.map
\No newline at end of file