a2host/.agents/skills/cpic-ui-design-and-templates/references/page-templates.md

8.2 KiB

Recetas y Plantillas de Componentes y Páginas - CPIC Conecta

Este archivo provee recetas completas listas para copiar y pegar de los componentes y páginas clave de CPIC Conecta.


1. Plantilla Astro Base (ScrollLayout.astro)

Utilizada para envolver cualquier página en Astro con detección instantánea de tema oscuro/claro y precarga de fuentes e iconos:

---
import '../styles/global.css';
import '@fortawesome/fontawesome-free/css/all.min.css';

export interface Props {
  title?: string;
  description?: string;
  lang?: string;
}

const {
  title = "CPIC - Conecta",
  description = "Asistente Virtual e Intranet del CPIC - SENA",
  lang = "es"
} = Astro.props;
---

<!DOCTYPE html>
<html lang={lang}>
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>{title}</title>
  <meta name="description" content={description} />
  <meta name="theme-color" content="#00FF00" />
  <link rel="icon" type="image/png" href="/Logo.png" />
  <link rel="preload" as="image" href="/background.webp" fetchpriority="high" />
  <script is:inline>
    (function () {
      try {
        var theme = localStorage.getItem('cpic_theme') || 'dark';
        document.documentElement.setAttribute('data-theme', theme);
        if (theme === 'dark') document.documentElement.classList.add('dark');
        else document.documentElement.classList.remove('dark');
      } catch (e) {
        document.documentElement.classList.add('dark');
      }
    })();
  </script>
</head>
<body class="scroll-page">
  <slot />

  {/* Page transition loader */}
  <div id="page-loader">
    <div style="position:relative;display:flex;align-items:center;justify-content:center">
      <div class="loader-ring"></div>
      <div class="loader-ring inner"></div>
      <div class="loader-logo"></div>
    </div>
    <div class="loader-text">Cargando&hellip;</div>
  </div>
</body>
</html>

2. Componente de Entrada de Cristal (GlassInput.jsx)

Estándar para formularios en modo oscuro y claro:

import React from "react";

export const GLASS_INPUT_CLASS =
  "w-full px-4 py-3 bg-white/60 dark:bg-black/40 backdrop-blur-xl border border-black/10 dark:border-white/12 rounded-2xl text-gray-900 dark:text-white placeholder-gray-400 dark:placeholder-white/30 focus:outline-none focus:border-[#39A900] focus:ring-2 focus:ring-[#39A900]/20 focus:bg-white/80 dark:focus:bg-black/60 shadow-[inset_0_1px_2px_rgba(0,0,0,0.05)] transition-all text-sm";

export const GlassInput = React.forwardRef(function GlassInput(
  { type = "text", value, onChange, placeholder, disabled, icon, ...props },
  ref
) {
  return (
    <div className="relative w-full flex items-center">
      {icon && (
        <span className="absolute left-4 text-gray-400 dark:text-white/40 text-sm pointer-events-none">
          <i className={`fa-solid ${icon}`} />
        </span>
      )}
      <input
        ref={ref}
        type={type}
        value={value}
        onChange={onChange}
        placeholder={placeholder}
        disabled={disabled}
        className={`${GLASS_INPUT_CLASS} ${icon ? "pl-11" : ""}`}
        {...props}
      />
    </div>
  );
});

3. Botones Estándar del Sistema

// 1. Botón Primario Institucional (Acento Lima con sombra resplandeciente)
<button
  type="button"
  className="px-4 py-2.5 rounded-2xl bg-lime text-black font-extrabold text-xs sm:text-sm flex items-center gap-2 shadow-[0_4px_16px_rgba(132,204,22,0.35)] hover:scale-[1.02] active:scale-[0.98] transition-all cursor-pointer"
>
  <i className="fa-solid fa-check text-xs" />
  <span>Guardar Cambios</span>
</button>

// 2. Botón Secundario (Vidrio Fantasma)
<button
  type="button"
  className="px-4 py-2.5 rounded-2xl bg-black/5 dark:bg-white/8 text-gray-700 dark:text-white/80 font-semibold text-xs sm:text-sm border border-black/8 dark:border-white/10 hover:bg-black/10 dark:hover:bg-white/12 active:scale-[0.98] transition-all cursor-pointer"
>
  <span>Cancelar</span>
</button>

// 3. Botón de Peligro / Eliminar
<button
  type="button"
  className="px-4 py-2.5 rounded-2xl bg-red-500/10 text-red-600 dark:text-red-400 font-semibold text-xs sm:text-sm border border-red-500/25 hover:bg-red-500/20 active:scale-[0.98] transition-all cursor-pointer"
>
  <i className="fa-solid fa-trash-can text-xs" />
  <span>Eliminar</span>
</button>

4. Modal de Confirmación Estándar (ConfirmModal.jsx)

Modal con elevación Tier 3, animación elástica y soporte para cierre con tecla Escape:

import React, { useEffect } from "react";
import { motion, AnimatePresence } from "framer-motion";

export default function ConfirmModal({
  isOpen,
  title,
  message,
  confirmText = "Confirmar",
  cancelText = "Cancelar",
  isDanger = false,
  onConfirm,
  onCancel
}) {
  useEffect(() => {
    const handleKeyDown = (e) => {
      if (e.key === "Escape" && isOpen) onCancel();
    };
    window.addEventListener("keydown", handleKeyDown);
    return () => window.removeEventListener("keydown", handleKeyDown);
  }, [isOpen, onCancel]);

  return (
    <AnimatePresence>
      {isOpen && (
        <div className="fixed inset-0 z-50 flex items-center justify-center p-4">
          {/* Fondo oscuro con desenfoque */}
          <motion.div
            initial={{ opacity: 0 }}
            animate={{ opacity: 1 }}
            exit={{ opacity: 0 }}
            onClick={onCancel}
            className="fixed inset-0 bg-black/70 backdrop-blur-md"
          />

          {/* Tarjeta del diálogo */}
          <motion.div
            initial={{ opacity: 0, scale: 0.95, y: 15 }}
            animate={{ opacity: 1, scale: 1, y: 0 }}
            exit={{ opacity: 0, scale: 0.95, y: 15 }}
            className="relative w-full max-w-md bg-white/95 dark:bg-[rgba(15,28,15,0.95)] backdrop-blur-3xl border border-black/10 dark:border-lime/25 rounded-3xl p-6 shadow-[0_20px_50px_rgba(0,0,0,0.4)] z-10"
          >
            <div className="flex items-center gap-3 mb-4">
              <div
                className={`w-10 h-10 rounded-2xl flex items-center justify-center text-lg ${
                  isDanger
                    ? "bg-red-500/10 text-red-500 border border-red-500/25"
                    : "bg-lime/15 text-lime-deep dark:text-lime border border-lime/30"
                }`}
              >
                <i className={`fa-solid ${isDanger ? "fa-triangle-exclamation" : "fa-circle-question"}`} />
              </div>
              <h3 className="text-base font-bold text-gray-900 dark:text-white">{title}</h3>
            </div>

            <p className="text-xs sm:text-sm text-gray-600 dark:text-white/70 leading-relaxed mb-6">
              {message}
            </p>

            <div className="flex items-center justify-end gap-2.5">
              <button
                type="button"
                onClick={onCancel}
                className="px-4 py-2 rounded-xl text-xs font-semibold text-gray-600 dark:text-white/70 hover:bg-black/5 dark:hover:bg-white/8 transition-colors"
              >
                {cancelText}
              </button>
              <button
                type="button"
                onClick={onConfirm}
                className={`px-4 py-2 rounded-xl text-xs font-bold transition-all ${
                  isDanger
                    ? "bg-red-500 text-white shadow-md hover:bg-red-600 active:scale-95"
                    : "bg-lime text-black shadow-md hover:scale-105 active:scale-95"
                }`}
              >
                {confirmText}
              </button>
            </div>
          </motion.div>
        </div>
      )}
    </AnimatePresence>
  );
}

5. Esqueletos de Carga Shimmer (Skeleton.jsx)

Para evitar saltos de diseño (Cumulative Layout Shift):

export function SkeletonBlock({ className = "h-10 w-full" }) {
  return (
    <div
      className={`animate-pulse bg-black/5 dark:bg-white/5 rounded-xl border border-black/4 dark:border-white/6 ${className}`}
    />
  );
}

export function TableRowSkeleton({ cols = 5 }) {
  return (
    <tr className="border-b border-black/6 dark:border-white/6">
      {Array.from({ length: cols }).map((_, idx) => (
        <td key={idx} className="p-4">
          <SkeletonBlock className="h-4 w-3/4" />
        </td>
      ))}
    </tr>
  );
}