export function createTheme(theme: IPartialTheme, depComments: boolean = false): ITheme { let newPalette = { ...DefaultPalette, ...theme.palette }; if (!theme.palette || !theme.palette.accent) { newPalette.accent = newPalette.themePrimary; } // mix in custom overrides with good slots first, since custom overrides might be used in fixing deprecated slots let newSemanticColors = { ..._makeSemanticColorsFromPalette(newPalette, !!theme.isInverted, depComments), ...theme.semanticColors }; let defaultFontStyles: IFontStyles = { ...DefaultFontStyles }; if (theme.defaultFontStyle) { for (const fontStyle of Object.keys(defaultFontStyles)) { defaultFontStyles[fontStyle] = merge({}, defaultFontStyles[fontStyle], theme.defaultFontStyle); } } if (theme.fonts) { for (const fontStyle of Object.keys(theme.fonts)) { defaultFontStyles[fontStyle] = merge({}, defaultFontStyles[fontStyle], theme.fonts[fontStyle]); } } return { palette: newPalette, fonts: { ...defaultFontStyles }, semanticColors: newSemanticColors, isInverted: !!theme.isInverted, disableGlobalClassNames: !!theme.disableGlobalClassNames, spacing: { ...DefaultSpacing, ...theme.spacing }, effects: { ...DefaultEffects, ...theme.effects } }; }
export function createTheme(theme: IPartialTheme, depComments: boolean = false): ITheme { let newPalette = { ...DefaultPalette, ...theme.palette }; if (!theme.palette || !theme.palette.accent) { newPalette.accent = newPalette.themePrimary; } // mix in custom overrides with good slots first, since custom overrides might be used in fixing deprecated slots let newSemanticColors = { ..._makeSemanticColorsFromPalette(newPalette, !!theme.isInverted, depComments), ...theme.semanticColors }; const typography = merge<ITypography>({}, DefaultTypography, theme.typography as ITypography); const { variants } = typography; for (const variantName in variants) { if (variants.hasOwnProperty(variantName)) { const variant: IFontVariant = { ...variants.default, ...variants[variantName] }; variant.family = _expandFrom(variant.family, typography.families); variant.size = _expandFrom(variant.size, typography.sizes); variant.weight = _expandFrom(variant.weight, typography.weights); variant.color = _expandFrom(variant.color, newSemanticColors); variant.hoverColor = _expandFrom(variant.hoverColor, newSemanticColors); variant.disabledColor = _expandFrom(variant.disabledColor, newSemanticColors); variants[variantName] = variant; } } return { palette: newPalette, fonts: { ...DefaultFontStyles, ...theme.fonts }, semanticColors: newSemanticColors, isInverted: !!theme.isInverted, disableGlobalClassNames: !!theme.disableGlobalClassNames, typography: typography as ITypography }; }