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 11import './App.css' ;
22import Navbar from './components/Navbar' ;
33import TextForm from './components/TextForm' ;
4+ import React , { useState } from 'react' ;
5+
46
57function 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+ }
620 return (
721 < >
822 { /* <Navbar title="TextUtils" aboutText="About TextUtils" /> */ }
923 { /* <Navbar/> */ }
10- < Navbar title = "TextUtils" />
24+ < Navbar title = "TextUtils" mode = { mode } toggleMode = { toggleMode } />
1125 < 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 } />
1327 </ div >
1428 </ >
1529 ) ;
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
33
44export default function Navbar ( props ) {
55 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 } ` } >
77 < div className = "container-fluid" >
88 < a className = "navbar-brand" href = "/" > { props . title } </ a >
99 < 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) {
2020 </ ul >
2121 { /* <form className="d-flex">
2222 <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>
2425 </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 >
2530 </ div >
2631 </ div >
2732 </ nav >
Original file line number Diff line number Diff line change @@ -43,23 +43,23 @@ export default function TextForm(props) {
4343 // setText("new text"); // Correct way to change the state
4444 return (
4545 < >
46- < div className = "container" >
46+ < div className = "container" style = { { color : props . mode === 'dark' ? 'white' : '#042743' } } >
4747 < h1 > { props . heading } </ h1 >
4848 < 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 >
5050 </ div >
5151 < button className = "btn btn-primary mx-1" onClick = { handleUpClick } > Convert to Uppercase</ button >
5252 < button className = "btn btn-primary mx-1" onClick = { handleLoClick } > Convert to Lowercase</ button >
5353 < button className = "btn btn-primary mx-1" onClick = { handleClearClick } > Clear Text</ button >
5454 < button className = "btn btn-primary mx-1" onClick = { handleCopy } > Copy Text</ button >
5555 < button className = "btn btn-primary mx-1" onClick = { handleExtraSpaces } > Remove Extra Spaces</ button >
5656 </ div >
57- < div className = "container my-3" >
57+ < div className = "container my-3" style = { { color : props . mode === 'dark' ? 'white' : '#042743' } } >
5858 < h2 > Your text summary</ h2 >
5959 < p > { text . split ( " " ) . length } words and { text . length } characters</ p >
6060 < p > { 0.008 * text . split ( " " ) . length } Minutes read</ p >
6161 < h2 > Preview</ h2 >
62- < p > { text } </ p >
62+ < p > { text . length > 0 ? text : "Enter something in the textbox above to preview it here" } </ p >
6363 </ div >
6464 </ >
6565 )
You can’t perform that action at this time.
0 commit comments