@@ -4,6 +4,7 @@ import { useEffect, useRef, useState } from 'react';
4
4
5
5
import { tString , useLanguage } from '@/intl/client' ;
6
6
import { tcls } from '@/lib/tailwind' ;
7
+ import { CustomizationAIMode } from '@gitbook/api' ;
7
8
import { Icon } from '@gitbook/icons' ;
8
9
import { Button , variantClasses } from '../primitives' ;
9
10
import { useClassnames } from '../primitives/StyleProvider' ;
@@ -13,7 +14,7 @@ interface SearchInputProps {
13
14
onKeyDown : ( event : React . KeyboardEvent < HTMLInputElement > ) => void ;
14
15
onFocus : ( ) => void ;
15
16
value : string ;
16
- withAI ?: boolean ;
17
+ aiMode : CustomizationAIMode ;
17
18
isOpen : boolean ;
18
19
className ?: string ;
19
20
}
@@ -26,7 +27,7 @@ const sizeClasses = ['text-sm', 'px-3.5', 'py-1.5', 'md:circular-corners:px-4'];
26
27
*/
27
28
export const SearchInput = React . forwardRef < HTMLDivElement , SearchInputProps > (
28
29
function SearchInput ( props , ref ) {
29
- const { onChange, onKeyDown, onFocus, value, withAI = false , isOpen, className } = props ;
30
+ const { onChange, onKeyDown, onFocus, value, aiMode , isOpen, className } = props ;
30
31
const inputRef = useRef < HTMLInputElement > ( null ) ;
31
32
32
33
const language = useLanguage ( ) ;
@@ -59,7 +60,7 @@ export const SearchInput = React.forwardRef<HTMLDivElement, SearchInputProps>(
59
60
sizeClasses ,
60
61
// Additional custom styles
61
62
'has-[input:focus]:-translate-y-px h-9 grow cursor-pointer px-2.5 has-[input:focus]:bg-tint-base depth-subtle:has-[input:focus]:shadow-lg depth-subtle:has-[input:focus]:shadow-primary-subtle has-[input:focus-visible]:ring-2 has-[input:focus-visible]:ring-primary-hover md:cursor-text' ,
62
- 'theme-bold:has-[input:focus-visible]:border-header-link/6 theme-bold:has-[input:focus-visible]:bg-header-link/3' ,
63
+ 'theme-bold:border-header-link/3 theme-bold: has-[input:focus-visible]:border-header-link/5 theme-bold:has-[input:focus-visible]:bg-header-link/3 theme-bold:has-[input:focus-visible]:ring-header-link/5 ' ,
63
64
'theme-bold:before:absolute theme-bold:before:inset-0 theme-bold:before:bg-header-background/7 theme-bold:before:backdrop-blur-xl ' , // Special overlay to make the transparent colors of theme-bold visible.
64
65
'relative z-30 shrink grow justify-start max-md:absolute max-md:right-0' ,
65
66
isOpen ? 'max-md:w-56' : 'max-md:w-[38px]' ,
@@ -73,7 +74,7 @@ export const SearchInput = React.forwardRef<HTMLDivElement, SearchInputProps>(
73
74
size = "medium"
74
75
iconOnly
75
76
icon = "circle-xmark"
76
- className = "-ml-1.5 -mr-1 animate-scaleIn px-1.5 theme-bold:text-header-link theme-bold:hover:bg-header-link/3 "
77
+ className = "-ml-1.5 -mr-1 animate-scaleIn px-1.5"
77
78
onClick = { ( ) => {
78
79
onChange ( '' ) ;
79
80
inputRef . current ?. focus ( ) ;
@@ -89,15 +90,17 @@ export const SearchInput = React.forwardRef<HTMLDivElement, SearchInputProps>(
89
90
onKeyDown = { onKeyDown }
90
91
onChange = { ( event ) => onChange ( event . target . value ) }
91
92
value = { value }
92
- placeholder = { `${ tString ( language , withAI ? 'search_or_ask' : 'search' ) } ...` }
93
+ // We only show "search or ask" if the search input actually handles both search and ask.
94
+ placeholder = { `${ tString ( language , aiMode === CustomizationAIMode . Search ? 'search_or_ask' : 'search' ) } ...` }
93
95
maxLength = { 512 }
96
+ size = { 10 }
94
97
className = { tcls (
95
98
'peer z-10 min-w-0 grow bg-transparent py-0.5 text-tint-strong theme-bold:text-header-link outline-none transition-[width] duration-300 contain-paint placeholder:text-tint theme-bold:placeholder:text-current theme-bold:placeholder:opacity-7' ,
96
99
isOpen ? '' : 'max-md:opacity-0'
97
100
) }
98
101
ref = { inputRef }
99
102
/>
100
- < Shortcut />
103
+ { ! isOpen ? < Shortcut /> : null }
101
104
</ div >
102
105
</ div >
103
106
) ;
@@ -124,7 +127,7 @@ function Shortcut() {
124
127
< div
125
128
aria-busy = { operatingSystem === null ? 'true' : undefined }
126
129
className = { tcls (
127
- `shortcut -mr-1 hidden justify-end gap-0.5 whitespace-nowrap text-xs [font-feature-settings:"calt",_"case"] contrast-more:text-tint-strong md:flex` ,
130
+ `shortcut -mr-1 relative z-10 hidden justify-end gap-0.5 whitespace-nowrap text-xs [font-feature-settings:"calt",_"case"] after:absolute after:right-full after:z-20 after:h-full after:w-8 after:bg-gradient-to-r after:from-transparent after:to-tint-base theme-bold:after:to-transparent after:content-['' ] contrast-more:text-tint-strong md:flex` ,
128
131
operatingSystem
129
132
? 'motion-safe:animate-fadeIn motion-reduce:opacity-11'
130
133
: 'opacity-0'
0 commit comments