Skip to content

Commit f8ee6dd

Browse files
committed
ver 0.3.0 - use render prop obj to set line prop
1 parent 6f3a931 commit f8ee6dd

File tree

7 files changed

+269
-76
lines changed

7 files changed

+269
-76
lines changed

README.md

Lines changed: 97 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,33 +65,33 @@ This value should not be changed after ReactPainter is mounted as it will mess u
6565
Set the width of the canvas
6666
Similar to height, this value should not be changed after mounted.
6767

68-
### color?: string
68+
### initialColor?: string
6969

7070
> defaults to `#000`
7171
72-
Set the stroke color.
73-
This value can be changed dynamically.
72+
Set the initial stroke color.
73+
Stroke can be changed dynamically using `setColor`.
7474

75-
### lineWidth?: number
75+
### initialLineWidth?: number
7676

7777
> defaults to `5`
7878
79-
Set the stroke line width.
80-
This value can be changed dynamically.
79+
Set the initial stroke line width.
80+
Line width can be changed dynamically using `setLineWidth`.
8181

8282
### lineCap?: 'round' | 'butt' | 'square'
8383

8484
> defaults to `round`
8585
86-
Set the stroke line cap.
87-
This value can be changed dynamically.
86+
Set the initial stroke line cap.
87+
Line cap can be changed dynamically using `setLineCap`.
8888

89-
### lineJoin?: 'round' | 'bevel' | 'miter'
89+
### initialLineJoin?: 'round' | 'bevel' | 'miter'
9090

9191
> defaults to `round`
9292
93-
Set the stroke line join.
94-
This value can be changed dynamically.
93+
Set the initial stroke line join.
94+
Line join type can be changed dynamically using `setLineJoin`.
9595

9696
### onSave?: (blob: Blob) => void
9797

@@ -129,7 +129,7 @@ This is the canvas node that you can used to mount in your component. Example:
129129
/>
130130
```
131131

132-
### triggerSave: () => void;
132+
### triggerSave: () => void
133133

134134
This is the function that you invoke when you want to save the canvas.
135135

@@ -147,7 +147,91 @@ Example:
147147
/>
148148
```
149149

150-
### imageCanDownload: boolean;
150+
### setColor: (color: string) => void
151+
152+
Set the color of the line.
153+
154+
Example:
155+
156+
```jsx
157+
<ReactPainter
158+
render={({ canvas, triggerSave, setColor }) => (
159+
<div>
160+
<div>Awesome heading</div>
161+
<input type="color" onChange={e => setColor(e.target.value)} />
162+
<div className="awesomeContainer">{canvas}</div>
163+
<button onClick={triggerSave}>Save</button>
164+
</div>
165+
)}
166+
/>
167+
```
168+
169+
### setLineWidth: (width: number) => void
170+
171+
Set the width of the line.
172+
173+
Example:
174+
175+
```jsx
176+
<ReactPainter
177+
render={({ canvas, triggerSave, setLineWidth }) => (
178+
<div>
179+
<div>Awesome heading</div>
180+
<input type="number" onChange={e => setLineWidth(e.target.value)} />
181+
<div className="awesomeContainer">{canvas}</div>
182+
<button onClick={triggerSave}>Save</button>
183+
</div>
184+
)}
185+
/>
186+
```
187+
188+
### setLineJoin: (type: 'round' | 'bevel' | 'miter') => void
189+
190+
Set the join type of the line.
191+
192+
Example:
193+
194+
```jsx
195+
<ReactPainter
196+
render={({ canvas, triggerSave, setLineJoin }) => (
197+
<div>
198+
<div>Awesome heading</div>
199+
<select onChange={e => setLineJoin(e.target.value)}>
200+
<option value="round">round</option>
201+
<option value="bevel">bevel</option>
202+
<option value="miter">miter</option>
203+
</selct>
204+
<div className="awesomeContainer">{canvas}</div>
205+
<button onClick={triggerSave}>Save</button>
206+
</div>
207+
)}
208+
/>
209+
```
210+
211+
### setLineCap: (type: 'round' | 'butt' | 'square') => void
212+
213+
Set the cap type of the line.
214+
215+
Example:
216+
217+
```jsx
218+
<ReactPainter
219+
render={({ canvas, triggerSave, setLineCap }) => (
220+
<div>
221+
<h2>Awesome heading</h2>
222+
<select onChange={e => setLineCap(e.target.value)}>
223+
<option value="round">round</option>
224+
<option value="butt">butt</option>
225+
<option value="square">square</option>
226+
</selct>
227+
<div className="awesomeContainer">{canvas}</div>
228+
<button onClick={triggerSave}>Save</button>
229+
</div>
230+
)}
231+
/>
232+
```
233+
234+
### imageCanDownload: boolean
151235

152236
This properties let you know if the image is inserted successfully. By default it is `null` until the checking of image import is successful.
153237

dist/ReactPainter.d.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ export interface RenderProps {
2323
getCanvasProps: (props: PropsGetterInput) => PropsGetterResult;
2424
imageCanDownload: boolean;
2525
imageDownloadUrl: string;
26+
setColor: (color: string) => void;
27+
setLineWidth: (width: number) => void;
28+
setLineJoin: (type: 'round' | 'bevel' | 'miter') => void;
29+
setLineCap: (type: 'round' | 'butt' | 'square') => void;
2630
}
2731
export interface ReactPainterProps {
2832
height?: number;
2933
width?: number;
30-
color?: string;
31-
lineWidth?: number;
32-
lineJoin?: 'round' | 'bevel' | 'miter';
33-
lineCap?: 'round' | 'butt' | 'square';
34+
initialColor?: string;
35+
initialLineWidth?: number;
36+
initialLineJoin?: 'round' | 'bevel' | 'miter';
37+
initialLineCap?: 'round' | 'butt' | 'square';
3438
onSave?: (blob: Blob) => void;
3539
image?: File | string;
3640
render?: (props: RenderProps) => JSX.Element;
@@ -41,6 +45,10 @@ export interface PainterState {
4145
imageCanDownload: boolean;
4246
imageDownloadUrl: string;
4347
isDrawing: boolean;
48+
color: string;
49+
lineWidth: number;
50+
lineJoin: 'round' | 'bevel' | 'miter';
51+
lineCap: 'round' | 'butt' | 'square';
4452
}
4553
export declare class ReactPainter extends React.Component<ReactPainterProps, PainterState> {
4654
static propTypes: {
@@ -71,6 +79,10 @@ export declare class ReactPainter extends React.Component<ReactPainterProps, Pai
7179
handleMouseMove: (e: React.SyntheticEvent<HTMLCanvasElement>) => void;
7280
handleMouseUp: (e: React.SyntheticEvent<HTMLCanvasElement>) => void;
7381
handleSave: () => void;
82+
handleSetColor: (color: string) => void;
83+
handleSetLineWidth: (lineWidth: number) => void;
84+
handleSetLineJoin: (type: "round" | "bevel" | "miter") => void;
85+
handleSetLineCap: (type: "square" | "round" | "butt") => void;
7486
getCanvasProps: (props?: PropsGetterInput) => PropsGetterResult;
7587
componentDidMount(): void;
7688
componentWillUnmount(): void;

dist/ReactPainter.js

Lines changed: 35 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)