Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Refactor image components to improve styling and maintain aspect ratios

Bill Yang72a0d773a1b4
diff --git a/client/src/app/[site]/components/shared/icons/Browser.tsx b/client/src/app/[site]/components/shared/icons/Browser.tsx
index 47b9bacd7..bcb56f8df 100644
--- a/client/src/app/[site]/components/shared/icons/Browser.tsx
+++ b/client/src/app/[site]/components/shared/icons/Browser.tsx
@@ -68,7 +68,13 @@ export function Browser({ browser, size = 16 }: { browser: string; size?: number
return (
<>
{BROWSER_TO_LOGO[browser] ? (
- <Image src={`/browsers/${BROWSER_TO_LOGO[browser]}`} alt={browser || "Other"} width={size} height={size} />
+ <Image
+ src={`/browsers/${BROWSER_TO_LOGO[browser]}`}
+ alt={browser || "Other"}
+ width={size}
+ height={size}
+ style={{ width: size, height: size, objectFit: "contain" }}
+ />
) : (
<Compass width={size} height={size} />
)}
diff --git a/client/src/app/[site]/main/components/MainSection/MainSection.tsx b/client/src/app/[site]/main/components/MainSection/MainSection.tsx
index 73cf8b004..56f1a61fe 100644
--- a/client/src/app/[site]/main/components/MainSection/MainSection.tsx
+++ b/client/src/app/[site]/main/components/MainSection/MainSection.tsx
@@ -104,7 +104,7 @@ export function MainSection() {
href={session.data ? "/" : "https://rybbit.com"}
className="opacity-75"
>
- <RybbitTextLogo width={80} height={0} />
+ <RybbitTextLogo width={80} />
</Link>
)}
</div>
diff --git a/client/src/app/[site]/performance/components/PerformanceChart.tsx b/client/src/app/[site]/performance/components/PerformanceChart.tsx
index 6079e2617..e823e832a 100644
--- a/client/src/app/[site]/performance/components/PerformanceChart.tsx
+++ b/client/src/app/[site]/performance/components/PerformanceChart.tsx
@@ -200,7 +200,7 @@ export function PerformanceChart() {
<div className="flex items-center justify-between px-2 md:px-0">
<div className="flex items-center space-x-4">
<Link href={session.data ? "/" : "https://rybbit.com"} className="opacity-75">
- <RybbitTextLogo width={80} height={0} />
+ <RybbitTextLogo width={80} />
</Link>
</div>
<div className="flex items-center space-x-4">
diff --git a/client/src/app/components/Footer.tsx b/client/src/app/components/Footer.tsx
index 85bf8c144..08cb0a05b 100644
--- a/client/src/app/components/Footer.tsx
+++ b/client/src/app/components/Footer.tsx
@@ -22,7 +22,14 @@ export function Footer() {
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8 mb-8">
{/* Company Info */}
<div className="space-y-4">
- <Image src="/rybbit/horizontal_white.svg" alt="Rybbit" width={140} height={0} style={{ height: "auto" }} className="dark:invert-0 invert" />
+ <Image
+ src="/rybbit/horizontal_white.svg"
+ alt="Rybbit"
+ width={140}
+ height={28}
+ style={{ width: 140, height: 28, objectFit: "contain" }}
+ className="dark:invert-0 invert"
+ />
{!IS_CLOUD && (
<div className="space-y-3">
<div className="text-sm text-neutral-600 dark:text-neutral-200">
diff --git a/client/src/components/RybbitLogo.tsx b/client/src/components/RybbitLogo.tsx
index e2120be70..3506eb23c 100644
--- a/client/src/components/RybbitLogo.tsx
+++ b/client/src/components/RybbitLogo.tsx
@@ -3,9 +3,16 @@ import { useEffect, useState } from "react";
import { useWhiteLabel } from "../hooks/useIsWhiteLabel";
import { Skeleton } from "./ui/skeleton";
+const HORIZONTAL_LOGO_ASPECT_RATIO = 500 / 100.27;
+
+function getTextLogoHeight(width: number, height?: number) {
+ return height && height > 0 ? height : Math.round(width / HORIZONTAL_LOGO_ASPECT_RATIO);
+}
+
export function RybbitLogo({ width = 32, height = 32 }: { width?: number; height?: number }) {
const { whiteLabelImage, isPending } = useWhiteLabel();
const [mounted, setMounted] = useState(false);
+ const imageStyle = { width, height, objectFit: "contain" as const };
useEffect(() => {
setMounted(true);
@@ -16,7 +23,7 @@ export function RybbitLogo({ width = 32, height = 32 }: { width?: number; height
}
if (whiteLabelImage) {
- return <Image src={whiteLabelImage} alt="Rybbit" width={width} height={height} />;
+ return <Image src={whiteLabelImage} alt="Rybbit" width={width} height={height} style={imageStyle} />;
}
return (
@@ -25,26 +32,48 @@ export function RybbitLogo({ width = 32, height = 32 }: { width?: number; height
alt="Rybbit"
width={width}
height={height}
+ style={imageStyle}
className="invert dark:invert-0"
/>
);
}
-export function RybbitTextLogo({ width = 150, height = 34 }: { width?: number; height?: number }) {
+export function RybbitTextLogo({ width = 150, height }: { width?: number; height?: number }) {
const { whiteLabelImage, isPending } = useWhiteLabel();
const [mounted, setMounted] = useState(false);
+ const resolvedHeight = getTextLogoHeight(width, height);
+ const imageStyle = { width, height: resolvedHeight, objectFit: "contain" as const };
useEffect(() => {
setMounted(true);
}, []);
if (!mounted || isPending) {
- return <Skeleton style={{ width, height }} />;
+ return <Skeleton style={{ width, height: resolvedHeight }} />;
}
if (whiteLabelImage) {
- return <Image src={whiteLabelImage} alt="Rybbit" width={width} height={height} />;
+ return (
+ <Image
+ src={whiteLabelImage}
+ alt="Rybbit"
+ width={width}
+ height={resolvedHeight}
+ style={imageStyle}
+ loading="eager"
+ />
+ );
}
- return <Image src="/rybbit/horizontal_white.svg" alt="Rybbit" width={width} height={height} className="dark:invert-0 invert" />;
+ return (
+ <Image
+ src="/rybbit/horizontal_white.svg"
+ alt="Rybbit"
+ width={width}
+ height={resolvedHeight}
+ style={imageStyle}
+ loading="eager"
+ className="dark:invert-0 invert"
+ />
+ );
}