Skip to content

Commit b789aa9

Browse files
committed
tidy up
1 parent 3e25ab0 commit b789aa9

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/frontend/components/FasterCarsFromBehind/FasterCarsFromBehind.stories.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ export default {
88
classColor: {
99
options: [undefined, 0xffda59, 0x33ceff, 0xff5888, 0xae6bff, 0xffffff],
1010
control: { type: 'select' },
11-
description: 'Background color for the component'
12-
}
11+
},
12+
percent: {
13+
control: { type: 'range', min: 0, max: 100 },
14+
},
1315
}
1416
} as Meta<typeof FasterCarsFromBehindDisplay>;
1517

src/frontend/components/FasterCarsFromBehind/FasterCarsFromBehind.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useFasterCarsSettings } from './hooks/useFasterCarsSettings';
44
import { getTailwindStyle } from '@irdashies/utils/colors';
55

66
export interface FasterCarsFromBehindProps {
7-
name?: string | null;
7+
name?: string;
88
distance?: number;
99
percent?: number;
1010
classColor?: number;
@@ -30,24 +30,23 @@ export const FasterCarsFromBehindDisplay = ({
3030
percent,
3131
classColor,
3232
}: FasterCarsFromBehindProps) => {
33-
const hidden = name === null || name == undefined ? 'hidden' : '';
33+
if (!name) {
34+
return null;
35+
}
36+
3437
const animate = distance && distance > -0.3 ? 'animate-pulse' : '';
3538
const red = percent || 0;
3639
const green = 100 - (percent || 0);
3740
const background = getTailwindStyle(classColor).classHeader;
3841

3942
return (
40-
<div className={`w-full flex justify-between rounded-sm p-1 pb-2 font-bold relative ${hidden}`}>
43+
<div className={`w-full flex justify-between rounded-sm p-1 pb-2 font-bold relative ${background} ${animate}`}>
4144
<div className="rounded-sm bg-gray-700 p-1">{name}</div>
4245
<div className="rounded-sm bg-gray-700 p-1">{distance}</div>
4346
<div
44-
className={`absolute inset-0 rounded-sm ${background} ${animate}`}
45-
style={{ zIndex: -1 }}
46-
></div>
47-
<div
48-
className={`absolute bottom-0 left-0 rounded-b-sm bg-white h-1 flex-none transition-all`}
47+
className={`absolute bottom-0 left-0 rounded-b-sm bg-white h-1 flex-none`}
4948
style={{
50-
width: `${percent}%`,
49+
width: `${percent ?? 0}%`,
5150
backgroundColor: `rgb(${red}%, ${green}%, 0%)`,
5251
}}
5352
></div>

src/frontend/components/FasterCarsFromBehind/hooks/useCarBehind.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const useCarBehind = ({
2929
carBehind?.carClass?.relativeSpeed <= myCar?.carClass?.relativeSpeed ||
3030
carBehind?.delta < threshold
3131
) {
32-
return { name: null, distance: 0, classColor: undefined, percent: 0 };
32+
return { name: undefined, distance: 0, classColor: undefined, percent: 0 };
3333
}
3434

3535
return fasterCarFromBehind;

0 commit comments

Comments
 (0)