UNPKG

nuke-theme-provider

Version:

主题换肤

71 lines (60 loc) 2.04 kB
import Core from 'nuke-core'; // Privates, ideally those should be symbols const THEME_STYLE = 'themeStyle'; const THEME_STYLE_CACHE = 'themeCachedStyle'; let defaultTheme; function mergeComponentAndThemeStyles() {} const resolveStyle = (style, baseStyle) => resolveIncludes(style, baseStyle); export default class Theme { constructor(themeStyle) { this[THEME_STYLE] = themeStyle; this[THEME_STYLE].Core = Object.assign(Core, this[THEME_STYLE].Core); this[THEME_STYLE_CACHE] = {}; } /** * Sets the given style as a default theme style. */ static setDefaultThemeStyle(style) { defaultTheme = new Theme(style); } /** * Returns the default theme that will be used as fallback * if the StyleProvider is not configured in the app. */ static getDefaultTheme() { if (!defaultTheme) { defaultTheme = new Theme({ Core }); } return defaultTheme; } /** * Creates a component style by merging the theme style on top of the * provided default component style. Any rules in the theme style will * override the rules from the base component style. * * This method will also resolve any INCLUDE keywords in the theme or * component styles before returning the final style. * * @param componentName fully qualified component name. * @param defaultStyle - default component style that will be used as base style. */ createComponentStyle(componentName) { if (this[THEME_STYLE_CACHE][componentName]) { return this[THEME_STYLE_CACHE][componentName]; } // const componentIncludedStyle = resolveStyle( // defaultStyle, // this[THEME_STYLE] // ); return this[THEME_STYLE_CACHE][componentName]; } getComponentRelavantStyle(componentName) { // if (this[THEME_STYLE_CACHE][componentName]) { // return this[THEME_STYLE_CACHE][componentName]; // } // let obj = { // Core: Object.assign(Core, this[THEME_STYLE]['Core']) // } // this[THEME_STYLE_CACHE][componentName]['Core'] = } }