From a7ce66c0a0535f9003898980f81da3ded9901e9e Mon Sep 17 00:00:00 2001 From: Adam Kudrna Date: Mon, 30 Nov 2026 19:01:04 +0100 Subject: [PATCH] Split form field state colors into text and decoration tokens (#801) Text needs 4.5:1 contrast, while borders need only 3:1. Add `--rui-color-state--text`, `-text-hover` and `-text-active`, and use them for the surrounding text and links of form fields in states. For the warning state, darken `--rui-color-state-warning` so the border uses it directly. Warning links get the darker colors of the warning text. --- src/docs/foundation/colors.md | 26 +++++++++++++++++++++++++ src/styles/theme-constants/_colors.scss | 11 +++++++---- src/styles/theme/_form-fields.scss | 24 +++++++++++------------ src/theme.scss | 22 ++++++++++++++++----- 4 files changed, 62 insertions(+), 21 deletions(-) diff --git a/src/docs/foundation/colors.md b/src/docs/foundation/colors.md index 8d3d6a9b..5bb9f9e1 100644 --- a/src/docs/foundation/colors.md +++ b/src/docs/foundation/colors.md @@ -121,26 +121,52 @@ form fields. Valid, warning, and invalid states look like the success, warning, and danger feedback colors by default, but they are separate and can be customized independently. The changed state has a color of its own. +Each state has two sets of colors: + +- `state-` for decorations, such as borders, +- `state--text` for text and links. It needs more contrast than + decorations, so it can be darker. +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
## Neutral Colors diff --git a/src/styles/theme-constants/_colors.scss b/src/styles/theme-constants/_colors.scss index 7115b672..9865423b 100644 --- a/src/styles/theme-constants/_colors.scss +++ b/src/styles/theme-constants/_colors.scss @@ -7,6 +7,8 @@ $_gray-base-color: #fff; $_amount-light: 90%; $_amount-dark: 10%; $_amount-darker: 20%; +$_amount-state-warning-dark: 15%; +$_state-warning-base: #f59f00; $gray-50: colors.darken-color($_gray-base-color, 5%); $gray-100: colors.darken-color($_gray-base-color, 10%); @@ -36,7 +38,7 @@ $info: #007bff; $state-valid: #2f9e44; $state-invalid: #e03131; -$state-warning: #f59f00; +$state-warning: colors.darken-color($_state-warning-base, $_amount-dark); $state-changed: #b5179e; $white: #fff; @@ -93,9 +95,10 @@ $state-invalid-light: colors.lighten-color($state-invalid, $_amount-light); $state-invalid-dark: colors.darken-color($state-invalid, $_amount-dark); $state-invalid-darker: colors.darken-color($state-invalid, $_amount-darker); -$state-warning-light: colors.lighten-color($state-warning, $_amount-light); -$state-warning-dark: colors.darken-color($state-warning, $_amount-dark); -$state-warning-darker: colors.darken-color($state-warning, $_amount-darker); +// Warning colors are derived from a color lighter than `$state-warning`, whose own value would be too light on borders. +$state-warning-light: colors.lighten-color($_state-warning-base, $_amount-light); +$state-warning-dark: colors.darken-color($_state-warning-base, $_amount-state-warning-dark); +$state-warning-darker: colors.darken-color($_state-warning-base, $_amount-darker); $state-changed-light: colors.lighten-color($state-changed, $_amount-light); $state-changed-dark: colors.darken-color($state-changed, $_amount-dark); diff --git a/src/styles/theme/_form-fields.scss b/src/styles/theme/_form-fields.scss index 3e2040b3..114501f0 100644 --- a/src/styles/theme/_form-fields.scss +++ b/src/styles/theme/_form-fields.scss @@ -33,24 +33,24 @@ $horizontal-full-width-label-width: var(--rui-FormField--horizontal--full-width_ // Form fields: links in states $link-state-colors: ( changed: ( - default: var(--rui-color-state-changed), - hover: var(--rui-color-state-changed-hover), - active: var(--rui-color-state-changed-active), + default: var(--rui-color-state-changed-text), + hover: var(--rui-color-state-changed-text-hover), + active: var(--rui-color-state-changed-text-active), ), invalid: ( - default: var(--rui-color-state-invalid), - hover: var(--rui-color-state-invalid-hover), - active: var(--rui-color-state-invalid-active), + default: var(--rui-color-state-invalid-text), + hover: var(--rui-color-state-invalid-text-hover), + active: var(--rui-color-state-invalid-text-active), ), valid: ( - default: var(--rui-color-state-valid), - hover: var(--rui-color-state-valid-hover), - active: var(--rui-color-state-valid-active), + default: var(--rui-color-state-valid-text), + hover: var(--rui-color-state-valid-text-hover), + active: var(--rui-color-state-valid-text-active), ), warning: ( - default: var(--rui-color-state-warning), - hover: var(--rui-color-state-warning-hover), - active: var(--rui-color-state-warning-active), + default: var(--rui-color-state-warning-text), + hover: var(--rui-color-state-warning-text-hover), + active: var(--rui-color-state-warning-text-active), ), ); diff --git a/src/theme.scss b/src/theme.scss index a7099e4b..a185ea4b 100644 --- a/src/theme.scss +++ b/src/theme.scss @@ -208,15 +208,27 @@ --rui-color-state-valid: #{colors.$state-valid}; --rui-color-state-valid-hover: #{colors.$state-valid-dark}; --rui-color-state-valid-active: #{colors.$state-valid-darker}; + --rui-color-state-valid-text: var(--rui-color-state-valid); + --rui-color-state-valid-text-hover: var(--rui-color-state-valid-hover); + --rui-color-state-valid-text-active: var(--rui-color-state-valid-active); --rui-color-state-invalid: #{colors.$state-invalid}; --rui-color-state-invalid-hover: #{colors.$state-invalid-dark}; --rui-color-state-invalid-active: #{colors.$state-invalid-darker}; + --rui-color-state-invalid-text: var(--rui-color-state-invalid); + --rui-color-state-invalid-text-hover: var(--rui-color-state-invalid-hover); + --rui-color-state-invalid-text-active: var(--rui-color-state-invalid-active); --rui-color-state-warning: #{colors.$state-warning}; --rui-color-state-warning-hover: #{colors.$state-warning-dark}; --rui-color-state-warning-active: #{colors.$state-warning-darker}; + --rui-color-state-warning-text: var(--rui-color-state-warning-active); + --rui-color-state-warning-text-hover: color-mix(in srgb, var(--rui-color-state-warning-text), black 12.5%); + --rui-color-state-warning-text-active: color-mix(in srgb, var(--rui-color-state-warning-text), black 25%); --rui-color-state-changed: #{colors.$state-changed}; --rui-color-state-changed-hover: #{colors.$state-changed-dark}; --rui-color-state-changed-active: #{colors.$state-changed-darker}; + --rui-color-state-changed-text: var(--rui-color-state-changed); + --rui-color-state-changed-text-hover: var(--rui-color-state-changed-hover); + --rui-color-state-changed-text-active: var(--rui-color-state-changed-active); // Neutral colors --rui-color-neutral-light: #{colors.$white}; @@ -877,28 +889,28 @@ --rui-FormField--invalid--default__border-color: var(--rui-color-state-invalid); --rui-FormField--invalid--default__background: var(--rui-color-background-state-invalid); --rui-FormField--invalid--default__check-background-color: var(--rui-FormField--invalid--default__background); - --rui-FormField--invalid--default__surrounding-text-color: var(--rui-color-state-invalid); + --rui-FormField--invalid--default__surrounding-text-color: var(--rui-color-state-invalid-text); --rui-FormField--invalid--checked__check-background-color: var(--rui-FormField--invalid--default__border-color); // Form fields: states: valid --rui-FormField--valid--default__border-color: var(--rui-color-state-valid); --rui-FormField--valid--default__background: var(--rui-color-background-state-valid); --rui-FormField--valid--default__check-background-color: var(--rui-FormField--valid--default__background); - --rui-FormField--valid--default__surrounding-text-color: var(--rui-color-state-valid); + --rui-FormField--valid--default__surrounding-text-color: var(--rui-color-state-valid-text); --rui-FormField--valid--checked__check-background-color: var(--rui-FormField--valid--default__border-color); // Form fields: states: warning - --rui-FormField--warning--default__border-color: var(--rui-color-state-warning-hover); + --rui-FormField--warning--default__border-color: var(--rui-color-state-warning); --rui-FormField--warning--default__background: var(--rui-color-background-state-warning); --rui-FormField--warning--default__check-background-color: var(--rui-FormField--warning--default__background); - --rui-FormField--warning--default__surrounding-text-color: var(--rui-color-state-warning-active); + --rui-FormField--warning--default__surrounding-text-color: var(--rui-color-state-warning-text); --rui-FormField--warning--checked__check-background-color: var(--rui-FormField--warning--default__border-color); // Form fields: states: changed --rui-FormField--changed--default__border-color: var(--rui-color-state-changed); --rui-FormField--changed--default__background: var(--rui-color-background-state-changed); --rui-FormField--changed--default__check-background-color: var(--rui-FormField--changed--default__background); - --rui-FormField--changed--default__surrounding-text-color: var(--rui-color-state-changed); + --rui-FormField--changed--default__surrounding-text-color: var(--rui-color-state-changed-text); --rui-FormField--changed--checked__check-background-color: var(--rui-FormField--changed--default__border-color); // Form fields: box fields