(
schemaOrComponent: FormKitSchemaNode | FormKitSection | Component,
definitionOptions: Partial<FormKitTypeDefinition<V>> = {},
sectionsSchema: FormKitSectionsSchema = {}
)
| 41 | * @public |
| 42 | */ |
| 43 | export function createInput<V = unknown>( |
| 44 | schemaOrComponent: FormKitSchemaNode | FormKitSection | Component, |
| 45 | definitionOptions: Partial<FormKitTypeDefinition<V>> = {}, |
| 46 | sectionsSchema: FormKitSectionsSchema = {} |
| 47 | ): FormKitTypeDefinition<V> { |
| 48 | const definition: FormKitTypeDefinition<V> = { |
| 49 | type: 'input', |
| 50 | ...definitionOptions, |
| 51 | } |
| 52 | let schema: FormKitSection |
| 53 | if (isComponent(schemaOrComponent)) { |
| 54 | const cmpName = `SchemaComponent${totalCreated++}` |
| 55 | schema = createSection('input', () => ({ |
| 56 | $cmp: cmpName, |
| 57 | props: { |
| 58 | context: '$node.context', |
| 59 | }, |
| 60 | })) |
| 61 | definition.library = { [cmpName]: markRaw(schemaOrComponent) } |
| 62 | } else if (typeof schemaOrComponent === 'function') { |
| 63 | schema = schemaOrComponent |
| 64 | } else { |
| 65 | schema = createSection('input', () => cloneAny(schemaOrComponent)) |
| 66 | } |
| 67 | |
| 68 | // Use the default wrapping schema |
| 69 | definition.schema = useSchema(schema || 'Schema undefined', sectionsSchema) |
| 70 | if (!definition.schemaMemoKey) { |
| 71 | definition.schemaMemoKey = `${Math.random()}` |
| 72 | } |
| 73 | return definition |
| 74 | } |
no test coverage detected