Zoeken...  ⌘K GitHub

ImageCaption image

Afbeelding met bijschrift en credit in figure-element.

/image-caption
src/components/image/ImageCaption.astro
---
interface Props {
  src?: string;
  alt?: string;
  caption?: string;
  credit?: string;
  aspectRatio?: string;
  rounded?: boolean;
}

const {
  src = '',
  alt = 'Afbeelding',
  caption = 'Een beeld zegt meer dan duizend woorden — zo ook bij BLURR-campagnes.',
  credit = 'Foto: BLURR Creative Studio',
  aspectRatio = '16/9',
  rounded = true,
} = Astro.props;
---

<figure class:list={['icap', rounded && 'icap--rounded']} style={`--icap-ratio: ${aspectRatio}`}>
  <div class="icap__media">
    {src ? (
      <img class="icap__img" src={src} alt={alt} />
    ) : (
      <div class="icap__placeholder" aria-label={alt}></div>
    )}
  </div>
  <figcaption class="icap__figcaption">
    <span class="icap__caption">{caption}</span>
    {credit && <span class="icap__credit">{credit}</span>}
  </figcaption>
</figure>

<style>
  :root {
    --color-accent: #6366f1;
    --color-primary: #0a0a0a;
  }
  .icap { margin: 0; }
  .icap__media {
    aspect-ratio: var(--icap-ratio, 16/9);
    overflow: hidden;
  }
  .icap--rounded .icap__media { border-radius: 10px; }
  .icap__img { width: 100%; height: 100%; object-fit: cover; }
  .icap__placeholder {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #e0e0f0 0%, #c8c8e8 100%);
  }
  .icap__figcaption {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.75rem 0.25rem 0;
    border-top: 1px solid #eee;
    margin-top: 0.5rem;
  }
  .icap__caption {
    font-size: 0.9rem;
    color: #555;
    line-height: 1.5;
    font-style: italic;
  }
  .icap__credit {
    font-size: 0.75rem;
    color: #999;
    white-space: nowrap;
    flex-shrink: 0;
  }
</style>

Props

Prop Type Default Beschrijving
src string Afbeelding URL
alt string Alt-tekst
caption string Bijschrift
credit string Fotocredit
aspectRatio string CSS aspect-ratio (bv. 16/9)
rounded boolean Afgeronde hoeken

* = verplicht