Last active
March 26, 2019 00:50
-
-
Save rachel-church/6fd96c8b5dab14d0363c1fef395ab33a to your computer and use it in GitHub Desktop.
Sample React component with global and modular styles
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
// styles/app.global.scss | |
// import all of bootstrap into this globally scoped file | |
@import "~bootstrap/scss/bootstrap"; | |
.header { | |
width: 100%; | |
background-color: red; | |
} |
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
// App.jsx | |
import 'styles/app.global.scss'; // Import the global styles once in the top-most App component | |
import styles from './app.scss'; // Import modular styles for the App component | |
import React from 'react'; | |
import cx from 'classnames'; // Optional classname helper library | |
import { Header } from './Header'; | |
export const App = () => ( | |
<div className={cx('container', styles.container)}> // Apply both a global class from bootstrap and a custom modular class | |
<Header /> | |
</div> | |
); |
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
// Header.jsx | |
import styles from './header.scss'; // Import modular styles for the Header component | |
import React from 'react'; | |
import cx from 'classnames'; // Optional classname helper library | |
export const Header = () => ( | |
<header className="header"> | |
<button className={cx('logo', styles.logo)}> // Apply both a global class and a modular class | |
{...} | |
</button> | |
</header> | |
); |
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
// header.scss | |
:global(.header) { | |
background-color: red; | |
} | |
.header { | |
font-size: 14px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment