React Picture Annotation

A simple annotation component.

Install
npm install react-picture-annotation
yarn add react-picture-annotation
Basic Example

const App = () => {
const [pageSize, setPageSize] = useState({
width: window.innerWidth,
height: window.innerHeight
});
const onResize = () => {
setPageSize({ width: window.innerWidth, height: window.innerHeight });
};
useEffect(() => {
window.addEventListener('resize', onResize);
return () => window.removeEventListener('resize', onResize);
}, []);
const onSelect = selectedId => console.log(selectedId);
const onChange = data => console.log(data);
return (
<div className="App">
<ReactPictureAnnotation
image="https://source.unsplash.com/random/800x600"
onSelect={onSelect}
onChange={onChange}
width={pageSize.width}
height={pageSize.height}
/>
</div>
);
};
const rootElement = document.getElementById('root');
ReactDOM.render(<App />, rootElement);
ReactPictureAnnotation Props
| onChange | (annotationData: IAnnotation[]) => void | Called every time the shape changes. | √ |
| onSelected | (id: string or null) => void | Called each time the selection is changed. | √ |
| width | number | Width of the canvas. | √ |
| height | number | Height of the canvas. | √ |
| image | string | Image to be annotated. | √ |
| inputElement | (value: string,onChange: (value: string) => void,onDelete: () => void) => React.ReactElement; | Customizable input control. | X |
| annotationData | Array<IAnnotation> | Control the marked areas on the page. | X |
| annotationStyle | IShapeStyle | Control the mark style | X |
| selectedId | string or null | Selected markId | X |
| scrollSpeed | number | Speed of wheel zoom, default 0.0005 | X |
| marginWithInput | number | Margin between input and mark, default 1 | X |
| defaultAnnotationSize | number[] | Size for annotations created by clicking. | X |
IShapeStyle
ReactPictureAnnotation can be easily modified the style through a prop named annotationStyle
export const defaultShapeStyle: IShapeStyle = {
padding: 5,
fontSize: 12,
fontColor: "#212529",
fontBackground: "#f8f9fa",
fontFamily:
"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', Helvetica, Arial, sans-serif",
lineWidth: 2,
shapeBackground: "hsla(210, 16%, 93%, 0.2)",
shapeStrokeStyle: "#f8f9fa",
shadowBlur: 10,
shapeShadowStyle: "hsla(210, 9%, 31%, 0.35)",
transformerBackground: "#5c7cfa",
transformerSize: 10
};
IAnnotation
{
id:"to identify this shape",
comment:"string type comment",
mark:{
type:"RECT",
x:0,
y:0,
width:0,
height:0
}
}
Licence
MIT License
How To Contribute
This repo uses semantic release. By running npm run commit and merging commits into master branch, travis will automatically trigger release.
Thanks all your great contributions.