Second frontend, written in Next.JS + Typescript.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

4 years ago
4 years ago
  1. import React from "react";
  2. import styles from "./MagicImage.module.sass";
  3. interface MagicImageProps {
  4. src: string
  5. alignH?: "left" | "center" | "right"
  6. alignV?: "top" | "middle" | "bottom"
  7. full?: boolean
  8. banner?: boolean
  9. fixed?: boolean
  10. opacity?: number
  11. children?: React.ReactNode
  12. }
  13. export default function MagicImage(props: MagicImageProps) {
  14. let containerClass = [styles.magicImageContainer]
  15. let imageClass = [styles.magicImage]
  16. let overlayClass = [styles.magicImageOverlay]
  17. if (props.fixed) {
  18. containerClass.push(styles.fixed);
  19. imageClass.push(styles.fixed);
  20. }
  21. if (props.full) {
  22. containerClass.push(styles.full);
  23. imageClass.push(styles.full);
  24. }
  25. if (props.banner) {
  26. imageClass.push(styles.banner)
  27. overlayClass.push(styles.banner)
  28. }
  29. const imageStyle = {
  30. background: `url(${JSON.stringify(props.src)}) no-repeat fixed center`,
  31. backgroundPositionX: props.alignH || "left",
  32. backgroundPositionY: props.alignV || "middle",
  33. };
  34. const overlayStyle = {
  35. backgroundColor: `rgba(0,0,0,${1.0 - (props.opacity || 0.25)})`,
  36. };
  37. return (
  38. <div className={containerClass.join(" ")}>
  39. <div className={imageClass.join(" ")} style={imageStyle}>
  40. <div className={overlayClass.join(" ")} style={overlayStyle}>
  41. {props.children}
  42. </div>
  43. </div>
  44. </div>
  45. );
  46. }