Skip to content

Commit 90d5689

Browse files
authored
docs(design): color and theming docs update (#3310)
1 parent cc6bc19 commit 90d5689

File tree

2 files changed

+76
-51
lines changed

2 files changed

+76
-51
lines changed

libs/design/guides/foundations/color.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# Color
2-
Color helps to distinguish and create consistent experiences across products.
2+
Color helps to distinguish and create consistent experiences across products. It highlights key areas, conveys status, urgency, and guides attention.
3+
4+
## Color palettes
5+
The design system includes three core palettes that reflect Daffodil's brand identity, three palettes used to indicate status, and a neutral palette that is dominant throughout the design system. These palettes are built using [HSLuv](https://www.hsluv.org/), a color space designed as a human-friendly alternative to the standard HSL. It aims to address the limitations of traidtional color spaces like RGB and HSL.
6+
7+
For guidance on how to set up your theme with customized palettes, see the [Theming](/libs/design/guides/foundations/theming.md) guide.
38

49
## Accessibility
510
We are committed to complying with the [Web Content Accessibility Guidelines (WCAG) 2.1](https://www.w3.org/TR/WCAG/). The design system is built to meet these guidelines automatically. If you choose to identify your own color palettes outside of Daffodil's colors, please make sure to choose primary, secondary, tertiary, and extended colors that will pass the guidelines. Ensure there is sufficient color contrast between elements so that people who are visually impaired can see and use your products.
611

7-
## Color Contrast
12+
### Color Contrast
813
We have encoded many of the WCAG requirements into our SASS mixins and functions. This means that if you swap to a color palette that does not meet the requirements of WCAG compliance and try to use it within the components, our code will proactively complain and issue errors. This is entirely intentional and will not be changed. The current state of accessibility is lacking, and as a result, we are enforcing accessibility requirements at development time in order to make it easier for developers to accommodate these issues before they are in the hands of users.
914

1015
To verify contrast ratios, we recommend using this [contrast ratio calculator](https://contrast-ratio.com/).

libs/design/guides/foundations/theming.md

+69-49
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,46 @@
11
# Theming
2-
Daffodil's theming capabilities enables you to customize `@daffodil/design` components to reflect your brand. A theme consists of custom color configurations that will work in dark and light themes.
2+
Daffodil's theming capabilities enable you to customize `@daffodil/design`'s component color styles to reflect your brand or product.
33

4-
## Custom Colors
5-
:stop: Before you begin, read the [accessibility guide on color in `@daffodil/design`](./color.md#accessibility).
4+
## Overview
5+
Themes allow you to customize `@daffodil/design` components to match your brand or product's visual style using a set of universal variables, eliminating the need for individual component modifications.
66

7-
## Themes
8-
Dark and light modes are supported in all `@daffodil/design` components. When a theme is not specified, Daffodil defaults to the `light` mode.
7+
## Before you begin
8+
`@daffodil/design` is built with [Sass](https://sass-lang.com/). You should be familiar with the basics of CSS and Sass, including variables, functions, and mixins.
9+
10+
## Modes
11+
Dark and light modes are supported in all `@daffodil/design` components. When a mode is not specified, Daffodil defaults to the `light` mode.
912

1013
## Palettes
1114
A palette is a collection of [perceptually uniform colors](https://programmingdesignsystems.com/color/perceptually-uniform-color-spaces/) with consistent contrast ratios. `@daffodil/design`'s color palettes are represented by a Sass map, with each value in a palette called a **hue**.
1215

13-
## Predefined palettes
14-
`@daffodil/design` offers predefined palettes based on our brand guidelines. You can choose to use our palettes or define your own. No further configuration is needed in your `app-theme.scss` file if you choose to use `@daffodil/design`'s palettes. Below is an example of the structure of a predefined `@daffodil/design` palette.
16+
`@daffodil/design` includes three core palettes that reflect our brand identity, three palettes used to indicate status, and a neutral palette that is dominant throughout the design system. You can choose to use our palettes or define your own.
17+
18+
## Defining a theme
19+
20+
### Using Daffodil's default theme
21+
22+
```scss
23+
@use '@daffodil/design/scss/theme' as daff-theme;
24+
```
25+
26+
Create classes in the `styles.scss` file to include the `daff-theme` mixin for `$theme` and `$theme-dark` variables. This will allow you to set a click event on a button to switch between modes. View this setup in [Stackblitz](https://stackblitz.com/edit/ng13-daffodil-design).
27+
28+
```scss
29+
@use '@daffodil/design/scss/theme' as daff-theme;
30+
31+
.app-theme-light {
32+
@include daff-theme.daff-theme(daff-theme.$theme);
33+
}
34+
35+
.app-theme-dark {
36+
@include daff-theme.daff-theme(daff-theme.$theme-dark);
37+
}
38+
```
39+
40+
### Customizing your own theme
41+
42+
#### Create custom palettes
43+
Create a palettes file that includes Sass maps that can be used as `$primary`, `$secondary`, and `$teritary` colors. Your Sass maps must have hues from 10 to 100, with a step increment of 10 like the example below:
1544

1645
```scss
1746
$daff-blue: (
@@ -28,67 +57,58 @@ $daff-blue: (
2857
);
2958
```
3059

31-
### Defining your own palettes
32-
You can define your own palettes by creating a Sass map that matches the example from above. Your Sass maps must have hues from 10 to 100, with a step increment of 10.
60+
#### Configure your custom palettes
61+
Configure your app to support the custom palettes and set defaults for each palette by using the `daff-configure-palettes` function:
3362

34-
### Setting up your custom theme file
35-
Configure your application to support the custom palettes you created by adding the following to your `app-theme.scss` file:
63+
| Argument | Description |
64+
| -------------- | ------------------------------------------------------------------------------ |
65+
| $color-palette | The name of the palette to read from. |
66+
| $hue | The hue number to read from the palette. This defaults to 60 if not specified. |
3667

3768
```scss
38-
@use '@daffodil/design/scss/theme' as daff-theme;
39-
@use 'app-color-palettes' as palette;
40-
41-
// These palettes describe the colors that make up the "theme" of the components.
42-
43-
$primary: daff-theme.daff-configure-palette(palette.$app-green, 60);
44-
$secondary: daff-theme.daff-configure-palette(palette.$app-blue, 60);
45-
$tertiary: daff-theme.daff-configure-palette(palette.$app-purple, 60);
46-
47-
$theme: daff-theme.daff-configure-theme($primary, $secondary, $tertiary, 'light');
48-
49-
$primary-dark: daff-theme.daff-configure-palette(palette.$app-green, 50);
50-
$secondary-dark: daff-theme.daff-configure-palette(palette.$app-blue, 50);
51-
$tertiary-dark: daff-theme.daff-configure-palette(palette.$app-purple, 50);
69+
app-theme.scss
5270

53-
$theme-dark: daff-theme.daff-configure-theme($primary-dark, $secondary-dark, $tertiary-dark, 'dark');
71+
@use '@daffodil/design/scss/theme' as daff-theme;
72+
@use 'app-color-palettes' as palette; // path to palettes file
5473

55-
$black: daff-theme.daff-map-deep-get($theme, 'core.black');
56-
$white: daff-theme.daff-map-deep-get($theme, 'core.white');
57-
$neutral: daff-theme.daff-map-deep-get($theme, 'core.neutral');
74+
$app-primary: daff-theme.daff-configure-palette(palette.$app-green, 60);
75+
$app-secondary: daff-theme.daff-configure-palette(palette.$app-blue, 60);
76+
$app-tertiary: daff-theme.daff-configure-palette(palette.$app-purple, 60);
5877
```
5978

60-
### Setting up the styles file with `@daffodil/design`'s theme
61-
Use `@daffodil/design`'s theme module to the `styles.scss` file:
79+
#### Define your themes
80+
Define your themes by using the `daff-configure-theme` function:
6281

63-
```scss
64-
@use '@daffodil/design/scss/theme' as daff-theme;
65-
```
82+
| Argument | Description |
83+
| -------- | ------------------------------------------------------------------------- |
84+
| $primary | Specifies the configured palette to use for your app's primary color. |
85+
| $secondary | Specifies the configured palette to use for your app's secondary color. |
86+
| $tertiary | Specifies the configured palette to use for your app's tertiary color. |
87+
| $type | Specifies the type of theme. This can be `light` or `dark`. |
6688

67-
Create classes in the `styles.scss` file to include the `theme` module for `$theme` and `$theme-dark` variables. This will allow you to set a click event on a button to switch between modes. [View this setup in Stackblitz](https://stackblitz.com/edit/ng13-daffodil-design)
89+
`app-theme.scss`
6890

6991
```scss
7092
@use '@daffodil/design/scss/theme' as daff-theme;
93+
@use 'app-color-palettes' as palette; // path to palettes file
7194

72-
.daff-theme-light {
73-
@include daff-theme.daff-theme(daff-theme.$theme);
74-
}
95+
$app-primary: daff-theme.daff-configure-palette(palette.$app-green, 60);
96+
$app-secondary: daff-theme.daff-configure-palette(palette.$app-blue, 60);
97+
$app-tertiary: daff-theme.daff-configure-palette(palette.$app-purple, 60);
7598

76-
.daff-theme-dark {
77-
@include daff-theme.daff-theme(daff-theme.$theme-dark);
78-
}
79-
```
99+
$theme: daff-theme.daff-configure-theme($app-primary, $app-secondary, $app-tertiary, 'light');
80100

81-
### Setting up the styles file with your custom theme
82-
Add `app-theme.scss` to the `styles.scss` file:
101+
$app-primary-dark: daff-theme.daff-configure-palette(palette.$app-green, 50);
102+
$app-secondary-dark: daff-theme.daff-configure-palette(palette.$app-blue, 50);
103+
$app-tertiary-dark: daff-theme.daff-configure-palette(palette.$app-purple, 50);
83104

84-
```scss
85-
@use '@daffodil/design/scss/theme' as daff-theme;
86-
@use 'app-theme';
105+
$theme-dark: daff-theme.daff-configure-theme($app-primary-dark, $app-secondary-dark, $app-tertiary-dark, 'dark');
87106
```
88107

89-
> These lines include theme variables and functions that will generate the theme CSS and style the components.
108+
#### Setting up the styles file with your custom theme
109+
Create classes in the `styles.scss` file to include the `daff-theme` mixin for `$theme` and `$theme-dark` variables. This will allow you to set a click event on a button to switch between modes. [View this setup in Stackblitz](https://stackblitz.com/edit/ng13-daffodil-design-custom-theme).
90110

91-
Create classes in the `styles.scss` file to include the `theme` module for `$theme` and `$theme-dark` variables. This will allow you to set a click event on a button to switch between modes. [View this setup in Stackblitz](https://stackblitz.com/edit/ng13-daffodil-design-custom-theme)
111+
`styles.scss`
92112

93113
```scss
94114
@use '@daffodil/design/scss/theme' as daff-theme;

0 commit comments

Comments
 (0)