Dropdown Menu
NewInstallation
npx shadcn@latest add https://uibrik.com/r/dropdown-menu.jsonInstall the packages
npm install motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/dropdown-menu/dropdown-menu.tsx"use client"; // A menu that opens from a button: items with icons and shortcuts, checkbox // and radio items, labels, separators and submenus. Click or Enter opens it; // arrows, Home/End and typing move through it; Escape or a click outside // closes it and hands focus back to the button. import { AnimatePresence } from "motion/react"; import { useEffect, useRef, useState, type KeyboardEvent, type ReactNode } from "react"; import { MenuPanel, type MenuItem } from "../_overlay/menu"; import { Portal, triggerBox, useDismiss, useLayer, type Align, type Side } from "../_overlay/overlay"; export type { MenuItem }; export type DropdownMenuProps = { /** The button that opens the menu. */ children: ReactNode; items: readonly MenuItem[]; side?: Side; align?: Align; /** Gap between button and menu in px. */ offset?: number; /** Controlled open state. Pair with `onOpenChange`. */ open?: boolean;
Adds the files to
components/uibrik/dropdown-menu and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/dropdown-menu.Props
DropdownMenu- side
- Type "bottom" | "top" | "right" | "left"
- "bottom"
- Preferred side. Flips when there isn't room.
- align
- Type "start" | "center" | "end"
- "start"
- Which edge of the button the menu lines up with.
- offset
- Type number
- 6
- Gap between button and menu.
- childrenrequired
- Type ReactNode
- –
- The button that opens the menu.
- itemsrequired
- Type MenuItem[]
- –
- { label, icon?, shortcut?, onSelect?, danger?, disabled? }, or with type: checkbox (checked, onCheckedChange), radio (checked, onSelect), sub (items), label, separator.
- open / onOpenChange
- Type boolean / (open) => void
- –
- Controlled open state.
- className
- Type string
- –
- Classes for the menu panel.