Skip to content

Commit 54a4073

Browse files
Add files via upload
1 parent 7db06d3 commit 54a4073

File tree

4 files changed

+92
-16
lines changed

4 files changed

+92
-16
lines changed

public/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
name="description"
1010
content="This react app is created using react by shubham"
1111
/>
12+
13+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.4/css/fontawesome.min.css">
1214

1315
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
1416
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />

src/App.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,50 @@ import Footer from './components/Footer';
44
import Navbar from './components/Navbar.js';
55
import About from './components/About.js'
66
import TextForm from './components/TextForm.js'
7+
import Alert from './components/Alert.js';
78

89
function App()
910
{
1011
const [mode, setMode] = useState('light');
12+
/* ---------Alert into website----------- */
13+
const [alert,setAlert] = useState(null);
14+
15+
const showAlert = (message,type) => {
16+
17+
/* Object created to set alert : */
18+
setAlert({
19+
msg : message,
20+
type: type
21+
})
22+
23+
/* Auto dismissing the alert after some time : */
24+
25+
setTimeout(() => {
26+
setAlert(null);
27+
},1500);
28+
}
1129

1230
const togglemode = () => {
1331
if( mode=== 'dark')
1432
{
1533
setMode('light');
1634
document.body.style.background = "linear-gradient(45deg, rgb(241, 241, 241) 50%, rgb(158, 232, 255) 50%)";
35+
showAlert("Light mode has been enabled","success");
1736
}
1837
else
1938
{
2039
setMode('dark');
2140
document.body.style.background = "linear-gradient(45deg, rgb(92, 92, 92) 50%, rgb(27, 27, 27) 50%)";
41+
showAlert("Dark mode has been enabled","success");
2242
}
2343
}
2444

2545

2646
return (
2747
<>
2848
<Navbar title="TextUtils" about="About Us" mode={mode} togglemode={togglemode}/>
29-
<TextForm heading="Text Analysis And Convertor" summaryHead="Summery Of Your Text" mode={mode}/>
49+
<Alert alert={alert} />
50+
<TextForm heading="Text Analysis And Convertor" summaryHead="Summery Of Your Text" mode={mode} showAlert={showAlert}/>
3051
{/* <About mode={mode}/> */}
3152
<Footer creatername="Shubham Bawankar"/>
3253
</>

src/components/Alert.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
3+
export default function Alert(props) {
4+
const capatalize = (word) => {
5+
const lower = word.toLowerCase();
6+
return lower.charAt(0).toUpperCase() + lower.slice(1);
7+
}
8+
return (
9+
10+
/* if props.alert is not null then we will get rest code */
11+
12+
props.alert && <div class={`alert alert-${props.alert.type} alert-dismissible fade show`} role="alert">
13+
<strong>{capatalize(props.alert.type)} </strong>: {props.alert.msg}
14+
</div>
15+
16+
)
17+
}

src/components/TextForm.js

+51-15
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,77 @@ export default function TextForm(props) {
1010
}
1111

1212
const handleUpChange = () =>{
13-
// console.log("you have clicked on uppercase");
14-
let newUppertext = text.toUpperCase();
15-
setText(newUppertext);
13+
if( text != '')
14+
{
15+
let newUppertext = text.toUpperCase();
16+
setText(newUppertext);
17+
props.showAlert("Converted to Uppercase","success");
18+
}
19+
else
20+
{
21+
props.showAlert("There's Nothing To UpperCase Into TextBox","warning");
22+
}
1623
}
1724

1825
const handleLoChange = () => {
1926
// console.log("you have clicked on lowercase");
20-
let newLowertext = text.toLowerCase();
21-
setText(newLowertext);
27+
if( text != '')
28+
{
29+
let newLowertext = text.toLowerCase();
30+
setText(newLowertext);
31+
props.showAlert("Converted to Lowercase","success");
32+
}
33+
else
34+
{
35+
props.showAlert("There's Nothing To LowerCase Into TextBox","warning");
36+
}
37+
2238
}
2339

2440
const handleClear = () => {
2541
// console.log("You have clicked on clear");
42+
if(text != '')
43+
{
2644
let cleartext = "";
2745
setText(cleartext);
46+
props.showAlert("Cleared the whole text","danger");
47+
}
48+
else
49+
{
50+
props.showAlert("There's Nothing To Clear Into TextBox","warning");
51+
}
2852
}
2953

3054
const handleOnChangeAlert = () => {
31-
alert("You cannot make changes in preview");
55+
props.showAlert("You cannot make changes into preview","warning");
3256
}
3357

3458
const handlecopyfunction = () => {
35-
var copyText = document.getElementById("text");
36-
copyText.select();
37-
navigator.clipboard.writeText(copyText.value);
38-
if(copyText.value != '')
59+
if(text != '')
3960
{
40-
alert("Copied the text: " + copyText.value);
61+
var copyText = document.getElementById("text");
62+
copyText.select();
63+
navigator.clipboard.writeText(copyText.value);
64+
props.showAlert("Copied the text : "+ copyText.value, "success");
4165
}
4266
else
4367
{
44-
alert('Pls write some text into textbox');
45-
}
68+
props.showAlert("There's Nothing To Copy Into TextBox","warning");
69+
}
70+
4671
}
4772

4873
const handleExtraspaces = () => {
49-
let newText = text.split(/[ ]+/);
50-
setText(newText.join(" "))
74+
if(text != '')
75+
{
76+
let newText = text.split(/[ ]+/);
77+
setText(newText.join(" "));
78+
props.showAlert("All extra spaces are cleared","success");
79+
}
80+
else
81+
{
82+
props.showAlert("There's Nothing Remove Spaces Into TextBox","warning");
83+
}
5184
}
5285

5386

@@ -82,7 +115,10 @@ export default function TextForm(props) {
82115

83116

84117
return (
118+
119+
85120
<div className="main">
121+
86122
<div className="container my-5">
87123
<h1 className="text-center" style={props.mode==='dark'?style2dark:style2light}>{props.heading}</h1>
88124
<div className="mb-3 my-3" >

0 commit comments

Comments
 (0)