This repository was archived by the owner on Dec 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
This repository was archived by the owner on Dec 11, 2021. It is now read-only.
File structure #29
Copy link
Copy link
Closed
Labels
Description
I suggest an atomic structure with small self-contained modules. I prefer a version inspired by a Dale Sande article (or video).
Here's how I propose each module is structured:
// Module structure
// 1. main file with styles
// 2. functions used with main file
// 3. mixins used with main file
// 4. variables used with main file
|- typography/
|--- functions.scss // 2
|--- mixins.scss // 3
|--- typography.scss // 1
|--- variables.scss // 4
And how the overall file structure might look:
// 1. _utilities contains global mixins module, normalize, etc
// 2. atoms contains modules like buttons
// 3. molecules contains modules like nav_horizontal
// 4. organisms contains more complex modules like banner
// 5. views contains individual page/view templates like admin
|- sass/
|--- _utilities/ // 1
|--- atoms/ // 2
|--- molecules/ // 3
|--- organisms/ // 4
|--- views/ // 5
|--- style.scss
Pros
- This method keeps everything pretty tidy. The variables, functions, mixins, extends (dependencies) relevant to a module together rather than scattering them around via a massive variables file, etc.
- The module name is the same as the
.base
name of the module's rules and components. If the module wascalendar
, it's rules might becalendar_day.is-today
(I'm referencing the BEM naming convention I referenced here. This makes it easy to avoid naming conflicts as it's easy to spot the base elements in use. There is an added benefit of knowing where to find which file a class was declared in by just knowing the class name. - There are no mystery junk drawer files. For example, there is no giant universal file with a series of placeholder selectors and no way to know which selectors exist and where they are used.
- Because of it's structure, style.css ends up being a pretty rad little table of contents that might look like this:
@import "atoms/colors/colors", // Global color variables
"_utilities/mixins/mixins", // Global mixins
"_utilities/clearings",
"atoms/typography/typography",
"atoms/media",
"atoms/animations",
"atoms/buttons",
"atoms/icons/genericons",
"molecules/nav-horizontal",
"molecules/nav-off-screen",
"molecules/alerts",
"organisms/contact-form",
"organisms/calendar",
"views/main",
"views/settings";
Cons
- Looks weird and scary at first. It's not.
- Can be tricky to figure out whether a module is a molecule or organism. Don't sweat it too much. Just place it where it feels right.