Skip to content

chore(CSS Utils): Update Tailwind colors to support GitLab dark mode

Peter Hegman requested to merge tailwind-darkmode-poc into main

What does this MR do?

Related to gitlab#439098 (closed)

In order to support GitLab dark mode we need to use CSS variables when defining colors in tailwind.defaults.js. Here is how it will work:

Caveats

  • Because we define colors in hex we won't be able to use the opacity modifier (see https://tailwindcss.com/docs/customizing-colors#using-css-variables). I don't foresee this being an issue as we don't currently have any color utility classes that use opacity. In the future we could convert colors from hex to rgb to support the opacity modifier.

  • The colors in Tailwind config viewer won't change when switching to dark mode because we haven't defined the CSS variables. We could possibly make use of the fonts option to add a stylesheet with the CSS variables (behind the scenes it just adds a stylesheet). The problem is you can't use a local stylesheet so we would need to host it somewhere. The other problem is you can't customize the class added to body for dark mode (defined in https://github.com/rogden/tailwind-config-viewer/blob/master/src/App.vue#L33) and we need that to be gl-dark. I don't think not having dark mode work in the Tailwind config viewer should be a blocker but it would be nice to open a follow-up issue to see how we could make it work.

Screenshots or screen recordings

Tailwind config viewer

Screenshot_2024-01-30_at_4.01.59_PM

gitlab-org/gitlab

Screenshot_2024-01-30_at_4.03.42_PM

How to test locally

  1. Checkout this branch
  2. In gitlab-org/gitlab checkout gitlab!142846 (merged)
  3. Use yalc to make this branch available in gitlab-org/gitlab. See https://gitlab.com/gitlab-org/gitlab-ui/-/blob/main/doc/contributing/gitlab_integration_test.md#testing-your-changes-in-a-local-gitlab-instance
  4. In gitlab-org/gitlab add corePlugins: ['backgroundColor'] to tailwind.config.js
  5. Restart GDK
  6. Start tailwind with bin/rails tailwindcss:watch
  7. Turn on dark mode in /-/profile/preferences
  8. Navigate to /flightjs/Flight/edit
  9. Open the Advanced section and find the Delete this project section.
  10. Inspect the background of the card, it should be using the --red-50 CSS variable

Does this MR meet the acceptance criteria?

This checklist encourages the authors, reviewers, and maintainers of merge requests (MRs) to confirm changes were analyzed for conformity with the project's guidelines, security and accessibility.

Toggle the acceptance checklist

Conformity

  • Code review guidelines.
  • GitLab UI's contributing guidelines.
  • If it changes a Pajamas-compliant component's look & feel, the MR has been reviewed by a UX designer.
  • If it changes GitLab UI's documentation guidelines, the MR has been reviewed by a Technical Writer.
  • If the MR changes a component's API, integration MR(s) have been opened (see integration merge requests above).
  • Added the ~"component:*" label(s) if applicable.

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • Security reports checked/validated by a reviewer from the AppSec team

Accessibility

If this MR adds or modifies a component, take a few moments to review the following:

  • All actions and functionality can be done with a keyboard.
  • Links, buttons, and controls have a visible focus state.
  • All content is presented in text or with a text equivalent. For example, alt text for SVG, or aria-label for icons that have meaning or perform actions.
  • Changes in a component’s state are announced by a screen reader. For example, changing aria-expanded="false" to aria-expanded="true" when an accordion is expanded.
  • Color combinations have sufficient contrast.
Edited by Peter Hegman

Merge request reports