import { useState, useRef, useEffect } from 'react'; import './FiltroAtivo.css'; const OPCOES = [ { value: null, label: 'Todos', icone: '👥' }, { value: true, label: 'Ativos', icone: '✅' }, { value: false, label: 'Inativos', icone: '📋' }, ]; function FiltroAtivo({ valor, onChange }) { const [aberto, setAberto] = useState(false); const ref = useRef(null); useEffect(() => { const handleClickOutside = (e) => { if (ref.current && !ref.current.contains(e.target)) { setAberto(false); } }; document.addEventListener('mousedown', handleClickOutside); return () => document.removeEventListener('mousedown', handleClickOutside); }, []); const selecionarOpcao = (novoValor) => { onChange(novoValor); setAberto(false); }; const limparFiltro = (e) => { e.stopPropagation(); onChange(null); }; const opcaoAtual = OPCOES.find((o) => o.value === valor) || OPCOES[0]; const filtroAtivo = valor !== null; return (
{aberto && (
Filtrar por status
{OPCOES.map((opcao) => ( ))}
)}
); } export default FiltroAtivo;