Skip to content

Commit

Permalink
feat(project): highlight, background color as var
Browse files Browse the repository at this point in the history
  • Loading branch information
RCVZ committed May 4, 2021
1 parent 743cefe commit 3cb89d9
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/providers/configProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React, {
} from 'react';

import loadConfig, { validateConfig } from '../services/config.service';
import type { Config } from '../../types/Config';
import type { Config, Options } from '../../types/Config';

const defaultConfig: Config = {
id: '',
Expand Down Expand Up @@ -45,6 +45,7 @@ const ConfigProvider: FunctionComponent<ProviderProps> = ({
validateConfig(config)
.then((configValidated) => {
setConfig(configValidated);
setCssVariables(configValidated.options);
onLoading(false);
})
.catch((error: Error) => {
Expand All @@ -55,6 +56,18 @@ const ConfigProvider: FunctionComponent<ProviderProps> = ({
loadAndValidateConfig(configLocation);
}, [configLocation, onLoading, onValidationError]);

const setCssVariables = ({
backgroundColor = '#000',
highlightColor = '#fff',
}: Options) => {
const root = document.querySelector(':root') as HTMLElement;

if (root) {
root.style.setProperty('--background-color', backgroundColor);
root.style.setProperty('--highlight-color', highlightColor);
}
};

return (
<ConfigContext.Provider value={config}>{children}</ConfigContext.Provider>
);
Expand Down

0 comments on commit 3cb89d9

Please sign in to comment.