Skip to content
Snippets Groups Projects
Commit bb8b6b98 authored by danieldeng2's avatar danieldeng2
Browse files

Add spinner on click

parent 60c995dc
Branches
No related tags found
No related merge requests found
...@@ -9,26 +9,66 @@ interface NavBarBrandProps { ...@@ -9,26 +9,66 @@ interface NavBarBrandProps {
onClick: (event: React.MouseEvent<HTMLImageElement>) => void; onClick: (event: React.MouseEvent<HTMLImageElement>) => void;
} }
const NavBarBrand: React.FC<NavBarBrandProps> = ({ interface NavBarBrandState {
onClick, iconRotate: boolean;
}: NavBarBrandProps) => { }
return (
<Navbar.Brand className={styles.brandContainer}> class NavBarBrand extends React.Component<NavBarBrandProps, NavBarBrandState> {
<img brandIcon: HTMLImageElement | null;
src={logo}
width="30" constructor(props: NavBarBrandProps) {
height="30" super(props);
className={cx( this.state = { iconRotate: false };
"d-inline-block", this.brandIcon = null;
"align-center", }
styles.brandImage
)} componentDidMount() {
alt="React Bootstrap logo" if (this.brandIcon) {
onClick={(e) => onClick(e)} this.brandIcon.addEventListener("animationend", () =>
/> this.rotatingDone()
<Link to="/">Scientia</Link> );
</Navbar.Brand> }
); }
};
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; export default NavBarBrand;
...@@ -22,3 +22,16 @@ ...@@ -22,3 +22,16 @@
text-decoration: none !important; 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment