mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-02-10 22:14:53 -05:00
30 lines
867 B
TypeScript
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>
|
|
);
|