Last active
September 14, 2023 17:55
-
-
Save rapPayne/7d8709ea8d391bbd118f799e63b4f211 to your computer and use it in GitHub Desktop.
React component styled with CSS nesting
This file contains hidden or 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
/* | |
** Note the use of CSS nesting. Nesting all styles underneath a class of | |
** ChangeName ensures they will ONLY be seen in the ChangeName component. | |
** ๐ This is the best of both worlds! | |
*/ | |
.ChangeName { | |
border: 1px solid var(--dark1); | |
padding: 10px; | |
&>div { | |
margin: 10px; | |
&>label { | |
display: block; | |
} | |
&>input { | |
font-size: 1.1em; | |
display: block; | |
} | |
} | |
&>button { | |
color: var(--light1); | |
background-color: var(--dark1); | |
} | |
} |
This file contains hidden or 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
// ๐ | |
// Back to simple! The only change is adding a className to the root and | |
// importing the CSS file. | |
import './ChangeName.css'; | |
export const ChangeName = ({ user, update, save }) => { | |
return ( | |
<section className="ChangeName"> | |
<div> | |
<label htmlFor="user">User name</label> | |
<input id="user" onChange={e => update(e.target.value)} value={user} /> | |
</div> | |
<button onClick={save}>Save</button> | |
</section> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment