File tree Expand file tree Collapse file tree 2 files changed +63
-5
lines changed
07. Toggle-Background-Color/src Expand file tree Collapse file tree 2 files changed +63
-5
lines changed Original file line number Diff line number Diff line change 1- import React from 'react'
1+ import React from "react" ;
2+ import { useState } from "react" ;
23
34function ToggleBackgroundColor ( ) {
5+ const [ backgroundColor , setBackgroundColor ] = useState ( "white" ) ;
6+ const [ textColor , setTextColor ] = useState ( "#1b1b1b" ) ;
7+ const [ buttonStyle , setButtonStyle ] = useState ( "white" ) ;
8+
9+ const handleClick = ( ) => {
10+ setBackgroundColor ( backgroundColor === "white" ? "#1b1b1b" : "white" ) ;
11+ setTextColor ( textColor === '#1b1b1b' ? '#ffa31a' : "#1b1b1b" ) ;
12+ setButtonStyle ( backgroundColor === 'white' ? '#1b1b1b' : "white" ) ;
13+ } ;
14+
415 return (
5- < div >
6- ToggleBackgroundColor
16+ < div style = { { backgroundColor, color : textColor } } >
17+ < button
18+ onClick = { handleClick }
19+ style = { {
20+ buttonStyle,
21+ color : textColor ,
22+ border : `2px solid ${ textColor } ` ,
23+ } }
24+ >
25+ { backgroundColor === "#1b1b1b" ? "Black Theme" : "White Theme" }
26+ </ button >
27+
28+ < section className = "content" >
29+ < h1 >
30+ Welcome to A< br />
31+ Real World..
32+ </ h1 >
33+ </ section >
734 </ div >
8- )
35+ ) ;
936}
1037
11- export default ToggleBackgroundColor
38+ export default ToggleBackgroundColor ;
Original file line number Diff line number Diff line change 1+ @import url ("https://fonts.googleapis.com/css2?family=Bungee+Outline&display=swap" );
2+
3+ * {
4+ margin : 0 ;
5+ padding : 0 ;
6+ box-sizing : border-box;
7+ font-family : sans-serif;
8+ }
9+
10+ body section {
11+ height : 100vh ;
12+ display : flex;
13+ flex-direction : column;
14+ justify-content : center;
15+ align-items : center;
16+ }
17+
18+ button {
19+ position : absolute;
20+ top : 20px ;
21+ right : 20px ;
22+ padding : 10px 20px ;
23+ background : transparent;
24+ cursor : pointer;
25+ }
26+
27+ section .content h1 {
28+ font-size : 5rem ;
29+ font-family : "Bungee Outline" , cursive;
30+ line-height : 80px ;
31+ }
You can’t perform that action at this time.
0 commit comments