4) A concise, practical tutorial: install, API, customization, and best practices
What is react-planet and when to use it
react-planet is a small React component pattern for building circular (orbital / radial) navigation menus. Think floating hub-and-spoke menus where items orbit around a central trigger. It’s useful for compact UIs, tool palettes, or playful navigational chrome when screen real estate is limited.
Use this pattern sparingly: circular menus can be highly discoverable for familiar users, but they may confuse new visitors if the affordances are not clear. Prefer them for secondary actions or on dashboards where visual flair complements functionality.
Technically, react-planet renders items positioned with transforms around a center point; animation is achieved with CSS transitions or JS-driven easing. It pairs well with React’s component model and can be extended to render custom JSX for each node, link, or button.
Installation and getting started
Install the package with npm or yarn (standard approach):
npm install react-planet --save
# or
yarn add react-planet
Then import and render it in your component tree. Example minimal usage:
import React from 'react'
import { Planet } from 'react-planet'
export default function App(){
return (
<Planet centerContent={<button>Menu</button>} radius={100}>
<button onClick={() => alert('A')}>A</button>
<button onClick={() => alert('B')}>B</button>
</Planet>
)
}
This pattern quickly gets you a floating circular menu. For a hands-on tutorial and live demo, see a community walkthrough: react-planet tutorial.
Core concepts and API
React-planet typically exposes props for radius, animation timing, and the center trigger content. Common props (varies by implementation) include radius, open/closed state, animation duration, easing function, and an array of children representing menu items.
Key behaviors to understand:
- Radius determines how far items are from the center; ensure values work across breakpoints.
- Animation controls (duration/easing) create entry/exit motion — prefer subtle, short easing for navigation.
- Item rendering is often customizable so you can inject links, icons, or complex components.
Always consult the package README or repo for exact prop names (the community tutorial linked above is a good supplement). If the component lacks a prop you need, wrap the core in a thin adapter component and handle transforms yourself.
Customization and animations
Customizing the visual behavior is where react-planet shines. You can tweak:
- Radius and layout angle (spread items over a full circle or a section)
- Animation duration, delay, and easing curve (CSS transition-timing-function or JS easing)
For polished motion, animate opacity and transform simultaneously: translate/rotate + opacity avoids janky layouts. Use will-change: transform to hint rendering engines to optimize the element before animation starts.
To coordinate staggered entry, compute per-item delay based on index. Example pattern:
const delay = index * 50; // ms
style={{ transition: `transform 300ms cubic-bezier(...), opacity 300ms ${delay}ms` }}
Tip: avoid long stagger delays for primary nav items; they slow perceived responsiveness. Reserve dramatic stagger for non-critical tool palettes.
Accessibility and best practices
A circular UI can be accessible if you design intentionally. Ensure items are reachable by keyboard (tab order or arrow keys), provide aria-labels, and set role attributes (role=”menu”/”menuitem” if appropriate). Avoid relying solely on hover to reveal options.
Touch and mobile: enlarge hit targets (minimum 44–48px), ensure the radius doesn’t push items off-screen on small viewports, and test with common gestures. Use media queries or switch to a linear menu on tiny screens if space is constrained.
Screen readers: provide meaningful labels and manage focus. When the menu opens, either move focus to the first actionable item, or ensure the toggle button has aria-expanded and a clear description. Add keyboard handlers to close the menu with Escape and cycle focus logically.
Examples & integration tips
Examples accelerate adoption. Export a demo sandbox or CodeSandbox URL with basic and advanced cases: default radius, constrained quadrant layout, and custom animated icons. Link these demos from docs and blog posts to boost dwell-time and backlinks.
Integrating with routing: render <Link> or programmatic navigation inside item renderers. When using React Router, ensure events don’t bubble unexpectedly: preventDefault only when necessary, and handle focus changes after navigation.
Performance: if many items are animated simultaneously, avoid heavy layout thrash. Use transform and opacity only. If you need complex per-item calculations, memoize computed positions and avoid recomputing on every render.
Troubleshooting & common pitfalls
Overlapping items: check radius and item size; inspect computed transforms and parent overflow. Clipping often occurs when the container has overflow hidden — move the menu to a portal (ReactDOM.createPortal) to avoid clipping by ancestor containers.
Janky animations: ensure no expensive layout-triggering properties are animated (e.g., top/left). Use transform/opacity and requestAnimationFrame-friendly CSS transitions. Inspect paint/compose layers in devtools if performance lags.
Inconsistent behavior across devices: test on real devices. Mobile browsers may handle touch events differently; ensure passive event listeners where appropriate and avoid capturing touchmove unless necessary.