MCPcopy Index your code
hub / github.com/formkit/formkit / createElement

Function createElement

packages/react/src/FormKitSchema.ts:884–1070  ·  view source on GitHub ↗
(
    lib: FormKitComponentLibrary,
    node: FormKitSchemaNode
  )

Source from the content-addressed store, hash-verified

882 }
883
884 function createElement(
885 lib: FormKitComponentLibrary,
886 node: FormKitSchemaNode
887 ): RenderNodes {
888 const [condition, element, attrs, children, alternate, iterator, resolve] =
889 parseNode(lib, node)
890
891 let createNodes: RenderNodes = ((iterationData?: Record<string, unknown>) => {
892 if (condition && element === null && children) {
893 return condition()
894 ? children(iterationData)
895 : alternate && alternate(iterationData)
896 }
897
898 if (element && (!condition || condition())) {
899 if (element === 'text') {
900 return children ? String(children(iterationData)) : ''
901 }
902
903 if (element === 'slot' && children) {
904 return children(iterationData)
905 }
906
907 const resolvedEl =
908 resolve && typeof element === 'string'
909 ? (lib[element] || (globalThis as any)[element])
910 : element
911
912 if (!resolvedEl) {
913 return null
914 }
915
916 let normalizedAttrs = normalizeAttrs(
917 resolvedEl as string | ComponentType<any> | null,
918 attrs()
919 )
920 const slots: RenderableSlots | null = children?.slot
921 ? createSlots(children, iterationData)
922 : null
923
924 if (slots) {
925 return h(
926 resolvedEl as ComponentType<any>,
927 {
928 ...(normalizedAttrs || {}),
929 slots,
930 },
931 slots.default ? slots.default() : null
932 )
933 }
934
935 let renderedChildren =
936 normalizedAttrs &&
937 typeof normalizedAttrs === 'object' &&
938 'dangerouslySetInnerHTML' in normalizedAttrs
939 ? null
940 : ((children ? children(iterationData) : null) as ReactNode)
941

Callers 15

FormKitKitchenSinkFunction · 0.90
FormKitRootFunction · 0.90
FormKitMessagesFunction · 0.90
FormKitProviderFunction · 0.90
FormKitConfigLoaderFunction · 0.90
FormKitLazyProviderFunction · 0.90
FormKitIconFunction · 0.90
FormKitImplFunction · 0.90
FormKitSummaryFunction · 0.90
createElementsFunction · 0.90
ChildComponentFunction · 0.90

Calls 7

normalizeAttrsFunction · 0.85
normalizeSelectOptionsFunction · 0.85
isDomValueManagedControlFunction · 0.85
resolveIterationKeyFunction · 0.85
parseNodeFunction · 0.70
attrsFunction · 0.70
createSlotsFunction · 0.70

Tested by 15

ChildComponentFunction · 0.72
ChildImmediateFunction · 0.72
ChildLaterFunction · 0.72
HostFunction · 0.72
ChildComponentFunction · 0.72
HostFunction · 0.72
HostFunction · 0.72
CustomInputFunction · 0.72
componentAFunction · 0.72
componentBFunction · 0.72
HostFunction · 0.72
ChildComponentFunction · 0.72