File tree Expand file tree Collapse file tree 3 files changed +27
-8
lines changed Expand file tree Collapse file tree 3 files changed +27
-8
lines changed Original file line number Diff line number Diff line change 1
1
import './App.css' ;
2
2
import Navbar from './components/Navbar' ;
3
3
import TextForm from './components/TextForm' ;
4
+ import React , { useState } from 'react' ;
5
+
4
6
5
7
function App ( ) {
8
+ const [ mode , setMode ] = useState ( 'light' ) ; // Whether dark mode is enabled or not
9
+
10
+ const toggleMode = ( ) => {
11
+ if ( mode === 'light' ) {
12
+ setMode ( 'dark' ) ;
13
+ document . body . style . backgroundColor = '#042743' ;
14
+ }
15
+ else {
16
+ setMode ( 'light' ) ;
17
+ document . body . style . backgroundColor = 'white' ;
18
+ }
19
+ }
6
20
return (
7
21
< >
8
22
{ /* <Navbar title="TextUtils" aboutText="About TextUtils" /> */ }
9
23
{ /* <Navbar/> */ }
10
- < Navbar title = "TextUtils" />
24
+ < Navbar title = "TextUtils" mode = { mode } toggleMode = { toggleMode } />
11
25
< div className = "container my-3" >
12
- < TextForm heading = "Enter the text to analyze below" />
26
+ < TextForm heading = "Enter the text to analyze below" mode = { mode } />
13
27
</ div >
14
28
</ >
15
29
) ;
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
3
3
4
4
export default function Navbar ( props ) {
5
5
return (
6
- < nav className = " navbar navbar-expand-lg navbar-dark bg-dark" >
6
+ < nav className = { ` navbar navbar-expand-lg navbar-${ props . mode } bg-${ props . mode } ` } >
7
7
< div className = "container-fluid" >
8
8
< a className = "navbar-brand" href = "/" > { props . title } </ a >
9
9
< button className = "navbar-toggler" type = "button" data-bs-toggle = "collapse" data-bs-target = "#navbarSupportedContent" aria-controls = "navbarSupportedContent" aria-expanded = "false" aria-label = "Toggle navigation" >
@@ -20,8 +20,13 @@ export default function Navbar(props) {
20
20
</ ul >
21
21
{ /* <form className="d-flex">
22
22
<input className="form-control me-2" type="search" placeholder="Search" aria-label="Search" />
23
- <button className="btn btn-primary" type="submit">Search</button>
23
+ <button cla
24
+ ssName="btn btn-primary" type="submit">Search</button>
24
25
</form> */ }
26
+ < div className = { `form-check form-switch text-${ props . mode === 'light' ?'dark' :'light' } ` } >
27
+ < input className = "form-check-input" onClick = { props . toggleMode } type = "checkbox" id = "flexSwitchCheckDefault" />
28
+ < label className = "form-check-label" htmlFor = "flexSwitchCheckDefault" > Enable DarkMode</ label >
29
+ </ div >
25
30
</ div >
26
31
</ div >
27
32
</ nav >
Original file line number Diff line number Diff line change @@ -43,23 +43,23 @@ export default function TextForm(props) {
43
43
// setText("new text"); // Correct way to change the state
44
44
return (
45
45
< >
46
- < div className = "container" >
46
+ < div className = "container" style = { { color : props . mode === 'dark' ? 'white' : '#042743' } } >
47
47
< h1 > { props . heading } </ h1 >
48
48
< div className = "mb-3" >
49
- < textarea className = "form-control" value = { text } onChange = { handleOnChange } id = "myBox" rows = "8" > </ textarea >
49
+ < textarea className = "form-control" value = { text } onChange = { handleOnChange } style = { { backgroundColor : props . mode === 'dark' ? 'grey' : 'white' , color : props . mode === 'dark' ? 'white' : '#042743' } } id = "myBox" rows = "8" > </ textarea >
50
50
</ div >
51
51
< button className = "btn btn-primary mx-1" onClick = { handleUpClick } > Convert to Uppercase</ button >
52
52
< button className = "btn btn-primary mx-1" onClick = { handleLoClick } > Convert to Lowercase</ button >
53
53
< button className = "btn btn-primary mx-1" onClick = { handleClearClick } > Clear Text</ button >
54
54
< button className = "btn btn-primary mx-1" onClick = { handleCopy } > Copy Text</ button >
55
55
< button className = "btn btn-primary mx-1" onClick = { handleExtraSpaces } > Remove Extra Spaces</ button >
56
56
</ div >
57
- < div className = "container my-3" >
57
+ < div className = "container my-3" style = { { color : props . mode === 'dark' ? 'white' : '#042743' } } >
58
58
< h2 > Your text summary</ h2 >
59
59
< p > { text . split ( " " ) . length } words and { text . length } characters</ p >
60
60
< p > { 0.008 * text . split ( " " ) . length } Minutes read</ p >
61
61
< h2 > Preview</ h2 >
62
- < p > { text } </ p >
62
+ < p > { text . length > 0 ? text : "Enter something in the textbox above to preview it here" } </ p >
63
63
</ div >
64
64
</ >
65
65
)
You can’t perform that action at this time.
0 commit comments