ResponsiveImage.tsx 647 B

1234567891011121314151617181920212223242526272829303132
  1. import clsx from 'clsx';
  2. import Image from 'next/image';
  3. export default function ResponsiveImage(props) {
  4. if (props.url) {
  5. return (
  6. <img
  7. src={props.url}
  8. className={clsx('img-fluid', props.className)}
  9. width={props.width}
  10. height={props.height}
  11. loading="lazy"
  12. alt={props.alt || ''}
  13. />
  14. );
  15. }
  16. const src2x = props.src;
  17. return (
  18. <Image
  19. className={clsx(props.className)}
  20. src={src2x}
  21. alt={props.alt || ''}
  22. width={props.width}
  23. height={props.height}
  24. quality={85}
  25. srcSet={[props.width, props.width * 2]}
  26. {...props}
  27. />
  28. );
  29. }