import React, { CSSProperties } from 'react'; import { useNode, UserComponent } from '@craftjs/core'; import { cssPropsToString } from '../../utils/style-helpers'; interface CallToActionProps { heading?: string; description?: string; buttonText?: string; buttonHref?: string; secondaryButtonText?: string; secondaryButtonHref?: string; bgType?: 'color' | 'gradient' | 'image'; bgValue?: string; overlayColor?: string; overlayOpacity?: number; textColor?: string; buttonColor?: string; style?: CSSProperties; } const defaultGradient = 'linear-gradient(135deg, #2563eb 0%, #7c3aed 100%)'; export const CallToAction: UserComponent = ({ heading = 'Ready to Get Started?', description = 'Join thousands of satisfied users and start building your dream website today.', buttonText = 'Get Started', buttonHref = '#', secondaryButtonText = '', secondaryButtonHref = '#', bgType = 'gradient', bgValue = defaultGradient, overlayColor = '#000000', overlayOpacity = 0, textColor = '#ffffff', buttonColor = '#ffffff', style = {}, }) => { const { connectors: { connect, drag }, selected, } = useNode((node) => ({ selected: node.events.selected, })); const bgStyle: CSSProperties = {}; if (bgType === 'color') { bgStyle.backgroundColor = bgValue; } else if (bgType === 'gradient') { bgStyle.background = bgValue; } else if (bgType === 'image') { bgStyle.backgroundImage = `url(${bgValue})`; bgStyle.backgroundSize = 'cover'; bgStyle.backgroundPosition = 'center'; } const isButtonDark = buttonColor === '#ffffff' || buttonColor === '#f8fafc'; const buttonTextColor = isButtonDark ? '#18181b' : '#ffffff'; return (
{ if (ref) connect(drag(ref)); }} style={{ position: 'relative', padding: '80px 20px', textAlign: 'center', outline: selected ? '2px solid #3b82f6' : 'none', ...bgStyle, ...style, }} > {/* Overlay */} {bgType === 'image' && overlayOpacity > 0 && (
)}

{heading}

{description}

e.preventDefault()} style={{ display: 'inline-block', padding: '14px 36px', backgroundColor: buttonColor, color: buttonTextColor, textDecoration: 'none', borderRadius: '8px', fontWeight: '600', fontSize: '16px', }} > {buttonText} {secondaryButtonText && ( e.preventDefault()} style={{ display: 'inline-block', padding: '14px 36px', backgroundColor: 'transparent', color: textColor, textDecoration: 'none', borderRadius: '8px', fontWeight: '600', fontSize: '16px', border: `2px solid ${textColor}`, }} > {secondaryButtonText} )}
); }; /* ---------- Settings panel ---------- */ const CallToActionSettings: React.FC = () => { const { actions: { setProp }, props } = useNode((node) => ({ props: node.data.props as CallToActionProps, })); const gradientPresets = [ { label: 'Blue-Purple', value: 'linear-gradient(135deg, #2563eb 0%, #7c3aed 100%)' }, { label: 'Purple', value: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)' }, { label: 'Teal', value: 'linear-gradient(135deg, #0d9488 0%, #0f766e 100%)' }, { label: 'Sunset', value: 'linear-gradient(135deg, #f97316 0%, #ec4899 100%)' }, { label: 'Dark', value: 'linear-gradient(135deg, #1e293b 0%, #0f172a 100%)' }, { label: 'Ocean', value: 'linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%)' }, ]; const colorPresets = ['#2563eb', '#7c3aed', '#0d9488', '#18181b', '#0f172a', '#1e293b', '#dc2626', '#f97316']; const buttonColorPresets = ['#ffffff', '#18181b', '#3b82f6', '#10b981', '#ef4444', '#8b5cf6', '#f59e0b', '#ec4899']; const textColorPresets = ['#ffffff', '#f8fafc', '#e2e8f0', '#18181b', '#1e293b', '#fef3c7']; const inputStyle: CSSProperties = { width: '100%', padding: '4px 8px', background: '#27272a', color: '#e4e4e7', border: '1px solid #3f3f46', borderRadius: 4, fontSize: 12, }; return (
setProp((p: CallToActionProps) => { p.heading = e.target.value; })} style={inputStyle} />