Skip to content

Commit dd8b06c

Browse files
committed
feat: add dynamic screen size table component
1 parent 2da2a3b commit dd8b06c

4 files changed

Lines changed: 99 additions & 4 deletions

File tree

src/pages/ScreenSize.jsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { useState, useEffect } from "react";
2+
3+
const ScreenSize = () => {
4+
const getViewport = () => {
5+
if (window.visualViewport) {
6+
return {
7+
width: window.visualViewport.width,
8+
height: window.visualViewport.height,
9+
dpr: window.devicePixelRatio,
10+
};
11+
}
12+
return {
13+
width: window.innerWidth,
14+
height: window.innerHeight,
15+
dpr: window.devicePixelRatio,
16+
};
17+
};
18+
19+
const [size, setSize] = useState(getViewport());
20+
21+
useEffect(() => {
22+
const handleResize = () => setSize(getViewport());
23+
24+
window.addEventListener("resize", handleResize);
25+
if (window.visualViewport) {
26+
window.visualViewport.addEventListener("resize", handleResize);
27+
}
28+
29+
return () => {
30+
window.removeEventListener("resize", handleResize);
31+
if (window.visualViewport) {
32+
window.visualViewport.removeEventListener("resize", handleResize);
33+
}
34+
};
35+
}, []);
36+
37+
const getReducedRatio = (w, h) => {
38+
const gcd = (a, b) => (b === 0 ? a : gcd(b, a % b));
39+
const divisor = gcd(Math.round(w), Math.round(h));
40+
return `${Math.round(w / divisor)}:${Math.round(h / divisor)}`;
41+
};
42+
43+
return (
44+
<div className="flex justify-center items-center min-h-screen">
45+
<table className="table-auto border-collapse border border-gray-400 shadow-lg rounded-lg">
46+
<thead className="bg-white/10">
47+
<tr>
48+
<th className="border border-gray-400 px-4 py-2">Property</th>
49+
<th className="border border-gray-400 px-4 py-2">Value</th>
50+
</tr>
51+
</thead>
52+
<tbody>
53+
{Object.entries({
54+
Width: `${size.width.toFixed(2)}px`,
55+
Height: `${size.height.toFixed(2)}px`,
56+
"Aspect Ratio": `${getReducedRatio(size.width, size.height)} (${(
57+
size.width / size.height
58+
).toFixed(2)})`,
59+
"Device Pixel Ratio": size.dpr.toFixed(2),
60+
}).map(([key, value]) => (
61+
<tr key={key}>
62+
<td className="border border-gray-400 px-4 py-2 capitalize text-center">
63+
{key}
64+
</td>
65+
<td className="border border-gray-400 px-4 py-2 text-center">{value}</td>
66+
</tr>
67+
))}
68+
</tbody>
69+
</table>
70+
</div>
71+
);
72+
};
73+
74+
export default ScreenSize;

src/routes.jsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
Hash,
1818
ClipboardList,
1919
ListChecks,
20-
CaseSensitive
20+
CaseSensitive,
21+
Monitor,
2122
} from "lucide-react";
2223

2324
import HomePage from "@/Home";
@@ -30,6 +31,7 @@ const SQIPPreviewer = lazy(() => import("@/pages/SQIPPreviewer"));
3031
const TypescriptPlayground = lazy(() => import("@/pages/TypescriptPlayground"));
3132
const GrapesJSEditor = lazy(() => import("@/pages/GrapesJSEditor"));
3233
const LoremIpsumGenerator = lazy(() => import("@/pages/LoremIpsumGenrator"));
34+
import ScreenSize from "@/pages/ScreenSize";
3335
import UnitConverter from "@/pages/UnitConverter";
3436
const MarkdownEditor = lazy(() => import("@/pages/MarkdownEditor"));
3537
const DiffViewer = lazy(() => import("@/pages/DiffViewer"));
@@ -40,7 +42,7 @@ import StringConverter from "@/pages/StringConverter";
4042
const QrCodeGenerator = lazy(() => import("@/pages/QRCodeGenrator"));
4143
const HashGenerator = lazy(() => import("@/pages/HashGenerator"));
4244
const ImageMetadataViewer = lazy(() => import("@/pages/ImageMetadataViewer"));
43-
const TextStylingTool = lazy(() => import("./pages/CssTextStyling"));
45+
const TextStylingTool = lazy(() => import("@/pages/CssTextStyling"));
4446
import Websites from "@/pages/Websites";
4547
// import Test from "@/pages/testing/Test"; // Testing purpose
4648
import NoPage from "@/pages/NoPage";
@@ -227,6 +229,15 @@ const routes = [
227229
category: "Color",
228230
icon: <Palette className={size5} />,
229231
},
232+
{
233+
isNew: true,
234+
path: "screen-size",
235+
element: <ScreenSize />,
236+
description:
237+
"Check your device screen width, height, and viewport dimensions in real time.",
238+
category: "Utility",
239+
icon: <Monitor className={size5} />,
240+
},
230241
{
231242
path: "css-unit-converter",
232243
element: <UnitConverter />,
@@ -245,6 +256,16 @@ const routes = [
245256
category: "css",
246257
icon: <CaseSensitive className={size5} />,
247258
},
259+
/*
260+
{ // Testing purpose
261+
path: "test",
262+
element: <Test />,
263+
description:
264+
"Interactive text style playground for tweaking fonts, gradients, shadows, strokes, and advanced CSS properties. Copy-ready output.",
265+
category: "null",
266+
icon: <CaseSensitive className={size5} />,
267+
},
268+
*/
248269
{
249270
path: "websites",
250271
element: <Websites />,

src/styles/output.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Tasks for allready exist component
44

5+
- every tool change need to be reflect in SEO meta tags for better seo
56
- add tool link: https://www.fontfabric.com/font-tester/?srsltid=AfmBOoqkzkNO_pSMffdfgjkWiVRWqj2p51Dj6mSX4DtUuZJyxg9AqHWz
67
- done just remove lib with command, [ ] remove `store` lib instead use locaStorageState hook if it is good option,
78
- For editor if mobile need to load simple simple textarea and initially monaco editor take time to load until need to show normal editor if until user allready type something need to show ask first want to change editor to monaco to better experiance
@@ -70,7 +71,6 @@
7071
* normal sms <<!--** https://salam.qanawat-me.com/Alnufais/ **-->>
7172
* \*find more
7273
- [ ] (Browser Info) browser all api support need to show table with api name and supprt yes or no example
73-
- [ ] screen width and height live specially for mobile means mobile first
7474
- also need add tip how to check in dev-tools like as you resize in dev tools show screen widthxheight in top-right corner
7575
- [ ] device info with navigator API
7676

0 commit comments

Comments
 (0)