Единый интерфейс элементов
This commit is contained in:
53
src/entitiy/element/model/implementations/TextElement.tsx
Normal file
53
src/entitiy/element/model/implementations/TextElement.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
import { Input } from '@/component/ui/input'
|
||||
import { ElementDefinition } from '@/entitiy/element/model/interface'
|
||||
import { ExtraSettingsBadge } from '@/entitiy/element/ui/extraSettingsBadge'
|
||||
import { Type } from 'lucide-react'
|
||||
|
||||
interface TextConfig {
|
||||
placeholder?: string
|
||||
required?: boolean
|
||||
targetCells: any[]
|
||||
name?: string
|
||||
}
|
||||
|
||||
export const textDefinition: ElementDefinition<TextConfig, string> = {
|
||||
type: 'text',
|
||||
label: 'Текстовое поле',
|
||||
icon: <Type className="h-4 w-4" />,
|
||||
version: 1,
|
||||
defaultConfig: {
|
||||
placeholder: '',
|
||||
required: false,
|
||||
targetCells: [],
|
||||
name: '',
|
||||
},
|
||||
mapToCells: config => config.targetCells || [],
|
||||
Editor: () => <ExtraSettingsBadge />,
|
||||
Preview: ({ config }) => (
|
||||
<div className="space-y-1">
|
||||
{config.name && (
|
||||
<label className="text-sm font-medium text-gray-900">
|
||||
{config.name}
|
||||
{config.required && <span className="ml-1 text-red-500">*</span>}
|
||||
</label>
|
||||
)}
|
||||
<Input placeholder={config.placeholder} className="w-full" />
|
||||
</div>
|
||||
),
|
||||
Render: ({ config, value, onChange }) => (
|
||||
<div className="space-y-1">
|
||||
{config.name && (
|
||||
<label className="text-sm font-medium text-gray-900">
|
||||
{config.name}
|
||||
{config.required && <span className="ml-1 text-red-500">*</span>}
|
||||
</label>
|
||||
)}
|
||||
<Input
|
||||
placeholder={config.placeholder}
|
||||
value={value || ''}
|
||||
onChange={e => onChange?.(e.target.value)}
|
||||
required={config.required}
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
}
|
||||
Reference in New Issue
Block a user