1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { useEffect, useRef } from "react";
/** Un `` modal nativo: Escape y «Cancelar» llaman a `alCancelar`; `abierto` es del padre. */
export function DialogoConfirmar({
abierto,
mensaje,
textoConfirmar = "Borrar",
alConfirmar,
alCancelar,
}: {
abierto: boolean;
mensaje: string;
textoConfirmar?: string;
alConfirmar: () => void;
alCancelar: () => void;
}) {
const dialogo = useRef(null);
useEffect(() => {
const elemento = dialogo.current;
if (elemento === null) return;
if (abierto && !elemento.open) elemento.showModal();
if (!abierto && elemento.open) elemento.close();
}, [abierto]);
return (
{
event.preventDefault();
alCancelar();
}}
>
{mensaje}
Cancelar
{textoConfirmar}
);
}