-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move layout to use isDesktop and isMobile
- Loading branch information
1 parent
cd5d760
commit a5710e5
Showing
12 changed files
with
42 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 15 additions & 6 deletions
21
...omponents/mobile/MobileLayoutProvider.tsx → .../src/components/layout/LayoutProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,52 @@ | ||
import type { FC } from 'react'; | ||
import React, { createContext, useContext, useState } from 'react'; | ||
import { useMediaQuery } from '../hooks/useMedia'; | ||
|
||
type MobileLayoutContextType = { | ||
type LayoutContextType = { | ||
isMobileMenuOpen: boolean; | ||
setMobileMenuOpen: React.Dispatch<React.SetStateAction<boolean>>; | ||
isMobileAboutOpen: boolean; | ||
setMobileAboutOpen: React.Dispatch<React.SetStateAction<boolean>>; | ||
isMobilePanelOpen: boolean; | ||
setMobilePanelOpen: React.Dispatch<React.SetStateAction<boolean>>; | ||
isDesktop: boolean; | ||
isMobile: boolean; | ||
}; | ||
|
||
const MobileLayoutContext = createContext<MobileLayoutContextType>({ | ||
const LayoutContext = createContext<LayoutContextType>({ | ||
isMobileMenuOpen: false, | ||
setMobileMenuOpen: () => {}, | ||
isMobileAboutOpen: false, | ||
setMobileAboutOpen: () => {}, | ||
isMobilePanelOpen: false, | ||
setMobilePanelOpen: () => {}, | ||
isDesktop: false, | ||
isMobile: false, | ||
}); | ||
|
||
export const MobileLayoutProvider: FC = ({ children }) => { | ||
export const LayoutProvider: FC = ({ children }) => { | ||
const [isMobileMenuOpen, setMobileMenuOpen] = useState(false); | ||
const [isMobileAboutOpen, setMobileAboutOpen] = useState(false); | ||
const [isMobilePanelOpen, setMobilePanelOpen] = useState(false); | ||
const isDesktop = useMediaQuery('(min-width: 600px)'); | ||
const isMobile = !isDesktop; | ||
|
||
return ( | ||
<MobileLayoutContext.Provider | ||
<LayoutContext.Provider | ||
value={{ | ||
isMobileMenuOpen, | ||
setMobileMenuOpen, | ||
isMobileAboutOpen, | ||
setMobileAboutOpen, | ||
isMobilePanelOpen, | ||
setMobilePanelOpen, | ||
isDesktop, | ||
isMobile, | ||
}} | ||
> | ||
{children} | ||
</MobileLayoutContext.Provider> | ||
</LayoutContext.Provider> | ||
); | ||
}; | ||
|
||
export const useMobileLayoutContext = () => useContext(MobileLayoutContext); | ||
export const useLayout = () => useContext(LayoutContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters