0.0.3 • Published 5 years ago
react-goodgraphics v0.0.3
react-goodgraphics
A set of components for working with SVGs in React. This library is a very thin wrapper over native SVG functionality. This project is part of goodgraphics.xyz
Usage
Install
npm i react-goodgraphicsUse
import React from "react";
import { SVG, Circle } from "react-goodgraphics";
const FooBar = () => {
return (
<SVG
height={400}
width={400}
style={{ background: "#1b1b1b", fill: "white" }}
>
<Circle x={200} y={200} radius={100} />
</SVG>
);
};
export default FooBar;API
NOTE: Detailed are props that we map to the native SVG markup. i.e. the x and y props on Circle get mapped to cx and cy. All valid html attributes are accepted and passed to the components.
SVG
@prop {Number} heightHeight of the svg. Defaults to 200.@prop {Number} widthWidth of the svg. Defaults to 200.
Circle
@prop {String | Number} xThe x position for the shape.@prop {String | Number} yThe y position for the shape.@prop {String | Number} radiusThe radius of the shape.
Ellipse
@prop {String | Number} xThe x position for the shape.@prop {String | Number} yThe y position for the shape.@prop {String | Number} widthThe width of the shape.@prop {String | Number} heightThe height of the shape.
Rect
@prop {String | Number} xThe x position for the shape.@prop {String | Number} yThe y position for the shape.@prop {String | Number} widthThe width of the shape.@prop {String | Number} heightThe height of the shape.
Square
@prop {String | Number} xThe x position for the shape.@prop {String | Number} yThe y position for the shape.@prop {String | Number} sizeThe size of the square.
Line
@prop {String | Number} x1The x position of the start of the line.@prop {String | Number} y1The y position of the start of the line.@prop {String | Number} x2The x position of the end of the line.@prop {String | Number} y2The y position of the end of the line.
Times
Runs the draw function x number of times.
@prop {Number} numberThe number of times to run the loop.@prop {Function} drawThe draw render prop function.
Grid
Draw items across a grid.
@prop {Function} drawThe draw render prop function.@prop {Number} columnsThe number of columns.@prop {Number} rowsThe number of rows.@prop {Number} heightHeight of the svg. Defaults to svg's height.@prop {Number} widthWidth of the svg. Defaults to svg's width.@prop {Number} marginMargin between the edges and the grid. Defaults to 0.