chore(CSS Utils): Update Tailwind colors to support GitLab dark mode
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:
- Define Tailwind colors as CSS variables with a fallback to the hex
- In light mode the fallback will be used
- In dark mode the CSS variables defined in app/assets/stylesheets/themes/dark_mode_overrides.scss#L2 will be used
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 tobody
for dark mode (defined in https://github.com/rogden/tailwind-config-viewer/blob/master/src/App.vue#L33) and we need that to begl-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
gitlab-org/gitlab
How to test locally
- Checkout this branch
- In
gitlab-org/gitlab
checkout gitlab!142846 (merged) - 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 - In
gitlab-org/gitlab
addcorePlugins: ['backgroundColor']
totailwind.config.js
- Restart GDK
- Start tailwind with
bin/rails tailwindcss:watch
- Turn on dark mode in
/-/profile/preferences
- Navigate to
/flightjs/Flight/edit
- Open the
Advanced
section and find theDelete this project
section. - 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"
toaria-expanded="true"
when an accordion is expanded. -
Color combinations have sufficient contrast.