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

Behold the raise of the Darth Mode 🌑 #2540

Merged
merged 16 commits into from
Jan 10, 2024
Merged

Behold the raise of the Darth Mode 🌑 #2540

merged 16 commits into from
Jan 10, 2024

Conversation

JF-Cozy
Copy link
Collaborator

@JF-Cozy JF-Cozy commented Nov 30, 2023

Ajout du theme sombre pour cozy-ui, alias dark mode. Pour l'activer, il faut passer le browser en mode dark.

Fonctionnement

On utilise le provider <CozyTheme /> pour wrapper les app, ainsi qu'une partie précise du DOM à l'intérieur d'une app, afin d'apporter le style de cozy-ui. Ce composant a été modifié :

  • il crée une var type dont la valeur peut être light | dark en fonction de la media query prefers-color-scheme: dark (selon la configuration du browser). Cette var type est passé en prop à <MuiCozyTheme /> ainsi qu'au div wrapper qui contient les var css.
  • il crée une balise <meta name="color-scheme" content="dark light" /> si elle n'est pas déjà présente
  • il y a toujours la prop historique variant qui peut avoir pour valeur normal | inverted.

Override

Si votre app ne supporte pas le thème sombre :

  • ajoutez <meta name="color-scheme" content="only light" /> dans index.ejs.

Note

  • Concernant la suppression de nombreuses var css, j'ai vérifié, elles ne sont pas utilisé dans nos overrides context actuels (c'était pour un ancien override que nous n'avons plus).
  • Concernant les screenshots Argos, on screenshot tous les cas, comme avant (on double donc le nombre de screenshots)

démo : https://jf-cozy.github.io/cozy-ui/react/

Pour tester dans la doc il faut mettre son browser en mode dark, ou changer le mode à gauche dans la barre de navigation (ce qui force le process).
Deux bons candidats : https://jf-cozy.github.io/cozy-ui/react/#/Core/Buttons et https://jf-cozy.github.io/cozy-ui/react/#/Core/Alert

Breaking changes

  • if you want to get or override css var, you need to do it on new classes, see below:
    CozyTheme--normal -> CozyTheme--light-normal
    CozyTheme--inverted -> CozyTheme--light-inverted

  • You can't now longer rely on theme.palette.type to determine normal or inverted theme, you have to use theme.palette.variant instead.

  • useCozyTheme() return now an object with type and variant. You must replace const theme = useCozyTheme() by const { variant } = useCozyTheme()

  • Remove some css vars. You should use semantic var instead. List of removed css vars :

--invertedBackgroundColor
--invertedContrastTextColor
--spinnerColor
--linkColor
--linkTextDecoration
--linkColorActive
--invertedTabsActiveTextColor
--invertedTabsInactiveTextColor
--invertedTabsIndicatorColor
--invertedTabsBackgroundColor
--regularButtonPrimaryColor
--regularButtonSecondaryColor
--regularButtonActiveColor
--regularButtonConstrastColor
--secondaryButtonPrimaryColor
--secondaryButtonSecondaryColor
--secondaryButtonActiveColor
--secondaryButtonContrastColor
--dividerColor2
--iconColor
--textIconColor
--actionMenuIconColor
--neutralBackground
--buttonTextTransform
--buttonBorderRadius
--alertErrorColor
--alertErrorBackgroundColor
--alertSuccessColor
--alertSuccessBackgroundColor
--alertInfoColor
--alertInfoBackgroundColor

icons8-dark-vador May the dark mode be with us!

Limitation

Copy link

bundlemon bot commented Nov 30, 2023

BundleMon

Files updated (3)
Status Path Size Limits
dist/cozy-ui.utils.min.css
10.75KB (+266B +2.48%) +10%
dist/cozy-ui.min.css
19.88KB (+180B +0.89%) +10%
transpiled/react/stylesheet.css
19.05KB (-137B -0.7%) +10%

Total files change +309B +0.61%

Groups updated (1)
Status Path Size Limits
transpiled/react/**
653.64KB (+1.72KB +0.26%) -

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@JF-Cozy JF-Cozy force-pushed the feat/darkMode branch 2 times, most recently from 0f4cf90 to 023d950 Compare November 30, 2023 16:38
Copy link

argos-ci bot commented Nov 30, 2023

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) 👍 Changes approved 38 changes Jan 10, 2024, 2:58 PM

@zatteo
Copy link
Contributor

zatteo commented Dec 1, 2023

🎉🎉🎉🎉🎉🎉

@JF-Cozy JF-Cozy force-pushed the feat/darkMode branch 3 times, most recently from 65341a5 to 198dd78 Compare December 7, 2023 08:14
@zatteo
Copy link
Contributor

zatteo commented Dec 7, 2023

Régression sur le composant Menu ?

image

@zatteo
Copy link
Contributor

zatteo commented Dec 7, 2023

Différences sur le composant Paper ? Mais liées aux ombres donc je ne sais pas si c'est normal.

image

@JF-Cozy
Copy link
Collaborator Author

JF-Cozy commented Dec 7, 2023

Bien vu merci @zatteo il y a un souci visiblement avec les shadows. Je regarde.

Edit : corrigé dans un commit à part.

En effet plusieurs soucis à ce sujet : suite à un correctif récent qui se basaient sur les var css et non les valeurs brutes, les shadows n'étaient plus responsive au thème car pour que les var css fonctionnent il faut être wrappé dans un div avec la bonne classe. Or dans le cas du Menu, ça passe par Popover (et donc Portal) qui fait donc poper un div dans le DOM (sans la classe css donc). Jusque là ça marchait encore car la balise html comportait les var css. Donc il y avait bien les shadows, pour qu'on soit en normal ou inverted ça utilisait les shadow normal.
Dans cette PR on supprime les var css accroché à la balise html. Ca ne marchait donc plus du tout.

J'ai revu l'approche en réintroduisant le fait qu'on aille chercher les valeurs des vars css, et non utiliser les vars css elles-mêmes pour la construction des shadows. A cause du fonctionnement Popover et du fait qu'il faille être wrappé dans un div qui contient les var css, ça ne peut pas marcher autrement.

@zatteo
Copy link
Contributor

zatteo commented Dec 7, 2023

Bien joué super résultat ! Hâte de voir ça dans les apps

@JF-Cozy JF-Cozy force-pushed the feat/darkMode branch 4 times, most recently from 4d7578d to 40e2666 Compare December 12, 2023 14:49
@JF-Cozy JF-Cozy force-pushed the feat/darkMode branch 2 times, most recently from c1ff095 to c8e23b4 Compare December 21, 2023 13:14
@JF-Cozy JF-Cozy force-pushed the feat/darkMode branch 2 times, most recently from 5f6092a to 13c960c Compare January 8, 2024 09:50
- Remove note about inverted theme
- Remove forced text color to use theme responsive ones
BREAKING CHANGE: if you want to get or override css var, you need to do it on new classes, see below:
`CozyTheme--normal` -> `CozyTheme--light-normal`
`CozyTheme--inverted` -> `CozyTheme--light-inverted`
… node

be more responsive to themes, because for the css variable to have the right value, we need to be under a node that carries the CozyTheme class. But in the `html, body` the tags are too high in the DOM, they're not under a CozyTheme tag, so the variable values aren't right.
To prepare the way to dark mode. `type` is set default to `light`.

BREAKING CHANGE: You can't now longer rely on `theme.palette.type` to determine `normal` or `inverted` theme, you have to use `theme.palette.variant` instead.
BREAKING CHANGE:
- `useCozyTheme()` return now an object with `type` and `variant`. You must replace `const theme = useCozyTheme()` by `const { variant } = useCozyTheme()`
- you can add `<meta name="color-scheme" content="only light" />` in your `index.ejs` app file to force Light Mode if Dark Mode not fully supported by your app.
BREAKING CHANGE:
- Remove some css vars. You should use semantic var instead. List of removed css vars :

```
--invertedBackgroundColor
--invertedContrastTextColor
--spinnerColor
--linkColor
--linkTextDecoration
--linkColorActive
--invertedTabsActiveTextColor
--invertedTabsInactiveTextColor
--invertedTabsIndicatorColor
--invertedTabsBackgroundColor
--regularButtonPrimaryColor
--regularButtonSecondaryColor
--regularButtonActiveColor
--regularButtonConstrastColor
--secondaryButtonPrimaryColor
--secondaryButtonSecondaryColor
--secondaryButtonActiveColor
--secondaryButtonContrastColor
--dividerColor2
--iconColor
--textIconColor
--actionMenuIconColor
--neutralBackground
--buttonTextTransform
--buttonBorderRadius
--alertErrorColor
--alertErrorBackgroundColor
--alertSuccessColor
--alertSuccessBackgroundColor
--alertInfoColor
--alertInfoBackgroundColor
```
@JF-Cozy JF-Cozy merged commit 34f8224 into master Jan 10, 2024
2 checks passed
@JF-Cozy JF-Cozy deleted the feat/darkMode branch January 10, 2024 15:09
@cozy-bot
Copy link

🎉 This PR is included in version 101.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Ldoppea added a commit to cozy/cozy-home that referenced this pull request Feb 23, 2024
`cozy-ui` has been upgraded to `103.6.2` to retrieve the new Theme
variants support (light and dark)

The code changes are for handling the `cozy-ui 101.0.0` breaking
changes

One of the changes consist to force the light theme as there are no
specs yet for this theme support on cozy-home

Related PR: cozy/cozy-ui#2540
Ldoppea added a commit to cozy/cozy-home that referenced this pull request Feb 26, 2024
`cozy-ui` has been upgraded to `103.6.2` to retrieve the new Theme
variants support (light and dark)

The code changes are for handling the `cozy-ui 101.0.0` breaking
changes

One of the changes consist to force the light theme as there are no
specs yet for this theme support on cozy-home

Related PR: cozy/cozy-ui#2540
Ldoppea added a commit to cozy/cozy-home that referenced this pull request Feb 26, 2024
`cozy-ui` has been upgraded to `103.6.2` to retrieve the new Theme
variants support (light and dark)

The code changes are for handling the `cozy-ui 101.0.0` breaking
changes

One of the changes consist to force the light theme as there are no
specs yet for this theme support on cozy-home

Related PR: cozy/cozy-ui#2540
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants