dev-resources.site
for different kinds of informations.
Animated Select component using typescript, shadcn and framer-motion
Published at
1/15/2025
Categories
webdev
javascript
frontend
frontendchallenge
Author
Bro Karim
The "Expand Select Animation" is a custom select component built using TypeScript and Framer Motion, with the base component provided by ShadCN. This component enhances the standard select element with a smooth, visually appealing animation that expands downward to reveal options and collapses upward to hide them.
Demo
// Detect dark theme var iframe = document.getElementById('tweet-1878086086502887693-992'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1878086086502887693&theme=dark" }
Source Code
expand-select.tsx
import { Globe } from "lucide-react";
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { motion, AnimatePresence } from "framer-motion";
export function ExapandSelect() {
return (
<Select>
<SelectTrigger className="text-white w-[180px]flex gap-2 bg-[#1a1a1a] hover:bg-[#3e3d3d] ring-none border-none ">
<Globe />
<SelectValue placeholder="English" />
</SelectTrigger>
<AnimatePresence>
<SelectContent className="bg-[#3e3d3d] text-white border-none p-[1px]">
<motion.div
initial={{ opacity: 0, height: 0, scale: 0.95 }}
animate={{
opacity: 1,
height: "auto",
scale: 1,
transition: {
type: "spring",
stiffness: 300,
damping: 30,
},
}}
exit={{
opacity: 0,
height: 0,
scale: 0.95,
transition: {
duration: 0.2,
},
}}
style={{ transformOrigin: "center" }}
>
<SelectGroup>
<SelectItem className=" focus:bg-[#1a1a1a] focus:text-white" value="eng">
English
</SelectItem>
<SelectItem className=" focus:bg-[#1a1a1a] focus:text-white" value="france">
Français
</SelectItem>
<SelectItem className=" focus:bg-[#1a1a1a] focus:text-white" value="spain">
Español
</SelectItem>
<SelectItem className=" focus:bg-[#1a1a1a] focus:text-white" value="deutsch">
Deutsch
</SelectItem>
<SelectItem className=" focus:bg-[#1a1a1a] focus:text-white" value="china">
中国
</SelectItem>
</SelectGroup>
</motion.div>
</SelectContent>
</AnimatePresence>
</Select>
);
}
Articles
12 articles in total
Animated Select component using typescript, shadcn and framer-motion
currently reading
Animated Hover Logo using Typescript, Tailwind and Framer Motion
read article
Animated Video Tooltip using typescript and framer-motion
read article
Handling Local Storage for Toaster Notifications
read article
Journey In Learning Pandas
read article
Docker Compose in Action : A Real Case Study for Nextjs Projects
read article
Docker on Windows: Led Into Container Wonderland
read article
Effortless Payments with Lemon Squeezy | Next.js Integration Made Simple
read article
Newsletter with Next.js | Nextjs Mailchimp API Integration✉️
read article
🍔My Minimal Web Portofolio as Frontend, Build with Nextjs
read article
📂How to compile and run MDX in React
read article
🌈How to Create a Theme with ReactJS and Tailwind CSS
read article
Featured ones: