1 | {"version":3,"file":"getGlobalClassNames.js","sourceRoot":"../src/","sources":["styles/getGlobalClassNames.ts"],"names":[],"mappings":";;AACA,uDAAoD;AACpD,iDAAsD;AAItD;;;GAGG;AACH,IAAM,oBAAoB,GAAG,2BAAe,CAC1C,UAAI,UAA+B,EAAE,uBAAiC;IACpE,IAAM,UAAU,GAAG,yBAAU,CAAC,WAAW,EAAE,CAAC;IAE5C,IAAI,uBAAuB,EAAE;QAC3B,4BAA4B;QAC5B,OAAQ,MAAM,CAAC,IAAI,CAAC,UAAU,CAAiB,CAAC,MAAM,CAAC,UAAC,GAAG,EAAE,SAAS;YACpE,GAAG,CAAC,SAAS,CAAC,GAAG,UAAU,CAAC,YAAY,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;YAChE,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAyB,CAAC,CAAC;KAC/B;IAED,wBAAwB;IACxB,OAAO,UAAU,CAAC;AACpB,CAAC,CACF,CAAC;AAEF;;;;;;;;GAQG;AACH,SAAgB,mBAAmB,CACjC,UAA+B,EAC/B,KAAa,EACb,uBAAiC;IAEjC,OAAO,oBAAoB,CACzB,UAAU,EACV,uBAAuB,KAAK,SAAS,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,KAAK,CAAC,uBAAuB,CAChG,CAAC;AACJ,CAAC;AATD,kDASC","sourcesContent":["import { ITheme } from '../interfaces/index';\nimport { Stylesheet } from '@uifabric/merge-styles';\nimport { memoizeFunction } from '@uifabric/utilities';\n\nexport type GlobalClassNames<IStyles> = Record<keyof IStyles, string>;\n\n/**\n * Internal memoized function which simply takes in the class map and the\n * disable boolean. These immutable values can be memoized.\n */\nconst _getGlobalClassNames = memoizeFunction(\n <T>(classNames: GlobalClassNames<T>, disableGlobalClassNames?: boolean): GlobalClassNames<T> => {\n const styleSheet = Stylesheet.getInstance();\n\n if (disableGlobalClassNames) {\n // disable global classnames\n return (Object.keys(classNames) as (keyof T)[]).reduce((acc, className) => {\n acc[className] = styleSheet.getClassName(classNames[className]);\n return acc;\n }, {} as GlobalClassNames<T>);\n }\n\n // use global classnames\n return classNames;\n },\n);\n\n/**\n * Checks for the `disableGlobalClassNames` property on the `theme` to determine if it should return `classNames`\n * Note that calls to this function are memoized.\n *\n * @param classNames - The collection of global class names that apply when the flag is false. Make sure to pass in\n * the same instance on each call to benefit from memoization.\n * @param theme - The theme to check the flag on\n * @param disableGlobalClassNames - Optional. Explicitly opt in/out of disabling global classnames. Defaults to false.\n */\nexport function getGlobalClassNames<T>(\n classNames: GlobalClassNames<T>,\n theme: ITheme,\n disableGlobalClassNames?: boolean,\n): GlobalClassNames<T> {\n return _getGlobalClassNames(\n classNames,\n disableGlobalClassNames !== undefined ? disableGlobalClassNames : theme.disableGlobalClassNames,\n );\n}\n"]} |