@j3ehcmz/ui 0.0.0-stage → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -2
- package/css/estilos.css +375 -0
- package/css/fuentes.css +60 -0
- package/css/tokens.css +95 -0
- package/fuentes/josefin-sans-300.woff2 +0 -0
- package/fuentes/josefin-sans-400.woff2 +0 -0
- package/fuentes/plex-mono-400.woff2 +0 -0
- package/fuentes/plex-mono-500.woff2 +0 -0
- package/fuentes/plex-sans-latin.woff2 +0 -0
- package/fuentes/sora-latin.woff2 +0 -0
- package/package.json +43 -4
- package/src/iconos/Icono.tsx +29 -0
- package/src/iconos/index.ts +5 -0
- package/src/iconos/registro.ts +787 -0
- package/src/index.ts +15 -0
- package/src/navegador/ScriptsCabecera.tsx +16 -0
- package/src/navegador/reportar-errores.tsx +127 -0
- package/src/navegador/transicion-portal.ts +39 -0
- package/src/shell/BotonPortal.tsx +49 -0
- package/src/shell/BotonTema.tsx +41 -0
- package/src/shell/Shell.tsx +124 -0
- package/src/ui/Dialogo.tsx +64 -0
- package/src/ui/clases.ts +16 -0
- package/src/ui/contenido.tsx +86 -0
- package/src/ui/controles.tsx +185 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @j3ehcmz/ui — sistema de diseño de los módulos del Portal HCMZ.
|
|
2
|
+
// Estilos: @import "@j3ehcmz/ui/estilos.css" en el globals.css del módulo.
|
|
3
|
+
|
|
4
|
+
export { Shell, Monograma, type Modulo } from "./shell/Shell";
|
|
5
|
+
export { BotonPortal, DivisorCabecera, URL_PORTAL } from "./shell/BotonPortal";
|
|
6
|
+
export { BotonTema } from "./shell/BotonTema";
|
|
7
|
+
|
|
8
|
+
export { Boton, BotonIcono, Pista, FilaInterruptor, Segmentado } from "./ui/controles";
|
|
9
|
+
export { ChipEstado, Avatar, EtiquetaSeccion, Titulo, Tarjeta, TarjetaFilas, FilaDato, Nota, Vacio, type Tono } from "./ui/contenido";
|
|
10
|
+
export { Dialogo } from "./ui/Dialogo";
|
|
11
|
+
export * from "./ui/clases";
|
|
12
|
+
|
|
13
|
+
export { ScriptsCabecera, TEMA_INICIAL } from "./navegador/ScriptsCabecera";
|
|
14
|
+
export { TRANSICION_PORTAL } from "./navegador/transicion-portal";
|
|
15
|
+
export { ReportarErrores, reportarErrorNavegador } from "./navegador/reportar-errores";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TRANSICION_PORTAL } from "./transicion-portal";
|
|
2
|
+
|
|
3
|
+
/* Tema compartido con el portal: la fuente es la cookie portal-tema de .hcmz.online (el localStorage es de cada
|
|
4
|
+
subdominio). Sin cookie = el del sistema, y lo sigue en vivo; al volver a la pestaña se relee. Si el botón de
|
|
5
|
+
un módulo cambia data-tema, se guarda en la cookie y lo heredan todos. */
|
|
6
|
+
export const TEMA_INICIAL = `(function(){try{var h=document.documentElement,q=matchMedia('(prefers-color-scheme: dark)'),propio=null;function aplicar(){var m=document.cookie.match(/(?:^|; )portal-tema=(claro|oscuro)/);var t=m?m[1]:(q.matches?'oscuro':'claro');propio=t;if(h.dataset.tema!==t)h.dataset.tema=t}aplicar();q.addEventListener('change',aplicar);document.addEventListener('visibilitychange',function(){if(!document.hidden)aplicar()});new MutationObserver(function(){var t=h.dataset.tema==='oscuro'?'oscuro':'claro';if(t===propio)return;propio=t;var d=location.hostname.endsWith('.hcmz.online')?'; domain=.hcmz.online':'',s=location.protocol==='https:'?'; secure':'';document.cookie='portal-tema='+t+'; path=/; max-age=31536000; samesite=lax'+d+s}).observe(h,{attributes:true,attributeFilter:['data-tema']})}catch(e){}})()`;
|
|
7
|
+
|
|
8
|
+
/** Va dentro de <head> del layout raíz: «el ícono viaja» (entrada/regreso del portal) + tema antes de pintar. */
|
|
9
|
+
export function ScriptsCabecera({ transicion = true }: { transicion?: boolean }) {
|
|
10
|
+
return (
|
|
11
|
+
<>
|
|
12
|
+
{transicion && <script dangerouslySetInnerHTML={{ __html: TRANSICION_PORTAL }} />}
|
|
13
|
+
<script dangerouslySetInnerHTML={{ __html: TEMA_INICIAL }} />
|
|
14
|
+
</>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
|
|
5
|
+
/* Errores del navegador → POST /api/errores (→ GlitchTip). Sin dependencias: ~1 KB. Máximo 10 por página y sin
|
|
6
|
+
repetir el mismo mensaje. Se ignora el ruido que no es del módulo (extensiones, «Script error.», ResizeObserver).
|
|
7
|
+
Además mide el rendimiento real de esta carga de página (Web Vitals) y lo manda UNA vez, al ocultar o cerrar la
|
|
8
|
+
pestaña, por la misma ruta (→ pestaña Rendimiento del Monitor). Solo ruta genérica y tiempos: nada de quién.
|
|
9
|
+
Vive SOLO en @j3ehcmz/ui: los módulos lo importan, no lo copian. */
|
|
10
|
+
|
|
11
|
+
function enviar(cuerpo: string) {
|
|
12
|
+
if (!navigator.sendBeacon?.("/api/errores", new Blob([cuerpo], { type: "application/json" }))) {
|
|
13
|
+
void fetch("/api/errores", { method: "POST", body: cuerpo, headers: { "Content-Type": "application/json" }, keepalive: true }).catch(() => {});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Segmentos con números o muy largos (ids, fechas, códigos) → «:id», para no mandar datos de nadie. */
|
|
18
|
+
const rutaGenerica = (p: string) =>
|
|
19
|
+
p
|
|
20
|
+
.split("/")
|
|
21
|
+
.map((s) => (s.length > 24 || (/\d/.test(s) && s.length > 2) ? ":id" : s.replace(/[^\w\-.]/g, "")))
|
|
22
|
+
.join("/")
|
|
23
|
+
.slice(0, 200) || "/";
|
|
24
|
+
|
|
25
|
+
let vitalesIniciadas = false;
|
|
26
|
+
|
|
27
|
+
function medirVitales() {
|
|
28
|
+
if (vitalesIniciadas || typeof PerformanceObserver === "undefined") return;
|
|
29
|
+
vitalesIniciadas = true;
|
|
30
|
+
const v: { lcp?: number; fcp?: number; cls?: number } = {};
|
|
31
|
+
const interacciones = new Map<number, number>();
|
|
32
|
+
let cls = 0;
|
|
33
|
+
let ventana = 0;
|
|
34
|
+
let primero = 0;
|
|
35
|
+
let ultimo = 0;
|
|
36
|
+
const observar = (type: string, cb: (e: PerformanceEntry) => void, extra: Record<string, unknown> = {}) => {
|
|
37
|
+
try {
|
|
38
|
+
new PerformanceObserver((l) => l.getEntries().forEach(cb)).observe({ type, buffered: true, ...extra } as PerformanceObserverInit);
|
|
39
|
+
} catch {
|
|
40
|
+
/* navegador viejo: esa métrica no se mide */
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
observar("largest-contentful-paint", (e) => (v.lcp = e.startTime));
|
|
44
|
+
observar("paint", (e) => {
|
|
45
|
+
if (e.name === "first-contentful-paint") v.fcp = e.startTime;
|
|
46
|
+
});
|
|
47
|
+
observar("layout-shift", (e) => {
|
|
48
|
+
const s = e as PerformanceEntry & { value: number; hadRecentInput: boolean };
|
|
49
|
+
if (s.hadRecentInput) return;
|
|
50
|
+
if (ventana && s.startTime - ultimo < 1000 && s.startTime - primero < 5000) ventana += s.value;
|
|
51
|
+
else {
|
|
52
|
+
ventana = s.value;
|
|
53
|
+
primero = s.startTime;
|
|
54
|
+
}
|
|
55
|
+
ultimo = s.startTime;
|
|
56
|
+
cls = Math.max(cls, ventana);
|
|
57
|
+
v.cls = cls;
|
|
58
|
+
});
|
|
59
|
+
observar(
|
|
60
|
+
"event",
|
|
61
|
+
(e) => {
|
|
62
|
+
const id = (e as PerformanceEntry & { interactionId?: number }).interactionId;
|
|
63
|
+
if (id) interacciones.set(id, Math.max(interacciones.get(id) ?? 0, e.duration));
|
|
64
|
+
},
|
|
65
|
+
{ durationThreshold: 16 },
|
|
66
|
+
);
|
|
67
|
+
let mandado = false;
|
|
68
|
+
const mandar = () => {
|
|
69
|
+
if (mandado || (v.fcp === undefined && v.lcp === undefined)) return;
|
|
70
|
+
mandado = true;
|
|
71
|
+
const n = performance.getEntriesByType("navigation")[0] as PerformanceNavigationTiming | undefined;
|
|
72
|
+
const d = [...interacciones.values()].sort((a, b) => b - a);
|
|
73
|
+
const red = (navigator as Navigator & { connection?: { effectiveType?: string } }).connection?.effectiveType;
|
|
74
|
+
enviar(
|
|
75
|
+
JSON.stringify({
|
|
76
|
+
tipo: "vitales",
|
|
77
|
+
ruta: rutaGenerica(location.pathname),
|
|
78
|
+
lcp: v.lcp,
|
|
79
|
+
fcp: v.fcp,
|
|
80
|
+
cls: v.cls ?? 0,
|
|
81
|
+
inp: d.length ? d[Math.min(Math.floor(d.length / 50), d.length - 1)] : undefined,
|
|
82
|
+
ttfb: n && n.responseStart > 0 ? n.responseStart : undefined,
|
|
83
|
+
carga: n && n.loadEventEnd > 0 ? n.loadEventEnd : undefined,
|
|
84
|
+
ancho: innerWidth,
|
|
85
|
+
red,
|
|
86
|
+
nav: n?.type,
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
addEventListener("visibilitychange", () => {
|
|
91
|
+
if (document.visibilityState === "hidden") mandar();
|
|
92
|
+
});
|
|
93
|
+
addEventListener("pagehide", mandar);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const vistos = new Set<string>();
|
|
97
|
+
|
|
98
|
+
export function reportarErrorNavegador(error: unknown, donde?: string) {
|
|
99
|
+
try {
|
|
100
|
+
const e = error instanceof Error ? error : new Error(typeof error === "string" ? error : JSON.stringify(error) ?? String(error));
|
|
101
|
+
const mensaje = (e.message || String(error)).slice(0, 2000);
|
|
102
|
+
const pila = e.stack ?? "";
|
|
103
|
+
if (/^Script error\.?$|ResizeObserver loop|^AbortError|signal is aborted/i.test(mensaje)) return;
|
|
104
|
+
if (/chrome-extension:|moz-extension:|safari-extension:/.test(pila)) return;
|
|
105
|
+
const clave = `${e.name}:${mensaje}`;
|
|
106
|
+
if (vistos.has(clave) || vistos.size >= 10) return;
|
|
107
|
+
vistos.add(clave);
|
|
108
|
+
enviar(JSON.stringify({ mensaje, tipo: e.name, pila: pila.slice(0, 8000), url: location.href, donde }));
|
|
109
|
+
} catch {
|
|
110
|
+
/* reportar nunca rompe la página */
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function ReportarErrores() {
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
const alError = (ev: ErrorEvent) => reportarErrorNavegador(ev.error ?? ev.message, "window.onerror");
|
|
117
|
+
const alRechazo = (ev: PromiseRejectionEvent) => reportarErrorNavegador(ev.reason, "promesa sin capturar");
|
|
118
|
+
addEventListener("error", alError);
|
|
119
|
+
addEventListener("unhandledrejection", alRechazo);
|
|
120
|
+
medirVitales();
|
|
121
|
+
return () => {
|
|
122
|
+
removeEventListener("error", alError);
|
|
123
|
+
removeEventListener("unhandledrejection", alRechazo);
|
|
124
|
+
};
|
|
125
|
+
}, []);
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* «El ícono viaja» — mitad del MÓDULO (handoff «Transiciones entre módulos», partes 1b y 1c).
|
|
2
|
+
El mismo archivo vive en cada módulo, al lado de su layout raíz (copiar tal cual; el original está
|
|
3
|
+
en portal-hcmz/docs/transicion-portal.ts). Se pone en <head>, antes de pintar:
|
|
4
|
+
<script dangerouslySetInnerHTML={{ __html: TRANSICION_PORTAL }} />
|
|
5
|
+
- Entrada (1b): si se llegó desde el portal (Referrer-Policy del portal = strict-origin-when-cross-origin,
|
|
6
|
+
llega el origen), el <main> funde 220 ms desde 6 px abajo. La barra NO se anima: queda fija desde el
|
|
7
|
+
primer cuadro donde terminó la réplica del portal. La marca se quita al terminar ese fundido (no con un
|
|
8
|
+
temporizador: si el módulo pinta tarde, el fundido igual corre y no hay brinco). Por eso la barra tiene que estar FUERA del <main>.
|
|
9
|
+
- Regreso (1c): un clic en cualquier enlace a la portada del portal (el botón «Portal») funde el <main>
|
|
10
|
+
160 ms y navega en el mismo clic (la red corre en paralelo; esperar el fundido solo sumaba espera). El portal, al ver que venís de acá, baja ícono y nombre a la tarjeta.
|
|
11
|
+
- Precarga: al dejar el puntero ~200 ms sobre el botón «Portal», Chrome/Edge ya piden la portada (regla de
|
|
12
|
+
precarga, mismo sitio: va con la cookie de Access) y el regreso no espera al servidor.
|
|
13
|
+
- NADA de este script agrega nodos al HTML antes de que React hidrate: un <style>/<script> metido en <head> mientras
|
|
14
|
+
se lee la página hacía que React no reconociera su <head>, tirara el error #418 y volviera a pintar TODA la página
|
|
15
|
+
en cada carga (~0,6-1,2 s de congelamiento, medido el 26-oct). Por eso el estilo va como hoja adoptada (no es un
|
|
16
|
+
nodo) y la regla de precarga se agrega al terminar de cargar.
|
|
17
|
+
Con movimiento reducido, teclas modificadoras, botón del medio o target=_blank: navegación normal. */
|
|
18
|
+
export const TRANSICION_PORTAL = `(function(){try{
|
|
19
|
+
var P="https://portal.hcmz.online",h=document.documentElement,C="cubic-bezier(.2,0,.2,1)";
|
|
20
|
+
var quieto=matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
21
|
+
var r=document.referrer&&new URL(document.referrer);
|
|
22
|
+
if(r&&r.origin===P&&!quieto){h.dataset.desdePortal="1";var fin=function(){delete h.dataset.desdePortal};addEventListener("animationend",function(e){if(e.animationName==="entra-modulo")fin()});setTimeout(fin,4000)}
|
|
23
|
+
var css="html[data-desde-portal] main{animation:entra-modulo 220ms "+C+" backwards}@keyframes entra-modulo{from{opacity:0;transform:translateY(6px)}}";
|
|
24
|
+
try{var hoja=new CSSStyleSheet();hoja.replaceSync(css);document.adoptedStyleSheets=document.adoptedStyleSheets.concat(hoja)}catch(_){addEventListener("DOMContentLoaded",function(){var s=document.createElement("style");s.textContent=css;document.head.appendChild(s)})}
|
|
25
|
+
if(HTMLScriptElement.supports&&HTMLScriptElement.supports("speculationrules"))addEventListener("load",function(){var sr=document.createElement("script");sr.type="speculationrules";sr.textContent=JSON.stringify({prefetch:[{where:{href_matches:P+"/"},eagerness:"moderate"}]});document.head.appendChild(sr)});
|
|
26
|
+
document.addEventListener("click",function(e){
|
|
27
|
+
if(quieto||e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;
|
|
28
|
+
var a=e.target&&e.target.closest&&e.target.closest("a[href]");
|
|
29
|
+
if(!a||(a.target&&a.target!=="_self")||a.hasAttribute("download"))return;
|
|
30
|
+
var u=new URL(a.href,location.href);
|
|
31
|
+
if(u.origin!==P||u.pathname!=="/"||u.search||u.hash)return;
|
|
32
|
+
var m=document.querySelector("main");
|
|
33
|
+
if(!m||!m.animate)return;
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
var an=m.animate([{opacity:1},{opacity:0}],{duration:160,easing:C,fill:"forwards"});
|
|
36
|
+
requestAnimationFrame(function(){location.href=P+"/"});
|
|
37
|
+
addEventListener("pageshow",function(ev){if(ev.persisted)an.cancel()},{once:true});
|
|
38
|
+
});
|
|
39
|
+
}catch(e){}})()`;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { LayoutGrid } from "lucide-react";
|
|
2
|
+
import type { MouseEvent } from "react";
|
|
3
|
+
|
|
4
|
+
export const URL_PORTAL = "https://portal.hcmz.online";
|
|
5
|
+
|
|
6
|
+
type Props = {
|
|
7
|
+
/** A dónde lleva (por omisión, la portada del portal). */
|
|
8
|
+
href?: string;
|
|
9
|
+
/** Solo ícono, 44×44 (cabecera móvil). */
|
|
10
|
+
compacto?: boolean;
|
|
11
|
+
/** Si se pasa, se usa en vez de navegar con href. */
|
|
12
|
+
onClick?: () => void;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/* Botón «Portal»: el último de la barra de todo módulo (regla barra-de-modulo.md).
|
|
16
|
+
Alto 34, padding 0 13, gap 7, radio 8, borde fuerte, glifo layout-grid 15 + «Portal» 13/500.
|
|
17
|
+
Nunca «Inicio», «Volver» ni «Salir». La transición del portal lo detecta por su href. */
|
|
18
|
+
export function BotonPortal({ href = URL_PORTAL, compacto = false, onClick }: Props) {
|
|
19
|
+
const manejar = onClick
|
|
20
|
+
? (e: MouseEvent) => {
|
|
21
|
+
e.preventDefault();
|
|
22
|
+
onClick();
|
|
23
|
+
}
|
|
24
|
+
: undefined;
|
|
25
|
+
|
|
26
|
+
if (compacto) {
|
|
27
|
+
return (
|
|
28
|
+
<a href={href} onClick={manejar} aria-label="Portal" title="Portal" className="inline-flex size-11 items-center justify-center rounded-[8px] text-tinta-2">
|
|
29
|
+
<LayoutGrid width={17} height={17} strokeWidth={1.75} aria-hidden="true" style={{ flex: "none" }} />
|
|
30
|
+
</a>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<a
|
|
36
|
+
href={href}
|
|
37
|
+
onClick={manejar}
|
|
38
|
+
className="inline-flex h-[34px] cursor-pointer items-center gap-[7px] whitespace-nowrap rounded-[8px] border border-borde-fuerte bg-tarjeta px-[13px] font-sans text-ui font-medium text-tinta hover:bg-sutil"
|
|
39
|
+
>
|
|
40
|
+
<LayoutGrid width={15} height={15} strokeWidth={1.75} aria-hidden="true" style={{ flex: "none" }} />
|
|
41
|
+
Portal
|
|
42
|
+
</a>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Divisor vertical que va antes del botón «Portal» en la cabecera de escritorio. */
|
|
47
|
+
export function DivisorCabecera({ alto = 26 }: { alto?: 24 | 26 }) {
|
|
48
|
+
return <span aria-hidden="true" className={`w-px flex-none bg-borde-sutil ${alto === 24 ? "h-6" : "h-[26px]"}`} />;
|
|
49
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Moon, Sun } from "lucide-react";
|
|
4
|
+
import { useSyncExternalStore } from "react";
|
|
5
|
+
|
|
6
|
+
type Tema = "claro" | "oscuro";
|
|
7
|
+
|
|
8
|
+
function leer(): Tema {
|
|
9
|
+
return document.documentElement.dataset.tema === "oscuro" ? "oscuro" : "claro";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function suscribir(cb: () => void) {
|
|
13
|
+
const obs = new MutationObserver(cb);
|
|
14
|
+
obs.observe(document.documentElement, { attributes: true, attributeFilter: ["data-tema"] });
|
|
15
|
+
return () => obs.disconnect();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* Cambia data-tema en <html>; el script TEMA_INICIAL lo guarda en la cookie portal-tema y lo heredan todos los módulos. */
|
|
19
|
+
export function BotonTema({ grande = false }: { grande?: boolean }) {
|
|
20
|
+
const tema = useSyncExternalStore(suscribir, leer, () => "claro" as Tema);
|
|
21
|
+
const Glifo = tema === "oscuro" ? Sun : Moon;
|
|
22
|
+
|
|
23
|
+
function alternar() {
|
|
24
|
+
document.documentElement.dataset.tema = leer() === "oscuro" ? "claro" : "oscuro";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<button
|
|
29
|
+
type="button"
|
|
30
|
+
onClick={alternar}
|
|
31
|
+
aria-label={tema === "oscuro" ? "Cambiar a modo claro" : "Cambiar a modo oscuro"}
|
|
32
|
+
className={
|
|
33
|
+
grande
|
|
34
|
+
? "inline-flex size-11 cursor-pointer items-center justify-center border-0 bg-transparent text-tinta-2"
|
|
35
|
+
: "inline-flex size-[34px] cursor-pointer items-center justify-center rounded-[8px] border border-borde-fuerte bg-control text-tinta transition-colors duration-[120ms] ease-estandar hover:bg-sutil"
|
|
36
|
+
}
|
|
37
|
+
>
|
|
38
|
+
<Glifo width={grande ? 18 : 16} height={grande ? 18 : 16} strokeWidth={1.85} aria-hidden="true" />
|
|
39
|
+
</button>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import Image from "next/image";
|
|
2
|
+
import { Circle, type LucideIcon } from "lucide-react";
|
|
3
|
+
import type { ReactNode } from "react";
|
|
4
|
+
import { BotonPortal, DivisorCabecera, URL_PORTAL } from "./BotonPortal";
|
|
5
|
+
import { BotonTema } from "./BotonTema";
|
|
6
|
+
|
|
7
|
+
export type Modulo = {
|
|
8
|
+
/** = PORTAL_MODULE_ID (para «Pedir permiso para editar»). */
|
|
9
|
+
id: string;
|
|
10
|
+
/** El de la tarjeta del portal; una sola línea. */
|
|
11
|
+
nombre: string;
|
|
12
|
+
/** Para la barra móvil. */
|
|
13
|
+
nombreCorto?: string;
|
|
14
|
+
/** El MISMO glifo de la tarjeta del portal (import por nombre de lucide-react). */
|
|
15
|
+
icono: LucideIcon;
|
|
16
|
+
/** Caja del ícono sin acento (fondo hundida, tinta-2), como el Monitor. Por omisión lleva el acento del módulo. */
|
|
17
|
+
sinAcento?: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type Props = {
|
|
21
|
+
modulo: Modulo;
|
|
22
|
+
/** Quién mira; null = sin sesión (no se muestra «quién»). */
|
|
23
|
+
persona: { nombre: string; nivel?: string; puedeEditar: boolean } | null;
|
|
24
|
+
/** Extras del grupo derecho (frescura, avisos), alto ≤ 34. Van ANTES del tema. */
|
|
25
|
+
extras?: ReactNode;
|
|
26
|
+
/** Franja propia DEBAJO de la barra (pestañas / navegación del módulo). */
|
|
27
|
+
navegacion?: ReactNode;
|
|
28
|
+
/** Barra pegada arriba al hacer scroll. */
|
|
29
|
+
fija?: boolean;
|
|
30
|
+
/** Ancho máximo del contenido; "completo" = sin límite (bandejas, tableros). */
|
|
31
|
+
ancho?: "normal" | "completo";
|
|
32
|
+
urlPortal?: string;
|
|
33
|
+
/** Debajo de la barra móvil (p. ej. la frescura de los datos). */
|
|
34
|
+
extrasMovil?: ReactNode;
|
|
35
|
+
/** false = no mostrar el aviso «Solo lectura» (módulos que son de solo lectura para todos). */
|
|
36
|
+
avisoSoloLectura?: boolean;
|
|
37
|
+
/** Clases extra del <main> (p. ej. "flex flex-col gap-[18px]"). */
|
|
38
|
+
claseContenido?: string;
|
|
39
|
+
/** Texto del aviso de solo lectura, después de «Solo lectura.». */
|
|
40
|
+
textoSoloLectura?: ReactNode;
|
|
41
|
+
children: ReactNode;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/* Barra de módulo (Sistema-de-diseno-Portal-HCMZ/reglas/barra-de-modulo.md). NO cambiar medidas ni orden: la
|
|
45
|
+
transición «el ícono viaja» del portal cuenta con ellas (ícono en 88,29; nombre en 130,29). La barra va FUERA
|
|
46
|
+
del <main>. La sesión se maneja en el Portal: aquí solo se regresa a él. */
|
|
47
|
+
export function Shell({ modulo, persona, extras, navegacion, fija, ancho = "normal", urlPortal = URL_PORTAL, textoSoloLectura = "Tu cuenta puede ver pero no cambiar nada.", extrasMovil, avisoSoloLectura = true, claseContenido = "", children }: Props) {
|
|
48
|
+
const Glifo = modulo.icono ?? Circle;
|
|
49
|
+
const nivel = persona?.nivel ?? (persona?.puedeEditar ? "Puede editar" : "Solo lectura");
|
|
50
|
+
const pedirEditar = `${urlPortal}/solicitar?modulo=${encodeURIComponent(modulo.id)}&nivel=editar`;
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<div className="min-h-screen bg-pagina">
|
|
54
|
+
<a
|
|
55
|
+
href="#contenido"
|
|
56
|
+
className="sr-only focus:not-sr-only focus:absolute focus:left-3 focus:top-3 focus:z-50 focus:rounded-control focus:bg-tarjeta focus:px-3 focus:py-2 focus:text-ui"
|
|
57
|
+
>
|
|
58
|
+
Saltar al contenido
|
|
59
|
+
</a>
|
|
60
|
+
|
|
61
|
+
<div className={`noprint ${fija ? "sticky top-0 z-30" : ""}`}>
|
|
62
|
+
{/* Escritorio */}
|
|
63
|
+
<header className="flex h-14 items-center gap-[14px] border-b border-borde-sutil bg-tarjeta px-6 max-[760px]:hidden">
|
|
64
|
+
<Monograma alto={30} />
|
|
65
|
+
<DivisorCabecera alto={24} />
|
|
66
|
+
<span className={`flex size-7 flex-none items-center justify-center rounded-[8px] ${modulo.sinAcento ? "bg-hundida text-tinta-2" : "bg-acento-bg text-acento-tinta"}`}>
|
|
67
|
+
<Glifo width={16} height={16} strokeWidth={1.75} aria-hidden="true" />
|
|
68
|
+
</span>
|
|
69
|
+
<span className="whitespace-nowrap font-display text-[15px] font-medium tracking-[-0.01em] text-tinta">{modulo.nombre}</span>
|
|
70
|
+
<div className="ml-auto flex items-center gap-[14px]">
|
|
71
|
+
{extras}
|
|
72
|
+
<BotonTema />
|
|
73
|
+
{persona && (
|
|
74
|
+
<div className="flex flex-col items-end gap-0.5 max-[1000px]:hidden">
|
|
75
|
+
<span className="whitespace-nowrap text-ui-lg font-medium text-tinta">{persona.nombre}</span>
|
|
76
|
+
<span className="font-mono text-etiqueta uppercase tracking-[0.08em] text-tinta-3">{nivel}</span>
|
|
77
|
+
</div>
|
|
78
|
+
)}
|
|
79
|
+
<DivisorCabecera />
|
|
80
|
+
<BotonPortal href={urlPortal} />
|
|
81
|
+
</div>
|
|
82
|
+
</header>
|
|
83
|
+
|
|
84
|
+
{/* Móvil */}
|
|
85
|
+
<header className="hidden border-b border-borde-sutil bg-tarjeta max-[760px]:block">
|
|
86
|
+
<div className="flex h-14 items-center gap-2.5 pl-4 pr-1.5">
|
|
87
|
+
<Monograma alto={28} />
|
|
88
|
+
<span className="whitespace-nowrap font-display text-[14.5px] font-medium text-tinta">{modulo.nombreCorto ?? modulo.nombre}</span>
|
|
89
|
+
<span className="ml-auto flex">
|
|
90
|
+
<BotonTema grande />
|
|
91
|
+
<BotonPortal href={urlPortal} compacto />
|
|
92
|
+
</span>
|
|
93
|
+
</div>
|
|
94
|
+
{extrasMovil && <div className="px-4 pb-2.5">{extrasMovil}</div>}
|
|
95
|
+
</header>
|
|
96
|
+
|
|
97
|
+
{navegacion}
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
<main
|
|
101
|
+
id="contenido"
|
|
102
|
+
className={`mx-auto w-full px-7 pb-9 pt-7 max-[620px]:px-4 max-[620px]:pb-6 max-[620px]:pt-5 ${ancho === "completo" ? "" : "max-w-[1240px]"} ${claseContenido}`}
|
|
103
|
+
>
|
|
104
|
+
{avisoSoloLectura && persona && !persona.puedeEditar && (
|
|
105
|
+
<div className="noprint mb-5 flex flex-wrap items-center gap-x-2 gap-y-1 rounded-panel border border-borde-sutil bg-sindatos-bg px-4 py-3 text-ui text-tinta-2">
|
|
106
|
+
<Circle width={14} height={14} strokeWidth={1.75} aria-hidden="true" className="text-sindatos" />
|
|
107
|
+
<span>
|
|
108
|
+
<b className="font-medium text-tinta">Solo lectura.</b> {textoSoloLectura}
|
|
109
|
+
</span>
|
|
110
|
+
<a className="font-medium text-tinta underline underline-offset-2" href={pedirEditar}>
|
|
111
|
+
Pedir permiso para editar
|
|
112
|
+
</a>
|
|
113
|
+
</div>
|
|
114
|
+
)}
|
|
115
|
+
{children}
|
|
116
|
+
</main>
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Monograma «M» del hospital (alt según la regla de marca). Lee /marca/monograma-m.png del public/ del módulo (todos lo tienen). */
|
|
122
|
+
export function Monograma({ alto = 30 }: { alto?: number }) {
|
|
123
|
+
return <Image src="/marca/monograma-m.png" alt="Hospital Centro Médico Zacapa" width={200} height={170} priority style={{ height: alto, width: "auto", display: "block" }} />;
|
|
124
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, type ReactNode } from "react";
|
|
4
|
+
import { Boton } from "./controles";
|
|
5
|
+
|
|
6
|
+
/** Diálogo: radio 14, sombra de menú, pie sutil con Cancelar + acción. Escape y clic afuera cancelan. */
|
|
7
|
+
export function Dialogo({
|
|
8
|
+
titulo,
|
|
9
|
+
descripcion,
|
|
10
|
+
children,
|
|
11
|
+
accion,
|
|
12
|
+
onAccion,
|
|
13
|
+
onCancelar,
|
|
14
|
+
ancho = 420,
|
|
15
|
+
ocupado,
|
|
16
|
+
error,
|
|
17
|
+
destructivo,
|
|
18
|
+
deshabilitado,
|
|
19
|
+
}: {
|
|
20
|
+
titulo: string;
|
|
21
|
+
descripcion?: ReactNode;
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
accion: string;
|
|
24
|
+
onAccion: () => void;
|
|
25
|
+
onCancelar: () => void;
|
|
26
|
+
ancho?: number;
|
|
27
|
+
ocupado?: boolean;
|
|
28
|
+
error?: string | null;
|
|
29
|
+
destructivo?: boolean;
|
|
30
|
+
deshabilitado?: boolean;
|
|
31
|
+
}) {
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const tecla = (e: KeyboardEvent) => e.key === "Escape" && !ocupado && onCancelar();
|
|
34
|
+
addEventListener("keydown", tecla);
|
|
35
|
+
return () => removeEventListener("keydown", tecla);
|
|
36
|
+
}, [onCancelar, ocupado]);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-velo-dialogo p-4" onMouseDown={(e) => e.target === e.currentTarget && !ocupado && onCancelar()}>
|
|
40
|
+
<div role="dialog" aria-modal="true" aria-label={titulo} style={{ maxWidth: ancho }} className="flex max-h-full w-full flex-col overflow-hidden rounded-[14px] bg-tarjeta text-tinta shadow-menu">
|
|
41
|
+
<div className="min-h-0 overflow-y-auto">
|
|
42
|
+
<div className="px-6 pt-6">
|
|
43
|
+
<span className="block font-display text-[19px] font-normal tracking-[-.01em]">{titulo}</span>
|
|
44
|
+
{descripcion && <p className="m-0 mt-[9px] text-[13.5px] leading-[1.55] text-tinta-2 [text-wrap:pretty]">{descripcion}</p>}
|
|
45
|
+
</div>
|
|
46
|
+
{children && <div className="flex flex-col gap-[10px] px-6 pt-[18px]">{children}</div>}
|
|
47
|
+
{error && (
|
|
48
|
+
<p role="alert" className="m-0 px-6 pt-3 text-[13px] text-suspendido-tinta">
|
|
49
|
+
{error}
|
|
50
|
+
</p>
|
|
51
|
+
)}
|
|
52
|
+
</div>
|
|
53
|
+
<div className="mt-[22px] flex flex-none justify-end gap-[9px] border-t border-divisor bg-sutil px-6 py-4">
|
|
54
|
+
<Boton onClick={onCancelar} disabled={ocupado}>
|
|
55
|
+
Cancelar
|
|
56
|
+
</Boton>
|
|
57
|
+
<Boton variante={destructivo ? "destructivo" : "primario"} onClick={onAccion} disabled={ocupado || deshabilitado}>
|
|
58
|
+
{ocupado ? "Un momento…" : accion}
|
|
59
|
+
</Boton>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
}
|
package/src/ui/clases.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* Clases sueltas para lo que no vale la pena volver componente (inputs nativos, enlaces con forma de botón).
|
|
2
|
+
Mismas medidas que los componentes. Si una pantalla necesita otra medida, primero se agrega aquí. */
|
|
3
|
+
|
|
4
|
+
export const BTN =
|
|
5
|
+
"inline-flex h-[34px] cursor-pointer items-center justify-center gap-[7px] whitespace-nowrap rounded-[8px] border border-borde-fuerte bg-control px-[13px] text-ui text-tinta-2 hover:bg-sutil disabled:cursor-default disabled:opacity-50";
|
|
6
|
+
export const BTN_PRIMARIO =
|
|
7
|
+
"inline-flex h-[34px] cursor-pointer items-center justify-center gap-[7px] whitespace-nowrap rounded-[8px] border border-tinta bg-tinta px-[13px] text-ui font-medium text-sobre-tinta hover:opacity-90 disabled:cursor-default disabled:opacity-50";
|
|
8
|
+
export const BTN_PELIGRO =
|
|
9
|
+
"inline-flex h-[34px] cursor-pointer items-center justify-center gap-[7px] whitespace-nowrap rounded-[8px] border border-suspendido bg-suspendido-bg px-[13px] text-ui font-medium text-suspendido-tinta hover:opacity-90 disabled:cursor-default disabled:opacity-50";
|
|
10
|
+
export const INPUT =
|
|
11
|
+
"h-9 w-full rounded-[8px] border border-borde-fuerte bg-control px-3 text-ui-lg text-tinta placeholder:text-tinta-apoyo focus:outline-2 focus:outline-tinta";
|
|
12
|
+
export const SELECT = `${INPUT} cursor-pointer`;
|
|
13
|
+
export const TEXTAREA = "w-full rounded-[8px] border border-borde-fuerte bg-control px-3 py-2 text-ui-lg text-tinta placeholder:text-tinta-apoyo focus:outline-2 focus:outline-tinta";
|
|
14
|
+
export const ETIQUETA = "mb-1 block text-mini font-medium text-tinta-2";
|
|
15
|
+
export const TARJETA = "rounded-tarjeta border border-borde-sutil bg-tarjeta shadow-plana";
|
|
16
|
+
export const TITULO = "m-0 font-display text-seccion font-medium text-tinta max-[620px]:text-[22px]";
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { CircleAlert, CircleCheck, CircleDashed, OctagonAlert, TriangleAlert, type LucideIcon } from "lucide-react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
export type Tono = "aldia" | "porvencer" | "fallo" | "suspendido" | "sindatos";
|
|
5
|
+
|
|
6
|
+
/* Estados VALIDADOS PARA DALTONISMO: van siempre con texto y ícono, nunca solo color.
|
|
7
|
+
Versión oficial del design system (4-nov): fondo -bg, texto -tinta, ícono en el hex validado. */
|
|
8
|
+
const TONO: Record<Tono, { chip: string; icono: string; glifo: LucideIcon }> = {
|
|
9
|
+
aldia: { chip: "bg-aldia-bg text-aldia-tinta", icono: "text-aldia", glifo: CircleCheck },
|
|
10
|
+
porvencer: { chip: "bg-porvencer-bg text-porvencer-tinta", icono: "text-porvencer", glifo: TriangleAlert },
|
|
11
|
+
fallo: { chip: "bg-fallo-bg text-fallo-tinta", icono: "text-fallo", glifo: CircleAlert },
|
|
12
|
+
suspendido: { chip: "bg-suspendido-bg text-suspendido-tinta", icono: "text-suspendido", glifo: OctagonAlert },
|
|
13
|
+
sindatos: { chip: "bg-sindatos-bg text-sindatos-tinta", icono: "text-sindatos", glifo: CircleDashed },
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** `icono` por omisión = el del estado; `icono={null}` lo quita. */
|
|
17
|
+
export function ChipEstado({ tono, icono, children }: { tono: Tono; icono?: LucideIcon | null; children: ReactNode }) {
|
|
18
|
+
const t = TONO[tono];
|
|
19
|
+
const Glifo = icono === undefined ? t.glifo : icono;
|
|
20
|
+
return (
|
|
21
|
+
<span className={`inline-flex h-6 items-center gap-[5px] whitespace-nowrap rounded-pildora px-[10px] text-[12.5px] font-medium ${t.chip}`}>
|
|
22
|
+
{Glifo && <Glifo width={14} height={14} strokeWidth={1.75} aria-hidden="true" className={t.icono} />}
|
|
23
|
+
{children}
|
|
24
|
+
</span>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Iniciales en círculo (persona o contacto). */
|
|
29
|
+
export function Avatar({ texto, size = 36, fuente = 14, peso = 500, className = "" }: { texto: string; size?: number; fuente?: number; peso?: 300 | 400 | 500; className?: string }) {
|
|
30
|
+
return (
|
|
31
|
+
<span
|
|
32
|
+
style={{ width: size, height: size, fontSize: fuente, fontWeight: peso }}
|
|
33
|
+
className={`flex flex-none items-center justify-center rounded-full bg-hundida font-display text-tinta-2 ${className}`}
|
|
34
|
+
>
|
|
35
|
+
{texto}
|
|
36
|
+
</span>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Etiqueta de sección: mono 11, +.12em, mayúsculas. */
|
|
41
|
+
export function EtiquetaSeccion({ children, className = "" }: { children: ReactNode; className?: string }) {
|
|
42
|
+
return <span className={`font-mono text-[11px] uppercase leading-[1.3] tracking-[.12em] text-tinta-3 ${className}`}>{children}</span>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Título de página (Sora 26/500; 22 en teléfono). */
|
|
46
|
+
export function Titulo({ children, className = "" }: { children: ReactNode; className?: string }) {
|
|
47
|
+
return <h1 className={`m-0 font-display text-seccion font-medium text-tinta max-[620px]:text-[22px] ${className}`}>{children}</h1>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Tarjeta base del portal (radio 14). */
|
|
51
|
+
export function Tarjeta({ children, className = "" }: { children: ReactNode; className?: string }) {
|
|
52
|
+
return <div className={`rounded-tarjeta border border-borde-sutil bg-tarjeta shadow-plana ${className}`}>{children}</div>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Tarjeta radio 16 con filas divididas (Ajustes, Desglose). Usar con FilaDato / FilaInterruptor. */
|
|
56
|
+
export function TarjetaFilas({ children, className = "" }: { children: ReactNode; className?: string }) {
|
|
57
|
+
return <div className={`overflow-hidden rounded-[16px] border border-borde-sutil bg-tarjeta shadow-plana ${className}`}>{children}</div>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function FilaDato({ k, children, ultima }: { k: ReactNode; children: ReactNode; ultima?: boolean }) {
|
|
61
|
+
return (
|
|
62
|
+
<div className={`flex items-center justify-between gap-3 px-[18px] py-[14px] text-[14px] ${ultima ? "" : "border-b border-divisor"}`}>
|
|
63
|
+
<span className="text-tinta-3">{k}</span>
|
|
64
|
+
<span className="min-w-0 text-right text-tinta">{children}</span>
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function Nota({ children, className = "" }: { children: ReactNode; className?: string }) {
|
|
70
|
+
return <p className={`m-0 text-[13px] leading-[1.5] text-tinta-3 ${className}`}>{children}</p>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Estado vacío: ícono, una línea de qué pasa y (opcional) qué hacer. */
|
|
74
|
+
export function Vacio({ icono: Glifo, titulo, children }: { icono?: LucideIcon; titulo: string; children?: ReactNode }) {
|
|
75
|
+
return (
|
|
76
|
+
<div className="flex flex-col items-center gap-2 px-6 py-12 text-center">
|
|
77
|
+
{Glifo && (
|
|
78
|
+
<span className="mb-1 flex size-10 items-center justify-center rounded-full bg-hundida text-tinta-3">
|
|
79
|
+
<Glifo width={18} height={18} strokeWidth={1.75} aria-hidden="true" />
|
|
80
|
+
</span>
|
|
81
|
+
)}
|
|
82
|
+
<span className="font-display text-titulo-tarjeta font-medium text-tinta">{titulo}</span>
|
|
83
|
+
{children && <div className="max-w-[420px] text-ui text-tinta-3">{children}</div>}
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
}
|