8bf525c600
SectionTypePanel (Accordion/Tabs/Testimonials/Countdown/NumberCounter/ CTASection/CallToAction/FeaturesGrid), PricingStylePanel, and SocialStylePanel all gain a Spacing & Border section (margin/padding per-side, border, box-shadow, opacity), an Animation section, and a Visibility section, wired to the shared SpacingControl/BorderControl/ AnimationControl/VisibilityControl. PricingTable's per-card colors (cardBg/textColor/subColor/featColor/ checkColor/btnBg/btnColor) were previously hard-coded literals computed from featuredBg inside toHtml -- promoted to real optional props (each falling back to the exact prior literal when unset) and exposed via ColorPickerField in PricingStylePanel. SocialStylePanel now exposes SocialLinks' iconShape/gap (already-built props with no control), plus Icon's bgColor/bgShape/bgSize/link and StarRating's filledColor/emptyColor, which the panel's generic iconBgColor/starColor checks never matched since those aren't Icon's or StarRating's real prop names. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
126 lines
4.0 KiB
TypeScript
126 lines
4.0 KiB
TypeScript
import React, { CSSProperties } from 'react';
|
|
import { useNode, UserComponent } from '@craftjs/core';
|
|
import { cssPropsToString } from '../../utils/style-helpers';
|
|
import { CtaButton, normalizeCtas, ctaInlineStyle, ctasToHtml } from './_cta-helpers';
|
|
import { escapeHtml, escapeAttr } from '../../utils/escape';
|
|
|
|
interface CTASectionProps {
|
|
heading?: string;
|
|
description?: string;
|
|
ctas?: CtaButton[];
|
|
/** Legacy props kept for backward compat with saved projects. */
|
|
buttonText?: string;
|
|
buttonHref?: string;
|
|
gradient?: string;
|
|
anchorId?: string;
|
|
style?: CSSProperties;
|
|
animation?: string;
|
|
animationDelay?: string;
|
|
hideOnDesktop?: boolean;
|
|
hideOnTablet?: boolean;
|
|
hideOnMobile?: boolean;
|
|
}
|
|
|
|
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.',
|
|
ctas,
|
|
buttonText,
|
|
buttonHref,
|
|
gradient = defaultGradient,
|
|
anchorId,
|
|
style = {},
|
|
}) => {
|
|
const {
|
|
connectors: { connect, drag },
|
|
selected,
|
|
} = useNode((node) => ({
|
|
selected: node.events.selected,
|
|
}));
|
|
|
|
const effectiveCtas = normalizeCtas({ ctas, buttonText, buttonHref });
|
|
const ctaDefaults = { primaryBg: '#ffffff', primaryText: '#18181b', outlineText: '#ffffff' };
|
|
|
|
return (
|
|
<section
|
|
ref={(ref: HTMLElement | null): void => { if (ref) connect(drag(ref)); }}
|
|
id={anchorId || undefined}
|
|
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>
|
|
<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>
|
|
</div>
|
|
</section>
|
|
);
|
|
};
|
|
|
|
/* ---------- 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.',
|
|
ctas: [
|
|
{ text: 'Start Free Trial', href: '#', variant: 'primary' },
|
|
] as CtaButton[],
|
|
gradient: defaultGradient,
|
|
anchorId: '',
|
|
style: {},
|
|
animation: '',
|
|
animationDelay: '',
|
|
hideOnDesktop: false,
|
|
hideOnTablet: false,
|
|
hideOnMobile: false,
|
|
},
|
|
rules: {
|
|
canDrag: () => true,
|
|
canMoveIn: () => false,
|
|
canMoveOut: () => true,
|
|
},
|
|
};
|
|
|
|
/* ---------- HTML export ---------- */
|
|
|
|
(CTASection as any).toHtml = (props: CTASectionProps, _childrenHtml: string) => {
|
|
const sectionStyle = cssPropsToString({
|
|
background: props.gradient || defaultGradient,
|
|
padding: '80px 20px',
|
|
textAlign: 'center',
|
|
...props.style,
|
|
});
|
|
const ctas = normalizeCtas(props);
|
|
const buttonsHtml = ctasToHtml(ctas, { primaryBg: '#ffffff', primaryText: '#18181b', outlineText: '#ffffff' });
|
|
const idAttr = props.anchorId ? ` id="${escapeAttr(props.anchorId)}"` : '';
|
|
return {
|
|
html: `<section${idAttr}${sectionStyle ? ` style="${sectionStyle}"` : ''}>
|
|
<div style="max-width:700px;margin:0 auto">
|
|
<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>
|
|
<div style="display:flex;gap:12px;justify-content:center;flex-wrap:wrap">${buttonsHtml}</div>
|
|
</div>
|
|
</section>`,
|
|
};
|
|
};
|