File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,21 @@ export default function TextForm(props) {
23
23
setText ( event . target . value )
24
24
}
25
25
26
+ // Credits: A
27
+ const handleCopy = ( ) => {
28
+ console . log ( "I am copy" ) ;
29
+ var text = document . getElementById ( "myBox" ) ;
30
+ text . select ( ) ;
31
+ text . setSelectionRange ( 0 , 9999 ) ;
32
+ navigator . clipboard . writeText ( text . value ) ;
33
+ }
34
+
35
+ // Credits: Coding Wala
36
+ const handleExtraSpaces = ( ) => {
37
+ let newText = text . split ( / [ ] + / ) ;
38
+ setText ( newText . join ( " " ) )
39
+ }
40
+
26
41
const [ text , setText ] = useState ( '' ) ;
27
42
// text = "new text"; // Wrong way to change the state
28
43
// setText("new text"); // Correct way to change the state
@@ -36,6 +51,8 @@ export default function TextForm(props) {
36
51
< button className = "btn btn-primary mx-1" onClick = { handleUpClick } > Convert to Uppercase</ button >
37
52
< button className = "btn btn-primary mx-1" onClick = { handleLoClick } > Convert to Lowercase</ button >
38
53
< button className = "btn btn-primary mx-1" onClick = { handleClearClick } > Clear Text</ button >
54
+ < button className = "btn btn-primary mx-1" onClick = { handleCopy } > Copy Text</ button >
55
+ < button className = "btn btn-primary mx-1" onClick = { handleExtraSpaces } > Remove Extra Spaces</ button >
39
56
</ div >
40
57
< div className = "container my-3" >
41
58
< h2 > Your text summary</ h2 >
You can’t perform that action at this time.
0 commit comments