A react component helps bring Figma's Cursor Chat to your web applications in less than 3 minutes, making real-time collaboration anywhere

Overview

@yomo/react-cursor-chat

🧬 Introduction

A react component helps bring Figma's Cursor Chat to your web applications in less than 3 minutes, making real-time collaboration anywhere.

  • Press / to bring up the input box
  • Press ESC to close the input box

screenshot

🤹🏻‍♀️ Quick Start

Installation

by npm:

$ npm i --save @yomo/react-cursor-chat

by yarn:

$ yarn add @yomo/react-cursor-chat

by pnpm:

$ pnpm i @yomo/react-cursor-chat

Request free dev/test account

Login with your Github account on https://presence.yomo.run, will get a free app_id and app_secret

then, add .env.local like:

APP_ID="abrHlqtooFakeID"
APP_SECRET="nFJqSVzQyhbVgdsBeBojoeJTooFakeSecret"

Integrate to your project

{ return (
logo

Press / to bring up the input box
Press{' '} ESC to close the input box

); }; ReactDOM.render(, document.getElementById('root'));">
import CursorChat from "@yomo/react-cursor-chat";
import "@yomo/react-cursor-chat/dist/cursor-chat.min.css";

const App = () => {
    return (
        <div className="main">
            <img className="logo" src={logo} alt="logo" />
            <p className="tips">
                Press <span>/</span> to bring up the input box <br /> Press{' '}
                <span>ESC</span> to close the input box
            </p>
            <CursorChat
                presenceURL="wss://prsc.yomo.dev"
                presenceAuth={{
                    type: 'token',
                    endpoint: "/api/auth",
                }}
                avatar='https://cursor-chat-example.vercel.app/_next/image?url=%2Flogo.png&w=256&q=75'
                theme="light"
            />
        </div>
    );
};

ReactDOM.render(<App />, document.getElementById('root'));

add /api/auth.js

export default async function handler(req, res) {
  if (req.method === "GET") {
    const response = await fetch("https://prsc.yomo.dev/api/v1/auth", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        app_id: process.env.APP_ID,
        app_secret: process.env.APP_SECRET,
      }),
    });
    const data = await response.json();
    res.status(200).json(data.data);
  } else {
    // Handle any other HTTP method
  }
}

Start dev

$ npm run dev

🥷🏼 for hackers

Importing the CursorChat component

;">
import React from 'react';
import CursorChat from '@yomo/react-cursor-chat';
import '@yomo/react-cursor-chat/dist/cursor-chat.min.css';

// `wss://presence.yomo.dev` is YoMo's free public test service 
<CursorChat
    presenceURL="wss://presence.yomo.dev"
    presenceAuth={{
        // Certification Type
        type: 'token',
        // api for getting access token
        endpoint: '/api/auth',
    }}
    avatar="https://avatars.githubusercontent.com/u/67308985?s=200&v=4"
    theme="light"
/>;
  • presenceURL: string: to set the WebSocket service address.
  • presenceAuth: { type: 'publickey' | 'token'; publicKey?: string; endpoint?: string; }: to set presencejs service Auth
  • room?: string: to set room.
  • avatar?: string: to set avatar.
  • name?: string: to set name.
  • theme?: 'light' | 'dark': The background color of the chat box, the default value is "dark".

Use hooks to customize the component:

{cursor.name &&
{cursor.name}
} {cursor.avatar && ( avatar )}
), [] ); }; // You can customise what other people's mouse blocks can display const OthersCursor = ({ cursor }) => { const refContainer = useRenderPosition(cursor); return (
{cursor.name &&
{cursor.name}
} {cursor.avatar && ( avatar )}
); }; // Exporting your custom components const YourComponent = ({ presenceURL, presenceAuth, name, avatar }) => { const { me, others } = useOnlineCursor({ presenceURL, presenceAuth, name, avatar, }); if (!me) { return null; } return (
{others.map(item => ( ))}
); };">
import React, { useMemo } from 'react';
import { useOnlineCursor, useRenderPosition } from '@yomo/react-cursor-chat';
import CursorIcon from './CursorIcon';

// You can customise the content of your own mouse block
const MeCursor = ({ cursor }) => {
    const refContainer = useRenderPosition(cursor);

    return useMemo(
        () => (
            <div className="cursor" ref={refContainer}>
                <CursorIcon color={cursor.color} />
                {cursor.name && <div>{cursor.name}</div>}
                {cursor.avatar && (
                    <img className="avatar" src={cursor.avatar} alt="avatar" />
                )}
            </div>
        ),
        []
    );
};

// You can customise what other people's mouse blocks can display
const OthersCursor = ({ cursor }) => {
    const refContainer = useRenderPosition(cursor);
    return (
        <div ref={refContainer} className="cursor">
            <CursorIcon color={cursor.color} />
            {cursor.name && <div>{cursor.name}</div>}
            {cursor.avatar && (
                <img className="avatar" src={cursor.avatar} alt="avatar" />
            )}
        </div>
    );
};

// Exporting your custom components
const YourComponent = ({ presenceURL, presenceAuth, name, avatar }) => {
    const { me, others } = useOnlineCursor({
        presenceURL,
        presenceAuth,
        name,
        avatar,
    });

    if (!me) {
        return null;
    }

    return (
        <div className="container">
            {others.map(item => (
                <OthersCursor key={item.id} cursor={item} />
            ))}
            <MeCursor cursor={me} />
        </div>
    );
};

Deploy to vercel

vc --prod

LICENSE

License: MIT
Comments
  • Not getting the others array from the useOnlineCursor() hook

    Not getting the others array from the useOnlineCursor() hook

    hi I am using this react-cursor-chat library in react application but not getting the others array from the useOnlineCursor hook

    `import CursorChat, { useOnlineCursor, useRenderPosition, } from "@yomo/react-cursor-chat";

    const { me, others } = useOnlineCursor({ presenceURL: "https://prsc.yomo.dev", presenceAuthEndpoint: "/api/auth", avatar: "https://cursor-chat-example.vercel.app/_next/image?url=%2Flogo.png&w=256&q=75", name: user.displayName, });`

    I am not getting the others online users

    Screenshot (35) Screenshot (36)

    bug 
    opened by swatantragoswami09 23
  • [ImgBot] Optimize images

    [ImgBot] Optimize images

    Beep boop. Your images are optimized!

    Your image file size has been reduced 🎉

    Details

    | File | Before | After | Percent reduction | |:--|:--|:--|:--| | /apricot-yellow.png | 23.11kb | 20.36kb | 11.91% | | /hairy-green.png | 22.84kb | 20.36kb | 10.83% | | /example/public/logo.png | 20.82kb | 20.26kb | 2.67% | | /show.gif | 1,516.50kb | 1,500.32kb | 1.07% | | | | | | | Total : | 1,583.26kb | 1,561.29kb | 1.39% |


    📝 docs | :octocat: repo | 🙋🏾 issues | 🏪 marketplace

    ~Imgbot - Part of Optimole family

    opened by imgbot[bot] 0
  • [ImgBot] Optimize images

    [ImgBot] Optimize images

    Beep boop. Your images are optimized!

    Your image file size has been reduced 🎉

    Details

    | File | Before | After | Percent reduction | |:--|:--|:--|:--| | /example/public/logo.png | 20.82kb | 20.26kb | 2.67% | | /show.gif | 1,516.50kb | 1,500.32kb | 1.07% | | | | | | | Total : | 1,537.32kb | 1,520.58kb | 1.09% |


    📝 docs | :octocat: repo | 🙋🏾 issues | 🏪 marketplace

    ~Imgbot - Part of Optimole family

    opened by imgbot[bot] 0
  • [ImgBot] Optimize images

    [ImgBot] Optimize images

    Beep boop. Your images are optimized!

    Your image file size has been reduced by 18% 🎉

    Details

    | File | Before | After | Percent reduction | |:--|:--|:--|:--| | /vercel-deploy.jpg | 109.66kb | 86.76kb | 20.88% | | /commerce-screenshot.jpg | 164.30kb | 134.74kb | 17.99% | | /example/logo.png | 20.82kb | 20.26kb | 2.67% | | | | | | | Total : | 294.77kb | 241.76kb | 17.99% |


    📝 docs | :octocat: repo | 🙋🏾 issues | 🏪 marketplace

    ~Imgbot - Part of Optimole family

    opened by imgbot[bot] 0
  • [ImgBot] Optimize images

    [ImgBot] Optimize images

    Beep boop. Your images are optimized!

    Your image file size has been reduced 🎉

    Details

    | File | Before | After | Percent reduction | |:--|:--|:--|:--| | /themeColor.png | 126.66kb | 92.35kb | 27.09% | | /apricot-yellow.png | 23.11kb | 20.36kb | 11.91% | | /hairy-green.png | 22.84kb | 20.36kb | 10.83% | | /show.gif | 1,516.50kb | 1,500.32kb | 1.07% | | | | | | | Total : | 1,689.11kb | 1,633.39kb | 3.30% |


    📝 docs | :octocat: repo | 🙋🏾 issues | 🏪 marketplace

    ~Imgbot - Part of Optimole family

    opened by imgbot[bot] 0
Owner
YoMo
Geo-distributed system Framework
YoMo
A chat application created using React,js and Chat Engine

⭐️ Chat-App ⭐️ A Chat Application created using React.js and Chat Engine Live Site Getting Started with Create React App This project was bootstrapped

Supuni Eleesha Randeniya 1 Dec 15, 2022
Tutorial created in collaboration with Enyel Sequeira, taught by JavaScript Mastery.

Travel Advisor Live Site Introduction Build and Deploy an advanced Travel Companion Application using Google Maps. With Geolocation, Google Maps API,

Adrian Hajdin - JavaScript Mastery 1.6k Jan 3, 2023
O Aluracord é um clone personalizado do discord com chat em tempo real.

Aluracord O Aluracord é um clone personalizado do Discord durante a Imersão React da Alura. Desde o início da imersão meu objetivo era ir além dela, e

Heitor Lisboa 11 Dec 15, 2022
An experimental hover effect, where a content preview is shown while a mini map indicates the position of the cursor.

Hover Preview Effect with Mini Map An experimental hover effect, where a content preview is shown while a mini map indicates the position of the curso

Codrops 27 Dec 29, 2022
Tweak React components in real time. (Deprecated: use Fast Refresh instead.)

React Hot Loader Tweak React components in real time ⚛️ ⚡️ Watch Dan Abramov's talk on Hot Reloading with Time Travel. Moving towards next step React-

Dan Abramov 12.2k Jan 1, 2023
Material-UI is a simple and customizable component library to build faster, beautiful, and more accessible React applications. Follow your own design system, or start with Material Design.

Material-UI Quickly build beautiful React apps. Material-UI is a simple and customizable component library to build faster, beautiful, and more access

Material-UI 83.6k Dec 30, 2022
A simple component for making elements draggable.

React Draggable Component A simple component for making elements draggable. Demo stackblitz Installation $ npm install drag-react # yarn add drag-reac

Haikel Fazzani 9 Sep 17, 2022
Hacker-news-with-react - 👾 Consuming the hacker news api, i created a more modern design for than the current site.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

João Thomaz 1 Jan 3, 2022
Application that show the survey results for backend frameworks to the user in real time.

.Net5 Hangfire and SignalR Survey Application Application that show the survey results for backend frameworks to the user in real time. The hangfire j

Cihat Girgin 4 Dec 17, 2021
Real-time covid data in Brazil states.

Brazil Covid Data Brazil Covid Data is a web application that allows you to see information about the pandemics on your state just by hovering it on t

Caio Lima 5 Feb 15, 2022
A React-Fullstack platform helps to track & compare your Incomes & Expenses transactions in one place via detailed Graphical information to manage your Budget.

Budget Master Track your income and expenses in one place via detailed graphical information to manage your budget. Manage your budget and transaction

Siddharth Singh Bhadoriya 9 Nov 27, 2022
Handle and dispatch transition states from anywhere in the application.

Transitions manager Transitions manager allows to handle and dispatch transition states from anywhere in the application. Installation npm i @cher-ami

Cher ami, 6 Dec 15, 2022
React tooltip is a React.JS Component that brings usefull UX and UI information in selected elements of your website.

React Tooltip ✅ React tooltip is a React.JS Component that brings usefull UX and UI information in elements of your website. Installation ⌨️ React Too

Marc Ramos 1 Dec 22, 2021
A react component available on npm to easily link to your project on github and is made using React, TypeScript and styled-components.

fork-me-corner fork-me-corner is a react component available on npm to easily link to your project on github and is made using React, TypeScript and s

Victor Dantas 9 Jun 30, 2022
Mirrors the functionality of Apollo client's useQuery hook, but with a "query" being any async function rather than GQL statement.

useAsyncQuery Mirrors the functionality of Apollo client's useQuery hook, but with a "query" being any async function rather than GQL statement. Usage

Alasdair McLeay 7 Nov 16, 2022
This is a simpler project than the full webpack source code, and you can understand the design ideas in webpack through it

my-webpack 这是一个简化版的webpack,旨在于理解webpack的设计原理以及webpack当中 loader和plugin的区别,运行方式。 运行步骤如下(方案一): 切换到my-webpack目录,运行npm install 切换到test目录,运行npm install 在tes

null 14 Sep 30, 2022
This command line helps you create components, pages and even redux implementation for your react project

react-help-create This command line helps you create components, pages and even redux implementation for your react project. How to install it? To ins

Omar 27 Dec 10, 2022
React features to enhance using Rollbar.js in React Applications

Rollbar React SDK React features to enhance using Rollbar.js in React Applications. This SDK provides a wrapper around the base Rollbar.js SDK in orde

Rollbar 39 Jan 3, 2023
React-Mini-Projects - Simple React mini-applications

React Mini Projects A Fully Responsive React Application contain these mini apps : Todo App Movie App Budget App Flash Card App Factor App This app wa

Morteza Rezaienia 1 Jan 1, 2022