Co-authored-by: Andre Silva <asilva01@acuitysso.com> Co-authored-by: Meier Lukas <meierschlumpf@gmail.com> Co-authored-by: Manuel <30572287+manuel-rw@users.noreply.github.com>
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import React from "react";
|
|
import { getThemeColor, useMantineTheme } from "@mantine/core";
|
|
import type { MantineColor } from "@mantine/core";
|
|
import combineClasses from "clsx";
|
|
import type { Property } from "csstype";
|
|
|
|
import classes from "./masked-image.module.css";
|
|
|
|
interface MaskedImageProps {
|
|
imageUrl?: string;
|
|
color: MantineColor;
|
|
alt?: string;
|
|
style?: React.CSSProperties;
|
|
className?: string;
|
|
maskSize?: Property.MaskSize;
|
|
maskRepeat?: Property.MaskRepeat;
|
|
maskPosition?: Property.MaskPosition;
|
|
}
|
|
|
|
export const MaskedImage = ({
|
|
imageUrl,
|
|
color,
|
|
alt,
|
|
style,
|
|
className,
|
|
maskSize = "contain",
|
|
maskRepeat = "no-repeat",
|
|
maskPosition = "center",
|
|
}: MaskedImageProps) => {
|
|
const theme = useMantineTheme();
|
|
|
|
return (
|
|
<div
|
|
className={combineClasses(classes.maskedImage, className)}
|
|
role="img"
|
|
aria-label={alt}
|
|
style={
|
|
{
|
|
...style,
|
|
"--image-color": getThemeColor(color, theme),
|
|
maskSize,
|
|
maskRepeat,
|
|
maskPosition,
|
|
maskImage: imageUrl ? `url(${imageUrl})` : undefined,
|
|
} as React.CSSProperties
|
|
}
|
|
/>
|
|
);
|
|
};
|