Skip to content

Commit 3729063

Browse files
fix(ui): make heading responsive in QuickstartFilter
Signed-off-by: Devesh Shukla <[email protected]>
1 parent 78b1aae commit 3729063

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/components/QuickStartFilter.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useState} from "react";
1+
import React, {useEffect, useState} from "react";
22
import quickstarts from "./QuickStartList";
33
import Link from "@docusaurus/Link";
44
import {FaGolang} from "react-icons/fa6";
@@ -31,10 +31,25 @@ const IconWrapper = ({icon, bg}) => (
3131
</div>
3232
);
3333

34+
35+
export function useMediaQuery(query) {
36+
const [matches, setMatches] = useState(false);
37+
38+
useEffect(() => {
39+
const media = window.matchMedia(query);
40+
setMatches(media.matches);
41+
const listener = () => setMatches(media.matches);
42+
media.addEventListener("change", listener);
43+
return () => media.removeEventListener("change", listener);
44+
}, [query]);
45+
46+
return matches;
47+
}
48+
3449
export default function QuickstartFilter({defaultLanguage = null}) {
3550
const {colorMode} = useColorMode();
3651
const isDark = colorMode === "dark";
37-
52+
const isMobile = useMediaQuery("(max-width: 480px)");
3853
// 👇 initialize with defaultLanguage if provided
3954
const [language, setLanguage] = useState(defaultLanguage);
4055
const [server, setServer] = useState(null);
@@ -109,8 +124,8 @@ export default function QuickstartFilter({defaultLanguage = null}) {
109124
// ----- Styles -----
110125
const headingStyle = {
111126
textAlign: "left",
112-
marginLeft: typeof window !== "undefined" && window.innerWidth < 480 ? "0.75rem" : "1rem",
113-
fontSize: typeof window !== "undefined" && window.innerWidth < 480 ? "1.2rem" : "1.4rem",
127+
marginLeft: isMobile ? "0.75rem" : "1rem",
128+
fontSize: isMobile ? "1.2rem" : "1.4rem",
114129
fontWeight: "600",
115130
color: isDark ? "#fff" : "#222",
116131
};

0 commit comments

Comments
 (0)