All Projects β†’ vinothpandian β†’ react-sketch-canvas

vinothpandian / react-sketch-canvas

Licence: MIT license
Freehand vector drawing component for React using SVG as canvas πŸ–ŒοΈ

Programming Languages

typescript
32286 projects
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to react-sketch-canvas

tracing-vs-freehand
Tracing Versus Freehand for Evaluating Computer-Generated Drawings (SIGGRAPH 2021)
Stars: ✭ 21 (-80.73%)
Mutual labels:  sketching, freehand-drawing
AODA
Official implementation of "Adversarial Open Domain Adaptation for Sketch-to-Photo Synthesis"(WACV 2022/CVPRW 2021)
Stars: ✭ 44 (-59.63%)
Mutual labels:  sketch
react-loading-icons
A TypeScript-React edition of Sam Herbert's amazing SVG Loaders.
Stars: ✭ 32 (-70.64%)
Mutual labels:  react-library
symbol-insert
A simple plugin to insert your Sketch symbols
Stars: ✭ 25 (-77.06%)
Mutual labels:  sketch
skeditor
Online sketch file editor.
Stars: ✭ 133 (+22.02%)
Mutual labels:  sketch
styledrop
A plugin for Sketch allows you to easily copy styles from one layer to another.
Stars: ✭ 54 (-50.46%)
Mutual labels:  sketch
sketch-debugger
πŸ› Debugger Plugin and Utils for Sketch Plugin Developers
Stars: ✭ 16 (-85.32%)
Mutual labels:  sketch
psd-to-sketch-converter
Convert PSD to Sketch for free
Stars: ✭ 42 (-61.47%)
Mutual labels:  sketch
open design system
Open Source Design System using Sketch. It's early days of my project.
Stars: ✭ 22 (-79.82%)
Mutual labels:  sketch
vgg runtime
VGG Runtime for loading and running designs as apps.
Stars: ✭ 19 (-82.57%)
Mutual labels:  sketch
SketchSVG
Have icons in a Sketch file but don't want to manually extract and compress them as SVGs? Let our SketchSVG tool do it!
Stars: ✭ 23 (-78.9%)
Mutual labels:  sketch
Sketch-SelectPlus
Sketch plugin to select different layers of specific types. It basically selects everything!
Stars: ✭ 20 (-81.65%)
Mutual labels:  sketch
Sketch-Keyboard-Resize
A Sketch plugin that lets you resize objects from all sides with keyboard shortcuts. As a bonus you can specify the resize amount.
Stars: ✭ 16 (-85.32%)
Mutual labels:  sketch
create-chakra-icons
Transform SVGs to React Chakra UI <Icon /> ✨
Stars: ✭ 80 (-26.61%)
Mutual labels:  react-library
SketchGen
A Swift command line tool for generating source code from sketch files
Stars: ✭ 27 (-75.23%)
Mutual labels:  sketch
animated-number-react
Super easy way to animate numbers with React
Stars: ✭ 91 (-16.51%)
Mutual labels:  react-library
DesignToken2Code
Convert design tokens to SCSS variables as code
Stars: ✭ 16 (-85.32%)
Mutual labels:  sketch
design-tokens-plugin
Support end of life! Delivering consistent Design System. A Sketch plugin that exports Design Tokens to JSON format. You can export colors, typography, icons and utilis. A must-have tool for design system project.
Stars: ✭ 100 (-8.26%)
Mutual labels:  sketch
sketch-library-unlinker
A Sketch plugin that can unlink symbols linked to a specific library, or unlink symbols that have been deleted in their libraries.
Stars: ✭ 21 (-80.73%)
Mutual labels:  sketch
sketch-reference-files
A store of automatically generated Sketch file JSON organised by document version and Sketch feature
Stars: ✭ 20 (-81.65%)
Mutual labels:  sketch

React Sketch Canvas


Freehand vector drawing component for React using SVG as canvas πŸ–Œ



npm    NPM    npm
npm bundle size    npm bundle size
codecov
This project was generated using DTS.

Overview

Features

  • Supports Desktop and Mobile.
  • Accepts input from Mouse, touch, and graphic tablets.

Requirements

  • Requires React >= 16.4

Wanna test React Sketch Canvas before using it?

Installation

If you use npm

npm i react-sketch-canvas

or with yarn

yarn add react-sketch-canvas

Example

Common usage example

import * as React from 'react';
import { ReactSketchCanvas } from 'react-sketch-canvas';

const styles = {
  border: '0.0625rem solid #9c9c9c',
  borderRadius: '0.25rem',
};

const Canvas = () => {
  return (
    <ReactSketchCanvas
      style={styles}
      width="600"
      height="400"
      strokeWidth={4}
      strokeColor="red"
    />
  );
};

To export Data URL of your sketch use ref

import * as React from "react";
import { ReactSketchCanvas } from "react-sketch-canvas";

const styles = {
  border: "0.0625rem solid #9c9c9c",
  borderRadius: "0.25rem"
};

const Canvas = class extends React.Component {
  constructor(props) {
    super(props);

    this.canvas = React.createRef();
  }

  render() {
    return (
      <div>
        <ReactSketchCanvas
          ref={this.canvas}
          strokeWidth={5}
          strokeColor="black"
        />
        <button
          onClick={() => {
            this.canvas.current.
              .exportImage("png")
              .then(data => {
                console.log(data);
              })
              .catch(e => {
                console.log(e);
              });
          }}
        >
          Get Image
        </button>
      </div>
    );
  }
};

List of Props

Props Expected datatype Default value Description
width PropTypes.string 100% canvas width (em/rem/px)
height PropTypes.string 100% canvas width (em/rem/px)
id PropTypes.string "react-sketch-canvas" ID field to uniquely identify a SVG canvas (Supports multiple canvases in a single page)
className PropTypes.string "" Class for using with CSS selectors
strokeColor PropTypes.string black Pen color
canvasColor PropTypes.string white canvas color (HTML colors)
backgroundImage PropTypes.string '' Set SVG background with image URL
exportWithBackgroundImage PropTypes.bool false Keep background image on image/SVG export (on false, canvasColor will be set as background)
preserveBackgroundImageAspectRatio PropTypes.string none Set aspect ratio of the background image. For possible values check MDN docs
strokeWidth PropTypes.number 4 Pen stroke size
eraserWidth PropTypes.number 8 Erase size
allowOnlyPointerType PropTypes.string all allow pointer type ("all"/"mouse"/"pen"/"touch")
onChange PropTypes.func Returns the current sketch path in CanvasPath type on every path change
onStroke PropTypes.func Returns the the last stroke path and whether it is an eraser stroke on every pointer up event
style PropTypes.object false Add CSS styling as CSS-in-JS object
withTimestamp PropTypes.bool false Add timestamp to individual strokes for measuring sketching time

Set SVG background using CSS background value

You can specify width and height values in em or rem. It fills the parent element space if width and height are not set


Methods

You can export the sketch as an image or as a svg

Use ref to access the element and call the following functions to export image

Props Expected datatype
eraseMode(boolean) Switch to eraser mode by passing true. You can switch back to pen mode by passing false
clearCanvas() Clears the canvas.
resetCanvas() Resets the canvas and clears the undo/redo stack along with it.
undo() Undo the last action.
redo() Redo the previous action.
exportImage(imageTypeString) Accepts an image type as argument (ExportImageType) and returns a Promise which resolves to base64 data url of the sketch.
exportSvg() returns a Promise which resolves to an inline SVG element.
exportPaths() returns a Promise which resolves to an instance of CanvasPath.
loadPaths(CanvasPath) Accepts an CanvasPath exported from exportPaths() and loads it on the canvas.
getSketchingTime() returns a Promise which resolves the time that user sketched in the canvas (considers only when the user made the strokes or erased the strokes)

Types

type ExportImageType = 'jpeg' | 'png';

interface Point {
  x: number;
  y: number;
}

interface CanvasPath {
  paths: Point[];
  strokeWidth: number;
  strokeColor: string;
  drawMode: boolean;
  startTimestamp?: number;
  endTimestamp?: number;
}

Thanks to

  • Philipp Spiess' tutorial
  • Draws smooth curves, thanks to FranΓ§ois Romain's tutorial

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].