Skip to content

Include some advice on using styles #735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/react-scripts/template/src/App.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/**
* This is a good place to put styles related to the <App /> component.
* We recommend that, when possible, a component CSS file only includes styles
* that are used by that specific component. This is why all class names start
* with "App" in this example. Instead of defining nested selectors for child
* components, we recommend passing all relevant information as props (such as
* <Button color="red" size="large" />) in React. Then you can have <Button />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case it seems like you are going to directly inline all those styles. One common pattern is to pass down high level props like size={"large" | "medium" | "small"} and then use those to add the class App-size-large, App-size-medium...

I would expand a tiny bit your "nested selector" explanation to explain what I mentioned above. I think this should cover a lot of use cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, this is what I meant! I’ll figure out how to rephrase this.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not to recommend BEM notation for elements and modifiers?

* use its own Button.css file without coupling their styles together.
*/

.App {
text-align: center;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/react-scripts/template/src/index.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* This is a good place to put styles that apply to the whole page.
* We recommend to put component-specific styles into separate files.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nit picky but "We recommend to put" sounds a bit odd, how about "We recommend putting"

*/

body {
margin: 0;
padding: 0;
Expand Down