diff --git a/Parts/Input.js b/Parts/Input.tsx similarity index 80% rename from Parts/Input.js rename to Parts/Input.tsx index 1b38a31..37afcfb 100644 --- a/Parts/Input.js +++ b/Parts/Input.tsx @@ -1,7 +1,7 @@ import React from "react"; -import tw, { styled } from "twin.macro"; -import { useField as useFormikField, useFormikContext } from "formik"; +import tw from "twin.macro"; +import { useField as useFormikField, useFormikContext, FieldHookConfig } from "formik"; //const useFormikField = null; //const useFormikContext = ()=>{}; @@ -9,37 +9,45 @@ export function useField(props){ let getField = useFormikField; const context = useFormikContext(); if(!context){ - getField = (props)=>{ + getField = (propsOrFieldName: FieldHookConfig)=>{ return [props, null, null]; } } return getField(props); } -export default function Input({ label, title, children, className, ...props }) { +export default function Input( + props: React.InputHTMLAttributes & { + label?: React.ComponentPropsWithoutRef<"label">; + title?: string; + children?: React.ReactNode; + className?: string; + } +) { /*name, id*/ - props.id = props.id ?? props.name ?? title; const [field, meta, helpers] = useField(props); return ( -
- {title && ( +
+ {props.title && ( )} {/*name={name || title} id={id || name || title}*/} - {children} + {props.children} {meta?.touched && meta.error ? (
{meta.error}
) : null}