Introduce light+dark theme via use of @primer/primitives - #4
Conversation
And also auto-generate dark theme.
paramaggarwal
left a comment
There was a problem hiding this comment.
Added some comments to explain the thought process/plan.
| "foreground": "#444d56", | ||
| "descriptionForeground": "#6a737d", | ||
| "errorForeground": "#cb2431", | ||
|
|
There was a problem hiding this comment.
The reason these lines got removed is because this file is now auto-generated. I have intentionally not modified any theme config/colors as I wanted this PR to purely focus on auto-generation first.
| } else if (name === "white") { | ||
| darkColors.black = val; | ||
| } else { | ||
| darkColors[name] = [...val].reverse(); |
There was a problem hiding this comment.
This is the key part. The colors array go from light to dark shades. For the dark theme, we simply reverse the ordering. This works surprisingly well!
| const fs = require("fs"); | ||
| const { colors } = require("@primer/primitives"); | ||
|
|
||
| const getTheme = require("./theme"); |
There was a problem hiding this comment.
The theme shall reside in this one single place and it references the Primer primitives rather than hardcoding any colors.
| "@primer/primitives": "^2.0.1" | ||
| }, | ||
| "scripts": { | ||
| "build": "node src/index.js" |
There was a problem hiding this comment.
The script to auto-generate the two themes. This can be hooked into a prepublish step.
| "publisherId": "7c1c19cd-78eb-4dfb-8999-99caf7679002" | ||
| }, | ||
| "devDependencies": { | ||
| "@primer/primitives": "^2.0.1" |
There was a problem hiding this comment.
The source of our raw color values.
| return { | ||
| name: name, | ||
| colors: { | ||
| focusBorder: colors.blue[4], |
There was a problem hiding this comment.
I had written a script to reverse-engineer the color reference from the underlying hardcoded hex string. Also, I have verified that the output theme config is exactly the same as before.
|
There are total 20 color values that do not have a direct mapping to the colors in Primer Primitives. I have started compiling a few of the suggested mappings:
|
simurai
left a comment
There was a problem hiding this comment.
This is awesome.. 😻 ❤️ Also thanks for explaining everything. 🙇
There are total 20 color values that do not have a direct mapping to the colors in Primer Primitives.
Yeah, some are custom colors that we started to use in https://github.com/primer/css but aren't part of the "system" yet.
we might need the
colornpm module to make some slightdarken(),lighten()operations on the raw color values.
Sometimes no color from the scale made sense. Like when hovering, it should only change a tiny bit but not as much as the next number in the scale. Having color functions would be nice. 👍
we simply reverse the ordering. This works surprisingly well!
Indeed it does. Although I wonder if hand tweaking the colors, here and there, could improve it even more? 🤔 Would something like the following be possible?
- If only one color defined:
scope: colors.blue[4],-> inverse for dark - If 2 colors defined:
scope: { colors.blue[4], colors.blue[3] },-> first is for light, second is for dark
That would allow to keep the scopes in sync, auto-inverse colors, but still be able to hand-tweak them if needed.
Co-Authored-By: simurai <simulus@gmail.com>
|
btw. sorry, this PR now has a merge conflict since these 3 scopes got added. Update: Should be fixed. |
|
I like all the suggestions.
|
No worries if converting the hex values into |
|
✅ - ability to specify a manual mapping of colors An approach that I found to create dark colors automatically is to use the HSL version and then flip the I am using this theme now and love it. One thing that I like about this PR is that it does not touch any original color value at all from |
Nice! I guess with
Yep, 0 regressions. 💥 Ok, I think this PR is good to merge. We can polish it more in follow-up PRs. Thanks for getting this up and running in no time. ❤️ 🙇 |
|
Thanks! 😊 |
|
...and published to the Marketplace. 🎉 /cc @paramaggarwal |
|
Wow! Great news @simurai! |
colors.red[3].Pending:
Light
Dark
System
(fixes #3)