@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.
@@ -0,0 +1,185 @@
1
+ "use client";
2
+
3
+ import type { LucideIcon } from "lucide-react";
4
+ import type { AnchorHTMLAttributes, ButtonHTMLAttributes, ReactNode } from "react";
5
+
6
+ /* Piezas del sistema de diseño con los valores del rediseño v4 de WhatsApp (el más pulido).
7
+ Íconos: se pasan como componente de lucide-react importado por nombre (icono={Plus}), así cada
8
+ módulo solo carga los que usa. */
9
+
10
+ type BotonBase = {
11
+ children: ReactNode;
12
+ variante?: "primario" | "secundario" | "destructivo" | "fantasma";
13
+ icono?: LucideIcon;
14
+ /** 32–36: módulos (v4 de WhatsApp). 38–42: los del portal (más padding y texto). */
15
+ alto?: 32 | 34 | 36 | 38 | 40 | 42;
16
+ className?: string;
17
+ };
18
+
19
+ type BotonProps =
20
+ | (BotonBase & Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children" | "className"> & { href?: undefined })
21
+ | (BotonBase & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "children" | "className"> & { href: string });
22
+
23
+ const VARIANTE: Record<NonNullable<BotonBase["variante"]>, string> = {
24
+ primario: "border-0 bg-tinta font-semibold text-sobre-tinta hover:opacity-90",
25
+ secundario: "border border-borde-fuerte bg-tarjeta text-tinta-2 hover:bg-sutil",
26
+ // En oscuro, suspendido-tinta es rosa (#f0908f) y el blanco no se lee: ahí va el rojo validado #d03b3b (6,6:1).
27
+ destructivo: "border-0 bg-suspendido-tinta font-semibold text-blanco hover:opacity-90 dark:bg-suspendido",
28
+ fantasma: "border-0 bg-transparent text-tinta-2 hover:bg-hundida",
29
+ };
30
+
31
+ const ALTO = {
32
+ 32: "h-8 px-[15px] text-[13px]",
33
+ 34: "h-[34px] px-[15px] text-[13px]",
34
+ 36: "h-9 px-[15px] text-[13px]",
35
+ 38: "h-[38px] px-4 text-[13.5px]",
36
+ 40: "h-10 px-[18px] text-[14px]",
37
+ 42: "h-[42px] px-5 text-[14.5px]",
38
+ } as const;
39
+
40
+ /** Con `href` se dibuja como enlace (antes BotonEnlace del portal). */
41
+ export function Boton(props: BotonProps) {
42
+ const { children, variante = "secundario", icono: Glifo, alto = 36, className = "" } = props;
43
+ 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}`;
44
+ const glifo = Glifo && <Glifo width={15} height={15} strokeWidth={1.75} aria-hidden="true" style={{ flex: "none" }} />;
45
+ if (props.href !== undefined) {
46
+ const { children: _c, variante: _v, icono: _i, alto: _a, className: _k, ...resto } = props;
47
+ return (
48
+ <a {...resto} className={clase}>
49
+ {glifo}
50
+ {children}
51
+ </a>
52
+ );
53
+ }
54
+ const { children: _c, variante: _v, icono: _i, alto: _a, className: _k, type = "button", ...resto } = props;
55
+ return (
56
+ <button type={type} {...resto} className={clase}>
57
+ {glifo}
58
+ {children}
59
+ </button>
60
+ );
61
+ }
62
+
63
+ /** Botón de solo ícono, 44×44 (objetivo táctil mínimo). `titulo` es obligatorio: es su nombre accesible. */
64
+ export function BotonIcono({
65
+ icono: Glifo,
66
+ titulo,
67
+ activo,
68
+ size = 20,
69
+ redondo,
70
+ expandido,
71
+ className = "",
72
+ ...resto
73
+ }: Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children"> & {
74
+ icono: LucideIcon;
75
+ titulo: string;
76
+ activo?: boolean;
77
+ size?: number;
78
+ redondo?: boolean;
79
+ expandido?: boolean;
80
+ }) {
81
+ return (
82
+ <button
83
+ type="button"
84
+ title={titulo}
85
+ aria-label={titulo}
86
+ aria-expanded={expandido}
87
+ {...resto}
88
+ 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}`}
89
+ >
90
+ <Glifo width={size} height={size} strokeWidth={1.75} aria-hidden="true" />
91
+ </button>
92
+ );
93
+ }
94
+
95
+ /** Interruptor 40×24: pista de acento (encendido) o borde fuerte; perilla blanca 18. Solo visual. */
96
+ export function Pista({ on }: { on: boolean }) {
97
+ return (
98
+ <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"}`}>
99
+ <span className="size-[18px] rounded-full bg-blanco shadow-[0_1px_2px_rgba(32,40,38,.2)]" />
100
+ </span>
101
+ );
102
+ }
103
+
104
+ /** Fila con título, explicación e interruptor (Ajustes). `suelta` = tarjeta propia en vez de fila dentro de TarjetaFilas. */
105
+ export function FilaInterruptor({
106
+ titulo,
107
+ sub,
108
+ on,
109
+ alternar,
110
+ suelta,
111
+ disabled,
112
+ }: {
113
+ titulo: ReactNode;
114
+ sub?: ReactNode;
115
+ on: boolean;
116
+ alternar: () => void;
117
+ suelta?: boolean;
118
+ disabled?: boolean;
119
+ }) {
120
+ return (
121
+ <button
122
+ type="button"
123
+ role="switch"
124
+ aria-checked={on}
125
+ onClick={alternar}
126
+ disabled={disabled}
127
+ className={`flex w-full cursor-pointer items-center gap-[14px] px-[18px] py-[14px] text-left disabled:cursor-default disabled:opacity-60 ${
128
+ suelta ? "rounded-[16px] border border-borde-sutil bg-tarjeta" : "border-b border-divisor bg-transparent last:border-b-0"
129
+ }`}
130
+ >
131
+ <span className="flex flex-1 flex-col gap-[3px]">
132
+ <span className="text-[14.5px] text-tinta">{titulo}</span>
133
+ {sub && <span className="text-[13px] leading-[1.4] text-tinta-3">{sub}</span>}
134
+ </span>
135
+ <Pista on={on} />
136
+ </button>
137
+ );
138
+ }
139
+
140
+ /** Control segmentado: fondo hundida, la opción activa en tarjeta con sombra mínima. */
141
+ export function Segmentado<T extends string>({
142
+ opciones,
143
+ valor,
144
+ elegir,
145
+ etiqueta,
146
+ alto = 34,
147
+ ancho,
148
+ colorActivo,
149
+ className = "",
150
+ }: {
151
+ opciones: { v: T; txt: ReactNode; disabled?: boolean }[];
152
+ valor: T;
153
+ elegir: (v: T) => void;
154
+ /** Nombre accesible del grupo. */
155
+ etiqueta: string;
156
+ alto?: 30 | 32 | 34;
157
+ /** "igual" = todas del mismo ancho. */
158
+ ancho?: "igual";
159
+ colorActivo?: (v: T) => string;
160
+ className?: string;
161
+ }) {
162
+ const h = { 30: "h-[30px]", 32: "h-8", 34: "h-[34px]" }[alto];
163
+ return (
164
+ <div role="tablist" aria-label={etiqueta} className={`flex rounded-[10px] bg-hundida p-[3px] ${className}`}>
165
+ {opciones.map((o) => {
166
+ const on = o.v === valor;
167
+ return (
168
+ <button
169
+ key={o.v}
170
+ type="button"
171
+ role="tab"
172
+ aria-selected={on}
173
+ disabled={o.disabled}
174
+ onClick={() => !o.disabled && elegir(o.v)}
175
+ className={`${h} cursor-pointer whitespace-nowrap rounded-[8px] font-medium disabled:cursor-default disabled:opacity-45 ${
176
+ ancho === "igual" ? "flex-1" : alto === 34 ? "px-4" : "px-3"
177
+ } ${alto === 34 ? "text-[13.5px]" : "text-[13px]"} ${on ? `bg-tarjeta shadow-plana ${colorActivo?.(o.v) ?? "text-tinta"}` : "bg-transparent text-tinta-3"}`}
178
+ >
179
+ {o.txt}
180
+ </button>
181
+ );
182
+ })}
183
+ </div>
184
+ );
185
+ }