-
Notifications
You must be signed in to change notification settings - Fork 2
Sass
William Pansky edited this page Dec 22, 2017
·
1 revision
The Sass rules we tend to follow are Hugo Giraudel's Sass guidelines, with the TLDR being:
- Having a styleguide is all about consistency. If you disagree with some rules from Sass Guidelines, fair enough as long as you are consistent. π
- Sass should be kept as simple as it can be. Avoid building complex systems unless absolutely necessary. π
- Keep in mind that sometimes KISS (Keep It Simple, Stupid) is better than DRY (Donβt Repeat Yourself). π
-
General markup rules
- An indentation is made of two (2) spaces, no tabs. π
- Lines should be, as much as possible, shorter than 80 characters. Feel free to split them into several lines when necessary. π
- CSS should be properly written, possibly following the CSS Guidelines from Harry Roberts. π
- Whitespace is free β use it to separate items, rules, and declarations. Do not hesitate to leave empty lines, it never hurts; this project's
.stylelintrcfile allows for up to three empty lines between code blocks (though comments are ignored). Whitespace is key to emphasis and readability. π
-
Strings
-
Numbers
- Sass makes no distinction between numbers, integers, floats so trailing zeros (0) should be omitted. However, leading zeros (0) help readability and should be added. π
- A zero (0) length should not have a unit. π
- Units manipulation should be thought as arithmetic operations, not string operations. π
- In order to improve readability, top-level calculations should be wrapped in parentheses. Also, complex math operations might be splitted into smaller chunks. π
- Magic numbers dramatically hurt code maintainability and should be avoided at all time. When in doubt, extensively explain the questionable value. π
-
Colors
- Colors should be expressed in HSL when possible, then RGB, then hexadecimal (in a lowercase and shortened form, e.g:
#fffinstead of#ffffffor#FFF). Color keywords, other thanwhite/blackshould be avoided. π - Prefer mix(..), e.g.
color: mix(white, $primary-color, 35%);, instead of darken(..) and lighten(..) when lightening or darkening a color. π
- Colors should be expressed in HSL when possible, then RGB, then hexadecimal (in a lowercase and shortened form, e.g:
-
Lists
-
Maps
-
Declaration sorting
- The system used for declaration sorting (alphabetical, by type, etc.) doesnβt matter as long as it is consistent. π
-
Selector nesting
-
Naming conventions
- It is best to stick to CSS naming conventions which are (except a few errors) lowercase and hyphen-delimited. π
-
Commenting
- CSS is a tricky language; please, feel free, to write very extensive comments about code blocks that may not be inheritely understandable. If you think there's even the slightest chance for a fellow dev to misunderstand a slice of code you've written, just slap down some comments to explain things. We're a team, remember! π π
- For variables, functions, mixins, and placeholders β use SassDoc comments. π
-
Variables
-
Extend
- Stick to extending placeholders, not existing CSS selectors. π
- Extend a placeholder as few times as possible in order to avoid side effects. π
Sass file architecure built off Hugo Giraaudel's 7-1 pattern (i.e. "7 folders, 1 file") by appending an additional utilities/ directory at the end to house a collection of helper classes to style our content.
|- abstracts/ --- Mixins, definitions, functions, selectors, etc.
|- vendors/ ----- 3rd-party vendor styles (normalize, bootstrap), etc.
|- base/ -------- Global styles such as non-vendor resets, typography, etc.
|- layout/ ------ Styling for larger layout modules; e.g. nav, header, etc.
|- components/ -- Resuable, independant, module components (buttons, etc.)
|- pages/ ------- Page-specific styling, such as homepage, if necessary.
|- themes/ ------ Styles for different themes; such as holidays, events, etc.
|- utilities/ --- Helper utility styles for adjusting margin, padding, etc.
Through consistency, linting, code reviews, and standards we strive to achieve a codebase like this:
scss/
|
|-- abstracts/
| |-- _!module.scss ------- Core file for abstract @import calls
| |-- variables/ ---------- Variables directory
| | |-- _colors.scss ----- Color definitions and maps
| | |-- _fonts.scss ------ Typography definitions and maps
| | |-- ...
| |-- mixins/ ------------- Mixins directory
| | |-- _example.1.scss -- Mixin example
| | |-- _example.2.scss -- Mixin example
| | |-- ...
|
|-- vendors/
| |-- _normalize.scss ----- Standard normalize.css file
| ... --------------------- Etc.
|
|-- base/
| |-- _!module.scss ------- Core file for base @import calls
| |-- _resets.scss -------- Specific resets and tweaks
| |-- _typography.scss ---- Global typography styles
| ... --------------------- Etc.
|
|-- layout/
| |-- _!module.scss ------- Core file for layout @import calls
| |-- _header.scss -------- <header>-specific styles
| |-- _grid.scss ---------- Project grid specs
| ... --------------------- Etc.
|
|-- components/
| |-- _!module.scss ------- Core file for component @import calls
| |-- _buttons.scss ------- Button settings, styles, modifiers, and states
| |-- _dropdowns.scss ----- Dropdown settings, styles, modifiers, and states
| |-- _lists.scss --------- List settings, styles, and modifiers
| ... --------------------- Etc.
|
|-- pages/
| |-- _!module.scss ------- Core file for page @import calls
| |-- _homepage.scss ------ Homepage-specific page styles
| |-- _contact.scss ------- Contact-specific page styles
| ... --------------------- Etc.
|
|-- themes/
| |-- _!module.scss ------- Core file for theme @import calls
| |-- theme-1/ ------------ Theme-1 directory
| | |-- ... -------------- Theme-1 files
| |-- theme-2/ ------------ Theme-2 directory
| | |-- ... -------------- Theme-2 files
| ... --------------------- Etc.
|
|-- utilities/
| |-- _!module.scss ------- Core file for utility @import calls
| |-- _display.scss ------- Single display property override classes
| |-- _flex.scss ---------- Stackable flex property classes
| |-- _no-scroll.scss ----- Prevent <body> scroll during open modals
| |-- _svg-fill.scss ------ Fill SVGs with specific colors
| ... --------------------- Etc.
|
-- main.scss
| |-- @import 'abstracts/!module';
| |-- @import 'vendors/!module';
| |-- @import 'base/!module';
| |-- @import 'layout/!module';
| |-- @import 'components/!module';
| |-- @import 'pages/!module';
| |-- @import 'themes/!module';
| |-- @import 'utilities/!module';