-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Leverage CSS cascade layers to fix and user-proof styles order
As long as `layers.scss` (layers order definition) is called first, our Sass styles can be imported in any order. It solves the incorrect (but unavoidable, due to the way we compile CSS) call order of styles in our `index.js`. Also, developers can now extend the CSS cascade instead of just prepending or appending their styles to ours. For example: ```css /* My custom app styles */ @layer foundation.elements { code { background-color: silver; } } ```
- Loading branch information
1 parent
6c00d0f
commit 2c19ce8
Showing
7 changed files
with
1,110 additions
and
1,087 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,33 @@ | ||
// Mandatory themeable CSS layer to prepare ground for components. | ||
// Structured according to ITCSS methodology, ie. most importantly in ascending specificity. | ||
|
||
@use "sass:meta"; | ||
|
||
// | ||
// 1. Generic | ||
// ========== | ||
// Generic | ||
// ======= | ||
// | ||
// Ground-zero styles. | ||
|
||
@use "styles/generic/box-sizing"; | ||
@use "normalize.css/normalize.css"; | ||
@use "styles/generic/focus"; | ||
@use "styles/generic/forms"; | ||
@use "styles/generic/reset"; | ||
@use "styles/generic/shared"; | ||
@layer foundation.generic { | ||
@include meta.load-css("styles/generic/box-sizing"); | ||
@include meta.load-css("normalize.css/normalize.css"); | ||
@include meta.load-css("styles/generic/focus"); | ||
@include meta.load-css("styles/generic/forms"); | ||
@include meta.load-css("styles/generic/reset"); | ||
@include meta.load-css("styles/generic/shared"); | ||
} | ||
|
||
// | ||
// 2. Elements | ||
// =========== | ||
// Elements | ||
// ======== | ||
// | ||
// Unclassed HTML elements (type selectors). | ||
|
||
@use "styles/elements/code"; | ||
@use "styles/elements/links"; | ||
@use "styles/elements/lists"; | ||
@use "styles/elements/page"; | ||
@use "styles/elements/rulers"; | ||
@use "styles/elements/small"; | ||
@layer foundation.elements { | ||
@include meta.load-css("styles/elements/code"); | ||
@include meta.load-css("styles/elements/links"); | ||
@include meta.load-css("styles/elements/lists"); | ||
@include meta.load-css("styles/elements/page"); | ||
@include meta.load-css("styles/elements/rulers"); | ||
@include meta.load-css("styles/elements/small"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
// Optional layer with helper CSS classes to easily adjust visual details. | ||
// Structured according to ITCSS methodology, ie. most importantly in ascending specificity. | ||
// This file should be imported as the very last of your stylesheets. | ||
|
||
@use "sass:meta"; | ||
|
||
// | ||
// 1. Helpers | ||
// ========== | ||
// Helpers | ||
// ======= | ||
// | ||
// General purpose helpers for common situations. They can compose multiple CSS rules to do a bit | ||
// more complicated tasks. | ||
|
||
@use "styles/helpers/animation"; | ||
@layer helpers { | ||
@include meta.load-css("styles/helpers/animation"); | ||
} | ||
|
||
// | ||
// 2. Utilities | ||
// ============ | ||
// Utilities | ||
// ========= | ||
// | ||
// Utility classes to tweak small details like typography, margins or padding. They do just one | ||
// thing: they set a single CSS rule and use the otherwise disallowed `!important` to enforce it. | ||
// Also they are often responsive (can be adjusted for individual breakpoints). | ||
|
||
@use "styles/utilities"; | ||
@layer utilities { | ||
@include meta.load-css("styles/utilities"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// First establish cascade layers: | ||
@forward "layers"; // Must come first for the cascade layers to work as intended. | ||
|
||
// Then import the rest of the files, already organized by layer: | ||
@forward "theme"; | ||
@forward "foundation"; | ||
@forward "helpers"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Establish CSS cascade layers. | ||
// ⚠️ WARNING: This file must be called before other React UI styles for the cascade layers to work as intended. | ||
|
||
@layer theme, foundation, helpers, components, utilities; |
Oops, something went wrong.