1.0.1 • Published 2 years ago

@skits/react-cursor v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

React Cursor

Lightweight zero dependency React Cursor component.

Use the provided Cursor component, to add a animated cursor to your website.

Installation

npm i @skits/react-cursor

Usage

Basic example

import Cursor from '@skits/react-cursor';

export default function App() {
  return (
    <div className="app">
      <Cursor />
    </div>
  );
}

Example with props

import Cursor from '@skits/react-cursor';

export default function App() {
  return (
    <div className="app">
      <Cursor
        size={40}
        color="red"
        opacity={0.3}
        radius="50%" // circle
        zIndex={-1} // use negative zIndex to place cursor below other elements
        className="custom-cursor-class"
      />
    </div>
  );
}

Scale shape element on click

import Cursor from '@skits/react-cursor';

export default function App() {
  return (
    <div className="app">
      <Cursor
        size={40}
        onMouseDown={(cursorElement, shapeElement) => {
          shapeElement.style.transform = 'scale(1.5)';
        }}
        onMouseUp={(cursorElement, shapeElement) => {
          shapeElement.style.transform = 'scale(1)';
        }}
      />
    </div>
  );
}

Props

Flexible component API for customisations to suit your needs

PropTypeDescriptionDefault
sizenumberrgb value40
colorstringrgb value1
opacitynumberamount of alpha transparency for outer cursor dotred
radiusnumberSize (px) of inner cursor dot50%
zIndexnumberSize (px) of outer cursor outline999999
classNamestringamount dot scales on click or link hover-
onMouseDownfunctionCallback that fires on a window.mousedown event.e.g. (cursorElement, shapeElement) => {}-
onMouseUpfunctionCallback that fires on a window.mouseup event.e.g. (cursorElement, shapeElement) => {}-

License: MIT Author: @samwyness