* initial implementation of search modal * added hit and search suggestions * added support for multiple indices * updated sample env * added close when click outside dropdown * test for mobile * added mobile design * added shortcut * dark mode fixes * added search to docs * added plugins filter * added React import * moved filters to configurations * handled error on page load * change suggestion text * removed hits limit * handle select all * open link in current tab * change highlight colors * added support for shortcuts + auto focus * change header and footer * redesigned search ui
66 lines
1.2 KiB
TypeScript
66 lines
1.2 KiB
TypeScript
"use client"
|
|
|
|
import React, {
|
|
createContext,
|
|
useCallback,
|
|
useContext,
|
|
useEffect,
|
|
useState,
|
|
} from "react"
|
|
|
|
type MobileContextType = {
|
|
isMobile?: boolean
|
|
}
|
|
|
|
const MobileContext = createContext<MobileContextType | null>(null)
|
|
|
|
type MobileProviderProps = {
|
|
children: React.ReactNode
|
|
}
|
|
|
|
const MobileProvider = ({ children }: MobileProviderProps) => {
|
|
const [isMobile, setIsMobile] = useState(false)
|
|
|
|
const handleResize = useCallback(() => {
|
|
if (window.innerWidth < 1025 && !isMobile) {
|
|
setIsMobile(true)
|
|
} else if (window.innerWidth >= 1025 && isMobile) {
|
|
setIsMobile(false)
|
|
}
|
|
}, [isMobile])
|
|
|
|
useEffect(() => {
|
|
window.addEventListener("resize", handleResize)
|
|
|
|
return () => {
|
|
window.removeEventListener("resize", handleResize)
|
|
}
|
|
}, [handleResize])
|
|
|
|
useEffect(() => {
|
|
handleResize()
|
|
}, [])
|
|
|
|
return (
|
|
<MobileContext.Provider
|
|
value={{
|
|
isMobile,
|
|
}}
|
|
>
|
|
{children}
|
|
</MobileContext.Provider>
|
|
)
|
|
}
|
|
|
|
export default MobileProvider
|
|
|
|
export const useMobile = () => {
|
|
const context = useContext(MobileContext)
|
|
|
|
if (!context) {
|
|
throw new Error("useMobile must be used within a MobileProvider")
|
|
}
|
|
|
|
return context
|
|
}
|