New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support from global for composes #669
Merged
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,6 +1,6 @@ | ||
### Style Composition | ||
|
||
Selector limitations mean that it's difficult to use complicated selectors, so to enable building anything of complexity you can compose selectors. These compositions can be within a file or even pull in classes defined in other files. | ||
Selector limitations mean that it's difficult to use complicated selectors, so to enable building anything of complexity you can compose selectors. These compositions can be within a file, reference global CSS class, or even pull in classes defined in other files. | ||
|
||
::: repl | ||
```css | ||
|
@@ -10,7 +10,7 @@ Selector limitations mean that it's difficult to use complicated selectors, so t | |
|
||
.local { | ||
composes: composable; | ||
|
||
color: red; | ||
} | ||
|
||
|
@@ -25,20 +25,53 @@ Selector limitations mean that it's difficult to use complicated selectors, so t | |
When this file is required the JS object will contain the expected keys, but the arrays will now contain more values. | ||
|
||
```js | ||
var css = require("./styles.css"); | ||
var css = require("./style.css"); | ||
|
||
// css is: | ||
/* | ||
{ | ||
single : "dafdfcc_other aeacf0c_single", | ||
// Since .multiple is only a singular composes: declaration there's no need | ||
// for it to be rewritten, it's left out of the output | ||
multiple : "dafdfcc_more f5507abd_than aeacf0c_one", | ||
local : "dafdfcc_other aeacf0c_single" | ||
composable : "dafdfcc_composable", | ||
local : "dafdfcc_composable aeacf0c_local", | ||
removed : "dafdfcc_composable aeacf0c_local aeacf0c_removed" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated this to match the output of the example file above |
||
} | ||
*/ | ||
``` | ||
|
||
Composition also works between files, by providing the source file. | ||
|
||
::: repl | ||
```css | ||
/* === style-guide.css === */ | ||
|
||
.body { | ||
margin: 10px; | ||
height: 100%; | ||
} | ||
|
||
/* === home-page.css === */ | ||
|
||
.body { | ||
composes: body from "/style-guide.css"; | ||
|
||
padding: 10px; | ||
} | ||
``` | ||
:::: | ||
|
||
Styles can also be composed directly from the global scope to help with interoperability | ||
with CSS frameworks or other non-module styles. | ||
|
||
::: repl | ||
```css | ||
.box { | ||
composes: d-flex px-4 py-3 from global; | ||
|
||
color: blue; | ||
} | ||
``` | ||
:::: | ||
|
||
|
||
If you're going to be doing a lot of composition with another file you can store the filename into a value for ease of referencing. | ||
|
||
::: repl | ||
|
@@ -58,13 +91,13 @@ If you're going to be doing a lot of composition with another file you can store | |
|
||
.head { | ||
composes: heading from guide; | ||
|
||
font-size: 120%; | ||
} | ||
|
||
.body { | ||
composes: body from guide; | ||
|
||
padding: 10px; | ||
} | ||
``` |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, I wish it was easier in pegjs to customize the error messages. Nothing you need to change here, just annoyed and sharing.