From 5f3262cfe86bfbfcb210c0bb85c11c724284ba53 Mon Sep 17 00:00:00 2001 From: Zohar Manor-Abel Date: Mon, 16 Nov 2026 14:57:35 +0000 Subject: [PATCH] Read intent colours from theme.vars - Progress: use the primary.main sx shortcut so it follows the colour mode - Practical guidance: add the "Read intent colours from theme.vars" section - Colour docs: show theme.vars.palette in the role tables and examples - Changelog entries --- changelog.md | 3 ++ src/components/controls/Progress.test.tsx | 12 +++++ src/components/controls/Progress.tsx | 18 +++---- src/storybook/PracticalGuidance.mdx | 53 +++++++++++++++---- src/storybook/foundation/1. colour.mdx | 16 +++--- .../foundation/1.1. theme-colours.mdx | 4 +- 6 files changed, 77 insertions(+), 29 deletions(-) diff --git a/changelog.md b/changelog.md index 4c8d9b1c..020cac4e 100644 --- a/changelog.md +++ b/changelog.md @@ -17,6 +17,9 @@ ### Fixed +- _Progress_ now follows the colour mode: its primary colour was fixed to the light value in dark mode. +- Practical guidance and theme colours docs read intent colours from `theme.vars.palette`. + ## [v0.8.0] - 2026-11-02 ### Added diff --git a/src/components/controls/Progress.test.tsx b/src/components/controls/Progress.test.tsx index f61fd5e5..59c36ea9 100644 --- a/src/components/controls/Progress.test.tsx +++ b/src/components/controls/Progress.test.tsx @@ -4,6 +4,7 @@ import "@testing-library/jest-dom"; import { screen } from "@testing-library/react"; import { renderWithProviders } from "../../__test-utils__/helpers"; +import { DiamondDSTheme } from "../../themes/DiamondDSTheme"; import { Progress } from "./Progress"; describe("Progress", () => { @@ -36,4 +37,15 @@ describe("Progress", () => { expect(progressbar.parentElement).toBeInTheDocument(); expect(progressbar.parentElement).toHaveStyle("position:relative"); }); + + it("should not hardcode the light-mode primary colour", () => { + renderWithProviders(); + + const css = Array.from(document.querySelectorAll("style")) + .map((style) => style.textContent) + .join("\n"); + expect(css).not.toMatch( + new RegExp(`color:\\s*${DiamondDSTheme.palette.primary.main}`, "i"), + ); + }); }); diff --git a/src/components/controls/Progress.tsx b/src/components/controls/Progress.tsx index 6ba51e07..dca307b6 100644 --- a/src/components/controls/Progress.tsx +++ b/src/components/controls/Progress.tsx @@ -31,10 +31,10 @@ const Progress = (props: ProgressProps) => ( {/* Outer */} ({ - color: theme.palette.primary.main, + sx={{ + color: "primary.main", opacity: 0.2, - })} + }} size={40} thickness={9} value={100} @@ -43,13 +43,13 @@ const Progress = (props: ProgressProps) => ( {/* Inner */} ({ - color: theme.palette.primary.main, + sx={{ + color: "primary.main", opacity: 0.5, position: "absolute", left: 2, top: 2, - })} + }} size={36} thickness={4} value={100} @@ -59,8 +59,8 @@ const Progress = (props: ProgressProps) => ( ({ - color: theme.palette.primary.main, + sx={{ + color: "primary.main", animationDuration: speed[props.speed ?? "medium"], position: "absolute", left: 2.4, @@ -72,7 +72,7 @@ const Progress = (props: ProgressProps) => ( ["@media (prefers-reduced-motion: reduce)"]: { animationDuration: speed["verySlow"], }, - })} + }} size={35} thickness={2} /> diff --git a/src/storybook/PracticalGuidance.mdx b/src/storybook/PracticalGuidance.mdx index 413bf889..ee74bc1c 100644 --- a/src/storybook/PracticalGuidance.mdx +++ b/src/storybook/PracticalGuidance.mdx @@ -49,7 +49,7 @@ Components should consume semantic theme roles rather than hardcoded values. The - theme.palette.primary.main + theme.vars.palette.primary.main #005bbb @@ -80,6 +80,39 @@ Using semantic roles keeps interfaces consistent across products, supports light and dark themes, and allows the system to evolve without rewriting component styles. +### Read intent colours from `theme.vars` + +The light, main, dark and contrast text slots of the intent colours (primary, secondary, error, warning, success, info) are fixed hex values on `theme.palette`. Read in code, they give the light theme's colour in both modes and do not change when the mode does. `theme.vars.palette` returns a CSS variable instead, so the colour follows the mode. It is there whenever the theme uses CSS variables, as the Diamond theme does. + + + + + + + + + + + + + + + + + + +
✅ Prefer❌ Avoid
+ theme.vars.palette.primary.main + + theme.palette.primary.main +
+ rgb(var(--ds-primary-channel) / 0.12) + + alpha(theme.palette.primary.main, 0.12) +
+ +Roles that are already CSS variables, such as text, background, border, surface and the container and solid roles, are safe to read from either. `alpha()`, `lighten()` and `darken()` throw on a `var()` colour, so use the channel tokens for transparency. The tokens for the error intent are named `danger`, so its channel token is `--ds-danger-channel`. + ## Using components Build with existing components and patterns before creating new ones. @@ -217,7 +250,7 @@ Brand colour is intentionally separate. Brand communicates Diamond identity rath
  • Use neutral roles for structure.
  • Use intent roles for meaning.
  • -
  • Use theme.palette or MUI component props so colours work across light and dark themes.
  • +
  • Use theme roles or MUI component props so colours work across light and dark themes.
  • Ensure disabled and error states override hover, focus and selected styling.
@@ -253,7 +286,7 @@ Each role includes related tokens for emphasis, contrast, containers, and intera --ds-[token] - palette.[role].main + theme.vars.palette.[role].main Main semantic colour Actions, status communication, emphasis, identity @@ -263,7 +296,7 @@ Each role includes related tokens for emphasis, contrast, containers, and intera --ds-on-[token] - palette.[role].contrastText + theme.vars.palette.[role].contrastText Foreground colour paired with the role Text and icons shown on the role colour @@ -273,7 +306,7 @@ Each role includes related tokens for emphasis, contrast, containers, and intera --ds-[token]-emphasis - palette.[role].dark + theme.vars.palette.[role].dark Stronger variation of the role Hover, active, or stronger emphasis states @@ -283,7 +316,7 @@ Each role includes related tokens for emphasis, contrast, containers, and intera --ds-[token]-accent - palette.[role].light + theme.vars.palette.[role].light Lighter accent variation Focus rings, highlights, supporting accents @@ -293,7 +326,7 @@ Each role includes related tokens for emphasis, contrast, containers, and intera --ds-[token]-container - palette.[role].container + theme.vars.palette.[role].container Lower-emphasis role surface Chips, alerts, selected regions, grouped states @@ -303,7 +336,7 @@ Each role includes related tokens for emphasis, contrast, containers, and intera --ds-on-[token]-container - palette.[role].onContainer + theme.vars.palette.[role].onContainer Foreground colour paired with role containers Text and icons inside semantic containers @@ -313,7 +346,7 @@ Each role includes related tokens for emphasis, contrast, containers, and intera --ds-[token]-solid - palette.[role].solid + theme.vars.palette.[role].solid High-emphasis interactive surface Contained buttons and strong interactive controls @@ -323,7 +356,7 @@ Each role includes related tokens for emphasis, contrast, containers, and intera --ds-on-[token]-solid - palette.[role].onSolid + theme.vars.palette.[role].onSolid Foreground colour paired with solid surfaces Text and icons inside solid controls diff --git a/src/storybook/foundation/1. colour.mdx b/src/storybook/foundation/1. colour.mdx index 62400b63..c333fe9b 100644 --- a/src/storybook/foundation/1. colour.mdx +++ b/src/storybook/foundation/1. colour.mdx @@ -783,7 +783,7 @@ Intent and brand colours follow a shared semantic structure. --ds-[token] - palette.[role].main + theme.vars.palette.[role].main Main semantic colour Actions, status communication, emphasis, identity @@ -793,7 +793,7 @@ Intent and brand colours follow a shared semantic structure. --ds-on-[token] - palette.[role].contrastText + theme.vars.palette.[role].contrastText Foreground colour paired with the role Text and icons shown on the role colour @@ -803,7 +803,7 @@ Intent and brand colours follow a shared semantic structure. --ds-[token]-emphasis - palette.[role].dark + theme.vars.palette.[role].dark Stronger variation of the role Hover, active, or stronger emphasis states @@ -813,7 +813,7 @@ Intent and brand colours follow a shared semantic structure. --ds-[token]-accent - palette.[role].light + theme.vars.palette.[role].light Lighter accent variation Focus rings, highlights, supporting accents @@ -823,7 +823,7 @@ Intent and brand colours follow a shared semantic structure. --ds-[token]-container - palette.[role].container + theme.vars.palette.[role].container Lower-emphasis role surface Chips, alerts, selected regions, grouped states @@ -833,7 +833,7 @@ Intent and brand colours follow a shared semantic structure. --ds-on-[token]-container - palette.[role].onContainer + theme.vars.palette.[role].onContainer Foreground colour paired with role containers Text and icons inside semantic containers @@ -843,7 +843,7 @@ Intent and brand colours follow a shared semantic structure. --ds-[token]-solid - palette.[role].solid + theme.vars.palette.[role].solid High-emphasis interactive surface Contained buttons and strong interactive controls @@ -853,7 +853,7 @@ Intent and brand colours follow a shared semantic structure. --ds-on-[token]-solid - palette.[role].onSolid + theme.vars.palette.[role].onSolid Foreground colour paired with solid surfaces Text and icons inside solid controls diff --git a/src/storybook/foundation/1.1. theme-colours.mdx b/src/storybook/foundation/1.1. theme-colours.mdx index 58facf6f..f4b93991 100644 --- a/src/storybook/foundation/1.1. theme-colours.mdx +++ b/src/storybook/foundation/1.1. theme-colours.mdx @@ -22,7 +22,7 @@ This page is a token reference. If you're deciding which colour role to use, rea

Intent colours

- Exposed as MUI palette roles (e.g. theme.palette.primary.main + Exposed as MUI palette roles (e.g. theme.vars.palette.primary.main ).

@@ -246,7 +246,7 @@ This page is a token reference. If you're deciding which colour role to use, rea

Intent colours

- Exposed as MUI palette roles (e.g. theme.palette.primary.main + Exposed as MUI palette roles (e.g. theme.vars.palette.primary.main ).