Dropdown Menu
scrollxui/dropdown-menuFreeComponent
Animated Dropdown Menu Reveals a menu of options or actions when activated by a button.
Live preview
live · rendered by the registry
Rendered by scrollxui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://scrollxui.dev/registry/dropdown-menu.jsonSource
1'use client';23import * as React from 'react';4import { useEffect, useState } from 'react';5import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';6import { CheckIcon, ChevronRightIcon, CircleIcon } from 'lucide-react';7import { motion, AnimatePresence, Variants } from 'motion/react';8import { cn } from '@/lib/utils';910const dropdownVariants: Variants = {11 hidden: {12 opacity: 0,13 scale: 0.5,14 rotateX: 40,15 y: 20,16 },17 visible: {18 opacity: 1,19 scale: 1,20 y: 0,21 rotateX: 0,22 transition: {23 type: 'spring' as const,24 stiffness: 260,25 damping: 15,26 },27 },28 exit: {29 opacity: 0,30 scale: 0.8,31 rotateX: 10,32 y: 10,33 transition: {34 duration: 0.2,35 },36 },37};3839const itemVariants: Variants = {40 hidden: {41 opacity: 0,42 x: -20,43 },44 visible: (i: number) => ({45 opacity: 1,46 x: 0,47 transition: {48 delay: i * 0.05,49 duration: 0.2,50 },51 }),52 exit: {53 opacity: 0,54 x: -20,55 transition: {56 duration: 0.1,57 },58 },59};6061const useMobile = () => {62 const [isMobile, setIsMobile] = useState(false);6364 useEffect(() => {65 const checkIfMobile = () => {66 setIsMobile(67 window.innerWidth < 768 ||68 /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(69 navigator.userAgent,70 ),71 );72 };7374 checkIfMobile();75 window.addEventListener('resize', checkIfMobile);7677 return () => {78 window.removeEventListener('resize', checkIfMobile);79 };80 }, []);8182 return isMobile;83};8485const DropdownMenuContext = React.createContext<{ animate: boolean }>({86 animate: true,87});8889function DropdownMenu({90 animate = true,91 ...props92}: React.ComponentProps<typeof DropdownMenuPrimitive.Root> & {93 animate?: boolean;94}) {95 return (96 <DropdownMenuContext.Provider value={{ animate }}>97 <DropdownMenuPrimitive.Root data-slot='dropdown-menu' {...props} />98 </DropdownMenuContext.Provider>99 );100}101102function DropdownMenuTrigger({103 className,104 children,105 ...props106}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {107 const { animate } = React.useContext(DropdownMenuContext);108109 return (110 <DropdownMenuPrimitive.Trigger111 data-slot='dropdown-menu-trigger'112 className={cn(113 'inline-flex items-center justify-center rounded-lg text-sm font-medium transition-all duration-200',114 'hover:shadow-lg',115 className,116 )}117 asChild118 {...props}119 >120// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from scrollxui
All 180 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | scrollxui | Components | Free | 4 deps | |
| Alert Dialogalert-dialog | scrollxui | Components | Free | 7 deps | |
| Animated Buttonanimated-button | scrollxui | Components | Free | 4 deps | |
| Animated Tabsanimated-tabs | scrollxui | Components | Free | 1 dep | |
| Animated Testimonialsanimated-testimonials | scrollxui | Components | Free | 2 deps | |
| Animated TextGenerateanimated-textgenerate | scrollxui | Components | Free | 3 deps | |
| Announcementannouncement | scrollxui | Components | Free | 5 deps | |
| Aspect Ratioaspect-ratio | scrollxui | Components | Free | 1 dep |
