Zoeken...  ⌘K GitHub

ImageCaption image

Afbeelding met bijschrift en optionele creditregel. Voor redactionele of editorial contexten.

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

const {
  src,
  alt = 'Afbeelding',
  caption = 'Een beeld zegt meer dan duizend woorden.',
  credit,
  ratio = '16/9',
  rounded = true,
} = Astro.props;
---

<section class="bl-section icap-section">
  <div class="bl-inner">
    <figure class:list={['icap', { 'icap--rounded': rounded }]} style={`--icap-ratio: ${ratio}`}>
      <div class="icap__media">
        {src
          ? <img data-allow-img class="icap__img" src={src} alt={alt} loading="lazy" decoding="async" />
          : <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>
  </div>
</section>

<style>
  .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, #c8c8e8);
  }
  .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.8rem;
    color: #888;
    white-space: nowrap;
    flex-shrink: 0;
  }
</style>

Props

Prop Type Default Beschrijving
src string - URL van de afbeelding
alt string "Afbeelding" Alt-tekst
caption string - Bijschrift onder de afbeelding
credit string - Fotocredit rechts in de figcaption
ratio string "16/9" Beeldverhouding (CSS aspect-ratio)
rounded boolean true Afgeronde hoeken op het beeld

* = verplicht