-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathFormField.tsx
More file actions
62 lines (57 loc) · 1.46 KB
/
FormField.tsx
File metadata and controls
62 lines (57 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* @license EUPL-1.2
* Copyright (c) 2026 Community for NL Design System
*/
import { type FormFieldProps, FormLabel, FormField as UtrechtFormField } from '@utrecht/component-library-react';
import clsx from 'clsx';
import { PropsWithChildren, ReactNode, Ref } from 'react';
import { FormFieldErrorMessage } from './FormFieldErrorMessage';
export interface CustomFormFieldProps extends FormFieldProps {
label: ReactNode;
description?: ReactNode;
errorMessage?: string;
input: ReactNode;
status?: ReactNode;
invalid?: boolean;
statusId: string;
errorMessageId: string;
descriptionId: string;
ref?: Ref<HTMLDivElement>;
}
export const FormField = ({
ref,
className,
errorMessageId,
dir,
statusId,
invalid,
input,
description,
label,
status,
id,
errorMessage,
children,
}: PropsWithChildren<CustomFormFieldProps>) => {
const labelComponent = <FormLabel htmlFor={id}>{label}</FormLabel>;
return (
<UtrechtFormField
className={clsx('rhc-form-field', className)}
description={description}
dir={dir}
invalid={invalid}
label={labelComponent}
ref={ref}
>
{invalid && errorMessage && <FormFieldErrorMessage id={errorMessageId}>{errorMessage}</FormFieldErrorMessage>}
{input}
{status && (
<div className="utrecht-form-field__status" id={statusId}>
{status}
</div>
)}
{children}
</UtrechtFormField>
);
};
FormField.displayName = 'FormField';