THE PLAYGROUND · SCROLL & NAVIGATION
Floating Action Button Transformation
An action button unfolds into a small menu.
Floating Action Button TransformationScroll & Navigation · An action button unfolds into a small menu.
CLICKCreate something
1import { useState } from "react";2import { motion, AnimatePresence } from "motion/react";3 4const surface = { width: 100, height: 100, borderRadius: 16, background: "#b8ed79", display: "grid", placeItems: "center", color: "#141714" };5 6export default function FabDemo() {7 const [open, setOpen] = useState(false);8 return <div style={{position: "relative", width: 320, minHeight: 200, overflow: "hidden"}}>9 <button aria-expanded={open} onClick={() => setOpen(v => !v)}>Toggle Floating Action Button Transformation</button>10 <AnimatePresence mode="wait">11 {open && <motion.div key="content" initial={{y:100, opacity:0}} animate={{y:0, opacity:1}} exit={{y:100, opacity:0}} transition={{ duration: 0.6, delay: 0, ease: "easeInOut" }} style={{...surface, width: 300, height: "auto", padding: 20}}>12 <p>Details and actions</p><button onClick={() => setOpen(false)}>Close</button>13 </motion.div>}14 </AnimatePresence>15 </div>;16}Install: npm install motion. Keep menu items independently focusable. This compact example illustrates the core technique; the styled playground contains additional presentation details.