UNPKG

@selfcommunity/react-core

Version:

React Core Components useful for integrating UI Community components (react-ui).

66 lines (65 loc) 3.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const createTheme_1 = tslib_1.__importDefault(require("@mui/material/styles/createTheme")); const utils_1 = require("@selfcommunity/utils"); const validate_color_1 = tslib_1.__importDefault(require("validate-color")); const Preferences_1 = require("../constants/Preferences"); const utils_2 = require("@selfcommunity/utils"); /** * check if colorProp is a valid color * @param preferences * @param prop * @param tFunc: type func validator * @return {boolean|(function(*=): boolean)} */ const isValidPreference = (preferences, prop, tFunc) => { // eslint-disable-next-line no-prototype-builtins if (preferences.hasOwnProperty(prop) && preferences[prop].hasOwnProperty('value')) { return tFunc(preferences[prop].value); } return false; }; /** * Overrides theme properties * @param options: store.settings.theme * @param preferences: community global preferences * @return {SCThemeType} */ const getTheme = (options, preferences) => { const selfcommunity = { user: { avatar: { sizeSmall: 24, sizeMedium: 40, sizeLarge: 50, sizeXLarge: 100, }, }, category: { icon: { sizeSmall: 24, sizeMedium: 40, sizeLarge: 50, }, }, group: { avatar: { sizeSmall: 40, sizeMedium: 60, sizeLarge: 90, sizeXLarge: 120, }, }, }; const defaultOptions = preferences ? { palette: Object.assign(Object.assign(Object.assign(Object.assign({}, (isValidPreference(preferences, Preferences_1.COLORS_COLORBACK, validate_color_1.default) && { background: { default: preferences[Preferences_1.COLORS_COLORBACK].value } })), { text: Object.assign(Object.assign({}, (isValidPreference(preferences, Preferences_1.COLORS_COLORFONT, validate_color_1.default) && { primary: preferences[Preferences_1.COLORS_COLORFONT].value })), (isValidPreference(preferences, Preferences_1.COLORS_COLORFONTSECONDARY, validate_color_1.default) && { secondary: preferences[Preferences_1.COLORS_COLORFONTSECONDARY].value, })) }), (isValidPreference(preferences, Preferences_1.COLORS_COLORPRIMARY, validate_color_1.default) && { primary: { main: preferences[Preferences_1.COLORS_COLORPRIMARY].value } })), (isValidPreference(preferences, Preferences_1.COLORS_COLORSECONDARY, validate_color_1.default) && Object.assign({ secondary: { main: preferences[Preferences_1.COLORS_COLORSECONDARY].value } }, (isValidPreference(preferences, Preferences_1.COLORS_NAVBARBACK, validate_color_1.default) && { navbar: { main: preferences[Preferences_1.COLORS_NAVBARBACK].value } })))), typography: Object.assign({}, (isValidPreference(preferences, Preferences_1.STYLE_FONT_FAMILY, utils_2.isString) && { fontFamily: preferences[Preferences_1.STYLE_FONT_FAMILY].value })), } : {}; return (0, createTheme_1.default)((0, utils_1.mergeDeep)(Object.assign({ selfcommunity }, defaultOptions), options)); }; exports.default = getTheme;