'use client' import { pageGridClass } from '@/components/layout/FeaturePage' import Link from 'next/link' import { useCallback, useEffect, useId, useRef, useState } from 'react' import { createPortal } from 'react-dom' // `m`, not `motion`: the app renders inside a strict `LazyMotion`, which // rejects the full component outright — the learning dashboard crashed on its // first card instead of animating it (#1549). import { AnimatePresence, m as motion, useReducedMotion, type Transition } from 'framer-motion' import { ArrowUpRight, ArrowRight, Check, X } from 'lucide-react' import { useTranslation } from 'react-i18next' type LearningKind = LearningSurface['kind'] import { LEARNING_SURFACES, type LearningSurface } from './surfaces' const FOCUSABLE = 'a[href], input:not([disabled]), select:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex="-1"])' const tileClass = (accent: string) => `flex h-11 w-11 shrink-0 items-center justify-center rounded-[14px] ${accent}` const titleClass = 'text-[16px] font-semibold tracking-[-0.02em]' /** The whole card owns the shared transform; child layout projection keeps text undistorted. */ export function LearningWays() { const { t } = useTranslation() const reduceMotion = useReducedMotion() const [openKind, setOpenKind] = useState(null) const triggerRef = useRef(null) const id = useId() const sharedId = (part: string, kind: LearningKind) => `${id}-${kind}-${part}` const close = useCallback(() => setOpenKind(null), []) const open = LEARNING_SURFACES.find(surface => surface.kind === openKind) const spring: Transition = reduceMotion ? { duration: 0 } : { type: 'spring', stiffness: 340, damping: 34, mass: 0.9 } return ( <>

{t('Ways to learn')}

{LEARNING_SURFACES.map((surface, index) => { const opened = openKind === surface.kind return ( {/* Entry staggering stays outside the card-to-dialog projection so opening and returning never inherit an entrance delay. */} ) })}
{open && ( )} ) } function WayPanel({ surface, id, sharedId, spring, reduceMotion, close, triggerRef, }: { surface: LearningSurface id: string sharedId: (part: string, kind: LearningKind) => string spring: Transition reduceMotion: boolean close: () => void triggerRef: React.RefObject }) { const { t } = useTranslation() const rootRef = useRef(null) const panelRef = useRef(null) const fade: Transition = { duration: reduceMotion ? 0 : 0.2 } // Keep the page inert and its scroll position intact until the return animation finishes. useEffect(() => { const trigger = triggerRef.current const siblings = Array.from(document.body.children).filter( (node): node is HTMLElement => node instanceof HTMLElement && node !== rootRef.current ) const previous = siblings.map(node => node.inert) siblings.forEach(node => { node.inert = true }) const overflow = document.body.style.overflow document.body.style.overflow = 'hidden' panelRef.current?.focus({ preventScroll: true }) return () => { siblings.forEach((node, index) => { node.inert = previous[index] }) document.body.style.overflow = overflow if (trigger?.isConnected) trigger.focus({ preventScroll: true }) } }, [triggerRef]) return createPortal( {/* The scrim must not fade the shared elements along with itself. */} , document.body ) }