|
1 | | -import React, {useState} from "react"; |
| 1 | +import React, {useEffect, useState} from "react"; |
2 | 2 | import quickstarts from "./QuickStartList"; |
3 | 3 | import Link from "@docusaurus/Link"; |
4 | 4 | import {FaGolang} from "react-icons/fa6"; |
@@ -31,10 +31,25 @@ const IconWrapper = ({icon, bg}) => ( |
31 | 31 | </div> |
32 | 32 | ); |
33 | 33 |
|
| 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 | + |
34 | 49 | export default function QuickstartFilter({defaultLanguage = null}) { |
35 | 50 | const {colorMode} = useColorMode(); |
36 | 51 | const isDark = colorMode === "dark"; |
37 | | - |
| 52 | + const isMobile = useMediaQuery("(max-width: 480px)"); |
38 | 53 | // 👇 initialize with defaultLanguage if provided |
39 | 54 | const [language, setLanguage] = useState(defaultLanguage); |
40 | 55 | const [server, setServer] = useState(null); |
@@ -109,8 +124,8 @@ export default function QuickstartFilter({defaultLanguage = null}) { |
109 | 124 | // ----- Styles ----- |
110 | 125 | const headingStyle = { |
111 | 126 | 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", |
114 | 129 | fontWeight: "600", |
115 | 130 | color: isDark ? "#fff" : "#222", |
116 | 131 | }; |
|
0 commit comments