import React from "react"; import tw from "twin.macro"; import { useField as useFormikField, useFormikContext, FieldHookConfig } from "formik"; import { IMaskInput, IMaskInputProps, IMaskMixinProps } from 'react-imask'; //const useFormikField = null; //const useFormikContext = ()=>{}; export function useField(props) { let getField = useFormikField; const context = useFormikContext(); if (!context) { getField = (propsOrFieldName: FieldHookConfig) => { return [props, null, null]; } } return getField(props); } export default function Input( props: React.InputHTMLAttributes & FieldHookConfig & { label?: React.ComponentPropsWithoutRef<"label">; title?: string; children?: React.ReactNode; className?: string; } ) { /*name, id*/ let { children, ...otherProps } = props; const [field, meta, helpers] = useField(otherProps); return (
{props.title && ( )} {/*name={name || title} id={id || name || title}*/} {props.children} {meta?.touched && meta.error ? (
{meta.error}
) : null}
); } export function MaskedInput( props: Omit, "validate" | "label"> & FieldHookConfig & { definitions: { [k: string]: RegExp }; label?: React.ComponentPropsWithoutRef<"label">; title?: string; children?: React.ReactNode; className?: string; } ) { /*name, id*/ let { children, validate, ...otherProps } = props; const [field, meta, helpers] = useField({ ...otherProps, validate }); return (
{props.title && ( )} {/*name={name || title} id={id || name || title}*/} field.onChange({ target: { value, name: field.name } }) } onBlur={field.onBlur} tw="bg-primary appearance-none border-2 border-secondary rounded w-full py-2 px-4 text-primary leading-tight focus:outline-none focus:bg-secondary focus:border-accent transition duration-150 " /> {props.children} {meta?.touched && meta.error ? (
{meta.error}
) : null}
); } export function TextArea({ title, children = null, label = null, ...props }) { const [field, meta, helpers] = useField(props); return (
{title && ( )}