Version 1.0.0
This commit is contained in:
27
resources/js/hooks/use-font-size.tsx
Normal file
27
resources/js/hooks/use-font-size.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
type FontSize = 'normal' | 'large' | 'larger';
|
||||
|
||||
export function useFontSize() {
|
||||
const [fontSize, setFontSize] = useState<FontSize>(() => {
|
||||
if (typeof window !== 'undefined') {
|
||||
const saved = localStorage.getItem('font-size');
|
||||
if (saved && ['normal', 'large', 'larger'].includes(saved)) {
|
||||
return saved as FontSize;
|
||||
}
|
||||
}
|
||||
return 'normal';
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const root = window.document.documentElement;
|
||||
root.classList.remove('text-normal', 'text-large', 'text-larger');
|
||||
root.classList.add(`text-${fontSize}`);
|
||||
localStorage.setItem('font-size', fontSize);
|
||||
}, [fontSize]);
|
||||
|
||||
return {
|
||||
fontSize,
|
||||
setFontSize,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user