Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit 9af5a11

Browse files
authored
Merge pull request #60 from agile-ts/develop
Develop
2 parents 7d4de01 + ce62244 commit 9af5a11

File tree

3 files changed

+47
-16
lines changed

3 files changed

+47
-16
lines changed

src/_pages/LandingPage/components/HeaderView/components/Astronaut/astronauts/AstronautDark.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React from 'react';
22

33
type Props = {
4-
onMouseEnter: (event: React.MouseEvent<SVGGElement, MouseEvent>) => void;
4+
onMouseEnter?: (event: React.MouseEvent<SVGGElement, MouseEvent>) => void;
5+
onMouseLeave?: (event: React.MouseEvent<SVGGElement, MouseEvent>) => void;
56
className?: string;
67
};
78

89
const AstronautDark: React.FC<Props> = (props) => {
9-
const { onMouseEnter, className } = props;
10+
const { onMouseEnter, onMouseLeave, className } = props;
1011
return (
1112
<svg
1213
className={className}
@@ -20,7 +21,8 @@ const AstronautDark: React.FC<Props> = (props) => {
2021
</defs>
2122
<g
2223
clipPath="url(#_clipPath_DJqdLJjPMCQuZbt7zMmdGqTw0kfPk0A5)"
23-
onMouseEnter={onMouseEnter}>
24+
onMouseEnter={onMouseEnter}
25+
onMouseLeave={onMouseLeave}>
2426
<path
2527
fill="none"
2628
stroke="#A2C1E4"

src/_pages/LandingPage/components/HeaderView/components/Astronaut/astronauts/AstronautLight.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React from 'react';
22

33
type Props = {
4-
onMouseEnter: (event: React.MouseEvent<SVGGElement, MouseEvent>) => void;
4+
onMouseEnter?: (event: React.MouseEvent<SVGGElement, MouseEvent>) => void;
5+
onMouseLeave?: (event: React.MouseEvent<SVGGElement, MouseEvent>) => void;
56
className?: string;
67
};
78

89
const AstronautLight: React.FC<Props> = (props) => {
9-
const { onMouseEnter, className } = props;
10+
const { onMouseEnter, onMouseLeave, className } = props;
1011
return (
1112
<svg
1213
className={className}
@@ -20,7 +21,8 @@ const AstronautLight: React.FC<Props> = (props) => {
2021
</defs>
2122
<g
2223
clipPath="url(#_clipPath_STwyEDuuaNbGIKbAX7KqxcyghTzV9bZj)"
23-
onMouseEnter={onMouseEnter}>
24+
onMouseEnter={onMouseEnter}
25+
onMouseLeave={onMouseLeave}>
2426
<path
2527
fill="none"
2628
stroke="#A2C1E4"

src/_pages/LandingPage/components/HeaderView/components/Astronaut/index.tsx

+37-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ type Props = { className?: string };
1212
const Astronaut: React.FC<Props> = (props) => {
1313
const { className } = props;
1414
const [timing] = useState(200);
15-
const [isRaised, setIsRaised] = React.useState(false);
15+
const [isRaised, setIsRaised] = useState(false);
16+
const [isOnAstronaut, setIsOnAstronaut] = useState(false);
1617
const animated_Astronaut = useSpring({
1718
transform: isRaised ? `translateY(-${30}px)` : `translateY(0px)`,
1819
config: {
@@ -23,10 +24,20 @@ const Astronaut: React.FC<Props> = (props) => {
2324
});
2425
const dark = useAgile(core.ui.ASTRONAUT_DARK);
2526

27+
const [mounted, setMounted] = useState(false);
28+
// The astronaut theme on SSR is always the default theme but the site theme
29+
// can be in a different mode. React hydration doesn't update DOM styles
30+
// that come from SSR. Hence force a re-render after mounting to apply the
31+
// current relevant styles. There will be a flash seen of the original
32+
// styles seen using this current approach but that's probably ok. Fixing
33+
// the flash will require changing the theming approach and is not worth it
34+
// at this point.
2635
useEffect(() => {
27-
if (!isRaised) {
28-
return;
29-
}
36+
setMounted(true);
37+
}, []);
38+
39+
useEffect(() => {
40+
if (!isRaised) return;
3041

3142
const timeoutId = setTimeout(() => {
3243
core.ui.toggleAstronautColor(!dark);
@@ -36,19 +47,35 @@ const Astronaut: React.FC<Props> = (props) => {
3647
return () => clearTimeout(timeoutId);
3748
}, [isRaised, timing]);
3849

39-
function trigger() {
40-
setIsRaised(true);
41-
}
50+
const onMouseEnter = () => {
51+
if (!isOnAstronaut) {
52+
setIsOnAstronaut(true);
53+
setIsRaised(true);
54+
}
55+
};
56+
57+
const onMouseLeave = () => {
58+
// to prevent endless bouncer
59+
setTimeout(() => {
60+
setIsOnAstronaut(false);
61+
}, 1100);
62+
};
4263

4364
return (
44-
<div className={clsx(styles.Container, className)}>
65+
<div key={String(mounted)} className={clsx(styles.Container, className)}>
4566
<animated.div
4667
style={animated_Astronaut}
4768
className={styles.ImageContainer}>
4869
{dark ? (
49-
<AstronautDark onMouseEnter={trigger} />
70+
<AstronautDark
71+
onMouseEnter={onMouseEnter}
72+
onMouseLeave={onMouseLeave}
73+
/>
5074
) : (
51-
<AstronautLight onMouseEnter={trigger} />
75+
<AstronautLight
76+
onMouseEnter={onMouseEnter}
77+
onMouseLeave={onMouseLeave}
78+
/>
5279
)}
5380
</animated.div>
5481
<div className={styles.Text}>Poke me 👆 to mutate my color State.</div>

0 commit comments

Comments
 (0)