Files
TheGame/packages/web/components/Forms/Field.tsx
2021-08-26 10:10:01 -06:00

30 lines
867 B
TypeScript

import { Flex, Text } from '@metafam/ds';
import React from 'react';
import { FieldError } from 'react-hook-form';
type FieldProps = {
children: React.ReactNode;
label: string;
error?: FieldError;
};
export const Field: React.FC<FieldProps> = ({ children, error, label }) => (
<Flex mb={2} w="100%" align="center" direction="column">
<Flex justify="space-between" w="100%" mb={2}>
<Text textStyle="caption" textAlign="left" ml={4}>
{label}
</Text>
<Text textStyle="caption" textAlign="left" color="red.400" mr={4}>
{error?.type === 'required' && 'Required'}
{error?.type === 'pattern' && 'Invalid URL'}
{error?.type === 'minLength' && 'Too short'}
{error?.type === 'maxLength' && 'Too long'}
{error?.type === 'min' && 'Too small'}
</Text>
</Flex>
{children}
</Flex>
);