ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
51.05k stars 13.51k forks source link

bug: Theme Step Colors are Only Defined for DARK Mode #29965

Open ejohanson-vi3 opened 1 week ago

ejohanson-vi3 commented 1 week ago

Prerequisites

Ionic Framework Version

v7.x, v8.x

Current Behavior

If an Ionic app has DARK mode active, there are "step" color variables defined, which are named "--ion-background-color-step-50", "--ion-background-color-step-100", etc., up to "--ion-background-color-step-950". Also there are contrasting "step" colors for text named "--ion-text-color-step-50", etc.

These step colors work as expected in DARK mode. However, if the app is put into LIGHT mode, these variables are not defined at all. This results in plain white for any color CSS attribute that tries to use them in LIGHT mode.

Expected Behavior

The "step" color definitions should work both in LIGHT mode and DARK mode, although the definitions for LIGHT mode should be the inverse of dark mode. That is, the "--ion-background-color-step-100" for LIGHT mode should be the same value as the "--ion-background-color-step-900" for DARK mode.

Steps to Reproduce

  1. Place some CSS into an Ionic app that references a "step" color, such as:
    .my-class {
    background-color: var(--ion-background-color-step-750);
    color: var(--ion-text-color-step-750);
    }
  2. Run the Ionic app using the LIGHT theme.
  3. You would expect a medium-dark gray background and a light gray text, but instead you get pure white.
  4. If you switch the app to the DARK them, then it will work.

Code Reproduction URL

https://github.com/ejohanson-vi3/step-colors

Ionic Info

Ionic:

Ionic CLI : 7.2.0 (C:\local\nodejs\node_modules\@ionic\cli) Ionic Framework : @ionic/vue 8.2.0

Capacitor:

Capacitor CLI : 6.0.0 @capacitor/android : 6.0.0 @capacitor/core : 6.0.0 @capacitor/ios : 6.0.0

Utility:

cordova-res : 0.15.4 native-run : 2.0.1

System:

NodeJS : v20.14.0 (C:\local\nodejs\node.exe) npm : 10.8.1 OS : Windows 10

Additional Information

As a workaround, a project can add the following to the theme/variables.css file. However, this just uses the Android MD colors, and does not differentiate between iOS and MD platforms (the definitions in the Ionic source code have slightly different color values for iOS and MD in DARK mode).

:root {
    --ion-background-color-step-950: #1e1e1e;
    --ion-background-color-step-900: #2a2a2a;
    --ion-background-color-step-850: #363636;
    --ion-background-color-step-800: #414141;
    --ion-background-color-step-750: #4d4d4d;
    --ion-background-color-step-700: #595959;
    --ion-background-color-step-650: #656565;
    --ion-background-color-step-600: #717171;
    --ion-background-color-step-550: #7d7d7d;
    --ion-background-color-step-500: #898989;
    --ion-background-color-step-450: #949494;
    --ion-background-color-step-400: #a0a0a0;
    --ion-background-color-step-350: #acacac;
    --ion-background-color-step-300: #b8b8b8;
    --ion-background-color-step-250: #c4c4c4;
    --ion-background-color-step-200: #d0d0d0;
    --ion-background-color-step-150: #dbdbdb;
    --ion-background-color-step-100: #e7e7e7;
    --ion-background-color-step-50: #f3f3f3;
    --ion-text-color-step-950: #f3f3f3;
    --ion-text-color-step-900: #e7e7e7;
    --ion-text-color-step-850: #dbdbdb;
    --ion-text-color-step-800: #d0d0d0;
    --ion-text-color-step-750: #c4c4c4;
    --ion-text-color-step-700: #b8b8b8;
    --ion-text-color-step-650: #acacac;
    --ion-text-color-step-600: #a0a0a0;
    --ion-text-color-step-550: #949494;
    --ion-text-color-step-500: #898989;
    --ion-text-color-step-450: #7d7d7d;
    --ion-text-color-step-400: #717171;
    --ion-text-color-step-350: #656565;
    --ion-text-color-step-300: #595959;
    --ion-text-color-step-250: #4d4d4d;
    --ion-text-color-step-200: #414141;
    --ion-text-color-step-150: #363636;
    --ion-text-color-step-100: #2a2a2a;
    --ion-text-color-step-50: #1e1e1e;
}
wsamoht commented 1 day ago

For reference, this was brought up on the forum too - https://forum.ionicframework.com/t/theme-color-definitions-for-ion-background-color-step/244827