Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/resources/scripts/components/elements/InputError.tsx
7461 views
1
import React from 'react';
2
import { FormikErrors, FormikTouched } from 'formik';
3
import tw from 'twin.macro';
4
import { capitalize } from '@/lib/strings';
5
6
interface Props {
7
errors: FormikErrors<any>;
8
touched: FormikTouched<any>;
9
name: string;
10
children?: string | number | null | undefined;
11
}
12
13
const InputError = ({ errors, touched, name, children }: Props) =>
14
touched[name] && errors[name] ? (
15
<p css={tw`text-xs text-red-400 pt-2`}>
16
{typeof errors[name] === 'string'
17
? capitalize(errors[name] as string)
18
: capitalize((errors[name] as unknown as string[])[0])}
19
</p>
20
) : (
21
<>{children ? <p css={tw`text-xs text-neutral-400 pt-2`}>{children}</p> : null}</>
22
);
23
24
export default InputError;
25
26