-
Notifications
You must be signed in to change notification settings - Fork 0
Pro 5776 v3 2 #4
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: v3
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
|
|
|
||
| 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.
Necessary to ensure even client-side interactive edits of the palette hit your custom renderer.
| }, | ||
| 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.
Your override of this method can be async if it needs to be. I didn't find it necessary for this basic use of the sass compiler.
| methods(self) { | ||
| return { | ||
| getStylesheet(doc) { | ||
| const prologue = self.schema.map(field => { |
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.
My strategy was to convert every palette field to a sass variable in snake case, and use this to create a prologue passed to sass before importing a palette.scss file.
| ${prologue} | ||
| @import 'palette.scss'; | ||
| `, { | ||
| loadPaths: [ `${__dirname}/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.
This allows palette.scss to be found and also allows @import in that file using relative paths if desired.
| ).css; | ||
| } catch (e) { | ||
| // sass produces highly readable errors this way | ||
| console.error(e.toString()); |
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.
Show the nice color-coded errors in the server log.
| @@ -0,0 +1,7 @@ | |||
| body { | |||
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 is clearly a tiny example, but the important thing is that I took a palette field (backgroundColor) and utilized it via its SASS variable equivalent ($background-color).
| } | ||
|
|
||
| * { | ||
| 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.
I know it's obnoxious 😄 I included this rule just to remove any doubt that the custom renderer is in use.
| "@apostrophecms-pro/basics": "^1.3.1", | ||
| "@apostrophecms-pro/document-versions": "^1.1.0", | ||
| "@apostrophecms-pro/palette": "^3.2.0", | ||
| "@apostrophecms-pro/palette": "^3.3.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. After Wednesday's release you can change this to ^3.3.0 and npm update.
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.