|
4 | 4 | * Supports glassmorphism, custom backgrounds, and automatic text color adjustment. |
5 | 5 | */ |
6 | 6 |
|
7 | | -import { Icon } from "../../shared/components/Icon.jsx"; |
| 7 | +import {Icon} from "../../shared/components/Icon.jsx"; |
8 | 8 |
|
9 | 9 | // Simple markdown renderer |
10 | 10 | function renderText(text) { |
11 | | - if (!text) return ""; |
12 | | - return String(text) |
13 | | - .replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>") |
14 | | - .replace(/\*(.*?)\*/g, "<em>$1</em>") |
15 | | - .replace(/`(.*?)`/g, "<code>$1</code>") |
16 | | - .replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>'); |
| 11 | + if (!text) return ""; |
| 12 | + return String(text) |
| 13 | + .replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>") |
| 14 | + .replace(/\*(.*?)\*/g, "<em>$1</em>") |
| 15 | + .replace(/`(.*?)`/g, "<code>$1</code>") |
| 16 | + .replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>'); |
17 | 17 | } |
18 | 18 |
|
19 | | -export const CtaCardBlock = ({ content, design, id, button_icon_svg }) => { |
20 | | - const card = design?.card || {}; |
21 | | - const cardClass = card.css_class || ""; |
22 | | - const cardStyle = card.css_style || ""; |
23 | | - |
24 | | - // Overlay Opacity Logic |
25 | | - let overlayOpacity = 0.15; |
26 | | - if (card.overlay_opacity !== undefined) { |
27 | | - const val = parseFloat(card.overlay_opacity); |
28 | | - if (!isNaN(val)) overlayOpacity = Math.max(0, Math.min(1, val)); |
29 | | - } |
30 | | - |
31 | | - // Text Color Logic |
32 | | - let textColorMode = "auto"; |
33 | | - if (["light", "dark", "auto"].includes(card.text_color?.toLowerCase())) { |
34 | | - textColorMode = card.text_color.toLowerCase(); |
35 | | - } |
36 | | - |
37 | | - let textClasses = "text-gray-900 dark:text-white"; |
38 | | - let buttonClasses = "text-gray-900 dark:text-gray-100"; |
39 | | - |
40 | | - // Auto-detect based on background gradient |
41 | | - const bg = design?.background || {}; |
42 | | - const gradientStart = bg.gradient?.start || ""; |
43 | | - const isDarkBg = ["primary-7", "primary-8", "primary-9", "secondary-7", "secondary-8", "secondary-9"].some(p => gradientStart.startsWith(p)); |
44 | | - |
45 | | - if (textColorMode === "light") { |
46 | | - textClasses = "text-white"; |
47 | | - buttonClasses = "text-gray-900 dark:text-white"; |
48 | | - } else if (textColorMode === "dark") { |
49 | | - textClasses = "text-gray-900 dark:text-white"; |
50 | | - buttonClasses = "text-gray-900 dark:text-white"; |
51 | | - } else if (isDarkBg) { |
52 | | - textClasses = "text-white"; |
53 | | - buttonClasses = "text-gray-900"; |
54 | | - } |
55 | | - |
56 | | - // Button Logic |
57 | | - const button = content?.button || {}; |
58 | | - const buttonText = button.text?.trim(); |
59 | | - const buttonUrl = button.url?.trim(); |
60 | | - const showButton = !!(buttonText && buttonUrl); |
61 | | - |
62 | | - let isExternal = false; |
63 | | - let isNewTab = button.new_tab === true; |
64 | | - if (buttonUrl) { |
65 | | - try { |
66 | | - const url = new URL(buttonUrl, window.location.origin); |
67 | | - isExternal = url.origin !== window.location.origin; |
68 | | - } catch { |
69 | | - isExternal = /^https?:\/\//.test(buttonUrl); |
70 | | - } |
71 | | - if (buttonUrl.endsWith(".pdf")) isNewTab = true; |
72 | | - if (isExternal) isNewTab = true; |
| 19 | +export const CtaCardBlock = ({content, design, _id, button_icon_svg}) => { |
| 20 | + const card = design?.card || {}; |
| 21 | + const cardClass = card.css_class || ""; |
| 22 | + const cardStyle = card.css_style || ""; |
| 23 | + |
| 24 | + // Overlay Opacity Logic |
| 25 | + let overlayOpacity = 0.15; |
| 26 | + if (card.overlay_opacity !== undefined) { |
| 27 | + const val = parseFloat(card.overlay_opacity); |
| 28 | + if (!Number.isNaN(val)) overlayOpacity = Math.max(0, Math.min(1, val)); |
| 29 | + } |
| 30 | + |
| 31 | + // Text Color Logic |
| 32 | + let textColorMode = "auto"; |
| 33 | + if (["light", "dark", "auto"].includes(card.text_color?.toLowerCase())) { |
| 34 | + textColorMode = card.text_color.toLowerCase(); |
| 35 | + } |
| 36 | + |
| 37 | + let textClasses = "text-gray-900 dark:text-white"; |
| 38 | + let buttonClasses = "text-gray-900 dark:text-gray-100"; |
| 39 | + |
| 40 | + // Auto-detect based on background gradient |
| 41 | + const bg = design?.background || {}; |
| 42 | + const gradientStart = bg.gradient?.start || ""; |
| 43 | + const isDarkBg = ["primary-7", "primary-8", "primary-9", "secondary-7", "secondary-8", "secondary-9"].some((p) => gradientStart.startsWith(p)); |
| 44 | + |
| 45 | + if (textColorMode === "light") { |
| 46 | + textClasses = "text-white"; |
| 47 | + buttonClasses = "text-gray-900 dark:text-white"; |
| 48 | + } else if (textColorMode === "dark") { |
| 49 | + textClasses = "text-gray-900 dark:text-white"; |
| 50 | + buttonClasses = "text-gray-900 dark:text-white"; |
| 51 | + } else if (isDarkBg) { |
| 52 | + textClasses = "text-white"; |
| 53 | + buttonClasses = "text-gray-900"; |
| 54 | + } |
| 55 | + |
| 56 | + // Button Logic |
| 57 | + const button = content?.button || {}; |
| 58 | + const buttonText = button.text?.trim(); |
| 59 | + const buttonUrl = button.url?.trim(); |
| 60 | + const showButton = !!(buttonText && buttonUrl); |
| 61 | + |
| 62 | + let isExternal = false; |
| 63 | + let isNewTab = button.new_tab === true; |
| 64 | + if (buttonUrl) { |
| 65 | + try { |
| 66 | + const url = new URL(buttonUrl, window.location.origin); |
| 67 | + isExternal = url.origin !== window.location.origin; |
| 68 | + } catch { |
| 69 | + isExternal = /^https?:\/\//.test(buttonUrl); |
73 | 70 | } |
74 | | - |
75 | | - const defaultBgClass = "bg-gradient-to-br from-primary-500/90 via-primary-600/95 to-primary-700/90"; |
76 | | - const finalCardClass = cardClass || defaultBgClass; |
77 | | - |
78 | | - const style = `--glassmorphism-opacity: ${overlayOpacity}; ${cardStyle}`; |
79 | | - |
80 | | - return ( |
| 71 | + if (buttonUrl.endsWith(".pdf")) isNewTab = true; |
| 72 | + if (isExternal) isNewTab = true; |
| 73 | + } |
| 74 | + |
| 75 | + const defaultBgClass = "bg-gradient-to-br from-primary-500/90 via-primary-600/95 to-primary-700/90"; |
| 76 | + const finalCardClass = cardClass || defaultBgClass; |
| 77 | + |
| 78 | + const style = `--glassmorphism-opacity: ${overlayOpacity}; ${cardStyle}`; |
| 79 | + |
| 80 | + return ( |
| 81 | + <div |
| 82 | + class={`relative overflow-hidden ${finalCardClass} p-8 sm:p-12 lg:p-16 xl:p-20 mx-auto max-w-6xl rounded-3xl shadow-2xl flex flex-col items-center text-center`} |
| 83 | + style={style} |
| 84 | + > |
| 85 | + {/* Title */} |
| 86 | + {content.title && ( |
| 87 | + <h2 |
| 88 | + class={`${textClasses} text-4xl sm:text-5xl lg:text-6xl xl:text-7xl font-bold tracking-tight leading-tight`} |
| 89 | + dangerouslySetInnerHTML={{__html: renderText(content.title)}} |
| 90 | + /> |
| 91 | + )} |
| 92 | + |
| 93 | + {/* Text */} |
| 94 | + {content.text && ( |
81 | 95 | <div |
82 | | - class={`relative overflow-hidden ${finalCardClass} p-8 sm:p-12 lg:p-16 xl:p-20 mx-auto max-w-6xl rounded-3xl shadow-2xl flex flex-col items-center text-center`} |
83 | | - style={style} |
84 | | - > |
85 | | - {/* Title */} |
86 | | - {content.title && ( |
87 | | - <h2 |
88 | | - class={`${textClasses} text-4xl sm:text-5xl lg:text-6xl xl:text-7xl font-bold tracking-tight leading-tight`} |
89 | | - dangerouslySetInnerHTML={{ __html: renderText(content.title) }} |
90 | | - /> |
| 96 | + class={`${textClasses}/80 mt-6 text-lg sm:text-xl lg:text-2xl max-w-3xl leading-relaxed font-light`} |
| 97 | + dangerouslySetInnerHTML={{__html: renderText(content.text)}} |
| 98 | + /> |
| 99 | + )} |
| 100 | + |
| 101 | + {/* Button */} |
| 102 | + {showButton && ( |
| 103 | + <div class="flex mt-10"> |
| 104 | + <a |
| 105 | + href={buttonUrl} |
| 106 | + target={isNewTab ? "_blank" : undefined} |
| 107 | + rel={isNewTab ? "noopener" : undefined} |
| 108 | + class={`group relative inline-flex items-center gap-3 px-8 py-4 text-lg font-semibold ${buttonClasses} transition-all duration-300 ease-out hover:scale-105 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-gray-500/50 dark:focus-visible:ring-white/50 focus-visible:ring-offset-2 focus-visible:ring-offset-transparent`} |
| 109 | + > |
| 110 | + {/* Glassmorphism Background */} |
| 111 | + <div class="absolute inset-0 bg-white/95 dark:bg-gray-900/95 backdrop-blur-md rounded-2xl ring-1 ring-gray-200/30 dark:ring-white/30 shadow-lg group-hover:bg-white dark:group-hover:bg-gray-800 group-hover:ring-gray-300/50 dark:group-hover:ring-white/50 group-hover:shadow-2xl transition-all duration-300"></div> |
| 112 | + |
| 113 | + {/* Button Content */} |
| 114 | + <span class="relative z-10">{buttonText}</span> |
| 115 | + {button_icon_svg && ( |
| 116 | + <span class="relative z-10 transition-transform duration-300 group-hover:translate-x-1"> |
| 117 | + <Icon svg={button_icon_svg} attributes={{style: "height: 1.25em", class: "inline-block"}} /> |
| 118 | + </span> |
91 | 119 | )} |
92 | 120 |
|
93 | | - {/* Text */} |
94 | | - {content.text && ( |
95 | | - <div |
96 | | - class={`${textClasses}/80 mt-6 text-lg sm:text-xl lg:text-2xl max-w-3xl leading-relaxed font-light`} |
97 | | - dangerouslySetInnerHTML={{ __html: renderText(content.text) }} |
98 | | - /> |
99 | | - )} |
100 | | - |
101 | | - {/* Button */} |
102 | | - {showButton && ( |
103 | | - <div class="flex mt-10"> |
104 | | - <a |
105 | | - href={buttonUrl} |
106 | | - target={isNewTab ? "_blank" : undefined} |
107 | | - rel={isNewTab ? "noopener" : undefined} |
108 | | - class={`group relative inline-flex items-center gap-3 px-8 py-4 text-lg font-semibold ${buttonClasses} transition-all duration-300 ease-out hover:scale-105 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-gray-500/50 dark:focus-visible:ring-white/50 focus-visible:ring-offset-2 focus-visible:ring-offset-transparent`} |
109 | | - > |
110 | | - {/* Glassmorphism Background */} |
111 | | - <div class="absolute inset-0 bg-white/95 dark:bg-gray-900/95 backdrop-blur-md rounded-2xl ring-1 ring-gray-200/30 dark:ring-white/30 shadow-lg group-hover:bg-white dark:group-hover:bg-gray-800 group-hover:ring-gray-300/50 dark:group-hover:ring-white/50 group-hover:shadow-2xl transition-all duration-300"></div> |
112 | | - |
113 | | - {/* Button Content */} |
114 | | - <span class="relative z-10">{buttonText}</span> |
115 | | - {button_icon_svg && ( |
116 | | - <span class="relative z-10 transition-transform duration-300 group-hover:translate-x-1"> |
117 | | - <Icon svg={button_icon_svg} attributes={{ style: "height: 1.25em", class: "inline-block" }} /> |
118 | | - </span> |
119 | | - )} |
120 | | - |
121 | | - {/* Glow Effect */} |
122 | | - <div class="absolute inset-0 bg-white/20 dark:bg-white/10 rounded-2xl opacity-0 group-hover:opacity-100 transition-opacity duration-300 blur-xl"></div> |
123 | | - </a> |
124 | | - </div> |
125 | | - )} |
| 121 | + {/* Glow Effect */} |
| 122 | + <div class="absolute inset-0 bg-white/20 dark:bg-white/10 rounded-2xl opacity-0 group-hover:opacity-100 transition-opacity duration-300 blur-xl"></div> |
| 123 | + </a> |
126 | 124 | </div> |
127 | | - ); |
| 125 | + )} |
| 126 | + </div> |
| 127 | + ); |
128 | 128 | }; |
0 commit comments