UNPKG

2.1 kBJavaScriptView Raw
1import { Customizations, mergeSettings } from '@uifabric/utilities';
2/**
3 * @internal
4 * This function is still in experimental phase in support of Foundation experimental development.
5 * Its API signature and existence are subject to change.
6 *
7 * Modify context to activate the specified scheme or theme. For schemes, look in context (if available) and fall back
8 * to global Customizations. If both scheme and theme are specified, scheme will be looked up in theme. In this case,
9 * scheme must be present in theme arg, otherwise new context will default to theme arg (there is no fallback to
10 * settings to look up scheme.)
11 *
12 * @param context - Context in which to get schemed customizations.
13 * @param scheme - Scheme to get customizations for from theme arg (if supplied) OR from context and global settings.
14 * @param theme - Theme to merge into context.
15 * @returns modified schemed context if scheme is valid and not already applied, unmodified context otherwise.
16 */
17export function getThemedContext(context, scheme, theme) {
18 var newContext = context;
19 var newSettings;
20 // Only fall back to context and customizations when theme arg is not provided.
21 var schemeSource = theme || Customizations.getSettings(['theme'], undefined, context.customizations).theme;
22 if (theme) {
23 newSettings = { theme: theme };
24 }
25 var schemeTheme = scheme && schemeSource && schemeSource.schemes && schemeSource.schemes[scheme];
26 // These first two checks are logically redundant but TS doesn't infer schemeSource.schemes is defined
27 // when schemeTheme is defined.
28 if (schemeSource && schemeTheme && schemeSource !== schemeTheme) {
29 newSettings = { theme: schemeTheme };
30 newSettings.theme.schemes = schemeSource.schemes;
31 }
32 if (newSettings) {
33 newContext = {
34 customizations: {
35 settings: mergeSettings(context.customizations.settings, newSettings),
36 scopedSettings: context.customizations.scopedSettings,
37 },
38 };
39 }
40 return newContext;
41}
42//# sourceMappingURL=scheme.js.map
\No newline at end of file