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

Function createSection

packages/inputs/src/createSection.ts:85–131  ·  view source on GitHub ↗
(
  section: string,
  el: string | null | (() => FormKitSchemaNode),
  fragment = false
)

Source from the content-addressed store, hash-verified

83
84/*@__NO_SIDE_EFFECTS__*/
85export function createSection(
86 section: string,
87 el: string | null | (() => FormKitSchemaNode),
88 fragment = false
89): FormKitSection<
90 FormKitExtendableSchemaRoot | FormKitSchemaExtendableSection
91> {
92 return (
93 ...children: Array<
94 FormKitSchemaExtendableSection | string | FormKitSchemaCondition
95 >
96 ) => {
97 const extendable = (extensions: FormKitSectionsSchema) => {
98 const node = !el || typeof el === 'string' ? { $el: el } : el()
99 if (isDOM(node) || isComponent(node)) {
100 if (!node.meta) {
101 node.meta = { section }
102 } else {
103 node.meta.section = section
104 }
105 if (children.length && !node.children) {
106 node.children = [
107 ...children.map((child) =>
108 typeof child === 'function' ? child(extensions) : child
109 ),
110 ]
111 }
112 if (isDOM(node)) {
113 node.attrs = {
114 class: `$classes.${section}`,
115 ...(node.attrs || {}),
116 }
117 }
118 }
119 return {
120 if: `$slots.${section}`,
121 then: `$slots.${section}`,
122 else:
123 section in extensions
124 ? extendSchema(node, extensions[section])
125 : node,
126 }
127 }
128 extendable._s = section
129 return fragment ? createRoot(extendable) : extendable
130 }
131}
132
133/**
134 * Returns an extendable schema root node.

Callers 15

FormKitMessages.tsFile · 0.90
FormKitSummary.tsFile · 0.90
createInputFunction · 0.90
badge.tsFile · 0.90
stepIconFunction · 0.90
wrapper.tsFile · 0.90
tabs.tsFile · 0.90
multiStepOuter.tsFile · 0.90
stepInner.tsFile · 0.90
stepPrevious.tsFile · 0.90
stepActions.tsFile · 0.90
stepNext.tsFile · 0.90

Calls 1

createRootFunction · 0.85

Tested by

no test coverage detected