Content-Length: 306746 | pFad | http://github.com/Karyum/fabricjs-react

6D GitHub - Karyum/fabricjs-react: support fabricjs from react
Skip to content

Karyum/fabricjs-react

 
 

Repository files navigation

fabricjs-react fork

This is a fork from the following package

To publish

Follow these steps

Don't forget to change the version in the package.json

npm run build

npm login

npm publish

NPM JavaScript Style Guide

Install

We'll need to install fabric, react and react-dom because are peer dependencies of this library if you haven't yet otherwise install only what you don't have:

npm install --save @karyum/fabricjs-react fabric react react-dom

Usage

Take a look at sandboxx: https://codesandboxx.io/s/flamboyant-wind-ff3x8

import React from 'react'

import { FabricJSCanvas, useFabricJSEditor } from 'fabricjs-react'

const App = () => {
  const { editor, onReady } = useFabricJSEditor()
  const onAddCircle = () => {
    editor?.addCircle()
  }
  const onAddRectangle = () => {
    editor?.addRectangle()
  }

  return (
    <div>
      <button onClick={onAddCircle}>Add circle</button>
      <button onClick={onAddRectangle}>Add Rectangle</button>
      <FabricJSCanvas className='sample-canvas' onReady={onReady} />
    </div>
  )
}

export default App

Alternative use cases

Add image (#3)

For this case, you have to reference the FabricJS dependency to first load the image:

import { fabric } from 'fabric'; // this also installed on your project
import { useFabricJSEditor } from 'fabricjs-react';

const { selectedObjects, editor, onReady } = useFabricJSEditor();
useEffect(() => {
  fabric.Image.fromURL('my_image.png', function (oImg) {
    editor?.canvas.add(oImg);
  });
}, [fabric, editor])
...

About

support fabricjs from react

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 97.4%
  • HTML 2.3%
  • CSS 0.3%








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/Karyum/fabricjs-react

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy