本文へ移動
日本語
「マグネティックボタン」は Pro に含まれます。解除するとプレビューが表示されます。

仕組み

A transparent sensing area wraps the button. While the pointer moves inside it, the button shifts by pointer-to-center distance × strength, and the label shifts a further 30% for depth. Following uses a 140ms ease-out to feel immediate; leaving uses a 600ms spring. Mouse only: touch and reduced motion do not move it.

向いている場面

  • The single most important call to action on a landing or campaign page.
  • A guiding button inside an empty state.

向かない場面

  • Frequent buttons such as form submit or list actions: the movement hurts click accuracy.
  • More than one per screen: several moving buttons feel restless.

使い方

import { MagneticButton } from './MagneticButton.jsx'

export function Hero() {
  return (
    <MagneticButton strength={0.35} onClick={() => startTrial()}>
      Try it now
    </MagneticButton>
  )
}

プロパティ

プロパティ型既定値説明
strengthnumber0.35Pull strength from 0 to 1: how far the button follows the pointer.
radiusnumber28Sensing range in px: how close the pointer must be to the button edge before it is pulled.
variant'solid' | 'outline' | 'ink''solid'Visual style: accent-filled solid, a raised outline with a hairline ring, or ink (text colour, inverts in dark). Each opens a soft 6px halo while pulled.
...restButtonHTMLAttributes—Other attributes go to the <button>, such as onClick and disabled (a disabled button neither pulls nor shows hover).

アクセシビリティ

  • Keyboard focus shows a focus ring and causes no movement.
  • Touch devices get no pull.
  • With reduced motion the button does not move; hover colour and shadow still appear while the pointer is on it.

モーション

Follow: 140ms ease-out. Return: 600ms spring. Halo opens to 6px and the shadow deepens in 240ms ease-out; a trailing icon leans 2px forward. Press scales to 0.96.

プロジェクトに追加

Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。

MagneticButton.jsxmagnetic-button.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

ボタン
「オーロラ縁ボタン」は Pro に含まれます。解除するとプレビューが表示されます。
「かじりボタン」は Pro に含まれます。解除するとプレビューが表示されます。