mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 23:52:19 +08:00

* update eslint, tsconfig + esbuild to handle new jsx transform * remove thing that breaks the new jsx transform * remove react imports * adjust grafana-icons build * is this the correct syntax? * try this * well this was much easier than expected... * change grafana-plugin-configs webpack config * fixes * fix lockfile * fix 2 more violations * use path.resolve instead of require.resolve * remove react import * fix react imports * more fixes * remove React import * remove import React from docs * remove another react import
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import * as React from 'react';
|
|
import { SkeletonTheme } from 'react-loading-skeleton';
|
|
|
|
import { GrafanaTheme2, ThemeContext } from '@grafana/data';
|
|
import { ThemeChangedEvent, config } from '@grafana/runtime';
|
|
|
|
import { appEvents } from '../core';
|
|
|
|
import 'react-loading-skeleton/dist/skeleton.css';
|
|
|
|
export const ThemeProvider = ({ children, value }: { children: React.ReactNode; value: GrafanaTheme2 }) => {
|
|
const [theme, setTheme] = useState(value);
|
|
|
|
useEffect(() => {
|
|
const sub = appEvents.subscribe(ThemeChangedEvent, (event) => {
|
|
config.theme2 = event.payload;
|
|
setTheme(event.payload);
|
|
});
|
|
|
|
return () => sub.unsubscribe();
|
|
}, []);
|
|
|
|
return (
|
|
<ThemeContext.Provider value={theme}>
|
|
<SkeletonTheme
|
|
baseColor={theme.colors.emphasize(theme.colors.background.secondary)}
|
|
highlightColor={theme.colors.emphasize(theme.colors.background.secondary, 0.1)}
|
|
borderRadius={theme.shape.radius.default}
|
|
>
|
|
{children}
|
|
</SkeletonTheme>
|
|
</ThemeContext.Provider>
|
|
);
|
|
};
|
|
|
|
export const provideTheme = <P extends {}>(component: React.ComponentType<P>, theme: GrafanaTheme2) => {
|
|
return function ThemeProviderWrapper(props: P) {
|
|
return <ThemeProvider value={theme}>{React.createElement(component, { ...props })}</ThemeProvider>;
|
|
};
|
|
};
|