2026-04-05 18:31:16 -07:00
|
|
|
import React, { CSSProperties } from 'react';
|
|
|
|
|
import { useNode, UserComponent } from '@craftjs/core';
|
|
|
|
|
import { cssPropsToString } from '../../utils/style-helpers';
|
2026-05-25 12:43:28 -07:00
|
|
|
import { CtaButton, CtasEditor, normalizeCtas, ctaInlineStyle, ctasToHtml } from './_cta-helpers';
|
|
|
|
|
import { AnchorIdField } from '../../ui/AnchorIdField';
|
2026-07-12 11:49:10 -07:00
|
|
|
import { escapeHtml, escapeAttr } from '../../utils/escape';
|
2026-04-05 18:31:16 -07:00
|
|
|
|
|
|
|
|
interface CTASectionProps {
|
|
|
|
|
heading?: string;
|
|
|
|
|
description?: string;
|
2026-05-25 12:43:28 -07:00
|
|
|
ctas?: CtaButton[];
|
|
|
|
|
/** Legacy props kept for backward compat with saved projects. */
|
2026-04-05 18:31:16 -07:00
|
|
|
buttonText?: string;
|
|
|
|
|
buttonHref?: string;
|
|
|
|
|
gradient?: string;
|
2026-05-25 12:43:28 -07:00
|
|
|
anchorId?: string;
|
2026-04-05 18:31:16 -07:00
|
|
|
style?: CSSProperties;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const defaultGradient = 'linear-gradient(135deg, #2563eb 0%, #7c3aed 100%)';
|
|
|
|
|
|
|
|
|
|
export const CTASection: UserComponent<CTASectionProps> = ({
|
|
|
|
|
heading = 'Ready to Get Started?',
|
|
|
|
|
description = 'Join thousands of satisfied users and start building your dream website today.',
|
2026-05-25 12:43:28 -07:00
|
|
|
ctas,
|
|
|
|
|
buttonText,
|
|
|
|
|
buttonHref,
|
2026-04-05 18:31:16 -07:00
|
|
|
gradient = defaultGradient,
|
2026-05-25 12:43:28 -07:00
|
|
|
anchorId,
|
2026-04-05 18:31:16 -07:00
|
|
|
style = {},
|
|
|
|
|
}) => {
|
|
|
|
|
const {
|
|
|
|
|
connectors: { connect, drag },
|
|
|
|
|
selected,
|
|
|
|
|
} = useNode((node) => ({
|
|
|
|
|
selected: node.events.selected,
|
|
|
|
|
}));
|
|
|
|
|
|
2026-05-25 12:43:28 -07:00
|
|
|
const effectiveCtas = normalizeCtas({ ctas, buttonText, buttonHref });
|
|
|
|
|
const ctaDefaults = { primaryBg: '#ffffff', primaryText: '#18181b', outlineText: '#ffffff' };
|
|
|
|
|
|
2026-04-05 18:31:16 -07:00
|
|
|
return (
|
|
|
|
|
<section
|
|
|
|
|
ref={(ref: HTMLElement | null): void => { if (ref) connect(drag(ref)); }}
|
2026-05-25 12:43:28 -07:00
|
|
|
id={anchorId || undefined}
|
2026-04-05 18:31:16 -07:00
|
|
|
style={{
|
|
|
|
|
background: gradient,
|
|
|
|
|
padding: '80px 20px',
|
|
|
|
|
textAlign: 'center',
|
|
|
|
|
outline: selected ? '2px solid #3b82f6' : 'none',
|
|
|
|
|
...style,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div style={{ maxWidth: '700px', margin: '0 auto' }}>
|
|
|
|
|
<h2 style={{ fontSize: '36px', fontWeight: '700', color: '#ffffff', marginBottom: '12px' }}>
|
|
|
|
|
{heading}
|
|
|
|
|
</h2>
|
|
|
|
|
<p style={{ fontSize: '18px', color: 'rgba(255,255,255,0.85)', marginBottom: '28px', lineHeight: '1.6' }}>
|
|
|
|
|
{description}
|
|
|
|
|
</p>
|
2026-05-25 12:43:28 -07:00
|
|
|
<div style={{ display: 'flex', gap: '12px', justifyContent: 'center', flexWrap: 'wrap' }}>
|
|
|
|
|
{effectiveCtas.map((cta, i) => (
|
|
|
|
|
<a key={i} href={cta.href || '#'} onClick={(e) => e.preventDefault()}
|
|
|
|
|
style={ctaInlineStyle(cta, ctaDefaults)}>
|
|
|
|
|
{cta.text}
|
|
|
|
|
</a>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
2026-04-05 18:31:16 -07:00
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* ---------- Settings panel ---------- */
|
|
|
|
|
|
|
|
|
|
const CTASectionSettings: React.FC = () => {
|
|
|
|
|
const { actions: { setProp }, props } = useNode((node) => ({
|
|
|
|
|
props: node.data.props as CTASectionProps,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
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%)' },
|
|
|
|
|
];
|
|
|
|
|
|
2026-05-25 12:43:28 -07:00
|
|
|
const effectiveCtas = normalizeCtas(props);
|
|
|
|
|
|
2026-04-05 18:31:16 -07:00
|
|
|
return (
|
|
|
|
|
<div style={{ padding: '12px', display: 'flex', flexDirection: 'column', gap: '14px' }}>
|
2026-05-25 12:43:28 -07:00
|
|
|
<AnchorIdField />
|
2026-04-05 18:31:16 -07:00
|
|
|
<div>
|
|
|
|
|
<label style={{ fontSize: 11, color: '#a1a1aa', display: 'block', marginBottom: 6 }}>Heading</label>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
value={props.heading || ''}
|
|
|
|
|
onChange={(e) => setProp((p: CTASectionProps) => { p.heading = e.target.value; })}
|
|
|
|
|
style={{ width: '100%', padding: '4px 8px', background: '#27272a', color: '#e4e4e7', border: '1px solid #3f3f46', borderRadius: 4, fontSize: 12 }}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<label style={{ fontSize: 11, color: '#a1a1aa', display: 'block', marginBottom: 6 }}>Description</label>
|
|
|
|
|
<textarea
|
|
|
|
|
value={props.description || ''}
|
|
|
|
|
onChange={(e) => setProp((p: CTASectionProps) => { p.description = e.target.value; })}
|
|
|
|
|
rows={2}
|
|
|
|
|
style={{ width: '100%', padding: '4px 8px', background: '#27272a', color: '#e4e4e7', border: '1px solid #3f3f46', borderRadius: 4, fontSize: 12, resize: 'vertical' }}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-05-25 12:43:28 -07:00
|
|
|
<CtasEditor
|
|
|
|
|
ctas={effectiveCtas}
|
|
|
|
|
onChange={(next) => setProp((p: CTASectionProps) => {
|
|
|
|
|
p.ctas = next;
|
|
|
|
|
p.buttonText = undefined;
|
|
|
|
|
p.buttonHref = undefined;
|
|
|
|
|
})}
|
|
|
|
|
/>
|
2026-04-05 18:31:16 -07:00
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<label style={{ fontSize: 11, color: '#a1a1aa', display: 'block', marginBottom: 6 }}>Gradient</label>
|
|
|
|
|
<div style={{ display: 'flex', gap: 4, flexWrap: 'wrap' }}>
|
|
|
|
|
{gradientPresets.map((g) => (
|
|
|
|
|
<button
|
|
|
|
|
key={g.label}
|
|
|
|
|
onClick={() => setProp((p: CTASectionProps) => { p.gradient = g.value; })}
|
|
|
|
|
title={g.label}
|
|
|
|
|
style={{
|
|
|
|
|
width: 32, height: 24, borderRadius: 4, border: '1px solid #3f3f46',
|
|
|
|
|
background: g.value, cursor: 'pointer',
|
|
|
|
|
outline: props.gradient === g.value ? '2px solid #3b82f6' : 'none',
|
|
|
|
|
outlineOffset: 1,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* ---------- Craft config ---------- */
|
|
|
|
|
|
|
|
|
|
CTASection.craft = {
|
|
|
|
|
displayName: 'CTA Section',
|
|
|
|
|
props: {
|
|
|
|
|
heading: 'Ready to Get Started?',
|
|
|
|
|
description: 'Join thousands of satisfied users and start building your dream website today.',
|
2026-05-25 12:43:28 -07:00
|
|
|
ctas: [
|
|
|
|
|
{ text: 'Start Free Trial', href: '#', variant: 'primary' },
|
|
|
|
|
] as CtaButton[],
|
2026-04-05 18:31:16 -07:00
|
|
|
gradient: defaultGradient,
|
2026-05-25 12:43:28 -07:00
|
|
|
anchorId: '',
|
2026-04-05 18:31:16 -07:00
|
|
|
style: {},
|
|
|
|
|
},
|
|
|
|
|
rules: {
|
|
|
|
|
canDrag: () => true,
|
|
|
|
|
canMoveIn: () => false,
|
|
|
|
|
canMoveOut: () => true,
|
|
|
|
|
},
|
|
|
|
|
related: {
|
|
|
|
|
settings: CTASectionSettings,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* ---------- HTML export ---------- */
|
|
|
|
|
|
|
|
|
|
(CTASection as any).toHtml = (props: CTASectionProps, _childrenHtml: string) => {
|
|
|
|
|
const sectionStyle = cssPropsToString({
|
|
|
|
|
background: props.gradient || defaultGradient,
|
|
|
|
|
padding: '80px 20px',
|
|
|
|
|
textAlign: 'center',
|
|
|
|
|
...props.style,
|
|
|
|
|
});
|
2026-05-25 12:43:28 -07:00
|
|
|
const ctas = normalizeCtas(props);
|
|
|
|
|
const buttonsHtml = ctasToHtml(ctas, { primaryBg: '#ffffff', primaryText: '#18181b', outlineText: '#ffffff' });
|
2026-07-12 11:49:10 -07:00
|
|
|
const idAttr = props.anchorId ? ` id="${escapeAttr(props.anchorId)}"` : '';
|
2026-04-05 18:31:16 -07:00
|
|
|
return {
|
2026-05-25 12:43:28 -07:00
|
|
|
html: `<section${idAttr}${sectionStyle ? ` style="${sectionStyle}"` : ''}>
|
2026-04-05 18:31:16 -07:00
|
|
|
<div style="max-width:700px;margin:0 auto">
|
2026-07-12 11:49:10 -07:00
|
|
|
<h2 style="font-size:36px;font-weight:700;color:#ffffff;margin-bottom:12px">${escapeHtml(props.heading || '')}</h2>
|
|
|
|
|
<p style="font-size:18px;color:rgba(255,255,255,0.85);margin-bottom:28px;line-height:1.6">${escapeHtml(props.description || '')}</p>
|
2026-05-25 12:43:28 -07:00
|
|
|
<div style="display:flex;gap:12px;justify-content:center;flex-wrap:wrap">${buttonsHtml}</div>
|
2026-04-05 18:31:16 -07:00
|
|
|
</div>
|
|
|
|
|
</section>`,
|
|
|
|
|
};
|
|
|
|
|
};
|