Skip to content

Commit 45e4310

Browse files
committed
chore: build out content to contrast SMACSS and our context
1 parent bdaf39f commit 45e4310

File tree

6 files changed

+10437
-25
lines changed

6 files changed

+10437
-25
lines changed

Diff for: assets/base.jpg

53.5 KB
Loading

Diff for: docs/assets/base.jpg

53.5 KB
Loading

Diff for: docs/index.html

+257-10
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
> frameworks into a flexible thought process
6161

6262
???
63+
6364
First off, I like the cut of Snook's jib. CSS is a complicated profession and
6465
Jonathan leans into thought process over tools/libs/implementation details.
6566

@@ -71,13 +72,18 @@
7172
---
7273

7374
## Categories
74-
The ability to separate CSS into easy-to-communicate channels of concern will help drive our CSS architecture decisions.
7575

7676
* What do I call this?
7777
* Where should I put this?
7878
* Should I even be writing this?
7979
* Where should I look for prior art before I likely introduce duplicate CSS?
8080

81+
???
82+
83+
The ability to separate CSS into easy-to-communicate channels of concern will
84+
help drive our CSS architecture decisions.
85+
86+
8187
---
8288

8389
## Categories
@@ -88,44 +94,245 @@
8894
* State
8995
* Theme
9096

97+
---
98+
background-image: url(./assets/base.jpg)
99+
background-size: 700px auto
100+
101+
## Base (examples from SMACSS)
102+
103+
104+
???
105+
106+
The base rules are your defaults.
107+
108+
This should probably come directly from the Design System, and if it doesn't,
109+
should be applied globally in the root stylesheet instead of in every component
110+
that wants sensible defaults.
111+
112+
Wording that a different way may make it more self evident:
113+
"Does it make sense to define a _default_ inside view encapsulation?"
114+
115+
- Establishing defaults for your app
116+
- Heavily rely on the Design system here
117+
- Never use a !important here
118+
119+
---
120+
121+
## Base (example from SMACSS)
122+
123+
```scss
124+
// styles.scss
125+
// styles/_base.scss
126+
127+
body, form {
128+
margin: 0;
129+
padding: 0;
130+
}
131+
132+
a {
133+
color: #039;
134+
}
135+
136+
a:hover {
137+
color: #03F;
138+
}
139+
140+
```
141+
142+
???
143+
144+
This is the demo that Snook shares in his book.
145+
91146
---
92147

93148
## Base
94149

95-
The base rules are your defaults. This should probably come directly from the
96-
Design System, and if it doesn't, should be applied globally in the root
97-
stylesheet instead of in every component that wants sensible defaults. Wording
98-
that a different way may make it more self evident "Does it make sense to define
99-
a _default_ inside view encapsulation?"
150+
```scss
151+
// styles.scss
152+
// styles/_base.scss
153+
154+
html,
155+
body {
156+
padding: 0;
157+
margin: 0;
158+
height: 100%;
159+
background-color: $whitish;
160+
color: $grey;
161+
}
162+
163+
body * {
164+
box-sizing: border-box;
165+
font-family: $font-family-sans;
166+
}
167+
168+
```
169+
170+
???
171+
172+
This is probably more how yours should look though
100173

101174
---
102175

103176
## Layout
104177

105-
The bulk of style of this category should probably live within a layout component, in our shared styles at the root of the project or a combination of the 2 like the full height panel layout.
178+
- Scoped like page layout
179+
- Structure to compose components
180+
- Traditionally ID selectors
181+
- we probably want component selectors.
182+
- _Could_ live in a more globally accessible place
183+
- `styles/_layout.scss` is common enough
184+
- _Probably should_ live in a set of components
185+
- `shared/layout.component` feels sensible to me
186+
187+
???
188+
189+
Snook calls out that you can use the word layout at many different scopes and
190+
be correct, but what he means is essentially a "page layout" or a higher level
191+
of laying out how various components (modules) come together.
192+
193+
---
194+
195+
## Layout (example from SMACSS)
196+
197+
```scss
198+
// styles/_layout.scss
199+
200+
#header, #article, #footer {
201+
width: 960px;
202+
margin: auto;
203+
}
204+
205+
#article {
206+
border: solid #CCC;
207+
border-width: 1px 0 0;
208+
}
209+
```
210+
211+
???
212+
213+
You can see what he's going for here, the app/ page has one header and footer
214+
and this is the level at which we think about establishing how they render.
215+
216+
---
217+
218+
## Layout
219+
220+
```scss
221+
// shared/layout/layout.component.ts
222+
223+
@Component({
224+
selector: 'app-layout',
225+
template: `
226+
<div class="aside" *ngIf="showAside">
227+
<ng-content select="[aside]"></ng-content>
228+
</div>
229+
<div class="primary">
230+
<ng-content></ng-content>
231+
</div>
232+
<div class="secondary" *ngIf="showDetails">
233+
<ng-content select="[secondary]"></ng-content>
234+
</div>
235+
`,
236+
styles: [`
237+
.primary {
238+
flex: 1;
239+
}
240+
.aside,
241+
.secondary {
242+
flex: 0 0 33.3%;
243+
}
244+
`]
245+
})
246+
```
247+
248+
???
249+
250+
The bulk of style of this category should probably live within a layout
251+
component, in our shared styles at the root of the project or a combination of
252+
the 2 like the full height panel layout.
106253

107254
---
108255

109256
## Module
110257

258+
- Read: components
259+
- View encapsulation simplifies this
260+
- Still worth thinking about
261+
262+
???
263+
111264
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.
112265

113266
---
114267

115268
## State
116269

117-
This is the category of CSS that feels most compatible with utility classes. Reusable classes like `.hidden` should probably be seen as bit of a smell considering we're not writing jquery though. Why put something in the DOM and force the browser to parse it just to render it invisible?
270+
> 1. State styles can apply to layout and/or module styles; and
271+
> 2. State styles indicate a JavaScript dependency.
272+
273+
```scss
274+
.is-hidden
275+
.is-collapsed
276+
.is-error
277+
```
278+
279+
???
280+
281+
This is the category of CSS that feels most compatible with utility classes.
282+
Reusable classes like `.is-hidden` should probably be seen as bit of a smell
283+
considering we're not writing jquery though. Why put something in the DOM and
284+
force the browser to parse it just to render it invisible?
285+
286+
If you can keep this abstract, you should and create a utility class or
287+
placeholder at the root of the project. When you're working with a state
288+
modifier that only makes sense applied to a given module, define it scoped as
289+
such. Do so either through naming convention `is-tab-active` or through a
290+
component's view encapsulation.
118291

119292
---
120293

121-
## Theme
294+
## Theme (example from SMACSS)
295+
296+
```scss
297+
// in module-name.css
298+
299+
.mod {
300+
border: 1px solid;
301+
}
302+
303+
// in theme.css
304+
305+
.mod {
306+
border-color: blue;
307+
}
308+
```
309+
310+
???
311+
312+
You probably don't need this, but I want to go over it quickly for completeness.
313+
314+
Note: there's not an override, this example defines the theme specific attribute
315+
in a theme file and not in the module's file.
316+
317+
The DS has a light and dark theme, which is one way to interpret this category.
318+
Should we lean into responsive design, you can make an argument for that sort of
319+
shift being a "mobile theme". For now, we'll mostly assume this category as not
320+
our problem.
122321

123-
The DS has a light and dark theme, which is one way to interpret this category. Should we lean into responsive design, you can make an argument for that sort of shift being a "mobile theme". For now, we'll mostly assume this category as not our problem.
322+
You may use this to define different color schemes or maybe more densely packed
323+
typography for.
124324

125325
---
126326

127327
## What maybe doesn't fit for us
128328

329+
* But we use scss
330+
* `src/styles.scss` has no view encapsulation
331+
* View encapsulation lower the stakes of name-spacing
332+
* You shouldn't be writing a lot of base or theme styles as a rule
333+
334+
???
335+
129336
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.
130337

131338
*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.
@@ -138,6 +345,46 @@
138345

139346
---
140347

348+
## Mobile First
349+
350+
* **Not about** _optimizing for mobile_
351+
* **Is about** starting with clarity
352+
353+
???
354+
355+
---
356+
357+
## Mobile First
358+
359+
```scss
360+
// styles/_nav.scss
361+
362+
%nav-vertical {
363+
@extend %nav;
364+
}
365+
366+
%nav-horizontal {
367+
@extend %nav;
368+
369+
@media (min-width: $small) {
370+
li {
371+
display: inline-block;
372+
}
373+
374+
a {
375+
margin: 0 0.25em;
376+
}
377+
}
378+
}
379+
```
380+
381+
???
382+
383+
In this example, I define navigation to be vertically oriented by default, then
384+
alter that to fit horizontal. However, I enable the horizontal variant in a
385+
media query because it's only applicable for bigger screens.
386+
---
387+
141388
# Resources
142389

143390
* [SMACSS](http://smacss.com/book/)

0 commit comments

Comments
 (0)