1.0.2 • Published 8 months ago

react-animated-polyline-cursor v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

React Animated Polyline Cursor

기본 커서를 커스텀 가능한 애니메이션 커서로 변경해주는 React Component입니다. 해당 Component는 함수형으로 제작되었습니다.

Contents

  1. Features
  2. Demo
  3. Install
  4. Options
  5. Notes

Features

  • Custom cursor replaced by default cursor
  • Line effects that track the path the cursor has traveled
  • Cursor scale down effect on click
  • Cursor resizing effect when hovering over elements with 'c-cursor-hover' class defined

Other customizations include color, size, polyline-delay, polyline-length, marker-blend-mode, and more for circle, polyline, and marker.

Live Demo

Install

npm i react-animated-polyline-cursor

Usage

Add to global scope. (ex. App.ts)

import React from "react";
import CustomAnimatedCursor from "user project dir path";

export default function App() {
    return (
        <div className="App">
            // It has default values, ​​and you can only override custom settings.
            <CustomAnimatedCursor
                dotColor={"#2AFADF"}
                lineColor={"#2AFADF"}
                markerColor={"#2AFADF"}
            />
            ...component
        </div>
    );
}

Hover Element (add 'c-cursor-hover' className)

export default function DemoContent() {
    return (
        <div>
            <div>
                <h1>Custom Animated Polyline Cursor</h1>
                <a href="#" className="c-cursor-hover">
                    Link Text.
                </a>
                <div className="c-cursor-hover">Hover Box</div>
                <div>
                    <label htmlFor="chk" className="c-cursor-hover">
                        Checkbox
                    </label>
                    <input type="checkbox" id="chk" />
                </div>
            </div>
        </div>
    );
}

Default Props

CustomAnimatedCursor.defaultProps = {
    dotColor: "#000",
    dotSize: 8,
    dotReductionRatio: 0.25,
    lineColor: "#000",
    lineDelay: 2,
    lineLength: 12,
    lineWidth: 2,
    markerSize: 24,
    markerColor: "#fff",
    removeCursorElements: ["a", "input", "label", "select", "textarea", "button"],
    markerBlendMode: true,
};

Props Types

export interface CursorTypes {
    dotColor: string;
    dotSize: number;
    dotReductionRatio: number;
    lineColor: string;
    lineDelay: number;
    lineLength: number;
    lineWidth: number;
    markerSize: number;
    markerColor: string;
    removeCursorElements: string[];
    markerBlendMode: boolean;
}

Options

OptionTypeDescriptionDefault
dotColorstringCursor color - rgb or hex#000
dotSizenumberCursor size - Minimum 18
dotReductionRationumberCursor reduction ratio - 0~10.25
lineColorstringDrawLine color - rgb or hex#000
lineDelaynumberDrawLine delay to follow - Minimum 12
lineLengthnumberDrawLine stretched length - Recommend 2~30 limit12
lineWidthnumberDrawLine width - Minimum 1, Maximum "dotSize"2
markerSizestringHoveredMarker size - Minimum "dotSize"24
markerColorstringHoveredMarker color - rgb or hex#000
removeCursorElementsarrayRemove default cursor from element - htmlTag, class, id['a', 'input', 'label', 'select', 'textarea', 'button']
markerBlendModebooleanOn/Off the Cursor blend mode - booleantrue

Todos

  • Webpack to Vite Migration
  • Add Hovered Marker Click Action
  • Add Input Type Element Hovered Action
  • Create & Deploy NPM Package
  • Add more detailed cursor style editing
  • Changed input element cursor hovered design
  • Add SSR Mode
  • Source Refactoring

Notes

  • Vue로 구현되어있는 DFY의 커서를 React 버전으로 만들어보고 싶어서 제작하였습니다.
  • 버그, 이슈, 리팩토링 등 다양한 피드백 환영합니다.