Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cold-dancers-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gitbook": patch
---

SearchInput fixes — Translate Clear button, Bold theme color, "Esc" keyboard shortcut
50 changes: 8 additions & 42 deletions packages/gitbook/src/components/Search/SearchInput.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use client';
import React from 'react';
import { useEffect, useRef, useState } from 'react';
import { useEffect, useRef } from 'react';

import { tString, useLanguage } from '@/intl/client';
import { tcls } from '@/lib/tailwind';
import { Icon } from '@gitbook/icons';
import { Button, variantClasses } from '../primitives';
import { KeyboardShortcut } from '../primitives/KeyboardShortcut';
import { useClassnames } from '../primitives/StyleProvider';

interface SearchInputProps {
Expand Down Expand Up @@ -79,11 +80,11 @@ export const SearchInput = React.forwardRef<HTMLDivElement, SearchInputProps>(
{value && isOpen ? (
<Button
variant="blank"
label="Clear"
label={tString(language, 'clear')}
size="medium"
iconOnly
icon="circle-xmark"
className="-ml-1.5 -mr-1 animate-scale-in px-1.5"
className="-ml-1.5 -mr-1 animate-scale-in px-1.5 theme-bold:text-header-link theme-bold:hover:bg-header-link/3"
onClick={() => {
onChange('');
inputRef.current?.focus();
Expand Down Expand Up @@ -120,47 +121,12 @@ export const SearchInput = React.forwardRef<HTMLDivElement, SearchInputProps>(
// Forward
ref={inputRef}
/>
{!isOpen ? <Shortcut /> : null}
<KeyboardShortcut
keys={isOpen ? ['esc'] : ['mod', 'k']}
className="theme-bold:border-header-link/5 theme-bold:bg-header-background theme-bold:text-header-link"
/>
</div>
</div>
);
}
);

function getOperatingSystem() {
const platform = navigator.platform.toLowerCase();

if (platform.includes('mac')) return 'mac';
if (platform.includes('win')) return 'win';

return 'win';
}

function Shortcut() {
const [operatingSystem, setOperatingSystem] = useState<string | null>(null);

useEffect(() => {
setOperatingSystem(getOperatingSystem());
}, []);

return (
<div
aria-busy={operatingSystem === null ? 'true' : undefined}
className={tcls(
`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`,
operatingSystem
? 'motion-safe:animate-fade-in motion-reduce:opacity-11'
: 'opacity-0'
)}
>
<kbd
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' : ''}`}
>
{operatingSystem === 'mac' ? '⌘' : 'Ctrl'}
</kbd>
<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">
K
</kbd>
</div>
);
}
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const de = {
switch_to_light_theme: 'Zum hellen Modus wechseln',
switch_to_system_theme: 'Zum Systemmodus wechseln',
search: 'Suche',
clear: 'Löschen',
search_back: 'Zurück zu den Suchergebnissen',
search_or_ask: 'Fragen oder Suchen',
search_input_placeholder: 'Inhalt durchsuchen',
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const en = {
switch_to_light_theme: 'Switch to light theme',
switch_to_system_theme: 'Switch to system theme',
search: 'Search',
clear: 'Clear',
search_back: 'Back to search results',
search_or_ask: 'Ask or search',
search_input_placeholder: 'Search content',
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const es: TranslationLanguage = {
switch_to_light_theme: 'Cambiar a tema claro',
switch_to_system_theme: 'Cambiar a tema del sistema',
search: 'Buscar',
clear: 'Limpiar',
search_back: 'Volver a los resultados de búsqueda',
search_or_ask: 'Preguntar o Buscar',
search_input_placeholder: 'Buscar contenido',
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const fr = {
switch_to_light_theme: 'Activer le thème clair',
switch_to_system_theme: 'Utiliser le thème du système',
search: 'Rechercher',
clear: 'Effacer',
search_back: 'Retour aux résultats de recherche',
search_or_ask: 'Rechercher',
search_input_placeholder: 'Rechercher dans le contenu',
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const it: TranslationLanguage = {
switch_to_light_theme: 'Passa al tema chiaro',
switch_to_system_theme: 'Passa al tema di sistema',
search: 'Cerca',
clear: 'Cancella',
search_back: 'Torna ai risultati di ricerca',
search_or_ask: 'Chiedi o cerca',
search_input_placeholder: 'Cerca contenuti',
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const ja: TranslationLanguage = {
switch_to_light_theme: 'ライトテーマに切り替え',
switch_to_system_theme: 'システムのテーマに切り替え',
search: '検索',
clear: 'クリア',
search_back: '検索結果に戻る',
search_or_ask: '質問または検索',
search_input_placeholder: 'コンテンツを検索',
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const nl: TranslationLanguage = {
switch_to_light_theme: 'Schakel over naar lichte modus',
switch_to_system_theme: 'Schakel over naar systeemmodus',
search: 'Zoeken',
clear: 'Wissen',
search_back: 'Terug naar zoekresultaten',
search_or_ask: 'Zoek of vraag',
search_input_placeholder: 'Zoek inhoud',
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/no.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const no: TranslationLanguage = {
switch_to_light_theme: 'Bytt til lyst tema',
switch_to_system_theme: 'Bytt til systemtema',
search: 'Søk',
clear: 'Tøm',
search_back: 'Tilbake til søkeresultater',
search_or_ask: 'Spør eller søk',
search_input_placeholder: 'Søk i innhold',
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/pt-br.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const pt_br = {
switch_to_light_theme: 'Mudar para modo claro',
switch_to_system_theme: 'Mudar para configuração do sistema',
search: 'Busca',
clear: 'Limpar',
search_back: 'Voltar aos resultados da busca',
search_or_ask: 'Perguntar ou buscar',
search_input_placeholder: 'Buscar conteúdo',
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const ru = {
switch_to_light_theme: 'Переключиться на светлую тему',
switch_to_system_theme: 'Переключиться на системную тему',
search: 'Поиск',
clear: 'Очистить',
search_back: 'Вернуться к результатам поиска',
search_or_ask: 'Найти или спросить',
search_input_placeholder: 'Поиск по содержимому',
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook/src/intl/translations/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const zh: TranslationLanguage = {
switch_to_light_theme: '切换到浅色主题',
switch_to_system_theme: '切换到系统主题',
search: '搜索',
clear: '清除',
search_back: '返回搜索结果',
search_or_ask: '询问或搜索',
search_input_placeholder: '搜索内容',
Expand Down