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

Function createInput

packages/vue/src/composables/createInput.ts:43–74  ·  view source on GitHub ↗
(
  schemaOrComponent: FormKitSchemaNode | FormKitSection | Component,
  definitionOptions: Partial<FormKitTypeDefinition<V>> = {},
  sectionsSchema: FormKitSectionsSchema = {}
)

Source from the content-addressed store, hash-verified

41 * @public
42 */
43export 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}

Callers 5

formkit.config.tsFile · 0.90
FormKit.spec.tsFile · 0.90
main.tsFile · 0.90

Calls 4

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

Tested by

no test coverage detected