Skip to content

Commit 577890d

Browse files
committed
fix: custom contrast color affected by parents
Signed-off-by: Sami Mazouz <[email protected]>
1 parent 253a3d2 commit 577890d

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

framework/core/js/src/common/components/Badge.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class Badge<CustomAttrs extends IBadgeAttrs = IBadgeAttrs> extend
2828
view() {
2929
const { type, icon: iconName, label, color, style = {}, ...attrs } = this.attrs;
3030

31-
const className = classList('Badge', [type && `Badge--${type}`], attrs.className, color && textContrastClass(color));
31+
const className = classList('Badge', [type && `Badge--${type}`], attrs.className, textContrastClass(color));
3232

3333
const iconChild = iconName ? icon(iconName, { className: 'Badge-icon' }) : m.trust('&nbsp;');
3434

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import isDark from '../utils/isDark';
22

3-
export default function textContrastClass(hexcolor: string | null): string {
3+
export default function textContrastClass(hexcolor: string | null | undefined): string {
4+
if (!hexcolor) return 'text-contrast--unchanged';
5+
46
return isDark(hexcolor) ? 'text-contrast--light' : 'text-contrast--dark';
57
}

framework/core/less/common/scaffolding.less

+6
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,10 @@ blockquote ol:last-child {
176176
--contrast-color: var(--text-on-dark);
177177
color: var(--contrast-color);
178178
}
179+
180+
// This exists to prevent inheriting the contrast color from a parent element.
181+
// Like when a badge is inside a tag hero.
182+
&--unchanged {
183+
--contrast-color: var(--unchanged-color);
184+
}
179185
}

0 commit comments

Comments
 (0)