import { Button } from '@/component/ui/button' import { Input } from '@/component/ui/input' import { ElementDefinition } from '@/entitiy/element/model/interface' import { ElementOption } from '@/type/template' import { CheckSquare, Plus, Trash2 } from 'lucide-react' interface RadioConfig { placeholder?: string required?: boolean options: ElementOption[] targetCells: any[] } export const radioDefinition: ElementDefinition = { type: 'radio', label: 'Радиокнопки', icon: , version: 1, defaultConfig: { placeholder: '', required: false, options: [], targetCells: [], }, mapToCells: config => config.targetCells || [], mapToCellValues: (config, value) => { const cells = config.targetCells || [] return cells.map(target => ({ target, value: value || '' })) }, Editor: ({ config, onChange }) => { const handleAddOption = () => { onChange({ ...config, options: [...config.options, { value: '', label: '' }], }) } const handleUpdateOption = ( index: number, field: 'value' | 'label', value: string ) => { onChange({ ...config, options: config.options.map((option, i) => i === index ? { ...option, [field]: value } : option ), }) } const handleRemoveOption = (index: number) => { onChange({ ...config, options: config.options.filter((_, i) => i !== index), }) } return (
{config.options.map((option, index) => (
handleUpdateOption(index, 'value', e.target.value) } /> handleUpdateOption(index, 'label', e.target.value) } />
))}
) }, Preview: ({ config }) => (
Предпросмотр
{config.options.length > 0 ? ( config.options.map((option, index) => (
{option.label}
)) ) : (
Вариант 1
)}
), Render: ({ config, value, onChange }) => (
{config.options.map((option, index) => (
onChange?.(e.target.value)} required={config.required} className="h-4 w-4" /> {option.label}
))}
), }