āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā š shadcn/directory/ibelick/motion-primitives/magnetic/page ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
export const metadata = { title: 'Magnetic - Motion-Primitives', description: 'A magnetic effect for elements that allows them to be attracted to the mouse cursor. Built for React, Next.js, and Tailwind CSS.', };
import { MagneticBasic } from './magnetic-basic'; import { MagneticNested } from './magnetic-nested'; import ComponentCodePreview from '@/components/website/component-code-preview';
A magnetic effect for elements that allows them to be attracted to the mouse cursor.
<ComponentCodePreview component={<MagneticBasic />} filePath='app/docs/magnetic/magnetic-basic.tsx' />
You can nest the Magnetic component to create a more complex effect. Here we use actionArea='global' to make the magnetic effect apply to the global area. We also use custom range to make the magnetic effect apply to a larger area.
<ComponentCodePreview component={<MagneticNested />} filePath='app/docs/magnetic/magnetic-nested.tsx' />
<Step>Copy and paste the following code into your project.</Step>
<CodeBlock filePath='components/core/magnetic.tsx' /><Step>Update the import paths to match your project setup.</Step>
</Steps> </TabsContent> </Tabs>| Prop | Type | Default | Description | | :------------ | :----------------------------- | :------------ | :--------------------------------------------------------------------------------------------- | | children | React.ReactNode | | The child elements to be displayed within the magnetic effect. | | intensity | number | 0.6 | The strength of the magnetic effect, scaling the distance effect. | | range | number | 100 | The effective range in pixels within which the magnetic effect is applied. | | actionArea | 'self' | 'parent' | 'global' | 'self' | Determines whether the magnetic effect is triggered by the component, its parent, or globally. | | springOptions | SpringOptions | SPRING_CONFIG | The spring options to be used for the magnetic effect. |
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā