Skip to content

Commit 3b542e0

Browse files
authored
fix: support alpha value in color returned (#1594)
1 parent cecadd5 commit 3b542e0

File tree

7 files changed

+31
-14
lines changed

7 files changed

+31
-14
lines changed

apis/nucleus/src/components/listbox/assets/styling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Color from '../../../utils/color';
1+
import { Color } from '@nebula.js/theme';
22
import { resolveBgColor, resolveBgImage } from '../../../utils/style/styling-props';
33

44
const LIGHT = '#FFF';

apis/theme/src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import paletteResolverFn from './palette-resolver';
66
import styleResolverFn from './style-resolver';
77
import contrasterFn from './contraster/contraster';
88
import luminance from './contraster/luminance';
9+
import Color from './utils/color/color';
910

1011
export default function theme() {
1112
let resolvedThemeJSON;
@@ -186,3 +187,5 @@ export default function theme() {
186187
internalAPI,
187188
};
188189
}
190+
191+
export { Color };

apis/theme/src/palette-resolver.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Color from './utils/color/color';
2+
13
/**
24
* @interface Theme~ScalePalette
35
* @property {string} key
@@ -82,21 +84,33 @@ export default function theme(resolvedTheme) {
8284
if (!somethingIsValid) {
8385
return undefined;
8486
}
85-
// eslint-disable-next-line no-param-reassign
86-
shift = !!shift;
87-
if (c?.index < 0 || typeof c?.index === 'undefined') {
88-
return c.color;
89-
}
90-
if (typeof uiPalette === 'undefined') {
91-
uiPalette = this.uiPalettes()[0] || false;
92-
}
93-
if (!uiPalette) {
94-
return c.color;
87+
const getColor = () => {
88+
// eslint-disable-next-line no-param-reassign
89+
shift = !!shift;
90+
if (c?.index < 0 || typeof c?.index === 'undefined') {
91+
return c.color;
92+
}
93+
if (typeof uiPalette === 'undefined') {
94+
uiPalette = this.uiPalettes()[0] || false;
95+
}
96+
if (!uiPalette) {
97+
return c.color;
98+
}
99+
if (typeof uiPalette.colors[c.index - shift] === 'undefined') {
100+
return c.color;
101+
}
102+
return uiPalette.colors[c.index - shift];
103+
};
104+
const color = getColor();
105+
if (c.alpha === undefined || c.alpha >= 1 || c.alpha < 0) {
106+
return color;
95107
}
96-
if (typeof uiPalette.colors[c.index - shift] === 'undefined') {
97-
return c.color;
108+
const rgbaColor = new Color(color);
109+
rgbaColor.setAlpha(c.alpha);
110+
if (rgbaColor.isInvalid()) {
111+
return color;
98112
}
99-
return uiPalette.colors[c.index - shift];
113+
return rgbaColor.toRGBA();
100114
},
101115
};
102116
}

0 commit comments

Comments
 (0)