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

Color Module - First Draft #147

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cb13637
color: Init first draft
adekunleoduye Jun 21, 2022
e674eeb
fix: clean up format
adekunleoduye Jun 23, 2022
fd0e930
Markdown lobster party!
kaelig Sep 8, 2022
0e2cc98
Updates for future section and tables
ayeshakmaz Sep 26, 2022
055697c
Merge branch 'main' into color-first-draft
ayeshakmaz Sep 26, 2022
bc0f325
More updates
ayeshakmaz Oct 19, 2022
0f02b4c
Merge branch 'color-first-draft' of https://github.com/design-tokens/…
ayeshakmaz Oct 19, 2022
ec0079e
prettier
ayeshakmaz Oct 19, 2022
b688a40
formatting
ayeshakmaz Nov 30, 2022
8ce0869
Update technical-reports/color/index.html
ayeshakmaz May 30, 2023
e4283bc
Update technical-reports/color/index.html
ayeshakmaz May 30, 2023
b938bb9
Update technical-reports/color/color-type.md
ayeshakmaz May 30, 2023
2f4349c
Update technical-reports/color/color-type.md
ayeshakmaz May 30, 2023
f4728eb
Update technical-reports/color/color-type.md
ayeshakmaz May 30, 2023
d25486c
Update technical-reports/color/color-type.md
ayeshakmaz May 30, 2023
f76ef65
Update technical-reports/color/token-naming.md
ayeshakmaz May 30, 2023
a618f5f
Update technical-reports/color/token-naming.md
ayeshakmaz May 30, 2023
3bb8998
Update technical-reports/color/token-naming.md
ayeshakmaz May 30, 2023
70c7212
Update technical-reports/color/color-type.md
ayeshakmaz May 30, 2023
d707312
Merge branch 'main' into color-first-draft
ayeshakmaz May 30, 2023
c5eeb7e
Update to new format with Hex fallback and Colorspace
ayeshakmaz Aug 2, 2023
f34cd40
add: Gradient sections
adekunleoduye Aug 2, 2023
1b18504
format: ran prettier
adekunleoduye Aug 2, 2023
15d896a
format updates
adekunleoduye Aug 2, 2023
5b65608
More format changes
adekunleoduye Aug 3, 2023
e47765b
Merge branch 'main' into color-first-draft
resource11 Aug 20, 2024
e7a9c30
fix format errors
adekunleoduye Aug 20, 2024
62b7771
revert change
adekunleoduye Aug 20, 2024
c61fab2
test verification
adekunleoduye Aug 20, 2024
c58ca34
Sync color-format color type verbiage
resource11 Aug 22, 2024
1226b98
Merge branch 'main' into color-first-draft
resource11 Aug 22, 2024
1195a2f
Merge branch 'main' into color-first-draft
resource11 Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
221 changes: 214 additions & 7 deletions technical-reports/color/color-type.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,229 @@
# The color type
# Color type

Represents a 24bit RGB or 24+8bit RGBA color in the sRGB color space. The `$type` property MUST be set to the string `color`. The value MUST be a string containing a hex triplet/quartet including the preceding `#` character. To support other color spaces, such as HSL, translation tools SHOULD convert color tokens to the equivalent value as needed.
## Format

For example, initially the color tokens MAY be defined as such:
Colors can be represented through various formats. For color tokens, the `$type` property MUST be set to the string `color`. The `$value` property can then be used to specify the details of the color, including color space, alpha settings, and more. The `$value` object contains the following properties:
drwpow marked this conversation as resolved.
Show resolved Hide resolved

- `$hex` (required): the hex color to use as the default or a guaranteed fallback
drwpow marked this conversation as resolved.
Show resolved Hide resolved
- `$colorSpace` (optional): An object detailing an alternative color space to be used to interpret the color, if supported
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Update this list with current format. object keys with current feedback:

Note: The wording is just a suggestion and can be entirely rewritten (please change / improve / rewrite everything!)

Suggested change
- `$colorSpace` (optional): An object detailing an alternative color space to be used to interpret the color, if supported
- `colorSpace` (required): a string representing the predefined colorspace. This value MUST be a value from CSS Color Module Level 4’s [predefined colorspaces](https://www.w3.org/TR/css-color-4/#predefined).
- `channels` (required): an array representing the channel values of the colorspace, excluding alpha. The array’s values MUST be numbers, and MUST have a length of 3. The range of the values depend on `colorSpace`, and match the ranges defined in CSS Color Module Level 4’s [predefined colorspaces](https://www.w3.org/TR/css-color-4/#predefined).
- `alpha` (optional): the alpha channel. The value MUST be a number between `0` (0%) and `1` (100%). If omitted, `1` is assumed.
- `hex` (optional): a string representing an sRGB fallback for colors outside the sRGB gamut. The value MUST be a valid 6-digit hexadecimal code. `alpha`, if supplied, will also apply to the fallback.


The `$colorSpace` object has the following properties:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Make a subheading for colorSpace and channels together, since they are validated together:
Suggested change
The `$colorSpace` object has the following properties:
## `colorSpace` and `channels`

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: make a markdown table that restates the information from CSS Color Module Level 4 that contains:

  • All the accepted colorSpace values accepted
  • For each colorSpace value, the min/max values allowed per channel. This is important because it won’t always be [0, 1] (e.g. the “H” in HSL is [0, 360]).
    • Question: should we use mathematical syntax that uses square brackets for inclusive ranges?
  • Some sort of introduction to this table so people have more context
| colorSpace | channel[0]  | channel[1]  | channel[2]  |
|:-----------|:------------|:------------|:------------|
| `srgb`     | [0, 1]      | [0, 1]      | [0, 1]      |
…
| `lab`      | [0, 1]      | [-125, 125] | [-125, 125] |

Note: the column names may change to whatever is most readable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: should we explain why it’s an array, and why the order matters (following CSS Color 4 spec)? Or is that too much information?


- `$name` (required): the name of the color space (either rgb, srgb, hsl, or lch)
drwpow marked this conversation as resolved.
Show resolved Hide resolved
- `$components` (required): the non-alpha pieces of the color, listed as an array of floating-point numbers or integers
drwpow marked this conversation as resolved.
Show resolved Hide resolved
- `$alpha` (optional): the alpha component of the color, listed as a floating-point number integer in the range of 0 to 1. If omitted, color is assumed to be fully opaque

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the phrasing is suggested and may be completely rewritten. Just communicates some things to think about.

## `alpha`

Alpha MAY be provided to denote the alpha channel. If provided, it MUST be a number ranging from `0` (0%) or `1` (100%). Any number <= `0` MUST be interpreted as `0`, and any number >= `1` MUST be interpreted as `1`, following the [CSS Color Module Level 4](https://www.w3.org/TR/css-color-4/#interpolation-alpha) specification. Tools that deal with alpha interpolation MAY use CSS Color Module Level 4’s [interpolation recommendations](https://www.w3.org/TR/css-color-4/#interpolation-alpha).

## Hex - required support
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Rename to ensure this is now optional
Suggested change
## Hex - required support
## `hex` fallback


For the color value, the required fallback format to represent color through design tokens is a [hex triplet/quartet](https://www.w3.org/TR/css-color-4/#typedef-hex-color) value. A hex triplet is a 6-digit, 24 bit, hexadecimal number that represents Red, Green, and Blue values as `#RRGGBB`. An eight-character hex will include the alpha value in the last 2 characters. If no alpha value is specified, it is assumed the color if fully opaque.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Rewrite these 2 paragraphs to explain why a person may or may not use the hex property
  • Remove “quartet,” and only allow 6-digit hexadecimal
  • Remove the “Pros / Cons” table?


For the initial version of this spec, we expect tools to support Hex values, at minimum. The `$value` property is an object that MUST include a `$hex` property containing a hex value, including the preceding `#` character. To support other color spaces, such as HSL, additional properties can be specified, as demonstrated below.

| Pros | Cons |
| ------------------------------------------ | -------------------------------------- |
| Easily recognized among tools and browsers | Cannot specify alpha value for opacity |

For example, initially color tokens may be defined as such:

<aside class="example">

```json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Update these examples to match current specification

{
"Majestic magenta": {
"$value": "#ff00ff",
"$type": "color"
"$type": "color",
"$value": {
"$hex": "#ff00ff"
}
},
"Translucent shadow": {
"$value": "#00000080",
"$type": "color"
"$type": "color",
"$value": {
"$hex": "#00000080"
}
drwpow marked this conversation as resolved.
Show resolved Hide resolved
}
}
```

</aside>

Then, the output file may look something like:

<aside class="example">

```scss
// colors-hex.scss
$majestic-magenta: #ff00ff;
$translucent-shadow: #00000080;
```

</aside>

## Other color space options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: remove this entire section, including all the colorspaces? (this can be found in the colorSpace table)


### sRGB

Formatted in R (red), G (green), B (blue) and (A) alpha. Red, green, and blue values can range from `0` to `255`, and the alpha value ranges from `0` to `1` (such as `0.5`) or a percentage (such as `50%`) where `1` or `100%` is full opacity.

| Pros | Cons |
| --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Can define alpha value with color directly | It is not perceptually uniform, and is difficult to create variants (lighter or darker, more or less vivid etc) by tweaking its parameters. [Learn more about RGBA issues.](https://lea.verou.me/2020/04/lch-colors-in-css-what-why-and-how/) |
| Alpha value is easy to comprehend at a glance | |

For example, initially color tokens may be defined as such:

<aside class="example">

```json
{
"Majestic magenta": {
"$type": "color",
"$value": {
"$hex": "#c44587",
"$colorSpace": {
"name": "srgb",
"$components": [196, 69, 135]
}
}
},
"Simple sage": {
"$type": "color",
"$value": {
"$hex": "#b4d8a7",
"$colorSpace": {
"name": "srgb",
"$components": [180, 216, 167],
"$alpha": 0.75
}
}
}
}
```

</aside>

Then, the output from a tool’s conversion to RGBA may look something like:

<aside class="example">

```scss
// colors-rgba.scss
$majestic-magenta: rgba(196, 69, 135, 1);
$simple-sage: rgba(180, 216, 167, 0.75);
```

</aside>

### HSL

Formatted in H (hue), S (saturation), L (lightness) and an optional (A) alpha. Hue ranges from `0` to `360`, saturation and lightness are percentage values that range from `0` to `1`, where `0.5` would equal `50%`. The optional alpha value also ranges from `0` to `1` (such as `0.8`) where `1` is full opacity (which is the default value if a value isn’t provided).

| Pros | Cons |
| ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| It is easy to understand and compare to other formats | Alpha parameter is not supported in all browsers [(IE 11)](https://caniuse.com/mdn-css_types_color_hsl_alpha_parameter) |

<aside class="example">

```json
{
"Majestic magenta": {
"$type": "color",
"$value": {
"$hex": "#c44587",
"$colorSpace": {
"name": "hsl",
"$components": [329, 0.52, 0.52]
}
}
},
"Simple sage": {
"$type": "color",
"$value": {
"$hex": "#b4d8a7",
"$colorSpace": {
"name": "hsl",
"$components": [104, 0.39, 0.75],
"$alpha": 0.75
}
}
}
}
```

</aside>

Then, the output variables may look like:

<aside class="example">

```scss
// colors-hsl.scss
$majestic-magenta: hsl(329, 52%, 52%);
$simple-sage: hsl(104, 39%, 74%, 0.75);
```

</aside>

### Hex8

Hex8 uses two extra digits, known as the alpha value, to change the transparency of the color. The format follows `#RRGGBBAA`. [Learn more about alpha values in hex codes](https://www.digitalocean.com/community/tutorials/css-hex-code-colors-alpha-values#adding-an-alpha-value-to-css-hex-codes).

| Pros | Cons |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| Can define alpha value with color | Less commonly used |
| | Alpha value is not immediately obvious (needs calculation) |
| | Not available in older versions of Internet Explorer ([caniuse reference](https://caniuse.com/css-rrggbbaa)) |

<aside class="example">

```json
{
"Majestic magenta": {
"$type": "color",
"$value": {
"$hex": "#c4458780"
}
},
"Simple sage": {
"$type": "color",
"$value": {
"$hex": "#b4d8a780"
}
}
}
```

</aside>

Then, the output variables may look like:

<aside class="example">

```scss
// colors-hex.scss
$majestic-magenta: #c4458780;
$simple-sage: #b4d8a780;

// colors-rgba.scss
$majestic-magenta: rgba(196, 69, 135, 0.5);
$simple-sage: rgba(180, 216, 167, 0.5);
```

</aside>

### LCH (Lightness Chroma Hue)

Formatted in L (lightness), C (chroma), H (hue) and an optional (A) alpha. Hue ranges from `0` to `360`, saturation and lightness are percentage values that range from `0%` to `100%`, and the optional alpha value ranges from `0` and `1` (such as `0.5`) or as a percentage (such as `50%`) where `1` or `100%` is full opacity (which is the default value if a value isn’t provided).

| Pros | Cons |
| ------------------------------------------ | --------------------------------------------------------------------------- |
| Access to 50% more colors (P3 color space) | Colors more perceptually uniform, so it can be harder to distinguish values |

---

## Future color type support

The initial version of the Design Token format will focus on widely-supported color spaces (such as Hex, RGB, HSL, and Hex8). Support for Hex is required, while other format options are optional.

### Backwards compatibility

While future versions of this spec may add support for color spaces like LCH, OKLCH, OKLAB, CAM16, Display P-3, etc., using these color spaces may result in a lack of support from tools. We plan to rely on a Hex back-up when colors need to be downgraded due to lack of support. Please keep this in mind when defining tokens in these more experimental color spaces.
134 changes: 134 additions & 0 deletions technical-reports/color/gradient.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Gradient
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Remove this file as it’s a separate proposal (but this can be a new PR if we want to review)
  • Changes instead should go in composite-types.md—updating all those examples to reference valid colors


Below are instances of implementing various types of gradients:

## Linear

```json
{
"red-to-blue": {
"$type": "gradient",
"$value": {
"$colorSpace": "sHex",
"$style": "linear",
"$angle": "45deg",
"$colors": [
{
"$value": "#b71803",
"$position": 0,
"$alpha": 1
},
{
"$value": "#1e03b7",
"$position": 1,
"$alpha": 1
}
]
}
}
}
```

## Linear using RGB

```json
{
"red-to-blue": {
"$type": "gradient",
"$value": {
"$colorSpace": "srgb",
"$style": "linear",
"$angle": "45deg",
"$colors": [
{
"$value": {
"$hex": "#b71803", // hex fallback
"$colorSpace": {
"$name": "srgb",
"$components": [183, 24, 3],
"$alpha": 1
},
"$position": 0,
"$alpha": 1
}
},
{
"$value": {
"$hex": "#1e03b7", // hex fallback
"$colorSpace": {
"$name": "srgb",
"$components": [30, 3, 183],
"$alpha": 1
},
"$position": 0,
"$alpha": 1
}
}
]
}
}
}
```

## Radial

```json
{
"yellow-glow": {
"$type": "gradient",
"$style": "radial",
"$position": "center",
"$value": {
"$colorSpace": "sHex",
"$colors": [
{
"$value": {
"$hex": "#bbc101",
"$alpha": 1
},
"$position": 0
},
{
"$value": {
"$hex": "#fff",
"$alpha": 0.75
},
"$position": 1
}
]
}
}
}
```

## Conic

```json
{
"purple-radial": {
"$type": "gradient",
"$style": "conic",
"$angle": "45deg",
"$value": {
"$colorSpace": "sHex",
"$colors": [
{
"$value": "#8300ef",
"$position": 0,
"$alpha": 1
},
{
"$value": "#5d04a5",
"$position": 0.5,
"$alpha": 1
},
{
"$value": "#310059",
"$position": 1,
"$alpha": 1
}
]
}
}
}
```
Loading
Loading