Skip to content

Commit 4b141c3

Browse files
committed
add cute animation
1 parent e6abd24 commit 4b141c3

File tree

1 file changed

+31
-2
lines changed
  • Web/React/component-variant-with-view-hook-pair/src/Panel

1 file changed

+31
-2
lines changed

Web/React/component-variant-with-view-hook-pair/src/Panel/MediaPanel.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Header } from "./parts/Header";
22
import { Attributes } from "./parts/Attributes";
33
import { Preview } from "./parts/Preview";
4-
import { css } from "@emotion/react";
4+
import { css, keyframes } from "@emotion/react";
55
import { useCallback, useState } from "react";
66

77
type Props = { id: string; name: string };
@@ -27,19 +27,30 @@ function View({
2727
previewProps,
2828
attributesProps,
2929
}: ReturnType<typeof useObject>[0]) {
30+
const [previewHovered, setPreviewHovered] = useState(false);
31+
3032
return (
3133
<div
3234
css={css`
3335
padding: 16px;
3436
`}
3537
>
36-
<div>
38+
<div
39+
css={
40+
previewHovered &&
41+
css`
42+
animation: ${bounce} 0.4s ease infinite;
43+
`
44+
}
45+
>
3746
<Header name={name} />
3847
</div>
3948
<div
4049
css={css`
4150
margin-top: 16px;
4251
`}
52+
onMouseEnter={() => setPreviewHovered(true)}
53+
onMouseLeave={() => setPreviewHovered(false)}
4354
>
4455
<Preview.View {...previewProps} />
4556
</div>
@@ -54,4 +65,22 @@ function View({
5465
);
5566
}
5667

68+
const bounce = keyframes`
69+
from, 20%, 53%, 80%, to {
70+
transform: translate3d(0,0,0);
71+
}
72+
73+
40%, 43% {
74+
transform: translate3d(0, -10px, 0);
75+
}
76+
77+
70% {
78+
transform: translate3d(0, -5px, 0);
79+
}
80+
81+
90% {
82+
transform: translate3d(0,-1px,0);
83+
}
84+
`;
85+
5786
export const MediaPanel = { useObject, View };

0 commit comments

Comments
 (0)