import React, { CSSProperties } from 'react'; import { useNode, UserComponent } from '@craftjs/core'; import { cssPropsToString } from '../../utils/style-helpers'; interface FormButtonProps { text?: string; style?: CSSProperties; } export const FormButton: UserComponent = ({ text = 'Submit', style = {}, }) => { const { connectors: { connect, drag }, selected, } = useNode((node) => ({ selected: node.events.selected, })); return ( ); }; /* ---------- Settings panel ---------- */ const FormButtonSettings: React.FC = () => { const { actions: { setProp }, props } = useNode((node) => ({ props: node.data.props as FormButtonProps, })); const colorPresets = [ { bg: '#3b82f6', color: '#ffffff', label: 'Blue' }, { bg: '#10b981', color: '#ffffff', label: 'Green' }, { bg: '#ef4444', color: '#ffffff', label: 'Red' }, { bg: '#f59e0b', color: '#18181b', label: 'Amber' }, { bg: '#8b5cf6', color: '#ffffff', label: 'Purple' }, { bg: '#18181b', color: '#ffffff', label: 'Dark' }, ]; const radiusPresets = ['0px', '4px', '6px', '8px', '9999px']; const widthPresets = ['auto', '100%']; return (
setProp((p: FormButtonProps) => { p.text = e.target.value; })} style={{ width: '100%', padding: '4px 8px', background: '#27272a', color: '#e4e4e7', border: '1px solid #3f3f46', borderRadius: 4, fontSize: 12 }} />
{colorPresets.map((preset) => (
{radiusPresets.map((r) => ( ))}
{widthPresets.map((w) => ( ))}
); }; /* ---------- Craft config ---------- */ FormButton.craft = { displayName: 'Submit Button', props: { text: 'Submit', style: { backgroundColor: '#3b82f6', color: '#ffffff', padding: '12px 32px', borderRadius: '6px', fontWeight: '600', fontSize: '16px', border: 'none', }, }, rules: { canDrag: () => true, canMoveIn: () => false, canMoveOut: () => true, }, related: { settings: FormButtonSettings, }, }; /* ---------- HTML export ---------- */ (FormButton as any).toHtml = (props: FormButtonProps, _childrenHtml: string) => { const styleStr = cssPropsToString({ padding: '12px 32px', border: 'none', cursor: 'pointer', ...props.style, }); const escapedText = (props.text || 'Submit').replace(//g, '>'); return { html: ``, }; };