BgImg.tsx 829 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import React, { CSSProperties } from 'react';
  2. type Props = {
  3. url: string;
  4. size?: number;
  5. width?: number;
  6. height?: number;
  7. circle?: boolean;
  8. className?: string;
  9. style?: CSSProperties;
  10. };
  11. export function BgImg (props: Props) {
  12. let { url, width, height, size, circle, className, style } = props;
  13. const fullClass = `JoyBgImg ${className || ''}`;
  14. let fullStyle: CSSProperties = {
  15. backgroundImage: `url(${url})`
  16. };
  17. if (!width || !height) {
  18. width = size;
  19. height = size;
  20. }
  21. fullStyle = Object.assign(fullStyle, {
  22. width,
  23. height,
  24. minWidth: width,
  25. minHeight: height
  26. });
  27. if (circle) {
  28. fullStyle = Object.assign(fullStyle, {
  29. borderRadius: '50%'
  30. });
  31. }
  32. fullStyle = Object.assign(fullStyle, style);
  33. return <div className={fullClass} style={fullStyle} />;
  34. }