(
props: Props & Record<string, any>,
options: FormKitOptions = {}
)
| 191 | } |
| 192 | |
| 193 | export 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) |
no test coverage detected