mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-10-24 03:33:09 +02:00
24 lines
627 B
TypeScript
24 lines
627 B
TypeScript
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 } />;
|
|
}
|