Skip to content
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: Dark Mode #718

Closed
wants to merge 12 commits into from
Closed

Conversation

lanesawyer
Copy link

@lanesawyer lanesawyer commented Nov 29, 2023

Dark Mode

Structural Element (Base, Gene, DNA, Chromosome or Cell)
Github issue: #XXXX
Copy isuue descirption here

Remaining Work

  • Real dark mode colors
  • Checking all the components to make sure nothing is broken
  • Accessibility verification
  • Updated documentation for setting up the project since you'll need to provide a theme now (or, we just default to light or something)
  • Probably other things I'm forgetting

Checklist

  • Default Story in Storybook
  • LivePreview Story in Storybook
  • Test Story in Storybook
  • Tests written
  • Variables from defaultTheme.ts used wherever possible
  • If updating an existing component, depreciate flag has been used where necessary
  • Chromatic build verified by @chanzuckerberg/sds-design

@@ -108,3 +108,12 @@ storybook-static

# OS Files
.DS_Store

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out I'm on the latest version of yarn which hasn't been used by this project yet so I was getting tons of added files from yarn's cache. This ensures the latest yarn doesn't cause git annoyances in the future 😄

@@ -39,12 +38,13 @@ export const StyledCallout = styled(Alert, {
// any buttom margin
const titleBottomMargin = props.collapsed ? "margin-bottom: 0;" : "";

// TODO: Theme shouldn't be saying it might be null
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type issue, needs to be addressed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this TODO is a little right and a little wrong, looking at it again.

The props here are listed as CalloutProps, which extends from the CommonThemeProps where theme is undefined.

At runtime, theme would never be undefined, so that's why I dropped the initial TODO here.

I'm sure we could do a bit of type juggling we could do to make it defined, but I think we'd want to do that in other components that are extending CommonThemeProps directly.

Given this PR is more targeted at making dark mode work, I'm inclined to live with the untrue ? on theme for now.

@@ -75,8 +75,64 @@ const defaultThemeColors = {
},
};

export const defaultAppTheme: AppTheme = {
colors: defaultThemeColors,
const darkThemeColors = {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gross ChatGPT generated ones, will be replaced.

@@ -94,7 +94,7 @@ export const Title - styled(Typography)`
```ts
import { css, SerializedStyles } from "@emotion/react";
import { styled } from '@mui/material/styles';
import { getColors, getCorners } from "@czi-sds/components";
import { getColors, getSpaces } from "@czi-sds/components";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just fixing a typo in the README

/**
* Default theme, uses light mode with no option to change it.
*
* @deprecated Use the `theme` to get a flexible light/dark mode theme function
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we don't deprecate it, some folks may never be interested in light/dark so why complicate their lives?

Alternatively, deprecate but give the new one a default theme of "light". 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question! Yeah I also feel that maybe don't deprecate it and just default to "light" sounds less intrusive 😄 👍

- Updated DialogTitle to use palette.text colors
- Updated Tabs to use palette.text colors
Comment on lines +640 to +642
900?: string;
800?: string;
700?: string;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't want all Color types to be able to climb this high we could make an ExtendedColor interface that extends Color and adds these three. Then it can be applied only where these values would be desired.

color: black;
${(props) => {
return `
color: ${props.theme.palette.text.primary};
Copy link
Author

@lanesawyer lanesawyer Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thinking about this a bit... Typography should be theme-aware for the text.primary color. I think we might be able to get away with removing color entirely!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for paving the way for our components to be runtime theme aware 💡 !!

Yeah using semantic text.primary sounds like best practice to me too 👍 !

Copy link
Author

@lanesawyer lanesawyer Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, going to remove the color entirely for Title then. Keeping for Subtitle since that won't be a secondary color by default!

@tihuan tihuan self-requested a review January 19, 2024 21:24
Copy link
Contributor

@tihuan tihuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks SUPER good! Thanks so much for going through the code to find places where we can start adopting runtime theme swapping!

These examples will definitely help us overhaul the rest of the stories and components in Q2 👏

Really appreciate it!

Just some minor questions/feedbacks, otherwise LGTM 🚀 !!

@@ -51,7 +51,9 @@ export const StyledTabs = styled(TempTabs, {
return `
margin-top: ${isLarge ? spaces?.l : spaces?.m}px;
margin-bottom: ${isLarge ? spaces?.xl : spaces?.m}px;
border-bottom: ${underlined ? `2px solid ${colors?.gray[200]};` : "none"};
border-bottom: ${
underlined ? `2px solid ${props.theme.palette.divider};` : "none"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nice!

Comment on lines 256 to 257
colors: lightThemeColors,
...sharedAppTheme,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we swap the order here, so we ensure colors: lightThemeColors, will overwrite sharedAppTheme.colors if sharedAppTheme happens to have colors at runtime 😄 ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Even though I've said sharedAppTheme omits colors, that doesn't mean it'll actually happen.

The joys of TypeScript lol

Swapping!

/**
* Default theme, uses light mode with no option to change it.
*
* @deprecated Use the `theme` to get a flexible light/dark mode theme function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question! Yeah I also feel that maybe don't deprecate it and just default to "light" sounds less intrusive 😄 👍

* @deprecated Use the `theme` to get a flexible light/dark mode theme function
*/
export const defaultTheme = createThemeAdaptor(
makeThemeOptions(chooseTheme("light"), "light")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels like potentially defaultTheme() could call theme() under the hood?

Something like:

export const defaultTheme = theme("light");

What do you think 🙆‍♂️ ?

divider: appTheme.colors.gray[200],
background: {
default: common.white,
secondary: appTheme.colors.gray[100],
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was added by @hthomas-czi during the hackathon, it's throwing a type error because we don't have it on TypeBackground.

@hthomas-czi Is a secondary background still something that's needed? There's paper that we could be using that already exists, so we'll have three background colors if we do use secondary.

If it's needed, it's easy to add to the type. I just want to check 😁

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was added by @hthomas-czi during the hackathon, it's throwing a type error because we don't have it on TypeBackground.

@hthomas-czi Is a secondary background still something that's needed? There's paper that we could be using that already exists, so we'll have three background colors if we do use secondary.

If it's needed, it's easy to add to the type. I just want to check 😁

Hey @lanesawyer! Sorry for the delay responding. For some horrible reason, I don't receive notifications for GitHub mentions.

I'll leave it up to you, but Paper doesn't fully address the reason I added a secondary background. They're equivalent in dark mode. But in light mode, Paper is always white, while background[secondary] is light gray in light mode. This maintains a consistent appearance between modes.

Thanks!

@lanesawyer
Copy link
Author

lanesawyer commented Jan 19, 2024

@tihuan Feedback addressed! I have an outstanding question for @hthomas-czi, but overall this PR should be pretty close to ready.

Also one more question, should we add details about the theme to the README in this PR, or update the README once the colors and polish are completed so people won't start thinking it's ready?

Finally, I guess my PR doesn't trigger the workflow. Probably want to approve those to run so we can check that I didn't miss anything. Running the linter locally, I got a bunch of errors saying Cannot find module @czi-sds/components' or its corresponding type declarations., but everything in Storybook seemed to be working. Not sure if that's my machine's problem, if I'm running the linter incorrectly (I'm doing yarn lint), or what.

@lanesawyer lanesawyer marked this pull request as ready for review January 19, 2024 22:41
Copy link
Contributor

@tihuan tihuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks for addressing the feedback quickly, Lane 🫡 LGTM!

CC: @masoudmanson in case I missed something 😎🙏

Thanks again!

Copy link
Contributor

@masoudmanson masoudmanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, @lanesawyer, this is truly fantastic!
A massive thank you for tackling the heavy lifting and crafting such a robust PR for us. Really appreciate it.
The PR looks great to me. I'll be continuing to update components and collaborate with the design team to fine-tune the colors and appearance of the components.
This is so exciting! 🥳

Finally, I feel right at home as a programmer. We got a dark theme 😱😍

@masoudmanson
Copy link
Contributor

@lanesawyer, Thanks a ton for your work on the dark theme! Since a lot has changed since your PR, and there were too many conflicts, I created a new PR to pick up where you left off.

You can check it out here: Dark Mode Implementation

Really appreciate your contributions! 🎉🥳

@lanesawyer
Copy link
Author

Woooo love to see it! Thanks for running with what I had and finishing it all up. That final PR is a big one!

Excited to start playing with the official dark mode once it's shipped 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants