|
1 | 1 | 'use client'; |
2 | 2 | import React from 'react'; |
3 | | -import { useEffect, useRef, useState } from 'react'; |
| 3 | +import { useEffect, useRef } from 'react'; |
4 | 4 |
|
5 | 5 | import { tString, useLanguage } from '@/intl/client'; |
6 | 6 | import { tcls } from '@/lib/tailwind'; |
7 | 7 | import { Icon } from '@gitbook/icons'; |
8 | 8 | import { Button, variantClasses } from '../primitives'; |
| 9 | +import { KeyboardShortcut } from '../primitives/KeyboardShortcut'; |
9 | 10 | import { useClassnames } from '../primitives/StyleProvider'; |
10 | 11 |
|
11 | 12 | interface SearchInputProps { |
@@ -79,11 +80,11 @@ export const SearchInput = React.forwardRef<HTMLDivElement, SearchInputProps>( |
79 | 80 | {value && isOpen ? ( |
80 | 81 | <Button |
81 | 82 | variant="blank" |
82 | | - label="Clear" |
| 83 | + label={tString(language, 'clear')} |
83 | 84 | size="medium" |
84 | 85 | iconOnly |
85 | 86 | icon="circle-xmark" |
86 | | - className="-ml-1.5 -mr-1 animate-scale-in px-1.5" |
| 87 | + className="-ml-1.5 -mr-1 animate-scale-in px-1.5 theme-bold:text-header-link theme-bold:hover:bg-header-link/3" |
87 | 88 | onClick={() => { |
88 | 89 | onChange(''); |
89 | 90 | inputRef.current?.focus(); |
@@ -120,47 +121,12 @@ export const SearchInput = React.forwardRef<HTMLDivElement, SearchInputProps>( |
120 | 121 | // Forward |
121 | 122 | ref={inputRef} |
122 | 123 | /> |
123 | | - {!isOpen ? <Shortcut /> : null} |
| 124 | + <KeyboardShortcut |
| 125 | + keys={isOpen ? ['esc'] : ['mod', 'k']} |
| 126 | + className="last:-mr-1 theme-bold:border-header-link/5 theme-bold:bg-header-background theme-bold:text-header-link" |
| 127 | + /> |
124 | 128 | </div> |
125 | 129 | </div> |
126 | 130 | ); |
127 | 131 | } |
128 | 132 | ); |
129 | | - |
130 | | -function getOperatingSystem() { |
131 | | - const platform = navigator.platform.toLowerCase(); |
132 | | - |
133 | | - if (platform.includes('mac')) return 'mac'; |
134 | | - if (platform.includes('win')) return 'win'; |
135 | | - |
136 | | - return 'win'; |
137 | | -} |
138 | | - |
139 | | -function Shortcut() { |
140 | | - const [operatingSystem, setOperatingSystem] = useState<string | null>(null); |
141 | | - |
142 | | - useEffect(() => { |
143 | | - setOperatingSystem(getOperatingSystem()); |
144 | | - }, []); |
145 | | - |
146 | | - return ( |
147 | | - <div |
148 | | - aria-busy={operatingSystem === null ? 'true' : undefined} |
149 | | - className={tcls( |
150 | | - `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-linear-to-r after:from-transparent after:to-tint-base theme-bold:after:to-transparent after:content-[''] contrast-more:text-tint-strong md:flex`, |
151 | | - operatingSystem |
152 | | - ? 'motion-safe:animate-fade-in motion-reduce:opacity-11' |
153 | | - : 'opacity-0' |
154 | | - )} |
155 | | - > |
156 | | - <kbd |
157 | | - className={`flex h-5 min-w-5 items-center justify-center rounded-sm border border-tint-subtle theme-bold:border-header-link/5 bg-tint-base theme-bold:bg-header-background px-1 ${operatingSystem === 'mac' ? 'text-sm' : ''}`} |
158 | | - > |
159 | | - {operatingSystem === 'mac' ? '⌘' : 'Ctrl'} |
160 | | - </kbd> |
161 | | - <kbd className="flex size-5 items-center justify-center rounded-sm border border-tint-subtle theme-bold:border-header-link/5 bg-tint-base theme-bold:bg-header-background px-1"> |
162 | | - K |
163 | | - </kbd> |
164 | | - </div> |
165 | | - ); |
166 | | -} |
0 commit comments