MCPcopy Create free account
hub / github.com/formkit/formkit / createInput

Function createInput

packages/react/src/composables/createInput.ts:23–55  ·  view source on GitHub ↗
(
  schemaOrComponent: FormKitSchemaNode | FormKitSection | ComponentType<any>,
  definitionOptions: Partial<FormKitTypeDefinition<V>> = {},
  sectionsSchema: FormKitSectionsSchema = {}
)

Source from the content-addressed store, hash-verified

21}
22
23export 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}

Callers 2

Calls 4

createSectionFunction · 0.90
cloneAnyFunction · 0.90
useSchemaFunction · 0.90
isComponentFunction · 0.70

Tested by

no test coverage detected