Skip to content

Commit d3882ac

Browse files
authored
Merge pull request #6066 from IgniteUI/didimmova/update-contrast-color-docs
docs(palette): update contrast color docs
2 parents 127ba99 + 7053e29 commit d3882ac

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

en/components/themes/misc/angular-material-theming.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ To get started with styling components using the Ignite UI theming engine, creat
101101

102102
### Color Palettes
103103

104-
Ignite UI for Angular's [`igx-palette`]({environment:sassApiUrl}/index.html#function-igx-palette) function produces a color palette map including three sub-palettes for the `primary`, `secondary` and `gray` shades as well as five additional colors for `info`, `success`, `warn`, `error` and `surface`. For each color variant, our theming engine automatically generates text contrast colors at build-time, that are also included in the palette. Below, you can see the predefined light material palette:
104+
Ignite UI for Angular's [`palette`]({environment:sassApiUrl}/index.html#function-igx-palette) function produces a color palette map including three sub-palettes for the `primary`, `secondary` and `gray` shades as well as five additional colors for `info`, `success`, `warn`, `error` and `surface`. For each color variant, our theming engine automatically generates text contrast colors at runtime, that are also included in the palette. Below, you can see the predefined light material palette:
105105

106106
```scss
107107
$igx-light-palette: palette(

en/components/themes/palettes.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,45 @@ As the table above shows, the `gray` color doesn't include the `A100`, `A200`, `
4545
On top of the aforementioned colors, we also include **Level AA** [WCAG](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html) compliant `contrast` colors for each color variant. This means that you can safely use the corresponding `contrast` color variants as foreground colors for the base color variant.
4646

4747
> [!NOTE]
48-
> Contrast colors are generated at build-time by the Sass theming engine based on the main variables color (primary, secondary, etc.).
48+
> Contrast colors are CSS relative colors and are runtime calculated, based on the corresponding shade color (primary, secondary, etc.).
4949
5050
Here's an excerpt of the `primary` variable color as declared in the Light Material Palette:
5151

5252
```css
5353
:root {
5454
//...
5555
--ig-primary-500: #09f;
56-
--ig-primary-500-contrast: black;
56+
--ig-primary-500-contrast: hsl(from color(from var(--ig-primary-500) var(--y-contrast)) h 0 l);
5757
--ig-primary-600: hsl(from var(--ig-primary-500) h calc(s * 1.26) calc(l * 0.89));
58-
--ig-primary-600-contrast: black;
58+
--ig-primary-600-contrast: hsl(from color(from var(--ig-primary-600) var(--y-contrast)) h 0 l);
5959
--ig-primary-700: hsl(from var(--ig-primary-500) h calc(s * 1.26) calc(l * 0.81));
6060
//...
6161
--ig-secondary-400: hsl(from var(--ig-secondary-500) h calc(s * 0.875) calc(l * 1.08));
62-
--ig-secondary-400-contrast: black;
62+
--ig-secondary-400-contrast: hsl(from color(from var(--ig-secondary-400) var(--y-contrast)) h 0 l);
6363
--ig-secondary-500: #df1b74;
64-
--ig-secondary-500-contrast: white;
64+
--ig-secondary-500-contrast: hsl(from color(from var(--ig-secondary-500) var(--y-contrast)) h 0 l);
6565
--ig-secondary-600: hsl(from var(--ig-secondary-500) h calc(s * 1.26) calc(l * 0.89));
66-
--ig-secondary-600-contrast: white;
66+
--ig-secondary-600-contrast: hsl(from color(from var(--ig-secondary-600) var(--y-contrast)) h 0 l);
6767
//...
68+
--ig-wcag-a: 0.31;
69+
--ig-wcag-aa: 0.185;
70+
--ig-wcag-aaa: 0.178;
71+
--ig-contrast-level: var(--ig-wcag-aa);
72+
--y: clamp(0,(y / var(--ig-contrast-level) - 1)* -infinity, 1);
73+
--y-contrast: xyz-d65 var(--y) var(--y) var(--y);
6874
}
6975
```
7076

71-
All primary color variants are derived from one base variable color variant `--ig-primary-500`. The same goes for the other color variables `--ig-secondary-500`, `--ig-surface-500`, etc. The other variants are generated through the relative color function `hsl()` which takes the main variable color variant `500` and changes it's `staturation` and `lightness` according to the variable variant which is assigned on (`600`,`700`, etc.). We decided to use this approach as it allows us to modify all variants of the `primary`, `secondary`, `surface` and other colors at runtime.
77+
All primary color variants come from a single base variable: `--ig-primary-500`. This same pattern applies to other color variables like `--ig-secondary-500` and `--ig-surface-500`. The additional variants are created using relative color CSS functions that take the main `500` variable and adjust its `saturation` and `lightness` to create other variants (600, 700, etc.). We chose this approach because it lets us modify all variants of `primary`, `secondary`, `surface`, and other colors during runtime.
7278

73-
> [!WARNING]
74-
> Because the contrast colors are not generated at CSS runtime like the rest, if we change the main color variant(`500`), the contrast color would not be updated. We would need to change them manually. This behavior will be improved upon in an upcoming release, where the contrast colors will also be calculated at CSS runtime.
79+
The contrast colors are CSS runtime generated, based on the the provided color's luminance and the chosen contrast-level to calculate the best contrast color for it. If we change the main color variant(`500`), the contrast colors will also be updated.
80+
81+
> [!NOTE]
82+
> You could specify the contrast-level globally by using the `palette` mixin, or if you'd like to set it specifically in the scope of your element, you could use the `adaptive-contrast` mixin. They both accept one of the predefined values: `a`, `aa` or `aaa`.
83+
84+
```scss
85+
@include palette($palette, $contrast-level: 'aaa');
86+
```
7587

7688
## Defining Palettes
7789

0 commit comments

Comments
 (0)