|
1 | 1 | --- |
| 2 | +import { getCurrentLocale, getUiTranslator } from "@/src/i18n/utils"; |
2 | 3 | import type { ComponentProps } from "astro/types"; |
3 | 4 | import { Image } from "astro:assets"; |
4 | 5 | type Props = ComponentProps<typeof Image> & { |
5 | 6 | /** Defaults to 'photo' aspect ratio */ |
6 | 7 | aspectRatio?: "photo" | "square" | "none"; |
7 | 8 | caption?: string; |
| 9 | + containerClass?: string; |
| 10 | + visibleAltTextClass?: string; |
8 | 11 | }; |
9 | 12 | const { props } = Astro; |
| 13 | +
|
| 14 | +const currentLocale = getCurrentLocale(Astro.url.pathname); |
| 15 | +const t = await getUiTranslator(currentLocale); |
| 16 | +const noAltText = t("No alt text"); |
10 | 17 | --- |
11 | 18 |
|
12 | | -<div class="relative w-fit h-fit"> |
| 19 | +<div class={props.containerClass || "relative w-fit h-fit"}> |
13 | 20 | <!-- The props are identical but the lack of "IntrinsicAttributes" gives an errant ts error --> |
14 | 21 | <!-- @ts-ignore --> |
15 | 22 | <Image |
16 | 23 | {...props} |
17 | 24 | class="" |
18 | | - class:list={(props.class, |
19 | | - { |
20 | | - "object-cover": props.aspectRatio !== "none", |
21 | | - "aspect-square": props.aspectRatio === "square", |
22 | | - "aspect-photo": |
23 | | - props.aspectRatio === "photo" || props.aspectRatio === undefined, |
24 | | - })} |
| 25 | + class:list={[ |
| 26 | + props.class, |
| 27 | + { |
| 28 | + "object-cover": props.aspectRatio !== "none", |
| 29 | + "aspect-square": props.aspectRatio === "square", |
| 30 | + "aspect-photo": |
| 31 | + props.aspectRatio === "photo" || props.aspectRatio === undefined, |
| 32 | + }, |
| 33 | + ]} |
25 | 34 | /> |
26 | 35 | <p |
27 | 36 | aria-hidden |
28 | | - class="renderable-alt bg-bg-gray-40 line-clamp-3 absolute top-0 mt-sm mx-sm px-[7.5px] pb-[2.5px] rounded-xl text-body-caption text-ellipsis" |
| 37 | + class:list={[ |
| 38 | + "renderable-alt", |
| 39 | + "text-body-caption", |
| 40 | + "bg-bg-gray-40 line-clamp-3 absolute top-0 mt-sm mx-sm px-[7.5px] pb-[2.5px] rounded-xl text-ellipsis", |
| 41 | + props.visibleAltTextClass, |
| 42 | + ]} |
29 | 43 | > |
30 | | - {props.alt} |
| 44 | + <!-- It shouldn't be possible to pass no alt text, but if its missing |
| 45 | + show a '?' so the component doesn't look broken --> |
| 46 | + {props.alt || noAltText} |
31 | 47 | </p> |
32 | 48 | {props.caption && <p class="text-body-caption mt-xs">{props.caption}</p>} |
33 | 49 | </div> |
0 commit comments