From e4bdc9b3ef1b87dfd7893fa41ec7bed435c8664f Mon Sep 17 00:00:00 2001 From: Javiera Munita Date: Tue, 24 Nov 2026 14:52:14 -0300 Subject: [PATCH 1/2] feat(PDYE-2353): nuevo componente caja ruta de aprendizaje --- src/atoms/Icons/LearningPath.tsx | 23 +++ src/atoms/Icons/index.tsx | 1 + src/index.ts | 9 +- .../CourseList/Boxes/BoxLearningPath.tsx | 188 ++++++++++++++++++ .../LearningPath/PathCourseLink.tsx | 92 +++++++++ .../components/LearningPath/PathHeader.tsx | 48 +++++ .../components/LearningPath/PathProgress.tsx | 31 +++ src/organisms/CourseList/index.ts | 2 + src/organisms/CourseList/types.d.ts | 23 +++ .../SimpleCourseBox/SimpleCourseBox.tsx | 32 ++- 10 files changed, 443 insertions(+), 6 deletions(-) create mode 100644 src/atoms/Icons/LearningPath.tsx create mode 100644 src/organisms/CourseList/Boxes/BoxLearningPath.tsx create mode 100644 src/organisms/CourseList/components/LearningPath/PathCourseLink.tsx create mode 100644 src/organisms/CourseList/components/LearningPath/PathHeader.tsx create mode 100644 src/organisms/CourseList/components/LearningPath/PathProgress.tsx 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 */} +