bito-code-review[bot] commented on code in PR #42053:
URL: https://github.com/apache/superset/pull/42053#discussion_r3677897421
##########
superset-frontend/packages/superset-ui-core/src/color/utils.ts:
##########
@@ -120,3 +121,30 @@ export function rgbToHex(red: number, green: number, blue:
number) {
return `#${r}${g}${b}`;
}
+
+export function rgbaToHex(rgb: RGBColor): string {
+ const { r, g, b, a = 1 } = rgb;
+ const toHex = (value: number) => {
+ const hex = Math.round(value).toString(16);
+ return hex.length === 1 ? `0${hex}` : hex;
+ };
+ const hexColor = `#${toHex(r)}${toHex(g)}${toHex(b)}`;
+ if (a !== 1) {
+ return `${hexColor}${toHex(Math.round(a * 255))}`;
+ }
+ return hexColor;
+}
+
+export const forceHexAlpha = (color: string | RGBColor): string => {
+ if (typeof color === 'object' && color !== null) {
+ return rgbaToHex({ ...color, a: 0.6 });
+ }
+
+ const hex = color.startsWith('#') ? color : `#${color}`;
+
+ if (hex.length === 9) {
+ return `${hex.slice(0, -2)}99`;
+ }
+
+ return `${hex}99`;
+};
Review Comment:
<!-- Bito Reply -->
The suggestion to add unit tests for the `forceHexAlpha` function is
appropriate. Adding tests for string and RGBColor object inputs, including
various hex formats, ensures the function behaves correctly across all
supported input types.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]