diff --git a/frontend/src/components/molecules/NavBarBrand/index.tsx b/frontend/src/components/molecules/NavBarBrand/index.tsx index 9f728425fcb37bb7319fb7bcc78a53af75243f40..cc81592b327ce7d79f9692e4915b201fc6eb54e3 100644 --- a/frontend/src/components/molecules/NavBarBrand/index.tsx +++ b/frontend/src/components/molecules/NavBarBrand/index.tsx @@ -9,26 +9,66 @@ interface NavBarBrandProps { onClick: (event: React.MouseEvent<HTMLImageElement>) => void; } -const NavBarBrand: React.FC<NavBarBrandProps> = ({ - onClick, -}: NavBarBrandProps) => { - return ( - <Navbar.Brand className={styles.brandContainer}> - <img - src={logo} - width="30" - height="30" - className={cx( - "d-inline-block", - "align-center", - styles.brandImage - )} - alt="React Bootstrap logo" - onClick={(e) => onClick(e)} - /> - <Link to="/">Scientia</Link> - </Navbar.Brand> - ); -}; +interface NavBarBrandState { + iconRotate: boolean; +} + +class NavBarBrand extends React.Component<NavBarBrandProps, NavBarBrandState> { + brandIcon: HTMLImageElement | null; + + constructor(props: NavBarBrandProps) { + super(props); + this.state = { iconRotate: false }; + this.brandIcon = null; + } + + componentDidMount() { + if (this.brandIcon) { + this.brandIcon.addEventListener("animationend", () => + this.rotatingDone() + ); + } + } + + componentWillUnmount() { + if (this.brandIcon) { + this.brandIcon.removeEventListener("animationend", () => + this.rotatingDone() + ); + } + } + + rotatingDone() { + this.setState({ + iconRotate: false, + }); + } + + render() { + return ( + <Navbar.Brand className={styles.brandContainer}> + <img + src={logo} + width="30" + height="30" + className={cx("d-inline-block", "align-center", styles.brandImage, { + rotate: this.state.iconRotate, + })} + alt="Scientia logo" + onClick={(e) => { + this.setState({ + iconRotate: true, + }); + this.props.onClick(e); + }} + ref={(elm) => { + this.brandIcon = elm; + }} + /> + <Link to="/">Scientia</Link> + </Navbar.Brand> + ); + } +} export default NavBarBrand; diff --git a/frontend/src/components/molecules/NavBarBrand/style.module.scss b/frontend/src/components/molecules/NavBarBrand/style.module.scss index 2eb403de5086051a69eeca361a11f45cc166a9f2..966e33b10e009aefba326e7db71ea83a9b7ac5cb 100644 --- a/frontend/src/components/molecules/NavBarBrand/style.module.scss +++ b/frontend/src/components/molecules/NavBarBrand/style.module.scss @@ -22,3 +22,16 @@ text-decoration: none !important; } +:global(.rotate) { + animation: rotate-keyframes 0.25s; + } + + @keyframes rotate-keyframes { + from { + transform: rotate(0deg); + } + + to { + transform: rotate(-90deg); + } + } \ No newline at end of file