import { RiDice4Line } from 'react-icons/ri'; import { SanitizedThemeConfig } from '../../interfaces/sanitized-config'; import { LOCAL_STORAGE_KEY_NAME } from '../../constants'; import { skeleton } from '../../utils'; import { MouseEvent } from 'react'; /** * Renders a theme changer component. * * @param {Object} props - The props object. * @param {string} props.theme - The current theme. * @param {function} props.setTheme - A function to set the theme. * @param {boolean} props.loading - Whether the component is in a loading state. * @param {SanitizedThemeConfig} props.themeConfig - The theme configuration object. * @return {JSX.Element} The rendered theme changer component. */ const ThemeChanger = ({ theme, setTheme, loading, themeConfig, }: { theme: string; setTheme: (theme: string) => void; loading: boolean; themeConfig: SanitizedThemeConfig; }) => { const changeTheme = ( e: MouseEvent, selectedTheme: string, ) => { e.preventDefault(); document.querySelector('html')?.setAttribute('data-theme', selectedTheme); typeof window !== 'undefined' && localStorage.setItem(LOCAL_STORAGE_KEY_NAME, selectedTheme); setTheme(selectedTheme); }; return (
{loading ? ( skeleton({ widthCls: 'w-20', heightCls: 'h-8', className: 'mb-1', }) ) : ( Theme )}
{loading ? skeleton({ widthCls: 'w-16', heightCls: 'h-5' }) : theme === themeConfig.defaultTheme ? 'Default' : theme}
{loading ? ( skeleton({ widthCls: 'w-12', heightCls: 'h-10', className: 'mr-6', }) ) : (
)}
); }; export default ThemeChanger;