| 
									
										
										
										
											2024-06-25 19:43:47 +08:00
										 |  |  | import { useEffect, useState } from 'react'; | 
					
						
							|  |  |  | import * as React from 'react'; | 
					
						
							| 
									
										
										
										
											2023-06-01 18:06:28 +08:00
										 |  |  | import { SkeletonTheme } from 'react-loading-skeleton'; | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-13 20:11:41 +08:00
										 |  |  | import { GrafanaTheme2, ThemeContext } from '@grafana/data'; | 
					
						
							| 
									
										
										
										
											2023-05-10 21:37:04 +08:00
										 |  |  | import { ThemeChangedEvent, config } from '@grafana/runtime'; | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-20 16:02:06 +08:00
										 |  |  | import { appEvents } from '../core'; | 
					
						
							| 
									
										
										
										
											2019-01-18 16:50:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-01 18:06:28 +08:00
										 |  |  | import 'react-loading-skeleton/dist/skeleton.css'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-15 02:34:00 +08:00
										 |  |  | export const ThemeProvider = ({ children, value }: { children: React.ReactNode; value: GrafanaTheme2 }) => { | 
					
						
							|  |  |  |   const [theme, setTheme] = useState(value); | 
					
						
							| 
									
										
										
										
											2019-01-18 16:50:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-20 16:02:06 +08:00
										 |  |  |   useEffect(() => { | 
					
						
							|  |  |  |     const sub = appEvents.subscribe(ThemeChangedEvent, (event) => { | 
					
						
							| 
									
										
										
										
											2023-05-10 21:37:04 +08:00
										 |  |  |       config.theme2 = event.payload; | 
					
						
							| 
									
										
										
										
											2021-02-20 16:02:06 +08:00
										 |  |  |       setTheme(event.payload); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-01-18 16:50:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-20 16:02:06 +08:00
										 |  |  |     return () => sub.unsubscribe(); | 
					
						
							|  |  |  |   }, []); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-01 18:06:28 +08:00
										 |  |  |   return ( | 
					
						
							|  |  |  |     <ThemeContext.Provider value={theme}> | 
					
						
							|  |  |  |       <SkeletonTheme | 
					
						
							| 
									
										
										
										
											2023-11-13 18:32:42 +08:00
										 |  |  |         baseColor={theme.colors.emphasize(theme.colors.background.secondary)} | 
					
						
							|  |  |  |         highlightColor={theme.colors.emphasize(theme.colors.background.secondary, 0.1)} | 
					
						
							| 
									
										
										
										
											2023-08-01 21:46:07 +08:00
										 |  |  |         borderRadius={theme.shape.radius.default} | 
					
						
							| 
									
										
										
										
											2023-06-01 18:06:28 +08:00
										 |  |  |       > | 
					
						
							|  |  |  |         {children} | 
					
						
							|  |  |  |       </SkeletonTheme> | 
					
						
							|  |  |  |     </ThemeContext.Provider> | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2019-01-18 16:50:29 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-02-06 00:04:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 00:21:37 +08:00
										 |  |  | export const provideTheme = <P extends {}>(component: React.ComponentType<P>, theme: GrafanaTheme2) => { | 
					
						
							|  |  |  |   return function ThemeProviderWrapper(props: P) { | 
					
						
							| 
									
										
										
										
											2022-07-23 23:09:03 +08:00
										 |  |  |     return <ThemeProvider value={theme}>{React.createElement(component, { ...props })}</ThemeProvider>; | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2019-02-06 00:04:48 +08:00
										 |  |  | }; |