(
schemaOrComponent: FormKitSchemaNode | FormKitSection | ComponentType<any>,
definitionOptions: Partial<FormKitTypeDefinition<V>> = {},
sectionsSchema: FormKitSectionsSchema = {}
)
| 21 | } |
| 22 | |
| 23 | export function createInput<V = unknown>( |
| 24 | schemaOrComponent: FormKitSchemaNode | FormKitSection | ComponentType<any>, |
| 25 | definitionOptions: Partial<FormKitTypeDefinition<V>> = {}, |
| 26 | sectionsSchema: FormKitSectionsSchema = {} |
| 27 | ): FormKitTypeDefinition<V> { |
| 28 | const definition: FormKitTypeDefinition<V> = { |
| 29 | type: 'input', |
| 30 | ...definitionOptions, |
| 31 | } |
| 32 | |
| 33 | let schema: FormKitSection |
| 34 | |
| 35 | if (isComponent(schemaOrComponent)) { |
| 36 | const cmpName = `SchemaComponent${totalCreated++}` |
| 37 | schema = createSection('input', () => ({ |
| 38 | $cmp: cmpName, |
| 39 | props: { |
| 40 | context: '$node.context', |
| 41 | }, |
| 42 | })) |
| 43 | definition.library = { [cmpName]: schemaOrComponent } |
| 44 | } else if (typeof schemaOrComponent === 'function') { |
| 45 | schema = schemaOrComponent |
| 46 | } else { |
| 47 | schema = createSection('input', () => cloneAny(schemaOrComponent)) |
| 48 | } |
| 49 | |
| 50 | definition.schema = useSchema(schema || 'Schema undefined', sectionsSchema) |
| 51 | if (!definition.schemaMemoKey) { |
| 52 | definition.schemaMemoKey = `${Math.random()}` |
| 53 | } |
| 54 | return definition |
| 55 | } |
no test coverage detected