feat/fix: improve responsive constraints & add live ThemeListener

This commit is contained in:
AI Studio 2026-05-15 18:41:57 +00:00
parent 5f4d715628
commit b3648c5bb4
6 changed files with 128 additions and 2 deletions

View file

@ -1,3 +1,4 @@
import { ThemeListener } from './components/layout/ThemeListener';
import React from 'react';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import { Navbar } from './components/layout/Navbar';
@ -16,8 +17,9 @@ import { Contact } from './pages/Contact';
export default function App() {
return (
<Router>
<ThemeListener />
<Analytics />
<div className="flex min-h-screen flex-col font-sans text-gray-800 antialiased selection:bg-brand-gold selection:text-white">
<div className="overflow-x-hidden flex min-h-screen flex-col font-sans text-gray-800 antialiased selection:bg-brand-gold selection:text-white">
<Navbar />
<div className="flex-1">
<Routes>

View file

@ -0,0 +1,50 @@
import { useEffect } from 'react';
export function ThemeListener() {
useEffect(() => {
const handleMessage = (event: MessageEvent) => {
// Allow messages from any origin since preview is generic
if (event.data?.type === 'UPDATE_APPEARANCE') {
const settings = event.data.settings;
if (!settings) return;
const root = document.documentElement;
// Update Primary Color
if (settings.primaryColor) {
root.style.setProperty('--color-brand-primary', settings.primaryColor);
root.style.setProperty('--color-brand-blue', settings.primaryColor);
root.style.setProperty('--color-brand-gold', settings.primaryColor);
}
// Update Background Color
if (settings.backgroundColor) {
root.style.setProperty('--color-brand-bg', settings.backgroundColor);
document.body.style.backgroundColor = settings.backgroundColor;
}
// Update Font Family
if (settings.fontFamily) {
const fontLink = document.getElementById('dynamic-font') as HTMLLinkElement;
const fontName = settings.fontFamily.replace(/ /g, '+');
if (fontLink) {
fontLink.href = `https://fonts.googleapis.com/css2?family=${fontName}:wght@300;400;500;600;700&display=swap`;
} else {
const link = document.createElement('link');
link.id = 'dynamic-font';
link.rel = 'stylesheet';
link.href = `https://fonts.googleapis.com/css2?family=${fontName}:wght@300;400;500;600;700&display=swap`;
document.head.appendChild(link);
}
root.style.setProperty('--font-sans', `"${settings.fontFamily}", sans-serif`);
document.body.style.fontFamily = `"${settings.fontFamily}", sans-serif`;
}
}
};
window.addEventListener('message', handleMessage);
return () => window.removeEventListener('message', handleMessage);
}, []);
return null;
}

View file

@ -35,3 +35,14 @@ body {
::-webkit-scrollbar-thumb:hover {
background: #D4AF37;
}
html, body {
overflow-x: hidden;
width: 100%;
max-width: 100vw;
}
img {
max-width: 100%;
}

View file

@ -1,3 +1,4 @@
import { ThemeListener } from './components/layout/ThemeListener';
import React from 'react';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import { ScrollToTop } from './components/ScrollToTop';
@ -17,9 +18,10 @@ import { Contact } from './pages/Contact';
export default function App() {
return (
<Router>
<ThemeListener />
<ScrollToTop />
<Analytics />
<div className="flex min-h-screen flex-col font-sans text-gray-800 antialiased selection:bg-brand-gold selection:text-white">
<div className="overflow-x-hidden flex min-h-screen flex-col font-sans text-gray-800 antialiased selection:bg-brand-gold selection:text-white">
<Navbar />
<div className="flex-1">
<Routes>

View file

@ -0,0 +1,50 @@
import { useEffect } from 'react';
export function ThemeListener() {
useEffect(() => {
const handleMessage = (event: MessageEvent) => {
// Allow messages from any origin since preview is generic
if (event.data?.type === 'UPDATE_APPEARANCE') {
const settings = event.data.settings;
if (!settings) return;
const root = document.documentElement;
// Update Primary Color
if (settings.primaryColor) {
root.style.setProperty('--color-brand-primary', settings.primaryColor);
root.style.setProperty('--color-brand-blue', settings.primaryColor);
root.style.setProperty('--color-brand-gold', settings.primaryColor);
}
// Update Background Color
if (settings.backgroundColor) {
root.style.setProperty('--color-brand-bg', settings.backgroundColor);
document.body.style.backgroundColor = settings.backgroundColor;
}
// Update Font Family
if (settings.fontFamily) {
const fontLink = document.getElementById('dynamic-font') as HTMLLinkElement;
const fontName = settings.fontFamily.replace(/ /g, '+');
if (fontLink) {
fontLink.href = `https://fonts.googleapis.com/css2?family=${fontName}:wght@300;400;500;600;700&display=swap`;
} else {
const link = document.createElement('link');
link.id = 'dynamic-font';
link.rel = 'stylesheet';
link.href = `https://fonts.googleapis.com/css2?family=${fontName}:wght@300;400;500;600;700&display=swap`;
document.head.appendChild(link);
}
root.style.setProperty('--font-sans', `"${settings.fontFamily}", sans-serif`);
document.body.style.fontFamily = `"${settings.fontFamily}", sans-serif`;
}
}
};
window.addEventListener('message', handleMessage);
return () => window.removeEventListener('message', handleMessage);
}, []);
return null;
}

View file

@ -35,3 +35,14 @@ body {
::-webkit-scrollbar-thumb:hover {
background: #DDA7A5;
}
html, body {
overflow-x: hidden;
width: 100%;
max-width: 100vw;
}
img {
max-width: 100%;
}