tldraw icon indicating copy to clipboard operation
tldraw copied to clipboard

Add support for custom cursor components

Open jamesbvaughan opened this issue 3 years ago • 6 comments

This introduces a new prop on the Renderer component that allows users integrating with @tldraw/core to provide custom components to override parts of the default UI.

At this point, the only thing you can override is the component that's rendered for multiplayer cursors.

The only change to the default behavior here for users who don't provide a custom cursor component is that the default multiplayer cursors are now wrapped in a <div>. I don't love adding an extra level of depth to the HTML like that, so I'd love suggestions for other ways to implement this that keep the API simple without introducing breaking changes or extra HTML elements.

Please let me know if there are any code style or general structural issues with this implementation that I can clean up or fix.

jamesbvaughan avatar Sep 21 '22 04:09 jamesbvaughan

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
core ✅ Ready (Inspect) Visit Preview Sep 24, 2022 at 7:32PM (UTC)
tldraw ✅ Ready (Inspect) Visit Preview Sep 24, 2022 at 7:32PM (UTC)

vercel[bot] avatar Sep 21 '22 04:09 vercel[bot]

I've added test cases for Renderer and Canvas to make sure that they render without crashing when they're given custom cursors, but I see that most props on those components have not been giving their own tests. If it's not desirable to have this kind of additional test case for simple component props, let me know and I'll remove them.

jamesbvaughan avatar Sep 21 '22 04:09 jamesbvaughan

I've added test cases for Renderer and Canvas to make sure that they render without crashing when they're given custom cursors, but I see that most props on those components have not been giving their own tests. If it's not desirable to have this kind of additional test case for simple component props, let me know and I'll remove them.

it's all good IMO anyway great work! just one thing tho, could you also let the tldraw package receive a prop for custom cursor components? like this one https://github.com/tldraw/tldraw/blob/31f0f02adf58b909f59764f62de09e97542eb2b1/packages/tldraw/src/Tldraw.tsx#L94-L96, and just pass it to the renderer https://github.com/tldraw/tldraw/blob/31f0f02adf58b909f59764f62de09e97542eb2b1/packages/tldraw/src/Tldraw.tsx#L478-L480

judicaelandria avatar Sep 21 '22 06:09 judicaelandria

let me know if you need with that

judicaelandria avatar Sep 21 '22 06:09 judicaelandria

closes https://github.com/tldraw/tldraw-v1/issues/358

judicaelandria avatar Sep 21 '22 06:09 judicaelandria

well done! thank you for taking time to do this

No problem, thanks for making it easy to do.

How soon should I expect to have this in an official release?

jamesbvaughan avatar Sep 21 '22 17:09 jamesbvaughan

How soon should I expect to have this in an official release?

maybe this friday PS: we love deploying on friday 😆

judicaelandria avatar Sep 22 '22 05:09 judicaelandria

Closes https://github.com/tldraw/tldraw-v1/issues/200

judicaelandria avatar Sep 22 '22 15:09 judicaelandria

Looks great @jamesbvaughan! I'm updating the PR to include the user's id in the props of the cursor. This should let certain applications pull related data using the ID (e.g. the user's name, etc).

steveruizok avatar Sep 24 '22 19:09 steveruizok