CHANGED: added conditional render for CardMedia component
This commit is contained in:
parent
6342db227c
commit
80702813f4
|
@ -1,17 +1,33 @@
|
||||||
|
import Image from 'next/image';
|
||||||
import React, { forwardRef } from 'react';
|
import React, { forwardRef } from 'react';
|
||||||
import { CardMediaProps, CardMediaType } from './card.types';
|
import { CardMediaProps, CardMediaType } from './card.types';
|
||||||
|
|
||||||
export const CardMedia = forwardRef<CardMediaType, CardMediaProps>(
|
export const CardMedia = forwardRef<CardMediaType, CardMediaProps>(
|
||||||
(
|
(
|
||||||
{ rounded = true, preview = true, type, className = '', ...props },
|
{
|
||||||
|
alt,
|
||||||
|
src,
|
||||||
|
type,
|
||||||
|
quality = 80,
|
||||||
|
rounded = true,
|
||||||
|
preview = true,
|
||||||
|
className = '',
|
||||||
|
...props
|
||||||
|
},
|
||||||
ref,
|
ref,
|
||||||
) => {
|
) => {
|
||||||
const classes =
|
const classes =
|
||||||
`m3 m3-card-media${rounded ? ' m3-rounded' : ''}${preview ? ' m3-preview' : ''} ${className}`.trimEnd();
|
`m3 m3-card-media${rounded ? ' m3-rounded' : ''}${preview ? ' m3-preview' : ''} ${className}`.trimEnd();
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case 'img':
|
||||||
|
return <Image alt={alt} quality={quality} src={src} />;
|
||||||
|
default:
|
||||||
return React.createElement(type, {
|
return React.createElement(type, {
|
||||||
...props,
|
...props,
|
||||||
className: classes,
|
className: classes,
|
||||||
ref: ref,
|
ref: ref,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -10,9 +10,12 @@ export interface CardActionAreaProps
|
||||||
export interface CardProps extends ContainerProps {}
|
export interface CardProps extends ContainerProps {}
|
||||||
|
|
||||||
export interface CardMediaProps extends HTMLAttributes<CardMediaType> {
|
export interface CardMediaProps extends HTMLAttributes<CardMediaType> {
|
||||||
type: 'img' | 'video' | 'picture' | 'iframe' | 'audio';
|
alt: string;
|
||||||
|
src: string;
|
||||||
|
quality?: number;
|
||||||
rounded?: boolean;
|
rounded?: boolean;
|
||||||
preview?: boolean;
|
preview?: boolean;
|
||||||
|
type: 'img' | 'video' | 'picture' | 'iframe' | 'audio';
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CardMediaType = HTMLImageElement &
|
export type CardMediaType = HTMLImageElement &
|
||||||
|
|
Loading…
Reference in New Issue