nitro-react/src/common/layout/LayoutBackgroundImage.tsx

24 lines
627 B
TypeScript
Raw Normal View History

2022-03-24 03:55:11 +01:00
import { FC, useMemo } from 'react';
import { Base, BaseProps } from '../Base';
export interface LayoutBackgroundImageProps extends BaseProps<HTMLDivElement>
{
imageUrl?: string;
}
export const LayoutBackgroundImage: FC<LayoutBackgroundImageProps> = props =>
{
const { imageUrl = null, fit = true, style = null, ...rest } = props;
const getStyle = useMemo(() =>
{
const newStyle = { ...style };
if(imageUrl) newStyle.background = `url(${ imageUrl }) center no-repeat`;
return newStyle;
}, [ style, imageUrl ]);
return <Base fit={ fit } style={ getStyle } { ...rest } />;
}