From cb70fffb5852a16245d20ab17065dd5062a2abe5 Mon Sep 17 00:00:00 2001 From: Jeff Galbraith Date: Tue, 14 Jan 2020 08:56:25 -0700 Subject: [PATCH] fix(colors): blend method return type should be same as input (#6107) --- docs/src/pages/quasar-utils/color-utils.md | 3 ++- ui/src/utils/colors.js | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/src/pages/quasar-utils/color-utils.md b/docs/src/pages/quasar-utils/color-utils.md index 7e9c9ddff6a..987097b7944 100644 --- a/docs/src/pages/quasar-utils/color-utils.md +++ b/docs/src/pages/quasar-utils/color-utils.md @@ -60,9 +60,10 @@ Returns a value between 0 and 255. A value of < 128 would be considered a dark c Calculates the [blend](https://www.w3.org/TR/compositing-1/#simplealphacompositing) of two colors. -Accepts a HEX/A String, a RGB/A String or a RGB/A Object as `fgColor`/`bgColor`. +Accepts a HEX/A String or a RGB/A Object as `fgColor`/`bgColor`. If the alpha channel of the `fgColor` is completely opaque, then the result will be the `fgColor`. If the alpha channel of the `bgColor` is completely opaque, then the resulting blended color will also be opaque. +Returns the same type as input for fgColor. ### updateAlpha (color, offset) diff --git a/ui/src/utils/colors.js b/ui/src/utils/colors.js index 4746cd51f63..fa5b3fdd759 100644 --- a/ui/src/utils/colors.js +++ b/ui/src/utils/colors.js @@ -252,7 +252,10 @@ export function blend (fgColor, bgColor) { g = Math.round(((g1 * a1 + g2 * a2 * (1 - a1)) / a) * 255), b = Math.round(((b1 * a1 + b2 * a2 * (1 - a1)) / a) * 255) - return rgbToHex({ r, g, b, a: Math.round(a * 100) }) + const ret = { r, g, b, a: Math.round(a * 100) } + return typeof fgColor === 'string' + ? rgbToHex(ret) + : ret } export function changeAlpha (color, offset) {