File tree Expand file tree Collapse file tree 2 files changed +50
-2
lines changed Expand file tree Collapse file tree 2 files changed +50
-2
lines changed Original file line number Diff line number Diff line change
1
+ "use client"
2
+
3
+ import { type ReactNode } from "react"
4
+
5
+ import { useMediaQuery } from "@/hooks/useMediaQuery"
6
+
7
+ type MediaQueryChildren =
8
+ | ( ( args : { matches : boolean [ ] ; any : boolean } ) => ReactNode )
9
+ | ReactNode
10
+
11
+ type MediaQueryProps = {
12
+ /**
13
+ * Array of CSS media query strings, e.g. ["(min-width: 768px)"]
14
+ */
15
+ queries : string [ ]
16
+ /**
17
+ * Optional SSR fallbacks for each query. If omitted, defaults to false.
18
+ */
19
+ fallbackMatches ?: boolean [ ]
20
+ /**
21
+ * Either render props or slot children
22
+ */
23
+ children : MediaQueryChildren
24
+ }
25
+
26
+ const MediaQuery = ( {
27
+ queries,
28
+ fallbackMatches,
29
+ children,
30
+ } : MediaQueryProps ) => {
31
+ const matches = useMediaQuery ( queries , fallbackMatches )
32
+ const any = matches . some ( Boolean )
33
+
34
+ if ( typeof children === "function" ) {
35
+ return < > { children ( { matches, any } ) } </ >
36
+ }
37
+
38
+ return < > { any ? children : null } </ >
39
+ }
40
+
41
+ export default MediaQuery
Original file line number Diff line number Diff line change @@ -2,7 +2,10 @@ import { getTranslations } from "next-intl/server"
2
2
3
3
import { EthHomeIcon } from "@/components/icons"
4
4
5
+ import { breakpointAsNumber } from "@/lib/utils/screen"
6
+
5
7
import ClientOnly from "../ClientOnly"
8
+ import MediaQuery from "../MediaQuery"
6
9
import { BaseLink } from "../ui/Link"
7
10
8
11
import DesktopNav from "./DesktopNav"
@@ -28,10 +31,14 @@ const Nav = async () => {
28
31
29
32
< div className = "ms-3 flex w-full justify-end md:justify-between xl:ms-8" >
30
33
< ClientOnly fallback = { < DesktopNavLoading /> } >
31
- < DesktopNav className = "hidden md:flex" />
34
+ < MediaQuery queries = { [ `(min-width: ${ breakpointAsNumber . md } px)` ] } >
35
+ < DesktopNav />
36
+ </ MediaQuery >
32
37
</ ClientOnly >
33
38
< ClientOnly fallback = { < MobileNavLoading /> } >
34
- < MobileNav className = "flex md:hidden" />
39
+ < MediaQuery queries = { [ `(max-width: ${ breakpointAsNumber . md - 1 } px)` ] } >
40
+ < MobileNav />
41
+ </ MediaQuery >
35
42
</ ClientOnly >
36
43
</ div >
37
44
</ nav >
You can’t perform that action at this time.
0 commit comments