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
javascript Article's
30 articles in total
JavaScript is a versatile language for web development, enabling interactive and dynamic user experiences across all major browsers.
Favicon
7 Developer Tools That Will Boost Your Workflow in 2025
Favicon
Creating a live HTML, CSS and JS displayer
Favicon
Designing for developers means designing for LLMs too
Favicon
Unique Symbols: How to Use Symbols for Type Safety
Favicon
Flutter vs React Native in 2025: A Comprehensive Comparison
Favicon
How To Build Beautiful Terminal UIs (TUIs) in JavaScript 2: forms!
Favicon
[Boost]
Favicon
Cómo Iniciar y Crecer como Desarrollador Frontend en 2025
Favicon
Building bun-tastic: A Fast, High-Performance Static Site Server (OSS)
Favicon
My React Journey: Project
Favicon
How to Use JavaScript to Reduce HTML Code: A Simple Example
Favicon
Easy Discount Calculation: Tax, Fees & Discount Percentage Explained
Favicon
GraphQL Transforming API Development
Favicon
7 Mistakes Developers Make When Learning a New Framework (and How to Avoid Them)
Favicon
Why Is Everyone Unhappy With JavaScript? | State of Javascript 2024 Survey
Favicon
Decreasing server load by using debouncing/throttle technique in reactjs
Favicon
What is Next Js: A Beginner's guide to Next Js
Favicon
Angular Addicts #33: NgRx 19, using the Page Object Model in tests, Micro Frontends using Vite & more
Favicon
Debugging Adventure Day 1: What to Do When Your Code Doesn’t Work
Favicon
10 Must-Bookmark Open Source Projects for Developers
Favicon
Build a Secure Password Generator with Javascript
Favicon
Everything you need to know about load testing concurrent users
Favicon
forms in the terminal w/ JavaScript? if you love Terminal UI's check this out!
Favicon
340+ Websites every developer should know
Favicon
Learning Vue
Favicon
Test Scenarios vs. Test Cases: Understanding the Differences
Favicon
LeetCode Challenge: 290. Word Pattern - JavaScript Solution 🚀
Favicon
Understanding Node.js Cluster: The Core Concepts
Favicon
Speed Up Your Frontend Development 10x with These Mock Tools 🚀
Favicon
[Boost]

Featured ones: