Created
September 21, 2016 23:13
-
-
Save choonkending/705827e0523adbdcef46c2d7ea13a6d3 to your computer and use it in GitHub Desktop.
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
/* Modal */ | |
<div className="modal"> | |
<CloseButton /> | |
</div> | |
/* CloseButton */ | |
<button className="close-button">Close</button> |
Better but
- Can't edit Modal s styles to use another button without having to refactor modal.css
- nested declaration makes debugging harder with unpredictable specificity
/* close-button.css */
.close-button {
red;
}
/* modal.css */
.modal .close-button {
position: absolute;
top: 10px;
}
Better:
- close button is an element of modal
Still not good:
- Extra DOM nesting
/* modal.css */
.modal__close-button {
position: absolute;
top: 10px;
}
/* Modal.js */
<div className="modal">
<div className="modal__close-button">
<CloseButton />
</div>
</div>
/* Modal.js */
<div className="modal">
<CloseButton className="modal__close-button"/>
</div>
/* CloseButton.jsx */
<button className=`close-button ${this.props.className || ''}`>Close</button>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pretty bad for re-usability because we shouldn't assume its position to always be the same whatever its parent context.