Skip to content

Commit 5f89ecf

Browse files
authored
Merge pull request #1 from the-working-party/feature/2023-july-updates
Feature/2023 july updates
2 parents 015bbac + 4f42876 commit 5f89ecf

7 files changed

+732
-480
lines changed

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.md

.prettierrc.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"semi": true,
3+
"tabWidth": 2,
4+
"singleQuote": true,
5+
"printWidth": 120,
6+
"bracketSpacing": false,
7+
"indentSchema": true,
8+
"overrides": [
9+
{
10+
"files": ["**/*.liquid"],
11+
"options": {
12+
"singleQuote": false
13+
}
14+
}
15+
]
16+
}

CSS-SASS.md

+233
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
# CSS
2+
3+
Work in progress
4+
5+
## Content
6+
7+
- [BEM Methodology](#bem-methodology)
8+
- [TWP Starter Theme common SASS usage](#twp-starter-theme-common-sass-usage)
9+
- [Additional notes](#additional-notes)
10+
- [Other style guides](#other-style-guides)
11+
12+
<br>
13+
<br>
14+
15+
---
16+
17+
## BEM methodology
18+
19+
By using the Block-Element-Modifier (BEM) CSS methodology, the chances of undesired and conflicting style overrides is virtually eliminated, and the need for nesting is diminished (which usually results in better performance, by eliminating excessive selector depth).
20+
21+
### Block, element, modifier basics
22+
23+
```scss
24+
.block {
25+
}
26+
27+
.block__element {
28+
}
29+
30+
.block__element--modifier {
31+
}
32+
33+
.block--modifier {
34+
}
35+
```
36+
37+
A good example is a simple card:
38+
39+
```scss
40+
// Product block
41+
.product {
42+
color: black;
43+
}
44+
45+
// Product elements
46+
.product__image {
47+
opacity: 1;
48+
}
49+
50+
// Product modifier
51+
.product--out-of-stock {
52+
color: red;
53+
54+
.product__image {
55+
opacity: 0.5;
56+
}
57+
}
58+
```
59+
60+
```html
61+
<!-- Normal product / color is black -->
62+
<div class="product">
63+
<img class="product__image" src="image.jpg" /> <!-- image is 100% opaque -->
64+
</div>
65+
66+
<!-- Out of stock product / color is red -->
67+
<div class="product product--out-of-stock">
68+
<img class="product__image" src="image.jpg" /> <!-- image is 50% opaque -->
69+
</div>
70+
```
71+
72+
### Do not use SASS `&__` or `&--`
73+
74+
That will make it much harder to debug and find the line of code.
75+
76+
```scss
77+
// Wrong
78+
.product {
79+
color: black;
80+
81+
&__image {
82+
opacity: 1;
83+
}
84+
}
85+
86+
// Right
87+
.product {
88+
color: black;
89+
}
90+
91+
.product__image {
92+
opacity: 1;
93+
}
94+
```
95+
96+
### Avoid over-qualified selectors by (unnecessary) nesting
97+
98+
That means the following code should be avoided. Not only because it produces more code, it also makes it harder to keep track of the parent-children chain, and harder to debug in some cases. The longer the rules, the harder it gets to keep track of the parent when deep nesting is used.
99+
100+
```scss
101+
// Unnecessary nesting
102+
.product {
103+
color: black;
104+
105+
.product__image {
106+
opacity: 1;
107+
}
108+
109+
&.product--out-of-stock {
110+
color: red;
111+
112+
.product__image {
113+
opacity: 0.5;
114+
}
115+
}
116+
}
117+
118+
// Would result in:
119+
.product { color: black }
120+
.product .product__image { opacity: 1 }
121+
.product.product--out-of-stock { color: red }
122+
.product.product--out-of-stock .product__image { opacity: 0.5 }
123+
124+
// As opposed to how it should be (without the unnecessary nesting):
125+
.product { color: black }
126+
.product__image { opacity: 1 }
127+
.product--out-of-stock { color: red }
128+
.product--out-of-stock .product__image { opacity: 0.5 }
129+
```
130+
131+
In the above example, `.product .product__image` is an over-qualification, as `.product__image` itself is sufficient to target the correct element.
132+
133+
### Blocks can also be elements of other blocks
134+
135+
In slightly more complex situations, blocks can also be elements of other blocks:
136+
137+
```scss
138+
// Price block
139+
.price {
140+
font-weight: 700;
141+
}
142+
143+
// Product price element
144+
.product__price {
145+
font-weight: 400;
146+
}
147+
```
148+
149+
```html
150+
<!-- Price used isolated / 700 -->
151+
<p><span class="price">$100</span></p>
152+
153+
<!-- Price used as a product element / 400 -->
154+
<div class="product">
155+
<p><span class="price product__price">$100</span></p>
156+
</div>
157+
```
158+
159+
<br>
160+
<br>
161+
162+
---
163+
164+
## TWP Starter Theme common SASS usage
165+
166+
### Use `$spacing-x` variables for defining margins and paddings
167+
168+
```scss
169+
.block {
170+
padding: $spacing-md;
171+
}
172+
```
173+
174+
### Use `media-min` and `media-max` mixins for breakpoints
175+
176+
```scss
177+
.block {
178+
font-size: rem(12px);
179+
180+
@include media-max($large) {
181+
font-size: rem(16px);
182+
}
183+
184+
@include media-min($large) {
185+
font-size: rem(24px);
186+
}
187+
}
188+
```
189+
190+
<br>
191+
<br>
192+
193+
---
194+
195+
## Additional notes
196+
197+
### Prefer `data-attributes` as selectors in JS
198+
199+
Whenever possible and where it makes sense.
200+
201+
```html
202+
<!-- HTML -->
203+
<button class="button button--primary" data-toggle-button>
204+
Open menu
205+
</button>
206+
```
207+
208+
```css
209+
/* CSS */
210+
.button {
211+
}
212+
213+
.button--primary {
214+
}
215+
```
216+
217+
```js
218+
// JS
219+
const toggleButton = container.querySelector('[data-toggle-button]');
220+
```
221+
222+
<br>
223+
<br>
224+
<br>
225+
226+
---
227+
228+
## Other style guides
229+
230+
1. [Core Principles](/README.md)
231+
2. [Javascript](/JAVASCRIPT.md)
232+
3. CSS
233+
4. [Liquid & HTML](/LIQUID-HTML.md)

0 commit comments

Comments
 (0)