@@ -3,25 +3,7 @@ import { useLocation, useNavigate, href } from "react-router";
33import { styled } from "@linaria/react" ;
44import { SearchContext } from "./SearchContext" ;
55import { DeclarationsContext } from "../schema/DeclarationsContext" ;
6- import { KindIcon , IconKind } from "../kind-icon/KindIcon" ;
7-
8- export function useCtrlFHook < T extends HTMLElement > ( ) {
9- const ref = useRef < T | null > ( null ) ;
10- useEffect ( ( ) => {
11- const listener = ( event : KeyboardEvent ) => {
12- if ( ref . current && ( event . ctrlKey || event . metaKey ) && event . key === "f" ) {
13- // Use default CTRL+F only when element already has focus
14- if ( document . activeElement !== ref . current ) event . preventDefault ( ) ;
15- ref . current . focus ( ) ;
16- }
17- } ;
18-
19- document . addEventListener ( "keydown" , listener ) ;
20- return ( ) => document . removeEventListener ( "keydown" , listener ) ;
21- } , [ ] ) ;
22-
23- return ref ;
24- }
6+ import { KindIcon , IconKind , ICONS_URL } from "../kind-icon/KindIcon" ;
257
268export const SearchInput = styled . input `
279 width: 100%;
@@ -130,6 +112,43 @@ const SearchBoxWrapper = styled.div`
130112 width: 100%;
131113` ;
132114
115+ const SearchIcon = styled . svg `
116+ position: absolute;
117+ left: 12px;
118+ top: 50%;
119+ translate: 0 -50%;
120+ pointer-events: none;
121+ color: var(--searchbox-placeholder);
122+ ` ;
123+
124+ const MainSearchInput = styled ( SearchInput ) `
125+ padding-left: 36px;
126+ ` ;
127+
128+ const SearchPlaceholder = styled . div `
129+ position: absolute;
130+ inset: 0;
131+ display: flex;
132+ align-items: center;
133+ gap: 4px;
134+ padding: 0 14px 0 36px;
135+ pointer-events: none;
136+ color: var(--searchbox-placeholder);
137+ font-size: 14px;
138+ font-family: inherit;
139+
140+ kbd {
141+ font-family: inherit;
142+ font-size: 12px;
143+ font-weight: 600;
144+ padding: 1px 6px;
145+ border-radius: 4px;
146+ border: 1px solid var(--searchbox-placeholder);
147+ opacity: 0.6;
148+ line-height: 1.4;
149+ }
150+ ` ;
151+
133152const TagPopup = styled . div `
134153 position: absolute;
135154 top: calc(100% + 4px);
@@ -414,13 +433,21 @@ export function SearchBox({ className }: { className?: string }) {
414433 }
415434 } ;
416435
417- const ref = useCtrlFHook < HTMLInputElement > ( ) ;
436+ const ref = useRef < HTMLInputElement > ( null ) ;
418437
419438 return (
420439 < SearchBoxWrapper className = { className } >
421- < SearchInput
440+ < SearchIcon width = "16" height = "16" >
441+ < use href = { `${ ICONS_URL } #search` } />
442+ </ SearchIcon >
443+ { ! inputValue && ! isFocused && (
444+ < SearchPlaceholder >
445+ Type < kbd > /</ kbd > to search
446+ </ SearchPlaceholder >
447+ ) }
448+ < MainSearchInput
449+ id = "main-search"
422450 type = "search"
423- placeholder = "Search…"
424451 ref = { ref }
425452 value = { inputValue }
426453 onChange = { onChange }
0 commit comments