diff --git a/ai/README.md b/ai/README.md index b341dd0b3..57b026bb7 100644 --- a/ai/README.md +++ b/ai/README.md @@ -4,7 +4,7 @@ Componentes React de eClass sobre Chakra UI 1.8. Funcionan desde React 16.8. Tod desde el paquete: ```tsx -import { ModalMultiple, ModalContent, ModalButtons, BtnPrimary, vars } from '@eclass/ui-kit' +import { ModalMultiple, ModalContent, ModalButtons, BtnPrimary, BoxLearningPath, vars } from '@eclass/ui-kit' ``` ## Reglas rápidas @@ -28,6 +28,8 @@ cómo reconocerlo en un diseño. | `BtnTertiary` | Acción de baja jerarquía: texto gris subrayado con ícono azul | [botones](components/botones.md) | | `BtnLink` | Acción con aspecto de enlace | [botones](components/botones.md) | | `Btn` | Botón base; preferir las variantes de arriba | [botones](components/botones.md) | +| `BoxLearningPath` | Caja para rutas de aprendizaje. | +[ruta-aprendizaje](components/ruta-aprendizaje.md) | | `Modal` | Modal con cabecera azul, título, contenido y botones | [modales](components/modales.md) | | `ModalMultiple` | Un solo modal que cambia entre contenido, alerta y carga | [modales](components/modales.md) | | `ModalContent` | Cuerpo de `Modal`/`ModalMultiple` | [modales](components/modales.md) | diff --git a/ai/components/ruta-aprendizaje.md b/ai/components/ruta-aprendizaje.md new file mode 100644 index 000000000..b6bb9dce1 --- /dev/null +++ b/ai/components/ruta-aprendizaje.md @@ -0,0 +1,55 @@ +# BoxLearningPath + +Exports: `BoxLearningPath`. +Tipos: `dist/organisms/CourseList/Boxes/BoxLearningPath.tsx` (`IBoxLearningPath`, no +exportado). + +## Cuándo usarlo + +Casos en que hay rutas de aprendizaje. + +## Ejemplo + +```tsx +import { BoxLearningPath } from '@eclass/ui-kit' + +export function RutaAprendizaje({ learningPath }: { courses: any[] }): JSX.Element { + return ( + <> + {learningPath.map((path, index) => ( + + ))} + + ) +} +``` + +## Props clave + +- `headerImage`, `title` y `coursesCount` (obligatorios): imagen, nombre y cantidad de cursos de la ruta. +- `progress`: porcentaje de avance (0-100). +- `start`: información sobre curso inicial o curso con última actividad. +- `buttonLabel`: texto del botón, por defecto: "Ver ruta de aprendizaje". +- `pathHref`: href para navegar a vista de ruta. +- `hasFinished`: valor booleano que indica si la ruta ha finalizado. + + +## Cómo se ve (para reconocerlo en un diseño) + +- Caja parecida a caja curso tradicional. +- Header con imagen y texto sobrepuesto con título de la ruta. +- Barra de progreso que muestra porcentaje de avance. +- Sección con fondo gris que indica curso por el cual comenzar o retomar, o alerta info de curso finalizado. diff --git a/src/atoms/Icons/LearningPath.tsx b/src/atoms/Icons/LearningPath.tsx new file mode 100644 index 000000000..0f4642f5e --- /dev/null +++ b/src/atoms/Icons/LearningPath.tsx @@ -0,0 +1,23 @@ +import { Base, BaseProps } from './Base' + +export function LearningPath(props: BaseProps): JSX.Element { + return ( + + + + + + + + + + + + + ) +} + +LearningPath.displayName = 'LearningPath' diff --git a/src/atoms/Icons/index.tsx b/src/atoms/Icons/index.tsx index 8448d3f91..5ce07ae0e 100644 --- a/src/atoms/Icons/index.tsx +++ b/src/atoms/Icons/index.tsx @@ -13,6 +13,7 @@ export * from './GoBack' export * from './Loader' export * from './MapIndicator' export * from './Multimedia' +export * from './LearningPath' export * from './Profile' export * from './Remote' export * from './Schedule' diff --git a/src/index.ts b/src/index.ts index 28f42ad1b..70cd88f37 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,7 +20,14 @@ export { UserWay } from './molecules/UserWay/UserWay' export { UserWayCookie } from './molecules/UserWay/UserWayCookie' // Organismos -export { CourseList, CourseStatus, dataFake, maxWidthCoursesList } from './organisms/CourseList' +export { + BoxLearningPath, + CourseList, + CourseStatus, + dataFake, + maxWidthCoursesList, +} from './organisms/CourseList' +export type { IBoxLearningPath, LearningPathStart } from './organisms/CourseList' export { Alert, FlashNotification, useFlashNotification } from './organisms/Alerts' export { Modal, diff --git a/src/organisms/CourseList/Boxes/BoxLearningPath.tsx b/src/organisms/CourseList/Boxes/BoxLearningPath.tsx new file mode 100644 index 000000000..513d27aa1 --- /dev/null +++ b/src/organisms/CourseList/Boxes/BoxLearningPath.tsx @@ -0,0 +1,188 @@ +import { + Box, + keyframes, + LinkBox, + LinkBoxProps, + LinkOverlay, + LinkOverlayProps, +} from '@chakra-ui/react' +import { useState } from 'react' + +import { vars } from '@theme' +import { PathHeader } from '../components/LearningPath/PathHeader' +import { PathProgress } from '../components/LearningPath/PathProgress' +import { PathCourseLink } from '../components/LearningPath/PathCourseLink' +import { IBoxLearningPath } from '../types' + +const StyledLinkBox = LinkBox as React.FC +const StyledLinkOverlay = LinkOverlay as React.FC + +// Desplazamiento de las tarjetas apiladas al bajar y al subir (atrás y adelante) +const BACK_PEEK = 8 +const FRONT_PEEK = 4 + +/** + * Subida de las tarjetas apiladas al hacer hover: bajan `peek` px y suben hasta + * `peek` px por sobre su posición inicial. Con `both`, la tarjeta de atrás espera su + * retraso en la posición inicial y al terminar ambas se quedan arriba. + */ +const stackBounce = (peek: number): string => keyframes` + 0% { transform: translateY(0); } + 40% { transform: translateY(${peek}px); } + 100% { transform: translateY(-${peek}px); } +` + +/** Bajada de las tarjetas apiladas a su posición inicial al salir el cursor */ +const stackDrop = (peek: number): string => keyframes` + from { transform: translateY(-${peek}px); } + to { transform: translateY(0); } +` + +const stackAnimations = { + back: { + rise: `${stackBounce(BACK_PEEK)} 680ms ease-in-out 90ms both`, + drop: `${stackDrop(BACK_PEEK)} 300ms ease-in-out both`, + }, + front: { + rise: `${stackBounce(FRONT_PEEK)} 680ms ease-in-out both`, + drop: `${stackDrop(FRONT_PEEK)} 300ms ease-in-out both`, + }, +} + +/** + * Fases de las tarjetas apiladas: + * - `rest`: en su posición inicial (sin animación). + * - `rising`: animación de subida en curso; siempre se completa, aunque el cursor salga. + * - `raised`: subida terminada y el cursor sigue en la caja; se quedan arriba. + * - `dropping`: bajando o ya abajo tras salir el cursor. + */ +type StackPhase = 'rest' | 'rising' | 'raised' | 'dropping' + +/** Animación CSS de una tarjeta apilada según la fase */ +const stackAnimation = ( + phase: StackPhase, + animations: { rise: string; drop: string } +): string | undefined => { + if (phase === 'rising' || phase === 'raised') return animations.rise + if (phase === 'dropping') return animations.drop + return undefined +} + +export const BoxLearningPath = ({ + headerImage, + title, + coursesCount, + progress = 0, + start, + buttonLabel = 'Ver ruta de aprendizaje', + pathHref, + hasFinished = false, +}: IBoxLearningPath): JSX.Element => { + const safeProgress = Math.min(100, Math.max(0, progress)) + const [isHovered, setIsHovered] = useState(false) + const [stackPhase, setStackPhase] = useState('rest') + + return ( + { + setIsHovered(true) + if (stackPhase === 'rest' || stackPhase === 'dropping') setStackPhase('rising') + }} + onMouseLeave={() => { + setIsHovered(false) + // Si la subida sigue en curso, la bajada parte en onAnimationEnd + if (stackPhase === 'raised') setStackPhase('dropping') + }} + > + {/* Efecto de tarjetas apiladas detrás; rebotan al pasar el mouse por la caja */} +