Zoeken...  ⌘K GitHub

VideoTestimonial video

Grid van video testimonial kaarten. Klik opent native dialog met YouTube autoplay. Hover toont play overlay.

/video-testimonial
src/components/video/VideoTestimonial.astro
---
interface Testimonial {
  name: string;
  role: string;
  company?: string;
  thumbnail: string;
  videoId?: string;
  quote?: string;
}

interface Props {
  eyebrow?: string;
  headline?: string;
  testimonials: Testimonial[];
}

const { eyebrow, headline, testimonials } = Astro.props;
---

<section class="vt__section">
  {(eyebrow || headline) && (
    <div class="vt__header">
      {eyebrow && <p class="vt__eyebrow">{eyebrow}</p>}
      {headline && <h2 class="vt__headline">{headline}</h2>}
    </div>
  )}

  <div class="vt__grid">
    {testimonials.map((t, index) => (
      <div
        class="vt__card"
        role={t.videoId ? 'button' : 'article'}
        tabindex={t.videoId ? '0' : undefined}
        data-video-id={t.videoId}
        data-name={t.name}
        aria-label={t.videoId ? `Bekijk video van ${t.name}` : undefined}
        style={`--vt-delay: ${index * 100}ms;`}
      >
        <div class="vt__thumb-wrap">
          <img
            src={t.thumbnail}
            alt={`${t.name} — ${t.role}`}
            class="vt__thumb"
            loading="lazy"
            decoding="async"
          />
          {t.videoId && (
            <div class="vt__overlay" aria-hidden="true">
              <div class="vt__play-icon">
                <svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor">
                  <polygon points="5,3 19,12 5,21" />
                </svg>
              </div>
            </div>
          )}
        </div>

        <div class="vt__info">
          <p class="vt__name">{t.name}</p>
          <p class="vt__role">
            {t.role}{t.company && `, ${t.company}`}
          </p>
          {t.quote && <blockquote class="vt__quote">"{t.quote}"</blockquote>}
        </div>
      </div>
    ))}
  </div>
</section>

<!-- Native dialog modal -->
<dialog class="vt__modal" id="vt-modal" aria-label="Video testimonial">
  <div class="vt__modal-inner">
    <button class="vt__modal-close" id="vt-modal-close" aria-label="Sluiten">
      <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round">
        <line x1="18" y1="6" x2="6" y2="18" />
        <line x1="6" y1="6" x2="18" y2="18" />
      </svg>
    </button>
    <div class="vt__modal-frame">
      <iframe
        id="vt-modal-iframe"
        class="vt__modal-iframe"
        src=""
        allow="autoplay; fullscreen; picture-in-picture"
        allowfullscreen
        frameborder="0"
        title="Video testimonial"
      />
    </div>
  </div>
</dialog>

<script>
  const modal = document.getElementById('vt-modal') as HTMLDialogElement | null;
  const iframe = document.getElementById('vt-modal-iframe') as HTMLIFrameElement | null;
  const closeBtn = document.getElementById('vt-modal-close');

  function openModal(videoId: string) {
    if (!modal || !iframe) return;
    iframe.src = `https://www.youtube.com/embed/${videoId}?autoplay=1&rel=0`;
    modal.showModal();
  }

  function closeModal() {
    if (!modal || !iframe) return;
    iframe.src = '';
    modal.close();
  }

  closeBtn?.addEventListener('click', closeModal);

  modal?.addEventListener('click', (e) => {
    if (e.target === modal) closeModal();
  });

  modal?.addEventListener('keydown', (e) => {
    if (e.key === 'Escape') closeModal();
  });

  document.querySelectorAll<HTMLElement>('.vt__card[data-video-id]').forEach((card) => {
    card.addEventListener('click', () => {
      const videoId = card.dataset.videoId;
      if (videoId) openModal(videoId);
    });

    card.addEventListener('keydown', (e) => {
      if (e.key === 'Enter' || e.key === ' ') {
        e.preventDefault();
        const videoId = card.dataset.videoId;
        if (videoId) openModal(videoId);
      }
    });
  });

  // IntersectionObserver for entrance animation
  const cards = document.querySelectorAll<HTMLElement>('.vt__card');
  const obs = new IntersectionObserver(
    (entries) => {
      entries.forEach((entry) => {
        if (entry.isIntersecting) {
          entry.target.classList.add('vt__card--visible');
          obs.unobserve(entry.target);
        }
      });
    },
    { threshold: 0.1, rootMargin: '0px 0px -40px 0px' }
  );
  cards.forEach((c) => obs.observe(c));
</script>

<style>
  :root {
    --color-primary: #0a0a0a;
    --color-accent: #6366f1;
    --color-bg: #fff;
    --color-muted: #6b7280;
    --radius: 0.5rem;
  }

  .vt__section {
    padding: 4rem 1.5rem;
    background: var(--color-bg);
  }

  .vt__header {
    text-align: center;
    margin-bottom: 2.5rem;
  }

  .vt__eyebrow {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-accent);
    margin: 0 0 0.5rem;
  }

  .vt__headline {
    font-size: clamp(1.75rem, 4vw, 2.75rem);
    font-weight: 700;
    color: var(--color-primary);
    margin: 0;
    line-height: 1.15;
  }

  .vt__grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    max-width: 1100px;
    margin: 0 auto;
  }

  .vt__card {
    border-radius: var(--radius);
    overflow: hidden;
    background: #f9fafb;
    cursor: default;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease var(--vt-delay, 0ms), transform 0.5s ease var(--vt-delay, 0ms);
  }

  .vt__card[data-video-id] {
    cursor: pointer;
  }

  .vt__card--visible {
    opacity: 1;
    transform: translateY(0);
  }

  .vt__card[data-video-id]:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.1);
  }

  .vt__card--visible[data-video-id]:hover {
    transform: translateY(-4px);
  }

  .vt__thumb-wrap {
    position: relative;
    aspect-ratio: 16 / 9;
    overflow: hidden;
  }

  .vt__thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.35s ease;
  }

  .vt__card[data-video-id]:hover .vt__thumb {
    transform: scale(1.03);
  }

  .vt__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
  }

  .vt__card[data-video-id]:hover .vt__overlay {
    background: rgba(0, 0, 0, 0.4);
  }

  .vt__play-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-primary);
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.3s ease, transform 0.3s ease;
    padding-left: 3px;
  }

  .vt__card[data-video-id]:hover .vt__play-icon {
    opacity: 1;
    transform: scale(1);
  }

  .vt__info {
    padding: 1.125rem 1.25rem 1.25rem;
  }

  .vt__name {
    margin: 0 0 0.2rem;
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--color-primary);
  }

  .vt__role {
    margin: 0 0 0.75rem;
    font-size: 0.8125rem;
    color: var(--color-muted);
  }

  .vt__quote {
    margin: 0;
    font-size: 0.875rem;
    font-style: italic;
    color: #374151;
    line-height: 1.55;
    padding: 0;
    border: none;
  }

  /* Modal */
  .vt__modal {
    position: fixed;
    inset: 0;
    max-width: 100%;
    max-height: 100%;
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .vt__modal::backdrop {
    background: rgba(0, 0, 0, 0.8);
  }

  .vt__modal[open] {
    display: flex;
  }

  .vt__modal-inner {
    position: relative;
    width: min(900px, 95vw);
    border-radius: var(--radius);
    overflow: hidden;
    background: #000;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.4);
  }

  .vt__modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    z-index: 10;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
  }

  .vt__modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
  }

  .vt__modal-frame {
    aspect-ratio: 16 / 9;
    width: 100%;
  }

  .vt__modal-iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
  }

  /* Responsive grid */
  @media (max-width: 900px) {
    .vt__grid {
      grid-template-columns: repeat(2, 1fr);
    }
  }

  @media (max-width: 560px) {
    .vt__grid {
      grid-template-columns: 1fr;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    * {
      animation: none !important;
      transition: none !important;
    }
  }
</style>

Props

Prop Type Default Beschrijving
testimonials * { name: string; role: string; thumbnail: string; videoId?: string; quote?: string }[] Video testimonial items
eyebrow string Label boven sectie
headline string Sectie headline

* = verplicht