Skip to content

Commit 3c33074

Browse files
committed
animate select cubes and modal-solve
1 parent 89112e4 commit 3c33074

File tree

2 files changed

+45
-31
lines changed

2 files changed

+45
-31
lines changed

src/components/Select.tsx

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import translation from "@/translations/global.json";
1212
import { useSettingsModalStore } from "@/store/SettingsModalStore";
1313
import { useCubesModalStore } from "@/store/CubesModalStore";
1414
import useClickOutside from "@/hooks/useClickOutside";
15+
import { AnimatePresence, motion } from "framer-motion";
1516

1617
export default function Select() {
1718
const [open, setOpen] = useState<boolean>(false);
@@ -51,17 +52,36 @@ export default function Select() {
5152
<SelectOptions />
5253
</div>
5354
</button>
54-
{open === true ? (
55-
<div
56-
id="list-options"
57-
className={
58-
"absolute z-40 overflow-auto max-h-[400px] p-1 top-12 mt-1 right-0 w-full h-auto border rounded-md light:bg-neutral-200 light:border-neutral-400 light:text-neutral-900 dark:bg-zinc-900 dark:border-zinc-700 dark:text-slate-100"
59-
}
60-
>
61-
{/* Favorites */}
62-
<LabelSection description={translation.inputs["favorites"][lang]} />
63-
{cubes?.map((cube) => {
64-
if (cube.favorite) {
55+
<AnimatePresence>
56+
{open === true ? (
57+
<motion.div
58+
initial={{ y: 0, scale: 0.9, opacity: 0.8 }}
59+
animate={{ y: 0, scale: 1, opacity: 1 }}
60+
exit={{ x: 0, scale: 0.9, opacity: 0 }}
61+
id="list-options"
62+
className={
63+
"absolute z-40 overflow-auto max-h-[400px] p-1 top-12 mt-1 right-0 w-full h-auto border rounded-md light:bg-neutral-200 light:border-neutral-400 light:text-neutral-900 dark:bg-zinc-900 dark:border-zinc-700 dark:text-slate-100"
64+
}
65+
>
66+
{/* Favorites */}
67+
<LabelSection
68+
description={translation.inputs["favorites"][lang]}
69+
/>
70+
{cubes?.map((cube) => {
71+
if (cube.favorite) {
72+
return (
73+
<Option
74+
key={genId()}
75+
name={cube.name}
76+
category={cube.category}
77+
cubeId={cube.id}
78+
handleClose={handleClose}
79+
/>
80+
);
81+
}
82+
})}
83+
<LabelSection description={translation.inputs["list"][lang]} />
84+
{cubes?.map((cube) => {
6585
return (
6686
<Option
6787
key={genId()}
@@ -71,23 +91,11 @@ export default function Select() {
7191
handleClose={handleClose}
7292
/>
7393
);
74-
}
75-
})}
76-
<LabelSection description={translation.inputs["list"][lang]} />
77-
{cubes?.map((cube) => {
78-
return (
79-
<Option
80-
key={genId()}
81-
name={cube.name}
82-
category={cube.category}
83-
cubeId={cube.id}
84-
handleClose={handleClose}
85-
/>
86-
);
87-
})}
88-
<AddCubeOption />
89-
</div>
90-
) : null}
94+
})}
95+
<AddCubeOption />
96+
</motion.div>
97+
) : null}
98+
</AnimatePresence>
9199
</div>
92100
</>
93101
);

src/components/solves/ModalSolve.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { useEffect, useState } from "react";
2121
import ChevronUp from "@/icons/ChevronUp";
2222
import { useSettingsModalStore } from "@/store/SettingsModalStore";
2323
import translation from "@/translations/global.json";
24+
import { motion } from "framer-motion";
2425

2526
export default function ModalSolve() {
2627
const [showOptions, setShowOptions] = useState<boolean>(false);
@@ -108,12 +109,17 @@ export default function ModalSolve() {
108109
return (
109110
<>
110111
<div
111-
className="fixed top-0 left-0 z-50 flex flex-col items-center justify-center w-full h-screen px-8 py-4 overflow-x-hidden overflow-y-auto bg-black bg-opacity-75 md:inset-0 text-neutral-950"
112+
className="fixed top-0 left-0 z-50 flex flex-col items-center justify-center w-full h-screen px-8 py-4 overflow-x-hidden overflow-y-auto bg-black bg-opacity-10 md:inset-0 text-neutral-950"
112113
onClick={(e) => {
113114
if (e.target === e.currentTarget) setStatus(false);
114115
}}
115116
>
116-
<div className="relative w-full h-auto text-xs bg-white rounded-md sm:w-96">
117+
<motion.div
118+
initial={{ y: 0, scale: 0.9, opacity: 0.8 }}
119+
animate={{ y: 0, scale: 1, opacity: 1 }}
120+
exit={{ x: 0, scale: 0.9, opacity: 0 }}
121+
className="relative w-full h-auto text-xs bg-white rounded-md sm:w-96"
122+
>
117123
<div className="flex items-center justify-between px-3 py-2 border-b border-neutral-200">
118124
<div className="flex items-center ">
119125
<div className="tracking-wider">
@@ -234,7 +240,7 @@ export default function ModalSolve() {
234240
</div>
235241
</div>
236242
)}
237-
</div>
243+
</motion.div>
238244
</div>
239245
</>
240246
);

0 commit comments

Comments
 (0)