Skip to content

Commit 36a43b6

Browse files
authored
Merge pull request #121 from cursor-js/feat/cursor-startpoint-react-ui
feat: add cursor startPoint and react ui player
2 parents 15cbae8 + 0d048a6 commit 36a43b6

18 files changed

Lines changed: 1434 additions & 8 deletions

File tree

‎.changeset/calm-carpets-learn.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cursor.js/core': minor
3+
---
4+
5+
Add `startPoint` support to `Cursor` so new cursor instances can spawn from an element, selector, or explicit coordinates instead of flashing from the top-left corner. New cursors now also fade in from their initial position, and UI examples such as `CursorPlayer` can pass the clicked trigger element directly into the core API.

‎apps/docs/content/docs/core-api/cursor.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const cursor = new Cursor({
2222
speed: 1.2,
2323
humanize: true,
2424
size: 1.5,
25+
startPoint: '.login-button',
2526
});
2627

2728
cursor.use(new RipplePlugin({ color: 'rgba(0,0,0,0.2)', size: 50, duration: 800 }));

‎apps/docs/content/docs/meta.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"pages": ["index", "installation", "skill", "core-api", "plugins"]
2+
"pages": ["index", "installation", "skill", "ui", "core-api", "plugins"]
33
}

‎apps/docs/content/docs/ui.mdx‎

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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`

‎apps/docs/registry.json‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"$schema": "https://ui.shadcn.com/schema/registry.json",
3+
"name": "cursorjs-ui",
4+
"homepage": "https://cursorjs.com/docs/ui",
5+
"items": [
6+
{
7+
"name": "cursor-player",
8+
"type": "registry:block",
9+
"title": "Cursor Player",
10+
"description": "A free compound component for starting, pausing, resuming, and stopping cursor.js demos.",
11+
"dependencies": ["@cursor.js/core", "lucide-react"],
12+
"registryDependencies": ["button"],
13+
"files": [
14+
{
15+
"path": "registry/default/cursor-player/cursor-player.tsx",
16+
"type": "registry:component",
17+
"target": "@components/cursor-player.tsx"
18+
},
19+
{
20+
"path": "registry/default/cursor-player/use-cursor-player.ts",
21+
"type": "registry:hook",
22+
"target": "@hooks/use-cursor-player.ts"
23+
}
24+
]
25+
}
26+
]
27+
}

0 commit comments

Comments
 (0)