@@ -55,12 +55,12 @@ yarn add react-sketch-canvas
5555Common usage example
5656
5757``` javascript
58- import React from " react" ;
59- import { ReactSketchCanvas } from " react-sketch-canvas" ;
58+ import React from ' react' ;
59+ import { ReactSketchCanvas } from ' react-sketch-canvas' ;
6060
6161const styles = {
62- border: " 0.0625rem solid #9c9c9c" ,
63- borderRadius: " 0.25rem" ,
62+ border: ' 0.0625rem solid #9c9c9c' ,
63+ borderRadius: ' 0.25rem' ,
6464};
6565
6666const Canvas = () => {
@@ -124,52 +124,30 @@ const Canvas = class extends React.Component {
124124
125125## List of Props
126126
127- | Props | Expected datatype | Default value | Description |
128- | -------------------- | ----------------- | ------------- | -------------------------------------------------------------------- |
129- | className | PropTypes.string | "" | Class for using with CSS selectors |
130- | width | PropTypes.string | 100% | canvas width (em/rem/px) |
131- | height | PropTypes.string | 100% | canvas width (em/rem/px) |
132- | canvasColor | PropTypes.string | white | canvas color (HTML colors) |
133- | background | PropTypes.string | '' | Set SVG background using CSS [ background] [ css-bg ] value |
134- | strokeColor | PropTypes.string | black | Pen color |
135- | strokeWidth | PropTypes.number | 4 | Pen stroke size |
136- | eraserWidth | PropTypes.number | 8 | Erase size |
137- | allowOnlyPointerType | PropTypes.string | all | allow pointer type ("all"/"mouse"/"pen"/"touch") |
138- | onUpdate | PropTypes.func | all | Returns the current sketch path in ` CanvasPath ` type on every update |
139- | withTimestamp | PropTypes.bool | false | Add timestamp to individual strokes for measuring sketching time |
127+ | Props | Expected datatype | Default value | Description |
128+ | ---------------------------------- | ----------------- | ------------- | --------------------------------------------------------------------------------------------------- |
129+ | width | PropTypes.string | 100% | canvas width (em/rem/px) |
130+ | height | PropTypes.string | 100% | canvas width (em/rem/px) |
131+ | className | PropTypes.string | "" | Class for using with CSS selectors |
132+ | strokeColor | PropTypes.string | black | Pen color |
133+ | canvasColor | PropTypes.string | white | canvas color (HTML colors) |
134+ | backgroundImage | PropTypes.string | '' | Set SVG background with image URL |
135+ | exportWithBackgroundImage | PropTypes.bool | true | Keep background image on image/SVG export (on false, canvasColor will be set as background) |
136+ | preserveBackgroundImageAspectRatio | PropTypes.string | none | Set aspect ratio of the background image. For possible values check [ MDN docs] [ preserveaspectratio ] |
137+ | strokeWidth | PropTypes.number | 4 | Pen stroke size |
138+ | eraserWidth | PropTypes.number | 8 | Erase size |
139+ | allowOnlyPointerType | PropTypes.string | all | allow pointer type ("all"/"mouse"/"pen"/"touch") |
140+ | onUpdate | PropTypes.func | all | Returns the current sketch path in ` CanvasPath ` type on every update |
141+ | style | PropTypes.object | false | Add CSS styling as CSS-in-JS object |
142+ | withTimestamp | PropTypes.bool | false | Add timestamp to individual strokes for measuring sketching time |
140143
141144Set SVG background using CSS [ background] [ css-bg ] value
142145
143146You can specify width and height values in em or rem. It fills the parent element space if width and height are not set
144147
145- Example
146-
147- ``` javascript
148- < ReactSketchCanvas width= " 25em" height= " 10rem" / >
149- ```
150-
151- ## Styling
152-
153- You can pass a CSS in JS style object to style the element. By default it has a border with following properties
148+ <br />
154149
155- ``` css
156- canvas {
157- border : 0.0625rem solid #9c9c9c ;
158- border-radius : 0.25rem ;
159- }
160- ```
161-
162- Example
163-
164- ``` javascript
165- < ReactSketchCanvas
166- style= {{
167- border: " 0.0625rem solid #9c9c9c" ,
168- }}
169- / >
170- ```
171-
172- ## Functions
150+ ## Methods
173151
174152You can export the sketch as an image or as a svg
175153
@@ -191,7 +169,7 @@ _Use ref to access the element and call the following functions to export image_
191169## Types
192170
193171``` ts
194- type ExportImageType = " jpeg" | " png" ;
172+ type ExportImageType = ' jpeg' | ' png' ;
195173
196174interface Point {
197175 x: number ;
@@ -216,10 +194,10 @@ interface CanvasPath {
216194- Draws smooth curves, thanks to François Romain's [ tutorial] [ smooth-curve-tutorial ]
217195- Immer [ link] [ immer ]
218196
219-
220197---
221198
222199[ based-on ] : https://pspdfkit.com/blog/2017/how-to-build-free-hand-drawing-using-react/
223200[ smooth-curve-tutorial ] : https://medium.com/@francoisromain/smooth-a-svg-path-with-cubic-bezier-curves-e37b49d46c74
224201[ css-bg ] : https://developer.mozilla.org/en-US/docs/Web/CSS/background
225202[ immer ] : https://immerjs.github.io/immer/docs/introduction
203+ [ preserveaspectratio ] : https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio
0 commit comments