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 ;
8
9
containerClass? : string ;
10
+ visibleAltTextClass? : string ;
9
11
};
10
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" );
11
17
---
12
18
13
19
<div class ={ props .containerClass || " relative w-fit h-fit" } >
@@ -16,19 +22,28 @@ const { props } = Astro;
16
22
<Image
17
23
{... props }
18
24
class =" "
19
- class:list ={ (props .class ,
20
- {
21
- " object-cover" : props .aspectRatio !== " none" ,
22
- " aspect-square" : props .aspectRatio === " square" ,
23
- " aspect-photo" :
24
- props .aspectRatio === " photo" || props .aspectRatio === undefined ,
25
- })}
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
+ ]}
26
34
/>
27
35
<p
28
36
aria-hidden
29
- 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
+ ]}
30
43
>
31
- { 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 }
32
47
</p >
33
48
{ props .caption && <p class = " text-body-caption mt-xs" >{ props .caption } </p >}
34
49
</div >
0 commit comments