
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-fabric-layers
Advanced tools
React components and hooks for fabric-layers - a powerful canvas layer management system built on Fabric.js. This package provides a seamless integration between React and the fabric-layers library.
npm install react-fabric-layers fabric-layers fabric-pure-browser
# or
yarn add react-fabric-layers fabric-layers fabric-pure-browser
import { Canvas, Grid, Layer, useCanvas } from 'react-fabric-layers';
import { useCallback } from 'react';
function App() {
const handleCanvasReady = useCallback((canvas) => {
console.log('Canvas is ready:', canvas);
}, []);
return (
<Canvas
width={800}
height={600}
onReady={handleCanvasReady}
>
<Grid
size={50}
color="#cccccc"
opacity={0.5}
snap={true}
/>
<Layer
id="background"
name="Background"
visible={true}
locked={false}
>
<rect
width={100}
height={100}
fill="#e0e0e0"
left={50}
top={50}
/>
</Layer>
<Layer
id="foreground"
name="Foreground"
>
<circle
radius={30}
fill="red"
left={200}
top={200}
/>
</Layer>
</Canvas>
);
}
interface CanvasProps {
width: number;
height: number;
onReady?: (canvas: fabric.Canvas) => void;
className?: string;
style?: React.CSSProperties;
children?: React.ReactNode;
}
interface GridProps {
size?: number; // Grid cell size
color?: string; // Grid line color
opacity?: number; // Grid opacity (0-1)
snap?: boolean; // Enable snap to grid
majorLines?: boolean; // Show major grid lines
majorLineFrequency?: number; // Major line frequency
}
interface LayerProps {
id: string; // Unique layer identifier
name?: string; // Layer name
visible?: boolean; // Layer visibility
locked?: boolean; // Layer locked state
opacity?: number; // Layer opacity (0-1)
children?: React.ReactNode;
}
function useCanvas(): fabric.Canvas | null;
Access the Fabric.js canvas instance from any child component.
function useLayer(layerId: string): {
layer: Layer;
visible: boolean;
setVisible: (visible: boolean) => void;
locked: boolean;
setLocked: (locked: boolean) => void;
opacity: number;
setOpacity: (opacity: number) => void;
addObject: (object: fabric.Object) => void;
removeObject: (object: fabric.Object) => void;
};
function useGrid(): {
visible: boolean;
setVisible: (visible: boolean) => void;
size: number;
setSize: (size: number) => void;
snap: boolean;
setSnap: (snap: boolean) => void;
opacity: number;
setOpacity: (opacity: number) => void;
};
import { Canvas, Layer, useLayer } from 'react-fabric-layers';
function ShapeManager() {
const { layer, addObject } = useLayer('myLayer');
const addRect = useCallback(() => {
const rect = new fabric.Rect({
width: 100,
height: 100,
fill: 'red',
left: 100,
top: 100
});
addObject(rect);
}, [addObject]);
return (
<button onClick={addRect}>Add Rectangle</button>
);
}
import { Canvas, useCanvas } from 'react-fabric-layers';
function CanvasEvents() {
const canvas = useCanvas();
useEffect(() => {
if (!canvas) return;
const handleObjectModified = (e) => {
console.log('Object modified:', e.target);
};
canvas.on('object:modified', handleObjectModified);
return () => {
canvas.off('object:modified', handleObjectModified);
};
}, [canvas]);
return null;
}
Contributions are welcome! Please feel free to submit a Pull Request.
MIT
MIT
FAQs
React components and hooks for fabric-layers
We found that react-fabric-layers demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.