-
Notifications
You must be signed in to change notification settings - Fork 0
PRO-5776: a4 demo of SASS compilation within palette (do not merge) #3
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
base: main
Are you sure you want to change the base?
Conversation
PRO-5776 Proof of Concept demonstrating the ability to pass Palette settings through SASS or any preprocessor before generating CSS.
Overview The head of product design at iCIMS has been inquiring about design token as a potential solution to their needs, and Tom suggests that actually Palette could be enough. iCIMS's Goal
More specifically, he noted that success would satisfy the following requirements:
Apostrophe's Response & POC Driver
Regarding the hooks needed: You can listen for changes in the palette settings in any module like this: handlers(self) { async transformForSass(req, doc) { } } }; } You'd also want to override the "stylesheet" async component of the palette module to output what comes from your SASS rather than the simple CSS compiled directly by palette. The system is designed from the ground up to make overriding things like this straightforward. One thing to keep in mind however is that the compilation needs to feel fast, as the palette does interactively save often as the user makes changes. Work to be done
Notes:
Acceptance Criteria
|
| } | ||
|
|
||
| * { | ||
| color: purple !important; |
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.
Just to prove that the styles are applying beyond any doubt.
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.
This file can have @import commands of its own relative to its path.
| @@ -0,0 +1,7 @@ | |||
| body { | |||
| background-color: $background-color; | |||
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.
In this particular simple example, every palette field is converted to a SASS variable automatically, in snake-case. Here I'm taking advantage of one of the palette fields that exist in this particular project.
| }, | ||
| methods(self) { | ||
| return { | ||
| getStylesheet(doc) { |
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.
This can also be an async method if desired.
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.
As seen here, overriding this particular method is the general technique to take over stylesheet rendering in the palette.
| return { | ||
| getStylesheet(doc) { | ||
| const prologue = self.schema.map(field => { | ||
| return `$${snakeCase(field.name)}: ${doc[field.name]};` |
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.
Convert all of the palette fields to SASS variables in snake case.
| return sass.compileString( | ||
| ` | ||
| ${prologue} | ||
| @import 'palette.scss'; |
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.
Import palette.scss from the scss subdirectory of this module in the project.
| "@apostrophecms-pro/basics": "^1.3.1", | ||
| "@apostrophecms-pro/document-versions": "^2.0.0", | ||
| "@apostrophecms-pro/palette": "^4.0.1", | ||
| "@apostrophecms-pro/palette": "4.1.0-alpha.1", |
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.
Temporarily necessary to use this alpha release. That requirement will go away on the 17th.
|
|
||
| module.exports = { | ||
| options: { | ||
| serverRendered: true |
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.
Without this option, our built-in renderer would still be used on the front end during editing, so you will need to set this. Trades off a little bit of speed for consistent server-side rendering using whatever implementation you wish to provide (see below).
Demonstrate the custom server side rendering technique. Converts palette settings directly to SASS variables before importing
palette.scss, which currently just takes the background color setting and applies it, and also intentionally also contains a rule to make an obvious change to the text color to verify it is in the mix.