Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"next": "15.3.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-icons": "^5.5.0",
"react-markdown": "^10.1.0",
"react-rnd": "^10.5.2",
"rehype-highlight": "^7.0.2",
Expand Down
5 changes: 5 additions & 0 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
:root {
--background: #ffffff;
--foreground: #171717;
--text-scale: 1.0;
}

html {
font-size: calc(16px * var(--text-scale));
}

@theme inline {
Expand Down
3 changes: 3 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const metadata: Metadata = {
},
};

import TextSizeAdjuster from '@/components/Common/TextSizeAdjuster';

export default function RootLayout({
children,
}: Readonly<{
Expand Down Expand Up @@ -79,6 +81,7 @@ export default function RootLayout({
{children}
</div>
</div>
<TextSizeAdjuster />
<Analytics />
<SpeedInsights />
</body>
Expand Down
54 changes: 54 additions & 0 deletions src/components/Common/TextSizeAdjuster.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use client';

import { useState, useEffect } from 'react';
import { FaPlus, FaMinus } from 'react-icons/fa';

const TEXT_SCALE_KEY = 'text-scale';
const DEFAULT_TEXT_SCALE = 1.0;
const MIN_TEXT_SCALE = 0.8;
const MAX_TEXT_SCALE = 1.2;
const STEP_TEXT_SCALE = 0.1;

export default function TextSizeAdjuster() {
const [currentScale, setCurrentScale] = useState<number>(DEFAULT_TEXT_SCALE);

useEffect(() => {
const savedScale = localStorage.getItem(TEXT_SCALE_KEY);
const initialScale = savedScale ? parseFloat(savedScale) : DEFAULT_TEXT_SCALE;
setCurrentScale(initialScale);
document.documentElement.style.setProperty('--text-scale', initialScale.toString());
}, []);

const adjustTextSize = (direction: 'increase' | 'decrease') => {
setCurrentScale((prevScale) => {
let newScale = prevScale;
if (direction === 'increase') {
newScale = Math.min(MAX_TEXT_SCALE, prevScale + STEP_TEXT_SCALE);
} else {
newScale = Math.max(MIN_TEXT_SCALE, prevScale - STEP_TEXT_SCALE);
}
localStorage.setItem(TEXT_SCALE_KEY, newScale.toString());
document.documentElement.style.setProperty('--text-scale', newScale.toString());
return newScale;
});
};

return (
<div className="fixed bottom-4 right-4 z-50 flex space-x-2 p-2 bg-gray-800 text-white rounded-full shadow-lg">
<button
onClick={() => adjustTextSize('decrease')}
className="p-2 rounded-full bg-gray-700 hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-gray-500"
aria-label="Decrease text size"
>
<FaMinus />
</button>
<button
onClick={() => adjustTextSize('increase')}
className="p-2 rounded-full bg-gray-700 hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-gray-500"
aria-label="Increase text size"
>
<FaPlus />
</button>
</div>
);
}