diff --git a/apps/docs/src/components/Providers.tsx b/apps/docs/src/components/Providers.tsx index 3c378ad..b463f3d 100644 --- a/apps/docs/src/components/Providers.tsx +++ b/apps/docs/src/components/Providers.tsx @@ -1,12 +1,12 @@ "use client"; -import { createContext, useCallback, useContext, useEffect, useState } from "react"; +import React, { createContext, useCallback, useContext, useEffect, useState } from "react"; type SidebarProps = { isSidebarOpen: boolean; isSearchOpen: boolean; toggleSidebar: () => void; - toggleSearch: () => void; + toggleSearch: React.MouseEventHandler; }; const SidebarContext = createContext({ diff --git a/apps/docs/src/components/Search.tsx b/apps/docs/src/components/Search.tsx index 7886888..1ce4ea7 100644 --- a/apps/docs/src/components/Search.tsx +++ b/apps/docs/src/components/Search.tsx @@ -5,14 +5,14 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-call */ // @ts-nocheck + "use client"; -import { useEffect, useState } from "react"; +import { forwardRef, useEffect, useState, type HTMLAttributes } from "react"; import Link from "next/link"; -import Router from "next/router"; import { DocSearchModal, useDocSearchKeyboardEvents } from "@docsearch/react"; import { SearchIcon } from "@iconicicons/react"; -import { Button, Kbd } from "@lemonsqueezy/wedges"; +import { Button, Kbd, type KbdKey } from "@lemonsqueezy/wedges"; import { createPortal } from "react-dom"; import { cn } from "@/lib/utils"; @@ -20,9 +20,17 @@ import { cn } from "@/lib/utils"; import { useSidebar } from "./Providers"; const docSearchConfig = { - appId: process.env.NEXT_PUBLIC_DOCSEARCH_APP_ID, - apiKey: process.env.NEXT_PUBLIC_DOCSEARCH_API_KEY, - indexName: process.env.NEXT_PUBLIC_DOCSEARCH_INDEX_NAME, + appId: process.env.NEXT_PUBLIC_DOCSEARCH_APP_ID!, + apiKey: process.env.NEXT_PUBLIC_DOCSEARCH_API_KEY!, + indexName: process.env.NEXT_PUBLIC_DOCSEARCH_INDEX_NAME!, +}; + +const suffixTitle = (title: string) => { + if (!title) { + return title; + } + + return `${title} - Wedges Docs`; }; function Hit({ hit, children }) { @@ -42,19 +50,10 @@ function Hit({ hit, children }) { ); } -export function Search({ className, ...otherProps }: { className?: string; otherProps?: any }) { +const Search = forwardRef>((props, ref) => { + const { className, ...otherProps } = props; const { isSearchOpen, toggleSearch } = useSidebar(); - const [modifierKey, setModifierKey] = useState("command"); - - const suffixTitle = (title) => { - if (!title) { - return title; - } - - const section = "Wedges Docs"; - - return `${title} - ${section}`; - }; + const [modifierKey, setModifierKey] = useState("command"); useDocSearchKeyboardEvents({ isOpen: isSearchOpen, onOpen: toggleSearch, onClose: toggleSearch }); @@ -63,7 +62,7 @@ export function Search({ className, ...otherProps }: { className?: string; other }, []); return ( - <> +
); -} +}); -export function SearchButton() { +function SearchButton() { const { toggleSearch } = useSidebar(); return ( @@ -195,3 +156,5 @@ export function SearchButton() { ); } + +export { Search, SearchButton };