Skip to content

Commit 5f8d8e7

Browse files
Prefer string | ReactElement to avoid null, boolean etc
1 parent c2abbcf commit 5f8d8e7

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/components/form-elements/date-input/DateInputContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use client';
22

3-
import { createContext, type ChangeEvent } from 'react';
3+
import { createContext, type ChangeEvent, type ReactElement } from 'react';
44

55
export type IDateInputContext = {
66
id: string;
77
name: string;
8-
error: React.ReactNode | undefined;
8+
error: string | ReactElement | undefined;
99
value?: { day?: string; month?: string; year?: string };
1010
defaultValue?: { day?: string; month?: string; year?: string };
1111
handleChange: (inputType: 'day' | 'month' | 'year', event: ChangeEvent<HTMLInputElement>) => void;

src/components/form-elements/date-input/components/DateInputField.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
'use client';
22

33
import classNames from 'classnames';
4-
import { forwardRef, useContext, type ChangeEvent, type ComponentPropsWithoutRef } from 'react';
4+
import {
5+
forwardRef,
6+
useContext,
7+
type ChangeEvent,
8+
type ComponentPropsWithoutRef,
9+
type ReactElement,
10+
} from 'react';
511

612
import { DateInputContext, type IDateInputContext } from '../DateInputContext.js';
713

@@ -11,7 +17,7 @@ import { type FormElementProps } from '#util/types/FormTypes.js';
1117
export interface IndividualDateInputProps
1218
extends ComponentPropsWithoutRef<'input'>,
1319
Pick<FormElementProps, 'label' | 'labelProps'> {
14-
error?: string | false;
20+
error?: string | ReactElement | false;
1521
inputType: 'day' | 'month' | 'year';
1622
}
1723

src/util/types/FormTypes.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { type ReactElement } from 'react';
2+
13
import { type ErrorMessageProps } from '#components/form-elements/error-message/index.js';
24
import { type FieldsetProps } from '#components/form-elements/fieldset/index.js';
35
import { type HintTextProps } from '#components/form-elements/hint-text/index.js';
@@ -7,13 +9,13 @@ import { type ComponentPropsWithDataAttributes } from '#util/types/NHSUKTypes.js
79

810
export interface FormElementProps {
911
'fieldsetProps'?: FieldsetProps;
10-
'legend'?: string;
12+
'legend'?: string | ReactElement;
1113
'legendProps'?: LegendProps;
12-
'label'?: string;
14+
'label'?: string | ReactElement;
1315
'labelProps'?: LabelProps;
14-
'error'?: React.ReactNode;
16+
'error'?: string | ReactElement;
1517
'errorProps'?: ErrorMessageProps;
16-
'hint'?: React.ReactNode;
18+
'hint'?: string | ReactElement;
1719
'hintProps'?: HintTextProps;
1820
'formGroupProps'?: ComponentPropsWithDataAttributes<'div'>;
1921
'id'?: string;

0 commit comments

Comments
 (0)