@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.
- package/CHANGELOG.md +35 -0
- package/README.md +10 -0
- package/package.json +4 -2
- package/src/iconos/Icono.tsx +13 -5
- package/src/iconos/glifos.tsx +92 -0
- package/src/index.ts +26 -3
- package/src/navegador/reportar-errores.tsx +15 -0
- package/src/shell/Shell.tsx +10 -2
- package/src/texto.ts +32 -0
- package/src/tiempo/Hace.tsx +69 -0
- package/src/tiempo/relativo.ts +70 -0
- package/src/ui/Dialogo.tsx +90 -33
- package/src/ui/NavModulo.tsx +129 -0
- package/src/ui/Tabla.tsx +88 -0
- package/src/ui/contenido.tsx +91 -12
- package/src/ui/controles.tsx +247 -185
- package/src/ui/interactivos.tsx +230 -0
- package/src/ui/pagina.tsx +205 -0
package/src/ui/controles.tsx
CHANGED
|
@@ -1,185 +1,247 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import type { LucideIcon } from "lucide-react";
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
| (BotonBase & Omit<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
{
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
{
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
aria-
|
|
87
|
-
{
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
opciones
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { LucideIcon } from "lucide-react";
|
|
4
|
+
import Link from "next/link";
|
|
5
|
+
import type { AnchorHTMLAttributes, ButtonHTMLAttributes, ReactNode } from "react";
|
|
6
|
+
|
|
7
|
+
/* Piezas del sistema de diseño con los valores del rediseño v4 de WhatsApp (el más pulido).
|
|
8
|
+
Íconos: se pasan como componente de lucide-react importado por nombre (icono={Plus}), así cada
|
|
9
|
+
módulo solo carga los que usa. */
|
|
10
|
+
|
|
11
|
+
type BotonBase = {
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
variante?: "primario" | "secundario" | "destructivo" | "fantasma";
|
|
14
|
+
icono?: LucideIcon;
|
|
15
|
+
/** 32–36: módulos (v4 de WhatsApp). 38–42: los del portal (más padding y texto). */
|
|
16
|
+
alto?: 32 | 34 | 36 | 38 | 40 | 42;
|
|
17
|
+
className?: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type BotonProps =
|
|
21
|
+
| (BotonBase & Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children" | "className"> & { href?: undefined })
|
|
22
|
+
| (BotonBase & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "children" | "className"> & { href: string });
|
|
23
|
+
|
|
24
|
+
const VARIANTE: Record<NonNullable<BotonBase["variante"]>, string> = {
|
|
25
|
+
primario: "border-0 bg-tinta font-semibold text-sobre-tinta hover:opacity-90",
|
|
26
|
+
secundario: "border border-borde-fuerte bg-tarjeta text-tinta-2 hover:bg-sutil",
|
|
27
|
+
// En oscuro, suspendido-tinta es rosa (#f0908f) y el blanco no se lee: ahí va el rojo validado #d03b3b (6,6:1).
|
|
28
|
+
destructivo: "border-0 bg-suspendido-tinta font-semibold text-blanco hover:opacity-90 dark:bg-suspendido",
|
|
29
|
+
fantasma: "border-0 bg-transparent text-tinta-2 hover:bg-hundida",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const ALTO = {
|
|
33
|
+
32: "h-8 px-[15px] text-[13px]",
|
|
34
|
+
34: "h-[34px] px-[15px] text-[13px]",
|
|
35
|
+
36: "h-9 px-[15px] text-[13px]",
|
|
36
|
+
38: "h-[38px] px-4 text-[13.5px]",
|
|
37
|
+
40: "h-10 px-[18px] text-[14px]",
|
|
38
|
+
42: "h-[42px] px-5 text-[14.5px]",
|
|
39
|
+
} as const;
|
|
40
|
+
|
|
41
|
+
/** Con `href` se dibuja como enlace (antes BotonEnlace del portal). */
|
|
42
|
+
export function Boton(props: BotonProps) {
|
|
43
|
+
const { children, variante = "secundario", icono: Glifo, alto = 36, className = "" } = props;
|
|
44
|
+
const clase = `inline-flex cursor-pointer items-center justify-center gap-[7px] whitespace-nowrap rounded-[9px] font-sans no-underline disabled:cursor-default disabled:opacity-50 ${ALTO[alto]} ${VARIANTE[variante]} ${className}`;
|
|
45
|
+
const glifo = Glifo && <Glifo width={15} height={15} strokeWidth={1.75} aria-hidden="true" style={{ flex: "none" }} />;
|
|
46
|
+
if (props.href !== undefined) {
|
|
47
|
+
const { children: _c, variante: _v, icono: _i, alto: _a, className: _k, ...resto } = props;
|
|
48
|
+
return (
|
|
49
|
+
<a {...resto} className={clase}>
|
|
50
|
+
{glifo}
|
|
51
|
+
{children}
|
|
52
|
+
</a>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
const { children: _c, variante: _v, icono: _i, alto: _a, className: _k, type = "button", ...resto } = props;
|
|
56
|
+
return (
|
|
57
|
+
<button type={type} {...resto} className={clase}>
|
|
58
|
+
{glifo}
|
|
59
|
+
{children}
|
|
60
|
+
</button>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Botón de solo ícono, 44×44 (objetivo táctil mínimo). `titulo` es obligatorio: es su nombre accesible. */
|
|
65
|
+
export function BotonIcono({
|
|
66
|
+
icono: Glifo,
|
|
67
|
+
titulo,
|
|
68
|
+
activo,
|
|
69
|
+
size = 20,
|
|
70
|
+
redondo,
|
|
71
|
+
expandido,
|
|
72
|
+
className = "",
|
|
73
|
+
...resto
|
|
74
|
+
}: Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children"> & {
|
|
75
|
+
icono: LucideIcon;
|
|
76
|
+
titulo: string;
|
|
77
|
+
activo?: boolean;
|
|
78
|
+
size?: number;
|
|
79
|
+
redondo?: boolean;
|
|
80
|
+
expandido?: boolean;
|
|
81
|
+
}) {
|
|
82
|
+
return (
|
|
83
|
+
<button
|
|
84
|
+
type="button"
|
|
85
|
+
title={titulo}
|
|
86
|
+
aria-label={titulo}
|
|
87
|
+
aria-expanded={expandido}
|
|
88
|
+
{...resto}
|
|
89
|
+
className={`flex size-11 flex-none cursor-pointer items-center justify-center text-tinta-2 hover:bg-hundida disabled:cursor-default disabled:opacity-50 ${redondo ? "rounded-full" : "rounded-[10px]"} ${activo ? "bg-hundida" : "bg-transparent"} ${className}`}
|
|
90
|
+
>
|
|
91
|
+
<Glifo width={size} height={size} strokeWidth={1.75} aria-hidden="true" />
|
|
92
|
+
</button>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Interruptor 40×24: pista de acento (encendido) o borde fuerte; perilla blanca 18. Solo visual. */
|
|
97
|
+
export function Pista({ on }: { on: boolean }) {
|
|
98
|
+
return (
|
|
99
|
+
<span aria-hidden="true" className={`flex h-6 w-10 flex-none rounded-pildora p-[3px] transition-colors duration-[120ms] ${on ? "justify-end bg-acento" : "justify-start bg-borde-fuerte"}`}>
|
|
100
|
+
<span className="size-[18px] rounded-full bg-blanco shadow-[0_1px_2px_rgba(32,40,38,.2)]" />
|
|
101
|
+
</span>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Fila con título, explicación e interruptor (Ajustes). `suelta` = tarjeta propia en vez de fila dentro de TarjetaFilas. */
|
|
106
|
+
export function FilaInterruptor({
|
|
107
|
+
titulo,
|
|
108
|
+
sub,
|
|
109
|
+
on,
|
|
110
|
+
alternar,
|
|
111
|
+
suelta,
|
|
112
|
+
disabled,
|
|
113
|
+
}: {
|
|
114
|
+
titulo: ReactNode;
|
|
115
|
+
sub?: ReactNode;
|
|
116
|
+
on: boolean;
|
|
117
|
+
alternar: () => void;
|
|
118
|
+
suelta?: boolean;
|
|
119
|
+
disabled?: boolean;
|
|
120
|
+
}) {
|
|
121
|
+
return (
|
|
122
|
+
<button
|
|
123
|
+
type="button"
|
|
124
|
+
role="switch"
|
|
125
|
+
aria-checked={on}
|
|
126
|
+
onClick={alternar}
|
|
127
|
+
disabled={disabled}
|
|
128
|
+
className={`flex w-full cursor-pointer items-center gap-[14px] px-[18px] py-[14px] text-left disabled:cursor-default disabled:opacity-60 ${
|
|
129
|
+
suelta ? "rounded-[16px] border border-borde-sutil bg-tarjeta" : "border-b border-divisor bg-transparent last:border-b-0"
|
|
130
|
+
}`}
|
|
131
|
+
>
|
|
132
|
+
<span className="flex flex-1 flex-col gap-[3px]">
|
|
133
|
+
<span className="text-[14.5px] text-tinta">{titulo}</span>
|
|
134
|
+
{sub && <span className="text-[13px] leading-[1.4] text-tinta-3">{sub}</span>}
|
|
135
|
+
</span>
|
|
136
|
+
<Pista on={on} />
|
|
137
|
+
</button>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Control segmentado: fondo hundida, la opción activa en tarjeta con sombra mínima.
|
|
142
|
+
* Con `href` en las opciones se dibuja como navegación (enlaces de next/link con aria-current) en vez de pestañas;
|
|
143
|
+
* sirve para filtros que viven en la URL (?estado=…) y funcionan sin JS. */
|
|
144
|
+
export function Segmentado<T extends string>({
|
|
145
|
+
opciones,
|
|
146
|
+
valor,
|
|
147
|
+
elegir,
|
|
148
|
+
etiqueta,
|
|
149
|
+
alto = 34,
|
|
150
|
+
ancho,
|
|
151
|
+
colorActivo,
|
|
152
|
+
className = "",
|
|
153
|
+
}: {
|
|
154
|
+
opciones: { v: T; txt: ReactNode; disabled?: boolean; href?: string }[];
|
|
155
|
+
valor: T;
|
|
156
|
+
/** Obligatorio salvo que todas las opciones tengan `href`. */
|
|
157
|
+
elegir?: (v: T) => void;
|
|
158
|
+
/** Nombre accesible del grupo. */
|
|
159
|
+
etiqueta: string;
|
|
160
|
+
alto?: 30 | 32 | 34;
|
|
161
|
+
/** "igual" = todas del mismo ancho. */
|
|
162
|
+
ancho?: "igual";
|
|
163
|
+
colorActivo?: (v: T) => string;
|
|
164
|
+
className?: string;
|
|
165
|
+
}) {
|
|
166
|
+
const h = { 30: "h-[30px]", 32: "h-8", 34: "h-[34px]" }[alto];
|
|
167
|
+
const enlaces = opciones.some((o) => o.href !== undefined);
|
|
168
|
+
const caja = `flex rounded-[10px] bg-hundida p-[3px] ${className}`;
|
|
169
|
+
const clase = (on: boolean, v: T) =>
|
|
170
|
+
`${h} cursor-pointer whitespace-nowrap rounded-[8px] font-medium disabled:cursor-default disabled:opacity-45 ${
|
|
171
|
+
ancho === "igual" ? "flex-1" : alto === 34 ? "px-4" : "px-3"
|
|
172
|
+
} ${alto === 34 ? "text-[13.5px]" : "text-[13px]"} ${on ? `bg-tarjeta shadow-plana ${colorActivo?.(v) ?? "text-tinta"}` : "bg-transparent text-tinta-3"}`;
|
|
173
|
+
|
|
174
|
+
if (enlaces) {
|
|
175
|
+
return (
|
|
176
|
+
<nav aria-label={etiqueta} className={caja}>
|
|
177
|
+
{opciones.map((o) => {
|
|
178
|
+
const on = o.v === valor;
|
|
179
|
+
const c = `${clase(on, o.v)} inline-flex items-center justify-center no-underline`;
|
|
180
|
+
if (o.href === undefined || o.disabled)
|
|
181
|
+
return (
|
|
182
|
+
<span key={o.v} aria-disabled={o.disabled || undefined} aria-current={on ? "page" : undefined} className={`${c} ${o.disabled ? "cursor-default opacity-45" : ""}`}>
|
|
183
|
+
{o.txt}
|
|
184
|
+
</span>
|
|
185
|
+
);
|
|
186
|
+
return (
|
|
187
|
+
<Link key={o.v} href={o.href} aria-current={on ? "page" : undefined} onClick={() => elegir?.(o.v)} className={c}>
|
|
188
|
+
{o.txt}
|
|
189
|
+
</Link>
|
|
190
|
+
);
|
|
191
|
+
})}
|
|
192
|
+
</nav>
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return (
|
|
197
|
+
<div role="tablist" aria-label={etiqueta} className={caja}>
|
|
198
|
+
{opciones.map((o) => {
|
|
199
|
+
const on = o.v === valor;
|
|
200
|
+
return (
|
|
201
|
+
<button
|
|
202
|
+
key={o.v}
|
|
203
|
+
type="button"
|
|
204
|
+
role="tab"
|
|
205
|
+
aria-selected={on}
|
|
206
|
+
disabled={o.disabled}
|
|
207
|
+
onClick={() => !o.disabled && elegir?.(o.v)}
|
|
208
|
+
className={clase(on, o.v)}
|
|
209
|
+
>
|
|
210
|
+
{o.txt}
|
|
211
|
+
</button>
|
|
212
|
+
);
|
|
213
|
+
})}
|
|
214
|
+
</div>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Interruptor suelto (sin fila): 40×24 con la misma Pista; dentro de un área tocable de 44 de alto en teléfono. */
|
|
219
|
+
export function Interruptor({
|
|
220
|
+
activo,
|
|
221
|
+
onCambio,
|
|
222
|
+
etiqueta,
|
|
223
|
+
deshabilitado,
|
|
224
|
+
className = "",
|
|
225
|
+
}: {
|
|
226
|
+
activo: boolean;
|
|
227
|
+
onCambio: (activo: boolean) => void;
|
|
228
|
+
/** Nombre accesible (lo que enciende). */
|
|
229
|
+
etiqueta: string;
|
|
230
|
+
deshabilitado?: boolean;
|
|
231
|
+
className?: string;
|
|
232
|
+
}) {
|
|
233
|
+
return (
|
|
234
|
+
<button
|
|
235
|
+
type="button"
|
|
236
|
+
role="switch"
|
|
237
|
+
aria-checked={activo}
|
|
238
|
+
aria-label={etiqueta}
|
|
239
|
+
title={etiqueta}
|
|
240
|
+
disabled={deshabilitado}
|
|
241
|
+
onClick={() => onCambio(!activo)}
|
|
242
|
+
className={`inline-flex flex-none cursor-pointer items-center rounded-pildora bg-transparent p-0 disabled:cursor-default disabled:opacity-50 max-[760px]:min-h-11 ${className}`}
|
|
243
|
+
>
|
|
244
|
+
<Pista on={activo} />
|
|
245
|
+
</button>
|
|
246
|
+
);
|
|
247
|
+
}
|