feat: implement immersive routes with Large Title component
- Added Large Title component to manage immersive screen headers. - Created ImmersiveBarProvider to handle the sticky bar for immersive routes. - Updated RootLayout to conditionally render Header based on immersive routes. - Modified Sidebar to adjust its position and height in immersive mode. - Integrated Large Title in ClassAttendanceView and AnalyticsView for consistent header display. - Updated GroupHeader to use Large Title for better layout management. - Implemented isImmersiveRoute function to determine immersive routes. - Added tests for immersive route detection.
This commit is contained in:
82
apps/web/src/components/layout/LargeTitle.tsx
Normal file
82
apps/web/src/components/layout/LargeTitle.tsx
Normal file
@@ -0,0 +1,82 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import { useImmersiveBarHost } from '../../context/ImmersiveBarProvider'
|
||||
import { useLargeTitleCollapse } from '../../hooks/useLargeTitleCollapse'
|
||||
|
||||
type LargeTitleProps = {
|
||||
/** Texto del título. Es el mismo en el grande y en el de la barra: el `h1`
|
||||
* real es el grande, el de la barra es un duplicado visual. */
|
||||
title: string
|
||||
/** Acción a la izquierda de la barra. En desktop es el link "volver" que
|
||||
* antes vivía en el cuerpo de la pantalla; en mobile se oculta. */
|
||||
leading?: ReactNode
|
||||
/** Contexto que no puede desaparecer al scrollear (ej. el contador de
|
||||
* presentes). Viaja a la barra y se funde con el título. */
|
||||
barTrailing?: ReactNode
|
||||
/** Metadatos bajo el título grande: badges, descripción. Se van al colapsar. */
|
||||
children?: ReactNode
|
||||
}
|
||||
|
||||
/**
|
||||
* Encabezado de pantalla con Large Title (patrón de iOS): el título arranca
|
||||
* grande y al scrollear se desliza debajo de la barra, que se opaca y recibe
|
||||
* el título en versión chica.
|
||||
*
|
||||
* El título grande es un bloque normal en el flujo; la barra vive en una caja
|
||||
* sticky que el layout monta arriba de `<main>` (ver `ImmersiveBarHost`), así
|
||||
* el contenido se desliza por debajo sin márgenes negativos ni `fixed` que
|
||||
* haya que compensar en desktop.
|
||||
*
|
||||
* El estado del scroll vive acá adentro a propósito: `children` llega como prop
|
||||
* ya construido, así React reutiliza los elementos y el subtree de abajo no se
|
||||
* re-renderiza en cada frame de scroll.
|
||||
*/
|
||||
export function LargeTitle({ title, leading, barTrailing, children }: LargeTitleProps) {
|
||||
const { titleRef, progress } = useLargeTitleCollapse()
|
||||
const barHost = useImmersiveBarHost()
|
||||
|
||||
return (
|
||||
<>
|
||||
{barHost
|
||||
? createPortal(
|
||||
<div className="relative flex h-full items-center gap-3 px-4 lg:px-0">
|
||||
{/* El fondo va en una capa propia: se opaca con el scroll mientras
|
||||
el título entra, y `leading` (el link "volver") no puede
|
||||
fundirse con él porque existe siempre. */}
|
||||
<div
|
||||
className="absolute inset-0 border-b border-border bg-background/80 backdrop-blur-md"
|
||||
style={{ opacity: progress }}
|
||||
/>
|
||||
{leading}
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="relative min-w-0 flex-1 truncate text-base font-semibold text-primary"
|
||||
style={{ opacity: progress, transform: `translateY(${(1 - progress) * 12}px)` }}
|
||||
>
|
||||
{title}
|
||||
</span>
|
||||
{barTrailing ? (
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="relative flex shrink-0 items-center"
|
||||
style={{ opacity: progress }}
|
||||
>
|
||||
{barTrailing}
|
||||
</span>
|
||||
) : null}
|
||||
</div>,
|
||||
barHost,
|
||||
)
|
||||
: null}
|
||||
|
||||
<h1
|
||||
ref={titleRef}
|
||||
className="text-balance text-[2.125rem] font-bold leading-[1.1] tracking-tight text-primary sm:text-[2.5rem]"
|
||||
>
|
||||
{title}
|
||||
</h1>
|
||||
|
||||
{children}
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,21 +1,39 @@
|
||||
import { useLocation } from '@tanstack/react-router'
|
||||
import type { ReactNode } from 'react'
|
||||
import { ImmersiveBarHost, ImmersiveBarProvider } from '../../context/ImmersiveBarProvider'
|
||||
import { isImmersiveRoute } from '../../lib/immersive-routes'
|
||||
import { cn } from '../../lib/utils'
|
||||
import { Header } from './Header'
|
||||
import { Sidebar } from './Sidebar'
|
||||
import { BottomNav } from './BottomNav'
|
||||
|
||||
export function RootLayout({ children }: { children: ReactNode }) {
|
||||
const immersive = useLocation({ select: (location) => isImmersiveRoute(location.pathname) })
|
||||
|
||||
return (
|
||||
<div className="min-h-dvh w-full">
|
||||
<Header />
|
||||
{/* En las rutas immersive la pantalla trae su propia barra (LargeTitle),
|
||||
con el logo y el nombre del grupo: el header global con logo + tema +
|
||||
avatar sería una segunda barra compitiendo por los mismos píxeles. */}
|
||||
{immersive ? null : <Header />}
|
||||
|
||||
<div className="mx-auto flex w-full max-w-7xl gap-6 lg:px-6">
|
||||
<Sidebar />
|
||||
<Sidebar immersive={immersive} />
|
||||
|
||||
{/* pb-24 deja lugar para la BottomNav; en iOS standalone hay que sumar
|
||||
el inset del home indicator o el contenido queda debajo. */}
|
||||
<main className="min-w-0 flex-1 px-4 pb-[calc(6rem+env(safe-area-inset-bottom))] pt-4 lg:px-0 lg:pb-8 lg:pt-8">
|
||||
{children}
|
||||
</main>
|
||||
<ImmersiveBarProvider>
|
||||
{/* pt-0 en immersive: el padding superior lo aporta la caja de la
|
||||
barra, y si no el título grande arrancaría 16px más abajo de la
|
||||
base de la barra y el colapso se mediría corrido. */}
|
||||
<main
|
||||
className={cn(
|
||||
'min-w-0 flex-1 px-4 pb-[calc(6rem+env(safe-area-inset-bottom))] lg:px-0 lg:pb-8',
|
||||
immersive ? 'pt-0' : 'pt-4 lg:pt-8',
|
||||
)}
|
||||
>
|
||||
{immersive ? <ImmersiveBarHost /> : null}
|
||||
{children}
|
||||
</main>
|
||||
</ImmersiveBarProvider>
|
||||
</div>
|
||||
|
||||
<BottomNav />
|
||||
|
||||
@@ -3,11 +3,19 @@ import { cn } from '../../lib/utils'
|
||||
import { Logo } from '../brand'
|
||||
import { isNavItemActive, NAV_ITEMS } from './nav-items'
|
||||
|
||||
export function Sidebar() {
|
||||
export function Sidebar({ immersive = false }: { immersive?: boolean }) {
|
||||
const location = useLocation()
|
||||
|
||||
return (
|
||||
<aside className="sticky top-16 hidden h-[calc(100dvh-4rem)] w-64 shrink-0 flex-col border-r border-border bg-surface px-4 py-6 lg:flex">
|
||||
// Sin header global no hay nada que esquive arriba: la columna del sidebar
|
||||
// pasa a ocupar la ventana completa y queda a la altura de la barra de
|
||||
// LargeTitle.
|
||||
<aside
|
||||
className={cn(
|
||||
'sticky hidden w-64 shrink-0 flex-col border-r border-border bg-surface px-4 py-6 lg:flex',
|
||||
immersive ? 'top-0 h-dvh' : 'top-16 h-[calc(100dvh-4rem)]',
|
||||
)}
|
||||
>
|
||||
{/* `Link` y no `<a>`: un anchor recargaría el documento y perdería el
|
||||
estado en memoria (cache de React Query, evento de instalación). */}
|
||||
<Link to="/" className="mb-8 flex items-center px-1" aria-label="Gruperly inicio">
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export { RootLayout } from './RootLayout'
|
||||
export { Header } from './Header'
|
||||
export { LargeTitle } from './LargeTitle'
|
||||
export { ThemeToggle } from './ThemeToggle'
|
||||
export { PublicHeader } from './PublicHeader'
|
||||
export { PublicFooter } from './PublicFooter'
|
||||
|
||||
Reference in New Issue
Block a user