3ae48af67c
This PR starts putting in place the high-level changes we want to make to the docs site. - It makes separate sections for Reference and Examples and Community. - Gets rid of the secondary sidebar and integrates it into the main sidebar. - Groups the reference articles by type. - Pulls in the examples alongside code and a live playground so people don't have to visit examples.tldraw.com separately. <img width="1458" alt="Screenshot 2024-01-30 at 09 43 46" src="https://github.com/tldraw/tldraw/assets/469604/4f5aa339-3a69-4d9b-9b9f-dfdddea623e8"> Again, this is the top-level changes and there's more to be done for the next PR(s): - create quick start page - clean up installation page - add accordion to Examples page prbly - put fun stuff in header (from footer) - landing page - something for landing page of API - search cmd-k and border - cleanup _sidebarReferenceContentLinks - external links _blank - address potential skew issue with code examples - have a link to other examples (next.js, etc.) ### Change Type - [x] `documentation` — Changes to the documentation only[^2] ### Test Plan 1. Make sure examples work! ### Release Notes - Rework our docs site to pull together the examples app and reference section more cohesively. --------- Co-authored-by: Taha <98838967+Taha-Hassan-Git@users.noreply.github.com> Co-authored-by: Steve Ruiz <steveruizok@gmail.com> Co-authored-by: Mitja Bezenšek <mitja.bezensek@gmail.com> Co-authored-by: alex <alex@dytry.ch> Co-authored-by: Lu Wilson <l2wilson94@gmail.com> Co-authored-by: Dan Groshev <git@dgroshev.com>
77 lines
1.8 KiB
TypeScript
77 lines
1.8 KiB
TypeScript
'use client'
|
|
|
|
import { usePathname, useRouter } from 'next/navigation'
|
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
import { useHotkeys } from 'react-hotkeys-hook'
|
|
import { Icon } from './Icon'
|
|
|
|
export function Search({
|
|
prevType = 'n',
|
|
prevQuery = '',
|
|
}: {
|
|
prevType?: string
|
|
prevQuery?: string
|
|
}) {
|
|
const [query, setQuery] = useState(prevQuery)
|
|
const [isDisabled, setIsDisabled] = useState(false)
|
|
|
|
const handleChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
|
setQuery(e.target.value)
|
|
}, [])
|
|
|
|
const rInput = useRef<HTMLInputElement>(null)
|
|
|
|
const pathName = usePathname()
|
|
const router = useRouter()
|
|
|
|
useHotkeys('meta+k,ctrl+k', (e) => {
|
|
e.preventDefault()
|
|
rInput.current?.focus()
|
|
rInput.current?.select()
|
|
})
|
|
|
|
useEffect(() => {
|
|
setIsDisabled(false)
|
|
}, [pathName])
|
|
|
|
const handleFocus = useCallback(() => {
|
|
// focus input and select all
|
|
rInput.current!.focus()
|
|
rInput.current!.select()
|
|
}, [])
|
|
|
|
const handleKeyDown = useCallback(
|
|
(e: React.KeyboardEvent) => {
|
|
const currentQuery = rInput.current!.value
|
|
if (e.key === 'Enter' && currentQuery !== prevQuery) {
|
|
setIsDisabled(true)
|
|
router.push(`/search-results?q=${currentQuery}&t=${prevType}`)
|
|
} else if (e.key === 'Escape') {
|
|
rInput.current!.blur()
|
|
}
|
|
},
|
|
[router, prevQuery, prevType]
|
|
)
|
|
|
|
return (
|
|
<div className="search__wrapper">
|
|
<div className="search">
|
|
<Icon className="search__icon" icon="search" small />
|
|
<input
|
|
ref={rInput}
|
|
type="text"
|
|
className="search__input"
|
|
placeholder="Search..."
|
|
value={query}
|
|
onChange={handleChange}
|
|
onFocus={handleFocus}
|
|
onKeyDown={handleKeyDown}
|
|
autoCapitalize="off"
|
|
autoComplete="off"
|
|
autoCorrect="off"
|
|
disabled={isDisabled}
|
|
/>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|