Skip to content

Commit a2e118e

Browse files
Initial version of coding guides styling section (#10)
* Initial version of coding guides styling section * Fixed a typo
1 parent bc060e4 commit a2e118e

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

docs/guides.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
# Styles
3+
4+
Project is using SASS language (`.scss` flavor) for styling.
5+
6+
In order to maintain separation and prevent "leaking" of styles this project is using simplified version of BEM naming convention.
7+
8+
BEM stands for Block Element Modifier and is a way to uniquely define class names regardless of the project size. Originally BEM convention mandates double underscores between block and element and double dash between element and modifier with an optional single dash inside block, element and modifier names like:
9+
10+
```
11+
block-name__element-name--modifier-name
12+
```
13+
14+
Given that elements with a modifier are required to keep a separate class name with block and element only this can lead to a cumbersome markup:
15+
16+
``` html
17+
<div class="block-name__element-name block-name__element-name--modifier1 block-name__element-name--modifier2">
18+
```
19+
20+
In order to simplify and improve readability, we made couple of changes to the original convention:
21+
22+
- All block, element and modifier names have to be in lowercase with no dashes.
23+
- In React components block name always corresponds to a component and has to be the same as component name but in all lowercase. There has to be exactly one block for every component.
24+
- Modifier name is a separate class and it starts with a double dash.
25+
26+
This leads to the following class names:
27+
28+
``` html
29+
<div className="blockname__elementname --modifier1 --modifier2">
30+
```
31+
32+
Note that modifier names used like this still have some minimal risk of leaking down to sub-elements that might be having modifiers of their own with the same name. If a component being styled is a container-type component with arbitrary child components than modifier names should follow more conventional naming.
33+
34+
## Global styles
35+
36+
Global styles follow similar naming conventions with the exception that block name is prefixed with `ep-` like:
37+
38+
``` html
39+
<btn className="ep-btn --primary --shadow">
40+
```
41+
42+
All global styles are included in `index.scss` file.
43+
44+
## Constants
45+
46+
Project has a number of constants that are saved in `constants.scss` file. These constants can be reused across different components and global styles.
47+
48+
Number of variables in this file should be kept to a minimum and a new one should be introduced only when there is a need for a consistency across components. Do not add variables here if they are used in one place only.
49+
50+
Minor adjustments to color constants (slightly darker shades etc.) should be made by using sass color functions on an original color.
51+
52+
## Colors
53+
54+
Prefer HSL format of colors over RGB. HSL format is easier to manipulate and make lighter/darker, more/less saturated etc. If you are using Visual Studio Code you can easily convert to HSL by hovering over color and clicking on the header of the color picker popup.
55+

0 commit comments

Comments
 (0)