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

Commit 65b57b7

Browse files
committed
optimized component structure
1 parent e90ab8d commit 65b57b7

File tree

36 files changed

+136
-18
lines changed

36 files changed

+136
-18
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { animated, useSpring } from 'react-spring';
2+
import React, { useEffect, useState } from 'react';
3+
import { useAgile } from '@agile-ts/react';
4+
import core from '../../../../../../core';
5+
import styles from './styles.module.css';
6+
import clsx from 'clsx';
7+
8+
type Props = { className?: string };
9+
10+
const Astronaut: React.FC<Props> = (props) => {
11+
const { className } = props;
12+
const [timing] = useState(200);
13+
const [isRaised, setIsRaised] = React.useState(false);
14+
const animated_Astronaut = useSpring({
15+
transform: isRaised ? `translateY(-${30}px)` : `translateY(0px)`,
16+
config: {
17+
mass: 1,
18+
tension: 400,
19+
friction: 15,
20+
},
21+
});
22+
const dark = useAgile(core.ui.ASTRONAUT_DARK);
23+
24+
useEffect(() => {
25+
if (!isRaised) {
26+
return;
27+
}
28+
29+
const timeoutId = setTimeout(() => {
30+
core.ui.toggleAstronautColor(!dark);
31+
setIsRaised(false);
32+
}, timing);
33+
34+
return () => clearTimeout(timeoutId);
35+
}, [isRaised, timing]);
36+
37+
const trigger = () => setIsRaised(true);
38+
39+
return (
40+
<div className={clsx(styles.Container, className)}>
41+
<animated.img
42+
onMouseEnter={trigger}
43+
style={animated_Astronaut}
44+
className={styles.Image}
45+
src={`img/astronaut-${dark ? 'dark' : 'light'}.svg`}
46+
alt={'Astronaut'}
47+
/>
48+
<div className={styles.Text}>Poke me 👆 to mutate my color State.</div>
49+
</div>
50+
);
51+
};
52+
53+
export default Astronaut;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.Container {
2+
display: flex;
3+
flex-direction: column;
4+
align-items: flex-end;
5+
}
6+
7+
.Text {
8+
color: var(--ifm-color-on-background-2);
9+
margin-top: 30px;
10+
align-self: center;
11+
}
12+
13+
.Image {
14+
width: 100%;
15+
max-width: 800px;
16+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)