mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-13 23:59:12 +08:00
ffbb19e090
* chore: enable tsc for demos * chore: site lint * chore: fix lint
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import * as React from 'react';
|
|
import useSiteToken from '../../../../hooks/useSiteToken';
|
|
import { COLOR_IMAGES, getClosetColor } from './colorUtil';
|
|
|
|
export interface BackgroundImageProps {
|
|
colorPrimary?: string;
|
|
isLight?: boolean;
|
|
}
|
|
|
|
export default function BackgroundImage({ colorPrimary, isLight }: BackgroundImageProps) {
|
|
const { token } = useSiteToken();
|
|
|
|
const activeColor = React.useMemo(() => getClosetColor(colorPrimary), [colorPrimary]);
|
|
|
|
const sharedStyle: React.CSSProperties = {
|
|
transition: `all ${token.motionDurationSlow}`,
|
|
position: 'absolute',
|
|
left: 0,
|
|
top: 0,
|
|
height: '100%',
|
|
width: '100%',
|
|
};
|
|
|
|
return (
|
|
<>
|
|
{COLOR_IMAGES.map(({ color, url }) => {
|
|
if (!url) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<img
|
|
key={color}
|
|
style={{
|
|
...sharedStyle,
|
|
opacity: isLight && activeColor === color ? 1 : 0,
|
|
objectFit: 'cover',
|
|
objectPosition: 'right top',
|
|
}}
|
|
src={url}
|
|
alt=""
|
|
/>
|
|
);
|
|
})}
|
|
|
|
{/* <div
|
|
style={{
|
|
...sharedStyle,
|
|
opacity: isLight || !activeColor || activeColor === DEFAULT_COLOR ? 0 : 1,
|
|
background: 'rgba(0,0,0,0.79)',
|
|
}}
|
|
/> */}
|
|
</>
|
|
);
|
|
}
|