refactor(frontend): extrae el lenguaje visual duplicado a theme.js compartido
Sin cambio visual ni de comportamiento — solo elimina la triplicación. - theme.js expone COLORS (unificada), FONT, SPACE, RADIUS y makeUI(flavor) con los componentes compartidos Btn/Card/Input/Badge/Field/Estado - 'flavor' (panel/becario/checada) reproduce las medidas exactas de cada página (escritorio vs móvil) para que se vea idéntico a hoy - los tres HTML cargan theme.js y usan makeUI en vez de sus defs locales; checada renombra su componente Big → Estado (compartido) - Dockerfile hornea theme.js para producción Verificado headless: transpila, monta sin throw y reproduce los estilos originales píxel por píxel (react-dom/server + asserts de estilo).
This commit is contained in:
1 parent
7307f7e591
commit
743440968b
5 files changed
+183
-116
No files matched your search
+1
-1
@@ -21,7 +21,7 @@ COPY --chown=node:node backend/src ./src
|
||||
# stat/leer los archivos; copiar con `--chmod=644 … /dir/` deja el propio
|
||||
# directorio en 0644 y nginx falla con "Permission denied". Por eso se fijan
|
||||
# los permisos explícitamente después del COPY.
|
||||
COPY frontend/checada.html frontend/panel.html frontend/becario.html /usr/share/nginx/html/
|
||||
COPY frontend/checada.html frontend/panel.html frontend/becario.html frontend/theme.js /usr/share/nginx/html/
|
||||
RUN chmod 755 /usr/share/nginx/html && chmod 644 /usr/share/nginx/html/*.html
|
||||
COPY --chmod=644 backend/nginx-default.conf /etc/nginx/http.d/default.conf
|
||||
COPY --chmod=755 backend/docker-entrypoint.sh /docker-entrypoint.sh
|
||||
|
||||
+4
-28
@@ -7,6 +7,7 @@
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.23.2/babel.min.js"></script>
|
||||
<script src="theme.js"></script>
|
||||
</head>
|
||||
<body style="margin:0;padding:0;">
|
||||
<div id="root"></div>
|
||||
@@ -29,12 +30,9 @@ async function apiFetch(path, options = {}) {
|
||||
return data;
|
||||
}
|
||||
|
||||
const COLORS = {
|
||||
bg: "#EEF1F4", surface: "#FFFFFF", ink: "#1F2933", inkSoft: "#616E7C",
|
||||
border: "#DDE2E7", primary: "#2A6FB0", success: "#2E7D5B", successBg: "#E7F3EC",
|
||||
warn: "#B7791F", warnBg: "#FBF2E1", danger: "#C0392B", dangerBg: "#FBEBE9", chip: "#F0F2F5",
|
||||
};
|
||||
const FONT = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
|
||||
// Base visual compartida (theme.js), ligada al flavor 'becario'.
|
||||
const { COLORS, FONT, SPACE, RADIUS, makeUI } = Theme;
|
||||
const { Btn, Card, Input, Badge, Field, Estado } = makeUI("becario");
|
||||
|
||||
function fmtDT(iso) {
|
||||
if (!iso) return "—";
|
||||
@@ -45,28 +43,6 @@ function fmtDT(iso) {
|
||||
const fmtHoras = (h) => `${(h ?? 0).toLocaleString("es-MX", { maximumFractionDigits: 1 })} h`;
|
||||
function localToIso(v) { return v ? new Date(v).toISOString() : null; }
|
||||
|
||||
const inputStyle = {
|
||||
width: "100%", padding: "12px 14px", borderRadius: "10px", border: `1px solid ${COLORS.border}`,
|
||||
fontSize: "16px", fontFamily: FONT, color: COLORS.ink, boxSizing: "border-box", outline: "none",
|
||||
};
|
||||
const Input = (p) => <input {...p} style={{ ...inputStyle, ...(p.style || {}) }} />;
|
||||
const Btn = ({ children, onClick, variant = "primary", disabled, type = "button" }) => {
|
||||
const V = { primary: COLORS.primary, success: COLORS.success, ghost: "transparent", danger: COLORS.danger }[variant];
|
||||
const ghost = variant === "ghost";
|
||||
return <button type={type} onClick={onClick} disabled={disabled} style={{
|
||||
width: "100%", padding: "13px", borderRadius: "10px", background: disabled ? COLORS.border : V,
|
||||
color: ghost ? COLORS.primary : "#fff", border: ghost ? `1px solid ${COLORS.border}` : "none",
|
||||
fontSize: "15px", fontWeight: 700, fontFamily: FONT, cursor: disabled ? "not-allowed" : "pointer",
|
||||
}}>{children}</button>;
|
||||
};
|
||||
const Card = ({ children, style }) => (
|
||||
<div style={{ background: COLORS.surface, borderRadius: "14px", border: `1px solid ${COLORS.border}`,
|
||||
padding: "18px", marginBottom: "14px", ...style }}>{children}</div>
|
||||
);
|
||||
const Badge = ({ children, tone }) => {
|
||||
const T = { pendiente: [COLORS.warnBg, COLORS.warn], activo: [COLORS.successBg, COLORS.success], baja: [COLORS.chip, COLORS.inkSoft] }[tone] || [COLORS.chip, COLORS.inkSoft];
|
||||
return <span style={{ background: T[0], color: T[1], padding: "3px 10px", borderRadius: "999px", fontSize: "12px", fontWeight: 700 }}>{children}</span>;
|
||||
};
|
||||
const ErrorBar = ({ error, onClose }) => !error ? null : (
|
||||
<div style={{ background: COLORS.dangerBg, color: COLORS.danger, padding: "10px 14px", borderRadius: "10px", fontSize: "14px", marginBottom: "12px", display: "flex", justifyContent: "space-between" }}>
|
||||
<span>⚠ {error}</span><span onClick={onClose} style={{ cursor: "pointer", fontWeight: 700 }}>✕</span>
|
||||
|
||||
+14
-37
@@ -7,12 +7,17 @@
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.23.2/babel.min.js"></script>
|
||||
<script src="theme.js"></script>
|
||||
</head>
|
||||
<body style="margin:0;padding:0;">
|
||||
<div id="root"></div>
|
||||
<script type="text/babel" data-presets="react">
|
||||
const { useState, useEffect } = React;
|
||||
|
||||
// Base visual compartida (theme.js), ligada al flavor 'checada'.
|
||||
const { COLORS, FONT, SPACE, RADIUS, makeUI } = Theme;
|
||||
const { Btn, Card, Input, Badge, Field, Estado } = makeUI("checada");
|
||||
|
||||
const API_BASE = `${window.location.origin}/api`;
|
||||
async function apiFetch(path, options = {}) {
|
||||
const res = await fetch(`${API_BASE}${path}`, {
|
||||
@@ -29,12 +34,6 @@ async function apiFetch(path, options = {}) {
|
||||
return data;
|
||||
}
|
||||
|
||||
const COLORS = {
|
||||
bg: "#EEF1F4", surface: "#FFFFFF", ink: "#1F2933", inkSoft: "#616E7C",
|
||||
border: "#DDE2E7", primary: "#2A6FB0", success: "#2E7D5B", successBg: "#E7F3EC",
|
||||
warn: "#B7791F", warnBg: "#FBF2E1", danger: "#C0392B", dangerBg: "#FBEBE9", chip: "#F0F2F5",
|
||||
};
|
||||
const FONT = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
|
||||
const fmtHoras = (h) => `${(h ?? 0).toLocaleString("es-MX", { maximumFractionDigits: 1 })} h`;
|
||||
const fmtHM = (iso) => (iso ? new Date(iso).toLocaleTimeString("es-MX", { timeZone: "America/Mexico_City", hour: "2-digit", minute: "2-digit" }) : "");
|
||||
|
||||
@@ -43,28 +42,6 @@ const Shell = ({ children }) => (
|
||||
<div style={{ width: "100%", maxWidth: "400px" }}>{children}</div>
|
||||
</div>
|
||||
);
|
||||
const Card = ({ children, style }) => (
|
||||
<div style={{ background: COLORS.surface, borderRadius: "16px", border: `1px solid ${COLORS.border}`, padding: "24px", ...style }}>{children}</div>
|
||||
);
|
||||
const inputStyle = { width: "100%", padding: "13px 14px", borderRadius: "10px", border: `1px solid ${COLORS.border}`, fontSize: "16px", fontFamily: FONT, color: COLORS.ink, boxSizing: "border-box", outline: "none" };
|
||||
const Input = (p) => <input {...p} style={{ ...inputStyle, ...(p.style || {}) }} />;
|
||||
const Btn = ({ children, onClick, variant = "primary", disabled, type = "button" }) => {
|
||||
const V = { primary: COLORS.primary, success: COLORS.success, ghost: "transparent" }[variant];
|
||||
const ghost = variant === "ghost";
|
||||
return <button type={type} onClick={onClick} disabled={disabled} style={{
|
||||
width: "100%", padding: "14px", borderRadius: "10px", background: disabled ? COLORS.border : V,
|
||||
color: ghost ? COLORS.primary : "#fff", border: ghost ? `1px solid ${COLORS.border}` : "none",
|
||||
fontSize: "16px", fontWeight: 700, fontFamily: FONT, cursor: disabled ? "not-allowed" : "pointer",
|
||||
}}>{children}</button>;
|
||||
};
|
||||
const Big = ({ emoji, title, sub, tone = COLORS.ink }) => (
|
||||
<Card style={{ textAlign: "center" }}>
|
||||
<div style={{ fontSize: "44px", marginBottom: "8px" }}>{emoji}</div>
|
||||
<h2 style={{ margin: "0 0 6px", color: tone, fontSize: "20px" }}>{title}</h2>
|
||||
{sub && <p style={{ margin: 0, color: COLORS.inkSoft, fontSize: "14px", lineHeight: 1.5 }}>{sub}</p>}
|
||||
</Card>
|
||||
);
|
||||
|
||||
// ═══════════════ Login inline (para no perder el token de la URL) ═══════════════
|
||||
function LoginInline({ onEntra }) {
|
||||
const [f, setF] = useState({ telefono: "", password: "" });
|
||||
@@ -135,29 +112,29 @@ function Checar({ token }) {
|
||||
// Errores de contexto / registro
|
||||
if (error && !resultado) {
|
||||
if (error.code === "BECARIO_NO_ACTIVO")
|
||||
return <Big emoji="⏳" title="Cuenta pendiente" tone={COLORS.warn} sub="Tu cuenta aún no está aprobada; no puedes checar todavía. Avisa a la supervisora." />;
|
||||
return <Estado emoji="⏳" title="Cuenta pendiente" tone={COLORS.warn} sub="Tu cuenta aún no está aprobada; no puedes checar todavía. Avisa a la supervisora." />;
|
||||
if (error.code === "TOKEN_VENCIDO" || error.code === "TOKEN_INVALIDO")
|
||||
return <Big emoji="⌛" title="El código expiró" tone={COLORS.warn} sub="Vuelve a acercar tu celular al chip para generar uno nuevo." />;
|
||||
return <Estado emoji="⌛" title="El código expiró" tone={COLORS.warn} sub="Vuelve a acercar tu celular al chip para generar uno nuevo." />;
|
||||
if (error.code === "TOKEN_YA_USADO")
|
||||
return <Big emoji="↩️" title="Código ya usado" sub="Ese código ya se utilizó. Acerca tu celular al chip de nuevo." />;
|
||||
return <Estado emoji="↩️" title="Código ya usado" sub="Ese código ya se utilizó. Acerca tu celular al chip de nuevo." />;
|
||||
// CONFLICTO_TIPO cae aquí como aviso, pero seguimos mostrando el formulario abajo.
|
||||
if (error.code !== "CONFLICTO_TIPO")
|
||||
return <Big emoji="⚠️" title="No se pudo registrar" tone={COLORS.danger} sub={error.message} />;
|
||||
return <Estado emoji="⚠️" title="No se pudo registrar" tone={COLORS.danger} sub={error.message} />;
|
||||
}
|
||||
|
||||
if (resultado) {
|
||||
// Token de un solo uso ya consumido: no es error del becario, es lo correcto.
|
||||
if (resultado.duplicada)
|
||||
return <Big emoji="🔄" title="Este código ya se usó" tone={COLORS.primary}
|
||||
return <Estado emoji="🔄" title="Este código ya se usó" tone={COLORS.primary}
|
||||
sub="Cada código del chip sirve una sola vez (así debe ser). Acerca de nuevo el celular al chip para registrar tu siguiente movimiento." />;
|
||||
// El título refleja el tipo REAL que aplicó el backend (toggle), no lo que
|
||||
// pulsó el becario — si hubo conflicto ya se reconfirmó antes de llegar aquí.
|
||||
const esEntrada = resultado.tipo === "entrada";
|
||||
const hora = fmtHM(resultado.ts);
|
||||
if (esEntrada)
|
||||
return <Big emoji="🟢" title={`Entrada registrada${hora ? ` a las ${hora}` : ""}`} tone={COLORS.success}
|
||||
return <Estado emoji="🟢" title={`Entrada registrada${hora ? ` a las ${hora}` : ""}`} tone={COLORS.success}
|
||||
sub={`Llevas ${fmtHoras(resultado.acumulado.total_horas)} de ${fmtHoras(resultado.acumulado.meta_horas)}. Cuando termines, vuelve a acercar el celular al chip para registrar tu salida.`} />;
|
||||
return <Big emoji="🔴" title={`Salida registrada${hora ? ` a las ${hora}` : ""}`} tone={COLORS.success}
|
||||
return <Estado emoji="🔴" title={`Salida registrada${hora ? ` a las ${hora}` : ""}`} tone={COLORS.success}
|
||||
sub={`Jornada cerrada. Llevas ${fmtHoras(resultado.acumulado.total_horas)} de ${fmtHoras(resultado.acumulado.meta_horas)} (${resultado.acumulado.porcentaje}%).`} />;
|
||||
}
|
||||
|
||||
@@ -196,10 +173,10 @@ function App() {
|
||||
|
||||
useEffect(() => { apiFetch("/becario/session").then(setSession).catch(() => setSession(null)); }, []);
|
||||
|
||||
if (cerrado) return <Shell><Big emoji="🚫" title="Checado cerrado" tone={COLORS.warn} sub="Estás fuera del horario permitido para checar. Intenta dentro de la ventana horaria." /></Shell>;
|
||||
if (cerrado) return <Shell><Estado emoji="🚫" title="Checado cerrado" tone={COLORS.warn} sub="Estás fuera del horario permitido para checar. Intenta dentro de la ventana horaria." /></Shell>;
|
||||
if (session === undefined) return <Shell><Card style={{ textAlign: "center", color: COLORS.inkSoft }}>Cargando…</Card></Shell>;
|
||||
if (!session) return <Shell><LoginInline onEntra={setSession} /></Shell>;
|
||||
if (!token) return <Shell><Big emoji="📲" title="Acerca tu celular al chip" sub="Para checar, escanea el chip NFC en la oficina de la supervisora." /></Shell>;
|
||||
if (!token) return <Shell><Estado emoji="📲" title="Acerca tu celular al chip" sub="Para checar, escanea el chip NFC en la oficina de la supervisora." /></Shell>;
|
||||
return <Shell><Checar token={token} /></Shell>;
|
||||
}
|
||||
ReactDOM.createRoot(document.getElementById("root")).render(<App />);
|
||||
|
||||
+5
-50
@@ -7,6 +7,7 @@
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.23.2/babel.min.js"></script>
|
||||
<script src="theme.js"></script>
|
||||
</head>
|
||||
<body style="margin:0;padding:0;">
|
||||
<div id="root"></div>
|
||||
@@ -36,13 +37,9 @@ async function apiFetch(path, options = {}) {
|
||||
return data;
|
||||
}
|
||||
|
||||
const COLORS = {
|
||||
bg: "#EEF1F4", surface: "#FFFFFF", ink: "#1F2933", inkSoft: "#616E7C",
|
||||
border: "#DDE2E7", primary: "#2A6FB0", primaryDark: "#1E4E7E",
|
||||
success: "#2E7D5B", successBg: "#E7F3EC", warn: "#B7791F", warnBg: "#FBF2E1",
|
||||
danger: "#C0392B", dangerBg: "#FBEBE9", chip: "#F0F2F5", accentBg: "#EAF2FA",
|
||||
};
|
||||
const FONT = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
|
||||
// Base visual compartida (theme.js), ligada al flavor 'panel'.
|
||||
const { COLORS, FONT, SPACE, RADIUS, makeUI } = Theme;
|
||||
const { Btn, Card, Input, Badge, Field, Estado } = makeUI("panel");
|
||||
|
||||
// ── Formato (presentación en America/Mexico_City, §7) ──
|
||||
function fmtDT(iso) {
|
||||
@@ -61,49 +58,7 @@ function isoToLocal(iso) {
|
||||
}
|
||||
function localToIso(v) { return v ? new Date(v).toISOString() : null; }
|
||||
|
||||
// ═══════════════════ UI primitivos ═══════════════════
|
||||
const Btn = ({ children, onClick, variant = "primary", disabled, size = "md", type = "button" }) => {
|
||||
const V = {
|
||||
primary: { bg: COLORS.primary, c: "#fff", bd: "none" },
|
||||
success: { bg: COLORS.success, c: "#fff", bd: "none" },
|
||||
danger: { bg: COLORS.danger, c: "#fff", bd: "none" },
|
||||
ghost: { bg: "transparent", c: COLORS.primary, bd: `1px solid ${COLORS.border}` },
|
||||
subtle: { bg: COLORS.chip, c: COLORS.ink, bd: "none" },
|
||||
}[variant];
|
||||
const pad = size === "sm" ? "6px 12px" : "10px 18px";
|
||||
return (
|
||||
<button type={type} onClick={onClick} disabled={disabled} style={{
|
||||
padding: pad, borderRadius: "8px", background: disabled ? COLORS.border : V.bg,
|
||||
color: disabled ? COLORS.inkSoft : V.c, border: V.bd, fontFamily: FONT,
|
||||
fontSize: size === "sm" ? "13px" : "14px", fontWeight: 600,
|
||||
cursor: disabled ? "not-allowed" : "pointer", transition: "opacity .15s",
|
||||
}}>{children}</button>
|
||||
);
|
||||
};
|
||||
const Card = ({ children, style }) => (
|
||||
<div style={{ background: COLORS.surface, borderRadius: "12px", border: `1px solid ${COLORS.border}`,
|
||||
padding: "20px", boxShadow: "0 1px 3px rgba(0,0,0,0.04)", ...style }}>{children}</div>
|
||||
);
|
||||
const Field = ({ label, children }) => (
|
||||
<label style={{ display: "block", marginBottom: "12px" }}>
|
||||
<span style={{ display: "block", fontSize: "13px", fontWeight: 600, color: COLORS.inkSoft, marginBottom: "5px" }}>{label}</span>
|
||||
{children}
|
||||
</label>
|
||||
);
|
||||
const inputStyle = {
|
||||
width: "100%", padding: "9px 11px", borderRadius: "8px", border: `1px solid ${COLORS.border}`,
|
||||
fontSize: "14px", fontFamily: FONT, color: COLORS.ink, boxSizing: "border-box", outline: "none",
|
||||
};
|
||||
const Input = (p) => <input {...p} style={{ ...inputStyle, ...(p.style || {}) }} />;
|
||||
const Badge = ({ children, tone = "chip" }) => {
|
||||
const T = {
|
||||
chip: { bg: COLORS.chip, c: COLORS.inkSoft }, success: { bg: COLORS.successBg, c: COLORS.success },
|
||||
warn: { bg: COLORS.warnBg, c: COLORS.warn }, danger: { bg: COLORS.dangerBg, c: COLORS.danger },
|
||||
primary: { bg: COLORS.accentBg, c: COLORS.primaryDark },
|
||||
}[tone];
|
||||
return <span style={{ background: T.bg, color: T.c, padding: "2px 9px", borderRadius: "999px",
|
||||
fontSize: "12px", fontWeight: 700, whiteSpace: "nowrap" }}>{children}</span>;
|
||||
};
|
||||
// ErrorBar y los helpers de tono son locales del panel (no compartidos).
|
||||
const ErrorBar = ({ error, onClose }) => !error ? null : (
|
||||
<div style={{ background: COLORS.dangerBg, color: COLORS.danger, padding: "10px 14px", borderRadius: "8px",
|
||||
fontSize: "14px", marginBottom: "14px", display: "flex", justifyContent: "space-between", alignItems: "center" }}>
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* theme.js — base visual compartida de las tres pantallas (panel/becario/checada).
|
||||
*
|
||||
* Sin build step: se carga como <script src="theme.js"> DESPUÉS de React/ReactDOM
|
||||
* y ANTES del <script type="text/babel"> de cada página. Expone window.Theme con:
|
||||
* - COLORS paleta unificada (base común de los tres + primaryDark/accentBg del panel)
|
||||
* - FONT stack tipográfico del sistema
|
||||
* - SPACE escala de espaciado (para el rediseño)
|
||||
* - RADIUS escala de radios
|
||||
* - makeUI(flavor) → { Btn, Card, Input, Badge, Field, Estado }
|
||||
*
|
||||
* Los componentes viven UNA sola vez aquí; makeUI(flavor) los liga a las medidas
|
||||
* exactas de cada página ('panel' escritorio, 'becario'/'checada' móvil) para que
|
||||
* el resultado se vea idéntico al de hoy. El rediseño se hace tocando este archivo.
|
||||
*/
|
||||
window.Theme = (function () {
|
||||
var COLORS = {
|
||||
bg: "#EEF1F4", surface: "#FFFFFF", ink: "#1F2933", inkSoft: "#616E7C",
|
||||
border: "#DDE2E7", primary: "#2A6FB0", primaryDark: "#1E4E7E",
|
||||
success: "#2E7D5B", successBg: "#E7F3EC", warn: "#B7791F", warnBg: "#FBF2E1",
|
||||
danger: "#C0392B", dangerBg: "#FBEBE9", chip: "#F0F2F5", accentBg: "#EAF2FA",
|
||||
};
|
||||
|
||||
var FONT = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
|
||||
|
||||
var SPACE = { none: "0", xs: "4px", sm: "8px", md: "12px", lg: "16px", xl: "20px", "2xl": "24px", "3xl": "32px" };
|
||||
var RADIUS = { sm: "8px", md: "10px", lg: "12px", xl: "14px", "2xl": "16px", pill: "999px" };
|
||||
|
||||
// Vocabulario de tonos de Badge, unión de los dos que usaban panel y becario.
|
||||
var TONES = {
|
||||
chip: { bg: COLORS.chip, color: COLORS.inkSoft },
|
||||
success: { bg: COLORS.successBg, color: COLORS.success },
|
||||
warn: { bg: COLORS.warnBg, color: COLORS.warn },
|
||||
danger: { bg: COLORS.dangerBg, color: COLORS.danger },
|
||||
primary: { bg: COLORS.accentBg, color: COLORS.primaryDark },
|
||||
pendiente: { bg: COLORS.warnBg, color: COLORS.warn },
|
||||
activo: { bg: COLORS.successBg, color: COLORS.success },
|
||||
baja: { bg: COLORS.chip, color: COLORS.inkSoft },
|
||||
};
|
||||
|
||||
// Medidas exactas por página (reproducen el look actual, píxel por píxel).
|
||||
var FLAVORS = {
|
||||
panel: {
|
||||
card: { radius: RADIUS.lg, pad: "20px", shadow: "0 1px 3px rgba(0,0,0,0.04)", mb: undefined },
|
||||
input: { pad: "9px 11px", radius: RADIUS.sm, font: "14px" },
|
||||
badge: { pad: "2px 9px", nowrap: true },
|
||||
btn: {
|
||||
block: false, weight: 600, radius: RADIUS.sm, disabledInk: true, transition: "opacity .15s",
|
||||
sizes: { sm: { pad: "6px 12px", font: "13px" }, md: { pad: "10px 18px", font: "14px" } },
|
||||
defaultSize: "md",
|
||||
},
|
||||
},
|
||||
becario: {
|
||||
card: { radius: RADIUS.xl, pad: "18px", shadow: undefined, mb: "14px" },
|
||||
input: { pad: "12px 14px", radius: RADIUS.md, font: "16px" },
|
||||
badge: { pad: "3px 10px", nowrap: false },
|
||||
btn: {
|
||||
block: true, weight: 700, radius: RADIUS.md, disabledInk: false, transition: undefined,
|
||||
sizes: { md: { pad: "13px", font: "15px" } }, defaultSize: "md",
|
||||
},
|
||||
},
|
||||
checada: {
|
||||
card: { radius: RADIUS["2xl"], pad: "24px", shadow: undefined, mb: undefined },
|
||||
input: { pad: "13px 14px", radius: RADIUS.md, font: "16px" },
|
||||
badge: { pad: "3px 10px", nowrap: false },
|
||||
btn: {
|
||||
block: true, weight: 700, radius: RADIUS.md, disabledInk: false, transition: undefined,
|
||||
sizes: { md: { pad: "14px", font: "16px" } }, defaultSize: "md",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
function btnVariant(v) {
|
||||
switch (v) {
|
||||
case "success": return { bg: COLORS.success, color: "#fff", border: "none" };
|
||||
case "danger": return { bg: COLORS.danger, color: "#fff", border: "none" };
|
||||
case "ghost": return { bg: "transparent", color: COLORS.primary, border: "1px solid " + COLORS.border };
|
||||
case "subtle": return { bg: COLORS.chip, color: COLORS.ink, border: "none" };
|
||||
default: return { bg: COLORS.primary, color: "#fff", border: "none" };
|
||||
}
|
||||
}
|
||||
|
||||
function makeUI(flavor) {
|
||||
var React = window.React;
|
||||
var h = React.createElement;
|
||||
var F = FLAVORS[flavor];
|
||||
if (!F) throw new Error("Theme.makeUI: flavor desconocido '" + flavor + "'");
|
||||
|
||||
function Card(props) {
|
||||
var base = {
|
||||
background: COLORS.surface, border: "1px solid " + COLORS.border,
|
||||
borderRadius: F.card.radius, padding: F.card.pad,
|
||||
boxShadow: F.card.shadow, marginBottom: F.card.mb,
|
||||
};
|
||||
return h("div", { style: Object.assign(base, props.style || {}) }, props.children);
|
||||
}
|
||||
|
||||
function Btn(props) {
|
||||
var v = btnVariant(props.variant);
|
||||
var size = F.btn.sizes[props.size || F.btn.defaultSize] || F.btn.sizes[F.btn.defaultSize];
|
||||
var disabled = props.disabled;
|
||||
var style = {
|
||||
padding: size.pad, borderRadius: F.btn.radius,
|
||||
background: disabled ? COLORS.border : v.bg,
|
||||
color: disabled && F.btn.disabledInk ? COLORS.inkSoft : v.color,
|
||||
border: v.border,
|
||||
fontFamily: FONT, fontSize: size.font, fontWeight: F.btn.weight,
|
||||
cursor: disabled ? "not-allowed" : "pointer",
|
||||
transition: F.btn.transition,
|
||||
};
|
||||
if (F.btn.block) style.width = "100%";
|
||||
return h("button", { type: props.type || "button", onClick: props.onClick, disabled: disabled, style: style }, props.children);
|
||||
}
|
||||
|
||||
function Input(props) {
|
||||
var rest = Object.assign({}, props);
|
||||
delete rest.style;
|
||||
var style = Object.assign({
|
||||
width: "100%", padding: F.input.pad, borderRadius: F.input.radius,
|
||||
border: "1px solid " + COLORS.border, fontSize: F.input.font,
|
||||
fontFamily: FONT, color: COLORS.ink, boxSizing: "border-box", outline: "none",
|
||||
}, props.style || {});
|
||||
return h("input", Object.assign(rest, { style: style }));
|
||||
}
|
||||
|
||||
function Badge(props) {
|
||||
var t = TONES[props.tone] || TONES.chip;
|
||||
var style = {
|
||||
background: t.bg, color: t.color, padding: F.badge.pad,
|
||||
borderRadius: RADIUS.pill, fontSize: "12px", fontWeight: 700,
|
||||
};
|
||||
if (F.badge.nowrap) style.whiteSpace = "nowrap";
|
||||
return h("span", { style: style }, props.children);
|
||||
}
|
||||
|
||||
function Field(props) {
|
||||
return h("label", { style: { display: "block", marginBottom: "12px" } },
|
||||
h("span", { style: { display: "block", fontSize: "13px", fontWeight: 600, color: COLORS.inkSoft, marginBottom: "5px" } }, props.label),
|
||||
props.children
|
||||
);
|
||||
}
|
||||
|
||||
// Patrón ícono + título + mensaje (+ botón opcional) de las pantallas de estado.
|
||||
// `tone` es un COLOR (no un tono de badge): tiñe el título.
|
||||
function Estado(props) {
|
||||
var kids = [
|
||||
h("div", { key: "e", style: { fontSize: "44px", marginBottom: "8px" } }, props.emoji),
|
||||
h("h2", { key: "t", style: { margin: "0 0 6px", color: props.tone || COLORS.ink, fontSize: "20px" } }, props.title),
|
||||
];
|
||||
if (props.sub) kids.push(h("p", { key: "s", style: { margin: 0, color: COLORS.inkSoft, fontSize: "14px", lineHeight: 1.5 } }, props.sub));
|
||||
if (props.action) kids.push(h("div", { key: "a", style: { marginTop: "16px" } }, props.action));
|
||||
return Card({ style: { textAlign: "center" }, children: kids });
|
||||
}
|
||||
|
||||
return { Btn: Btn, Card: Card, Input: Input, Badge: Badge, Field: Field, Estado: Estado };
|
||||
}
|
||||
|
||||
return { COLORS: COLORS, FONT: FONT, SPACE: SPACE, RADIUS: RADIUS, makeUI: makeUI };
|
||||
})();
|
||||
Reference in new issue
Block a user