keycloak_theme/stories/intro/KeycloakifyRotatingLogo.tsx

62 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-04-19 23:41:25 +02:00
import React from "react";
import { memo, useState } from "react";
import { useConstCallback } from "powerhooks";
import { keyframes } from "tss-react";
import keycloakifyLogoHeroMovingPngUrl from "./keycloakify-logo-hero-moving.png";
import keycloakifyLogoHeroStillPngUrl from "./keycloakify-logo-hero-still.png";
import { makeStyles } from "./tss";
export type Props = {
style?: React.CSSProperties;
id?: string;
onLoad?: () => void;
};
export const KeycloakifyRotatingLogo = memo((props: Props) => {
const { id, style, onLoad: onLoadProp } = props;
const [isImageLoaded, setIsImageLoaded] = useState(false);
const onLoad = useConstCallback(() => {
setIsImageLoaded(true);
onLoadProp?.();
});
const { classes } = useStyles({
2023-04-19 23:41:25 +02:00
isImageLoaded
});
return (
<div id={id} className={classes.root} style={style}>
<img className={classes.rotatingImg} onLoad={onLoad} src={keycloakifyLogoHeroMovingPngUrl} alt={"Rotating react logo"} />
<img className={classes.stillImg} src={keycloakifyLogoHeroStillPngUrl} alt={"keyhole"} />
</div>
);
});
const useStyles = makeStyles<{ isImageLoaded: boolean }>({
2024-05-20 15:48:51 +02:00
name: { KeycloakifyRotatingLogo }
2023-04-19 23:41:25 +02:00
})((_theme, { isImageLoaded }) => ({
2024-05-20 15:48:51 +02:00
root: {
position: "relative"
2023-04-19 23:41:25 +02:00
},
2024-05-20 15:48:51 +02:00
rotatingImg: {
animation: `${keyframes({
from: {
transform: "rotate(0deg)"
2023-04-19 23:41:25 +02:00
},
2024-05-20 15:48:51 +02:00
to: {
transform: "rotate(360deg)"
2023-04-19 23:41:25 +02:00
}
})} infinite 20s linear`,
2024-05-20 15:48:51 +02:00
width: isImageLoaded ? "100%" : undefined,
height: isImageLoaded ? "auto" : undefined
2023-04-19 23:41:25 +02:00
},
2024-05-20 15:48:51 +02:00
stillImg: {
position: "absolute",
top: "0",
left: "0",
width: isImageLoaded ? "100%" : undefined,
height: isImageLoaded ? "auto" : undefined
2023-04-19 23:41:25 +02:00
}
}));