diff --git a/components/theme/__tests__/util.test.tsx b/components/theme/__tests__/util.test.tsx new file mode 100644 index 0000000000..45741d15ba --- /dev/null +++ b/components/theme/__tests__/util.test.tsx @@ -0,0 +1,9 @@ +import getAlphaColor from '../util/getAlphaColor'; + +describe('util', () => { + describe('getAlphaColor', () => { + it('should not process color with alpha', () => { + expect(getAlphaColor('rgba(0, 0, 0, 0.5)', 'rgba(255, 255, 255)')).toBe('rgba(0, 0, 0, 0.5)'); + }); + }); +}); diff --git a/components/theme/util/getAlphaColor.ts b/components/theme/util/getAlphaColor.ts index 13c5bad82f..a0adc212f9 100644 --- a/components/theme/util/getAlphaColor.ts +++ b/components/theme/util/getAlphaColor.ts @@ -5,7 +5,11 @@ function isStableColor(color: number): boolean { } function getAlphaColor(frontColor: string, backgroundColor: string): string { - const { r: fR, g: fG, b: fB } = new TinyColor(frontColor).toRgb(); + const { r: fR, g: fG, b: fB, a: originAlpha } = new TinyColor(frontColor).toRgb(); + if (originAlpha < 1) { + return frontColor; + } + const { r: bR, g: bG, b: bB } = new TinyColor(backgroundColor).toRgb(); for (let fA = 0.01; fA <= 1; fA += 0.01) {