import React from 'react' import { ColorRow, NumberRow, SelectRow, TextRow, ToggleRow, Segmented, SubHeading, FourSides, inputBase } from './Controls' import InfoTip from './InfoTip' import { getFieldType, Slot } from '../../extensions/registry' // Per-type Field Settings blocks (the reference builder keys; older WP keys are read as fallbacks and cleared with null on write). const isSet = (v) => v !== undefined && v !== null && v !== '' const pick = (...vals) => vals.find(isSet) /* ── Colours per field type (the reference builder F:16468-17240) ───────────────────────────────────────────── */ const COLOR_TYPES = ['text', 'email', 'number', 'tel', 'url', 'textarea', 'address', 'select', 'dropdown', 'checkbox', 'radio', 'submit', 'date', 'time', 'name', 'password'] export function hasFieldColors(type) { const registered = getFieldType(type) if (registered) return Boolean(registered.hasColors) return COLOR_TYPES.includes(type) } export function FieldColors({ field, onUpdate }) { const t = field.type const choice = t === 'checkbox' || t === 'radio' const isSubmit = t === 'submit' const row = (label, key, placeholder, tip) => ( onUpdate({ [key]: v })} onClear={() => onUpdate({ [key]: null })} /> ) return (
Colors {!choice && !isSubmit && row('Input Background', 'inputBackgroundColor', '#F9FAFB')} {!choice && !isSubmit && row('Input Border', 'inputBorderColor', '#D1D5DB')} {isSubmit && row('Background Color', 'backgroundColor', '#4F46E5', 'Background of this submit button.')} {row('Text Color', 'textColor', isSubmit ? '#FFFFFF' : '#000000')} {!choice && !isSubmit && row('Placeholder Text', 'placeholderTextColor', '#9CA3AF')} {!choice && !isSubmit && row('Hover Border', 'hoverBorderColor', '#6B7280')} {!choice && !isSubmit && row('Focus Border', 'focusBorderColor', '#3B82F6')} {(t === 'select' || t === 'dropdown') && row('Selected Value Color', 'selectedValueColor', '#000000', 'Text color of the chosen value in the dropdown.')} {t === 'checkbox' && row('Checkbox Selected', 'checkboxSelectedColor', '#2563EB')} {t === 'checkbox' && row('Checkbox Unselected', 'checkboxUnselectedColor', '#D1D5DB')} {t === 'radio' && row('Radio Selected', 'radioSelectedColor', '#2563EB')} {choice && (field.radioStyle === 'card' || field.checkboxStyle === 'card') && row('Selected Card Border', 'selectedBorderColor', '#2563EB', 'Border of the selected card.')} {isSubmit && ( <> onUpdate({ submitButtonAlignment: v })} /> onUpdate({ submitButtonWidth: v || null })} onReset={() => onUpdate({ submitButtonWidth: null })} tip="0 or empty = fit the text." /> )}
) } /* ── Default value per type (the reference builder F:17530-17958) ───────────────────────────────────────────── */ const NO_DEFAULT = ['submit', 'checkbox', 'radio', 'switch', 'html', 'section', 'image', 'captcha', 'select', 'dropdown', 'grid', 'static-content', 'promo-banner', 'trust-badges', 'faq-accordion', 'countdown-banner', 'name', 'address'] export function hasPlainDefault(type) { const registered = getFieldType(type) if (registered) return registered.hasDefault === true return !NO_DEFAULT.includes(type) && type !== 'date' && type !== 'time' } export function DefaultValueEditor({ field, onUpdate }) { const t = field.type if (t === 'date') { const dv = field.defaultValues && typeof field.defaultValues === 'object' ? field.defaultValues : {} const set = (k, v) => onUpdate({ defaultValues: { ...dv, [k]: v } }) return (
Default Value
set('month', e.target.value)} className={inputBase} /> set('day', e.target.value)} className={inputBase} /> set('year', e.target.value)} className={inputBase} />
) } if (t === 'time') { const dv = field.defaultValues && typeof field.defaultValues === 'object' ? field.defaultValues : {} const set = (k, v) => onUpdate({ defaultValues: { ...dv, [k]: v } }) const is12 = timeFormatOf(field) === '12hour' return (
Default Value
set('hour', e.target.value)} className={inputBase} /> set('minute', e.target.value)} className={inputBase} /> {is12 && ( )}
) } if (!hasPlainDefault(t)) return null const multiline = t === 'textarea' return (
Default Value {multiline ? (