Skip to content

Commit 6662ee3

Browse files
cassidooserhalpdanielroe
authored
fix: improve color contrast of comparison table via badge styling (#790)
Co-authored-by: Cassidy Williams <cassidoo@users.noreply.github.com> Co-authored-by: Philippe Serhal <philippe.serhal@gmail.com> Co-authored-by: Daniel Roe <daniel@roe.dev>
1 parent 7c18e8f commit 6662ee3

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

app/components/Compare/FacetRow.vue

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,49 @@ function getBarWidth(value: FacetValue | null | undefined): number {
3838
return (value.raw / maxValue.value) * 100
3939
}
4040
41-
function getStatusClass(status?: FacetValue['status']): string {
41+
function getStatusClass(status?: FacetValue['status'], hasBar = false): string {
42+
// When there's a bar, only apply text color, not background
43+
if (hasBar) {
44+
switch (status) {
45+
case 'muted':
46+
return 'text-fg-subtle'
47+
default:
48+
return 'text-fg'
49+
}
50+
}
51+
52+
// Original behavior when no bar
4253
switch (status) {
4354
case 'good':
44-
return 'text-emerald-400'
55+
return 'bg-emerald-400/20 px-3 py-0.5 rounded-xl'
4556
case 'info':
46-
return 'text-blue-400'
57+
return 'bg-blue-400/20 px-3 py-0.5 rounded-xl'
4758
case 'warning':
48-
return 'text-amber-400'
59+
return 'bg-amber-400/20 px-3 py-0.5 rounded-xl'
4960
case 'bad':
50-
return 'text-red-400'
61+
return 'bg-red-400/20 px-3 py-0.5 rounded-xl'
5162
case 'muted':
5263
return 'text-fg-subtle'
5364
default:
5465
return 'text-fg'
5566
}
5667
}
5768
69+
function getStatusBarClass(status?: FacetValue['status']): string {
70+
switch (status) {
71+
case 'good':
72+
return 'bg-emerald-500/20'
73+
case 'info':
74+
return 'bg-blue-500/20'
75+
case 'warning':
76+
return 'bg-amber-500/20'
77+
case 'bad':
78+
return 'bg-red-500/20'
79+
default:
80+
return 'bg-fg/5'
81+
}
82+
}
83+
5884
// Check if a specific cell is loading
5985
function isCellLoading(index: number): boolean {
6086
return props.facetLoading || (props.columnLoading?.[index] ?? false)
@@ -80,7 +106,8 @@ function isCellLoading(index: number): boolean {
80106
<!-- Background bar for numeric values -->
81107
<div
82108
v-if="showBar && value && getBarWidth(value) > 0"
83-
class="absolute inset-y-1 inset-is-1 bg-fg/5 rounded-sm transition-all duration-300"
109+
class="absolute inset-y-1 inset-is-1 rounded-sm transition-all duration-300"
110+
:class="getStatusBarClass(value.status)"
84111
:style="{ width: `calc(${getBarWidth(value)}% - 8px)` }"
85112
aria-hidden="true"
86113
/>
@@ -103,7 +130,8 @@ function isCellLoading(index: number): boolean {
103130
<TooltipApp v-if="value.tooltip" :text="value.tooltip" position="top">
104131
<span
105132
class="relative font-mono text-sm text-center tabular-nums cursor-help"
106-
:class="getStatusClass(value.status)"
133+
:class="getStatusClass(value.status, showBar && getBarWidth(value) > 0)"
134+
:data-status="value.status"
107135
>
108136
<!-- Date values use DateTime component for i18n and user settings -->
109137
<DateTime v-if="value.type === 'date'" :datetime="value.display" date-style="medium" />
@@ -113,7 +141,8 @@ function isCellLoading(index: number): boolean {
113141
<span
114142
v-else
115143
class="relative font-mono text-sm text-center tabular-nums"
116-
:class="getStatusClass(value.status)"
144+
:class="getStatusClass(value.status, showBar && getBarWidth(value) > 0)"
145+
:data-status="value.status"
117146
>
118147
<!-- Date values use DateTime component for i18n and user settings -->
119148
<DateTime v-if="value.type === 'date'" :datetime="value.display" date-style="medium" />

test/nuxt/components/compare/FacetRow.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,44 +98,44 @@ describe('FacetRow', () => {
9898
})
9999

100100
describe('status styling', () => {
101-
it('applies good status class', async () => {
101+
it('applies good status', async () => {
102102
const component = await mountSuspended(FacetRow, {
103103
props: {
104104
...baseProps,
105105
values: [{ raw: 0, display: 'None', status: 'good' }],
106106
},
107107
})
108-
expect(component.find('.text-emerald-400').exists()).toBe(true)
108+
expect(component.find('[data-status="good"]').exists()).toBe(true)
109109
})
110110

111-
it('applies warning status class', async () => {
111+
it('applies warning status', async () => {
112112
const component = await mountSuspended(FacetRow, {
113113
props: {
114114
...baseProps,
115115
values: [{ raw: 100, display: '100 MB', status: 'warning' }],
116116
},
117117
})
118-
expect(component.find('.text-amber-400').exists()).toBe(true)
118+
expect(component.find('[data-status="warning"]').exists()).toBe(true)
119119
})
120120

121-
it('applies bad status class', async () => {
121+
it('applies bad status', async () => {
122122
const component = await mountSuspended(FacetRow, {
123123
props: {
124124
...baseProps,
125125
values: [{ raw: 5, display: '5 critical', status: 'bad' }],
126126
},
127127
})
128-
expect(component.find('.text-red-400').exists()).toBe(true)
128+
expect(component.find('[data-status="bad"]').exists()).toBe(true)
129129
})
130130

131-
it('applies info status class', async () => {
131+
it('applies info status', async () => {
132132
const component = await mountSuspended(FacetRow, {
133133
props: {
134134
...baseProps,
135135
values: [{ raw: '@types', display: '@types', status: 'info' }],
136136
},
137137
})
138-
expect(component.find('.text-blue-400').exists()).toBe(true)
138+
expect(component.find('[data-status="info"]').exists()).toBe(true)
139139
})
140140
})
141141

0 commit comments

Comments
 (0)