Add colors in JS and Color Palette #18
Labels
No Label
Bug
Component
Config
Good First Issue
Low-Priority
Page
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: www/cs-2022-class-profile#18
Loading…
Reference in New Issue
No description provided.
Delete Branch "shahanneda/js-colors"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
After further investgation, the solutions that we planned on using (
getComputedStyle(document.documentElement) .getPropertyValue(property);
) did not end up working, because of some weird issues with nextjs. However, luckly it seems we can still just use the css variables inside the js (I tried it out with Amy's bar graph demo and it seemed to work well).Thus I created a typesafe helper, utils/Colors.ts , anytime you need a color, you can use this object, eg.
And importantly the Colors is typesafe so you can get autocomplete. (Protip: press Cntrl + Space if you want autocomplete to pop up if it is not coming)
Staging: https://shahanneda-js-colors-csc-class-profile-staging-snedadah.k8s.csclub.cloud
Add colors in JS and Color Palateto Add colors in JS and Color Palette@ -0,0 +1,20 @@
.box {
width: 100px;
height: 100px;
Two nits:
calc(100rem / 16)
syntax that we're accustomed to from the website. I think the CSS plugins here should be configured so that suchcalc
statements get computed as6.25rem
in the exported site, similar to what we have for the website.@ -0,0 +20,4 @@
type ColorName = typeof colorNames[number];
export const Colors: { [key in ColorName]: string } = {
primaryBackground: "var(--primary-background)",
I think there's probably a way to directly map the
colorNames
array to an object of this format, so that in the future if we add more colours we only need to update the one array... but since this is just a demo component I won't be too picky about it. 😆Also, a super nit: consider naming the object
Color
(singular) so that individual colours can be accessed likeColor.primaryBackground
instead ofColors.primaryBackground
- makes more sense IMO since we're just using one colour at a time.True, I think Color is used more often in order codebases as well.