Skip to content

Commit d3e63be

Browse files
committed
chore: one last round of revisions
1 parent 079b987 commit d3e63be

File tree

1 file changed

+121
-20
lines changed

1 file changed

+121
-20
lines changed

slides.md

+121-20
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ class: middle, center, title
99

1010
???
1111

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.
1314

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.
1819

1920
---
2021

@@ -25,8 +26,10 @@ linked up at the end.
2526
2627
???
2728

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.
3033

3134

3235
I like how this system focuses on separating CSS into categories and applies
@@ -44,10 +47,11 @@ good job explaining this.
4447

4548
???
4649

50+
Naming things is hard... and so is sorting things.
51+
4752
The ability to separate CSS into easy-to-communicate channels of concern will
4853
help drive our CSS architecture decisions.
4954

50-
5155
---
5256

5357
## Categories
@@ -131,7 +135,7 @@ body * {
131135

132136
```
133137

134-
???
138+
???
135139

136140
This is probably more how yours should look though
137141

@@ -177,6 +181,9 @@ of laying out how various components (modules) come together.
177181
You can see what he's going for here, the app/ page has one header and footer
178182
and this is the level at which we think about establishing how they render.
179183

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+
180187
---
181188

182189
## Layout
@@ -215,6 +222,13 @@ The bulk of style of this category should probably live within a layout
215222
component, in our shared styles at the root of the project or a combination of
216223
the 2 like the full height panel layout.
217224

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+
218232
---
219233

220234
## Module
@@ -225,7 +239,79 @@ the 2 like the full height panel layout.
225239

226240
???
227241

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+
.module span {
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 $radius 0;
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.
229315

230316
---
231317

@@ -247,11 +333,11 @@ Reusable classes like `.is-hidden` should probably be seen as bit of a smell
247333
considering we're not writing jquery though. Why put something in the DOM and
248334
force the browser to parse it just to render it invisible?
249335

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`.
255341

256342
---
257343

@@ -291,19 +377,33 @@ typography for.
291377
## What maybe doesn't fit for us
292378

293379
* But we use scss
294-
* `src/styles.scss` has no view encapsulation
295380
* View encapsulation lower the stakes of name-spacing
296381
* You shouldn't be writing a lot of base or theme styles as a rule
297382

298383
???
299384

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.
301393

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-*`)
303395

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.
305397

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).
307407

308408
Let's hold off on *theme* for the time being.
309409

@@ -356,3 +456,4 @@ media query because it's only applicable for bigger screens.
356456
* [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)
357457
* [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)
358458

459+

0 commit comments

Comments
 (0)