@j3ehcmz/ui 0.1.2 → 0.2.1

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.
@@ -0,0 +1,129 @@
1
+ "use client";
2
+
3
+ import Link from "next/link";
4
+ import { usePathname } from "next/navigation";
5
+ import type { CSSProperties } from "react";
6
+ import { GlifoIcono, type IconoProp } from "../iconos/glifos";
7
+
8
+ export type EnlaceModulo = {
9
+ href: string;
10
+ texto: string;
11
+ /** Lo normal: componente de lucide-react (icono={Lightbulb}). */
12
+ icono?: IconoProp;
13
+ /** Cuándo está activo. Por omisión: "/" solo en "/", lo demás en la ruta y sus hijas. */
14
+ activo?: (ruta: string) => boolean;
15
+ /** Insignia con un número (sin leer, pendientes). 0 o undefined = sin insignia. */
16
+ cuenta?: number;
17
+ };
18
+
19
+ type Props = {
20
+ enlaces: EnlaceModulo[];
21
+ /** Nombre accesible («Secciones de Ideas»). */
22
+ etiqueta: string;
23
+ /**
24
+ * - "barra" (Ideas): franja bajo la barra, pestañas compactas con subrayado de acento.
25
+ * - "banda" (Central de Atención): franja centrada a 1180, borde inferior de acento de punta a punta de la pestaña.
26
+ * - "inferior-movil" (Avisos): pestañas bajo la barra en escritorio; en el teléfono, barra inferior FIJA de 64 px.
27
+ * Con esta variante el módulo deja espacio abajo: `<Shell claseContenido="max-[760px]:pb-24">`.
28
+ */
29
+ variante?: "barra" | "banda" | "inferior-movil";
30
+ className?: string;
31
+ };
32
+
33
+ const porOmision = (href: string) => (ruta: string) => (href === "/" ? ruta === "/" : ruta === href || ruta.startsWith(`${href}/`));
34
+
35
+ function Insignia({ n, movil }: { n: number; movil?: boolean }) {
36
+ if (!n || n <= 0) return null;
37
+ return (
38
+ <span
39
+ className={`inline-flex h-[18px] min-w-[18px] items-center justify-center rounded-pildora bg-tinta px-[5px] font-mono text-etiqueta tracking-normal text-sobre-tinta ${
40
+ movil ? "max-[760px]:absolute max-[760px]:left-[calc(50%+6px)] max-[760px]:top-[9px]" : ""
41
+ }`}
42
+ >
43
+ <span className="sr-only">, {n} pendientes</span>
44
+ <span aria-hidden="true">{n > 99 ? "99+" : n}</span>
45
+ </span>
46
+ );
47
+ }
48
+
49
+ /** Navegación del módulo para el slot `navegacion` del Shell (franja propia DEBAJO de la barra). */
50
+ export function NavModulo({ enlaces, etiqueta, variante = "barra", className = "" }: Props) {
51
+ const ruta = usePathname() ?? "/";
52
+ const items = enlaces.map((e) => ({ ...e, on: (e.activo ?? porOmision(e.href))(ruta) }));
53
+
54
+ if (variante === "banda") {
55
+ return (
56
+ <nav aria-label={etiqueta} className={`noprint border-b border-borde-sutil bg-tarjeta ${className}`}>
57
+ <div className="sin-barra mx-auto flex w-full max-w-[1180px] gap-1 overflow-x-auto px-5 max-[620px]:px-2">
58
+ {items.map((e) => (
59
+ <Link
60
+ key={e.href}
61
+ href={e.href}
62
+ aria-current={e.on ? "page" : undefined}
63
+ className={`-mb-px inline-flex h-11 items-center gap-2 whitespace-nowrap border-b-2 px-3 text-ui ${
64
+ e.on ? "border-acento font-medium text-tinta" : "border-transparent text-tinta-3 hover:text-tinta"
65
+ }`}
66
+ >
67
+ {e.icono && <GlifoIcono icono={e.icono} tamano={15} />}
68
+ {e.texto}
69
+ <Insignia n={e.cuenta ?? 0} />
70
+ </Link>
71
+ ))}
72
+ </div>
73
+ </nav>
74
+ );
75
+ }
76
+
77
+ if (variante === "inferior-movil") {
78
+ return (
79
+ <nav
80
+ aria-label={etiqueta}
81
+ className={`noprint border-b border-borde-sutil bg-tarjeta pb-[env(safe-area-inset-bottom,0px)] max-[760px]:fixed max-[760px]:inset-x-0 max-[760px]:bottom-0 max-[760px]:z-40 max-[760px]:border-b-0 max-[760px]:border-t ${className}`}
82
+ >
83
+ <ul
84
+ style={{ "--columnas": `repeat(${items.length}, minmax(0, 1fr))` } as CSSProperties}
85
+ className="m-0 flex list-none items-center gap-1 px-7 py-0 max-[760px]:grid max-[760px]:grid-cols-[var(--columnas)] max-[760px]:gap-0 max-[760px]:px-0"
86
+ >
87
+ {items.map((e) => (
88
+ <li key={e.href} className="flex-none">
89
+ <Link
90
+ href={e.href}
91
+ aria-current={e.on ? "page" : undefined}
92
+ className={`relative inline-flex h-11 items-center gap-[7px] whitespace-nowrap px-3 text-ui-lg max-[760px]:h-16 max-[760px]:w-full max-[760px]:flex-col max-[760px]:justify-center max-[760px]:gap-[3px] max-[760px]:px-0 max-[760px]:text-mini ${
93
+ e.on
94
+ ? "-mb-px border-b-2 border-tinta font-semibold text-tinta max-[760px]:mb-0 max-[760px]:border-b-0 max-[760px]:shadow-[inset_0_2px_0_var(--tinta)]"
95
+ : "text-tinta-3"
96
+ }`}
97
+ >
98
+ {e.icono && <GlifoIcono icono={e.icono} tamano={19} trazo={e.on ? 2 : 1.75} />}
99
+ {e.texto}
100
+ <Insignia n={e.cuenta ?? 0} movil />
101
+ </Link>
102
+ </li>
103
+ ))}
104
+ </ul>
105
+ </nav>
106
+ );
107
+ }
108
+
109
+ // "barra"
110
+ return (
111
+ <div className={`noprint sin-barra overflow-x-auto border-b border-borde-sutil bg-tarjeta px-5 max-[760px]:px-3 ${className}`}>
112
+ <nav aria-label={etiqueta} className="flex items-center gap-1">
113
+ {items.map((e) => (
114
+ <Link
115
+ key={e.href}
116
+ href={e.href}
117
+ aria-current={e.on ? "page" : undefined}
118
+ className={`relative inline-flex h-10 items-center gap-1.5 whitespace-nowrap rounded-[8px] px-2.5 text-ui ${e.on ? "font-medium text-tinta" : "text-tinta-3 hover:text-tinta"}`}
119
+ >
120
+ {e.icono && <GlifoIcono icono={e.icono} tamano={15} />}
121
+ {e.texto}
122
+ <Insignia n={e.cuenta ?? 0} />
123
+ {e.on && <span aria-hidden="true" className="absolute inset-x-2.5 -bottom-px h-[2px] rounded-pildora bg-acento" />}
124
+ </Link>
125
+ ))}
126
+ </nav>
127
+ </div>
128
+ );
129
+ }
@@ -0,0 +1,88 @@
1
+ import Link from "next/link";
2
+ import type { Key, ReactNode } from "react";
3
+
4
+ /* Tabla de datos (modelo: isc-hcmz components/ui/datos.tsx). Sin estado: sirve en componentes de servidor.
5
+ Scroll horizontal PROPIO (nunca ensancha la página), números tabulares, encabezado mono. */
6
+
7
+ /** Clases de celda para tablas armadas a mano (mismas medidas que <Tabla>). */
8
+ export const TH = "whitespace-nowrap px-4 py-2.5 font-mono text-etiqueta font-medium uppercase tracking-[0.06em] text-tinta-3";
9
+ export const TD = "px-4 py-2.5 align-top text-tinta-2";
10
+ /** Fila del cuerpo (divisor + resalte al pasar). */
11
+ export const TR = "border-b border-borde-sutil last:border-0 hover:bg-sutil";
12
+
13
+ export type Columna<T> = {
14
+ titulo: ReactNode;
15
+ celda: (fila: T) => ReactNode;
16
+ /** Alinea a la derecha (cifras, montos). */
17
+ derecha?: boolean;
18
+ /** Ancho CSS de la columna ("120px", "30%"). */
19
+ ancho?: string;
20
+ };
21
+
22
+ export function Tabla<T>({
23
+ etiqueta,
24
+ columnas,
25
+ filas,
26
+ clave,
27
+ enlace,
28
+ vacio = "No hay resultados.",
29
+ minAncho,
30
+ enTarjeta = true,
31
+ className = "",
32
+ }: {
33
+ /** Nombre accesible de la tabla (y de su región con scroll). */
34
+ etiqueta: string;
35
+ columnas: Columna<T>[];
36
+ filas: T[];
37
+ /** Clave estable de cada fila; por omisión el índice. */
38
+ clave?: (fila: T, i: number) => Key;
39
+ /** Si la fila lleva a un detalle: la primera celda se vuelve enlace. */
40
+ enlace?: (fila: T) => string;
41
+ /** Lo que se ve sin filas (texto o un <Vacio />). */
42
+ vacio?: ReactNode;
43
+ /** Ancho mínimo en px antes de desplazar horizontalmente. */
44
+ minAncho?: number;
45
+ /** false = sin tarjeta alrededor (dentro de un Panel con sinRelleno). */
46
+ enTarjeta?: boolean;
47
+ className?: string;
48
+ }) {
49
+ const marco = enTarjeta ? "rounded-tarjeta border border-borde-sutil bg-tarjeta shadow-plana" : "";
50
+ if (filas.length === 0) {
51
+ return typeof vacio === "string" ? <div className={`${marco} px-5 py-8 text-center text-ui-lg text-tinta-3 ${className}`}>{vacio}</div> : <div className={`${marco} ${className}`}>{vacio}</div>;
52
+ }
53
+ return (
54
+ <div role="region" aria-label={etiqueta} tabIndex={0} className={`${marco} overflow-x-auto ${className}`}>
55
+ <table aria-label={etiqueta} className="w-full border-collapse text-ui tabular-nums" style={minAncho ? { minWidth: minAncho } : undefined}>
56
+ <thead>
57
+ <tr className="border-b border-borde-sutil">
58
+ {columnas.map((c, j) => (
59
+ <th key={j} scope="col" className={`${TH} ${c.derecha ? "text-right" : "text-left"}`} style={c.ancho ? { width: c.ancho } : undefined}>
60
+ {c.titulo}
61
+ </th>
62
+ ))}
63
+ </tr>
64
+ </thead>
65
+ <tbody>
66
+ {filas.map((f, i) => {
67
+ const href = enlace?.(f);
68
+ return (
69
+ <tr key={clave ? clave(f, i) : i} className={TR}>
70
+ {columnas.map((c, j) => (
71
+ <td key={j} className={`${TD} ${c.derecha ? "text-right" : ""}`}>
72
+ {href && j === 0 ? (
73
+ <Link href={href} className="font-medium text-tinta underline-offset-2 hover:underline">
74
+ {c.celda(f)}
75
+ </Link>
76
+ ) : (
77
+ c.celda(f)
78
+ )}
79
+ </td>
80
+ ))}
81
+ </tr>
82
+ );
83
+ })}
84
+ </tbody>
85
+ </table>
86
+ </div>
87
+ );
88
+ }
@@ -1,5 +1,6 @@
1
- import { CircleAlert, CircleCheck, CircleDashed, OctagonAlert, TriangleAlert, type LucideIcon } from "lucide-react";
1
+ import { CircleAlert, CircleCheck, CircleDashed, CloudOff, Inbox, OctagonAlert, SearchX, TriangleAlert, type LucideIcon } from "lucide-react";
2
2
  import type { ReactNode } from "react";
3
+ import { GlifoIcono, type IconoProp } from "../iconos/glifos";
3
4
 
4
5
  export type Tono = "aldia" | "porvencer" | "fallo" | "suspendido" | "sindatos";
5
6
 
@@ -13,13 +14,56 @@ const TONO: Record<Tono, { chip: string; icono: string; glifo: LucideIcon }> = {
13
14
  sindatos: { chip: "bg-sindatos-bg text-sindatos-tinta", icono: "text-sindatos", glifo: CircleDashed },
14
15
  };
15
16
 
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 }) {
17
+ /** Fondo + tinta de texto de cada estado (chips, avisos, celdas). Para el ícono del estado, `text-<tono>`. */
18
+ export const CLASES_TONO: Record<Tono, string> = {
19
+ aldia: TONO.aldia.chip,
20
+ porvencer: TONO.porvencer.chip,
21
+ fallo: TONO.fallo.chip,
22
+ suspendido: TONO.suspendido.chip,
23
+ sindatos: TONO.sindatos.chip,
24
+ };
25
+
26
+ /** Color «hex» validado del estado, para el ícono (`text-aldia`…). */
27
+ export const COLOR_TONO: Record<Tono, string> = {
28
+ aldia: TONO.aldia.icono,
29
+ porvencer: TONO.porvencer.icono,
30
+ fallo: TONO.fallo.icono,
31
+ suspendido: TONO.suspendido.icono,
32
+ sindatos: TONO.sindatos.icono,
33
+ };
34
+
35
+ /** Glifo reservado de cada estado. */
36
+ export const GLIFO_TONO: Record<Tono, LucideIcon> = {
37
+ aldia: TONO.aldia.glifo,
38
+ porvencer: TONO.porvencer.glifo,
39
+ fallo: TONO.fallo.glifo,
40
+ suspendido: TONO.suspendido.glifo,
41
+ sindatos: TONO.sindatos.glifo,
42
+ };
43
+
44
+ /** `icono` por omisión = el del estado; `icono={null}` lo quita. Acepta componente, elemento o nombre del juego base.
45
+ * `tamano="chica"` = 20 px de alto (dentro de tablas y filas densas). */
46
+ export function ChipEstado({
47
+ tono,
48
+ icono,
49
+ tamano = "normal",
50
+ className = "",
51
+ children,
52
+ }: {
53
+ tono: Tono;
54
+ icono?: IconoProp | null;
55
+ tamano?: "normal" | "chica";
56
+ className?: string;
57
+ children: ReactNode;
58
+ }) {
18
59
  const t = TONO[tono];
19
- const Glifo = icono === undefined ? t.glifo : icono;
60
+ const glifo = icono === undefined ? t.glifo : icono;
61
+ const chica = tamano === "chica";
20
62
  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} />}
63
+ <span
64
+ className={`inline-flex items-center whitespace-nowrap rounded-pildora font-medium ${chica ? "h-5 gap-1 px-2 text-mini" : "h-6 gap-[5px] px-[10px] text-[12.5px]"} ${t.chip} ${className}`}
65
+ >
66
+ {glifo && <GlifoIcono icono={glifo} tamano={chica ? 12 : 14} className={t.icono} />}
23
67
  {children}
24
68
  </span>
25
69
  );
@@ -70,17 +114,52 @@ export function Nota({ children, className = "" }: { children: ReactNode; classN
70
114
  return <p className={`m-0 text-[13px] leading-[1.5] text-tinta-3 ${className}`}>{children}</p>;
71
115
  }
72
116
 
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 }) {
117
+ type TipoVacio = "vacio" | "sin-datos" | "caido" | "sin-coincidencias";
118
+
119
+ const ICONO_VACIO: Record<TipoVacio, LucideIcon> = {
120
+ vacio: Inbox,
121
+ "sin-datos": CircleDashed,
122
+ caido: CloudOff,
123
+ "sin-coincidencias": SearchX,
124
+ };
125
+
126
+ /** Estado vacío: ícono, una línea de qué pasa y (opcional) qué hacer.
127
+ * - `tipo` pone el ícono por omisión (vacío, sin datos de la fuente, servicio caído, búsqueda sin resultados);
128
+ * «caido» pinta el ícono en rojo y se anuncia (role="alert").
129
+ * - `accion`: botón o enlace de qué hacer («Agregar la primera», «Quitar filtros», «Reintentar»).
130
+ * - `marco`: caja con borde (cuando el vacío va suelto en la página y no dentro de una tarjeta). */
131
+ export function Vacio({
132
+ icono,
133
+ titulo,
134
+ tipo,
135
+ accion,
136
+ marco,
137
+ className = "",
138
+ children,
139
+ }: {
140
+ icono?: IconoProp;
141
+ titulo: string;
142
+ tipo?: TipoVacio;
143
+ accion?: ReactNode;
144
+ marco?: boolean;
145
+ className?: string;
146
+ children?: ReactNode;
147
+ }) {
148
+ const glifo = icono ?? (tipo ? ICONO_VACIO[tipo] : undefined);
149
+ const caido = tipo === "caido";
75
150
  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" />
151
+ <div
152
+ role={caido ? "alert" : undefined}
153
+ className={`flex flex-col items-center gap-2 px-6 py-12 text-center ${marco ? "rounded-tarjeta border border-borde-sutil bg-tarjeta shadow-plana" : ""} ${className}`}
154
+ >
155
+ {glifo && (
156
+ <span className={`mb-1 flex size-10 items-center justify-center rounded-full ${caido ? "bg-fallo-bg text-fallo" : "bg-hundida text-tinta-3"}`}>
157
+ <GlifoIcono icono={glifo} tamano={18} />
80
158
  </span>
81
159
  )}
82
160
  <span className="font-display text-titulo-tarjeta font-medium text-tinta">{titulo}</span>
83
161
  {children && <div className="max-w-[420px] text-ui text-tinta-3">{children}</div>}
162
+ {accion && <div className="mt-2 flex flex-wrap items-center justify-center gap-2">{accion}</div>}
84
163
  </div>
85
164
  );
86
165
  }