-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextForm.js
More file actions
60 lines (56 loc) · 2.52 KB
/
TextForm.js
File metadata and controls
60 lines (56 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React,{useState} from 'react'
export default function TextForm(props) {
const handleUpClick=()=>{
//console.log("Uppercase was clicked" + text);
let newText = text.toUpperCase();
setText(newText)
props.showAlert("Converted to upper case!","success")
}
const handleLowClick=()=>{
let newText = text.toLowerCase();
setText(newText)
props.showAlert("Converted to lower case!","success")
}
const handleClClick=()=>{
let newText = '';
setText(newText)
props.showAlert("Text cleared!","success")
}
const handleTrimClick=()=>{
let newText = text.trim();
setText(newText)
props.showAlert(" Extra Space removed!","success")
}
const handleCopy=()=>{
navigator.clipboard.writeText(text);
props.showAlert("Copied to clipboard!","success")
}
const handleOnChange=(event)=>{
//console.log("On Change");
setText(event.target.value);
}
const[text,setText]=useState('');
// setText("new text") ---to change text
return (
<>
<div className="container" style={{color: props.mode==='dark'?'white':'black'}}>
<h1>{props.heading}</h1>
<div className="mb-3">
<textarea className="form-control" value={text} id="myBox" onChange={handleOnChange} style={{backgroundColor: props.mode==='dark'?'#191b24':'white',color: props.mode==='dark'?'white':'black'}} rows="7"></textarea>
</div>
<button disabled={text.length===0} className="btn btn-primary mx-2 my-1" onClick={handleUpClick}>Convert to Uppercase</button>
<button disabled={text.length===0} className="btn btn-primary mx-2 my-1" onClick={handleLowClick}>Convert to Lowercase</button>
<button disabled={text.length===0} className="btn btn-primary mx-2 my-1" onClick={handleTrimClick}>Trim Space</button>
<button disabled={text.length===0} className="btn btn-primary mx-2 my-1" onClick={handleClClick}>Clear Text</button>
<button disabled={text.length===0} className="btn btn-primary mx-2 my-1" onClick={handleCopy}>Copy Text</button>
</div>
<div className="container my-4" style={{color: props.mode==='dark'?'white':'black'}}>
<h4> Text Summary</h4>
<p>{text.split(/\s+/).filter((element)=>{return element.length!==0}).length} words and {text.length} characters</p>
<p>{0.008 * text.split(" ").length} Minutes to read </p>
<h4>Preview</h4>
<p>{text.length>0?text:"Nothing to preview"}</p>
</div>
</>
)
}