You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-svg-annotation

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-svg-annotation

SVG Annotation Component

0.0.15
latest
Source
npmnpm
Version published
Weekly downloads
9
200%
Maintainers
1
Weekly downloads
 
Created
Source

React SVG Annotation

The SVG Annotation Tool

Live Demo

Checkout Storybook Demo to get more information!

Installation

# use yarn
yarn add react-svg-annotation

# use npm
npm install react-svg-annotation

Basic Usage

import { SvgAnnotation } from "react-svg-annotation";

const Example = () => {
  return <SvgAnnotation width={400} height={400} />;
};

export default Example;

Advanced Usage with Custom UI

If SvgAnnotation Component is not suitable for your use case, you may combine useSvgAnnotation and SvgRenderer to make your own component

import { useSvgAnnotation, SvgRenderer } from "react-svg-annotation";

const Example = () => {
  const { svgProps, changeTool, tool } = useSvgAnnotation({
    styleOption: {
      color: "black",
      fillColor: "transparent",
      lineWidth: 5,
    },
  });

  return (
    <div>
      <div>{/* Custom Control Component */}</div>
      <SvgRenderer {...svgProps} width={400} height={400} />
    </div>
  );
};

export default Example;

Common Type

Annotation

type Annotation = Array<SVGObject>; // list of SVG Object

SVGStyleOption

type SVGStyleOption = Partial<{
  color: string;
  lineWidth: number;
  fillColor: string;
}>;
PropertyTypeDescriptionDefault Value
colorstringstroke color of svg elementblack
fillColorstringfill color of svg elementtransparent
lineWidthnumberstroke width of svg element5

Component API

SvgAnnotation Component

interface SvgAnnotationProps extends SVGStyleOption {
  backgroundImage?: string;
  width?: number;
  height?: number;
  value?: Annotation;
  onChange?: (value: Annotation) => void;
}
PropertyTypeDescriptionDefault Value
backgroundImagestringcustom background image urlNA
widthnumberwidth of svg400
heightnumberheight of svg400
valueAnnotationAnnotation Objectundefined
onChange(value: Annotation) => voidhandle change functionundefined

useSvgAnnotation hook

type UseSvgAnnotationParams = {
  styleOption?: SVGStyleOption;
  value?: Annotation;
  onChange?: (value: Annotation) => void;
};

type UseSvgAnnotation<T extends SVGSVGElement> = (options?: UseSvgAnnotationParams) => {
  svgProps: SvgRendererProps;
  tool: Tools;
  changeTool: (value: Tools) => void;
  download: (type: ImageType) => void;
  toSvgString: () => string | null;
};

SvgRenderer Component

interface SvgRendererProps extends SVGAttributes<SVGSVGElement> {
  tool: Tools;
  annotation: Annotation;
  currentSVGObject: SVGObject | null;
  shapeControl: ShapeControl | null;
}

Keywords

svg

FAQs

Package last updated on 31 Jan 2023

Did you know?

Socket

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.

Install

Related posts