Files
ESPDocs/components/SeriesTabMenu.jsx
T
Lucas RayanandAntigravity 660b28c09d
CI / Lint e auditorias (push) Successful in 1m31s
CI / Trivy (dependências e segredos) (push) Successful in 10s
CI / Imagem Docker (linux/arm64) (push) Successful in 2m23s
feat(i18n): Spanish localization (phase 4)
Complete implementation of Spanish (es-419) language support:
- Canonical catalogs and data: messages/es.json, data/es/**, lib/data/es/**, public/exemplos/es/**
- Canonical slugs: /es/series, /es/catalogo, /es/comparacion, /es/componentes, /es/diagnostico, /es/frameworks, /es/glosario, /es/selector, /es/acerca
- Dedicated search index at /api/busca/es with Spanish accent normalization
- Strict exclusion of book references in Spanish routes and catalogs
- Language selector and root negotiation with es active (ENABLED_LOCALES = ['pt', 'en', 'es'])
- Extended verification suite: check-i18n, smoke-imagem and verifica-vazamentos

Co-Authored-By: Antigravity <noreply@google.com>
2026-11-01 19:50:20 -03:00

90 lines
3.1 KiB
React

"use client";
import { useEffect, useRef, useState } from "react";
export default function SeriesTabMenu({ tabs, isEn = false, isEs = false, locale }) {
const effectiveIsEn = isEn || locale === "en";
const effectiveIsEs = isEs || locale === "es";
const availableTabs = tabs.filter((tab) => tab.available);
const [activeTab, setActiveTab] = useState(availableTabs[0]?.id);
const refs = useRef({});
// Troca manual limpa o hash. Sem isso, depois de abrir o diagrama pelo link e
// mudar de aba na mão, o hash continuaria em #connections e um novo clique no
// link não dispararia hashchange e o botão pareceria quebrado.
const trocarAba = (id) => {
setActiveTab(id);
if (window.location.hash) {
history.replaceState(null, "", window.location.pathname + window.location.search);
}
};
// Abas endereçáveis por hash: #connections abre o diagrama de pinos direto.
// É o que permite a seção de restrições apontar para cá.
useEffect(() => {
const abrirPeloHash = () => {
const alvo = window.location.hash.replace("#", "");
if (alvo && availableTabs.some((t) => t.id === alvo)) {
setActiveTab(alvo);
// Nenhum elemento tem id="connections", então o navegador não rola
// sozinho: levamos até as abas na mão.
const semAnimacao = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
document.getElementById("diagrama-abas")?.scrollIntoView({
behavior: semAnimacao ? "auto" : "smooth",
block: "start",
});
}
};
abrirPeloHash();
window.addEventListener("hashchange", abrirPeloHash);
return () => window.removeEventListener("hashchange", abrirPeloHash);
}, [availableTabs]);
// Setas, Home e End movem o foco entre as abas, como no padrão WAI-ARIA.
const aoTeclar = (evento, indice) => {
const total = availableTabs.length;
const destino =
evento.key === "ArrowRight" ? (indice + 1) % total
: evento.key === "ArrowLeft" ? (indice - 1 + total) % total
: evento.key === "Home" ? 0
: evento.key === "End" ? total - 1
: null;
if (destino === null) return;
evento.preventDefault();
const id = availableTabs[destino].id;
trocarAba(id);
refs.current[id]?.focus();
};
if (availableTabs.length === 0) return null;
const ativa = availableTabs.find((tab) => tab.id === activeTab) ?? availableTabs[0];
return (
<div id="diagrama-abas" className="scroll-mt-28">
<div role="tablist" aria-label={effectiveIsEn ? "Board and diagram" : effectiveIsEs ? "Placa y diagrama" : "Placa e diagrama"} className="no-scrollbar flex gap-2 overflow-x-auto pb-1">
{availableTabs.map((tab, indice) => (
<button
key={tab.id}
ref={(el) => (refs.current[tab.id] = el)}
type="button"
role="tab"
id={`aba-${tab.id}`}
aria-selected={ativa.id === tab.id}
aria-controls={`painel-${tab.id}`}
tabIndex={ativa.id === tab.id ? 0 : -1}
onClick={() => trocarAba(tab.id)}
onKeyDown={(e) => aoTeclar(e, indice)}
className="chip-btn shrink-0"
>
{tab.label}
</button>
))}
</div>
<div role="tabpanel" id={`painel-${ativa.id}`} aria-labelledby={`aba-${ativa.id}`} className="mt-4">
{ativa.content}
</div>
</div>
);
}