|
14 | 14 |
|
15 | 15 | - Use camelCase for object keys (i.e. "selectors").
|
16 | 16 |
|
17 |
| - > Why? We access these keys as properties on the `styles` object in the component, so it is most convenient to use camelCase. |
| 17 | + > Why? We access these keys as properties on the `styles` object in the component, so it is most convenient to use camelCase. |
18 | 18 |
|
19 | 19 | ```js
|
20 | 20 | // bad
|
|
34 | 34 |
|
35 | 35 | - Use an underscore for modifiers to other styles.
|
36 | 36 |
|
37 |
| - > Why? Similar to BEM, this naming convention makes it clear that the styles are intended to modify the element preceded by the underscore. Underscores do not need to be quoted, so they are preferred over other characters, such as dashes. |
| 37 | + > Why? Similar to BEM, this naming convention makes it clear that the styles are intended to modify the element preceded by the underscore. Underscores do not need to be quoted, so they are preferred over other characters, such as dashes. |
38 | 38 |
|
39 | 39 | ```js
|
40 | 40 | // bad
|
|
64 | 64 |
|
65 | 65 | - Use `selectorName_fallback` for sets of fallback styles.
|
66 | 66 |
|
67 |
| - > Why? Similar to modifiers, keeping the naming consistent helps reveal the relationship of these styles to the styles that override them in more adequate browsers. |
| 67 | + > Why? Similar to modifiers, keeping the naming consistent helps reveal the relationship of these styles to the styles that override them in more adequate browsers. |
68 | 68 |
|
69 | 69 | ```js
|
70 | 70 | // bad
|
|
92 | 92 |
|
93 | 93 | - Use a separate selector for sets of fallback styles.
|
94 | 94 |
|
95 |
| - > Why? Keeping fallback styles contained in a separate object clarifies their purpose, which improves readability. |
| 95 | + > Why? Keeping fallback styles contained in a separate object clarifies their purpose, which improves readability. |
96 | 96 |
|
97 | 97 | ```js
|
98 | 98 | // bad
|
|
133 | 133 |
|
134 | 134 | - Use device-agnostic names (e.g. "small", "medium", and "large") to name media query breakpoints.
|
135 | 135 |
|
136 |
| - > Why? Commonly used names like "phone", "tablet", and "desktop" do not match the characteristics of the devices in the real world. Using these names sets the wrong expectations. |
| 136 | + > Why? Commonly used names like "phone", "tablet", and "desktop" do not match the characteristics of the devices in the real world. Using these names sets the wrong expectations. |
137 | 137 |
|
138 | 138 | ```js
|
139 | 139 | // bad
|
|
155 | 155 |
|
156 | 156 | - Define styles after the component.
|
157 | 157 |
|
158 |
| - > Why? We use a higher-order component to theme our styles, which is naturally used after the component definition. Passing the styles object directly to this function reduces indirection. |
| 158 | + > Why? We use a higher-order component to theme our styles, which is naturally used after the component definition. Passing the styles object directly to this function reduces indirection. |
159 | 159 |
|
160 | 160 | ```jsx
|
161 | 161 | // bad
|
|
198 | 198 |
|
199 | 199 | - Leave a blank line between adjacent blocks at the same indentation level.
|
200 | 200 |
|
201 |
| - > Why? The whitespace improves readability and reduces the likelihood of merge conflicts. |
| 201 | + > Why? The whitespace improves readability and reduces the likelihood of merge conflicts. |
202 | 202 |
|
203 | 203 | ```js
|
204 | 204 | // bad
|
|
234 | 234 |
|
235 | 235 | - Use inline styles for styles that have a high cardinality (e.g. uses the value of a prop) and not for styles that have a low cardinality.
|
236 | 236 |
|
237 |
| - > Why? Generating themed stylesheets can be expensive, so they are best for discrete sets of styles. |
| 237 | + > Why? Generating themed stylesheets can be expensive, so they are best for discrete sets of styles. |
238 | 238 |
|
239 | 239 | ```jsx
|
240 | 240 | // bad
|
|
373 | 373 |
|
374 | 374 | - Define tricky fallback properties in themes.
|
375 | 375 |
|
376 |
| - > Why? Many CSS-in-JavaScript implementations merge style objects together which makes specifying fallbacks for the same property (e.g. `display`) a little tricky. To keep the approach unified, put these fallbacks in the theme. |
| 376 | + > Why? Many CSS-in-JavaScript implementations merge style objects together which makes specifying fallbacks for the same property (e.g. `display`) a little tricky. To keep the approach unified, put these fallbacks in the theme. |
377 | 377 |
|
378 | 378 | ```js
|
379 | 379 | // bad
|
|
0 commit comments