Magnetic Button

Use Magnetic Button for a playful pointer interaction around a focused call to action. The element shifts toward the pointer within the configured range, then returns to its resting position.

Preview

Reduce motion:Off
Tune:Off
Inspect

Installation

Basic usage

TypeScript
magnetic-action.tsx

Examples

Adjust the range and intensity to keep the response subtle. Use the parent interaction area when the surrounding surface should control the effect.

Usage

API

PropertyTypeDefaultDescription
childrenReactNoderequiredThe content to be rendered inside the magnetic button.
magneticIntensitynumber0.6The intensity of the magnetic pull effect.
magneticRangenumber100The range within which the magnetic effect is active.
interactionArea"self" | "parent""self"Defines the area of interaction for the magnetic effect.
springConfigSpringOptions—Configuration for the spring animation.
customClassNamestring—Additional class names for custom styling.
classNamestring—Additional classes for the wrapper. Prefer this for new usage.

Accessibility

Keep a real interactive element inside the wrapper and provide a clear action label. The pointer response is optional, so the content remains usable with keyboard input.

Styling

Use className on the wrapper and style the child control for the visual treatment. Reduced-motion preferences keep the button at rest.

Contact

Found a bug or need help using this component? Open an issue on GitHub.

License & Usage

Sona UI is available under the MIT license. You may use, modify, and distribute this component in personal and commercial projects.

Was this page helpful?

Your response helps us improve component docs.

Related components