diff --git a/public/app/core/utils/ConfigProvider.tsx b/public/app/core/utils/ConfigProvider.tsx new file mode 100644 index 00000000000..6883401ad27 --- /dev/null +++ b/public/app/core/utils/ConfigProvider.tsx @@ -0,0 +1,28 @@ +import React from 'react'; +import config, { Settings } from 'app/core/config'; +import { GrafanaTheme } from '@grafana/ui'; + +export const ConfigContext = React.createContext(config); +export const ConfigConsumer = ConfigContext.Consumer; + +export const provideConfig = (component: React.ComponentType) => { + const ConfigProvider = (props: any) => ( + {React.createElement(component, { ...props })} + ); + + return ConfigProvider; +}; + +interface ThemeProviderProps { + children: (theme: GrafanaTheme) => JSX.Element; +} + +export const ThemeProvider = ({ children }: ThemeProviderProps) => { + return ( + + {({ bootData }) => { + return children(bootData.user.lightTheme ? GrafanaTheme.Light : GrafanaTheme.Dark); + }} + + ); +}; diff --git a/public/app/core/utils/react2angular.ts b/public/app/core/utils/react2angular.ts index 6dc1803133a..1057f68fcda 100644 --- a/public/app/core/utils/react2angular.ts +++ b/public/app/core/utils/react2angular.ts @@ -1,10 +1,11 @@ import coreModule from 'app/core/core_module'; +import { provideConfig } from 'app/core/utils/ConfigProvider'; export function react2AngularDirective(name: string, component: any, options: any) { coreModule.directive(name, [ 'reactDirective', reactDirective => { - return reactDirective(component, options); + return reactDirective(provideConfig(component), options); }, ]); }