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

Function useInput

packages/react/src/composables/useInput.ts:193–549  ·  view source on GitHub ↗
(
  props: Props & Record<string, any>,
  options: FormKitOptions = {}
)

Source from the content-addressed store, hash-verified

191}
192
193export function useInput<Props extends FormKitInputs<Props>>(
194 props: Props & Record<string, any>,
195 options: FormKitOptions = {}
196): FormKitNode {
197 const providedOptions = useContext(optionsSymbol)
198 const config = Object.assign({}, providedOptions || {}, options)
199 const __root = useContext(rootSymbol)
200 const __cmpCallback = useContext(componentSymbol)
201 const inheritedParent = useContext(parentSymbol)
202
203 const listeners = onlyListeners(props)
204 const isVModeled =
205 props.modelValue !== undefined ||
206 props.value !== undefined ||
207 typeof props.onUpdateModelValue === 'function'
208
209 const value: any =
210 props.modelValue !== undefined
211 ? props.modelValue
212 : props.value !== undefined
213 ? props.value
214 : cloneAny(props.defaultValue)
215
216 const createInitialProps = useMemo(() => {
217 const initialProps: Record<string, any> = {
218 ...nodeProps(props),
219 ...listeners,
220 type: props.type ?? 'text',
221 __root,
222 __slots: props.slots || {},
223 }
224
225 const allProps = nodeProps(props)
226 const attrs = Object.keys(allProps).reduce((acc, key) => {
227 if (
228 runtimeOnlyProps.has(key) ||
229 patternMatches(key, pseudoProps as Array<string | RegExp>)
230 ) {
231 return acc
232 }
233 acc[key] = allProps[key]
234 return acc
235 }, {} as Record<string, unknown>)
236
237 if (!attrs.key) attrs.key = token()
238 initialProps.attrs = attrs
239
240 const propValues = only(allProps, pseudoProps)
241 for (const propName in propValues) {
242 if (boolProps.includes(propName) && propValues[propName] === '') {
243 propValues[propName] = true
244 }
245 initialProps[camel(propName)] = propValues[propName]
246 }
247
248 const classesProps = { props: {} }
249 classesToNodeProps(classesProps as FormKitNode, props)
250 Object.assign(initialProps, classesProps.props)

Callers 1

FormKitImplFunction · 0.90

Calls 15

cloneAnyFunction · 0.90
nodePropsFunction · 0.90
tokenFunction · 0.90
onlyFunction · 0.90
camelFunction · 0.90
extendFunction · 0.90
undefineFunction · 0.90
createNodeFunction · 0.90
errorFunction · 0.90
onSSRCompleteFunction · 0.90
kebabFunction · 0.90
oncePerTickFunction · 0.90

Tested by

no test coverage detected