mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-25 13:58:46 +00:00
feat(login): comprehensive theme system (#10848)
# Which Problems Are Solved This PR introduces a comprehensive theme customization system for the login application with responsive behavior and enhanced visual options. <img width="1122" height="578" alt="Screenshot 2025-08-19 at 09 55 24" src="https://github.com/user-attachments/assets/cdcc8948-533d-4e13-bf45-fdcc24acfb2b" /> # How the Problems Are Solved ## ✨ Features Added - **🔄 Responsive Layout System**: Automatic switching between side-by-side and top-to-bottom layouts based on screen size - **🖼️ Background Image Support**: Custom background images configurable via environment variables - **⚙️ Theme Configuration**: Complete theme system with roundness, spacing, appearance, and layout options - **📱 Mobile-First Design**: Intelligent layout adaptation for different screen sizes - **🎯 Enhanced Typography**: Improved visual hierarchy with larger titles in side-by-side mode ## 🏗️ Architecture - **Server-Safe Theme Functions**: Theme configuration accessible on both server and client - **SSR-Safe Hooks**: Proper hydration handling for responsive layouts - **Component Separation**: Clear boundaries between server and client components - **Two-Section Layout**: Consistent content structure across all login pages ## 🔧 Configuration Options All theme options are configurable via environment variables: - `NEXT_PUBLIC_THEME_ROUNDNESS`: `edgy` | `mid` | `full` - `NEXT_PUBLIC_THEME_LAYOUT`: `side-by-side` | `top-to-bottom` - `NEXT_PUBLIC_THEME_APPEARANCE`: `flat` | `material` - `NEXT_PUBLIC_THEME_SPACING`: `regular` | `compact` - `NEXT_PUBLIC_THEME_BACKGROUND_IMAGE`: Custom background image URL ## 📄 Pages Updated Updated all major login pages to use the new two-section responsive layout: - Login name entry - Password verification - MFA verification - User registration - Account selection - Device authorization - Logout confirmation ## 📚 Documentation - **THEME_ARCHITECTURE.md**: Complete technical documentation of the theme system - **THEME_CUSTOMIZATION.md**: User-friendly guide with examples and troubleshooting ## 🚀 Benefits - **Better UX**: Responsive design that works seamlessly across all devices - **Brand Flexibility**: Easy customization to match any brand identity - **Maintainable Code**: Clean separation of concerns and well-documented architecture - **Future-Proof**: Extensible system for additional theme options <img width="580" height="680" alt="Screenshot 2025-08-19 at 09 22 23" src="https://github.com/user-attachments/assets/9de8da37-6d56-4fe9-b337-5d8ad2a3ba59" /> <img width="599" height="689" alt="Screenshot 2025-08-19 at 09 23 45" src="https://github.com/user-attachments/assets/26a30cc7-4017-4f4b-8b87-a49466c42b94" /> <img width="595" height="681" alt="Screenshot 2025-08-19 at 09 23 17" src="https://github.com/user-attachments/assets/a3d31088-4545-4f36-aafe-1aae1253d677" />
This commit is contained in:
@@ -243,7 +243,12 @@ describe("isSessionValid", () => {
|
||||
const result = await isSessionValid({ serviceUrl: mockServiceUrl, session });
|
||||
|
||||
expect(result).toBe(false);
|
||||
expect(consoleSpy).toHaveBeenCalledWith("Session has no valid MFA factor. Configured methods:", expect.any(Array), "Session factors:", expect.any(Object));
|
||||
expect(consoleSpy).toHaveBeenCalledWith(
|
||||
"Session has no valid MFA factor. Configured methods:",
|
||||
expect.any(Array),
|
||||
"Session factors:",
|
||||
expect.any(Object),
|
||||
);
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { getThemeConfig } from "./theme";
|
||||
|
||||
/**
|
||||
* Custom hook that returns the effective layout mode, taking into account
|
||||
* both the theme configuration and responsive breakpoints.
|
||||
*
|
||||
* On medium screens and below (md: max-width 767px), it will automatically
|
||||
* switch to top-to-bottom layout regardless of the theme setting.
|
||||
*
|
||||
* NOTE: This is a client-side hook and requires "use client" directive.
|
||||
*/
|
||||
export function useResponsiveLayout(): { isSideBySide: boolean; isResponsiveOverride: boolean } {
|
||||
const themeConfig = getThemeConfig();
|
||||
const [isMdOrSmaller, setIsMdOrSmaller] = useState(false);
|
||||
const [isHydrated, setIsHydrated] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
// Mark as hydrated on client side
|
||||
setIsHydrated(true);
|
||||
|
||||
// Check if we're in a browser environment
|
||||
if (typeof window === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
const mediaQuery = window.matchMedia("(max-width: 767px)"); // md breakpoint is 768px in Tailwind
|
||||
|
||||
// Set initial value
|
||||
setIsMdOrSmaller(mediaQuery.matches);
|
||||
|
||||
// Listen for changes
|
||||
const handleChange = (e: MediaQueryListEvent) => {
|
||||
setIsMdOrSmaller(e.matches);
|
||||
};
|
||||
|
||||
mediaQuery.addEventListener("change", handleChange);
|
||||
|
||||
// Cleanup
|
||||
return () => mediaQuery.removeEventListener("change", handleChange);
|
||||
}, []);
|
||||
|
||||
const configuredSideBySide = themeConfig.layout === "side-by-side";
|
||||
|
||||
// During SSR or before hydration, assume desktop (side-by-side if configured)
|
||||
// This prevents hydration mismatches
|
||||
const isSideBySide = configuredSideBySide && (isHydrated ? !isMdOrSmaller : true);
|
||||
const isResponsiveOverride = configuredSideBySide && isHydrated && isMdOrSmaller;
|
||||
|
||||
return { isSideBySide, isResponsiveOverride };
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom hook that returns the theme configuration for client-side usage.
|
||||
*
|
||||
* NOTE: This is a client-side hook and requires "use client" directive.
|
||||
*/
|
||||
export function useThemeConfig() {
|
||||
return getThemeConfig();
|
||||
}
|
||||
@@ -0,0 +1,453 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
||||
import {
|
||||
ThemeRoundness,
|
||||
ThemeLayout,
|
||||
ThemeAppearance,
|
||||
ThemeSpacing,
|
||||
ComponentRoundnessConfig,
|
||||
DEFAULT_COMPONENT_ROUNDNESS,
|
||||
DEFAULT_THEME,
|
||||
getThemeConfig,
|
||||
ROUNDNESS_CLASSES,
|
||||
getComponentRoundness,
|
||||
SPACING_STYLES,
|
||||
APPEARANCE_STYLES,
|
||||
} from "./theme";
|
||||
|
||||
describe("Theme Configuration", () => {
|
||||
const originalEnv = process.env;
|
||||
|
||||
beforeEach(() => {
|
||||
// Reset environment variables before each test
|
||||
process.env = { ...originalEnv };
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// Restore original environment variables
|
||||
process.env = originalEnv;
|
||||
});
|
||||
|
||||
describe("DEFAULT_COMPONENT_ROUNDNESS", () => {
|
||||
it("should have correct default values for all components", () => {
|
||||
expect(DEFAULT_COMPONENT_ROUNDNESS).toEqual({
|
||||
card: "mid",
|
||||
button: "mid",
|
||||
input: "mid",
|
||||
image: "mid",
|
||||
avatar: "full",
|
||||
avatarContainer: "full",
|
||||
themeSwitch: "full",
|
||||
});
|
||||
});
|
||||
|
||||
it("should have all required component types", () => {
|
||||
const requiredComponents: (keyof ComponentRoundnessConfig)[] = [
|
||||
"card",
|
||||
"button",
|
||||
"input",
|
||||
"image",
|
||||
"avatar",
|
||||
"avatarContainer",
|
||||
"themeSwitch",
|
||||
];
|
||||
|
||||
requiredComponents.forEach((component) => {
|
||||
expect(DEFAULT_COMPONENT_ROUNDNESS).toHaveProperty(component);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DEFAULT_THEME", () => {
|
||||
it("should have all required properties", () => {
|
||||
expect(DEFAULT_THEME).toEqual({
|
||||
roundness: "mid",
|
||||
componentRoundness: DEFAULT_COMPONENT_ROUNDNESS,
|
||||
layout: "top-to-bottom",
|
||||
appearance: "flat",
|
||||
spacing: "regular",
|
||||
});
|
||||
});
|
||||
|
||||
it("should have valid default values", () => {
|
||||
expect(DEFAULT_THEME.roundness).toBe("mid");
|
||||
expect(DEFAULT_THEME.layout).toBe("top-to-bottom");
|
||||
expect(DEFAULT_THEME.appearance).toBe("flat");
|
||||
expect(DEFAULT_THEME.spacing).toBe("regular");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getThemeConfig", () => {
|
||||
it("should return default theme when no environment variables are set", () => {
|
||||
const config = getThemeConfig();
|
||||
|
||||
expect(config.roundness).toBe(DEFAULT_THEME.roundness);
|
||||
expect(config.layout).toBe(DEFAULT_THEME.layout);
|
||||
expect(config.appearance).toBe(DEFAULT_THEME.appearance);
|
||||
expect(config.spacing).toBe(DEFAULT_THEME.spacing);
|
||||
expect(config.componentRoundness).toEqual(DEFAULT_COMPONENT_ROUNDNESS);
|
||||
});
|
||||
|
||||
it("should use global roundness from environment variable", () => {
|
||||
process.env.NEXT_PUBLIC_THEME_ROUNDNESS = "full";
|
||||
|
||||
const config = getThemeConfig();
|
||||
|
||||
expect(config.roundness).toBe("full");
|
||||
});
|
||||
|
||||
it("should apply global roundness to all components when env var is set", () => {
|
||||
process.env.NEXT_PUBLIC_THEME_ROUNDNESS = "edgy";
|
||||
|
||||
const config = getThemeConfig();
|
||||
|
||||
expect(config.componentRoundness?.card).toBe("edgy");
|
||||
expect(config.componentRoundness?.button).toBe("edgy");
|
||||
expect(config.componentRoundness?.input).toBe("edgy");
|
||||
expect(config.componentRoundness?.image).toBe("edgy");
|
||||
expect(config.componentRoundness?.avatar).toBe("edgy");
|
||||
expect(config.componentRoundness?.avatarContainer).toBe("edgy");
|
||||
expect(config.componentRoundness?.themeSwitch).toBe("edgy");
|
||||
});
|
||||
|
||||
it("should use component-specific defaults when global roundness is not set", () => {
|
||||
const config = getThemeConfig();
|
||||
|
||||
expect(config.componentRoundness).toEqual(DEFAULT_COMPONENT_ROUNDNESS);
|
||||
expect(config.componentRoundness?.avatar).toBe("full");
|
||||
expect(config.componentRoundness?.avatarContainer).toBe("full");
|
||||
expect(config.componentRoundness?.card).toBe("mid");
|
||||
});
|
||||
|
||||
it("should use layout from environment variable", () => {
|
||||
process.env.NEXT_PUBLIC_THEME_LAYOUT = "side-by-side";
|
||||
|
||||
const config = getThemeConfig();
|
||||
|
||||
expect(config.layout).toBe("side-by-side");
|
||||
});
|
||||
|
||||
it("should use appearance from environment variable", () => {
|
||||
process.env.NEXT_PUBLIC_THEME_APPEARANCE = "material";
|
||||
|
||||
const config = getThemeConfig();
|
||||
|
||||
expect(config.appearance).toBe("material");
|
||||
});
|
||||
|
||||
it("should use spacing from environment variable", () => {
|
||||
process.env.NEXT_PUBLIC_THEME_SPACING = "compact";
|
||||
|
||||
const config = getThemeConfig();
|
||||
|
||||
expect(config.spacing).toBe("compact");
|
||||
});
|
||||
|
||||
it("should use background image from environment variable", () => {
|
||||
const backgroundUrl = "https://example.com/image.jpg";
|
||||
process.env.NEXT_PUBLIC_THEME_BACKGROUND_IMAGE = backgroundUrl;
|
||||
|
||||
const config = getThemeConfig();
|
||||
|
||||
expect(config.backgroundImage).toBe(backgroundUrl);
|
||||
});
|
||||
|
||||
it("should have undefined background image when not set", () => {
|
||||
const config = getThemeConfig();
|
||||
|
||||
expect(config.backgroundImage).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should combine multiple environment variables correctly", () => {
|
||||
process.env.NEXT_PUBLIC_THEME_ROUNDNESS = "full";
|
||||
process.env.NEXT_PUBLIC_THEME_LAYOUT = "side-by-side";
|
||||
process.env.NEXT_PUBLIC_THEME_APPEARANCE = "glass";
|
||||
process.env.NEXT_PUBLIC_THEME_SPACING = "compact";
|
||||
process.env.NEXT_PUBLIC_THEME_BACKGROUND_IMAGE = "https://example.com/bg.png";
|
||||
|
||||
const config = getThemeConfig();
|
||||
|
||||
expect(config.roundness).toBe("full");
|
||||
expect(config.layout).toBe("side-by-side");
|
||||
expect(config.appearance).toBe("glass");
|
||||
expect(config.spacing).toBe("compact");
|
||||
expect(config.backgroundImage).toBe("https://example.com/bg.png");
|
||||
});
|
||||
});
|
||||
|
||||
describe("ROUNDNESS_CLASSES", () => {
|
||||
it("should have classes for all roundness levels", () => {
|
||||
expect(ROUNDNESS_CLASSES).toHaveProperty("edgy");
|
||||
expect(ROUNDNESS_CLASSES).toHaveProperty("mid");
|
||||
expect(ROUNDNESS_CLASSES).toHaveProperty("full");
|
||||
});
|
||||
|
||||
it("should have classes for all component types in each roundness level", () => {
|
||||
const components: (keyof ComponentRoundnessConfig)[] = [
|
||||
"card",
|
||||
"button",
|
||||
"input",
|
||||
"image",
|
||||
"avatar",
|
||||
"avatarContainer",
|
||||
"themeSwitch",
|
||||
];
|
||||
|
||||
const roundnessLevels: ThemeRoundness[] = ["edgy", "mid", "full"];
|
||||
|
||||
roundnessLevels.forEach((level) => {
|
||||
components.forEach((component) => {
|
||||
expect(ROUNDNESS_CLASSES[level]).toHaveProperty(component);
|
||||
expect(typeof ROUNDNESS_CLASSES[level][component]).toBe("string");
|
||||
expect(ROUNDNESS_CLASSES[level][component].length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should have distinct classes for different roundness levels", () => {
|
||||
const components: (keyof ComponentRoundnessConfig)[] = ["card", "button", "input"];
|
||||
|
||||
components.forEach((component) => {
|
||||
// Each roundness level should have different classes for the same component
|
||||
expect(ROUNDNESS_CLASSES.edgy[component]).not.toBe(ROUNDNESS_CLASSES.mid[component]);
|
||||
expect(ROUNDNESS_CLASSES.mid[component]).not.toBe(ROUNDNESS_CLASSES.full[component]);
|
||||
expect(ROUNDNESS_CLASSES.edgy[component]).not.toBe(ROUNDNESS_CLASSES.full[component]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("getComponentRoundness", () => {
|
||||
it("should return a valid CSS class string for any component", () => {
|
||||
const cardClass = getComponentRoundness("card");
|
||||
expect(typeof cardClass).toBe("string");
|
||||
expect(cardClass.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("should return different classes for different components with default config", () => {
|
||||
const cardClass = getComponentRoundness("card");
|
||||
const avatarClass = getComponentRoundness("avatar");
|
||||
|
||||
// Avatar defaults to full roundness, card to mid - they should be different
|
||||
expect(cardClass).not.toBe(avatarClass);
|
||||
});
|
||||
|
||||
it("should change output when global roundness environment variable changes", () => {
|
||||
// Get default
|
||||
const defaultCardClass = getComponentRoundness("card");
|
||||
|
||||
// Set to different roundness
|
||||
process.env.NEXT_PUBLIC_THEME_ROUNDNESS = "edgy";
|
||||
const edgyCardClass = getComponentRoundness("card");
|
||||
|
||||
// Should be different
|
||||
expect(edgyCardClass).not.toBe(defaultCardClass);
|
||||
|
||||
// Try another roundness level
|
||||
process.env.NEXT_PUBLIC_THEME_ROUNDNESS = "full";
|
||||
const fullCardClass = getComponentRoundness("card");
|
||||
|
||||
expect(fullCardClass).not.toBe(defaultCardClass);
|
||||
expect(fullCardClass).not.toBe(edgyCardClass);
|
||||
});
|
||||
|
||||
it("should return classes for all component types", () => {
|
||||
const components: (keyof ComponentRoundnessConfig)[] = [
|
||||
"card",
|
||||
"button",
|
||||
"input",
|
||||
"image",
|
||||
"avatar",
|
||||
"avatarContainer",
|
||||
"themeSwitch",
|
||||
];
|
||||
|
||||
components.forEach((component) => {
|
||||
const cssClass = getComponentRoundness(component);
|
||||
expect(typeof cssClass).toBe("string");
|
||||
expect(cssClass.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
it("should apply global roundness to all components when set", () => {
|
||||
process.env.NEXT_PUBLIC_THEME_ROUNDNESS = "full";
|
||||
|
||||
const cardClass = getComponentRoundness("card");
|
||||
const buttonClass = getComponentRoundness("button");
|
||||
const avatarClass = getComponentRoundness("avatar");
|
||||
|
||||
// All should get classes from the "full" roundness level
|
||||
expect(cardClass).toBe(ROUNDNESS_CLASSES.full.card);
|
||||
expect(buttonClass).toBe(ROUNDNESS_CLASSES.full.button);
|
||||
expect(avatarClass).toBe(ROUNDNESS_CLASSES.full.avatar);
|
||||
});
|
||||
|
||||
it("should respect component-specific defaults when no global roundness is set", () => {
|
||||
delete process.env.NEXT_PUBLIC_THEME_ROUNDNESS;
|
||||
|
||||
const avatarClass = getComponentRoundness("avatar");
|
||||
const cardClass = getComponentRoundness("card");
|
||||
|
||||
// Avatar should use its default (full), card should use its default (mid)
|
||||
expect(avatarClass).toBe(ROUNDNESS_CLASSES.full.avatar);
|
||||
expect(cardClass).toBe(ROUNDNESS_CLASSES.mid.card);
|
||||
});
|
||||
});
|
||||
|
||||
describe("SPACING_STYLES", () => {
|
||||
it("should have regular and compact spacing options", () => {
|
||||
expect(SPACING_STYLES).toHaveProperty("regular");
|
||||
expect(SPACING_STYLES).toHaveProperty("compact");
|
||||
});
|
||||
|
||||
it("should have spacing and padding properties for each option", () => {
|
||||
expect(SPACING_STYLES.regular).toHaveProperty("spacing");
|
||||
expect(SPACING_STYLES.regular).toHaveProperty("padding");
|
||||
expect(SPACING_STYLES.compact).toHaveProperty("spacing");
|
||||
expect(SPACING_STYLES.compact).toHaveProperty("padding");
|
||||
});
|
||||
|
||||
it("should have non-empty string values for all properties", () => {
|
||||
expect(typeof SPACING_STYLES.regular.spacing).toBe("string");
|
||||
expect(SPACING_STYLES.regular.spacing.length).toBeGreaterThan(0);
|
||||
expect(typeof SPACING_STYLES.regular.padding).toBe("string");
|
||||
expect(SPACING_STYLES.regular.padding.length).toBeGreaterThan(0);
|
||||
|
||||
expect(typeof SPACING_STYLES.compact.spacing).toBe("string");
|
||||
expect(SPACING_STYLES.compact.spacing.length).toBeGreaterThan(0);
|
||||
expect(typeof SPACING_STYLES.compact.padding).toBe("string");
|
||||
expect(SPACING_STYLES.compact.padding.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("should have different values between regular and compact", () => {
|
||||
expect(SPACING_STYLES.regular.spacing).not.toBe(SPACING_STYLES.compact.spacing);
|
||||
expect(SPACING_STYLES.regular.padding).not.toBe(SPACING_STYLES.compact.padding);
|
||||
});
|
||||
});
|
||||
|
||||
describe("APPEARANCE_STYLES", () => {
|
||||
it("should have flat, material, and glass appearance options", () => {
|
||||
expect(APPEARANCE_STYLES).toHaveProperty("flat");
|
||||
expect(APPEARANCE_STYLES).toHaveProperty("material");
|
||||
expect(APPEARANCE_STYLES).toHaveProperty("glass");
|
||||
});
|
||||
|
||||
it("should have required properties for each appearance", () => {
|
||||
const requiredProperties = ["card", "button", "idp-button", "typography", "background"];
|
||||
|
||||
Object.values(APPEARANCE_STYLES).forEach((style) => {
|
||||
requiredProperties.forEach((prop) => {
|
||||
expect(style).toHaveProperty(prop);
|
||||
// @ts-ignore - dynamic property access
|
||||
expect(typeof style[prop]).toBe("string");
|
||||
// @ts-ignore - dynamic property access
|
||||
expect(style[prop].length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should have different styles for different appearances", () => {
|
||||
// Each appearance should have distinct card styles
|
||||
expect(APPEARANCE_STYLES.flat.card).not.toBe(APPEARANCE_STYLES.material.card);
|
||||
expect(APPEARANCE_STYLES.material.card).not.toBe(APPEARANCE_STYLES.glass.card);
|
||||
expect(APPEARANCE_STYLES.flat.card).not.toBe(APPEARANCE_STYLES.glass.card);
|
||||
|
||||
// Each appearance should have distinct button styles
|
||||
expect(APPEARANCE_STYLES.flat.button).not.toBe(APPEARANCE_STYLES.material.button);
|
||||
expect(APPEARANCE_STYLES.material.button).not.toBe(APPEARANCE_STYLES.glass.button);
|
||||
expect(APPEARANCE_STYLES.flat.button).not.toBe(APPEARANCE_STYLES.glass.button);
|
||||
});
|
||||
|
||||
it("should have idp-button styles for all appearances", () => {
|
||||
expect(APPEARANCE_STYLES.flat["idp-button"]).toBeDefined();
|
||||
expect(typeof APPEARANCE_STYLES.flat["idp-button"]).toBe("string");
|
||||
|
||||
expect(APPEARANCE_STYLES.material["idp-button"]).toBeDefined();
|
||||
expect(typeof APPEARANCE_STYLES.material["idp-button"]).toBe("string");
|
||||
|
||||
expect(APPEARANCE_STYLES.glass["idp-button"]).toBeDefined();
|
||||
expect(typeof APPEARANCE_STYLES.glass["idp-button"]).toBe("string");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Type Safety", () => {
|
||||
it("should accept valid ThemeRoundness values", () => {
|
||||
const validValues: ThemeRoundness[] = ["edgy", "mid", "full"];
|
||||
validValues.forEach((value) => {
|
||||
expect(["edgy", "mid", "full"]).toContain(value);
|
||||
});
|
||||
});
|
||||
|
||||
it("should accept valid ThemeLayout values", () => {
|
||||
const validValues: ThemeLayout[] = ["side-by-side", "top-to-bottom"];
|
||||
validValues.forEach((value) => {
|
||||
expect(["side-by-side", "top-to-bottom"]).toContain(value);
|
||||
});
|
||||
});
|
||||
|
||||
it("should accept valid ThemeAppearance values", () => {
|
||||
const validValues: ThemeAppearance[] = ["flat", "material", "glass"];
|
||||
validValues.forEach((value) => {
|
||||
expect(["flat", "material", "glass"]).toContain(value);
|
||||
});
|
||||
});
|
||||
|
||||
it("should accept valid ThemeSpacing values", () => {
|
||||
const validValues: ThemeSpacing[] = ["regular", "compact"];
|
||||
validValues.forEach((value) => {
|
||||
expect(["regular", "compact"]).toContain(value);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Integration Tests", () => {
|
||||
it("should work correctly when switching between different roundness levels", () => {
|
||||
// Get classes for different roundness levels
|
||||
process.env.NEXT_PUBLIC_THEME_ROUNDNESS = "edgy";
|
||||
const edgyClass = getComponentRoundness("card");
|
||||
|
||||
process.env.NEXT_PUBLIC_THEME_ROUNDNESS = "mid";
|
||||
const midClass = getComponentRoundness("card");
|
||||
|
||||
process.env.NEXT_PUBLIC_THEME_ROUNDNESS = "full";
|
||||
const fullClass = getComponentRoundness("card");
|
||||
|
||||
// All should be different
|
||||
expect(edgyClass).not.toBe(midClass);
|
||||
expect(midClass).not.toBe(fullClass);
|
||||
expect(edgyClass).not.toBe(fullClass);
|
||||
|
||||
// All should be valid strings
|
||||
expect(typeof edgyClass).toBe("string");
|
||||
expect(typeof midClass).toBe("string");
|
||||
expect(typeof fullClass).toBe("string");
|
||||
});
|
||||
|
||||
it("should maintain consistency across all theme properties", () => {
|
||||
process.env.NEXT_PUBLIC_THEME_ROUNDNESS = "full";
|
||||
process.env.NEXT_PUBLIC_THEME_LAYOUT = "side-by-side";
|
||||
process.env.NEXT_PUBLIC_THEME_APPEARANCE = "material";
|
||||
process.env.NEXT_PUBLIC_THEME_SPACING = "compact";
|
||||
|
||||
const config = getThemeConfig();
|
||||
|
||||
// Verify all properties are set correctly
|
||||
expect(config.roundness).toBe("full");
|
||||
expect(config.layout).toBe("side-by-side");
|
||||
expect(config.appearance).toBe("material");
|
||||
expect(config.spacing).toBe("compact");
|
||||
|
||||
// Verify component roundness is applied globally
|
||||
expect(config.componentRoundness?.card).toBe("full");
|
||||
expect(config.componentRoundness?.button).toBe("full");
|
||||
});
|
||||
|
||||
it("should handle empty string environment variables by using defaults", () => {
|
||||
process.env.NEXT_PUBLIC_THEME_ROUNDNESS = "";
|
||||
process.env.NEXT_PUBLIC_THEME_LAYOUT = "";
|
||||
|
||||
const config = getThemeConfig();
|
||||
|
||||
expect(config.roundness).toBe(DEFAULT_THEME.roundness);
|
||||
expect(config.layout).toBe(DEFAULT_THEME.layout);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,154 @@
|
||||
// Theme configuration system for customizable login experience
|
||||
|
||||
export type ThemeRoundness = "edgy" | "mid" | "full";
|
||||
export type ThemeLayout = "side-by-side" | "top-to-bottom";
|
||||
export type ThemeAppearance = "flat" | "material" | "glass";
|
||||
export type ThemeSpacing = "regular" | "compact";
|
||||
|
||||
export interface ComponentRoundnessConfig {
|
||||
card: ThemeRoundness;
|
||||
button: ThemeRoundness;
|
||||
input: ThemeRoundness;
|
||||
image: ThemeRoundness;
|
||||
avatar: ThemeRoundness;
|
||||
avatarContainer: ThemeRoundness;
|
||||
themeSwitch: ThemeRoundness;
|
||||
}
|
||||
|
||||
export interface ThemeConfig {
|
||||
roundness: ThemeRoundness; // Global fallback
|
||||
componentRoundness?: ComponentRoundnessConfig; // Component-specific overrides
|
||||
layout: ThemeLayout;
|
||||
backgroundImage?: string;
|
||||
appearance: ThemeAppearance;
|
||||
spacing: ThemeSpacing;
|
||||
}
|
||||
|
||||
// Default component-specific roundness configuration
|
||||
export const DEFAULT_COMPONENT_ROUNDNESS: ComponentRoundnessConfig = {
|
||||
card: "mid",
|
||||
button: "mid",
|
||||
input: "mid",
|
||||
image: "mid",
|
||||
avatar: "full", // Avatars default to full roundness
|
||||
avatarContainer: "full", // Avatar containers default to full roundness
|
||||
themeSwitch: "full", // Theme switch defaults to full roundness
|
||||
};
|
||||
|
||||
// Default theme configuration
|
||||
export const DEFAULT_THEME: ThemeConfig = {
|
||||
roundness: "mid",
|
||||
componentRoundness: DEFAULT_COMPONENT_ROUNDNESS,
|
||||
layout: "top-to-bottom",
|
||||
appearance: "flat",
|
||||
spacing: "regular",
|
||||
};
|
||||
|
||||
// Get theme configuration from environment variables
|
||||
export function getThemeConfig(): ThemeConfig {
|
||||
const globalRoundness = process.env.NEXT_PUBLIC_THEME_ROUNDNESS as ThemeRoundness;
|
||||
|
||||
// If global roundness is set via env var, use it for all components
|
||||
// Otherwise, use component-specific defaults
|
||||
const componentRoundness = globalRoundness
|
||||
? {
|
||||
card: globalRoundness,
|
||||
button: globalRoundness,
|
||||
input: globalRoundness,
|
||||
image: globalRoundness,
|
||||
avatar: globalRoundness,
|
||||
avatarContainer: globalRoundness,
|
||||
themeSwitch: globalRoundness,
|
||||
}
|
||||
: DEFAULT_COMPONENT_ROUNDNESS;
|
||||
|
||||
return {
|
||||
roundness: globalRoundness || DEFAULT_THEME.roundness,
|
||||
componentRoundness: componentRoundness,
|
||||
layout: (process.env.NEXT_PUBLIC_THEME_LAYOUT as ThemeLayout) || DEFAULT_THEME.layout,
|
||||
backgroundImage: process.env.NEXT_PUBLIC_THEME_BACKGROUND_IMAGE || undefined,
|
||||
appearance: (process.env.NEXT_PUBLIC_THEME_APPEARANCE as ThemeAppearance) || DEFAULT_THEME.appearance,
|
||||
spacing: (process.env.NEXT_PUBLIC_THEME_SPACING as ThemeSpacing) || DEFAULT_THEME.spacing,
|
||||
};
|
||||
}
|
||||
|
||||
// Roundness CSS classes
|
||||
export const ROUNDNESS_CLASSES = {
|
||||
edgy: {
|
||||
card: "rounded-none",
|
||||
button: "rounded-none",
|
||||
input: "rounded-none",
|
||||
image: "rounded-none",
|
||||
avatar: "rounded-none",
|
||||
avatarContainer: "rounded-none",
|
||||
themeSwitch: "rounded-none",
|
||||
},
|
||||
mid: {
|
||||
card: "rounded-lg",
|
||||
button: "rounded-md",
|
||||
input: "rounded-md",
|
||||
image: "rounded-lg",
|
||||
avatar: "rounded-lg",
|
||||
avatarContainer: "rounded-md",
|
||||
themeSwitch: "rounded-md",
|
||||
},
|
||||
full: {
|
||||
card: "rounded-3xl",
|
||||
button: "rounded-full",
|
||||
input: "rounded-full pl-4",
|
||||
image: "rounded-full",
|
||||
avatar: "rounded-full",
|
||||
avatarContainer: "rounded-full",
|
||||
themeSwitch: "rounded-full",
|
||||
},
|
||||
} as const;
|
||||
|
||||
// Helper function to get component-specific roundness
|
||||
export function getComponentRoundness(componentType: keyof ComponentRoundnessConfig): string {
|
||||
const themeConfig = getThemeConfig();
|
||||
|
||||
// Use component-specific roundness if available, otherwise fall back to global roundness
|
||||
const roundnessLevel = themeConfig.componentRoundness?.[componentType] || themeConfig.roundness;
|
||||
|
||||
return ROUNDNESS_CLASSES[roundnessLevel][componentType];
|
||||
}
|
||||
|
||||
// Spacing configuration
|
||||
export const SPACING_STYLES = {
|
||||
regular: {
|
||||
spacing: "space-y-6",
|
||||
padding: "p-6 py-8",
|
||||
},
|
||||
compact: {
|
||||
spacing: "space-y-4",
|
||||
padding: "p-4",
|
||||
},
|
||||
} as const;
|
||||
|
||||
// Appearance styling (complete design philosophies)
|
||||
export const APPEARANCE_STYLES = {
|
||||
flat: {
|
||||
card: "bg-background-light-400 dark:bg-background-dark-500 border border-opacity-20 border border-black/10 dark:border-white/10",
|
||||
button: "border border-button-light-border dark:border-button-dark-border", // No shadows for flat design
|
||||
"idp-button": "border border-button-light-border dark:border-button-dark-border", // No shadows for flat design
|
||||
typography: "font-normal",
|
||||
background: "bg-background-light-500 dark:bg-background-dark-500", // Same as usual background
|
||||
},
|
||||
material: {
|
||||
card: "bg-background-light-400 dark:bg-background-dark-500 shadow-sm border-0",
|
||||
button: "shadow hover:shadow-xl active:shadow-xl", // Material shadows for buttons
|
||||
"idp-button":
|
||||
"!bg-background-[#00000020] !dark:bg-background-[#ffffff50] transition shadow shadow-md hover:shadow-lg active:shadow-xl", // Material shadows for IDP buttons
|
||||
typography: "font-medium",
|
||||
background: "bg-background-light-400 dark:bg-background-dark-500", // Current system (shade 400)
|
||||
},
|
||||
glass: {
|
||||
card: "backdrop-blur-md bg-white/10 dark:bg-black/10 border border-white/20 dark:border-white/10 shadow-xl",
|
||||
button:
|
||||
"backdrop-blur-sm bg-white/20 dark:bg-black/20 border border-white/30 dark:border-white/20 shadow-lg hover:shadow-xl", // Glass effect for buttons
|
||||
"idp-button":
|
||||
"backdrop-blur-sm bg-white/20 dark:bg-black/20 border border-white/30 dark:border-white/20 shadow-lg hover:shadow-xl", // Glass effect for IDP buttons
|
||||
typography: "font-medium",
|
||||
background: "bg-transparent", // Transparent background to show blur effect
|
||||
},
|
||||
} as const;
|
||||
@@ -0,0 +1,49 @@
|
||||
"use client";
|
||||
|
||||
import { clsx } from "clsx";
|
||||
|
||||
// Generic theme-aware properties interface (kept for backward compatibility)
|
||||
export interface ThemeableProps {
|
||||
roundness?: string;
|
||||
spacing?: string;
|
||||
padding?: string;
|
||||
typography?: string;
|
||||
}
|
||||
|
||||
// Utility for conditional roundness classes (avoids Tailwind conflicts)
|
||||
export function getRoundnessClasses(roundness: string, baseClasses: string = "") {
|
||||
return clsx(baseClasses, {
|
||||
"rounded-none": roundness === "rounded-none",
|
||||
"rounded-md": roundness === "rounded-md",
|
||||
"rounded-full": roundness === "rounded-full",
|
||||
"rounded-lg": roundness === "rounded-lg",
|
||||
"rounded-3xl": roundness === "rounded-3xl",
|
||||
});
|
||||
}
|
||||
|
||||
// Utility for button-specific roundness
|
||||
export function getButtonRoundnessClasses(roundness: string) {
|
||||
return clsx({
|
||||
"rounded-none": roundness === "rounded-none",
|
||||
"rounded-md": roundness === "rounded-md",
|
||||
"rounded-full": roundness === "rounded-full",
|
||||
});
|
||||
}
|
||||
|
||||
// Utility for input-specific roundness
|
||||
export function getInputRoundnessClasses(roundness: string) {
|
||||
return clsx({
|
||||
"rounded-none": roundness === "rounded-none",
|
||||
"rounded-md": roundness === "rounded-md",
|
||||
"rounded-full": roundness === "rounded-full",
|
||||
});
|
||||
}
|
||||
|
||||
// Utility for card-specific roundness
|
||||
export function getCardRoundnessClasses(roundness: string) {
|
||||
return clsx({
|
||||
"rounded-none": roundness === "rounded-none",
|
||||
"rounded-lg": roundness === "rounded-lg",
|
||||
"rounded-3xl": roundness === "rounded-3xl",
|
||||
});
|
||||
}
|
||||
@@ -448,7 +448,7 @@ export async function createInviteCode({
|
||||
userId: string;
|
||||
}) {
|
||||
let medium = create(SendInviteCodeSchema, {
|
||||
applicationName: "Typescript Login",
|
||||
applicationName: process.env.NEXT_PUBLIC_APPLICATION_NAME || "Zitadel Login",
|
||||
});
|
||||
|
||||
medium = {
|
||||
@@ -1210,9 +1210,9 @@ export function createServerTransport(token: string, baseUrl: string) {
|
||||
(next) => {
|
||||
return (req) => {
|
||||
process.env.CUSTOM_REQUEST_HEADERS!.split(",").forEach((header) => {
|
||||
const kv = header.split(":");
|
||||
if (kv.length === 2) {
|
||||
req.header.set(kv[0].trim(), kv[1].trim());
|
||||
const kv = header.indexOf(":");
|
||||
if (kv > 0) {
|
||||
req.header.set(header.slice(0, kv).trim(), header.slice(kv + 1).trim());
|
||||
} else {
|
||||
console.warn(`Skipping malformed header: ${header}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user