@@ -103,7 +103,7 @@ export default function App() {
103
103
## Render Path
104
104
105
105
` ` ` jsx mdx: preview
106
- import React , { useRef , useEffect } from " react" ;
106
+ import React , { useRef } from " react" ;
107
107
import Signature from ' @uiw/react-signature' ;
108
108
109
109
const points = {
@@ -112,26 +112,32 @@ const points = {
112
112
}
113
113
114
114
export default function App () {
115
+ const $svg = useRef (null );
116
+ const handle = (evn ) => $svg .current ? .clear ();
115
117
return (
116
- < Signature
117
- defaultPoints= {points}
118
- renderPath= {(path , keyName ) => {
119
- if (keyName === ' path-1' ) {
120
- return < path d= {path} fill= " red" / >
121
- }
122
- if (keyName === ' path-2' ) {
123
- return < path d= {path} fill= " blue" / >
124
- }
125
- }}
126
- / >
118
+ <>
119
+ < Signature
120
+ ref= {$svg}
121
+ defaultPoints= {points}
122
+ renderPath= {(path , keyName , data , index ) => {
123
+ if (keyName === ' path-1' || index === 0 ) {
124
+ return < path d= {path} fill= " red" / >
125
+ }
126
+ if (keyName === ' path-2' || index === 1 ) {
127
+ return < path d= {path} fill= " blue" / >
128
+ }
129
+ }}
130
+ / >
131
+ < button onClick= {handle}> Clear< / button>
132
+ < / >
127
133
);
128
134
}
129
135
` ` `
130
136
131
137
## Stroke
132
138
133
139
` ` ` jsx mdx: preview
134
- import React , { useRef , useEffect } from " react" ;
140
+ import React , { useRef } from " react" ;
135
141
import Signature from ' @uiw/react-signature' ;
136
142
137
143
const points = {
@@ -140,37 +146,43 @@ const points = {
140
146
}
141
147
142
148
export default function App () {
149
+ const $svg = useRef (null );
150
+ const handle = (evn ) => $svg .current ? .clear ();
143
151
return (
144
- < Signature
145
- defaultPoints= {points}
146
- options= {{
147
- size: 6 ,
148
- }}
149
- renderPath= {(path , keyName ) => {
150
- return (
151
- <>
152
- < path
153
- d= {path}
154
- strokeWidth= " 3"
155
- stroke= " blue"
156
- fill= " transparent"
157
- strokeLinejoin= " round"
158
- strokeLinecap= " round"
159
- pointerEvents= " all"
160
- / >
161
- < path
162
- d= {path}
163
- strokeWidth= " 0"
164
- stroke= " transparent"
165
- fill= " #dadada"
166
- strokeLinejoin= " round"
167
- strokeLinecap= " round"
168
- pointerEvents= " all"
169
- / >
170
- < / >
171
- )
172
- }}
173
- / >
152
+ <>
153
+ < Signature
154
+ ref= {$svg}
155
+ defaultPoints= {points}
156
+ options= {{
157
+ size: 6 ,
158
+ }}
159
+ renderPath= {(path , keyName ) => {
160
+ return (
161
+ <>
162
+ < path
163
+ d= {path}
164
+ strokeWidth= " 3"
165
+ stroke= " blue"
166
+ fill= " transparent"
167
+ strokeLinejoin= " round"
168
+ strokeLinecap= " round"
169
+ pointerEvents= " all"
170
+ / >
171
+ < path
172
+ d= {path}
173
+ strokeWidth= " 0"
174
+ stroke= " transparent"
175
+ fill= " #dadada"
176
+ strokeLinejoin= " round"
177
+ strokeLinecap= " round"
178
+ pointerEvents= " all"
179
+ / >
180
+ < / >
181
+ )
182
+ }}
183
+ / >
184
+ < button onClick= {handle}> Clear< / button>
185
+ < / >
174
186
);
175
187
}
176
188
` ` `
0 commit comments