Skip to content

Commit d4bca3d

Browse files
authored
Update README.md
1 parent b07ffb1 commit d4bca3d

File tree

1 file changed

+78
-19
lines changed

1 file changed

+78
-19
lines changed

README.md

Lines changed: 78 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h1 align='center'>
2-
Atelier
2+
Atelier 🎨
33
</h1>
44

55
<p align="center"><strong>Expandable drawing component for React built by <a href="https://cobalt.run">Cobalt, Inc.</a></strong></p>
@@ -35,26 +35,85 @@ Demo page: [`https://cobaltinc.github.io/atelier`](https://cobaltinc.github.io/a
3535

3636
Prop | Description | Default
3737
---- | ----------- | -------
38-
`command` | | `pen`
39-
`color` | | `#000000`
40-
`lineWidth` | | `2`
41-
`width` | | `800`
42-
`height` | | `600`
43-
`enableDraw` | | `true`
44-
`enablePressure` | | `false`
45-
`plugins` | | `[PenPlugin]`
46-
`style` |
47-
`className` |
48-
49-
### 🖋️ Default Plugins
50-
* PenPlugin
51-
* EraserPlugin
52-
* BrushPlugin
53-
* HighlighterPlugin
54-
* LaserPlugin
38+
`command` | Set the name of registered plugin | `pen`
39+
`color` | Set the color of the line | `#000000`
40+
`lineWidth` | Set the width of the line | `2`
41+
`width` | Set the width of the canvas | `800`
42+
`height` | Set the height of the canvas | `600`
43+
`enableDraw` | Set to `true` or `false` to enable or disable draw the canvas | `true`
44+
`enablePressure` | Set to `true` or `false` to enable or disable pressure the canvas | `false`
45+
`plugins` | Register the plugins to use | `[PenPlugin]`
46+
`style` | Add inline styles to the root element
47+
`className` | Add className to the root element
48+
49+
### Instance Methods
50+
Use `ref` to call instance methods. See the [demo page](https://cobaltinc.github.io/atelier) for an example of this.
51+
Prop | Description
52+
---- | -----------
53+
`clear()` | Erase everything on the canvas
54+
55+
## 🖋️ Default Plugins
56+
<table>
57+
<tr>
58+
<th>PenPlugin</th><th>BrushPlugin</th><th>ErasePlugin</th>
59+
</tr>
60+
<tr>
61+
<td><img src="https://user-images.githubusercontent.com/3623695/141398823-7fe13e29-cbf7-4ae3-84fa-b14e88659148.gif" width='187' alt="PenPlugin gif"></td>
62+
<td><img src="https://user-images.githubusercontent.com/3623695/141398991-4f70f01f-59bd-494e-9f69-ce39372af698.gif" width='187' alt="BrushPlugin gif"></td>
63+
<td><img src="https://user-images.githubusercontent.com/3623695/141399191-aa396b83-7e05-4c5d-b075-3b8ebd701274.gif" width='187' alt="ErasePlugin gif"></td>
64+
</tr>
65+
<tr>
66+
<th>HighlighterPlugin</th><th>LaserPlugin</th>
67+
</tr>
68+
<tr>
69+
<td><img src="https://user-images.githubusercontent.com/3623695/141399532-d29a3454-d5c0-45f3-a4df-6f8794f382bd.gif" width='187' alt="HighlighterPlugin gif"></td>
70+
<td><img src="https://user-images.githubusercontent.com/3623695/141399656-677cb722-8556-477d-8106-635d548c350c.gif" width='187' alt="LaserPlugin gif"></td>
71+
</tr>
72+
</table>
5573

5674
## 🖌️ Custom Plugin
57-
WIP
75+
76+
If you want new plugin, you can make easily.
77+
78+
```tsx
79+
class DashPlugin extends Plugin {
80+
name: string = 'dash'; // Required
81+
lastX: number;
82+
lastY: number;
83+
84+
draw(data: DrawingInterface) {
85+
super.draw(data);
86+
87+
const { x, y, state } = data;
88+
const context = this.canvas.getContext('2d');
89+
context.setLineDash([5, 30]);
90+
91+
if (state === 'draw-started') {
92+
Object.assign(this, {
93+
lastX: x,
94+
lastY: y,
95+
});
96+
} else {
97+
context.beginPath();
98+
context.moveTo(this.lastX, this.lastY);
99+
context.lineTo(x, y);
100+
context.stroke();
101+
context.closePath();
102+
103+
Object.assign(this, {
104+
lastX: x,
105+
lastY: y,
106+
});
107+
}
108+
}
109+
}
110+
111+
<Atelier command="dash" plugins={[DashPlugin]} />
112+
```
113+
114+
And the result:
115+
116+
<img src="https://user-images.githubusercontent.com/3623695/141399812-9f8e3645-ad40-4d16-887e-0de485c7a720.gif" width="500" alt="DashPlugin gif">
58117

59118
## :page_facing_up: License
60119

0 commit comments

Comments
 (0)