### Install Bloom Menu and Framer Motion Source: https://github.com/joshpuckett/bloom/blob/main/README.md Installs the bloom-menu package and its peer dependency framer-motion using npm. This is the initial setup step for using the Bloom component library. ```bash npm install bloom-menu framer-motion ``` -------------------------------- ### Bloom Menu Direction and Anchor Configuration Examples Source: https://context7.com/joshpuckett/bloom/llms.txt Illustrates how to control the expansion direction and alignment anchor point of the menu. Examples cover 'top', 'bottom', 'left', and 'right' directions with 'start', 'center', and 'end' anchors. ```tsx import { Menu } from 'bloom-menu' import { Plus } from 'lucide-react' // All direction and anchor combinations function DirectionAnchorExamples() { return (
{/* Expands upward, aligned to start (left) */} {}}>Top + Start {/* Expands upward, centered on trigger */} {}}>Top + Center {/* Expands downward, aligned to end (right) */} {}}>Bottom + End {/* Expands to the left (anchor forced to center for horizontal) */} {}}>Left Direction {/* Expands to the right (anchor forced to center for horizontal) */} {}}>Right Direction
) } ``` -------------------------------- ### Bloom Menu Content Wrapper Example (React/TSX) Source: https://context7.com/joshpuckett/bloom/llms.txt Demonstrates the Menu.Content component, which acts as a wrapper for menu items. It fades in with a delay after the container animation, providing a polished reveal. This example shows how to import necessary components and icons, and how to structure the menu with trigger and content, including styling and event handling. ```tsx import { Menu } from 'bloom-menu' import { Pencil, Trash2, Copy, Share } from 'lucide-react' function ContentExample() { return ( Menu console.log('Content animation finished')} > console.log('Edit clicked')}> Edit console.log('Copy clicked')}> Copy console.log('Share clicked')}> Share console.log('Delete clicked')}> Delete ) } ``` -------------------------------- ### Bloom Menu.Trigger Component Examples Source: https://context7.com/joshpuckett/bloom/llms.txt Shows how to use the Menu.Trigger component for the clickable element that opens the menu. Examples include using icons as triggers and disabling the trigger to prevent interaction. ```tsx import { Menu } from 'bloom-menu' import { MoreHorizontal, Plus } from 'lucide-react' function TriggerExample() { return ( {/* Icon trigger */} {/* Menu items */} ) } // Disabled trigger function DisabledTriggerExample() { return ( {/* Content won't be accessible */} ) } ``` -------------------------------- ### Bloom Menu Overlay Examples Source: https://context7.com/joshpuckett/bloom/llms.txt Demonstrates how to use the Menu.Overlay component for an animated backdrop. It shows a default overlay that closes the menu on click and a custom overlay with a specific click handler. ```tsx import { Menu } from 'bloom-menu' function OverlayExample() { return ( {/* Overlay with semi-transparent backdrop */} Menu {}}> Click overlay to dismiss ) } // Custom overlay click handler function CustomOverlayExample() { return ( { console.log('Custom overlay action') // Perform custom action instead of closing }} className="bg-black/30" /> + {}}>Item ) } ``` -------------------------------- ### Bloom useBloomContext Hook Example Source: https://context7.com/joshpuckett/bloom/llms.txt Demonstrates how to use the `useBloomContext` hook to access and manipulate the internal menu state from custom components. This example shows a custom 'Cancel' button that closes the menu. ```tsx import { Menu, useBloomContext } from 'bloom-menu' // Custom component that uses menu context function CustomCloseButton() { const { setOpen, open } = useBloomContext() if (!open) return null return ( ) } function ContextHookExample() { return ( Open console.log('Confirmed')}> Confirm Action {/* Custom component using context */} ) } ``` -------------------------------- ### Bloom Menu Item Configuration Example (React/TSX) Source: https://context7.com/joshpuckett/bloom/llms.txt Illustrates the Menu.Item component, designed for individual menu entries. It supports hover highlighting, selection handling, and an optional auto-close behavior. This example showcases standard items, items that remain open on selection, disabled items, and items with specific styling for actions like 'Log Out'. ```tsx import { Menu } from 'bloom-menu' import { Settings, LogOut, User, Bell } from 'lucide-react' function ItemExample() { const handleLogout = () => { console.log('Logging out...') // Perform logout } return ( {/* Standard item - closes menu on select */} console.log('Profile selected')} className="flex items-center gap-2 px-3 py-2 rounded-lg hover:bg-gray-100" > Profile {/* Item that stays open after selection */} console.log('Notifications toggled')} closeOnSelect={false} className="flex items-center gap-2 px-3 py-2 rounded-lg hover:bg-gray-100" > Toggle Notifications {/* Disabled item */} Settings (Coming Soon) {/* Danger item */} Log Out ) } ``` -------------------------------- ### Bloom Menu.Container Component Examples Source: https://context7.com/joshpuckett/bloom/llms.txt Illustrates the Menu.Container component, which acts as the morphing element between the trigger and the menu. Examples show configuring button and menu dimensions, radii, and applying custom styles. ```tsx import { Menu } from 'bloom-menu' function ContainerExample() { return ( {/* Square button (40x40px) that expands to 200px wide menu */} + {/* Menu items */} ) } // Rectangular button with custom closed radius function RectangularButtonExample() { return ( Options {/* Menu items */} ) } ``` -------------------------------- ### Bloom Menu.Root Component Examples Source: https://context7.com/joshpuckett/bloom/llms.txt Demonstrates the usage of the Menu.Root component for managing menu state and animation configuration. It supports both uncontrolled (internal state) and controlled (external state) modes, along with custom animation settings. ```tsx import { Menu } from 'bloom-menu' import { useState } from 'react' // Uncontrolled usage (internal state management) function UncontrolledMenu() { return ( {/* Menu children go here */} ) } // Controlled usage (external state management) function ControlledMenu() { const [isOpen, setIsOpen] = useState(false) return ( {/* Menu children go here */} ) } // With custom animation configuration function CustomAnimationMenu() { return ( {/* Menu children go here */} ) } ``` -------------------------------- ### Configure Bloom Menu Expansion Direction and Anchor Source: https://github.com/joshpuckett/bloom/blob/main/README.md Illustrates how to control the expansion direction and anchor alignment of the Bloom menu. The 'direction' prop accepts 'top', 'bottom', 'left', or 'right', while 'anchor' accepts 'start', 'center', or 'end'. ```tsx {/* Expands up, aligned to start */} {/* Expands down, centered */} {/* Expands left, aligned to end */} ``` -------------------------------- ### Basic Bloom Menu Implementation in React Source: https://github.com/joshpuckett/bloom/blob/main/README.md Demonstrates a basic implementation of the Bloom menu component in a React application. It shows how to import and use Menu.Root, Menu.Container, Menu.Trigger, and Menu.Content with Menu.Item components. Requires lucide-react for icons. ```tsx import { Menu } from 'bloom-menu' import { MoreHorizontal, Pencil, Trash } from 'lucide-react' function Example() { return ( console.log('edit')}> Edit console.log('delete')}> Delete ) } ``` -------------------------------- ### Apply Bloom Menu Animation Presets Source: https://github.com/joshpuckett/bloom/blob/main/README.md Shows how to apply different animation presets to the Bloom menu using the 'animation' prop. Available presets include 'snappy', 'gentle', and 'relaxed'. Custom spring configurations can also be provided. ```tsx {/* Quick ease-out curve */} {/* Default, smooth spring */} {/* Slower, laid-back spring */} {/* Or use custom spring config */} ``` -------------------------------- ### Create Nested Submenus with Bloom Menu (React) Source: https://context7.com/joshpuckett/bloom/llms.txt Demonstrates how to create nested submenus using Menu.SubMenu, Menu.SubMenuTrigger, and Menu.SubMenuContent from the 'bloom-menu' library. This system supports smooth animations and proper focus management for an enhanced user experience. It requires 'lucide-react' for icons. ```tsx import { Menu } from 'bloom-menu' import { ChevronRight, Palette, Sun, Moon, Monitor, Check } from 'lucide-react' function SubMenuExample() { const [theme, setTheme] = useState('system') return ( console.log('Option 1')}> Option 1 {/* SubMenu with unique id */} {/* SubMenuTrigger supports render props for active state */} {(isActive) => ( <> Theme )} {/* SubMenuContent renders the nested items */} setTheme('light')} className="flex items-center gap-2 px-3 py-2 rounded-lg hover:bg-gray-100" > Light {theme === 'light' && } setTheme('dark')} className="flex items-center gap-2 px-3 py-2 rounded-lg hover:bg-gray-100" > Dark {theme === 'dark' && } setTheme('system')} className="flex items-center gap-2 px-3 py-2 rounded-lg hover:bg-gray-100" > System {theme === 'system' && } console.log('Option 2')}> Option 2 ) } ``` -------------------------------- ### React Animation Utilities with Framer Motion Source: https://context7.com/joshpuckett/bloom/llms.txt Demonstrates the usage of pre-configured animation constants and spring configurations from 'bloom-menu' with Framer Motion in a React application. It showcases default transitions, delayed fade-ins, reduced motion fallbacks, and blur effects. ```tsx import { transitionConfig, contentTransitionConfig, reducedMotionSpring, CONTENT_ENTER_DELAY, TRIGGER_BLUR, CONTENT_BLUR } from 'bloom-menu' import { motion } from 'framer-motion' function AnimationUtilitiesExample() { return (
{/* Use the default menu spring config */} Default spring animation {/* Use content-specific timing */} Content with delayed fade-in {/* Reduced motion fallback */} Instant transition for reduced motion {/* Use blur constants */} Blur transition using constants
) } // Available exports: // transitionConfig = { type: 'spring', visualDuration: 0.25, bounce: 0.2 } // contentTransitionConfig = { type: 'spring', visualDuration: 0.3, bounce: 0.2 } // reducedMotionSpring = { stiffness: 1000, damping: 100 } // CONTENT_ENTER_DELAY = 0.08 // TRIGGER_BLUR = 8 // CONTENT_BLUR = 8 ``` -------------------------------- ### Complete Menu Implementation in React Source: https://context7.com/joshpuckett/bloom/llms.txt This React component demonstrates a full-featured menu using the 'bloom-menu' library. It showcases styling, submenus, controlled state, and accessibility features. Dependencies include 'react', 'bloom-menu', and 'lucide-react' for icons. ```tsx import { Menu } from 'bloom-menu' import { useState } from 'react' import { MoreHorizontal, Pencil, Copy, Trash2, Share, ChevronRight, Twitter, Facebook, Link, Check } from 'lucide-react' function CompleteMenuExample() { const [isOpen, setIsOpen] = useState(false) const [copied, setCopied] = useState(false) const handleCopy = () => { navigator.clipboard.writeText(window.location.href) setCopied(true) setTimeout(() => setCopied(false), 2000) } const handleDelete = () => { if (confirm('Are you sure you want to delete this item?')) { console.log('Item deleted') } } return ( {/* Optional overlay */} {/* Standard items */} console.log('Edit')} className="flex items-center gap-3 px-3 py-2.5 rounded-xl text-gray-700 hover:bg-gray-100 transition-colors" > Edit {copied ? : } {copied ? 'Copied!' : 'Copy Link'} {/* Share submenu */} {(isActive) => ( <> Share )} window.open('https://twitter.com/intent/tweet')} className="flex items-center gap-3 px-3 py-2.5 rounded-lg text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition-colors" > Twitter window.open('https://facebook.com/sharer')} className="flex items-center gap-3 px-3 py-2.5 rounded-lg text-gray-700 hover:bg-blue-50 hover:text-blue-600 transition-colors" > Facebook Copy Link {/* Divider */}
{/* Danger item */} Delete ) } export default CompleteMenuExample ``` -------------------------------- ### Render Bloom Menu Content in a Portal (React) Source: https://context7.com/joshpuckett/bloom/llms.txt Illustrates the use of Menu.Portal from 'bloom-menu' to render menu content in a React portal, bypassing DOM hierarchy constraints. This is useful for avoiding clipping issues caused by overflow:hidden or z-index stacking contexts. It supports rendering to the document body or a custom DOM element. ```tsx import { Menu } from 'bloom-menu' import { useRef } from 'react' function PortalExample() { const customContainer = useRef(null) return ( <> {/* Custom portal target */}