This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<StyledInput | |
invalid={!isValid} // prop | |
className={`${!isValid ? " invalid" : ""}`} | |
value={name} | |
type="text" | |
name="name" | |
onChange={nameChangeHandler} | |
></StyledInput> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<StyledButton type="submit">Submit</StyledButton> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const StyledButton = styled.button` | |
display: inline-block; | |
border-radius: 3px; | |
padding: 0.5rem 0; | |
margin: 0.5rem 1rem; | |
width: 11rem; | |
background: #000; | |
color: white; | |
border: 2px solid white; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in App.js | |
// import | |
import styled from 'styled-components'; | |
// Creating the styled button using the "styled" object imported from "styled-components" | |
// It will return a styled React component | |
const StyledButton = styled.button` | |
display: inline-block; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install --save styled-components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in App.js | |
{/* Conditionally set border and background color for invalid input */} | |
<input | |
className={`${!isValid ? " invalid" : ""}`} | |
value={name} | |
type="text" | |
name="name" | |
onChange={nameChangeHandler} | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* style.css */ | |
.main-heading { | |
background-color: aqua; | |
} | |
.invalid { | |
border: 2px solid red; | |
background-color: #ffcfcf; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* style.css */ | |
.main-heading { | |
background-color: aqua; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "./style.css"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1 className="main-heading">Styling in React by Aditya Tyagi</h1> |