mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-20 12:28:10 +08:00
e96059cd76
* docs: migrate to antd-style * [CodeFactor] Apply fixes * chore: code clean * chore: lint * chore: try cache * chore: try * fix: ssr * chore: code clean --------- Co-authored-by: codefactor-io <support@codefactor.io>
44 lines
1.0 KiB
TypeScript
44 lines
1.0 KiB
TypeScript
import { createStyles, css } from 'antd-style';
|
|
import React, { useMemo } from 'react';
|
|
import { COLOR_IMAGES, getClosetColor } from './colorUtil';
|
|
|
|
export interface BackgroundImageProps {
|
|
colorPrimary?: string;
|
|
isLight?: boolean;
|
|
}
|
|
|
|
const useStyle = createStyles(({ token }) => ({
|
|
image: css`
|
|
transition: all ${token.motionDurationSlow};
|
|
position: absolute;
|
|
left: 0;
|
|
top: 0;
|
|
height: 100%;
|
|
width: 100%;
|
|
object-fit: cover;
|
|
object-position: right top;
|
|
`,
|
|
}));
|
|
|
|
const BackgroundImage: React.FC<BackgroundImageProps> = ({ colorPrimary, isLight }) => {
|
|
const activeColor = useMemo(() => getClosetColor(colorPrimary), [colorPrimary]);
|
|
|
|
const { styles } = useStyle();
|
|
|
|
return (
|
|
<>
|
|
{COLOR_IMAGES.filter(({ url }) => url).map(({ color, url }) => (
|
|
<img
|
|
className={styles.image}
|
|
style={{ opacity: isLight && activeColor === color ? 1 : 0 }}
|
|
key={color}
|
|
src={url}
|
|
alt=""
|
|
/>
|
|
))}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default BackgroundImage;
|