Skip to content

Commit 26ffd4b

Browse files
committed
Constrast when alpha
1 parent a8c9b01 commit 26ffd4b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/uui-color-swatch/lib/uui-color-swatch.element.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,15 @@ export class UUIColorSwatchElement extends LabelMixin(
9999
if (color.startsWith('#')) {
100100
this._contrast = this.#contrast(color) === 'light' ? 'light' : 'dark';
101101
} else if (color.startsWith('rgb')) {
102-
const [r, g, b] = color.match(/\d+/g)?.map(Number) ?? [0, 0, 0];
103-
this._contrast =
104-
this.#contrast(this.#rgbToHex(r, g, b)) === 'light' ? 'light' : 'dark';
102+
const [r, g, b, a] = color.match(/[.\d]+/g)?.map(Number) ?? [0, 0, 0];
103+
if (a <= 0.5) {
104+
this._contrast = 'light';
105+
} else {
106+
this._contrast =
107+
this.#contrast(this.#rgbToHex(r, g, b)) === 'light'
108+
? 'light'
109+
: 'dark';
110+
}
105111
}
106112
}
107113

0 commit comments

Comments
 (0)