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
Copy file name to clipboardExpand all lines: slides.md
+121-20
Original file line number
Diff line number
Diff line change
@@ -9,12 +9,13 @@ class: middle, center, title
9
9
10
10
???
11
11
12
-
Well, here we go again
12
+
In this presentation, I'd like to articulate a strategy for proper care and
13
+
feeding of CSS.
13
14
14
-
The presentation in which I attempt to articulate a strategy for proper care and
15
-
feeding of CSS. First off, if you haven't read [Jonathan Snook's take](http://smacss.com/book/)
16
-
on the subject, I recommend you still check out the source material. I have it
17
-
linked up at the end.
15
+
First off, if you haven't read [Jonathan Snook's take](http://smacss.com/book/)
16
+
on the subject, I recommend you still check out the source material.
17
+
18
+
I have it linked up at the end.
18
19
19
20
---
20
21
@@ -25,8 +26,10 @@ linked up at the end.
25
26
26
27
???
27
28
28
-
First off, I like the cut of Snook's jib. CSS is a complicated profession and
29
-
Jonathan leans into thought process over tools/libs/implementation details.
29
+
I'll start by saying: I like the cut of Snook's jib.
30
+
31
+
CSS is a complicated profession and Jonathan leans into thought process over
32
+
tools/libs/implementation details.
30
33
31
34
32
35
I like how this system focuses on separating CSS into categories and applies
@@ -44,10 +47,11 @@ good job explaining this.
44
47
45
48
???
46
49
50
+
Naming things is hard... and so is sorting things.
51
+
47
52
The ability to separate CSS into easy-to-communicate channels of concern will
48
53
help drive our CSS architecture decisions.
49
54
50
-
51
55
---
52
56
53
57
## Categories
@@ -131,7 +135,7 @@ body * {
131
135
132
136
```
133
137
134
-
???
138
+
???
135
139
136
140
This is probably more how yours should look though
137
141
@@ -177,6 +181,9 @@ of laying out how various components (modules) come together.
177
181
You can see what he's going for here, the app/ page has one header and footer
178
182
and this is the level at which we think about establishing how they render.
179
183
184
+
The fact that snook has IDs for header and article feels a touch dated, but the
185
+
general idea holds and those are pretty good names to drive the point.
186
+
180
187
---
181
188
182
189
## Layout
@@ -215,6 +222,13 @@ The bulk of style of this category should probably live within a layout
215
222
component, in our shared styles at the root of the project or a combination of
216
223
the 2 like the full height panel layout.
217
224
225
+
I don't want to dig too deep into component composition, but it's worth
226
+
mentioning that a sensible component strategy can greatly simplify your CSS
227
+
strategy. Really challenge how you interpret "separation of concerns".
228
+
229
+
Are you separating in a way that makes your life easier or just making files
230
+
smaller?
231
+
218
232
---
219
233
220
234
## Module
@@ -225,7 +239,79 @@ the 2 like the full height panel layout.
225
239
226
240
???
227
241
228
-
This class of style probably makes sense to live in the Style block of a given component, but still should be questioned before simply adding more to the app. Why do you feel you _need_ this CSS. Are you using the right classes and DOM structure? Are you striving for pixel perfection implementation of a mock that is off brand? Did you blindly copy from zeplin? The answer to these questions should guide your hand here.
242
+
This class of style probably makes sense to live in the context of a given
243
+
component. Do be critical when considering a component _should_ be customized.
244
+
245
+
Why do you feel you _need_ this CSS?
246
+
247
+
Are you using the right classes and DOM structure?
248
+
249
+
Are you striving for pixel perfection implementation of a mock that is off brand?
250
+
251
+
Did you blindly copy from zeplin?
252
+
253
+
The answer to these questions should guide your hand here.
254
+
255
+
---
256
+
257
+
## Module (example from SMACSS)
258
+
259
+
```scss
260
+
.module > h2 {
261
+
padding: 5px;
262
+
}
263
+
264
+
.modulespan {
265
+
padding: 5px;
266
+
}
267
+
```
268
+
269
+
???
270
+
271
+
See how in the book, Snook is using the name of a module to namespace the
272
+
styling? If you're writing styles in a component context, view encapsulation
273
+
will take care of that for you without a need to come up with clever names.
274
+
275
+
---
276
+
## Module
277
+
278
+
```scss
279
+
selector: 'app-card',
280
+
template: `
281
+
<h2>{{ title }}</h2>
282
+
<ng-content></ng-content>
283
+
`,
284
+
styles: [`
285
+
@import'variables';
286
+
287
+
:host {
288
+
border: solid$border-thickness$red;
289
+
display: block;
290
+
border-radius: $radius;
291
+
padding: $gap;
292
+
background-color: $brown-light-1;
293
+
}
294
+
295
+
h2 {
296
+
background: $whitish;
297
+
border: solid$border-thickness$grey;
298
+
padding: $gap;
299
+
border-radius: 0$radius$radius0;
300
+
box-shadow: $outer-shadow;
301
+
}
302
+
`]
303
+
```
304
+
305
+
???
306
+
307
+
:host is your friend. You've already declared a selector, You don't need to wrap
308
+
a div just to decorate it with something like .card .content or the like. If you
309
+
want to have something akin to a module without the component implication, you
310
+
could bundle such a thing up as global styles.
311
+
312
+
Considering how such styling tends to be coupled with the "right" markup to
313
+
work... you probably mostly want to leverage a small presenter component to
314
+
assure a convenient amount of coupling.
229
315
230
316
---
231
317
@@ -247,11 +333,11 @@ Reusable classes like `.is-hidden` should probably be seen as bit of a smell
247
333
considering we're not writing jquery though. Why put something in the DOM and
248
334
force the browser to parse it just to render it invisible?
249
335
250
-
If you can keep this abstract, you should and create a utility class or
251
-
placeholder at the root of the project. When you're working with a state
252
-
modifier that only makes sense applied to a given module, define it scoped as
253
-
such. Do so either through naming convention `is-tab-active` or through a
254
-
component's view encapsulation.
336
+
If you can keep this abstract, you should and creating a utility class or
337
+
placeholder at the root of the project makes sense. When you're working with a
338
+
state modifier that only makes sense applied to a given module, define it scoped
339
+
as such. Do so either through naming convention `is-tab-active` or through a
340
+
component's view encapsulation`is-active`.
255
341
256
342
---
257
343
@@ -291,19 +377,33 @@ typography for.
291
377
## What maybe doesn't fit for us
292
378
293
379
* But we use scss
294
-
*`src/styles.scss` has no view encapsulation
295
380
* View encapsulation lower the stakes of name-spacing
296
381
* You shouldn't be writing a lot of base or theme styles as a rule
297
382
298
383
???
299
384
300
-
SMACSS was written as a good strategy for plane ol vanilla CSS with no consideration or recommendation for getting tied to frameworks. As such, I think the problem solved with naming may better be solved in our context by location of css. SMACSS based thinking applied to our Angular + DS architecture probably shakes out like this.
385
+
SMACSS was written as a good strategy for plane ol vanilla CSS with no
386
+
consideration or recommendation for getting tied to frameworks. As such, I think
387
+
the problem solved with naming may better be solved in our context by location
388
+
of css. SMACSS based thinking applied to our Angular + DS architecture probably
389
+
shakes out like this.
390
+
391
+
*Base* code should come directly from the DS and be applied globally
392
+
(`src/styles/`). Keep all this out of component files.
301
393
302
-
*Base* code should come directly from the DS and be applied globally (`src/styles/`). Keep all this out of component files. Layout components (`modules/layout-*`) and global styles (`src/styles/`) will share the responsibility of *layout* styles.
394
+
Layout components (`modules/layout-*`)
303
395
304
-
*Module* is synonymous with how we see components, but we need to lean into granular components for this to work smoothly. Also, be more aware of how your base styles want to work and be more conservative about overriding that all willie nillie.
396
+
global styles (`src/styles/`) will share the responsibility of *layout*styles.
305
397
306
-
*State* CSS may live in the globally accessible styles (`src/styles`) if it makes sense outside of the context of your component, but is probably largely fine living in your component so long as you've confirmed you're not writing redundant code (this really is the enemy here).
398
+
*Module* is synonymous with how we see components, but we need to lean into
399
+
granular components for this to work smoothly. Also, be more aware of how your
400
+
base styles want to work and be more conservative about overriding that all
401
+
willie nillie.
402
+
403
+
*State* CSS may live in the globally accessible styles (`src/styles`) if it
404
+
makes sense outside of the context of your component, but is probably largely
405
+
fine living in your component so long as you've confirmed you're not writing
406
+
redundant code (this really is the enemy here).
307
407
308
408
Let's hold off on *theme* for the time being.
309
409
@@ -356,3 +456,4 @@ media query because it's only applicable for bigger screens.
356
456
*[Custom utility class defined in Match](https://dev.azure.com/jbhunt/EngAndTech/_git/app_operationsexecution_load_workflow_ui?path=/src/styles/panel-full-height.scss) (can be improved, but in the right direction)
357
457
*[Example of a layout component](https://dev.azure.com/jbhunt/EngAndTech/_git/app_operationsexecution_load_workflow_ui?path=/src/app/modules/layout/layout-panel/layout-panel.component.ts) (can be improved, but in the right direction)
0 commit comments