SPB Git

Repository Public

HeroPlayer.tsx 2.8 KB 48 lines tsx

1"use client";2import dynamic from "next/dynamic";3import { useState } from "react";4import type { PlayerProps } from "./Player";5import { IconPlay } from "./icons";67// Le lecteur (et hls.js) n'est téléchargé qu'au clic sur « Lire » : l'accueil reste léger.8const Player = dynamic(() => import("./Player"), { ssr: false, loading: () => <div className="aspect-video w-full bg-black" role="status" aria-label="…" /> });910/**11 * Héros de l'accueil : l'affiche de la vidéo vedette dans un grand cadre, le texte à côté (dessous sur téléphone).12 * La lecture démarre sur place, dans le cadre, au clic sur l'affiche ou sur « Lire la vidéo ».13 */14export function HeroPlayer({ player, playLabel, duration, actions, children }: { player: Omit<PlayerProps, "autoPlay">; playLabel: string; duration: string; actions?: React.ReactNode; children: React.ReactNode }) {15  const [open, setOpen] = useState(false);16  return (17    <div className="relative isolate overflow-x-clip" data-testid={open ? "hero-playing" : "hero"}>18      <div className="hero-glow" aria-hidden="true" />19      <div className="shell grid items-center gap-x-12 gap-y-7 pb-4 pt-5 sm:pt-8 lg:grid-cols-12 lg:pb-8 lg:pt-12">20        <div className="lg:col-span-7 lg:col-start-6 lg:row-start-1">21          {open ? (22            <div className="hero-media"><Player {...player} autoPlay embedded /></div>23          ) : (24            <button type="button" onClick={() => setOpen(true)} aria-label={`${playLabel} — ${player.title}`} className="hero-media group block w-full cursor-pointer" style={{ aspectRatio: "16 / 9" }}>25              {player.poster && <img src={player.poster} alt="" width={player.width} height={player.height} fetchPriority="high" decoding="async" className="absolute inset-0 h-full w-full object-cover transition-transform duration-700 group-hover:scale-[1.03]" />}26              <span className="absolute inset-0 bg-gradient-to-t from-black/45 via-transparent to-black/5" aria-hidden="true" />27              <span className="play-disc absolute left-1/2 top-1/2 h-[4.5rem] w-[4.5rem] -translate-x-1/2 -translate-y-1/2 sm:h-20 sm:w-20"><IconPlay size={30} /></span>28              <span className="absolute bottom-3 right-3 rounded-lg bg-black/70 px-2 py-1 text-xs font-semibold tabular-nums text-white backdrop-blur-sm">{duration}</span>29            </button>30          )}31        </div>32        <div className="min-w-0 lg:col-span-5 lg:col-start-1 lg:row-start-1">33          {children}34          <div className="mt-6 flex flex-wrap gap-3">35            {!open && (36              <button type="button" className="btn btn-primary btn-lg" onClick={() => setOpen(true)} data-testid="hero-play">37                <IconPlay size={18} />38                {playLabel}39              </button>40            )}41            {actions}42          </div>43        </div>44      </div>45    </div>46  );47}48
Files main
Menu

Theme