|
1 | 1 | <h1 align='center'> |
2 | | - Atelier |
| 2 | + Atelier 🎨 |
3 | 3 | </h1> |
4 | 4 |
|
5 | 5 | <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 |
35 | 35 |
|
36 | 36 | Prop | Description | Default |
37 | 37 | ---- | ----------- | ------- |
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> |
55 | 73 |
|
56 | 74 | ## 🖌️ 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"> |
58 | 117 |
|
59 | 118 | ## :page_facing_up: License |
60 | 119 |
|
|
0 commit comments