Skip to content

Commit df9c4e3

Browse files
author
Peter Hozak
committed
add first 3 examples and tips
1 parent 9f06243 commit df9c4e3

File tree

10 files changed

+209
-26
lines changed

10 files changed

+209
-26
lines changed

03-css-debugging/README.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,26 @@ npm start
2121

2222
## Content
2323

24-
* TODO links to code examples
25-
26-
## Useful tips
27-
28-
* TODO links to external pages
24+
```sh
25+
cd src/examples/
26+
```
27+
* 00 Intro
28+
* Using [browser inspector](https://developers.google.com/web/tools/chrome-devtools/css/) (right click > Inspect)
29+
* Good class names more important due to lack of step-by-step debug
30+
* Know thy framework / use consistent code style to simplify search in code
31+
* CSS vs CSS-in-JS => hot reload vs cleaner code over time
32+
* 01 Vertical alignment
33+
* Parent height
34+
* [`vertical-align`](https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align) is only for inline and table cells
35+
* Know thy [flexbox](https://css-tricks.com/snippets/css/a-guide-to-flexbox/) (or trial & error)
36+
* 02 Z-index
37+
* [Stacking context](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context)
38+
* `static` content is for elements that keep to themselves
39+
* if they need to overlap in arbitrary ways, best to go `absolute`
40+
* or [`grid`](https://css-tricks.com/snippets/css/complete-guide-grid/) (order in HTML according to Z order, manual row+column for position)
41+
* 03 Selector specificity
42+
* TODO
43+
* 04 Responsive
44+
* TODO
45+
* 05 Transitions
46+
* TODO

03-css-debugging/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"emotion": "10.0.7",
7+
"node-sass": "4.11.0",
68
"react": "^16.7.0-alpha",
79
"react-dom": "^16.7.0-alpha",
10+
"react-router": "4.3.1",
11+
"react-router-dom": "4.3.1",
812
"react-scripts": "2.1.3"
913
},
1014
"scripts": {

03-css-debugging/src/App.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
import React, { Component } from 'react';
2-
import './App.scss';
1+
import React from 'react'
2+
import {BrowserRouter as Router, Route, NavLink} from 'react-router-dom'
3+
import './App.scss'
4+
import examples from './examples'
35

4-
class App extends Component {
5-
render() {
6-
return (
7-
<div className="App">
8-
Case 01: vertical alignment
6+
const App = () => (
7+
<Router>
8+
<div className="App">
9+
<div className="App__header">
10+
{examples.map(ex => <NavLink key={ex.id} to={`/${ex.id}`}>{ex.title}</NavLink>)}
911
</div>
10-
);
11-
}
12-
}
1312

14-
export default App;
13+
<div className="App__content">
14+
{examples.map(ex => <Route key={ex.id} path={`/${ex.id}`} component={ex.component} />)}
15+
</div>
16+
</div>
17+
</Router>
18+
)
19+
20+
export default App

03-css-debugging/src/App.scss

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,41 @@
1-
$debugColor: transparent;
2-
31
.App {
4-
background: $debugColor;
52
display: flex;
3+
flex-direction: column;
4+
flex-wrap: wrap;
65
align-items: center;
7-
justify-content: center;
6+
height: 100vh;
7+
background: #aaa;
88
}
9+
10+
.App__header {
11+
margin: 10px;
12+
13+
a {
14+
color: #557;
15+
text-decoration: none;
16+
padding: 0 5px;
17+
}
18+
a.active {
19+
color: black;
20+
font-weight: bold;
21+
}
22+
a:hover {
23+
color: #33b;
24+
}
25+
}
26+
27+
.App__content {
28+
display: flex;
29+
flex: 1;
30+
31+
*:not(.Vertical) {
32+
margin: auto;
33+
}
34+
}
35+
36+
//$debugColor: #c30;
37+
//* {
38+
// background: rgba($debugColor, .1) !important;
39+
// outline: 1px dotted $debugColor !important;
40+
// color: $debugColor !important;
41+
//}

03-css-debugging/src/App.test.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom';
3-
import App from './App';
1+
import React from 'react'
2+
import ReactDOM from 'react-dom'
3+
import App from './App'
4+
import examples from './examples'
5+
import fs from 'fs'
46

57
it('renders without crashing', () => {
6-
const div = document.createElement('div');
7-
ReactDOM.render(<App />, div);
8-
ReactDOM.unmountComponentAtNode(div);
8+
const div = document.createElement('div')
9+
ReactDOM.render(<App />, div)
10+
ReactDOM.unmountComponentAtNode(div)
911
});
12+
13+
it('all examples are imported', () => {
14+
const files = fs.readdirSync(`${__dirname}/examples`).filter(f => f.match(/^\d.*\.js$/)).map(f => f.slice(0, 2))
15+
const imported = examples.map(e => e.id)
16+
expect(imported.sort()).toEqual(files.sort())
17+
})
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react'
2+
import {css, cx} from 'emotion'
3+
4+
const clsPrefix = 'Intro'
5+
const coin = 0.5 // Math.random()
6+
7+
const randomStyle = css`color: orange;`
8+
const randomName = cx({
9+
first: coin < 0.6,
10+
second: coin > 0.4
11+
})
12+
const niceName = cx(`${clsPrefix}__niceName`, css`color: green;`)
13+
14+
const Example = () => (
15+
<div className={clsPrefix}>
16+
Example 00: browser inspector + class names
17+
<div className={randomStyle}>Lorem ipsum</div>
18+
<div className={randomName}>Lorem ipsum</div>
19+
<div className={niceName}>Lorem ipsum</div>
20+
</div>
21+
)
22+
23+
export default {
24+
id: '00',
25+
title: 'Intro',
26+
component: Example,
27+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react'
2+
3+
const Example = () => (
4+
<div className="Vertical">
5+
Example 01: why am I not vertically centered?
6+
</div>
7+
)
8+
9+
export default {
10+
id: '01',
11+
title: 'Vertical alignment',
12+
component: Example,
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react'
2+
3+
const Example = () => (
4+
<div className="Z">
5+
<div className="Z__shouldBeOnTop">
6+
Example 02: why am I not on top?
7+
</div>
8+
<div className="Z__evilStackingContext">
9+
Lorem ipsum
10+
</div>
11+
</div>
12+
)
13+
14+
export default {
15+
id: '02',
16+
title: 'Z-index',
17+
component: Example,
18+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.Intro {
2+
.first {
3+
color: skyblue;
4+
}
5+
.second {
6+
color: navy;
7+
}
8+
&__niceName {
9+
color: maroon;
10+
}
11+
}
12+
13+
14+
15+
16+
.Vertical {
17+
vertical-align: center; // <-- doesn't work
18+
}
19+
20+
21+
22+
23+
.Z {
24+
.Z__shouldBeOnTop {
25+
z-index: 9999;
26+
}
27+
.Z__evilStackingContext {
28+
position: relative;
29+
display: inline-block;
30+
&::after {
31+
z-index: 1;
32+
position: absolute;
33+
top: -20px;
34+
right: 0;
35+
color: red;
36+
content: 'X';
37+
font-size: 2em;
38+
}
39+
}
40+
}
41+
42+
43+
#ddfdsfas, div[dsfas*=fsafdsa], .first.second, .dfasfsafasdfc {
44+
color: red;
45+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import './examples.scss'
2+
3+
import ex00 from './00-intro'
4+
import ex01 from './01-vertical-alignment'
5+
import ex02 from './02-z-index'
6+
7+
export default [
8+
ex00,
9+
ex01,
10+
ex02,
11+
]

0 commit comments

Comments
 (0)