Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🚧 Add getPrimaryColorVars and use it for space primary color theming (#2308)

Luke Vella48633f5bdd15
diff --git a/apps/web/src/app/[locale]/layout.tsx b/apps/web/src/app/[locale]/layout.tsx
index fe5f1bf9a..71315eab6 100644
--- a/apps/web/src/app/[locale]/layout.tsx
+++ b/apps/web/src/app/[locale]/layout.tsx
@@ -18,7 +18,6 @@ import { initI18next } from "@/i18n/i18n";
import { FeatureFlagsProvider } from "@/lib/feature-flags/client";
import { featureFlagConfig } from "@/lib/feature-flags/config";
import { TRPCProvider } from "@/trpc/client/provider";
-import { getForegroundColor } from "@/utils/color";
import { PostHogPageView } from "../posthog-page-view";
const inter = Inter({
@@ -61,13 +60,9 @@ export default async function Root({
const brandingStyles = {
"--primary-light": brandingConfig.primaryColor.light,
- "--primary-light-foreground": getForegroundColor(
- brandingConfig.primaryColor.light,
- ),
+ "--primary-light-foreground": brandingConfig.primaryColor.lightForeground,
"--primary-dark": brandingConfig.primaryColor.dark,
- "--primary-dark-foreground": getForegroundColor(
- brandingConfig.primaryColor.dark,
- ),
+ "--primary-dark-foreground": brandingConfig.primaryColor.darkForeground,
} as React.CSSProperties;
return (
diff --git a/apps/web/src/features/branding/client.tsx b/apps/web/src/features/branding/client.tsx
index b5f6a2984..e55689d41 100644
--- a/apps/web/src/features/branding/client.tsx
+++ b/apps/web/src/features/branding/client.tsx
@@ -5,7 +5,9 @@ import React from "react";
export interface BrandingConfig {
primaryColor: {
light: string;
+ lightForeground: string;
dark: string;
+ darkForeground: string;
};
logo: {
light: string;
diff --git a/apps/web/src/features/branding/color.ts b/apps/web/src/features/branding/color.ts
new file mode 100644
index 000000000..f3152d301
--- /dev/null
+++ b/apps/web/src/features/branding/color.ts
@@ -0,0 +1,13 @@
+import { adjustColorForContrast, getForegroundColor } from "@/utils/color";
+import { DARK_MODE_BACKGROUND, LIGHT_MODE_BACKGROUND } from "./constants";
+
+export function getPrimaryColorVars(primaryColor: string) {
+ const light = adjustColorForContrast(primaryColor, LIGHT_MODE_BACKGROUND);
+ const dark = adjustColorForContrast(primaryColor, DARK_MODE_BACKGROUND);
+ return {
+ light,
+ lightForeground: getForegroundColor(light),
+ dark,
+ darkForeground: getForegroundColor(dark),
+ };
+}
diff --git a/apps/web/src/features/branding/queries.ts b/apps/web/src/features/branding/queries.ts
index a47db66b6..b67b5ce83 100644
--- a/apps/web/src/features/branding/queries.ts
+++ b/apps/web/src/features/branding/queries.ts
@@ -3,29 +3,21 @@ import "server-only";
import { cache } from "react";
import { env } from "@/env";
import { loadInstanceLicense } from "@/features/licensing/data";
-import { adjustColorForContrast } from "@/utils/color";
+import { getForegroundColor } from "@/utils/color";
import { isSelfHosted } from "@/utils/constants";
import type { BrandingConfig } from "./client";
+import { getPrimaryColorVars } from "./color";
import {
- DARK_MODE_BACKGROUND,
DEFAULT_APP_NAME,
DEFAULT_LOGO_ICON_URL,
DEFAULT_LOGO_URL,
DEFAULT_LOGO_URL_DARK,
DEFAULT_PRIMARY_COLOR,
- LIGHT_MODE_BACKGROUND,
} from "./constants";
function getDefaultBrandingConfig(): BrandingConfig {
- const baseColor = DEFAULT_PRIMARY_COLOR;
- const light = adjustColorForContrast(baseColor, LIGHT_MODE_BACKGROUND);
- const dark = adjustColorForContrast(baseColor, DARK_MODE_BACKGROUND);
-
return {
- primaryColor: {
- light,
- dark,
- },
+ primaryColor: getPrimaryColorVars(DEFAULT_PRIMARY_COLOR),
logo: {
light: DEFAULT_LOGO_URL,
dark: DEFAULT_LOGO_URL_DARK,
@@ -38,15 +30,15 @@ function getDefaultBrandingConfig(): BrandingConfig {
export function getCustomBrandingConfig() {
const baseColor = env.PRIMARY_COLOR ?? DEFAULT_PRIMARY_COLOR;
- const light = adjustColorForContrast(baseColor, LIGHT_MODE_BACKGROUND);
- const dark =
- env.PRIMARY_COLOR_DARK ??
- adjustColorForContrast(baseColor, DARK_MODE_BACKGROUND);
+ const vars = getPrimaryColorVars(baseColor);
+ const dark = env.PRIMARY_COLOR_DARK ?? vars.dark;
return {
primaryColor: {
- light,
+ light: vars.light,
+ lightForeground: vars.lightForeground,
dark,
+ darkForeground: dark ? getForegroundColor(dark) : vars.darkForeground,
},
logo: {
light: env.LOGO_URL ?? DEFAULT_LOGO_URL,
diff --git a/apps/web/src/features/space/client.tsx b/apps/web/src/features/space/client.tsx
index 3a33fa8c2..a3ea3560f 100644
--- a/apps/web/src/features/space/client.tsx
+++ b/apps/web/src/features/space/client.tsx
@@ -4,6 +4,7 @@ import { usePostHog } from "@rallly/posthog/client";
import { useRouter } from "next/navigation";
import React from "react";
import { RouterLoadingIndicator } from "@/components/router-loading-indicator";
+import { getPrimaryColorVars } from "@/features/branding/color";
import { defineAbilityForMember } from "@/features/space/member/ability";
import { trpc } from "@/trpc/client";
import { defineAbilityForSpace } from "./ability";
@@ -58,5 +59,25 @@ export function SpaceProvider({ children }: { children: React.ReactNode }) {
return <RouterLoadingIndicator />;
}
- return <>{children}</>;
+ const primaryColorVars = space.primaryColor
+ ? getPrimaryColorVars(space.primaryColor)
+ : null;
+
+ return (
+ <>
+ {primaryColorVars ? (
+ <style>{`
+ .light {
+ --primary: ${primaryColorVars.light};
+ --primary-foreground: ${primaryColorVars.lightForeground};
+ }
+ .dark {
+ --primary: ${primaryColorVars.dark};
+ --primary-foreground: ${primaryColorVars.darkForeground};
+ }
+ `}</style>
+ ) : null}
+ {children}
+ </>
+ );
}