Files
WooNooW/customer-spa/src/lib/sectionStyles.ts

48 lines
1.6 KiB
TypeScript

/**
* Shared utility to compute background styles from section styles.
* Used by all customer SPA section components.
*/
export function getSectionBackground(styles?: Record<string, any>): {
style: React.CSSProperties;
hasOverlay: boolean;
overlayOpacity: number;
backgroundImage?: string;
} {
if (!styles) {
return { style: {}, hasOverlay: false, overlayOpacity: 0 };
}
const bgType = styles.backgroundType || 'solid';
let style: React.CSSProperties = {};
let hasOverlay = false;
let overlayOpacity = 0;
let backgroundImage: string | undefined;
switch (bgType) {
case 'gradient':
style.background = `linear-gradient(${styles.gradientAngle ?? 135}deg, ${styles.gradientFrom || '#9333ea'}, ${styles.gradientTo || '#3b82f6'})`;
break;
case 'image':
if (styles.backgroundImage) {
backgroundImage = styles.backgroundImage;
overlayOpacity = (styles.backgroundOverlay || 0) / 100;
hasOverlay = overlayOpacity > 0;
}
break;
case 'solid':
default:
if (styles.backgroundColor) {
style.backgroundColor = styles.backgroundColor;
}
// Legacy: if backgroundImage exists without explicit type
if (!styles.backgroundType && styles.backgroundImage) {
backgroundImage = styles.backgroundImage;
overlayOpacity = (styles.backgroundOverlay || 0) / 100;
hasOverlay = overlayOpacity > 0;
}
break;
}
return { style, hasOverlay, overlayOpacity, backgroundImage };
}