-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExampleAnimatedComponent.tsx
46 lines (40 loc) · 1.13 KB
/
ExampleAnimatedComponent.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { useEffect } from "react";
import useFocusable from "../../hooks/useFocusable";
type Props = React.HTMLAttributes<HTMLButtonElement>;
const ExampleFocusComponent = ({ ...props }: Props) => {
const { ref, focused, updatePosition } = useFocusable<HTMLButtonElement>();
useEffect(() => {
const interval = setInterval(updatePosition, 420);
return () => {
clearInterval(interval);
};
}, [updatePosition]);
return (
<>
<button
id="animated"
ref={ref}
style={{ backgroundColor: focused ? "blue" : "transparent" }}
onClick={() => console.log("button pressed!")}
{...props}
>
Animated Focusable Component
</button>
<style>
{`
@keyframes move-horizontal {
from { transform: translateX(0px) }
to { transform: translateX(20px) }
}
#animated {
animation-name: move-horizontal;
animation-duration: 4s;
animation-direction: alternate;
animation-iteration-count: infinite;
}
`}
</style>
</>
);
};
export default ExampleFocusComponent;