* 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
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
"use client"
|
|
|
|
import { createContext, useContext, useState } from "react"
|
|
import SearchModal from "../components/Search/Modal"
|
|
|
|
type SearchContextType = {
|
|
isOpen: boolean
|
|
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>
|
|
defaultFilters: string[]
|
|
setDefaultFilters: (value: string[]) => void
|
|
}
|
|
|
|
const SearchContext = createContext<SearchContextType | null>(null)
|
|
|
|
type SearchProviderProps = {
|
|
children: React.ReactNode
|
|
}
|
|
|
|
const SearchProvider = ({ children }: SearchProviderProps) => {
|
|
const [isOpen, setIsOpen] = useState(false)
|
|
const [defaultFilters, setDefaultFilters] = useState<string[]>([])
|
|
|
|
return (
|
|
<SearchContext.Provider
|
|
value={{
|
|
isOpen,
|
|
setIsOpen,
|
|
defaultFilters,
|
|
setDefaultFilters,
|
|
}}
|
|
>
|
|
{children}
|
|
<SearchModal />
|
|
</SearchContext.Provider>
|
|
)
|
|
}
|
|
|
|
export default SearchProvider
|
|
|
|
export const useSearch = (): SearchContextType => {
|
|
const context = useContext(SearchContext)
|
|
|
|
if (!context) {
|
|
throw new Error("useSearch must be used inside a SearchProvider")
|
|
}
|
|
|
|
return context
|
|
}
|