refactor/add build time to page footers
This commit is contained in:
		
							
								
								
									
										13
									
								
								src/hooks/useHtmlThemeAttr.jsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/hooks/useHtmlThemeAttr.jsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
export function useHtmlThemeAttr () {
 | 
			
		||||
  const [theme, setTheme] = useState(() =>
 | 
			
		||||
    document.documentElement.getAttribute("data-theme") || "light"
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    const handler = (e) => setTheme(e.detail);
 | 
			
		||||
    document.addEventListener("set-theme", handler);
 | 
			
		||||
    return () => document.removeEventListener("set-theme", handler);
 | 
			
		||||
  }, []);
 | 
			
		||||
 | 
			
		||||
  return theme;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										17
									
								
								src/hooks/usePrimeReactThemeSwitcher.jsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/hooks/usePrimeReactThemeSwitcher.jsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
import { useEffect } from "react";
 | 
			
		||||
 | 
			
		||||
export function usePrimeReactThemeSwitcher(theme) {
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    const themeLink = document.getElementById("primereact-theme");
 | 
			
		||||
    if (!themeLink) return;
 | 
			
		||||
 | 
			
		||||
    const newTheme =
 | 
			
		||||
      theme === "dark"
 | 
			
		||||
        ? "/themes/bootstrap4-dark-blue/theme.css"
 | 
			
		||||
        : "/themes/bootstrap4-light-blue/theme.css";
 | 
			
		||||
 | 
			
		||||
    if (themeLink.href !== newTheme) {
 | 
			
		||||
      themeLink.href = newTheme;
 | 
			
		||||
    }
 | 
			
		||||
  }, [theme]);
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user