@@ -49,21 +49,24 @@ type ImageV3Props = {
49
49
src : string ;
50
50
alt : string ;
51
51
children ?: never ;
52
+ imgProps ?: React . HTMLProps < HTMLImageElement >
52
53
} & ImageTransformationProps ;
53
54
54
55
interface ImageV2Props {
55
56
src ?: never ;
57
+ alt : string ;
56
58
cldImg : UrlGenCloudinaryImage ;
57
59
children ?: never ;
60
+ imgProps ?: React . HTMLProps < HTMLImageElement >
58
61
}
59
62
60
63
export type CloudinaryImageProps = ImageV3Props | ImageV2Props ;
61
64
62
65
export const CloudinaryImage = forwardRef < HTMLImageElement , CloudinaryImageProps > (
63
66
( props , ref ) => {
64
67
if ( props . cldImg ) {
65
- const { cldImg, ...rest } = props ;
66
- return < img src = { cldImg . toURL ( ) } { ...rest } ref = { ref } /> ;
68
+ const { cldImg, alt , imgProps , ...rest } = props ;
69
+ return < img { ... imgProps } src = { cldImg . toURL ( ) } alt = { alt } { ...rest } ref = { ref } /> ;
67
70
}
68
71
const transformationMap = {
69
72
format : parseFormat ,
@@ -84,12 +87,12 @@ export const CloudinaryImage = forwardRef<HTMLImageElement, CloudinaryImageProps
84
87
roundCorners : parseRoundCorners ,
85
88
opacity : parseOpacity
86
89
} satisfies TransformationMap < ImageTransformationProps > ;
87
- const { src, alt, children, cldImg, ...rest } = props ;
90
+ const { src, alt, children, cldImg, imgProps , ...rest } = props ;
88
91
const { baseCloudUrl, assetPath } = parseCloudinaryUrlToParts ( src ) ;
89
92
const transformationString = parsePropsToTransformationString ( {
90
93
transformationProps : rest ,
91
94
transformationMap
92
95
} ) ;
93
96
94
- return < img src = { `${ baseCloudUrl } /${ transformationString } /${ assetPath } ` } alt = { alt } ref = { ref } /> ;
97
+ return < img { ... imgProps } src = { `${ baseCloudUrl } /${ transformationString } /${ assetPath } ` } alt = { alt } ref = { ref } /> ;
95
98
} ) ;
0 commit comments