|
| 1 | +--- |
| 2 | +title: React UI |
| 3 | +description: Free installable React building blocks for cursor.js. |
| 4 | +--- |
| 5 | + |
| 6 | +import { Step, Steps } from 'fumadocs-ui/components/steps'; |
| 7 | + |
| 8 | +`CursorPlayer` is a free, installable React UI block for cursor.js. It gives you a visible cursor anchor plus composable play, pause, and stop controls while keeping the code fully editable inside your app. |
| 9 | + |
| 10 | +## Preview |
| 11 | + |
| 12 | +<CursorPlayerShowcase /> |
| 13 | + |
| 14 | +## Overlay example |
| 15 | + |
| 16 | +In tighter layouts, you can stack `PlayPause` on top of the waiting cursor and keep it quiet until hover. |
| 17 | + |
| 18 | +<CursorPlayerOverlayShowcase /> |
| 19 | + |
| 20 | +## Installation |
| 21 | + |
| 22 | +<Tabs items={["Command", "Manual"]}> |
| 23 | +<Tab> |
| 24 | + |
| 25 | +```bash |
| 26 | +pnpm dlx shadcn@latest add https://cursorjs.com/r/cursor-player.json |
| 27 | +``` |
| 28 | + |
| 29 | +</Tab> |
| 30 | +<Tab> |
| 31 | + |
| 32 | +<Steps className="mb-0 pt-2"> |
| 33 | +<Step> |
| 34 | + |
| 35 | +Copy the registry files into your app: |
| 36 | + |
| 37 | +- `@components/cursor-player.tsx` |
| 38 | +- `@hooks/use-cursor-player.ts` |
| 39 | + |
| 40 | +<CursorPlayerSourceFiles /> |
| 41 | + |
| 42 | +</Step> |
| 43 | + |
| 44 | +<Step> |
| 45 | + |
| 46 | +Install the peer dependencies used by the block: |
| 47 | + |
| 48 | +```bash |
| 49 | +pnpm add @cursor.js/core lucide-react |
| 50 | +``` |
| 51 | + |
| 52 | +</Step> |
| 53 | + |
| 54 | +<Step> |
| 55 | + |
| 56 | +Make sure your app already has shadcn `button` or adjust the import paths to match your project structure. |
| 57 | + |
| 58 | +</Step> |
| 59 | +</Steps> |
| 60 | + |
| 61 | +</Tab> |
| 62 | +</Tabs> |
| 63 | + |
| 64 | +## Usage |
| 65 | + |
| 66 | +```tsx |
| 67 | +import { Cursor } from '@cursor.js/core'; |
| 68 | +import { Pause, Play } from 'lucide-react'; |
| 69 | +import { CursorPlayer } from '@/components/cursor-player'; |
| 70 | + |
| 71 | +function createSignupCursor(anchorElement: HTMLElement) { |
| 72 | + const cursor = new Cursor({ |
| 73 | + humanize: true, |
| 74 | + speed: 0.7, |
| 75 | + startPoint: anchorElement, |
| 76 | + }); |
| 77 | + |
| 78 | + return cursor; |
| 79 | +} |
| 80 | + |
| 81 | +function buildSignupSequence(cursor: Cursor) { |
| 82 | + cursor |
| 83 | + .hover('#email') |
| 84 | + .type('#email', 'hello@cursorjs.com', { delay: 50 }) |
| 85 | + .click('#join') |
| 86 | + .wait(350); |
| 87 | +} |
| 88 | + |
| 89 | +export function DemoLauncher() { |
| 90 | + return ( |
| 91 | + <CursorPlayer createCursor={createSignupCursor} buildSequence={buildSignupSequence}> |
| 92 | + <CursorPlayer.Cursor className="size-5" /> |
| 93 | + |
| 94 | + <CursorPlayer.PlayPause> |
| 95 | + <CursorPlayer.PlayIcon asChild> |
| 96 | + <Play className="size-4 fill-current" /> |
| 97 | + </CursorPlayer.PlayIcon> |
| 98 | + <CursorPlayer.PauseIcon asChild> |
| 99 | + <Pause className="size-4 fill-current" /> |
| 100 | + </CursorPlayer.PauseIcon> |
| 101 | + </CursorPlayer.PlayPause> |
| 102 | + |
| 103 | + <CursorPlayer.StopButton /> |
| 104 | + </CursorPlayer> |
| 105 | + ); |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +`CursorPlayer.Cursor` uses its real rendered size as the preview frame. If you change it with classes like `size-5` or `w-6 h-6`, the waiting cursor is scaled to fit that box automatically. |
| 110 | + |
| 111 | +## Composition |
| 112 | + |
| 113 | +Use the following composition to build a `CursorPlayer`: |
| 114 | + |
| 115 | +```text |
| 116 | +CursorPlayer |
| 117 | +|- CursorPlayer.Cursor |
| 118 | +|- CursorPlayer.PlayPause |
| 119 | +| |- CursorPlayer.PlayIcon |
| 120 | +| `- CursorPlayer.PauseIcon |
| 121 | +`- CursorPlayer.StopButton |
| 122 | +``` |
| 123 | + |
| 124 | +When a run completes, `CursorPlayer` restores its waiting preview at the anchor automatically. In most cases you should not manually move back to `anchorElement` at the end of the sequence. |
| 125 | + |
| 126 | +## Behavior patterns |
| 127 | + |
| 128 | +The end of a cursor.js demo should usually be modeled in the sequence itself instead of a separate global `endBehavior` option. |
| 129 | + |
| 130 | +- Stop chaining actions if the demo should finish where it ended. |
| 131 | +- Move back to a known anchor and call `.do(buildDemoSequence)` if it should loop. |
| 132 | + |
| 133 | +```tsx |
| 134 | +function buildDemoSequence(cursor: Cursor) { |
| 135 | + cursor |
| 136 | + .hover('#email') |
| 137 | + .type('#email', 'hello@cursorjs.com') |
| 138 | + .click('#join') |
| 139 | + .wait(350); |
| 140 | +} |
| 141 | +``` |
| 142 | + |
| 143 | +## Included |
| 144 | + |
| 145 | +The block includes: |
| 146 | + |
| 147 | +- `CursorPlayer` |
| 148 | +- `CursorPlayer.Cursor` |
| 149 | +- `CursorPlayer.PlayPause` |
| 150 | +- `CursorPlayer.PlayIcon` |
| 151 | +- `CursorPlayer.PauseIcon` |
| 152 | +- `CursorPlayer.StopButton` |
| 153 | +- `useCursorPlayer` |
0 commit comments