Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Backgrounds

  • DotPattern
  • GridPattern
  • StripedPattern
  • Spotlight
  • FadeMask
  • RetroGrid
  • Ripple
  • Meteors
  • Aurora
  • Particles
  • FlickeringGrid
  • WavyBackground
  • Silk
  • Iridescence
  • Threads
  • Orb
  • LiquidChrome
  • Balatro
  • Ballpit
  • Beams
  • ColorBends
  • DarkVeil
  • Dither
  • DotField
  • EvilEye
  • FaultyTerminal
  • Ferrofluid
  • FloatingLines
  • Galaxy
  • GradientBlinds
  • Grainient
  • GridDistortion
  • GridMotion
  • GridScan
  • Hyperspeed
  • LetterGlitch
  • Lightfall
  • Lightning
  • LightPillar
  • LightRays
  • LineWaves
  • LiquidEther
  • PixelBlast
  • PixelSnow
  • Plasma
  • PlasmaWave
  • Prism
  • PrismaticBurst
  • Radar
  • RippleGrid
  • ShapeGrid
  • SideRays
  • SoftAurora

Overlay Effects

  • BorderBeam
  • ShineBorder
  • GlareHover
  • Lens
  • AnimatedBeam
  • OrbitingCircles
  • ProgressiveBlur
  • CardSpotlight
  • Reveal
  • Antigravity
  • BlobCursor
  • ClickSpark
  • Crosshair
  • ElectricBorder
  • GhostCursor
  • GradualBlur
  • ImageTrail
  • LaserFlow
  • MagicRings
  • Magnet
  • MagnetLines
  • MetaBalls
  • MetallicPaint
  • OrbitImages
  • PixelTrail
  • PixelTransition
  • Ribbons
  • ShapeBlur
  • SplashCursor
  • StarBorder
  • StickerPeel
  • TargetCursor
  • Cubes
  • Tilt
  • BorderGlow
  • GlassIcons
  • GlassSurface
  • Lanyard
  • ModelViewer
  • FluidGlass

Magnet

magnet

Pulls child content toward the pointer within a configurable attraction radius.

Usage

Basic usage

Wrap any content, the pointer will be magnetically attracted to follow when it is close to the sensing area, and will return smoothly when it leaves.

Pull me over
tsx
<Magnet padding={100} magnetStrength={2}>
  <button className="rounded-full bg-primary px-6 py-3 text-primary-foreground">
    Pull me over
  </button>
</Magnet>

Strong suction

magnetStrength The smaller the value, the stronger the suction; when it is 1, the content almost sticks to the pointer.

Strong magnetic attraction
tsx
<Magnet padding={140} magnetStrength={1}>
  <button className="rounded-full bg-primary px-6 py-3 text-primary-foreground">
    Strong magnetic attraction
  </button>
</Magnet>

Large sensing area + weak suction

padding Turn up the "long range sensing", magnetStrength turn it up to make the displacement more restrained.

✦
tsx
<Magnet padding={180} magnetStrength={5}>
  <span className="inline-flex h-16 w-16 items-center justify-center rounded-2xl border bg-surface shadow-md">
    ✦
  </span>
</Magnet>

Disable magnetic suction

Stop pulling when disabled, the content remains centered, and the structure of DOM remains unchanged.

Disabled
tsx
<Magnet disabled>
  <button className="rounded-full bg-primary px-6 py-3 text-primary-foreground">
    Disabled
  </button>
</Magnet>

When to Use

Wrap a single interactive element (a button, icon, or CTA) when it should move toward a nearby pointer and return smoothly on leave. For an area-wide cursor or image trail, use GhostCursor or ImageTrail. Magnet inherits HTMLAttributes<HTMLDivElement> except children and forwards the remaining div attributes.

Import

ts
import { Magnet } from "@hulianui/ui"

Props

NameTypeDefaultDescription
paddingnumber100Detection radius in pixels, extending beyond the element boundary
disabledbooleanfalseDisables attraction and returns the element smoothly to its origin without changing the DOM structure
magnetStrengthnumber2Attraction divisor: displacement = pointer-to-center distance / this value. Lower values are stronger; recommended range 1-6
activeTransitionstring"transform 0.3s ease-out"Transition while the element follows the pointer
inactiveTransitionstring"transform 0.5s ease-in-out"Inactive state transition (when leaving homing)
wrapperClassNamestring-Additional class name for the outer wrapper div
innerClassNamestring-Forward the inner displacement div (carrying transform) additional className
styleCSSProperties-Inline styles forwarded to the outer wrapper div
Also inherits all standard div properties of Omit<HTMLAttributes<HTMLDivElement>, "children">.

Slots

SlotTypeDescription
childrenReactNodeMagnetic content (buttons, icons, cards, etc.)

Usage Guidelines

  • magnetStrength is a divisor, not a multiplier: the smaller the value, the stronger the suction force (=1 almost sticks to the pointer), don’t understand it the other way around.
  • Reduced-motion limits displacement and keeps the interaction subtle. Do not rely on magnetic movement for essential actions.

Related

BorderBeam · ShineBorder · GlareHover · Lens · AnimatedBeam · OrbitingCircles

Playground

Pull me over
<Magnet
  padding={100}
  magnetStrength={2}
  disabled={false}
>
  <button className="rounded-full bg-primary px-6 py-3 text-primary-foreground">
    Pull me over
  </button>
</Magnet>
PreviousMagicRingsDecorationNextMagnetLines

On this page

  • Usage
  • Documentation
    • When to Use
    • Import
    • Props
    • Slots
    • Usage Guidelines
    • Related
  • Playground