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 30 commits into
base: main
Choose a base branch
from
Open

Color Module - First Draft #147

wants to merge 30 commits into from

Conversation

adekunleoduye
Copy link

@adekunleoduye adekunleoduye commented Jun 21, 2022

Overview

This is the first draft of the Design Tokens Color Module.

@adekunleoduye adekunleoduye added the Do not merge Add this label to a PR to prevent it from accidentally being merged. label Jun 21, 2022
@netlify
Copy link

netlify bot commented Jun 21, 2022

Deploy Preview for dtcg-tr ready!

Name Link
🔨 Latest commit c58ca34
🔍 Latest deploy log https://app.netlify.com/sites/dtcg-tr/deploys/66c78acd82949c00080b6713
😎 Deploy Preview https://deploy-preview-147--dtcg-tr.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines 25 to 34
{
"Majestic magenta": {
"value": "#ff00ff",
"type": "color"
},
"Simple sage": {
"value": "#abcabc",
"type": "color"
}
}
Copy link
Author

Choose a reason for hiding this comment

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

Update examples

Co-authored-by: Ayesha Mazumdar <ayeshakmaz@users.noreply.github.com>
Co-authored-by: Adekunle Oduye <adekunleoduye@gmail.com>
Co-authored-by: Kathleen McMahon <resource11@users.noreply.github.com>
</td>
<td>
<ul>
<li>No fully supported (only safari)</li>
Copy link

Choose a reason for hiding this comment

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

Suggested change
<li>No fully supported (only safari)</li>
<li>Not fully supported (only safari)</li>

Copy link

Choose a reason for hiding this comment

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

Just a nitpick. It would be nice if the Con sections mentioning the lack of browser support were consistent.

Something like

"Limited Browser Support (Safari)"

Consistent verbiage and browsers with support are listed.

@adekunleoduye adekunleoduye added To be reviewed by editors Issues that need to be reviewed in an upcoming meeting between editors. and removed Do not merge Add this label to a PR to prevent it from accidentally being merged. labels Dec 7, 2022
@adekunleoduye adekunleoduye marked this pull request as ready for review December 7, 2022 17:50
@adekunleoduye adekunleoduye changed the title [WIP] color: Init first draft Color Module - First Draft Dec 7, 2022
technical-reports/color/index.html Outdated Show resolved Hide resolved
technical-reports/color/index.html Show resolved Hide resolved
@@ -0,0 +1,7 @@
## Color module
Copy link
Member

Choose a reason for hiding this comment

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

I think we may need to move this section directly into the technical-reports/color/index.html file like we do with the format:

<section id="introduction">
<h1>Introduction</h1>
<p>
<em>This section is non normative</em>
</p>
<p>
Design tokens are a methodology for expressing design decisions in a
platform-agnostic way so that they can be shared across different
disciplines, tools, and technologies. They help establish a common
vocabulary across organisations.
</p>

And we can probably remove the Color module title.


| Pros | Cons |
| ----------------------------------------------------- | ------------------------------------- |
| It is easy to understand and compare to other formats | Not supported in all browsers (IE 11) |
Copy link
Member

Choose a reason for hiding this comment

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

Not supported in all browsers (IE 11)

Source?

| Pros | Cons |
| ------------------------------------------ | --------------------------------------------------------------------------- |
| Access to 50% more colors (P3 color space) | Colors more perceptually uniform, so it can be harder to distinguish values |
| | Limited browser support (Safari only) |
Copy link
Member

@kaelig kaelig Apr 3, 2023

Choose a reason for hiding this comment

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

Limited browser support (Safari only)

Now supported in Chrome, Edge, Safari, and Firefox behind a flag.

https://caniuse.com/mdn-css_types_color_oklch

return (
<SubbrandContext.Provider value={subbrand}>
<ThemeContext.Provider value={theme}>
<div className={cx(subbrand, theme)} ref={forwardedRef}>
Copy link
Member

Choose a reason for hiding this comment

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

Is there another way to write this without the cx utility function?

ayeshakmaz and others added 16 commits May 30, 2023 14:23
Co-authored-by: Kaelig Deloumeau-Prigent <kaelig@users.noreply.github.com>
Co-authored-by: Kaelig Deloumeau-Prigent <kaelig@users.noreply.github.com>
Co-authored-by: Kaelig Deloumeau-Prigent <kaelig@users.noreply.github.com>
Co-authored-by: Kaelig Deloumeau-Prigent <kaelig@users.noreply.github.com>
Co-authored-by: Kaelig Deloumeau-Prigent <kaelig@users.noreply.github.com>
Co-authored-by: Kaelig Deloumeau-Prigent <kaelig@users.noreply.github.com>
Co-authored-by: Kaelig Deloumeau-Prigent <kaelig@users.noreply.github.com>
Co-authored-by: Kaelig Deloumeau-Prigent <kaelig@users.noreply.github.com>
Co-authored-by: Kaelig Deloumeau-Prigent <kaelig@users.noreply.github.com>
Co-authored-by: Kaelig Deloumeau-Prigent <kaelig@users.noreply.github.com>
Update examples to include colorspace object option, and rearrange files
"text": {
"default": {
"$description": "Default text color",
"$value": {
Copy link
Contributor

@kevinmpowell kevinmpowell Sep 13, 2023

Choose a reason for hiding this comment

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

@adekunleoduye @ayeshakmaz is there any reason for single declarations we can't do:

...
"$value": "#111111"
...

?
The additional object with a single key of "$hex" seems unnecessary.

Copy link
Member

Choose a reason for hiding this comment

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

My understanding was that this notation was still supported?

Copy link
Member

Choose a reason for hiding this comment

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

That's my understanding too. So, both of the syntaxes below are permitted and are exactly equivalent:

{
  "my-color-token": {
    "$type": "color",
    "$value": "#111111"
  }
}

and

{
  "my-color-token": {
    "$type": "color",
    "$value": {
      "$hex": "#111111"
    }
  }
}

However, for this example, it might be better to use the first style since it'll be more familiar to folks used to the current spec draft (which only permits that syntax at the moment) and is more terse.

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:

- `$hex` (required): the hex color to use as the default or a guaranteed fallback
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: $hex, $colorSpace, $name etc should probably drop the $ prefix, right? For all other tokens, $value objects contain normal non-prefixed keys. Which feels more expected because outside the token, $value is a special reserved word that marks any object as a token. But inside the $value, a strict schema is enforced where arbitrary properties are no longer allowed (so no benefit to prefixing keys).

Apologies if there’s a discussion I missed or if this suggestion isn’t helpful.

Copy link
Member

Choose a reason for hiding this comment

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

I was just about to make the same point! :-)

(FWIW, alternatively we could go down the route of making all spec-related properties have a $ prefix for consistency. But then we'd need to make some significant changes to the current format draft in order to update all the composite types. Personally, I'd prefer to stick with the current approach though)

Copy link
Member

@c1rrus c1rrus left a comment

Choose a reason for hiding this comment

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

Sorry it's taken me so long to review this. Great work putting all of this together!

However, I think there's still work to be done to better align this with the format spec.

</p>

<p>Work in progress.</p>
<section
data-include="./overview.md"
Copy link
Member

Choose a reason for hiding this comment

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

The overview.md is missing in this PR. Is this an old link that needs to be removed, or does this file just need to be added to git?

@@ -77,16 +79,29 @@
<h1>Introduction</h1>

<p>
Copy link
Member

Choose a reason for hiding this comment

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

Dunno if this is something that's (going to be?) covered in the missing overview.md file (see my other review comment), but I think it would be helpful to provide a bit more context about this document's purpose here.

My reading is that the "Token naming" chapter is providing non-normative guidance and advice for how to name & organise colour tokens. However, the later sections are detailed specs for how colour tokens should be represented in DTCG files - so I presume they are intended to be normative. Furthermore, those specs conflict with the current format draft (e.g. the format doc currently states that the $value of a color token MUST be a string with a hex value. My understanding is that we want the info in this doc to supersede that though)

I therefore suggest we distinguish between the spec stuff and the guidance stuff more clearly. A few ways we might do this:

  • Move the color type and gradient chapters into the format spec, replacing/updating the corresponding chapters there as needed. Then the color report would only contain guidance and the intro could make that clear.
  • OR, remove the existing color and gradient type chapters from the format spec and replace them with links to this doc. Then this doc becomes the definitive spec for those types - and also complements that with some helpful guidance. In that case, I'd argue that this doc's primary purpose would become being the spec for color tokens in the DTCG format. So maybe we ought to then move the token naming chapter to the end - perhaps even as an appendix (bear in mind that format spec is intentionally agnostic about how folks name and organise their tokens, so putting advice about that at the start of a "spec" document might feel a little odd to readers).

Personally, I have a slight preference for the first option, since it keeps all the spec stuff in one place. But, I'd be OK with the other approach too.

Either way, this will also set a nice precedent for the animation module and any others we may have in the future to follow.


### Base

Base tokens are the lowest level tokens and typically consist of a name and [hexadecimal](https://www.w3.org/TR/css-color-4/#hex-notation) value pair.
Copy link
Member

Choose a reason for hiding this comment

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

Given that we're broadening the ways color values can be expressed in the DTCG format, this should probably be worded more generically:

Suggested change
Base tokens are the lowest level tokens and typically consist of a name and [hexadecimal](https://www.w3.org/TR/css-color-4/#hex-notation) value pair.
Base tokens are the lowest level tokens and typically consist of a name and color value pair.

Copy link

Choose a reason for hiding this comment

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

If the naming convention for color tokens are in the same format as the others (most likely?), why don't we reference a global naming convention here?

"text": {
"default": {
"$description": "Default text color",
"$value": {
Copy link
Member

Choose a reason for hiding this comment

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

That's my understanding too. So, both of the syntaxes below are permitted and are exactly equivalent:

{
  "my-color-token": {
    "$type": "color",
    "$value": "#111111"
  }
}

and

{
  "my-color-token": {
    "$type": "color",
    "$value": {
      "$hex": "#111111"
    }
  }
}

However, for this example, it might be better to use the first style since it'll be more familiar to folks used to the current spec draft (which only permits that syntax at the moment) and is more terse.

Comment on lines +209 to +211
"$darkValue": {
"$hex": "#ffffff"
}
Copy link
Member

Choose a reason for hiding this comment

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

This is not permitted by the format (as it stands). There's no $darkValue format property defined for tokens and extraneous properties not defined in the spec are not allowed.

Right now, there isn't really a means of doing the "single file method" in a DTCG file. We need to reach some conclusion on #210 to have a means of doing that. (and once we do, we can always revisit this section and add a valid DTCG example then)

For now though, I think it would be best to remove this example completely for the time being. I wouldn't want folks to see this and mistakenly think $darkMode in DTCG files is something they can use.

We could still describe a "single file approach" in general terms and cite things like @dbanksdesign "Dark Mode with Style Dictionary" article or Figma's variables as examples of tools that can use this approach though


The `$colorSpace` object has the following properties:

- `$name` (required): the name of the color space (either rgb, srgb, hsl, or lch)
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps make the list of permitted color spaces more explicit? Maybe something like...

- `name` (required): one of the following keys, identifying the color space that this color is in. Note: Other keys are not permitted to avoid clashes with future spec iterations that might add support for additional color spaces.
    - `rgb`: _Some blurb about the RGB color space_
    - `srgb`: _Some blurb about the sRGB color space_
    - `hsl`: _Some blurb about the HSL color space_
    - `lch`: _Some blurb about the LCH color space_

Copy link
Member

Choose a reason for hiding this comment

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

Would something like colorSpace or space be a better property name than name? That would be more explicit about its purpose.

Also, given that this is within a design token, might some folks confuse this with the name of the token?

Copy link

Choose a reason for hiding this comment

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

I agree, since colorSpace is optional, it can have a more distinct nomenclature instead of name

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry; this PR needs to be updated to reflect the current proposal. In an upcoming update you’ll see colorSpace is required, and MUST be a value matching a defined colorspace in CSS Color Module 4. We’ve kept it colorSpace from @c1rrus’ proposal for clarity.

The `$colorSpace` object has the following properties:

- `$name` (required): the name of the color space (either rgb, srgb, hsl, or lch)
- `$components` (required): the non-alpha pieces of the color, listed as an array of floating-point numbers or integers
Copy link
Member

Choose a reason for hiding this comment

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

Question: Do we need to specify what ranges those component values can have? For example, are they always in the range of [0 ... 1] and, if so, how should tools interpret values that fall outside that range - do they clamp them down to that range (similar to what we do for the position values in the format's gradient type), or should they be treated as errors and the whole color value (or even token?) is ignored?

Or, if the permitted range of values might vary depending on the color space, then we ought to list that out somewhere.

Copy link

Choose a reason for hiding this comment

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

Just curious, Is it not clear enough from 0 - 1? My only concern is that designers (that I have worked with) says 70% transparency, but in CSS that is equal to 0.3 or 30%. Should that be commented on?

Copy link
Contributor

@drwpow drwpow Aug 21, 2024

Choose a reason for hiding this comment

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

Oh yes this definitely needs clarification! Because no, values won’t always be between 0-1 if we follow CSS Color Module 4. There are 2 reasons:

  1. Degrees. As in the case of HSL, the range is 0°–360°. This could probably be normalized to 1 but I think most would agree that fails the goal of this spec being human writable since that’s nonstandard
  2. Device-independent colorspaces. In the case of colorspaces like LAB/LCH and OKLAB/OKLCH, they describe many colors that are outside the range of any device existing today, and so there’s no “maximum.”

For the latter, CSS Color Module 4 still does define allowable ranges which are still far beyond what most devices can support; I believe they just put reasonable caps on values that decades of hardware improvements still wouldn’t catch up to (without overreaching and normalizing, which “sets it in stone;” this, conversely, can be expanded if ever needed). Here are some of the values:

  • Lab: L [0 … 100], a [-125 … 125], b [-125 … 125]
  • Lch: L [0 … 100], c [0 … 150], h [0 … 360]
  • Oklab: L [0 … 1], a [-0.4 … 0.4], b [-0.4 … 0.4]
  • Oklch: L [0 … 1], c [0 … 0.4], h [0 … 360]
  • XYZ: 🤔 for some reason this is normalized [0 … 1] but not sure why

The general approach of “match CSS Color Module 4 as much as possible” has been discussed in meetings but I think it would be good to explicate this as much as possible. As far as I know, the color proposal wouldn’t deviate from Color Module 4 in any way. cc @resource11

Copy link
Contributor

Choose a reason for hiding this comment

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

Also alpha in all cases is always normalized [0 … 1], and is optional (default 1 if omitted).

Copy link

Choose a reason for hiding this comment

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

@drwpow yeah, if no color space is omitted, and no other color function is used, opacity/alpha channel (rgba) should always default to normalized 0-1


## Hex - required support

For the color value, the required fallback format to represent color through design tokens is a hex or hex8 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
Member

Choose a reason for hiding this comment

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

To align with the current spec draft and, as far as I know, how hex color values are interpreted in CSS and most design tools, should we say here that the sRGB color space is always implied for these fallback hex values?

Copy link
Contributor

@drwpow drwpow Aug 21, 2024

Choose a reason for hiding this comment

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

Agreed. Hex values have started to be used for Display P3 in design tools, but the intent is limited to sRGB.

Copy link

@Shrinks99 Shrinks99 Aug 21, 2024

Choose a reason for hiding this comment

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

Suggested change
For the color value, the required fallback format to represent color through design tokens is a hex or hex8 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.
For the color value, the required fallback format to represent color through design tokens is a hex or hex8 value. A hex triplet is a 6-character, 24 bit, hexadecimal number that represents Red, Green, and Blue values as `#RRGGBB`. An eight-character hex encoded value will include the alpha value in the last 2 characters. If no alpha value is specified, it is assumed the color if fully opaque. The sRGB colorspace MUST be used when interpreting fallback hex values.

Comment on lines +40 to +42
"$value": {
"$hex": "#00000080"
}
Copy link
Member

Choose a reason for hiding this comment

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

Might it be worth using the string value syntax for this token, to show that that is something people can still do?

Suggested change
"$value": {
"$hex": "#00000080"
}
"$value": "#00000080"

Or adding a 3rd token that uses that syntax?

Copy link
Member

Choose a reason for hiding this comment

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

I suggest splitting this out into a separate PR for now.

As it stands, this has got quite a few deviations from how the gradient type is currently defined in the format:

  • The format does not use $ prefixes for the value's inner properties and, as per the comments from @drwpow and myself on the updated color type, I think we should stick with that. (or, if we didn't, we'd need to change all the other composite types to be consistent)
  • The format does not include a style property, though several folks have suggested something along those lines in Gradient type feedback #101. I think that's probably a worthwhile addition, but there are other interesting proprosals in that thread too, which I think we ought to consider holistically.
  • The format does not have an alpha property on the stops and, given that the color values can have an alpha channel, it feels kinda redundant. Besides, what would be the expected behaviour if both have been specified but have conflicting values?

I presume the intent of this section is really just to show that the new, expanded color value syntax defined in the previous chapter can be used anywhere else that color values are permitted.

The value of a gradient stop is one case of that, but there are others too:

  • the color sub-value of a shadow
  • the color sub-value of a border

So, perhaps this section could be reworked into something that just states that the new object-style color values can be used throughout the spec and include an example of each of those things?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
To be reviewed by editors Issues that need to be reviewed in an upcoming meeting between editors.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants