UNPKG

react-native-ui-lib

Version:

<p align="center"> <img src="https://user-images.githubusercontent.com/1780255/105469025-56759000-5ca0-11eb-993d-3568c1fd54f4.png" height="250px" style="display:block"/> </p> <p align="center">UI Toolset & Components Library for React Native</p> <p a

93 lines (74 loc) 1.96 kB
import _ from 'lodash'; import Colors from "./colors"; export class ThemeManager { theme = { primaryColor: Colors.primary, CTA: { textColor: Colors.white, disabledColor: Colors.grey60, backgroundColor: Colors.primary }, titleColor: Colors.grey10, subtitleColor: Colors.grey40, dividerColor: Colors.grey70, components: {} // leave this key and delete the rest on V6 }; forcedTheme = { components: {} }; getTheme() { return this.theme; } setItem(key, value) { if (key === 'components') { throw new Error('Overriding the "components" key is not possible.'); } // this.theme[key] = value; _.set(this.theme, key, value); } getItem(key) { // return this.theme[key]; return _.get(this.theme, key); } setComponentTheme(componentName, overrides) { if (_.isFunction(overrides)) { this.theme.components[componentName] = overrides; } else { this.theme.components[componentName] = _.cloneDeep(overrides); } } setComponentForcedTheme(componentName, overrides) { if (_.isFunction(overrides)) { this.forcedTheme.components[componentName] = overrides; } else { this.forcedTheme.components[componentName] = _.cloneDeep(overrides); } } get components() { return this.theme.components; } get forcedThemeComponents() { return this.forcedTheme.components; } // TODO: remove getters below get primaryColor() { return this.theme.primaryColor; } get CTATextColor() { return this.theme.CTA.textColor; } get CTADisabledColor() { return this.theme.CTA.disabledColor; } get CTABackgroundColor() { return this.theme.CTA.backgroundColor; } get titleColor() { return this.theme.titleColor; } get subtitleColor() { return this.theme.subtitleColor; } get dividerColor() { return this.theme.dividerColor; } } export default new ThemeManager();