A Pen by John K. Speck on CodePen.
Created
March 27, 2020 16:50
-
-
Save speckworks/81d09ef0feb4a16a367dc0f33fcf3a4d to your computer and use it in GitHub Desktop.
Specialization of Components in ReactJS.
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
<div id="root"> | |
<!-- This div's content will be managed by React. --> | |
</div> |
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
function FancyBorder(props) { | |
return ( | |
<div className={'FancyBorder FancyBorder-' + props.color}> | |
{props.children} | |
</div> | |
); | |
} | |
function Dialog(props) { | |
return ( | |
<FancyBorder color="blue"> | |
<h1 className="Dialog-title"> | |
{props.title} | |
</h1> | |
<p className="Dialog-message"> | |
{props.message} | |
</p> | |
</FancyBorder> | |
); | |
} | |
function HowdyDialog() { | |
return ( | |
<Dialog | |
title="Howdy!" | |
message="Thank you for tasting specialized components with me!" /> | |
); | |
} | |
ReactDOM.render( | |
<HowdyDialog />, | |
document.getElementById('root') | |
); |
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
<script src="https://unpkg.com/react/umd/react.development.js"></script> | |
<script src="https://unpkg.com/react-dom/umd/react-dom.development.js"></script> |
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
.FancyBorder { | |
padding: 10px 10px; | |
border: 10px solid; | |
border-radius:10%; | |
} | |
.FancyBorder-blue { | |
border-color: purple; | |
} | |
.Dialog-title { | |
margin: 10; | |
font-family: sans-serif; | |
} | |
.Dialog-message { | |
margin: 10px; | |
font-size: larger; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment