Logo

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
brokarim
Author
8 person written this
brokarim
open
Animated Select component using typescript, shadcn and framer-motion

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

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>
  );
}

Enter fullscreen mode Exit fullscreen mode
frontend Article's
30 articles in total
Favicon
[Boost]
Favicon
💡 Smarter UX, AI-Powered Design & HTML in 2025
Favicon
5 Fun Projects to Master ES6 Javascript Basics in 2025 🚀👨‍💻
Favicon
POST ABOUT AI'S INCREASING INFLUENCE IN CODING
Favicon
Truncating Text with Text-Overflow
Favicon
5 Tools Every Developer Should Know in 2025
Favicon
Checkout the new @defer in Angular
Favicon
Speed Up Your Frontend Development 10x with These Mock Tools 🚀
Favicon
Animated Select component using typescript, shadcn and framer-motion
Favicon
[Boost]
Favicon
Deferred loading with @defer: Optimize Your App's Performance
Favicon
Understanding React's useState with Callback Functions: A Deep Dive
Favicon
Hello World from Anti-chaos
Favicon
微前端
Favicon
How to improve the Frontend part of the project using one button as an example :))))
Favicon
Things About Contexts in Front-end Projects
Favicon
37 Tip dành cho sự nghiệp của Frontend Develop (P1)
Favicon
How to Load Remote Components in Vue 3
Favicon
Emotional Resilience: A Key to Success Across Fields
Favicon
Middlewares: O que são e como utilizar no Nuxt.JS
Favicon
Recreating the Interswitch Homepage with React and TailwindCSS.
Favicon
Create Stunning Gradual Div Reveals with JavaScript setTimeout and CSS Transitions
Favicon
Master GrapesJS: Build Stunning Web Pages and Seamlessly Integrate Grapes Studio SDK
Favicon
Magic of Axios Interceptors: A Deep Dive
Favicon
The Ultimate Guide to Trusting QuickBooks in Your Browser for Business Efficiency
Favicon
8 Common Front-End Developer Interview Questions For 2025
Favicon
[Boost]
Favicon
The System of UI Components in Front-end Projects
Favicon
Transform Your Web Development Workflow with These JavaScript Giants
Favicon
Animated Hover Logo using Typescript, Tailwind and Framer Motion

Featured ones: