@@ -5,19 +5,41 @@ import {AnimateProps, useAnimation} from '../animation'
55
66export const ImageBorderRadiusOptions = [ 'small' , 'medium' , 'large' , 'xlarge' , 'full' ] as const
77export type ImageBorderRadiusOptions = ( typeof ImageBorderRadiusOptions ) [ number ]
8+ export type ImageAspectRatio = '1:1' | '16:9' | '16:10' | '4:3' | 'custom'
89
910export type ImageProps = React . ImgHTMLAttributes < HTMLImageElement > & {
1011 alt : string
1112 animate ?: AnimateProps
1213 borderRadius ?: ImageBorderRadiusOptions
14+ aspectRatio ?: ImageAspectRatio
1315}
1416
15- export const Image = ( { alt, animate, borderRadius, className, style, ...props } : ImageProps ) => {
17+ const getAspectRatioClassName = ( aspectRatio ?: ImageAspectRatio ) : string | null => {
18+ if ( ! aspectRatio ) {
19+ return null
20+ }
21+
22+ if ( aspectRatio === 'custom' ) {
23+ return styles [ 'Image--aspectRatio-custom' ]
24+ }
25+
26+ const className = `Image--aspectRatio-${ aspectRatio . replace ( ':' , '-' ) } `
27+
28+ return styles [ className ]
29+ }
30+
31+ export const Image = ( { alt, animate, borderRadius, className, style, aspectRatio, ...props } : ImageProps ) => {
1632 const { classes : animationClasses , styles : animationInlineStyles } = useAnimation ( animate )
1733
1834 return (
1935 < img
20- className = { clsx ( animationClasses , styles . Image , styles [ `Image--borderRadius-${ borderRadius } ` ] , className ) }
36+ className = { clsx (
37+ animationClasses ,
38+ styles . Image ,
39+ styles [ `Image--borderRadius-${ borderRadius } ` ] ,
40+ getAspectRatioClassName ( aspectRatio ) ,
41+ className ,
42+ ) }
2143 style = { { ...animationInlineStyles , ...style } }
2244 alt = { alt }
2345 { ...props }
0 commit comments