Skip to content

Commit 0c01832

Browse files
authored
SearchInput fixes (#3762)
1 parent 6b1c9fe commit 0c01832

File tree

13 files changed

+24
-42
lines changed

13 files changed

+24
-42
lines changed

.changeset/cold-dancers-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
SearchInput fixes — Translate Clear button, Bold theme color, "Esc" keyboard shortcut

packages/gitbook/src/components/Search/SearchInput.tsx

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
'use client';
22
import React from 'react';
3-
import { useEffect, useRef, useState } from 'react';
3+
import { useEffect, useRef } from 'react';
44

55
import { tString, useLanguage } from '@/intl/client';
66
import { tcls } from '@/lib/tailwind';
77
import { Icon } from '@gitbook/icons';
88
import { Button, variantClasses } from '../primitives';
9+
import { KeyboardShortcut } from '../primitives/KeyboardShortcut';
910
import { useClassnames } from '../primitives/StyleProvider';
1011

1112
interface SearchInputProps {
@@ -79,11 +80,11 @@ export const SearchInput = React.forwardRef<HTMLDivElement, SearchInputProps>(
7980
{value && isOpen ? (
8081
<Button
8182
variant="blank"
82-
label="Clear"
83+
label={tString(language, 'clear')}
8384
size="medium"
8485
iconOnly
8586
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"
8788
onClick={() => {
8889
onChange('');
8990
inputRef.current?.focus();
@@ -120,47 +121,12 @@ export const SearchInput = React.forwardRef<HTMLDivElement, SearchInputProps>(
120121
// Forward
121122
ref={inputRef}
122123
/>
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+
/>
124128
</div>
125129
</div>
126130
);
127131
}
128132
);
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-
}

packages/gitbook/src/intl/translations/de.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const de = {
66
switch_to_light_theme: 'Zum hellen Modus wechseln',
77
switch_to_system_theme: 'Zum Systemmodus wechseln',
88
search: 'Suche',
9+
clear: 'Löschen',
910
search_back: 'Zurück zu den Suchergebnissen',
1011
search_or_ask: 'Fragen oder Suchen',
1112
search_input_placeholder: 'Inhalt durchsuchen',

packages/gitbook/src/intl/translations/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const en = {
66
switch_to_light_theme: 'Switch to light theme',
77
switch_to_system_theme: 'Switch to system theme',
88
search: 'Search',
9+
clear: 'Clear',
910
search_back: 'Back to search results',
1011
search_or_ask: 'Ask or search',
1112
search_input_placeholder: 'Search content',

packages/gitbook/src/intl/translations/es.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const es: TranslationLanguage = {
88
switch_to_light_theme: 'Cambiar a tema claro',
99
switch_to_system_theme: 'Cambiar a tema del sistema',
1010
search: 'Buscar',
11+
clear: 'Limpiar',
1112
search_back: 'Volver a los resultados de búsqueda',
1213
search_or_ask: 'Preguntar o Buscar',
1314
search_input_placeholder: 'Buscar contenido',

packages/gitbook/src/intl/translations/fr.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const fr = {
66
switch_to_light_theme: 'Activer le thème clair',
77
switch_to_system_theme: 'Utiliser le thème du système',
88
search: 'Rechercher',
9+
clear: 'Effacer',
910
search_back: 'Retour aux résultats de recherche',
1011
search_or_ask: 'Rechercher',
1112
search_input_placeholder: 'Rechercher dans le contenu',

packages/gitbook/src/intl/translations/it.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const it: TranslationLanguage = {
88
switch_to_light_theme: 'Passa al tema chiaro',
99
switch_to_system_theme: 'Passa al tema di sistema',
1010
search: 'Cerca',
11+
clear: 'Cancella',
1112
search_back: 'Torna ai risultati di ricerca',
1213
search_or_ask: 'Chiedi o cerca',
1314
search_input_placeholder: 'Cerca contenuti',

packages/gitbook/src/intl/translations/ja.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const ja: TranslationLanguage = {
88
switch_to_light_theme: 'ライトテーマに切り替え',
99
switch_to_system_theme: 'システムのテーマに切り替え',
1010
search: '検索',
11+
clear: 'クリア',
1112
search_back: '検索結果に戻る',
1213
search_or_ask: '質問または検索',
1314
search_input_placeholder: 'コンテンツを検索',

packages/gitbook/src/intl/translations/nl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const nl: TranslationLanguage = {
88
switch_to_light_theme: 'Schakel over naar lichte modus',
99
switch_to_system_theme: 'Schakel over naar systeemmodus',
1010
search: 'Zoeken',
11+
clear: 'Wissen',
1112
search_back: 'Terug naar zoekresultaten',
1213
search_or_ask: 'Zoek of vraag',
1314
search_input_placeholder: 'Zoek inhoud',

packages/gitbook/src/intl/translations/no.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const no: TranslationLanguage = {
88
switch_to_light_theme: 'Bytt til lyst tema',
99
switch_to_system_theme: 'Bytt til systemtema',
1010
search: 'Søk',
11+
clear: 'Tøm',
1112
search_back: 'Tilbake til søkeresultater',
1213
search_or_ask: 'Spør eller søk',
1314
search_input_placeholder: 'Søk i innhold',

0 commit comments

Comments
 (0)