mirror of
https://github.com/grafana/grafana.git
synced 2025-08-03 02:02:12 +08:00
29 lines
855 B
TypeScript
29 lines
855 B
TypeScript
import React from 'react';
|
|
import config, { Settings } from 'app/core/config';
|
|
import { GrafanaTheme } from '@grafana/ui';
|
|
|
|
export const ConfigContext = React.createContext<Settings>(config);
|
|
export const ConfigConsumer = ConfigContext.Consumer;
|
|
|
|
export const provideConfig = (component: React.ComponentType<any>) => {
|
|
const ConfigProvider = (props: any) => (
|
|
<ConfigContext.Provider value={config}>{React.createElement(component, { ...props })}</ConfigContext.Provider>
|
|
);
|
|
|
|
return ConfigProvider;
|
|
};
|
|
|
|
interface ThemeProviderProps {
|
|
children: (theme: GrafanaTheme) => JSX.Element;
|
|
}
|
|
|
|
export const ThemeProvider = ({ children }: ThemeProviderProps) => {
|
|
return (
|
|
<ConfigConsumer>
|
|
{({ bootData }) => {
|
|
return children(bootData.user.lightTheme ? GrafanaTheme.Light : GrafanaTheme.Dark);
|
|
}}
|
|
</ConfigConsumer>
|
|
);
|
|
};
|