You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
templates include a script tag which assigns app_options to
218
218
a Javascript variable so that it as accessible from JS.
219
219
220
+
### React
221
+
Our default style if not mentioned here should be that mentioned in the AirBnb guide https://github.com/airbnb/javascript/tree/master/react (perhaps with the exception of closing tags on their own line).
222
+
* <aname="js-react-inline-styles"></a>
223
+
Prefer single object for all styles vs. inlined style objects
224
+
```jsx
225
+
// Bad
226
+
var component = (
227
+
<div style={{color:'red', display:'block'}}>
228
+
<div style={{color:'blue', fontSize:10}}>I'm a child</div>
229
+
</div>
230
+
);
231
+
232
+
// Good
233
+
var styles = {
234
+
root: {
235
+
color: 'red',
236
+
display: 'block
237
+
},
238
+
child: {
239
+
color:'blue',
240
+
fontSize:10
241
+
}
242
+
};
243
+
...
244
+
var component = (
245
+
<div style={styles.root}>
246
+
<div style={styles.child}>I'm a child</div>
247
+
</div>
248
+
);
249
+
```
250
+
* <a name="js-react-pixel-numbers"></a>
251
+
Prefer numbers vs strings for pixel values
252
+
```jsx
253
+
// Bad
254
+
var styles = {
255
+
root: {
256
+
width: '100px',
257
+
height: '100px'
258
+
}
259
+
}'
260
+
261
+
// Good
262
+
var styles = {
263
+
root: {
264
+
width:100,
265
+
height:100
266
+
}
267
+
};
268
+
```
269
+
* <a name="js-react-long-components"></a>
270
+
Components with many attributes should have one per line, with 4 spaces of indentation. Child components should have 2 spaces of indentation.
Since JSX [removes newlines before rendering to HTML](http://andrewhfarmer.com/how-whitespace-works-in-jsx/)
293
+
you can and should put child elements on their own line, instead of putting
294
+
them on the same line to avoid extra spaces.
295
+
296
+
```
297
+
// good
298
+
<Component
299
+
prop1="prop1"
300
+
prop2="prop2">
301
+
textContent
302
+
</Component>
303
+
304
+
305
+
// bad
306
+
<Component
307
+
prop1="prop1"
308
+
prop2="prop2">textContent</Component>
309
+
310
+
// good - fine to put content on same line if the tag opens & closes on that line
311
+
<Component>textContent</Component>
312
+
```
313
+
314
+
* <a name="js-react-aligned-tags"></a>
315
+
align open and close tags
316
+
```jsx
317
+
// Bad
318
+
var component = (<MyComponent
319
+
foo="bar"
320
+
onClose={this.handleClose}>
321
+
<ChildComponent/>
322
+
</MyComponent>);
323
+
324
+
// Good
325
+
var component = (
326
+
<MyComponent
327
+
foo="bar"
328
+
onClose={this.handleClose}>
329
+
<ChildComponent/>
330
+
</MyComponent>
331
+
);
332
+
```
333
+
334
+
220
335
### In /apps
221
336
222
337
Use lodash and jQuery libraries in `/apps`.
@@ -225,31 +340,6 @@ Use lodash and jQuery libraries in `/apps`.
225
340
226
341
Use Google Closure Tools in `/blockly-core`, especially for color conversion and keyboard identifiers. Prefer raw HTML over Closure Tools UI constructs for new code.
227
342
228
-
## JSX
229
-
230
-
* <aname="jsx-child-elements-on-own-line"></a>
231
-
Since JSX [removes newlines before rendering to HTML](http://andrewhfarmer.com/how-whitespace-works-in-jsx/)
232
-
you can and should put child elements on their own line, instead of putting
233
-
them on the same line to avoid extra spaces.
234
-
235
-
```
236
-
// good
237
-
<Component
238
-
prop1="prop1"
239
-
prop2="prop2">
240
-
textContent
241
-
</Component>
242
-
243
-
244
-
// bad
245
-
<Component
246
-
prop1="prop1"
247
-
prop2="prop2">textContent</Component>
248
-
249
-
// good - fine to put content on same line if the tag opens & closes on that line
0 commit comments